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

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 {

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(_, _) => {}

View File

@@ -239,23 +239,30 @@ 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()
{ {
// to make sure padding and layout_options changes get applied for users after a quick restart if let Some(state_workspace) = state_monitor.workspaces().get(workspace_idx)
let container_padding = workspace.container_padding; {
let workspace_padding = workspace.workspace_padding; // to make sure padding and layout_options changes get applied for users after a quick restart
let layout_options = workspace.layout_options; let container_padding = workspace.container_padding;
let workspace_padding = workspace.workspace_padding;
let layout_options = workspace.layout_options;
*workspace = state_workspace.clone(); *workspace = state_workspace.clone();
workspace.container_padding = container_padding; workspace.container_padding = container_padding;
workspace.workspace_padding = workspace_padding; workspace.workspace_padding = workspace_padding;
workspace.layout_options = layout_options; workspace.layout_options = layout_options;
if state_monitor.focused_workspace_idx() == workspace_idx { if state_monitor.focused_workspace_idx() == workspace_idx {
focused_workspace = workspace_idx; focused_workspace = workspace_idx;
}
} }
} }
} }

File diff suppressed because it is too large Load Diff