Skip to content

Commit

Permalink
feat: add system sleep event handling
Browse files Browse the repository at this point in the history
Adds support for system sleep events in the window manager:

- Introduced `SystemSleep` variant to `PlatformEvent`

- Updated event handling in `wm.rs` to process system sleep events

- Prepared `handle_system_sleep` function for future implementation
  • Loading branch information
al3rez committed Feb 27, 2025
1 parent 518bfb4 commit 4d79dd7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/wm-platform/src/event_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum PlatformEvent {
DisplaySettingsChanged,
KeybindingTriggered(KeybindingConfig),
MouseMove(MouseMoveEvent),
SystemSleep,
WindowDestroyed(NativeWindow),
WindowFocused(NativeWindow),
WindowHidden(NativeWindow),
Expand Down
4 changes: 4 additions & 0 deletions packages/wm-platform/src/event_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ pub extern "system" fn event_window_proc(
// System is entering sleep/hibernation.
PBT_APMSUSPEND => {
IS_SYSTEM_SUSPENDED.store(true, Ordering::Relaxed);
// Emit SystemSleep event
if let Err(err) = event_tx.send(PlatformEvent::SystemSleep) {
warn!("Failed to send SystemSleep event: {}", err);
}
}
_ => {}
}
Expand Down
15 changes: 7 additions & 8 deletions packages/wm/src/events/handle_system_resume.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::Context;
use tracing::info;
use wm_common::WmEvent;

Expand All @@ -7,8 +6,8 @@ use crate::{
container::move_container_within_tree,
workspace::sort_workspaces,
},
models::{Monitor, WindowContainer},
traits::{CommonGetters, WindowGetters},
models::WindowContainer,
traits::CommonGetters,
user_config::UserConfig,
wm_state::WmState,
};
Expand Down Expand Up @@ -58,7 +57,7 @@ pub fn handle_system_resume(
// Find the target monitor with the saved hardware ID
let target_monitor = state.monitors().into_iter().find(|monitor| {
if let Ok(Some(id)) = monitor.native().hardware_id() {
id == *saved_hardware_id
*id == *saved_hardware_id
} else {
false
}
Expand All @@ -70,9 +69,9 @@ pub fn handle_system_resume(
// Move the window to the target workspace
move_container_to_workspace(&window, &target_workspace, state, config)?;

state.emit_event(WmEvent::WindowMoved {
window_id: window.id(),
workspace_id: target_workspace.id(),
// Emit an event that the window was moved to a different workspace
state.emit_event(WmEvent::FocusedContainerMoved {
focused_container: window.to_dto()?,
});
}
}
Expand Down Expand Up @@ -104,7 +103,7 @@ fn move_container_to_workspace(
}

// Queue redraw
state.pending_sync.queue_container_to_redraw(window.clone().into());
state.pending_sync.queue_container_to_redraw(window.clone());

Ok(())
}
1 change: 0 additions & 1 deletion packages/wm/src/events/handle_system_sleep.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::Context;
use tracing::info;

use crate::{
Expand Down
5 changes: 4 additions & 1 deletion packages/wm/src/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
handle_window_location_changed, handle_window_minimize_ended,
handle_window_minimized, handle_window_moved_or_resized_end,
handle_window_moved_or_resized_start, handle_window_shown,
handle_window_title_changed,
handle_window_title_changed, handle_system_sleep,
},
models::{Container, WorkspaceTarget},
traits::{CommonGetters, WindowGetters},
Expand Down Expand Up @@ -81,6 +81,9 @@ impl WindowManager {
PlatformEvent::MouseMove(event) => {
handle_mouse_move(&event, state, config)
}
PlatformEvent::SystemSleep => {
handle_system_sleep(state, config)
}
PlatformEvent::WindowDestroyed(window) => {
handle_window_destroyed(&window, state)
}
Expand Down

0 comments on commit 4d79dd7

Please sign in to comment.