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 Jeezy
parent 8a1447f543
commit bcdfc0799a
4 changed files with 1359 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ use strum::EnumString;
use crate::KomorebiTheme;
use crate::animation::prefix::AnimationPrefix;
use crate::state::State;
// Re-export everything from komorebi-layouts
pub use komorebi_layouts::Arrangement;
@@ -256,6 +257,8 @@ pub enum SocketMessage {
StaticConfigSchema,
GenerateStaticConfig,
DebugWindow(isize),
// low level commands
ApplyState(State),
}
impl SocketMessage {

View File

@@ -2296,6 +2296,9 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
SocketMessage::Theme(ref theme) => {
theme_manager::send_notification(*theme.clone());
}
SocketMessage::ApplyState(ref state) => {
self.apply_state(state.clone());
}
// Deprecated commands
SocketMessage::AltFocusHack(_)
| SocketMessage::IdentifyBorderOverflowApplication(_, _) => {}

View File

@@ -239,23 +239,28 @@ impl WindowManager {
let mouse_follows_focus = self.mouse_follows_focus;
for (monitor_idx, monitor) in self.monitors_mut().iter_mut().enumerate() {
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)
&& 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
let container_padding = workspace.container_padding;
let workspace_padding = workspace.workspace_padding;
let layout_options = workspace.layout_options;
if let Some(state_monitor) = state.monitors.elements().get(monitor_idx) {
monitor
.workspaces_mut()
.resize(state_monitor.workspaces().len(), Workspace::default());
*workspace = state_workspace.clone();
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
let container_padding = workspace.container_padding;
let workspace_padding = workspace.workspace_padding;
let layout_options = workspace.layout_options;
workspace.container_padding = container_padding;
workspace.workspace_padding = workspace_padding;
workspace.layout_options = layout_options;
*workspace = state_workspace.clone();
if state_monitor.focused_workspace_idx() == workspace_idx {
focused_workspace = workspace_idx;
workspace.container_padding = container_padding;
workspace.workspace_padding = workspace_padding;
workspace.layout_options = layout_options;
if state_monitor.focused_workspace_idx() == workspace_idx {
focused_workspace = workspace_idx;
}
}
}
}

File diff suppressed because it is too large Load Diff