Added pivotol functions to get urgency of clients, window title backend, configurenotify to get screen resolution correctly, and focusin to prevent focus stealing.
Browse files
+166 −3 src/window_manager.rs
| @@ -48,6 +48,7 @@ struct AtomCache { | |||
| 48 | wm_normal_hints: Atom, | 48 | wm_normal_hints: Atom, |
| 49 | wm_hints: Atom, | 49 | wm_hints: Atom, |
| 50 | wm_transient_for: Atom, | 50 | wm_transient_for: Atom, |
| 51 | + net_active_window: Atom, | ||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | impl AtomCache { | 54 | impl AtomCache { |
| @@ -99,6 +100,7 @@ impl AtomCache { | |||
| 99 | let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into(); | 100 | let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into(); |
| 100 | let wm_hints = AtomEnum::WM_HINTS.into(); | 101 | let wm_hints = AtomEnum::WM_HINTS.into(); |
| 101 | let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into(); | 102 | let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into(); |
| 103 | + let net_active_window = connection.intern_atom(false, b"_NET_ACTIVE_WINDOW")?.reply()?.atom; | ||
| 102 | 104 | ||
| 103 | Ok(Self { | 105 | Ok(Self { |
| 104 | net_current_desktop, | 106 | net_current_desktop, |
| @@ -115,6 +117,7 @@ impl AtomCache { | |||
| 115 | wm_normal_hints, | 117 | wm_normal_hints, |
| 116 | wm_hints, | 118 | wm_hints, |
| 117 | wm_transient_for, | 119 | wm_transient_for, |
| 120 | + net_active_window, | ||
| 118 | }) | 121 | }) |
| 119 | } | 122 | } |
| 120 | } | 123 | } |
| @@ -2527,17 +2530,49 @@ impl WindowManager { | |||
| 2527 | } | 2530 | } |
| 2528 | } | 2531 | } |
| 2529 | Event::PropertyNotify(event) => { | 2532 | Event::PropertyNotify(event) => { |
| 2530 | - if !self.windows.contains(&event.window) { | 2533 | + if event.state == x11rb::protocol::xproto::Property::DELETE { |
| 2531 | return Ok(None); | 2534 | return Ok(None); |
| 2532 | } | 2535 | } |
| 2533 | 2536 | ||
| 2537 | + if !self.clients.contains_key(&event.window) { | ||
| 2538 | + return Ok(None); | ||
| 2539 | + } | ||
| 2540 | + | ||
| 2541 | + if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() { | ||
| 2542 | + let is_floating = self.clients | ||
| 2543 | + .get(&event.window) | ||
| 2544 | + .map(|c| c.is_floating) | ||
| 2545 | + .unwrap_or(false); | ||
| 2546 | + | ||
| 2547 | + if !is_floating { | ||
| 2548 | + if let Some(transient_parent) = self.get_transient_parent(event.window) { | ||
| 2549 | + if self.clients.contains_key(&transient_parent) { | ||
| 2550 | + if let Some(client) = self.clients.get_mut(&event.window) { | ||
| 2551 | + client.is_floating = true; | ||
| 2552 | + } | ||
| 2553 | + self.floating_windows.insert(event.window); | ||
| 2554 | + self.apply_layout()?; | ||
| 2555 | + } | ||
| 2556 | + } | ||
| 2557 | + } | ||
| 2558 | + } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() { | ||
| 2559 | + if let Some(client) = self.clients.get_mut(&event.window) { | ||
| 2560 | + client.hints_valid = false; | ||
| 2561 | + } | ||
| 2562 | + } else if event.atom == AtomEnum::WM_HINTS.into() { | ||
| 2563 | + self.update_wm_hints(event.window)?; | ||
| 2564 | + self.update_bar()?; | ||
| 2565 | + } | ||
| 2566 | + | ||
| 2534 | if event.atom == self.atoms.wm_name || event.atom == self.atoms.net_wm_name { | 2567 | if event.atom == self.atoms.wm_name || event.atom == self.atoms.net_wm_name { |
| 2535 | let _ = self.update_window_title(event.window); | 2568 | let _ = self.update_window_title(event.window); |
| 2536 | if self.layout.name() == "tabbed" { | 2569 | if self.layout.name() == "tabbed" { |
| 2537 | self.update_tab_bars()?; | 2570 | self.update_tab_bars()?; |
| 2538 | } | 2571 | } |
| 2539 | - } else if event.atom == self.atoms.wm_normal_hints { | 2572 | + } |
| 2540 | - let _ = self.update_size_hints(event.window); | 2573 | + |
| 2574 | + if event.atom == self.atoms.net_wm_window_type { | ||
| 2575 | + self.update_window_type(event.window)?; | ||
| 2541 | } | 2576 | } |
| 2542 | } | 2577 | } |
| 2543 | Event::EnterNotify(event) => { | 2578 | Event::EnterNotify(event) => { |
| @@ -2842,6 +2877,10 @@ impl WindowManager { | |||
| 2842 | } | 2877 | } |
| 2843 | } | 2878 | } |
| 2844 | Event::ClientMessage(event) => { | 2879 | Event::ClientMessage(event) => { |
| 2880 | + if !self.clients.contains_key(&event.window) { | ||
| 2881 | + return Ok(None); | ||
| 2882 | + } | ||
| 2883 | + | ||
| 2845 | if event.type_ == self.atoms.net_wm_state { | 2884 | if event.type_ == self.atoms.net_wm_state { |
| 2846 | if let Some(data) = event.data.as_data32().get(1) { | 2885 | if let Some(data) = event.data.as_data32().get(1) { |
| 2847 | if *data == self.atoms.net_wm_state_fullscreen { | 2886 | if *data == self.atoms.net_wm_state_fullscreen { |
| @@ -2855,6 +2894,46 @@ impl WindowManager { | |||
| 2855 | self.set_window_fullscreen(event.window, fullscreen)?; | 2894 | self.set_window_fullscreen(event.window, fullscreen)?; |
| 2856 | } | 2895 | } |
| 2857 | } | 2896 | } |
| 2897 | + } else if event.type_ == self.atoms.net_active_window { | ||
| 2898 | + let selected_window = self.monitors | ||
| 2899 | + .get(self.selected_monitor) | ||
| 2900 | + .and_then(|m| m.selected_client); | ||
| 2901 | + | ||
| 2902 | + let is_urgent = self.clients | ||
| 2903 | + .get(&event.window) | ||
| 2904 | + .map(|c| c.is_urgent) | ||
| 2905 | + .unwrap_or(false); | ||
| 2906 | + | ||
| 2907 | + if Some(event.window) != selected_window && !is_urgent { | ||
| 2908 | + self.set_urgent(event.window, true)?; | ||
| 2909 | + } | ||
| 2910 | + } | ||
| 2911 | + } | ||
| 2912 | + Event::FocusIn(event) => { | ||
| 2913 | + let selected_window = self.monitors | ||
| 2914 | + .get(self.selected_monitor) | ||
| 2915 | + .and_then(|m| m.selected_client); | ||
| 2916 | + | ||
| 2917 | + if let Some(sel_win) = selected_window { | ||
| 2918 | + if event.event != sel_win { | ||
| 2919 | + self.set_focus(sel_win)?; | ||
| 2920 | + } | ||
| 2921 | + } | ||
| 2922 | + } | ||
| 2923 | + Event::MappingNotify(event) => { | ||
| 2924 | + if event.request == x11rb::protocol::xproto::Mapping::KEYBOARD { | ||
| 2925 | + keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; | ||
| 2926 | + } | ||
| 2927 | + } | ||
| 2928 | + Event::ConfigureNotify(event) => { | ||
| 2929 | + if event.window == self.root { | ||
| 2930 | + let old_width = self.screen.width_in_pixels; | ||
| 2931 | + let old_height = self.screen.height_in_pixels; | ||
| 2932 | + | ||
| 2933 | + if event.width != old_width || event.height != old_height { | ||
| 2934 | + self.screen = self.connection.setup().roots[self.screen_number].clone(); | ||
| 2935 | + self.apply_layout()?; | ||
| 2936 | + } | ||
| 2858 | } | 2937 | } |
| 2859 | } | 2938 | } |
| 2860 | _ => {} | 2939 | _ => {} |
| @@ -3236,6 +3315,90 @@ impl WindowManager { | |||
| 3236 | Ok(()) | 3315 | Ok(()) |
| 3237 | } | 3316 | } |
| 3238 | 3317 | ||
| 3318 | + fn update_wm_hints(&mut self, window: Window) -> WmResult<()> { | ||
| 3319 | + let hints_reply = self.connection.get_property( | ||
| 3320 | + false, | ||
| 3321 | + window, | ||
| 3322 | + AtomEnum::WM_HINTS, | ||
| 3323 | + AtomEnum::WM_HINTS, | ||
| 3324 | + 0, | ||
| 3325 | + 9, | ||
| 3326 | + )?.reply(); | ||
| 3327 | + | ||
| 3328 | + if let Ok(hints) = hints_reply { | ||
| 3329 | + if hints.value.len() >= 4 { | ||
| 3330 | + let flags = u32::from_ne_bytes([ | ||
| 3331 | + hints.value[0], | ||
| 3332 | + hints.value[1], | ||
| 3333 | + hints.value[2], | ||
| 3334 | + hints.value[3], | ||
| 3335 | + ]); | ||
| 3336 | + | ||
| 3337 | + let selected_window = self.monitors | ||
| 3338 | + .get(self.selected_monitor) | ||
| 3339 | + .and_then(|m| m.selected_client); | ||
| 3340 | + | ||
| 3341 | + if Some(window) == selected_window && (flags & 256) != 0 { | ||
| 3342 | + let new_flags = flags & !256; | ||
| 3343 | + let mut new_hints = hints.value.clone(); | ||
| 3344 | + new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes()); | ||
| 3345 | + | ||
| 3346 | + self.connection.change_property( | ||
| 3347 | + x11rb::protocol::xproto::PropMode::REPLACE, | ||
| 3348 | + window, | ||
| 3349 | + AtomEnum::WM_HINTS, | ||
| 3350 | + AtomEnum::WM_HINTS, | ||
| 3351 | + 32, | ||
| 3352 | + 9, | ||
| 3353 | + &new_hints, | ||
| 3354 | + )?; | ||
| 3355 | + } else { | ||
| 3356 | + if let Some(client) = self.clients.get_mut(&window) { | ||
| 3357 | + client.is_urgent = (flags & 256) != 0; | ||
| 3358 | + } | ||
| 3359 | + } | ||
| 3360 | + | ||
| 3361 | + if hints.value.len() >= 8 && (flags & 1) != 0 { | ||
| 3362 | + let input = i32::from_ne_bytes([ | ||
| 3363 | + hints.value[4], | ||
| 3364 | + hints.value[5], | ||
| 3365 | + hints.value[6], | ||
| 3366 | + hints.value[7], | ||
| 3367 | + ]); | ||
| 3368 | + | ||
| 3369 | + if let Some(client) = self.clients.get_mut(&window) { | ||
| 3370 | + client.never_focus = input == 0; | ||
| 3371 | + } | ||
| 3372 | + } else { | ||
| 3373 | + if let Some(client) = self.clients.get_mut(&window) { | ||
| 3374 | + client.never_focus = false; | ||
| 3375 | + } | ||
| 3376 | + } | ||
| 3377 | + } | ||
| 3378 | + } | ||
| 3379 | + | ||
| 3380 | + Ok(()) | ||
| 3381 | + } | ||
| 3382 | + | ||
| 3383 | + fn update_window_type(&mut self, window: Window) -> WmResult<()> { | ||
| 3384 | + if let Ok(Some(state_atom)) = self.get_atom_prop(window, self.atoms.net_wm_state) { | ||
| 3385 | + if state_atom == self.atoms.net_wm_state_fullscreen { | ||
| 3386 | + self.set_window_fullscreen(window, true)?; | ||
| 3387 | + } | ||
| 3388 | + } | ||
| 3389 | + | ||
| 3390 | + if let Ok(Some(type_atom)) = self.get_atom_prop(window, self.atoms.net_wm_window_type) { | ||
| 3391 | + if type_atom == self.atoms.net_wm_window_type_dialog { | ||
| 3392 | + if let Some(client) = self.clients.get_mut(&window) { | ||
| 3393 | + client.is_floating = true; | ||
| 3394 | + } | ||
| 3395 | + self.floating_windows.insert(window); | ||
| 3396 | + } | ||
| 3397 | + } | ||
| 3398 | + | ||
| 3399 | + Ok(()) | ||
| 3400 | + } | ||
| 3401 | + | ||
| 3239 | fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) { | 3402 | fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) { |
| 3240 | if !client.hints_valid { | 3403 | if !client.hints_valid { |
| 3241 | return (width.max(1), height.max(1)); | 3404 | return (width.max(1), height.max(1)); |