diff options
author | tcmal <me@aria.rip> | 2024-06-09 17:34:45 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-09 17:34:45 +0100 |
commit | 124e6878b1de561f4bc3fccea768203821c88469 (patch) | |
tree | ff46ede6bc720148402841bfaad6d850ec900ab0 /src/focus.rs | |
parent | 66e3423828892a72e5e525f2dc8d5ad91e634445 (diff) |
minor cleanup
Diffstat (limited to 'src/focus.rs')
-rw-r--r-- | src/focus.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/focus.rs b/src/focus.rs index a237e24..bee148d 100644 --- a/src/focus.rs +++ b/src/focus.rs @@ -1,12 +1,13 @@ use xcb::x::{ - self, ChangeWindowAttributes, Cw, EnterNotifyEvent, FocusInEvent, InputFocus, NotifyDetail, - NotifyMode, SetInputFocus, Window, + self, EnterNotifyEvent, FocusInEvent, InputFocus, NotifyDetail, NotifyMode, SetInputFocus, + Window, }; -use crate::{clients::Client, error::*, WM}; +use crate::{error::*, WM}; impl WM<'_> { - pub(crate) fn handle_enter_notify(&mut self, e: EnterNotifyEvent) -> Result<()> { + /// When a new window is entered, focus it. + pub fn handle_enter_notify(&mut self, e: EnterNotifyEvent) -> Result<()> { if (e.mode() != NotifyMode::Normal || e.detail() == NotifyDetail::Inferior) && e.event() != self.root { @@ -19,7 +20,8 @@ impl WM<'_> { Ok(()) } - pub(crate) fn handle_focus_in(&mut self, e: FocusInEvent) -> Result<()> { + /// When a new window requests focus, focus it. + pub fn handle_focus_in(&mut self, e: FocusInEvent) -> Result<()> { if self .clients .focused_mut() @@ -27,12 +29,14 @@ impl WM<'_> { .unwrap_or(true) { self.focus_window(e.event()); + self.conn.flush()?; } + Ok(()) } - /// Attempt to focus the given window, falling back to the root if the window isn't our client. - /// This function sends multiple requests without checking them, so conn.flush() should be called after. + /// Attempt to focus the given window, even if it isn't managed. + /// This function sends multiple requests without checking them, so `conn.flush()` should be called after. pub fn focus_window(&mut self, window: Window) { if let Some((mon, i)) = self.clients.find_client_pos(window) { self.refocus(mon, i); @@ -46,8 +50,8 @@ impl WM<'_> { } } - /// Refocus on the client with the given co-ordinates, setting the X11 properties as required. - /// This function sends multiple requests without checking them, so conn.flush() should be called after. + /// Refocus on the client with the given co-ordinates, setting X11 properties as required. + /// This function sends multiple requests without checking them, so `conn.flush()` should be called after. pub fn refocus(&mut self, mon: usize, i: usize) { self.unfocus(); if let Some(new) = self.clients.set_focused(mon, i) { @@ -60,6 +64,8 @@ impl WM<'_> { } } + /// Unfocus the currently focused window, if it exists. + /// This function sends multiple requests without checking them, so `conn.flush()` should be called after. pub fn unfocus(&mut self) { if let Some(old) = self.clients.focused_mut() { old.set_border(self.conn, self.colours.border_normal()); |