diff options
| author | srdusr <[email protected]> | 2024-07-31 16:22:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2024-07-31 16:22:00 +0200 |
| commit | c180bfc34e4c74ba7cac9e0220e9c172c239fe71 (patch) | |
| tree | 45550c7eb7ae819a9c3a415acb9cfa5be1cfd03b /crates/x11/src/platform/actions.rs | |
| parent | 38683f069a039f9da6d7ddc64167850560fd07ed (diff) | |
| download | srdwm-c180bfc34e4c74ba7cac9e0220e9c172c239fe71.tar.gz srdwm-c180bfc34e4c74ba7cac9e0220e9c172c239fe71.zip | |
Split crates/x11/src/lib.rs (925 lines) into platform/
Pure reorganization, no behavior change - verified by diffing the
function-name and struct/trait-name sets before/after (both identical)
plus a full cargo test pass. lib.rs is now a thin shim (mod
declaration + pub use), same pattern crates/config used, since a crate
root can't itself become a directory. platform/mod.rs keeps the atom
table, Frame/X11Platform's struct definitions, the small free-function
helpers (err, modmask_for_keycode_in_mod_slots, rgb_to_pixel), and the
ClonedForRender trait+impl. The rest splits by concern:
- connect.rs: connect, keymap/modifier helpers, grab_keybindings.
- window.rs: manage_new_window and the other per-client lifecycle
methods (window_title/class, supports_wm_delete, unmanage,
frame_for).
- events.rs: handle_event, the X11 event-dispatch loop.
- actions.rs: raise_and_focus/request_close/sync_geometry/
redraw_all_decorations.
- trait_impl.rs: `impl Platform for X11Platform` - named to avoid
clippy's module_inception lint, since the containing directory is
already named `platform`.
- tests.rs: unsplit, same reasoning as every other split this pass.
A handful of X11Platform methods (frame_for, manage_new_window,
unmanage, raise_and_focus, request_close, sync_geometry,
keycode_to_keysym, modifiers_from_state, handle_event) went from
private to pub(super): called across what are now sibling submodules,
which Rust's privacy model doesn't let see each other's private items.
Diffstat (limited to 'crates/x11/src/platform/actions.rs')
| -rw-r--r-- | crates/x11/src/platform/actions.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/x11/src/platform/actions.rs b/crates/x11/src/platform/actions.rs new file mode 100644 index 0000000..9d31d01 --- /dev/null +++ b/crates/x11/src/platform/actions.rs @@ -0,0 +1,49 @@ +use super::*; + +impl X11Platform { + + pub(super) fn raise_and_focus(&mut self, id: WindowId) -> PlatformResult<()> { + self.wm.borrow_mut().focus_window(id); + if let Some(frame) = self.frame_for(id) { + self.conn.configure_window(frame, &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE)).map_err(err)?; + } + self.redraw_all_decorations()?; + Ok(()) + } + + pub(super) fn request_close(&mut self, id: WindowId) -> PlatformResult<()> { + let Some(frame) = self.frames.get(&id) else { return Ok(()) }; + if frame.supports_delete { + let event = x11rb::protocol::xproto::ClientMessageEvent::new( + 32, + frame.client, + self.atoms.WM_PROTOCOLS, + [self.atoms.WM_DELETE_WINDOW, x11rb::CURRENT_TIME, 0, 0, 0], + ); + self.conn.send_event(false, frame.client, EventMask::NO_EVENT, event).map_err(err)?; + } else { + self.conn.destroy_window(frame.client).map_err(err)?; + } + Ok(()) + } + + pub(super) fn sync_geometry(&mut self, id: WindowId) -> PlatformResult<()> { + let geom = self.wm.borrow().window(id).map(|w| w.geometry); + if let Some(g) = geom { + self.apply_geometry(id, g)?; + } + Ok(()) + } + + fn redraw_all_decorations(&mut self) -> PlatformResult<()> { + let focused = self.wm.borrow().focused_id(); + let ids: Vec<WindowId> = self.frames.keys().copied().collect(); + for id in ids { + let w = self.wm.borrow().window(id).cloned_for_render(); + if let Some(w) = w { + self.redraw_decoration(id, &w, focused == Some(id))?; + } + } + Ok(()) + } +} |