summaryrefslogtreecommitdiff
path: root/src/focus.rs
blob: 0c9512ff47d5c16f9f210e66e58e8e81579e3c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use xcb::x::{EnterNotifyEvent, FocusInEvent, NotifyDetail, NotifyMode};

use crate::{error::Result, WM};

impl WM<'_> {
    /// 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.conn.root()
        {
            return Ok(());
        }

        if let Some((mon, pos)) = self.clients.find_client_pos(e.event()) {
            self.clients.refocus(&self.conn, mon, pos);
            self.conn.flush()?;
        }

        Ok(())
    }

    /// When a new window requests focus, focus it.
    pub fn handle_focus_in(&mut self, e: &FocusInEvent) -> Result<()> {
        if !self.clients.is_focused(e.event()) {
            if let Some((mon, pos)) = self.clients.find_client_pos(e.event()) {
                self.clients.refocus(&self.conn, mon, pos);
                self.conn.flush()?;
            }
        }

        Ok(())
    }
}