feat(wm): add apply state socket message

This allows clients to send a state and get it applied to the wm.

By using the already there apply_state function we have all the
safety we need to apply the sent state.

This is also intentionally not open for the komorebic binary because I
think the average user doesnt need such a command and this is much safer
also to not give them the ability.
This commit is contained in:
pro470
2025-04-03 22:32:47 +02:00
committed by LGUG2Z
parent 8a1447f543
commit d7580d2271
4 changed files with 1360 additions and 13 deletions
+3
View File
@@ -15,6 +15,7 @@ use strum::EnumString;
use crate::KomorebiTheme; use crate::KomorebiTheme;
use crate::animation::prefix::AnimationPrefix; use crate::animation::prefix::AnimationPrefix;
use crate::state::State;
// Re-export everything from komorebi-layouts // Re-export everything from komorebi-layouts
pub use komorebi_layouts::Arrangement; pub use komorebi_layouts::Arrangement;
@@ -256,6 +257,8 @@ pub enum SocketMessage {
StaticConfigSchema, StaticConfigSchema,
GenerateStaticConfig, GenerateStaticConfig,
DebugWindow(isize), DebugWindow(isize),
// low level commands
ApplyState(State),
} }
impl SocketMessage { impl SocketMessage {
+3
View File
@@ -2296,6 +2296,9 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
SocketMessage::Theme(ref theme) => { SocketMessage::Theme(ref theme) => {
theme_manager::send_notification(*theme.clone()); theme_manager::send_notification(*theme.clone());
} }
SocketMessage::ApplyState(ref state) => {
self.apply_state(state.clone());
}
// Deprecated commands // Deprecated commands
SocketMessage::AltFocusHack(_) SocketMessage::AltFocusHack(_)
| SocketMessage::IdentifyBorderOverflowApplication(_, _) => {} | SocketMessage::IdentifyBorderOverflowApplication(_, _) => {}
+10 -3
View File
@@ -239,9 +239,15 @@ impl WindowManager {
let mouse_follows_focus = self.mouse_follows_focus; let mouse_follows_focus = self.mouse_follows_focus;
for (monitor_idx, monitor) in self.monitors_mut().iter_mut().enumerate() { for (monitor_idx, monitor) in self.monitors_mut().iter_mut().enumerate() {
let mut focused_workspace = 0; let mut focused_workspace = 0;
for (workspace_idx, workspace) in monitor.workspaces_mut().iter_mut().enumerate() { if let Some(state_monitor) = state.monitors.elements().get(monitor_idx) {
if let Some(state_monitor) = state.monitors.elements().get(monitor_idx) monitor
&& let Some(state_workspace) = state_monitor.workspaces().get(workspace_idx) .workspaces_mut()
.resize(state_monitor.workspaces().len(), Workspace::default());
for (workspace_idx, workspace) in
monitor.workspaces_mut().iter_mut().enumerate()
{
if let Some(state_workspace) = state_monitor.workspaces().get(workspace_idx)
{ {
// to make sure padding and layout_options changes get applied for users after a quick restart // to make sure padding and layout_options changes get applied for users after a quick restart
let container_padding = workspace.container_padding; let container_padding = workspace.container_padding;
@@ -259,6 +265,7 @@ impl WindowManager {
} }
} }
} }
}
if let Err(error) = monitor.focus_workspace(focused_workspace) { if let Err(error) = monitor.focus_workspace(focused_workspace) {
tracing::warn!( tracing::warn!(
+1334
View File
File diff suppressed because it is too large Load Diff