summaryrefslogtreecommitdiff
path: root/src/focus.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/focus.rs')
-rw-r--r--src/focus.rs24
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());