|
|
@@ -1,5 +1,6 @@ |
| 1 |
1 |
use crate::Config; |
| 2 |
2 |
use crate::bar::Bar; |
|
3 |
+use crate::client::{Client, TagMask}; |
| 3 |
4 |
use crate::errors::WmError; |
| 4 |
5 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
| 5 |
6 |
use crate::layout::GapConfig; |
|
|
@@ -7,7 +8,7 @@ use crate::layout::tiling::TilingLayout; |
| 7 |
8 |
use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}; |
| 8 |
9 |
use crate::monitor::{Monitor, detect_monitors}; |
| 9 |
10 |
use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; |
| 10 |
|
-use std::collections::HashSet; |
|
11 |
+use std::collections::{HashMap, HashSet}; |
| 11 |
12 |
use std::process::Command; |
| 12 |
13 |
use x11rb::cursor::Handle as CursorHandle; |
| 13 |
14 |
|
|
|
@@ -16,11 +17,6 @@ use x11rb::protocol::Event; |
| 16 |
17 |
use x11rb::protocol::xproto::*; |
| 17 |
18 |
use x11rb::rust_connection::RustConnection; |
| 18 |
19 |
|
| 19 |
|
-const DEFAULT_FLOAT_WIDTH_RATIO: f32 = 0.5; |
| 20 |
|
-const DEFAULT_FLOAT_HEIGHT_RATIO: f32 = 0.5; |
| 21 |
|
-const SMART_MOVE_STEP_RATIO_VERTICAL: i32 = 4; |
| 22 |
|
-const SMART_MOVE_STEP_RATIO_HORIZONTAL: i32 = 6; |
| 23 |
|
- |
| 24 |
20 |
#[derive(Debug, Clone, Copy)] |
| 25 |
21 |
pub struct CachedGeometry { |
| 26 |
22 |
pub x_position: i16, |
|
|
@@ -30,7 +26,6 @@ pub struct CachedGeometry { |
| 30 |
26 |
pub border_width: u16, |
| 31 |
27 |
} |
| 32 |
28 |
|
| 33 |
|
-pub type TagMask = u32; |
| 34 |
29 |
pub fn tag_mask(tag: usize) -> TagMask { |
| 35 |
30 |
1 << tag |
| 36 |
31 |
} |
|
|
@@ -43,6 +38,15 @@ struct AtomCache { |
| 43 |
38 |
wm_delete_window: Atom, |
| 44 |
39 |
net_wm_state: Atom, |
| 45 |
40 |
net_wm_state_fullscreen: Atom, |
|
41 |
+ net_wm_window_type: Atom, |
|
42 |
+ net_wm_window_type_dialog: Atom, |
|
43 |
+ wm_name: Atom, |
|
44 |
+ net_wm_name: Atom, |
|
45 |
+ utf8_string: Atom, |
|
46 |
+ wm_normal_hints: Atom, |
|
47 |
+ wm_hints: Atom, |
|
48 |
+ wm_transient_for: Atom, |
|
49 |
+ net_active_window: Atom, |
| 46 |
50 |
} |
| 47 |
51 |
|
| 48 |
52 |
impl AtomCache { |
|
|
@@ -79,6 +83,24 @@ impl AtomCache { |
| 79 |
83 |
.reply()? |
| 80 |
84 |
.atom; |
| 81 |
85 |
|
|
86 |
+ let net_wm_window_type = connection |
|
87 |
+ .intern_atom(false, b"_NET_WM_WINDOW_TYPE")? |
|
88 |
+ .reply()? |
|
89 |
+ .atom; |
|
90 |
+ |
|
91 |
+ let net_wm_window_type_dialog = connection |
|
92 |
+ .intern_atom(false, b"_NET_WM_WINDOW_TYPE_DIALOG")? |
|
93 |
+ .reply()? |
|
94 |
+ .atom; |
|
95 |
+ |
|
96 |
+ let wm_name = AtomEnum::WM_NAME.into(); |
|
97 |
+ let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom; |
|
98 |
+ let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom; |
|
99 |
+ let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into(); |
|
100 |
+ let wm_hints = AtomEnum::WM_HINTS.into(); |
|
101 |
+ let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into(); |
|
102 |
+ let net_active_window = connection.intern_atom(false, b"_NET_ACTIVE_WINDOW")?.reply()?.atom; |
|
103 |
+ |
| 82 |
104 |
Ok(Self { |
| 83 |
105 |
net_current_desktop, |
| 84 |
106 |
net_client_info, |
|
|
@@ -87,6 +109,15 @@ impl AtomCache { |
| 87 |
109 |
wm_delete_window, |
| 88 |
110 |
net_wm_state, |
| 89 |
111 |
net_wm_state_fullscreen, |
|
112 |
+ net_wm_window_type, |
|
113 |
+ net_wm_window_type_dialog, |
|
114 |
+ wm_name, |
|
115 |
+ net_wm_name, |
|
116 |
+ utf8_string, |
|
117 |
+ wm_normal_hints, |
|
118 |
+ wm_hints, |
|
119 |
+ wm_transient_for, |
|
120 |
+ net_active_window, |
| 90 |
121 |
}) |
| 91 |
122 |
} |
| 92 |
123 |
} |
|
|
@@ -98,14 +129,13 @@ pub struct WindowManager { |
| 98 |
129 |
root: Window, |
| 99 |
130 |
screen: Screen, |
| 100 |
131 |
windows: Vec<Window>, |
|
132 |
+ clients: HashMap<Window, Client>, |
| 101 |
133 |
layout: LayoutBox, |
| 102 |
|
- window_tags: std::collections::HashMap<Window, TagMask>, |
| 103 |
|
- window_monitor: std::collections::HashMap<Window, usize>, |
| 104 |
|
- window_geometry_cache: std::collections::HashMap<Window, CachedGeometry>, |
|
134 |
+ window_geometry_cache: HashMap<Window, CachedGeometry>, |
| 105 |
135 |
gaps_enabled: bool, |
| 106 |
136 |
floating_windows: HashSet<Window>, |
| 107 |
137 |
fullscreen_windows: HashSet<Window>, |
| 108 |
|
- floating_geometry_before_fullscreen: std::collections::HashMap<Window, (i16, i16, u16, u16, u16)>, |
|
138 |
+ floating_geometry_before_fullscreen: HashMap<Window, (i16, i16, u16, u16, u16)>, |
| 109 |
139 |
bars: Vec<Bar>, |
| 110 |
140 |
tab_bars: Vec<crate::tab_bar::TabBar>, |
| 111 |
141 |
show_bar: bool, |
|
|
@@ -154,29 +184,40 @@ impl WindowManager { |
| 154 |
184 |
)? |
| 155 |
185 |
.check()?; |
| 156 |
186 |
|
| 157 |
|
- connection.grab_button( |
| 158 |
|
- false, |
| 159 |
|
- root, |
| 160 |
|
- EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
| 161 |
|
- GrabMode::SYNC, |
| 162 |
|
- GrabMode::ASYNC, |
| 163 |
|
- x11rb::NONE, |
| 164 |
|
- x11rb::NONE, |
| 165 |
|
- ButtonIndex::M1, |
| 166 |
|
- u16::from(config.modkey).into(), |
| 167 |
|
- )?; |
|
187 |
+ let ignore_modifiers = [ |
|
188 |
+ 0, |
|
189 |
+ u16::from(ModMask::LOCK), |
|
190 |
+ u16::from(ModMask::M2), |
|
191 |
+ u16::from(ModMask::LOCK | ModMask::M2), |
|
192 |
+ ]; |
| 168 |
193 |
|
| 169 |
|
- connection.grab_button( |
| 170 |
|
- false, |
| 171 |
|
- root, |
| 172 |
|
- EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
| 173 |
|
- GrabMode::SYNC, |
| 174 |
|
- GrabMode::ASYNC, |
| 175 |
|
- x11rb::NONE, |
| 176 |
|
- x11rb::NONE, |
| 177 |
|
- ButtonIndex::M3, |
| 178 |
|
- u16::from(config.modkey).into(), |
| 179 |
|
- )?; |
|
194 |
+ for &ignore_mask in &ignore_modifiers { |
|
195 |
+ let grab_mask = u16::from(config.modkey) | ignore_mask; |
|
196 |
+ |
|
197 |
+ connection.grab_button( |
|
198 |
+ false, |
|
199 |
+ root, |
|
200 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
201 |
+ GrabMode::SYNC, |
|
202 |
+ GrabMode::ASYNC, |
|
203 |
+ x11rb::NONE, |
|
204 |
+ x11rb::NONE, |
|
205 |
+ ButtonIndex::M1, |
|
206 |
+ grab_mask.into(), |
|
207 |
+ )?; |
|
208 |
+ |
|
209 |
+ connection.grab_button( |
|
210 |
+ false, |
|
211 |
+ root, |
|
212 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
213 |
+ GrabMode::SYNC, |
|
214 |
+ GrabMode::ASYNC, |
|
215 |
+ x11rb::NONE, |
|
216 |
+ x11rb::NONE, |
|
217 |
+ ButtonIndex::M3, |
|
218 |
+ grab_mask.into(), |
|
219 |
+ )?; |
|
220 |
+ } |
| 180 |
221 |
|
| 181 |
222 |
let monitors = detect_monitors(&connection, &screen, root)?; |
| 182 |
223 |
|
|
|
@@ -196,9 +237,9 @@ impl WindowManager { |
| 196 |
237 |
&config, |
| 197 |
238 |
display, |
| 198 |
239 |
&font, |
| 199 |
|
- monitor.x as i16, |
| 200 |
|
- monitor.y as i16, |
| 201 |
|
- monitor.width as u16, |
|
240 |
+ monitor.screen_x as i16, |
|
241 |
+ monitor.screen_y as i16, |
|
242 |
+ monitor.screen_width as u16, |
| 202 |
243 |
)?; |
| 203 |
244 |
bars.push(bar); |
| 204 |
245 |
} |
|
|
@@ -212,9 +253,9 @@ impl WindowManager { |
| 212 |
253 |
screen_number, |
| 213 |
254 |
display, |
| 214 |
255 |
&font, |
| 215 |
|
- (monitor.x + config.gap_outer_horizontal as i32) as i16, |
| 216 |
|
- (monitor.y as f32 + bar_height + config.gap_outer_vertical as f32) as i16, |
| 217 |
|
- monitor.width.saturating_sub(2 * config.gap_outer_horizontal) as u16, |
|
256 |
+ (monitor.screen_x + config.gap_outer_horizontal as i32) as i16, |
|
257 |
+ (monitor.screen_y as f32 + bar_height + config.gap_outer_vertical as f32) as i16, |
|
258 |
+ monitor.screen_width.saturating_sub(2 * config.gap_outer_horizontal as i32) as u16, |
| 218 |
259 |
config.scheme_occupied, |
| 219 |
260 |
config.scheme_selected, |
| 220 |
261 |
)?; |
|
|
@@ -244,14 +285,13 @@ impl WindowManager { |
| 244 |
285 |
root, |
| 245 |
286 |
screen, |
| 246 |
287 |
windows: Vec::new(), |
|
288 |
+ clients: HashMap::new(), |
| 247 |
289 |
layout: Box::new(TilingLayout), |
| 248 |
|
- window_tags: std::collections::HashMap::new(), |
| 249 |
|
- window_monitor: std::collections::HashMap::new(), |
| 250 |
|
- window_geometry_cache: std::collections::HashMap::new(), |
|
290 |
+ window_geometry_cache: HashMap::new(), |
| 251 |
291 |
gaps_enabled, |
| 252 |
292 |
floating_windows: HashSet::new(), |
| 253 |
293 |
fullscreen_windows: HashSet::new(), |
| 254 |
|
- floating_geometry_before_fullscreen: std::collections::HashMap::new(), |
|
294 |
+ floating_geometry_before_fullscreen: HashMap::new(), |
| 255 |
295 |
bars, |
| 256 |
296 |
tab_bars, |
| 257 |
297 |
show_bar: true, |
|
|
@@ -280,18 +320,27 @@ impl WindowManager { |
| 280 |
320 |
} |
| 281 |
321 |
|
| 282 |
322 |
pub fn show_migration_overlay(&mut self) { |
| 283 |
|
- let message = "Your config.lua uses legacy syntax or has errors.\n\n\ |
| 284 |
|
- You are now running with default configuration.\n\n\ |
| 285 |
|
- Press Mod+Shift+/ to see default keybinds\n\ |
|
323 |
+ let message = "We are on version 0.8.0 now.\n\n\ |
|
324 |
+ Your config file has been deprecated once again.\n\ |
|
325 |
+ Backup your current config, and run oxwm --init to generate a new one with correct values.\n\n\ |
|
326 |
+ Please reach out to Tony, or check out the\n\ |
|
327 |
+ documentation for help with migration.\n\n\ |
|
328 |
+ We appreciate you testing oxwm!\n\n\ |
|
329 |
+ Press Mod+Shift+/ to see keybinds\n\ |
| 286 |
330 |
Press Mod+Shift+R to reload after fixing your config"; |
| 287 |
331 |
|
| 288 |
|
- let screen_width = self.screen.width_in_pixels; |
| 289 |
|
- let screen_height = self.screen.height_in_pixels; |
|
332 |
+ let monitor = &self.monitors[self.selected_monitor]; |
|
333 |
+ let monitor_x = monitor.screen_x as i16; |
|
334 |
+ let monitor_y = monitor.screen_y as i16; |
|
335 |
+ let screen_width = monitor.screen_width as u16; |
|
336 |
+ let screen_height = monitor.screen_height as u16; |
| 290 |
337 |
|
| 291 |
338 |
if let Err(e) = self.overlay.show_error( |
| 292 |
339 |
&self.connection, |
| 293 |
340 |
&self.font, |
| 294 |
341 |
message, |
|
342 |
+ monitor_x, |
|
343 |
+ monitor_y, |
| 295 |
344 |
screen_width, |
| 296 |
345 |
screen_height, |
| 297 |
346 |
) { |
|
|
@@ -349,10 +398,8 @@ impl WindowManager { |
| 349 |
398 |
} |
| 350 |
399 |
|
| 351 |
400 |
if attrs.map_state == MapState::VIEWABLE { |
| 352 |
|
- let tag = self.get_saved_tag(window, net_client_info)?; |
|
401 |
+ let _tag = self.get_saved_tag(window, net_client_info)?; |
| 353 |
402 |
self.windows.push(window); |
| 354 |
|
- self.window_tags.insert(window, tag); |
| 355 |
|
- self.window_monitor.insert(window, self.selected_monitor); |
| 356 |
403 |
continue; |
| 357 |
404 |
} |
| 358 |
405 |
|
|
|
@@ -374,17 +421,15 @@ impl WindowManager { |
| 374 |
421 |
.is_ok_and(|prop| !prop.value.is_empty()); |
| 375 |
422 |
|
| 376 |
423 |
if has_wm_class { |
| 377 |
|
- let tag = self.get_saved_tag(window, net_client_info)?; |
|
424 |
+ let _tag = self.get_saved_tag(window, net_client_info)?; |
| 378 |
425 |
self.connection.map_window(window)?; |
| 379 |
426 |
self.windows.push(window); |
| 380 |
|
- self.window_tags.insert(window, tag); |
| 381 |
|
- self.window_monitor.insert(window, self.selected_monitor); |
| 382 |
427 |
} |
| 383 |
428 |
} |
| 384 |
429 |
} |
| 385 |
430 |
|
| 386 |
431 |
if let Some(&first) = self.windows.first() { |
| 387 |
|
- self.set_focus(first)?; |
|
432 |
+ self.focus(Some(first))?; |
| 388 |
433 |
} |
| 389 |
434 |
|
| 390 |
435 |
self.apply_layout()?; |
|
|
@@ -418,7 +463,7 @@ impl WindowManager { |
| 418 |
463 |
Ok(self |
| 419 |
464 |
.monitors |
| 420 |
465 |
.get(self.selected_monitor) |
| 421 |
|
- .map(|m| m.selected_tags) |
|
466 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 422 |
467 |
.unwrap_or(tag_mask(0))) |
| 423 |
468 |
} |
| 424 |
469 |
|
|
|
@@ -496,350 +541,71 @@ impl WindowManager { |
| 496 |
541 |
} |
| 497 |
542 |
|
| 498 |
543 |
fn toggle_floating(&mut self) -> WmResult<()> { |
| 499 |
|
- if let Some(focused) = self |
|
544 |
+ let focused = self |
| 500 |
545 |
.monitors |
| 501 |
546 |
.get(self.selected_monitor) |
| 502 |
|
- .and_then(|m| m.focused_window) |
| 503 |
|
- { |
| 504 |
|
- if self.floating_windows.contains(&focused) { |
| 505 |
|
- self.floating_windows.remove(&focused); |
| 506 |
|
- |
| 507 |
|
- let selected_tags = self |
| 508 |
|
- .monitors |
| 509 |
|
- .get(self.selected_monitor) |
| 510 |
|
- .map(|m| m.selected_tags) |
| 511 |
|
- .unwrap_or(tag_mask(0)); |
| 512 |
|
- |
| 513 |
|
- self.window_tags.insert(focused, selected_tags); |
| 514 |
|
- self.window_monitor.insert(focused, self.selected_monitor); |
| 515 |
|
- if let Err(error) = self.save_client_tag(focused, selected_tags) { |
| 516 |
|
- eprintln!("Failed to save client tag: {:?}", error); |
| 517 |
|
- } |
| 518 |
|
- |
| 519 |
|
- self.apply_layout()?; |
| 520 |
|
- } else { |
| 521 |
|
- let float_width = (self.screen.width_in_pixels / 2) as u32; |
| 522 |
|
- let float_height = (self.screen.height_in_pixels / 2) as u32; |
|
547 |
+ .and_then(|m| m.selected_client); |
| 523 |
548 |
|
| 524 |
|
- let border_width = self.config.border_width; |
| 525 |
|
- |
| 526 |
|
- let center_width = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32; |
| 527 |
|
- let center_height = |
| 528 |
|
- ((self.screen.height_in_pixels - float_height as u16) / 2) as i32; |
| 529 |
|
- |
| 530 |
|
- self.connection.configure_window( |
| 531 |
|
- focused, |
| 532 |
|
- &ConfigureWindowAux::new() |
| 533 |
|
- .x(center_width) |
| 534 |
|
- .y(center_height) |
| 535 |
|
- .width(float_width) |
| 536 |
|
- .height(float_height) |
| 537 |
|
- .border_width(border_width) |
| 538 |
|
- .stack_mode(StackMode::ABOVE), |
| 539 |
|
- )?; |
|
549 |
+ if focused.is_none() { |
|
550 |
+ return Ok(()); |
|
551 |
+ } |
|
552 |
+ let focused = focused.unwrap(); |
| 540 |
553 |
|
| 541 |
|
- self.floating_windows.insert(focused); |
| 542 |
|
- self.apply_layout()?; |
| 543 |
|
- self.connection.flush()?; |
|
554 |
+ if let Some(client) = self.clients.get(&focused) { |
|
555 |
+ if client.is_fullscreen { |
|
556 |
+ return Ok(()); |
| 544 |
557 |
} |
| 545 |
558 |
} |
| 546 |
|
- Ok(()) |
| 547 |
|
- } |
| 548 |
|
- |
| 549 |
|
- fn collect_visible_floating_geometries(&mut self) -> Vec<(Window, CachedGeometry)> { |
| 550 |
|
- let focused_window = self.monitors.get(self.selected_monitor) |
| 551 |
|
- .and_then(|monitor| monitor.focused_window) |
| 552 |
|
- .unwrap_or(0); |
| 553 |
|
- let selected_monitor_index = self.selected_monitor; |
| 554 |
|
- |
| 555 |
|
- let candidate_windows: Vec<Window> = self.windows.iter() |
| 556 |
|
- .filter(|&&window| { |
| 557 |
|
- window != focused_window |
| 558 |
|
- && self.floating_windows.contains(&window) |
| 559 |
|
- && self.is_window_visible(window) |
| 560 |
|
- && self.window_monitor.get(&window).copied().unwrap_or(0) == selected_monitor_index |
| 561 |
|
- }) |
| 562 |
|
- .copied() |
| 563 |
|
- .collect(); |
| 564 |
|
- |
| 565 |
|
- candidate_windows.into_iter() |
| 566 |
|
- .filter_map(|window| { |
| 567 |
|
- self.get_or_query_geometry(window).ok().map(|geometry| (window, geometry)) |
| 568 |
|
- }) |
| 569 |
|
- .collect() |
| 570 |
|
- } |
| 571 |
559 |
|
| 572 |
|
- fn calculate_smart_move_position( |
| 573 |
|
- &self, |
| 574 |
|
- current_x: i32, |
| 575 |
|
- current_y: i32, |
| 576 |
|
- current_width: i32, |
| 577 |
|
- current_height: i32, |
| 578 |
|
- direction: i32, |
| 579 |
|
- monitor: &Monitor, |
| 580 |
|
- other_geometries: &[(Window, CachedGeometry)], |
| 581 |
|
- ) -> (i32, i32) { |
| 582 |
|
- let (gap_inner_horizontal, gap_inner_vertical, gap_outer_horizontal, gap_outer_vertical) = if self.gaps_enabled { |
| 583 |
|
- ( |
| 584 |
|
- self.config.gap_inner_horizontal as i32, |
| 585 |
|
- self.config.gap_inner_vertical as i32, |
| 586 |
|
- self.config.gap_outer_horizontal as i32, |
| 587 |
|
- self.config.gap_outer_vertical as i32, |
| 588 |
|
- ) |
|
560 |
+ let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) { |
|
561 |
+ (client.is_fixed, client.x_position as i32, client.y_position as i32, client.width as u32, client.height as u32) |
| 589 |
562 |
} else { |
| 590 |
|
- (0, 0, 0, 0) |
|
563 |
+ return Ok(()); |
| 591 |
564 |
}; |
| 592 |
565 |
|
| 593 |
|
- match direction { |
| 594 |
|
- 0 => { |
| 595 |
|
- let mut target_position = i32::MIN; |
| 596 |
|
- let current_top = current_y; |
| 597 |
|
- let mut new_y_position = current_y - (monitor.height as i32 / SMART_MOVE_STEP_RATIO_VERTICAL); |
| 598 |
|
- |
| 599 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 600 |
|
- let other_x = other_geometry.x_position as i32; |
| 601 |
|
- let other_y = other_geometry.y_position as i32; |
| 602 |
|
- let other_width = other_geometry.width as i32; |
| 603 |
|
- let other_height = other_geometry.height as i32; |
| 604 |
|
- |
| 605 |
|
- if current_x + current_width < other_x || current_x > other_x + other_width { |
| 606 |
|
- continue; |
| 607 |
|
- } |
| 608 |
|
- |
| 609 |
|
- let other_bottom = other_y + other_height + gap_inner_vertical; |
| 610 |
|
- if current_top > other_bottom && new_y_position < other_bottom { |
| 611 |
|
- target_position = target_position.max(other_bottom); |
| 612 |
|
- } |
| 613 |
|
- } |
| 614 |
|
- |
| 615 |
|
- if target_position != i32::MIN { |
| 616 |
|
- new_y_position = target_position; |
| 617 |
|
- } |
| 618 |
|
- new_y_position = new_y_position.max(monitor.y as i32 + gap_outer_vertical); |
| 619 |
|
- (current_x, new_y_position) |
| 620 |
|
- } |
| 621 |
|
- 1 => { |
| 622 |
|
- let mut target_position = i32::MAX; |
| 623 |
|
- let current_bottom = current_y + current_height; |
| 624 |
|
- let mut new_y_position = current_y + (monitor.height as i32 / SMART_MOVE_STEP_RATIO_VERTICAL); |
| 625 |
|
- |
| 626 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 627 |
|
- let other_x = other_geometry.x_position as i32; |
| 628 |
|
- let other_y = other_geometry.y_position as i32; |
| 629 |
|
- let other_width = other_geometry.width as i32; |
| 630 |
|
- |
| 631 |
|
- if current_x + current_width < other_x || current_x > other_x + other_width { |
| 632 |
|
- continue; |
| 633 |
|
- } |
| 634 |
|
- |
| 635 |
|
- let other_top = other_y - gap_inner_vertical; |
| 636 |
|
- if current_bottom < other_top && (new_y_position + current_height) > other_top { |
| 637 |
|
- target_position = target_position.min(other_top - current_height); |
| 638 |
|
- } |
| 639 |
|
- } |
| 640 |
|
- |
| 641 |
|
- if target_position != i32::MAX { |
| 642 |
|
- new_y_position = target_position; |
| 643 |
|
- } |
| 644 |
|
- new_y_position = new_y_position.min(monitor.y as i32 + monitor.height as i32 - current_height - gap_outer_vertical); |
| 645 |
|
- (current_x, new_y_position) |
| 646 |
|
- } |
| 647 |
|
- 2 => { |
| 648 |
|
- let mut target_position = i32::MIN; |
| 649 |
|
- let current_left = current_x; |
| 650 |
|
- let mut new_x_position = current_x - (monitor.width as i32 / SMART_MOVE_STEP_RATIO_HORIZONTAL); |
|
566 |
+ let was_floating = self.floating_windows.contains(&focused); |
| 651 |
567 |
|
| 652 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 653 |
|
- let other_x = other_geometry.x_position as i32; |
| 654 |
|
- let other_y = other_geometry.y_position as i32; |
| 655 |
|
- let other_width = other_geometry.width as i32; |
| 656 |
|
- let other_height = other_geometry.height as i32; |
| 657 |
|
- |
| 658 |
|
- if current_y + current_height < other_y || current_y > other_y + other_height { |
| 659 |
|
- continue; |
| 660 |
|
- } |
| 661 |
|
- |
| 662 |
|
- let other_right = other_x + other_width + gap_inner_horizontal; |
| 663 |
|
- if current_left > other_right && new_x_position < other_right { |
| 664 |
|
- target_position = target_position.max(other_right); |
| 665 |
|
- } |
| 666 |
|
- } |
| 667 |
|
- |
| 668 |
|
- if target_position != i32::MIN { |
| 669 |
|
- new_x_position = target_position; |
| 670 |
|
- } |
| 671 |
|
- new_x_position = new_x_position.max(monitor.x as i32 + gap_outer_horizontal); |
| 672 |
|
- (new_x_position, current_y) |
|
568 |
+ if was_floating { |
|
569 |
+ self.floating_windows.remove(&focused); |
|
570 |
+ if let Some(client) = self.clients.get_mut(&focused) { |
|
571 |
+ client.is_floating = false; |
| 673 |
572 |
} |
| 674 |
|
- 3 => { |
| 675 |
|
- let mut target_position = i32::MAX; |
| 676 |
|
- let current_right = current_x + current_width; |
| 677 |
|
- let mut new_x_position = current_x + (monitor.width as i32 / SMART_MOVE_STEP_RATIO_HORIZONTAL); |
| 678 |
|
- |
| 679 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 680 |
|
- let other_x = other_geometry.x_position as i32; |
| 681 |
|
- let other_y = other_geometry.y_position as i32; |
| 682 |
|
- let other_height = other_geometry.height as i32; |
| 683 |
|
- |
| 684 |
|
- if current_y + current_height < other_y || current_y > other_y + other_height { |
| 685 |
|
- continue; |
| 686 |
|
- } |
| 687 |
|
- |
| 688 |
|
- let other_left = other_x - gap_inner_horizontal; |
| 689 |
|
- if current_right < other_left && (new_x_position + current_width) > other_left { |
| 690 |
|
- target_position = target_position.min(other_left - current_width); |
| 691 |
|
- } |
| 692 |
|
- } |
| 693 |
|
- |
| 694 |
|
- if target_position != i32::MAX { |
| 695 |
|
- new_x_position = target_position; |
| 696 |
|
- } |
| 697 |
|
- new_x_position = new_x_position.min(monitor.x as i32 + monitor.width as i32 - current_width - gap_outer_horizontal); |
| 698 |
|
- (new_x_position, current_y) |
|
573 |
+ } else { |
|
574 |
+ self.floating_windows.insert(focused); |
|
575 |
+ if let Some(client) = self.clients.get_mut(&focused) { |
|
576 |
+ client.is_floating = is_fixed || !client.is_floating; |
| 699 |
577 |
} |
| 700 |
|
- _ => (current_x, current_y), |
| 701 |
|
- } |
| 702 |
|
- } |
| 703 |
|
- |
| 704 |
|
- fn smart_move_window(&mut self, direction: i32) -> WmResult<()> { |
| 705 |
|
- let focused = match self |
| 706 |
|
- .monitors |
| 707 |
|
- .get(self.selected_monitor) |
| 708 |
|
- .and_then(|monitor| monitor.focused_window) |
| 709 |
|
- { |
| 710 |
|
- Some(window) => window, |
| 711 |
|
- None => return Ok(()), |
| 712 |
|
- }; |
| 713 |
|
- |
| 714 |
|
- if !self.floating_windows.contains(&focused) { |
| 715 |
|
- let float_width = (self.screen.width_in_pixels as f32 * DEFAULT_FLOAT_WIDTH_RATIO) as u32; |
| 716 |
|
- let float_height = (self.screen.height_in_pixels as f32 * DEFAULT_FLOAT_HEIGHT_RATIO) as u32; |
| 717 |
|
- let border_width = self.config.border_width; |
| 718 |
|
- let center_x_position = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32; |
| 719 |
|
- let center_y_position = ((self.screen.height_in_pixels - float_height as u16) / 2) as i32; |
| 720 |
578 |
|
| 721 |
579 |
self.connection.configure_window( |
| 722 |
580 |
focused, |
| 723 |
581 |
&ConfigureWindowAux::new() |
| 724 |
|
- .x(center_x_position) |
| 725 |
|
- .y(center_y_position) |
| 726 |
|
- .width(float_width) |
| 727 |
|
- .height(float_height) |
| 728 |
|
- .border_width(border_width) |
|
582 |
+ .x(x) |
|
583 |
+ .y(y) |
|
584 |
+ .width(w) |
|
585 |
+ .height(h) |
| 729 |
586 |
.stack_mode(StackMode::ABOVE), |
| 730 |
587 |
)?; |
| 731 |
|
- self.floating_windows.insert(focused); |
| 732 |
588 |
} |
| 733 |
589 |
|
| 734 |
|
- let current_geometry = self.get_or_query_geometry(focused)?; |
| 735 |
|
- let current_x = current_geometry.x_position as i32; |
| 736 |
|
- let current_y = current_geometry.y_position as i32; |
| 737 |
|
- let current_width = current_geometry.width as i32; |
| 738 |
|
- let current_height = current_geometry.height as i32; |
| 739 |
|
- |
| 740 |
|
- let other_geometries = self.collect_visible_floating_geometries(); |
| 741 |
|
- |
| 742 |
|
- let monitor = match self.monitors.get(self.selected_monitor) { |
| 743 |
|
- Some(monitor) => monitor, |
| 744 |
|
- None => return Ok(()), |
| 745 |
|
- }; |
| 746 |
|
- |
| 747 |
|
- let (new_x_position, new_y_position) = self.calculate_smart_move_position( |
| 748 |
|
- current_x, |
| 749 |
|
- current_y, |
| 750 |
|
- current_width, |
| 751 |
|
- current_height, |
| 752 |
|
- direction, |
| 753 |
|
- monitor, |
| 754 |
|
- &other_geometries, |
| 755 |
|
- ); |
| 756 |
|
- |
| 757 |
|
- self.connection.configure_window( |
| 758 |
|
- focused, |
| 759 |
|
- &ConfigureWindowAux::new() |
| 760 |
|
- .x(new_x_position) |
| 761 |
|
- .y(new_y_position) |
| 762 |
|
- .stack_mode(StackMode::ABOVE), |
| 763 |
|
- )?; |
| 764 |
|
- |
| 765 |
|
- self.update_geometry_cache(focused, CachedGeometry { |
| 766 |
|
- x_position: new_x_position as i16, |
| 767 |
|
- y_position: new_y_position as i16, |
| 768 |
|
- width: current_width as u16, |
| 769 |
|
- height: current_height as u16, |
| 770 |
|
- border_width: current_geometry.border_width, |
| 771 |
|
- }); |
| 772 |
|
- |
| 773 |
|
- self.connection.flush()?; |
|
590 |
+ self.apply_layout()?; |
| 774 |
591 |
Ok(()) |
| 775 |
592 |
} |
| 776 |
593 |
|
| 777 |
|
- fn exchange_client(&mut self, direction: i32) -> WmResult<()> { |
| 778 |
|
- let focused = match self |
| 779 |
|
- .monitors |
| 780 |
|
- .get(self.selected_monitor) |
| 781 |
|
- .and_then(|m| m.focused_window) |
| 782 |
|
- { |
| 783 |
|
- Some(win) => win, |
| 784 |
|
- None => return Ok(()), |
| 785 |
|
- }; |
| 786 |
|
- |
| 787 |
|
- if self.floating_windows.contains(&focused) { |
| 788 |
|
- return Ok(()); |
| 789 |
|
- } |
| 790 |
|
- |
| 791 |
|
- let visible = self.visible_windows(); |
| 792 |
|
- if visible.len() < 2 { |
| 793 |
|
- return Ok(()); |
|
594 |
+ fn set_master_factor(&mut self, delta: f32) -> WmResult<()> { |
|
595 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
596 |
+ let new_mfact = (monitor.master_factor + delta).max(0.05).min(0.95); |
|
597 |
+ monitor.master_factor = new_mfact; |
|
598 |
+ self.apply_layout()?; |
| 794 |
599 |
} |
|
600 |
+ Ok(()) |
|
601 |
+ } |
| 795 |
602 |
|
| 796 |
|
- let current_idx = match visible.iter().position(|&w| w == focused) { |
| 797 |
|
- Some(idx) => idx, |
| 798 |
|
- None => return Ok(()), |
| 799 |
|
- }; |
| 800 |
|
- |
| 801 |
|
- let target_idx = match direction { |
| 802 |
|
- 0 | 2 => { |
| 803 |
|
- // UP or LEFT - previous in stack |
| 804 |
|
- if current_idx == 0 { |
| 805 |
|
- visible.len() - 1 |
| 806 |
|
- } else { |
| 807 |
|
- current_idx - 1 |
| 808 |
|
- } |
| 809 |
|
- } |
| 810 |
|
- 1 | 3 => { |
| 811 |
|
- // DOWN or RIGHT - next in stack |
| 812 |
|
- (current_idx + 1) % visible.len() |
| 813 |
|
- } |
| 814 |
|
- _ => return Ok(()), |
| 815 |
|
- }; |
| 816 |
|
- |
| 817 |
|
- let target = visible[target_idx]; |
| 818 |
|
- |
| 819 |
|
- let focused_pos = self.windows.iter().position(|&w| w == focused); |
| 820 |
|
- let target_pos = self.windows.iter().position(|&w| w == target); |
| 821 |
|
- |
| 822 |
|
- if let (Some(f_pos), Some(t_pos)) = (focused_pos, target_pos) { |
| 823 |
|
- self.windows.swap(f_pos, t_pos); |
| 824 |
|
- |
|
603 |
+ fn inc_num_master(&mut self, delta: i32) -> WmResult<()> { |
|
604 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
605 |
+ let new_nmaster = (monitor.num_master + delta).max(0); |
|
606 |
+ monitor.num_master = new_nmaster; |
| 825 |
607 |
self.apply_layout()?; |
| 826 |
|
- |
| 827 |
|
- self.set_focus(focused)?; |
| 828 |
|
- |
| 829 |
|
- if let Ok(geometry) = self.connection.get_geometry(focused)?.reply() { |
| 830 |
|
- self.connection.warp_pointer( |
| 831 |
|
- x11rb::NONE, |
| 832 |
|
- focused, |
| 833 |
|
- 0, |
| 834 |
|
- 0, |
| 835 |
|
- 0, |
| 836 |
|
- 0, |
| 837 |
|
- geometry.width as i16 / 2, |
| 838 |
|
- geometry.height as i16 / 2, |
| 839 |
|
- )?; |
| 840 |
|
- } |
| 841 |
608 |
} |
| 842 |
|
- |
| 843 |
609 |
Ok(()) |
| 844 |
610 |
} |
| 845 |
611 |
|
|
|
@@ -905,9 +671,9 @@ impl WindowManager { |
| 905 |
671 |
for (monitor_index, monitor) in self.monitors.iter().enumerate() { |
| 906 |
672 |
if let Some(bar) = self.bars.get_mut(monitor_index) { |
| 907 |
673 |
let mut occupied_tags: TagMask = 0; |
| 908 |
|
- for (&window, &tags) in &self.window_tags { |
| 909 |
|
- if self.window_monitor.get(&window).copied().unwrap_or(0) == monitor_index { |
| 910 |
|
- occupied_tags |= tags; |
|
674 |
+ for client in self.clients.values() { |
|
675 |
+ if client.monitor_index == monitor_index { |
|
676 |
+ occupied_tags |= client.tags; |
| 911 |
677 |
} |
| 912 |
678 |
} |
| 913 |
679 |
|
|
|
@@ -917,7 +683,7 @@ impl WindowManager { |
| 917 |
683 |
&self.connection, |
| 918 |
684 |
&self.font, |
| 919 |
685 |
self.display, |
| 920 |
|
- monitor.selected_tags, |
|
686 |
+ monitor.tagset[monitor.selected_tags_index], |
| 921 |
687 |
occupied_tags, |
| 922 |
688 |
draw_blocks, |
| 923 |
689 |
&layout_symbol, |
|
|
@@ -931,27 +697,26 @@ impl WindowManager { |
| 931 |
697 |
fn update_tab_bars(&mut self) -> WmResult<()> { |
| 932 |
698 |
for (monitor_index, monitor) in self.monitors.iter().enumerate() { |
| 933 |
699 |
if let Some(tab_bar) = self.tab_bars.get_mut(monitor_index) { |
| 934 |
|
- let visible_windows: Vec<Window> = self |
|
700 |
+ let visible_windows: Vec<(Window, String)> = self |
| 935 |
701 |
.windows |
| 936 |
702 |
.iter() |
| 937 |
|
- .filter(|&&window| { |
| 938 |
|
- let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); |
| 939 |
|
- if window_monitor_index != monitor_index |
| 940 |
|
- || self.floating_windows.contains(&window) |
| 941 |
|
- || self.fullscreen_windows.contains(&window) |
| 942 |
|
- { |
| 943 |
|
- return false; |
| 944 |
|
- } |
| 945 |
|
- if let Some(&tags) = self.window_tags.get(&window) { |
| 946 |
|
- (tags & monitor.selected_tags) != 0 |
| 947 |
|
- } else { |
| 948 |
|
- false |
|
703 |
+ .filter_map(|&window| { |
|
704 |
+ if let Some(client) = self.clients.get(&window) { |
|
705 |
+ if client.monitor_index != monitor_index |
|
706 |
+ || self.floating_windows.contains(&window) |
|
707 |
+ || self.fullscreen_windows.contains(&window) |
|
708 |
+ { |
|
709 |
+ return None; |
|
710 |
+ } |
|
711 |
+ if (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0 { |
|
712 |
+ return Some((window, client.name.clone())); |
|
713 |
+ } |
| 949 |
714 |
} |
|
715 |
+ None |
| 950 |
716 |
}) |
| 951 |
|
- .copied() |
| 952 |
717 |
.collect(); |
| 953 |
718 |
|
| 954 |
|
- let focused_window = monitor.focused_window; |
|
719 |
+ let focused_window = monitor.selected_client; |
| 955 |
720 |
|
| 956 |
721 |
tab_bar.draw( |
| 957 |
722 |
&self.connection, |
|
|
@@ -966,7 +731,7 @@ impl WindowManager { |
| 966 |
731 |
|
| 967 |
732 |
fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { |
| 968 |
733 |
match action { |
| 969 |
|
- KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
|
734 |
+ KeyAction::Spawn => handlers::handle_spawn_action(action, arg, self.selected_monitor)?, |
| 970 |
735 |
KeyAction::SpawnTerminal => { |
| 971 |
736 |
use std::process::Command; |
| 972 |
737 |
let terminal = &self.config.terminal; |
|
|
@@ -978,13 +743,14 @@ impl WindowManager { |
| 978 |
743 |
if let Some(focused) = self |
| 979 |
744 |
.monitors |
| 980 |
745 |
.get(self.selected_monitor) |
| 981 |
|
- .and_then(|m| m.focused_window) |
|
746 |
+ .and_then(|m| m.selected_client) |
| 982 |
747 |
{ |
| 983 |
748 |
self.kill_client(focused)?; |
| 984 |
749 |
} |
| 985 |
750 |
} |
| 986 |
751 |
KeyAction::ToggleFullScreen => { |
| 987 |
752 |
self.fullscreen()?; |
|
753 |
+ self.restack()?; |
| 988 |
754 |
} |
| 989 |
755 |
KeyAction::ChangeLayout => { |
| 990 |
756 |
if let Arg::Str(layout_name) = arg { |
|
|
@@ -996,6 +762,7 @@ impl WindowManager { |
| 996 |
762 |
} |
| 997 |
763 |
self.apply_layout()?; |
| 998 |
764 |
self.update_bar()?; |
|
765 |
+ self.restack()?; |
| 999 |
766 |
} |
| 1000 |
767 |
Err(e) => eprintln!("Failed to change layout: {}", e), |
| 1001 |
768 |
} |
|
|
@@ -1012,39 +779,24 @@ impl WindowManager { |
| 1012 |
779 |
} |
| 1013 |
780 |
self.apply_layout()?; |
| 1014 |
781 |
self.update_bar()?; |
|
782 |
+ self.restack()?; |
| 1015 |
783 |
} |
| 1016 |
784 |
Err(e) => eprintln!("Failed to cycle layout: {}", e), |
| 1017 |
785 |
} |
| 1018 |
786 |
} |
| 1019 |
787 |
KeyAction::ToggleFloating => { |
| 1020 |
788 |
self.toggle_floating()?; |
| 1021 |
|
- } |
| 1022 |
|
- |
| 1023 |
|
- KeyAction::SmartMoveWin => { |
| 1024 |
|
- if let Arg::Int(direction) = arg { |
| 1025 |
|
- self.smart_move_window(*direction)?; |
| 1026 |
|
- } |
| 1027 |
|
- } |
| 1028 |
|
- |
| 1029 |
|
- KeyAction::ExchangeClient => { |
| 1030 |
|
- if let Arg::Int(direction) = arg { |
| 1031 |
|
- self.exchange_client(*direction)?; |
| 1032 |
|
- } |
|
789 |
+ self.restack()?; |
| 1033 |
790 |
} |
| 1034 |
791 |
|
| 1035 |
792 |
KeyAction::FocusStack => { |
| 1036 |
793 |
if let Arg::Int(direction) = arg { |
| 1037 |
|
- self.cycle_focus(*direction)?; |
| 1038 |
|
- } |
| 1039 |
|
- } |
| 1040 |
|
- KeyAction::FocusDirection => { |
| 1041 |
|
- if let Arg::Int(direction) = arg { |
| 1042 |
|
- self.focus_direction(*direction)?; |
|
794 |
+ self.focusstack(*direction)?; |
| 1043 |
795 |
} |
| 1044 |
796 |
} |
| 1045 |
|
- KeyAction::SwapDirection => { |
|
797 |
+ KeyAction::MoveStack => { |
| 1046 |
798 |
if let Arg::Int(direction) = arg { |
| 1047 |
|
- self.swap_direction(*direction)?; |
|
799 |
+ self.move_stack(*direction)?; |
| 1048 |
800 |
} |
| 1049 |
801 |
} |
| 1050 |
802 |
KeyAction::Quit | KeyAction::Restart => { |
|
|
@@ -1064,100 +816,108 @@ impl WindowManager { |
| 1064 |
816 |
self.view_tag(*tag_index as usize)?; |
| 1065 |
817 |
} |
| 1066 |
818 |
} |
|
819 |
+ KeyAction::ToggleView => { |
|
820 |
+ if let Arg::Int(tag_index) = arg { |
|
821 |
+ self.toggleview(*tag_index as usize)?; |
|
822 |
+ } |
|
823 |
+ } |
| 1067 |
824 |
KeyAction::MoveToTag => { |
| 1068 |
825 |
if let Arg::Int(tag_index) = arg { |
| 1069 |
826 |
self.move_to_tag(*tag_index as usize)?; |
| 1070 |
827 |
} |
| 1071 |
828 |
} |
|
829 |
+ KeyAction::ToggleTag => { |
|
830 |
+ if let Arg::Int(tag_index) = arg { |
|
831 |
+ self.toggletag(*tag_index as usize)?; |
|
832 |
+ } |
|
833 |
+ } |
| 1072 |
834 |
KeyAction::ToggleGaps => { |
| 1073 |
835 |
self.gaps_enabled = !self.gaps_enabled; |
| 1074 |
836 |
self.apply_layout()?; |
|
837 |
+ self.restack()?; |
| 1075 |
838 |
} |
| 1076 |
839 |
KeyAction::FocusMonitor => { |
| 1077 |
840 |
if let Arg::Int(direction) = arg { |
| 1078 |
841 |
self.focus_monitor(*direction)?; |
| 1079 |
842 |
} |
| 1080 |
843 |
} |
|
844 |
+ KeyAction::TagMonitor => { |
|
845 |
+ if let Arg::Int(direction) = arg { |
|
846 |
+ self.send_window_to_adjacent_monitor(*direction)?; |
|
847 |
+ } |
|
848 |
+ } |
| 1081 |
849 |
KeyAction::ShowKeybindOverlay => { |
| 1082 |
850 |
let monitor = &self.monitors[self.selected_monitor]; |
| 1083 |
851 |
self.keybind_overlay.toggle( |
| 1084 |
852 |
&self.connection, |
| 1085 |
853 |
&self.font, |
| 1086 |
854 |
&self.config.keybindings, |
| 1087 |
|
- monitor.width as u16, |
| 1088 |
|
- monitor.height as u16, |
|
855 |
+ monitor.screen_width as u16, |
|
856 |
+ monitor.screen_height as u16, |
| 1089 |
857 |
)?; |
| 1090 |
858 |
} |
|
859 |
+ KeyAction::SetMasterFactor => { |
|
860 |
+ if let Arg::Int(delta) = arg { |
|
861 |
+ self.set_master_factor(*delta as f32 / 100.0)?; |
|
862 |
+ } |
|
863 |
+ } |
|
864 |
+ KeyAction::IncNumMaster => { |
|
865 |
+ if let Arg::Int(delta) = arg { |
|
866 |
+ self.inc_num_master(*delta)?; |
|
867 |
+ } |
|
868 |
+ } |
| 1091 |
869 |
KeyAction::None => {} |
| 1092 |
870 |
} |
| 1093 |
871 |
Ok(()) |
| 1094 |
872 |
} |
| 1095 |
873 |
|
| 1096 |
|
- fn focus_monitor(&mut self, direction: i32) -> WmResult<()> { |
| 1097 |
|
- if self.monitors.is_empty() { |
| 1098 |
|
- return Ok(()); |
| 1099 |
|
- } |
| 1100 |
|
- |
| 1101 |
|
- let new_monitor = if direction > 0 { |
| 1102 |
|
- (self.selected_monitor + 1) % self.monitors.len() |
| 1103 |
|
- } else { |
| 1104 |
|
- (self.selected_monitor + self.monitors.len() - 1) % self.monitors.len() |
| 1105 |
|
- }; |
| 1106 |
|
- |
| 1107 |
|
- if new_monitor == self.selected_monitor { |
| 1108 |
|
- return Ok(()); |
| 1109 |
|
- } |
| 1110 |
|
- |
| 1111 |
|
- self.selected_monitor = new_monitor; |
| 1112 |
|
- |
| 1113 |
|
- self.update_bar()?; |
| 1114 |
|
- |
| 1115 |
|
- let visible = self.visible_windows_on_monitor(new_monitor); |
| 1116 |
|
- if let Some(&win) = visible.first() { |
| 1117 |
|
- self.set_focus(win)?; |
| 1118 |
|
- } |
| 1119 |
|
- |
| 1120 |
|
- Ok(()) |
| 1121 |
|
- } |
| 1122 |
874 |
|
| 1123 |
875 |
fn is_window_visible(&self, window: Window) -> bool { |
| 1124 |
|
- let window_mon = self.window_monitor.get(&window).copied().unwrap_or(0); |
| 1125 |
|
- |
| 1126 |
|
- if let Some(&tags) = self.window_tags.get(&window) { |
| 1127 |
|
- let monitor = self.monitors.get(window_mon); |
| 1128 |
|
- let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0); |
| 1129 |
|
- (tags & selected_tags) != 0 |
|
876 |
+ if let Some(client) = self.clients.get(&window) { |
|
877 |
+ let monitor = self.monitors.get(client.monitor_index); |
|
878 |
+ let selected_tags = monitor.map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); |
|
879 |
+ (client.tags & selected_tags) != 0 |
| 1130 |
880 |
} else { |
| 1131 |
881 |
false |
| 1132 |
882 |
} |
| 1133 |
883 |
} |
| 1134 |
884 |
|
| 1135 |
885 |
fn visible_windows(&self) -> Vec<Window> { |
| 1136 |
|
- self.windows |
| 1137 |
|
- .iter() |
| 1138 |
|
- .filter(|&&w| self.is_window_visible(w)) |
| 1139 |
|
- .copied() |
| 1140 |
|
- .collect() |
|
886 |
+ let mut result = Vec::new(); |
|
887 |
+ for monitor in &self.monitors { |
|
888 |
+ let mut current = monitor.clients_head; |
|
889 |
+ while let Some(window) = current { |
|
890 |
+ if let Some(client) = self.clients.get(&window) { |
|
891 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
892 |
+ if visible_tags != 0 { |
|
893 |
+ result.push(window); |
|
894 |
+ } |
|
895 |
+ current = client.next; |
|
896 |
+ } else { |
|
897 |
+ break; |
|
898 |
+ } |
|
899 |
+ } |
|
900 |
+ } |
|
901 |
+ result |
| 1141 |
902 |
} |
| 1142 |
903 |
|
| 1143 |
904 |
fn visible_windows_on_monitor(&self, monitor_index: usize) -> Vec<Window> { |
| 1144 |
|
- self.windows |
| 1145 |
|
- .iter() |
| 1146 |
|
- .filter(|&&w| { |
| 1147 |
|
- let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0); |
| 1148 |
|
- if window_mon != monitor_index { |
| 1149 |
|
- return false; |
| 1150 |
|
- } |
| 1151 |
|
- if let Some(&tags) = self.window_tags.get(&w) { |
| 1152 |
|
- let monitor = self.monitors.get(monitor_index); |
| 1153 |
|
- let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0); |
| 1154 |
|
- (tags & selected_tags) != 0 |
|
905 |
+ let mut result = Vec::new(); |
|
906 |
+ if let Some(monitor) = self.monitors.get(monitor_index) { |
|
907 |
+ let mut current = monitor.clients_head; |
|
908 |
+ while let Some(window) = current { |
|
909 |
+ if let Some(client) = self.clients.get(&window) { |
|
910 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
911 |
+ if visible_tags != 0 { |
|
912 |
+ result.push(window); |
|
913 |
+ } |
|
914 |
+ current = client.next; |
| 1155 |
915 |
} else { |
| 1156 |
|
- false |
|
916 |
+ break; |
| 1157 |
917 |
} |
| 1158 |
|
- }) |
| 1159 |
|
- .copied() |
| 1160 |
|
- .collect() |
|
918 |
+ } |
|
919 |
+ } |
|
920 |
+ result |
| 1161 |
921 |
} |
| 1162 |
922 |
|
| 1163 |
923 |
fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<usize> { |
|
|
@@ -1166,53 +926,203 @@ impl WindowManager { |
| 1166 |
926 |
.position(|mon| mon.contains_point(x, y)) |
| 1167 |
927 |
} |
| 1168 |
928 |
|
| 1169 |
|
- // Dwm's g-loaded approach to handling the spam alternating crash. |
| 1170 |
|
- fn update_window_visibility(&self) -> WmResult<()> { |
| 1171 |
|
- for &window in &self.windows { |
| 1172 |
|
- if !self.is_window_visible(window) { |
| 1173 |
|
- if let Ok(geom) = self.connection.get_geometry(window)?.reply() { |
| 1174 |
|
- self.connection.configure_window( |
| 1175 |
|
- window, |
| 1176 |
|
- &ConfigureWindowAux::new() |
| 1177 |
|
- .x(-(geom.width as i32 * 2)) |
| 1178 |
|
- .y(geom.y as i32), |
| 1179 |
|
- )?; |
| 1180 |
|
- } |
|
929 |
+ fn get_monitor_for_rect(&self, x: i32, y: i32, w: i32, h: i32) -> usize { |
|
930 |
+ let mut best_monitor = self.selected_monitor; |
|
931 |
+ let mut max_area = 0; |
|
932 |
+ |
|
933 |
+ for (idx, monitor) in self.monitors.iter().enumerate() { |
|
934 |
+ let intersect_width = 0.max((x + w).min(monitor.window_area_x + monitor.window_area_width) - x.max(monitor.window_area_x)); |
|
935 |
+ let intersect_height = 0.max((y + h).min(monitor.window_area_y + monitor.window_area_height) - y.max(monitor.window_area_y)); |
|
936 |
+ let area = intersect_width * intersect_height; |
|
937 |
+ |
|
938 |
+ if area > max_area { |
|
939 |
+ max_area = area; |
|
940 |
+ best_monitor = idx; |
| 1181 |
941 |
} |
| 1182 |
942 |
} |
| 1183 |
|
- self.connection.flush()?; |
| 1184 |
|
- Ok(()) |
|
943 |
+ |
|
944 |
+ best_monitor |
| 1185 |
945 |
} |
| 1186 |
946 |
|
| 1187 |
|
- pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 1188 |
|
- if tag_index >= self.config.tags.len() { |
| 1189 |
|
- return Ok(()); |
| 1190 |
|
- } |
|
947 |
+ fn move_window_to_monitor(&mut self, window: Window, target_monitor_index: usize) -> WmResult<()> { |
|
948 |
+ let current_monitor_index = self.clients |
|
949 |
+ .get(&window) |
|
950 |
+ .map(|c| c.monitor_index); |
| 1191 |
951 |
|
| 1192 |
|
- if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 1193 |
|
- monitor.selected_tags = tag_mask(tag_index); |
|
952 |
+ if let Some(current_idx) = current_monitor_index { |
|
953 |
+ if current_idx == target_monitor_index { |
|
954 |
+ return Ok(()); |
|
955 |
+ } |
| 1194 |
956 |
} |
| 1195 |
957 |
|
| 1196 |
|
- self.save_selected_tags()?; |
| 1197 |
|
- self.update_window_visibility()?; |
| 1198 |
|
- self.apply_layout()?; |
| 1199 |
|
- self.update_bar()?; |
|
958 |
+ self.unfocus(window)?; |
|
959 |
+ self.detach(window); |
|
960 |
+ self.detach_stack(window); |
| 1200 |
961 |
|
| 1201 |
|
- let visible = self.visible_windows_on_monitor(self.selected_monitor); |
| 1202 |
|
- if let Some(&win) = visible.first() { |
| 1203 |
|
- self.set_focus(win)?; |
|
962 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
963 |
+ client.monitor_index = target_monitor_index; |
|
964 |
+ if let Some(target_monitor) = self.monitors.get(target_monitor_index) { |
|
965 |
+ client.tags = target_monitor.tagset[target_monitor.selected_tags_index]; |
|
966 |
+ } |
| 1204 |
967 |
} |
| 1205 |
968 |
|
|
969 |
+ self.attach_aside(window, target_monitor_index); |
|
970 |
+ self.attach_stack(window, target_monitor_index); |
|
971 |
+ |
|
972 |
+ self.focus(None)?; |
|
973 |
+ self.apply_layout()?; |
|
974 |
+ |
| 1206 |
975 |
Ok(()) |
| 1207 |
976 |
} |
| 1208 |
977 |
|
| 1209 |
|
- fn save_selected_tags(&self) -> WmResult<()> { |
| 1210 |
|
- let net_current_desktop = self.atoms.net_current_desktop; |
|
978 |
+ fn get_adjacent_monitor(&self, direction: i32) -> Option<usize> { |
|
979 |
+ if self.monitors.len() <= 1 { |
|
980 |
+ return None; |
|
981 |
+ } |
|
982 |
+ |
|
983 |
+ if direction > 0 { |
|
984 |
+ if self.selected_monitor + 1 < self.monitors.len() { |
|
985 |
+ Some(self.selected_monitor + 1) |
|
986 |
+ } else { |
|
987 |
+ Some(0) |
|
988 |
+ } |
|
989 |
+ } else { |
|
990 |
+ if self.selected_monitor == 0 { |
|
991 |
+ Some(self.monitors.len() - 1) |
|
992 |
+ } else { |
|
993 |
+ Some(self.selected_monitor - 1) |
|
994 |
+ } |
|
995 |
+ } |
|
996 |
+ } |
|
997 |
+ |
|
998 |
+ fn is_visible(&self, window: Window) -> bool { |
|
999 |
+ let Some(client) = self.clients.get(&window) else { |
|
1000 |
+ return false; |
|
1001 |
+ }; |
|
1002 |
+ |
|
1003 |
+ let Some(monitor) = self.monitors.get(client.monitor_index) else { |
|
1004 |
+ return false; |
|
1005 |
+ }; |
|
1006 |
+ |
|
1007 |
+ (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0 |
|
1008 |
+ } |
|
1009 |
+ |
|
1010 |
+ fn showhide(&mut self, window: Option<Window>) -> WmResult<()> { |
|
1011 |
+ let Some(window) = window else { |
|
1012 |
+ return Ok(()); |
|
1013 |
+ }; |
|
1014 |
+ |
|
1015 |
+ let Some(client) = self.clients.get(&window).cloned() else { |
|
1016 |
+ return Ok(()); |
|
1017 |
+ }; |
|
1018 |
+ |
|
1019 |
+ let monitor = match self.monitors.get(client.monitor_index) { |
|
1020 |
+ Some(m) => m, |
|
1021 |
+ None => return Ok(()), |
|
1022 |
+ }; |
|
1023 |
+ |
|
1024 |
+ let is_visible = (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0; |
|
1025 |
+ |
|
1026 |
+ if is_visible { |
|
1027 |
+ self.connection.configure_window( |
|
1028 |
+ window, |
|
1029 |
+ &ConfigureWindowAux::new() |
|
1030 |
+ .x(client.x_position as i32) |
|
1031 |
+ .y(client.y_position as i32), |
|
1032 |
+ )?; |
|
1033 |
+ |
|
1034 |
+ let is_floating = client.is_floating; |
|
1035 |
+ let is_fullscreen = client.is_fullscreen; |
|
1036 |
+ let has_no_layout = self.layout.name() == LayoutType::Normie.as_str(); |
|
1037 |
+ |
|
1038 |
+ if (has_no_layout || is_floating) && !is_fullscreen { |
|
1039 |
+ self.connection.configure_window( |
|
1040 |
+ window, |
|
1041 |
+ &ConfigureWindowAux::new() |
|
1042 |
+ .x(client.x_position as i32) |
|
1043 |
+ .y(client.y_position as i32) |
|
1044 |
+ .width(client.width as u32) |
|
1045 |
+ .height(client.height as u32), |
|
1046 |
+ )?; |
|
1047 |
+ } |
|
1048 |
+ |
|
1049 |
+ self.showhide(client.stack_next)?; |
|
1050 |
+ } else { |
|
1051 |
+ self.showhide(client.stack_next)?; |
|
1052 |
+ |
|
1053 |
+ let width = client.width_with_border() as i32; |
|
1054 |
+ self.connection.configure_window( |
|
1055 |
+ window, |
|
1056 |
+ &ConfigureWindowAux::new() |
|
1057 |
+ .x(width * -2) |
|
1058 |
+ .y(client.y_position as i32), |
|
1059 |
+ )?; |
|
1060 |
+ } |
|
1061 |
+ |
|
1062 |
+ Ok(()) |
|
1063 |
+ } |
|
1064 |
+ |
|
1065 |
+ pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> { |
|
1066 |
+ if tag_index >= self.config.tags.len() { |
|
1067 |
+ return Ok(()); |
|
1068 |
+ } |
|
1069 |
+ |
|
1070 |
+ let monitor = match self.monitors.get_mut(self.selected_monitor) { |
|
1071 |
+ Some(m) => m, |
|
1072 |
+ None => return Ok(()), |
|
1073 |
+ }; |
|
1074 |
+ |
|
1075 |
+ let new_tagset = tag_mask(tag_index); |
|
1076 |
+ |
|
1077 |
+ if new_tagset == monitor.tagset[monitor.selected_tags_index] { |
|
1078 |
+ return Ok(()); |
|
1079 |
+ } |
|
1080 |
+ |
|
1081 |
+ monitor.selected_tags_index ^= 1; |
|
1082 |
+ monitor.tagset[monitor.selected_tags_index] = new_tagset; |
|
1083 |
+ |
|
1084 |
+ self.save_selected_tags()?; |
|
1085 |
+ self.focus(None)?; |
|
1086 |
+ self.apply_layout()?; |
|
1087 |
+ self.update_bar()?; |
|
1088 |
+ |
|
1089 |
+ Ok(()) |
|
1090 |
+ } |
|
1091 |
+ |
|
1092 |
+ pub fn toggleview(&mut self, tag_index: usize) -> WmResult<()> { |
|
1093 |
+ if tag_index >= self.config.tags.len() { |
|
1094 |
+ return Ok(()); |
|
1095 |
+ } |
|
1096 |
+ |
|
1097 |
+ let monitor = match self.monitors.get_mut(self.selected_monitor) { |
|
1098 |
+ Some(m) => m, |
|
1099 |
+ None => return Ok(()), |
|
1100 |
+ }; |
|
1101 |
+ |
|
1102 |
+ let mask = tag_mask(tag_index); |
|
1103 |
+ let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask; |
|
1104 |
+ |
|
1105 |
+ if new_tagset == 0 { |
|
1106 |
+ return Ok(()); |
|
1107 |
+ } |
|
1108 |
+ |
|
1109 |
+ monitor.tagset[monitor.selected_tags_index] = new_tagset; |
|
1110 |
+ |
|
1111 |
+ self.save_selected_tags()?; |
|
1112 |
+ self.focus(None)?; |
|
1113 |
+ self.apply_layout()?; |
|
1114 |
+ self.update_bar()?; |
|
1115 |
+ |
|
1116 |
+ Ok(()) |
|
1117 |
+ } |
|
1118 |
+ |
|
1119 |
+ fn save_selected_tags(&self) -> WmResult<()> { |
|
1120 |
+ let net_current_desktop = self.atoms.net_current_desktop; |
| 1211 |
1121 |
|
| 1212 |
1122 |
let selected_tags = self |
| 1213 |
1123 |
.monitors |
| 1214 |
1124 |
.get(self.selected_monitor) |
| 1215 |
|
- .map(|m| m.selected_tags) |
|
1125 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 1216 |
1126 |
.unwrap_or(tag_mask(0)); |
| 1217 |
1127 |
let desktop = selected_tags.trailing_zeros(); |
| 1218 |
1128 |
|
|
|
@@ -1236,23 +1146,66 @@ impl WindowManager { |
| 1236 |
1146 |
return Ok(()); |
| 1237 |
1147 |
} |
| 1238 |
1148 |
|
| 1239 |
|
- if let Some(focused) = self |
|
1149 |
+ let focused = match self |
| 1240 |
1150 |
.monitors |
| 1241 |
1151 |
.get(self.selected_monitor) |
| 1242 |
|
- .and_then(|m| m.focused_window) |
|
1152 |
+ .and_then(|m| m.selected_client) |
| 1243 |
1153 |
{ |
| 1244 |
|
- let mask = tag_mask(tag_index); |
| 1245 |
|
- self.window_tags.insert(focused, mask); |
|
1154 |
+ Some(win) => win, |
|
1155 |
+ None => return Ok(()), |
|
1156 |
+ }; |
| 1246 |
1157 |
|
| 1247 |
|
- if let Err(error) = self.save_client_tag(focused, mask) { |
| 1248 |
|
- eprintln!("Failed to save client tag: {:?}", error); |
| 1249 |
|
- } |
|
1158 |
+ let mask = tag_mask(tag_index); |
| 1250 |
1159 |
|
| 1251 |
|
- self.update_window_visibility()?; |
| 1252 |
|
- self.apply_layout()?; |
| 1253 |
|
- self.update_bar()?; |
|
1160 |
+ if let Some(client) = self.clients.get_mut(&focused) { |
|
1161 |
+ client.tags = mask; |
|
1162 |
+ } |
|
1163 |
+ |
|
1164 |
+ if let Err(error) = self.save_client_tag(focused, mask) { |
|
1165 |
+ eprintln!("Failed to save client tag: {:?}", error); |
|
1166 |
+ } |
|
1167 |
+ |
|
1168 |
+ self.focus(None)?; |
|
1169 |
+ self.apply_layout()?; |
|
1170 |
+ self.update_bar()?; |
|
1171 |
+ |
|
1172 |
+ Ok(()) |
|
1173 |
+ } |
|
1174 |
+ |
|
1175 |
+ pub fn toggletag(&mut self, tag_index: usize) -> WmResult<()> { |
|
1176 |
+ if tag_index >= self.config.tags.len() { |
|
1177 |
+ return Ok(()); |
|
1178 |
+ } |
|
1179 |
+ |
|
1180 |
+ let focused = match self |
|
1181 |
+ .monitors |
|
1182 |
+ .get(self.selected_monitor) |
|
1183 |
+ .and_then(|m| m.selected_client) |
|
1184 |
+ { |
|
1185 |
+ Some(win) => win, |
|
1186 |
+ None => return Ok(()), |
|
1187 |
+ }; |
|
1188 |
+ |
|
1189 |
+ let mask = tag_mask(tag_index); |
|
1190 |
+ let current_tags = self.clients.get(&focused).map(|c| c.tags).unwrap_or(0); |
|
1191 |
+ let new_tags = current_tags ^ mask; |
|
1192 |
+ |
|
1193 |
+ if new_tags == 0 { |
|
1194 |
+ return Ok(()); |
|
1195 |
+ } |
|
1196 |
+ |
|
1197 |
+ if let Some(client) = self.clients.get_mut(&focused) { |
|
1198 |
+ client.tags = new_tags; |
|
1199 |
+ } |
|
1200 |
+ |
|
1201 |
+ if let Err(error) = self.save_client_tag(focused, new_tags) { |
|
1202 |
+ eprintln!("Failed to save client tag: {:?}", error); |
| 1254 |
1203 |
} |
| 1255 |
1204 |
|
|
1205 |
+ self.focus(None)?; |
|
1206 |
+ self.apply_layout()?; |
|
1207 |
+ self.update_bar()?; |
|
1208 |
+ |
| 1256 |
1209 |
Ok(()) |
| 1257 |
1210 |
} |
| 1258 |
1211 |
|
|
|
@@ -1266,7 +1219,7 @@ impl WindowManager { |
| 1266 |
1219 |
let current = self |
| 1267 |
1220 |
.monitors |
| 1268 |
1221 |
.get(self.selected_monitor) |
| 1269 |
|
- .and_then(|m| m.focused_window); |
|
1222 |
+ .and_then(|m| m.selected_client); |
| 1270 |
1223 |
|
| 1271 |
1224 |
let next_window = if let Some(current) = current { |
| 1272 |
1225 |
if let Some(current_index) = visible.iter().position(|&w| w == current) { |
|
|
@@ -1291,7 +1244,7 @@ impl WindowManager { |
| 1291 |
1244 |
)?; |
| 1292 |
1245 |
} |
| 1293 |
1246 |
|
| 1294 |
|
- self.set_focus(next_window)?; |
|
1247 |
+ self.focus(Some(next_window))?; |
| 1295 |
1248 |
|
| 1296 |
1249 |
if is_tabbed { |
| 1297 |
1250 |
self.update_tab_bars()?; |
|
|
@@ -1300,104 +1253,6 @@ impl WindowManager { |
| 1300 |
1253 |
Ok(()) |
| 1301 |
1254 |
} |
| 1302 |
1255 |
|
| 1303 |
|
- fn find_directional_window_candidate(&mut self, focused_window: Window, direction: i32) -> Option<Window> { |
| 1304 |
|
- let visible_windows = self.visible_windows(); |
| 1305 |
|
- if visible_windows.len() < 2 { |
| 1306 |
|
- return None; |
| 1307 |
|
- } |
| 1308 |
|
- |
| 1309 |
|
- let focused_geometry = self.get_or_query_geometry(focused_window).ok()?; |
| 1310 |
|
- let focused_center_x = focused_geometry.x_position + (focused_geometry.width as i16 / 2); |
| 1311 |
|
- let focused_center_y = focused_geometry.y_position + (focused_geometry.height as i16 / 2); |
| 1312 |
|
- |
| 1313 |
|
- let mut candidates = Vec::new(); |
| 1314 |
|
- |
| 1315 |
|
- for &window in &visible_windows { |
| 1316 |
|
- if window == focused_window { |
| 1317 |
|
- continue; |
| 1318 |
|
- } |
| 1319 |
|
- |
| 1320 |
|
- let geometry = match self.get_or_query_geometry(window) { |
| 1321 |
|
- Ok(geometry) => geometry, |
| 1322 |
|
- Err(_) => continue, |
| 1323 |
|
- }; |
| 1324 |
|
- |
| 1325 |
|
- let center_x = geometry.x_position + (geometry.width as i16 / 2); |
| 1326 |
|
- let center_y = geometry.y_position + (geometry.height as i16 / 2); |
| 1327 |
|
- |
| 1328 |
|
- let is_valid_direction = match direction { |
| 1329 |
|
- 0 => center_y < focused_center_y, |
| 1330 |
|
- 1 => center_y > focused_center_y, |
| 1331 |
|
- 2 => center_x < focused_center_x, |
| 1332 |
|
- 3 => center_x > focused_center_x, |
| 1333 |
|
- _ => false, |
| 1334 |
|
- }; |
| 1335 |
|
- |
| 1336 |
|
- if is_valid_direction { |
| 1337 |
|
- let delta_x = (center_x - focused_center_x) as i32; |
| 1338 |
|
- let delta_y = (center_y - focused_center_y) as i32; |
| 1339 |
|
- let distance_squared = delta_x * delta_x + delta_y * delta_y; |
| 1340 |
|
- candidates.push((window, distance_squared)); |
| 1341 |
|
- } |
| 1342 |
|
- } |
| 1343 |
|
- |
| 1344 |
|
- candidates.iter().min_by_key(|&(_window, distance)| distance).map(|&(window, _distance)| window) |
| 1345 |
|
- } |
| 1346 |
|
- |
| 1347 |
|
- pub fn focus_direction(&mut self, direction: i32) -> WmResult<()> { |
| 1348 |
|
- let focused_window = match self |
| 1349 |
|
- .monitors |
| 1350 |
|
- .get(self.selected_monitor) |
| 1351 |
|
- .and_then(|monitor| monitor.focused_window) |
| 1352 |
|
- { |
| 1353 |
|
- Some(window) => window, |
| 1354 |
|
- None => return Ok(()), |
| 1355 |
|
- }; |
| 1356 |
|
- |
| 1357 |
|
- if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) { |
| 1358 |
|
- self.set_focus(target_window)?; |
| 1359 |
|
- } |
| 1360 |
|
- |
| 1361 |
|
- Ok(()) |
| 1362 |
|
- } |
| 1363 |
|
- |
| 1364 |
|
- pub fn swap_direction(&mut self, direction: i32) -> WmResult<()> { |
| 1365 |
|
- let focused_window = match self |
| 1366 |
|
- .monitors |
| 1367 |
|
- .get(self.selected_monitor) |
| 1368 |
|
- .and_then(|monitor| monitor.focused_window) |
| 1369 |
|
- { |
| 1370 |
|
- Some(window) => window, |
| 1371 |
|
- None => return Ok(()), |
| 1372 |
|
- }; |
| 1373 |
|
- |
| 1374 |
|
- if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) { |
| 1375 |
|
- let focused_position = self.windows.iter().position(|&window| window == focused_window); |
| 1376 |
|
- let target_position = self.windows.iter().position(|&window| window == target_window); |
| 1377 |
|
- |
| 1378 |
|
- if let (Some(focused_index), Some(target_index)) = (focused_position, target_position) { |
| 1379 |
|
- self.windows.swap(focused_index, target_index); |
| 1380 |
|
- self.apply_layout()?; |
| 1381 |
|
- self.set_focus(focused_window)?; |
| 1382 |
|
- |
| 1383 |
|
- if let Ok(geometry) = self.get_or_query_geometry(focused_window) { |
| 1384 |
|
- self.connection.warp_pointer( |
| 1385 |
|
- x11rb::NONE, |
| 1386 |
|
- focused_window, |
| 1387 |
|
- 0, |
| 1388 |
|
- 0, |
| 1389 |
|
- 0, |
| 1390 |
|
- 0, |
| 1391 |
|
- geometry.width as i16 / 2, |
| 1392 |
|
- geometry.height as i16 / 2, |
| 1393 |
|
- )?; |
| 1394 |
|
- } |
| 1395 |
|
- } |
| 1396 |
|
- } |
| 1397 |
|
- |
| 1398 |
|
- Ok(()) |
| 1399 |
|
- } |
| 1400 |
|
- |
| 1401 |
1256 |
fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> { |
| 1402 |
1257 |
use std::collections::HashMap; |
| 1403 |
1258 |
use x11rb::protocol::xproto::Keycode; |
|
|
@@ -1431,6 +1286,13 @@ impl WindowManager { |
| 1431 |
1286 |
|
| 1432 |
1287 |
let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new(); |
| 1433 |
1288 |
|
|
1289 |
+ let ignore_modifiers = [ |
|
1290 |
+ 0, |
|
1291 |
+ u16::from(ModMask::LOCK), |
|
1292 |
+ u16::from(ModMask::M2), |
|
1293 |
+ u16::from(ModMask::LOCK | ModMask::M2), |
|
1294 |
+ ]; |
|
1295 |
+ |
| 1434 |
1296 |
for &candidate_index in candidates { |
| 1435 |
1297 |
let binding = &self.config.keybindings[candidate_index]; |
| 1436 |
1298 |
if keys_pressed < binding.keys.len() { |
|
|
@@ -1439,17 +1301,20 @@ impl WindowManager { |
| 1439 |
1301 |
|
| 1440 |
1302 |
if let Some(keycodes) = keysym_to_keycode.get(&next_key.keysym) { |
| 1441 |
1303 |
if let Some(&keycode) = keycodes.first() { |
| 1442 |
|
- let key_tuple = (modifier_mask, keycode); |
| 1443 |
|
- |
| 1444 |
|
- if grabbed_keys.insert(key_tuple) { |
| 1445 |
|
- self.connection.grab_key( |
| 1446 |
|
- false, |
| 1447 |
|
- self.root, |
| 1448 |
|
- modifier_mask.into(), |
| 1449 |
|
- keycode, |
| 1450 |
|
- GrabMode::ASYNC, |
| 1451 |
|
- GrabMode::ASYNC, |
| 1452 |
|
- )?; |
|
1304 |
+ for &ignore_mask in &ignore_modifiers { |
|
1305 |
+ let grab_mask = modifier_mask | ignore_mask; |
|
1306 |
+ let key_tuple = (grab_mask, keycode); |
|
1307 |
+ |
|
1308 |
+ if grabbed_keys.insert(key_tuple) { |
|
1309 |
+ self.connection.grab_key( |
|
1310 |
+ false, |
|
1311 |
+ self.root, |
|
1312 |
+ grab_mask.into(), |
|
1313 |
+ keycode, |
|
1314 |
+ GrabMode::ASYNC, |
|
1315 |
+ GrabMode::ASYNC, |
|
1316 |
+ )?; |
|
1317 |
+ } |
| 1453 |
1318 |
} |
| 1454 |
1319 |
} |
| 1455 |
1320 |
} |
|
|
@@ -1458,14 +1323,16 @@ impl WindowManager { |
| 1458 |
1323 |
|
| 1459 |
1324 |
if let Some(keycodes) = keysym_to_keycode.get(&keyboard::keysyms::XK_ESCAPE) { |
| 1460 |
1325 |
if let Some(&keycode) = keycodes.first() { |
| 1461 |
|
- self.connection.grab_key( |
| 1462 |
|
- false, |
| 1463 |
|
- self.root, |
| 1464 |
|
- ModMask::from(0u16), |
| 1465 |
|
- keycode, |
| 1466 |
|
- GrabMode::ASYNC, |
| 1467 |
|
- GrabMode::ASYNC, |
| 1468 |
|
- )?; |
|
1326 |
+ for &ignore_mask in &ignore_modifiers { |
|
1327 |
+ self.connection.grab_key( |
|
1328 |
+ false, |
|
1329 |
+ self.root, |
|
1330 |
+ ModMask::from(ignore_mask), |
|
1331 |
+ keycode, |
|
1332 |
+ GrabMode::ASYNC, |
|
1333 |
+ GrabMode::ASYNC, |
|
1334 |
+ )?; |
|
1335 |
+ } |
| 1469 |
1336 |
} |
| 1470 |
1337 |
} |
| 1471 |
1338 |
|
|
|
@@ -1482,12 +1349,9 @@ impl WindowManager { |
| 1482 |
1349 |
} |
| 1483 |
1350 |
|
| 1484 |
1351 |
fn kill_client(&self, window: Window) -> WmResult<()> { |
| 1485 |
|
- // Try to send WM_DELETE_WINDOW message first (graceful close) |
| 1486 |
1352 |
if self.send_event(window, self.atoms.wm_delete_window)? { |
| 1487 |
|
- // Window supports WM_DELETE_WINDOW, it will close gracefully |
| 1488 |
1353 |
self.connection.flush()?; |
| 1489 |
1354 |
} else { |
| 1490 |
|
- // Window doesn't support WM_DELETE_WINDOW, forcefully kill it |
| 1491 |
1355 |
eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window); |
| 1492 |
1356 |
self.connection.kill_client(window)?; |
| 1493 |
1357 |
self.connection.flush()?; |
|
|
@@ -1496,7 +1360,6 @@ impl WindowManager { |
| 1496 |
1360 |
} |
| 1497 |
1361 |
|
| 1498 |
1362 |
fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> { |
| 1499 |
|
- // Check if the window supports this protocol |
| 1500 |
1363 |
let protocols_reply = self.connection.get_property( |
| 1501 |
1364 |
false, |
| 1502 |
1365 |
window, |
|
|
@@ -1521,7 +1384,6 @@ impl WindowManager { |
| 1521 |
1384 |
return Ok(false); |
| 1522 |
1385 |
} |
| 1523 |
1386 |
|
| 1524 |
|
- // Send a ClientMessage event |
| 1525 |
1387 |
let event = x11rb::protocol::xproto::ClientMessageEvent { |
| 1526 |
1388 |
response_type: x11rb::protocol::xproto::CLIENT_MESSAGE_EVENT, |
| 1527 |
1389 |
format: 32, |
|
|
@@ -1541,6 +1403,120 @@ impl WindowManager { |
| 1541 |
1403 |
Ok(true) |
| 1542 |
1404 |
} |
| 1543 |
1405 |
|
|
1406 |
+ fn set_urgent(&mut self, window: Window, urgent: bool) -> WmResult<()> { |
|
1407 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1408 |
+ client.is_urgent = urgent; |
|
1409 |
+ } |
|
1410 |
+ |
|
1411 |
+ let hints_reply = self.connection.get_property( |
|
1412 |
+ false, |
|
1413 |
+ window, |
|
1414 |
+ AtomEnum::WM_HINTS, |
|
1415 |
+ AtomEnum::WM_HINTS, |
|
1416 |
+ 0, |
|
1417 |
+ 9, |
|
1418 |
+ )?.reply(); |
|
1419 |
+ |
|
1420 |
+ if let Ok(hints) = hints_reply { |
|
1421 |
+ if hints.value.len() >= 4 { |
|
1422 |
+ let mut flags = u32::from_ne_bytes([ |
|
1423 |
+ hints.value[0], |
|
1424 |
+ hints.value[1], |
|
1425 |
+ hints.value[2], |
|
1426 |
+ hints.value[3], |
|
1427 |
+ ]); |
|
1428 |
+ |
|
1429 |
+ if urgent { |
|
1430 |
+ flags |= 256; |
|
1431 |
+ } else { |
|
1432 |
+ flags &= !256; |
|
1433 |
+ } |
|
1434 |
+ |
|
1435 |
+ let mut new_hints = hints.value.clone(); |
|
1436 |
+ new_hints[0..4].copy_from_slice(&flags.to_ne_bytes()); |
|
1437 |
+ |
|
1438 |
+ self.connection.change_property( |
|
1439 |
+ PropMode::REPLACE, |
|
1440 |
+ window, |
|
1441 |
+ AtomEnum::WM_HINTS, |
|
1442 |
+ AtomEnum::WM_HINTS, |
|
1443 |
+ 32, |
|
1444 |
+ new_hints.len() as u32 / 4, |
|
1445 |
+ &new_hints, |
|
1446 |
+ )?; |
|
1447 |
+ } |
|
1448 |
+ } |
|
1449 |
+ |
|
1450 |
+ Ok(()) |
|
1451 |
+ } |
|
1452 |
+ |
|
1453 |
+ fn get_window_state(&self, window: Window) -> WmResult<i32> { |
|
1454 |
+ let reply = self.connection.get_property( |
|
1455 |
+ false, |
|
1456 |
+ window, |
|
1457 |
+ self.atoms.wm_state, |
|
1458 |
+ self.atoms.wm_state, |
|
1459 |
+ 0, |
|
1460 |
+ 2, |
|
1461 |
+ )?.reply(); |
|
1462 |
+ |
|
1463 |
+ match reply { |
|
1464 |
+ Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => { |
|
1465 |
+ let state = u32::from_ne_bytes([ |
|
1466 |
+ prop.value[0], |
|
1467 |
+ prop.value[1], |
|
1468 |
+ prop.value[2], |
|
1469 |
+ prop.value[3], |
|
1470 |
+ ]); |
|
1471 |
+ Ok(state as i32) |
|
1472 |
+ } |
|
1473 |
+ _ => Ok(-1), |
|
1474 |
+ } |
|
1475 |
+ } |
|
1476 |
+ |
|
1477 |
+ fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> { |
|
1478 |
+ let reply = self.connection.get_property( |
|
1479 |
+ false, |
|
1480 |
+ window, |
|
1481 |
+ property, |
|
1482 |
+ AtomEnum::ATOM, |
|
1483 |
+ 0, |
|
1484 |
+ 1, |
|
1485 |
+ )?.reply(); |
|
1486 |
+ |
|
1487 |
+ match reply { |
|
1488 |
+ Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => { |
|
1489 |
+ let atom = u32::from_ne_bytes([ |
|
1490 |
+ prop.value[0], |
|
1491 |
+ prop.value[1], |
|
1492 |
+ prop.value[2], |
|
1493 |
+ prop.value[3], |
|
1494 |
+ ]); |
|
1495 |
+ Ok(Some(atom)) |
|
1496 |
+ } |
|
1497 |
+ _ => Ok(None), |
|
1498 |
+ } |
|
1499 |
+ } |
|
1500 |
+ |
|
1501 |
+ fn get_window_text_property(&self, window: Window, atom: Atom) -> WmResult<Option<String>> { |
|
1502 |
+ let reply = self.connection.get_property( |
|
1503 |
+ false, |
|
1504 |
+ window, |
|
1505 |
+ atom, |
|
1506 |
+ AtomEnum::ANY, |
|
1507 |
+ 0, |
|
1508 |
+ 1024, |
|
1509 |
+ )?.reply(); |
|
1510 |
+ |
|
1511 |
+ match reply { |
|
1512 |
+ Ok(prop) if !prop.value.is_empty() => { |
|
1513 |
+ let text = String::from_utf8_lossy(&prop.value).to_string(); |
|
1514 |
+ Ok(Some(text.trim_end_matches('\0').to_string())) |
|
1515 |
+ } |
|
1516 |
+ _ => Ok(None), |
|
1517 |
+ } |
|
1518 |
+ } |
|
1519 |
+ |
| 1544 |
1520 |
fn fullscreen(&mut self) -> WmResult<()> { |
| 1545 |
1521 |
if self.show_bar { |
| 1546 |
1522 |
let windows: Vec<Window> = self.windows.iter() |
|
|
@@ -1571,7 +1547,9 @@ impl WindowManager { |
| 1571 |
1547 |
.collect(); |
| 1572 |
1548 |
|
| 1573 |
1549 |
for window in floating_windows { |
| 1574 |
|
- let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); |
|
1550 |
+ let monitor_idx = self.clients.get(&window) |
|
1551 |
+ .map(|c| c.monitor_index) |
|
1552 |
+ .unwrap_or(self.selected_monitor); |
| 1575 |
1553 |
let monitor = &self.monitors[monitor_idx]; |
| 1576 |
1554 |
|
| 1577 |
1555 |
let (outer_gap_h, outer_gap_v) = if self.gaps_enabled { |
|
|
@@ -1583,18 +1561,18 @@ impl WindowManager { |
| 1583 |
1561 |
(0, 0) |
| 1584 |
1562 |
}; |
| 1585 |
1563 |
|
| 1586 |
|
- let window_x = monitor.x + outer_gap_h as i32; |
| 1587 |
|
- let window_y = monitor.y + outer_gap_v as i32; |
| 1588 |
|
- let window_width = monitor.width.saturating_sub(2 * outer_gap_h).saturating_sub(2 * border_width); |
| 1589 |
|
- let window_height = monitor.height.saturating_sub(2 * outer_gap_v).saturating_sub(2 * border_width); |
|
1564 |
+ let window_x = monitor.screen_x + outer_gap_h as i32; |
|
1565 |
+ let window_y = monitor.screen_y + outer_gap_v as i32; |
|
1566 |
+ let window_width = monitor.screen_width.saturating_sub(2 * outer_gap_h as i32).saturating_sub(2 * border_width as i32); |
|
1567 |
+ let window_height = monitor.screen_height.saturating_sub(2 * outer_gap_v as i32).saturating_sub(2 * border_width as i32); |
| 1590 |
1568 |
|
| 1591 |
1569 |
self.connection.configure_window( |
| 1592 |
1570 |
window, |
| 1593 |
1571 |
&x11rb::protocol::xproto::ConfigureWindowAux::new() |
| 1594 |
1572 |
.x(window_x) |
| 1595 |
1573 |
.y(window_y) |
| 1596 |
|
- .width(window_width) |
| 1597 |
|
- .height(window_height), |
|
1574 |
+ .width(window_width as u32) |
|
1575 |
+ .height(window_height as u32), |
| 1598 |
1576 |
)?; |
| 1599 |
1577 |
} |
| 1600 |
1578 |
self.connection.flush()?; |
|
|
@@ -1654,6 +1632,11 @@ impl WindowManager { |
| 1654 |
1632 |
} |
| 1655 |
1633 |
|
| 1656 |
1634 |
fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> { |
|
1635 |
+ let monitor_idx = self.clients.get(&window) |
|
1636 |
+ .map(|c| c.monitor_index) |
|
1637 |
+ .unwrap_or(self.selected_monitor); |
|
1638 |
+ let monitor = &self.monitors[monitor_idx]; |
|
1639 |
+ |
| 1657 |
1640 |
if fullscreen && !self.fullscreen_windows.contains(&window) { |
| 1658 |
1641 |
let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec(); |
| 1659 |
1642 |
self.connection.change_property( |
|
|
@@ -1666,30 +1649,28 @@ impl WindowManager { |
| 1666 |
1649 |
&bytes, |
| 1667 |
1650 |
)?; |
| 1668 |
1651 |
|
| 1669 |
|
- self.fullscreen_windows.insert(window); |
| 1670 |
|
- |
| 1671 |
|
- let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); |
| 1672 |
|
- let monitor = &self.monitors[monitor_idx]; |
| 1673 |
|
- |
| 1674 |
|
- if self.show_bar { |
| 1675 |
|
- if let Some(bar) = self.bars.get(monitor_idx) { |
| 1676 |
|
- self.connection.unmap_window(bar.window())?; |
| 1677 |
|
- } |
|
1652 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1653 |
+ client.is_fullscreen = true; |
|
1654 |
+ client.old_state = client.is_floating; |
|
1655 |
+ client.old_border_width = client.border_width; |
|
1656 |
+ client.border_width = 0; |
|
1657 |
+ client.is_floating = true; |
| 1678 |
1658 |
} |
| 1679 |
1659 |
|
|
1660 |
+ self.fullscreen_windows.insert(window); |
|
1661 |
+ |
| 1680 |
1662 |
self.connection.configure_window( |
| 1681 |
1663 |
window, |
| 1682 |
1664 |
&x11rb::protocol::xproto::ConfigureWindowAux::new() |
| 1683 |
1665 |
.border_width(0) |
| 1684 |
|
- .x(monitor.x) |
| 1685 |
|
- .y(monitor.y) |
| 1686 |
|
- .width(monitor.width as u32) |
| 1687 |
|
- .height(monitor.height as u32) |
|
1666 |
+ .x(monitor.screen_x) |
|
1667 |
+ .y(monitor.screen_y) |
|
1668 |
+ .width(monitor.screen_width as u32) |
|
1669 |
+ .height(monitor.screen_height as u32) |
| 1688 |
1670 |
.stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), |
| 1689 |
1671 |
)?; |
| 1690 |
1672 |
|
| 1691 |
1673 |
self.connection.flush()?; |
| 1692 |
|
- self.update_bar()?; |
| 1693 |
1674 |
} else if !fullscreen && self.fullscreen_windows.contains(&window) { |
| 1694 |
1675 |
self.connection.change_property( |
| 1695 |
1676 |
PropMode::REPLACE, |
|
|
@@ -1703,17 +1684,26 @@ impl WindowManager { |
| 1703 |
1684 |
|
| 1704 |
1685 |
self.fullscreen_windows.remove(&window); |
| 1705 |
1686 |
|
| 1706 |
|
- self.connection.configure_window( |
| 1707 |
|
- window, |
| 1708 |
|
- &x11rb::protocol::xproto::ConfigureWindowAux::new() |
| 1709 |
|
- .border_width(self.config.border_width), |
| 1710 |
|
- )?; |
|
1687 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1688 |
+ client.is_fullscreen = false; |
|
1689 |
+ client.is_floating = client.old_state; |
|
1690 |
+ client.border_width = client.old_border_width; |
| 1711 |
1691 |
|
| 1712 |
|
- let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); |
| 1713 |
|
- if self.show_bar { |
| 1714 |
|
- if let Some(bar) = self.bars.get(monitor_idx) { |
| 1715 |
|
- self.connection.map_window(bar.window())?; |
| 1716 |
|
- } |
|
1692 |
+ let x = client.old_x_position; |
|
1693 |
+ let y = client.old_y_position; |
|
1694 |
+ let w = client.old_width; |
|
1695 |
+ let h = client.old_height; |
|
1696 |
+ let bw = client.border_width; |
|
1697 |
+ |
|
1698 |
+ self.connection.configure_window( |
|
1699 |
+ window, |
|
1700 |
+ &x11rb::protocol::xproto::ConfigureWindowAux::new() |
|
1701 |
+ .x(x as i32) |
|
1702 |
+ .y(y as i32) |
|
1703 |
+ .width(w as u32) |
|
1704 |
+ .height(h as u32) |
|
1705 |
+ .border_width(bw as u32), |
|
1706 |
+ )?; |
| 1717 |
1707 |
} |
| 1718 |
1708 |
|
| 1719 |
1709 |
self.apply_layout()?; |
|
|
@@ -1736,8 +1726,8 @@ impl WindowManager { |
| 1736 |
1726 |
Ok(()) |
| 1737 |
1727 |
} |
| 1738 |
1728 |
|
| 1739 |
|
- fn is_transient_window(&self, window: Window) -> bool { |
| 1740 |
|
- let transient_for = self.connection |
|
1729 |
+ fn get_transient_parent(&self, window: Window) -> Option<Window> { |
|
1730 |
+ self.connection |
| 1741 |
1731 |
.get_property( |
| 1742 |
1732 |
false, |
| 1743 |
1733 |
window, |
|
|
@@ -1748,29 +1738,737 @@ impl WindowManager { |
| 1748 |
1738 |
) |
| 1749 |
1739 |
.ok() |
| 1750 |
1740 |
.and_then(|cookie| cookie.reply().ok()) |
| 1751 |
|
- .filter(|reply| !reply.value.is_empty()); |
|
1741 |
+ .filter(|reply| !reply.value.is_empty()) |
|
1742 |
+ .and_then(|reply| { |
|
1743 |
+ if reply.value.len() >= 4 { |
|
1744 |
+ let parent_window = u32::from_ne_bytes([ |
|
1745 |
+ reply.value[0], |
|
1746 |
+ reply.value[1], |
|
1747 |
+ reply.value[2], |
|
1748 |
+ reply.value[3], |
|
1749 |
+ ]); |
|
1750 |
+ Some(parent_window) |
|
1751 |
+ } else { |
|
1752 |
+ None |
|
1753 |
+ } |
|
1754 |
+ }) |
|
1755 |
+ } |
|
1756 |
+ |
|
1757 |
+ fn is_dialog_window(&self, window: Window) -> bool { |
|
1758 |
+ let window_type_property = self.connection |
|
1759 |
+ .get_property( |
|
1760 |
+ false, |
|
1761 |
+ window, |
|
1762 |
+ self.atoms.net_wm_window_type, |
|
1763 |
+ AtomEnum::ATOM, |
|
1764 |
+ 0, |
|
1765 |
+ 32, |
|
1766 |
+ ) |
|
1767 |
+ .ok() |
|
1768 |
+ .and_then(|cookie| cookie.reply().ok()); |
|
1769 |
+ |
|
1770 |
+ if let Some(reply) = window_type_property { |
|
1771 |
+ let atoms: Vec<Atom> = reply |
|
1772 |
+ .value |
|
1773 |
+ .chunks_exact(4) |
|
1774 |
+ .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])) |
|
1775 |
+ .collect(); |
|
1776 |
+ |
|
1777 |
+ atoms.contains(&self.atoms.net_wm_window_type_dialog) |
|
1778 |
+ } else { |
|
1779 |
+ false |
|
1780 |
+ } |
|
1781 |
+ } |
|
1782 |
+ |
|
1783 |
+ fn get_window_class(&self, window: Window) -> Option<String> { |
|
1784 |
+ self.connection |
|
1785 |
+ .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024) |
|
1786 |
+ .ok() |
|
1787 |
+ .and_then(|cookie| cookie.reply().ok()) |
|
1788 |
+ .and_then(|reply| { |
|
1789 |
+ if reply.value.is_empty() { |
|
1790 |
+ None |
|
1791 |
+ } else { |
|
1792 |
+ std::str::from_utf8(&reply.value).ok().map(|s| { |
|
1793 |
+ s.split('\0').nth(1).unwrap_or(s.split('\0').next().unwrap_or("")).to_string() |
|
1794 |
+ }) |
|
1795 |
+ } |
|
1796 |
+ }) |
|
1797 |
+ } |
|
1798 |
+ |
|
1799 |
+ fn get_window_class_instance(&self, window: Window) -> (String, String) { |
|
1800 |
+ let reply = self.connection |
|
1801 |
+ .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024) |
|
1802 |
+ .ok() |
|
1803 |
+ .and_then(|cookie| cookie.reply().ok()); |
|
1804 |
+ |
|
1805 |
+ if let Some(reply) = reply { |
|
1806 |
+ if !reply.value.is_empty() { |
|
1807 |
+ if let Ok(text) = std::str::from_utf8(&reply.value) { |
|
1808 |
+ let parts: Vec<&str> = text.split('\0').collect(); |
|
1809 |
+ let instance = parts.get(0).unwrap_or(&"").to_string(); |
|
1810 |
+ let class = parts.get(1).unwrap_or(&"").to_string(); |
|
1811 |
+ return (instance, class); |
|
1812 |
+ } |
|
1813 |
+ } |
|
1814 |
+ } |
|
1815 |
+ |
|
1816 |
+ (String::new(), String::new()) |
|
1817 |
+ } |
|
1818 |
+ |
|
1819 |
+ fn apply_rules(&mut self, window: Window) -> WmResult<()> { |
|
1820 |
+ let (instance, class) = self.get_window_class_instance(window); |
|
1821 |
+ let title = self.clients.get(&window).map(|c| c.name.clone()).unwrap_or_default(); |
|
1822 |
+ |
|
1823 |
+ let mut rule_tags: Option<u32> = None; |
|
1824 |
+ let mut rule_floating: Option<bool> = None; |
|
1825 |
+ let mut rule_monitor: Option<usize> = None; |
|
1826 |
+ |
|
1827 |
+ for rule in &self.config.window_rules { |
|
1828 |
+ if rule.matches(&class, &instance, &title) { |
|
1829 |
+ if rule.tags.is_some() { |
|
1830 |
+ rule_tags = rule.tags; |
|
1831 |
+ } |
|
1832 |
+ if rule.is_floating.is_some() { |
|
1833 |
+ rule_floating = rule.is_floating; |
|
1834 |
+ } |
|
1835 |
+ if rule.monitor.is_some() { |
|
1836 |
+ rule_monitor = rule.monitor; |
|
1837 |
+ } |
|
1838 |
+ } |
|
1839 |
+ } |
|
1840 |
+ |
|
1841 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1842 |
+ if let Some(is_floating) = rule_floating { |
|
1843 |
+ client.is_floating = is_floating; |
|
1844 |
+ if is_floating { |
|
1845 |
+ self.floating_windows.insert(window); |
|
1846 |
+ } else { |
|
1847 |
+ self.floating_windows.remove(&window); |
|
1848 |
+ } |
|
1849 |
+ } |
|
1850 |
+ |
|
1851 |
+ if let Some(monitor_index) = rule_monitor { |
|
1852 |
+ if monitor_index < self.monitors.len() { |
|
1853 |
+ client.monitor_index = monitor_index; |
|
1854 |
+ } |
|
1855 |
+ } |
|
1856 |
+ |
|
1857 |
+ let tags = rule_tags.unwrap_or_else(|| { |
|
1858 |
+ self.monitors |
|
1859 |
+ .get(client.monitor_index) |
|
1860 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
|
1861 |
+ .unwrap_or(tag_mask(0)) |
|
1862 |
+ }); |
|
1863 |
+ |
|
1864 |
+ client.tags = tags; |
|
1865 |
+ } |
|
1866 |
+ |
|
1867 |
+ Ok(()) |
|
1868 |
+ } |
|
1869 |
+ |
|
1870 |
+ fn manage_window(&mut self, window: Window) -> WmResult<()> { |
|
1871 |
+ let geometry = self.connection.get_geometry(window)?.reply()?; |
|
1872 |
+ let mut window_x = geometry.x as i32; |
|
1873 |
+ let mut window_y = geometry.y as i32; |
|
1874 |
+ let window_width = geometry.width as u32; |
|
1875 |
+ let window_height = geometry.height as u32; |
|
1876 |
+ |
|
1877 |
+ let transient_parent = self.get_transient_parent(window); |
|
1878 |
+ let (window_tags, monitor_index) = if let Some(parent) = transient_parent { |
|
1879 |
+ if let Some(parent_client) = self.clients.get(&parent) { |
|
1880 |
+ (parent_client.tags, parent_client.monitor_index) |
|
1881 |
+ } else { |
|
1882 |
+ let tags = self.monitors |
|
1883 |
+ .get(self.selected_monitor) |
|
1884 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
|
1885 |
+ .unwrap_or(tag_mask(0)); |
|
1886 |
+ (tags, self.selected_monitor) |
|
1887 |
+ } |
|
1888 |
+ } else { |
|
1889 |
+ let selected_tags = self.monitors |
|
1890 |
+ .get(self.selected_monitor) |
|
1891 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
|
1892 |
+ .unwrap_or(tag_mask(0)); |
|
1893 |
+ (selected_tags, self.selected_monitor) |
|
1894 |
+ }; |
|
1895 |
+ |
|
1896 |
+ let monitor = self.monitors[monitor_index].clone(); |
|
1897 |
+ let border_width = self.config.border_width; |
|
1898 |
+ |
|
1899 |
+ let mut client = Client::new(window, monitor_index, window_tags); |
|
1900 |
+ client.x_position = window_x as i16; |
|
1901 |
+ client.y_position = window_y as i16; |
|
1902 |
+ client.width = window_width as u16; |
|
1903 |
+ client.height = window_height as u16; |
|
1904 |
+ client.old_x_position = window_x as i16; |
|
1905 |
+ client.old_y_position = window_y as i16; |
|
1906 |
+ client.old_width = window_width as u16; |
|
1907 |
+ client.old_height = window_height as u16; |
|
1908 |
+ client.border_width = border_width as u16; |
|
1909 |
+ client.old_border_width = border_width as u16; |
|
1910 |
+ |
|
1911 |
+ if window_x + (window_width as i32) + (2 * border_width as i32) > monitor.screen_x + monitor.screen_width as i32 { |
|
1912 |
+ window_x = monitor.screen_x + monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32); |
|
1913 |
+ } |
|
1914 |
+ if window_y + (window_height as i32) + (2 * border_width as i32) > monitor.screen_y + monitor.screen_height as i32 { |
|
1915 |
+ window_y = monitor.screen_y + monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32); |
|
1916 |
+ } |
|
1917 |
+ window_x = window_x.max(monitor.screen_x); |
|
1918 |
+ window_y = window_y.max(monitor.screen_y); |
|
1919 |
+ |
|
1920 |
+ let is_transient = transient_parent.is_some(); |
|
1921 |
+ let is_dialog = self.is_dialog_window(window); |
|
1922 |
+ |
|
1923 |
+ let class_name = self.get_window_class(window).unwrap_or_default(); |
|
1924 |
+ eprintln!("MapRequest 0x{:x}: class='{}' size={}x{} pos=({},{}) transient={} dialog={}", |
|
1925 |
+ window, class_name, window_width, window_height, window_x, window_y, is_transient, is_dialog); |
|
1926 |
+ |
|
1927 |
+ let off_screen_x = window_x + (2 * self.screen.width_in_pixels as i32); |
|
1928 |
+ |
|
1929 |
+ self.connection.configure_window( |
|
1930 |
+ window, |
|
1931 |
+ &ConfigureWindowAux::new() |
|
1932 |
+ .x(off_screen_x) |
|
1933 |
+ .y(window_y) |
|
1934 |
+ .width(window_width) |
|
1935 |
+ .height(window_height) |
|
1936 |
+ .border_width(border_width) |
|
1937 |
+ )?; |
|
1938 |
+ |
|
1939 |
+ self.connection.change_window_attributes( |
|
1940 |
+ window, |
|
1941 |
+ &ChangeWindowAttributesAux::new().event_mask( |
|
1942 |
+ EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE |
|
1943 |
+ ), |
|
1944 |
+ )?; |
|
1945 |
+ |
|
1946 |
+ client.is_floating = is_transient || is_dialog; |
|
1947 |
+ |
|
1948 |
+ self.clients.insert(window, client); |
|
1949 |
+ self.update_size_hints(window)?; |
|
1950 |
+ self.update_window_title(window)?; |
|
1951 |
+ self.apply_rules(window)?; |
|
1952 |
+ |
|
1953 |
+ let updated_monitor_index = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(monitor_index); |
|
1954 |
+ let updated_monitor = self.monitors.get(updated_monitor_index).cloned().unwrap_or(monitor.clone()); |
|
1955 |
+ let is_rule_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false); |
|
1956 |
+ |
|
1957 |
+ self.attach_aside(window, updated_monitor_index); |
|
1958 |
+ self.attach_stack(window, updated_monitor_index); |
|
1959 |
+ |
|
1960 |
+ self.windows.push(window); |
|
1961 |
+ |
|
1962 |
+ if is_transient || is_dialog { |
|
1963 |
+ self.floating_windows.insert(window); |
|
1964 |
+ |
|
1965 |
+ let (center_x, center_y) = if let Some(parent) = transient_parent { |
|
1966 |
+ if let Ok(parent_geom) = self.connection.get_geometry(parent)?.reply() { |
|
1967 |
+ let parent_center_x = parent_geom.x as i32 + (parent_geom.width as i32 / 2); |
|
1968 |
+ let parent_center_y = parent_geom.y as i32 + (parent_geom.height as i32 / 2); |
|
1969 |
+ (parent_center_x, parent_center_y) |
|
1970 |
+ } else { |
|
1971 |
+ let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2); |
|
1972 |
+ let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2); |
|
1973 |
+ (monitor_center_x, monitor_center_y) |
|
1974 |
+ } |
|
1975 |
+ } else { |
|
1976 |
+ let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2); |
|
1977 |
+ let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2); |
|
1978 |
+ (monitor_center_x, monitor_center_y) |
|
1979 |
+ }; |
|
1980 |
+ |
|
1981 |
+ let positioned_x = center_x - (window_width as i32 / 2); |
|
1982 |
+ let positioned_y = center_y - (window_height as i32 / 2); |
|
1983 |
+ |
|
1984 |
+ let clamped_x = positioned_x |
|
1985 |
+ .max(monitor.screen_x) |
|
1986 |
+ .min(monitor.screen_x + monitor.screen_width as i32 - window_width as i32); |
|
1987 |
+ let clamped_y = positioned_y |
|
1988 |
+ .max(monitor.screen_y) |
|
1989 |
+ .min(monitor.screen_y + monitor.screen_height as i32 - window_height as i32); |
|
1990 |
+ |
|
1991 |
+ self.update_geometry_cache(window, CachedGeometry { |
|
1992 |
+ x_position: clamped_x as i16, |
|
1993 |
+ y_position: clamped_y as i16, |
|
1994 |
+ width: window_width as u16, |
|
1995 |
+ height: window_height as u16, |
|
1996 |
+ border_width: border_width as u16, |
|
1997 |
+ }); |
|
1998 |
+ |
|
1999 |
+ self.connection.configure_window( |
|
2000 |
+ window, |
|
2001 |
+ &ConfigureWindowAux::new() |
|
2002 |
+ .x(clamped_x) |
|
2003 |
+ .y(clamped_y) |
|
2004 |
+ .width(window_width) |
|
2005 |
+ .height(window_height) |
|
2006 |
+ .border_width(border_width) |
|
2007 |
+ .stack_mode(StackMode::ABOVE), |
|
2008 |
+ )?; |
|
2009 |
+ } else if is_rule_floating && !is_transient && !is_dialog { |
|
2010 |
+ let mut adjusted_x = window_x; |
|
2011 |
+ let mut adjusted_y = window_y; |
|
2012 |
+ |
|
2013 |
+ if adjusted_x + (window_width as i32) + (2 * border_width as i32) > updated_monitor.screen_x + updated_monitor.screen_width as i32 { |
|
2014 |
+ adjusted_x = updated_monitor.screen_x + updated_monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32); |
|
2015 |
+ } |
|
2016 |
+ if adjusted_y + (window_height as i32) + (2 * border_width as i32) > updated_monitor.screen_y + updated_monitor.screen_height as i32 { |
|
2017 |
+ adjusted_y = updated_monitor.screen_y + updated_monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32); |
|
2018 |
+ } |
|
2019 |
+ adjusted_x = adjusted_x.max(updated_monitor.screen_x); |
|
2020 |
+ adjusted_y = adjusted_y.max(updated_monitor.screen_y); |
|
2021 |
+ |
|
2022 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
2023 |
+ client.x_position = adjusted_x as i16; |
|
2024 |
+ client.y_position = adjusted_y as i16; |
|
2025 |
+ client.width = window_width as u16; |
|
2026 |
+ client.height = window_height as u16; |
|
2027 |
+ } |
|
2028 |
+ |
|
2029 |
+ self.update_geometry_cache(window, CachedGeometry { |
|
2030 |
+ x_position: adjusted_x as i16, |
|
2031 |
+ y_position: adjusted_y as i16, |
|
2032 |
+ width: window_width as u16, |
|
2033 |
+ height: window_height as u16, |
|
2034 |
+ border_width: border_width as u16, |
|
2035 |
+ }); |
|
2036 |
+ |
|
2037 |
+ self.connection.configure_window( |
|
2038 |
+ window, |
|
2039 |
+ &ConfigureWindowAux::new() |
|
2040 |
+ .x(adjusted_x) |
|
2041 |
+ .y(adjusted_y) |
|
2042 |
+ .width(window_width) |
|
2043 |
+ .height(window_height) |
|
2044 |
+ .border_width(border_width) |
|
2045 |
+ .stack_mode(StackMode::ABOVE), |
|
2046 |
+ )?; |
|
2047 |
+ } |
|
2048 |
+ |
|
2049 |
+ self.set_wm_state(window, 1)?; |
|
2050 |
+ if let Err(error) = self.save_client_tag(window, window_tags) { |
|
2051 |
+ eprintln!("Failed to save client tag for new window: {:?}", error); |
|
2052 |
+ } |
|
2053 |
+ |
|
2054 |
+ self.apply_layout()?; |
|
2055 |
+ self.connection.map_window(window)?; |
|
2056 |
+ self.update_bar()?; |
|
2057 |
+ self.focus(Some(window))?; |
|
2058 |
+ |
|
2059 |
+ if self.layout.name() == "tabbed" { |
|
2060 |
+ self.update_tab_bars()?; |
|
2061 |
+ } |
|
2062 |
+ |
|
2063 |
+ Ok(()) |
|
2064 |
+ } |
|
2065 |
+ |
|
2066 |
+ pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
|
2067 |
+ let old_focused = self.previous_focused; |
|
2068 |
+ |
|
2069 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
2070 |
+ monitor.selected_client = Some(window); |
|
2071 |
+ } |
|
2072 |
+ |
|
2073 |
+ self.connection |
|
2074 |
+ .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?; |
|
2075 |
+ self.connection.flush()?; |
|
2076 |
+ |
|
2077 |
+ self.update_focus_visuals(old_focused, window)?; |
|
2078 |
+ self.previous_focused = Some(window); |
|
2079 |
+ |
|
2080 |
+ if self.layout.name() == "tabbed" { |
|
2081 |
+ self.update_tab_bars()?; |
|
2082 |
+ } |
|
2083 |
+ |
|
2084 |
+ Ok(()) |
|
2085 |
+ } |
|
2086 |
+ |
|
2087 |
+ fn unfocus(&self, window: Window) -> WmResult<()> { |
|
2088 |
+ if !self.windows.contains(&window) { |
|
2089 |
+ return Ok(()); |
|
2090 |
+ } |
|
2091 |
+ |
|
2092 |
+ self.connection.change_window_attributes( |
|
2093 |
+ window, |
|
2094 |
+ &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused), |
|
2095 |
+ )?; |
|
2096 |
+ |
|
2097 |
+ self.connection.grab_button( |
|
2098 |
+ false, |
|
2099 |
+ window, |
|
2100 |
+ EventMask::BUTTON_PRESS.into(), |
|
2101 |
+ GrabMode::SYNC, |
|
2102 |
+ GrabMode::SYNC, |
|
2103 |
+ x11rb::NONE, |
|
2104 |
+ x11rb::NONE, |
|
2105 |
+ ButtonIndex::ANY, |
|
2106 |
+ ModMask::ANY, |
|
2107 |
+ )?; |
|
2108 |
+ |
|
2109 |
+ Ok(()) |
|
2110 |
+ } |
|
2111 |
+ |
|
2112 |
+ fn focus(&mut self, window: Option<Window>) -> WmResult<()> { |
|
2113 |
+ let monitor = self.monitors.get_mut(self.selected_monitor).unwrap(); |
|
2114 |
+ let old_selected = monitor.selected_client; |
|
2115 |
+ |
|
2116 |
+ if let Some(old_win) = old_selected { |
|
2117 |
+ if old_selected != window { |
|
2118 |
+ self.unfocus(old_win)?; |
|
2119 |
+ } |
|
2120 |
+ } |
|
2121 |
+ |
|
2122 |
+ let mut win = window; |
|
2123 |
+ if win.is_none() || !self.is_visible(win.unwrap()) { |
|
2124 |
+ let mut current = self.monitors.get(self.selected_monitor) |
|
2125 |
+ .and_then(|m| m.stack_head); |
|
2126 |
+ |
|
2127 |
+ while let Some(w) = current { |
|
2128 |
+ if self.is_visible(w) { |
|
2129 |
+ win = Some(w); |
|
2130 |
+ break; |
|
2131 |
+ } |
|
2132 |
+ current = self.clients.get(&w).and_then(|c| c.stack_next); |
|
2133 |
+ } |
|
2134 |
+ } |
|
2135 |
+ |
|
2136 |
+ if let Some(win) = win { |
|
2137 |
+ if !self.windows.contains(&win) { |
|
2138 |
+ return Ok(()); |
|
2139 |
+ } |
|
2140 |
+ |
|
2141 |
+ let monitor_idx = self.clients.get(&win) |
|
2142 |
+ .map(|c| c.monitor_index) |
|
2143 |
+ .unwrap_or(self.selected_monitor); |
|
2144 |
+ if monitor_idx != self.selected_monitor { |
|
2145 |
+ self.selected_monitor = monitor_idx; |
|
2146 |
+ } |
|
2147 |
+ |
|
2148 |
+ self.detach_stack(win); |
|
2149 |
+ self.attach_stack(win, monitor_idx); |
|
2150 |
+ |
|
2151 |
+ self.connection.change_window_attributes( |
|
2152 |
+ win, |
|
2153 |
+ &ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused), |
|
2154 |
+ )?; |
|
2155 |
+ |
|
2156 |
+ self.connection.ungrab_button(ButtonIndex::ANY, win, ModMask::ANY)?; |
|
2157 |
+ |
|
2158 |
+ self.connection.set_input_focus( |
|
2159 |
+ InputFocus::POINTER_ROOT, |
|
2160 |
+ win, |
|
2161 |
+ x11rb::CURRENT_TIME, |
|
2162 |
+ )?; |
|
2163 |
+ |
|
2164 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
2165 |
+ monitor.selected_client = Some(win); |
|
2166 |
+ } |
|
2167 |
+ |
|
2168 |
+ self.previous_focused = Some(win); |
|
2169 |
+ } else { |
|
2170 |
+ self.connection.set_input_focus( |
|
2171 |
+ InputFocus::POINTER_ROOT, |
|
2172 |
+ self.root, |
|
2173 |
+ x11rb::CURRENT_TIME, |
|
2174 |
+ )?; |
|
2175 |
+ |
|
2176 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
2177 |
+ monitor.selected_client = None; |
|
2178 |
+ } |
|
2179 |
+ } |
|
2180 |
+ |
|
2181 |
+ self.restack()?; |
|
2182 |
+ self.connection.flush()?; |
|
2183 |
+ |
|
2184 |
+ Ok(()) |
|
2185 |
+ } |
|
2186 |
+ |
|
2187 |
+ fn restack(&mut self) -> WmResult<()> { |
|
2188 |
+ let monitor = match self.monitors.get(self.selected_monitor) { |
|
2189 |
+ Some(m) => m, |
|
2190 |
+ None => return Ok(()), |
|
2191 |
+ }; |
|
2192 |
+ |
|
2193 |
+ let mut windows_to_restack: Vec<Window> = Vec::new(); |
|
2194 |
+ |
|
2195 |
+ if let Some(selected) = monitor.selected_client { |
|
2196 |
+ if self.floating_windows.contains(&selected) { |
|
2197 |
+ windows_to_restack.push(selected); |
|
2198 |
+ } |
|
2199 |
+ } |
|
2200 |
+ |
|
2201 |
+ let mut current = monitor.stack_head; |
|
2202 |
+ while let Some(win) = current { |
|
2203 |
+ if self.windows.contains(&win) && self.floating_windows.contains(&win) { |
|
2204 |
+ if Some(win) != monitor.selected_client { |
|
2205 |
+ windows_to_restack.push(win); |
|
2206 |
+ } |
|
2207 |
+ } |
|
2208 |
+ current = self.clients.get(&win).and_then(|c| c.stack_next); |
|
2209 |
+ } |
|
2210 |
+ |
|
2211 |
+ current = monitor.stack_head; |
|
2212 |
+ while let Some(win) = current { |
|
2213 |
+ if self.windows.contains(&win) && !self.floating_windows.contains(&win) { |
|
2214 |
+ windows_to_restack.push(win); |
|
2215 |
+ } |
|
2216 |
+ current = self.clients.get(&win).and_then(|c| c.stack_next); |
|
2217 |
+ } |
|
2218 |
+ |
|
2219 |
+ for (i, &win) in windows_to_restack.iter().enumerate() { |
|
2220 |
+ if i == 0 { |
|
2221 |
+ self.connection.configure_window( |
|
2222 |
+ win, |
|
2223 |
+ &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), |
|
2224 |
+ )?; |
|
2225 |
+ } else { |
|
2226 |
+ self.connection.configure_window( |
|
2227 |
+ win, |
|
2228 |
+ &ConfigureWindowAux::new() |
|
2229 |
+ .sibling(windows_to_restack[i - 1]) |
|
2230 |
+ .stack_mode(StackMode::BELOW), |
|
2231 |
+ )?; |
|
2232 |
+ } |
|
2233 |
+ } |
|
2234 |
+ |
|
2235 |
+ Ok(()) |
|
2236 |
+ } |
|
2237 |
+ |
|
2238 |
+ fn focusstack(&mut self, direction: i32) -> WmResult<()> { |
|
2239 |
+ let monitor = match self.monitors.get(self.selected_monitor) { |
|
2240 |
+ Some(m) => m, |
|
2241 |
+ None => return Ok(()), |
|
2242 |
+ }; |
|
2243 |
+ |
|
2244 |
+ let selected = match monitor.selected_client { |
|
2245 |
+ Some(win) => win, |
|
2246 |
+ None => return Ok(()), |
|
2247 |
+ }; |
|
2248 |
+ |
|
2249 |
+ let selected_tags = monitor.tagset[monitor.selected_tags_index]; |
|
2250 |
+ |
|
2251 |
+ let mut stack_windows: Vec<Window> = Vec::new(); |
|
2252 |
+ let mut current = monitor.clients_head; |
|
2253 |
+ while let Some(win) = current { |
|
2254 |
+ if let Some(client) = self.clients.get(&win) { |
|
2255 |
+ if client.tags & selected_tags != 0 && !client.is_floating { |
|
2256 |
+ stack_windows.push(win); |
|
2257 |
+ } |
|
2258 |
+ current = client.next; |
|
2259 |
+ } else { |
|
2260 |
+ break; |
|
2261 |
+ } |
|
2262 |
+ } |
|
2263 |
+ |
|
2264 |
+ if stack_windows.is_empty() { |
|
2265 |
+ return Ok(()); |
|
2266 |
+ } |
|
2267 |
+ |
|
2268 |
+ let current_idx = stack_windows.iter().position(|&w| w == selected); |
|
2269 |
+ |
|
2270 |
+ let next_window = if let Some(idx) = current_idx { |
|
2271 |
+ if direction > 0 { |
|
2272 |
+ if idx + 1 < stack_windows.len() { |
|
2273 |
+ stack_windows[idx + 1] |
|
2274 |
+ } else { |
|
2275 |
+ stack_windows[0] |
|
2276 |
+ } |
|
2277 |
+ } else { |
|
2278 |
+ if idx > 0 { |
|
2279 |
+ stack_windows[idx - 1] |
|
2280 |
+ } else { |
|
2281 |
+ stack_windows[stack_windows.len() - 1] |
|
2282 |
+ } |
|
2283 |
+ } |
|
2284 |
+ } else { |
|
2285 |
+ return Ok(()); |
|
2286 |
+ }; |
|
2287 |
+ |
|
2288 |
+ self.focus(Some(next_window))?; |
|
2289 |
+ self.update_tab_bars()?; |
|
2290 |
+ |
|
2291 |
+ Ok(()) |
|
2292 |
+ } |
|
2293 |
+ |
|
2294 |
+ pub fn move_stack(&mut self, direction: i32) -> WmResult<()> { |
|
2295 |
+ let monitor_index = self.selected_monitor; |
|
2296 |
+ let monitor = match self.monitors.get(monitor_index) { |
|
2297 |
+ Some(m) => m.clone(), |
|
2298 |
+ None => return Ok(()), |
|
2299 |
+ }; |
|
2300 |
+ |
|
2301 |
+ let selected = match monitor.selected_client { |
|
2302 |
+ Some(win) => win, |
|
2303 |
+ None => return Ok(()), |
|
2304 |
+ }; |
|
2305 |
+ |
|
2306 |
+ let selected_client = match self.clients.get(&selected) { |
|
2307 |
+ Some(c) => c, |
|
2308 |
+ None => return Ok(()), |
|
2309 |
+ }; |
|
2310 |
+ |
|
2311 |
+ let target = if direction > 0 { |
|
2312 |
+ let next = self.next_tiled(selected_client.next, &monitor); |
|
2313 |
+ if next.is_some() { |
|
2314 |
+ next |
|
2315 |
+ } else { |
|
2316 |
+ self.next_tiled(monitor.clients_head, &monitor) |
|
2317 |
+ } |
|
2318 |
+ } else { |
|
2319 |
+ let mut previous = None; |
|
2320 |
+ let mut current = monitor.clients_head; |
|
2321 |
+ while let Some(window) = current { |
|
2322 |
+ if window == selected { |
|
2323 |
+ break; |
|
2324 |
+ } |
|
2325 |
+ if let Some(client) = self.clients.get(&window) { |
|
2326 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
2327 |
+ if visible_tags != 0 && !client.is_floating { |
|
2328 |
+ previous = Some(window); |
|
2329 |
+ } |
|
2330 |
+ current = client.next; |
|
2331 |
+ } else { |
|
2332 |
+ break; |
|
2333 |
+ } |
|
2334 |
+ } |
|
2335 |
+ if previous.is_none() { |
|
2336 |
+ let mut last = None; |
|
2337 |
+ let mut current = monitor.clients_head; |
|
2338 |
+ while let Some(window) = current { |
|
2339 |
+ if let Some(client) = self.clients.get(&window) { |
|
2340 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
2341 |
+ if visible_tags != 0 && !client.is_floating { |
|
2342 |
+ last = Some(window); |
|
2343 |
+ } |
|
2344 |
+ current = client.next; |
|
2345 |
+ } else { |
|
2346 |
+ break; |
|
2347 |
+ } |
|
2348 |
+ } |
|
2349 |
+ last |
|
2350 |
+ } else { |
|
2351 |
+ previous |
|
2352 |
+ } |
|
2353 |
+ }; |
|
2354 |
+ |
|
2355 |
+ let target = match target { |
|
2356 |
+ Some(t) if t != selected => t, |
|
2357 |
+ _ => return Ok(()), |
|
2358 |
+ }; |
|
2359 |
+ |
|
2360 |
+ let mut prev_selected = None; |
|
2361 |
+ let mut prev_target = None; |
|
2362 |
+ let mut current = monitor.clients_head; |
|
2363 |
+ |
|
2364 |
+ while let Some(window) = current { |
|
2365 |
+ if let Some(client) = self.clients.get(&window) { |
|
2366 |
+ if client.next == Some(selected) { |
|
2367 |
+ prev_selected = Some(window); |
|
2368 |
+ } |
|
2369 |
+ if client.next == Some(target) { |
|
2370 |
+ prev_target = Some(window); |
|
2371 |
+ } |
|
2372 |
+ current = client.next; |
|
2373 |
+ } else { |
|
2374 |
+ break; |
|
2375 |
+ } |
|
2376 |
+ } |
|
2377 |
+ |
|
2378 |
+ let selected_next = self.clients.get(&selected).and_then(|c| c.next); |
|
2379 |
+ let target_next = self.clients.get(&target).and_then(|c| c.next); |
|
2380 |
+ |
|
2381 |
+ let temp = if selected_next == Some(target) { |
|
2382 |
+ Some(selected) |
|
2383 |
+ } else { |
|
2384 |
+ selected_next |
|
2385 |
+ }; |
|
2386 |
+ |
|
2387 |
+ if let Some(client) = self.clients.get_mut(&selected) { |
|
2388 |
+ client.next = if target_next == Some(selected) { |
|
2389 |
+ Some(target) |
|
2390 |
+ } else { |
|
2391 |
+ target_next |
|
2392 |
+ }; |
|
2393 |
+ } |
|
2394 |
+ |
|
2395 |
+ if let Some(client) = self.clients.get_mut(&target) { |
|
2396 |
+ client.next = temp; |
|
2397 |
+ } |
|
2398 |
+ |
|
2399 |
+ if let Some(prev) = prev_selected { |
|
2400 |
+ if prev != target { |
|
2401 |
+ if let Some(client) = self.clients.get_mut(&prev) { |
|
2402 |
+ client.next = Some(target); |
|
2403 |
+ } |
|
2404 |
+ } |
|
2405 |
+ } |
|
2406 |
+ |
|
2407 |
+ if let Some(prev) = prev_target { |
|
2408 |
+ if prev != selected { |
|
2409 |
+ if let Some(client) = self.clients.get_mut(&prev) { |
|
2410 |
+ client.next = Some(selected); |
|
2411 |
+ } |
|
2412 |
+ } |
|
2413 |
+ } |
|
2414 |
+ |
|
2415 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
2416 |
+ if monitor.clients_head == Some(selected) { |
|
2417 |
+ monitor.clients_head = Some(target); |
|
2418 |
+ } else if monitor.clients_head == Some(target) { |
|
2419 |
+ monitor.clients_head = Some(selected); |
|
2420 |
+ } |
|
2421 |
+ } |
| 1752 |
2422 |
|
| 1753 |
|
- transient_for.is_some() |
|
2423 |
+ self.apply_layout()?; |
|
2424 |
+ Ok(()) |
| 1754 |
2425 |
} |
| 1755 |
2426 |
|
| 1756 |
|
- pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
| 1757 |
|
- let old_focused = self.previous_focused; |
|
2427 |
+ pub fn focus_monitor(&mut self, direction: i32) -> WmResult<()> { |
|
2428 |
+ if self.monitors.len() <= 1 { |
|
2429 |
+ return Ok(()); |
|
2430 |
+ } |
| 1758 |
2431 |
|
| 1759 |
|
- if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 1760 |
|
- monitor.focused_window = Some(window); |
|
2432 |
+ let target_monitor = match self.get_adjacent_monitor(direction) { |
|
2433 |
+ Some(idx) if idx != self.selected_monitor => idx, |
|
2434 |
+ _ => return Ok(()), |
|
2435 |
+ }; |
|
2436 |
+ |
|
2437 |
+ let old_selected = self.monitors |
|
2438 |
+ .get(self.selected_monitor) |
|
2439 |
+ .and_then(|m| m.selected_client); |
|
2440 |
+ |
|
2441 |
+ if let Some(win) = old_selected { |
|
2442 |
+ self.unfocus(win)?; |
| 1761 |
2443 |
} |
| 1762 |
2444 |
|
| 1763 |
|
- self.connection |
| 1764 |
|
- .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?; |
| 1765 |
|
- self.connection.flush()?; |
|
2445 |
+ self.selected_monitor = target_monitor; |
|
2446 |
+ self.focus(None)?; |
| 1766 |
2447 |
|
| 1767 |
|
- self.update_focus_visuals(old_focused, window)?; |
| 1768 |
|
- self.previous_focused = Some(window); |
|
2448 |
+ Ok(()) |
|
2449 |
+ } |
| 1769 |
2450 |
|
| 1770 |
|
- if self.layout.name() == "tabbed" { |
| 1771 |
|
- self.update_tab_bars()?; |
|
2451 |
+ pub fn send_window_to_adjacent_monitor(&mut self, direction: i32) -> WmResult<()> { |
|
2452 |
+ if self.monitors.len() <= 1 { |
|
2453 |
+ return Ok(()); |
| 1772 |
2454 |
} |
| 1773 |
2455 |
|
|
2456 |
+ let selected_window = self.monitors |
|
2457 |
+ .get(self.selected_monitor) |
|
2458 |
+ .and_then(|m| m.selected_client); |
|
2459 |
+ |
|
2460 |
+ let window = match selected_window { |
|
2461 |
+ Some(win) => win, |
|
2462 |
+ None => return Ok(()), |
|
2463 |
+ }; |
|
2464 |
+ |
|
2465 |
+ let target_monitor = match self.get_adjacent_monitor(direction) { |
|
2466 |
+ Some(idx) => idx, |
|
2467 |
+ None => return Ok(()), |
|
2468 |
+ }; |
|
2469 |
+ |
|
2470 |
+ self.move_window_to_monitor(window, target_monitor)?; |
|
2471 |
+ |
| 1774 |
2472 |
Ok(()) |
| 1775 |
2473 |
} |
| 1776 |
2474 |
|
|
|
@@ -1807,63 +2505,146 @@ impl WindowManager { |
| 1807 |
2505 |
Ok(()) |
| 1808 |
2506 |
} |
| 1809 |
2507 |
|
| 1810 |
|
- fn move_mouse(&mut self, window: Window) -> WmResult<()> { |
| 1811 |
|
- self.floating_windows.insert(window); |
|
2508 |
+ fn drag_window(&mut self, window: Window) -> WmResult<()> { |
|
2509 |
+ let is_fullscreen = self.clients |
|
2510 |
+ .get(&window) |
|
2511 |
+ .map(|c| c.is_fullscreen) |
|
2512 |
+ .unwrap_or(false); |
| 1812 |
2513 |
|
| 1813 |
|
- let geometry = self.connection.get_geometry(window)?.reply()?; |
|
2514 |
+ if is_fullscreen { |
|
2515 |
+ return Ok(()); |
|
2516 |
+ } |
| 1814 |
2517 |
|
| 1815 |
|
- self.connection |
| 1816 |
|
- .grab_pointer( |
| 1817 |
|
- false, |
| 1818 |
|
- self.root, |
| 1819 |
|
- (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE).into(), |
| 1820 |
|
- GrabMode::ASYNC, |
| 1821 |
|
- GrabMode::ASYNC, |
| 1822 |
|
- x11rb::NONE, |
| 1823 |
|
- x11rb::NONE, |
| 1824 |
|
- x11rb::CURRENT_TIME, |
| 1825 |
|
- )? |
| 1826 |
|
- .reply()?; |
|
2518 |
+ let client_info = self.clients.get(&window).map(|c| { |
|
2519 |
+ (c.x_position, c.y_position, c.width, c.height, c.is_floating, c.monitor_index) |
|
2520 |
+ }); |
|
2521 |
+ |
|
2522 |
+ let Some((orig_x, orig_y, width, height, was_floating, monitor_idx)) = client_info else { |
|
2523 |
+ return Ok(()); |
|
2524 |
+ }; |
|
2525 |
+ |
|
2526 |
+ let monitor = self.monitors.get(monitor_idx).cloned(); |
|
2527 |
+ let Some(monitor) = monitor else { |
|
2528 |
+ return Ok(()); |
|
2529 |
+ }; |
|
2530 |
+ |
|
2531 |
+ let snap = 32; |
|
2532 |
+ let is_normie = self.layout.name() == "normie"; |
|
2533 |
+ |
|
2534 |
+ if !was_floating && !is_normie { |
|
2535 |
+ self.toggle_floating()?; |
|
2536 |
+ } |
|
2537 |
+ |
|
2538 |
+ self.connection.grab_pointer( |
|
2539 |
+ false, |
|
2540 |
+ self.root, |
|
2541 |
+ (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | |
|
2542 |
+ EventMask::BUTTON_PRESS).into(), |
|
2543 |
+ GrabMode::ASYNC, |
|
2544 |
+ GrabMode::ASYNC, |
|
2545 |
+ x11rb::NONE, |
|
2546 |
+ x11rb::NONE, |
|
2547 |
+ x11rb::CURRENT_TIME, |
|
2548 |
+ )?.reply()?; |
| 1827 |
2549 |
|
| 1828 |
2550 |
let pointer = self.connection.query_pointer(self.root)?.reply()?; |
| 1829 |
|
- let (start_x, start_y) = (pointer.root_x, pointer.root_y); |
|
2551 |
+ let (start_x, start_y) = (pointer.root_x as i32, pointer.root_y as i32); |
| 1830 |
2552 |
|
| 1831 |
|
- self.connection.configure_window( |
| 1832 |
|
- window, |
| 1833 |
|
- &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), |
| 1834 |
|
- )?; |
|
2553 |
+ let mut last_time = 0u32; |
| 1835 |
2554 |
|
| 1836 |
2555 |
loop { |
| 1837 |
2556 |
let event = self.connection.wait_for_event()?; |
| 1838 |
2557 |
match event { |
|
2558 |
+ Event::ConfigureRequest(_) | Event::MapRequest(_) | Event::Expose(_) => {} |
| 1839 |
2559 |
Event::MotionNotify(e) => { |
| 1840 |
|
- let new_x = geometry.x + (e.root_x - start_x); |
| 1841 |
|
- let new_y = geometry.y + (e.root_y - start_y); |
| 1842 |
|
- self.connection.configure_window( |
| 1843 |
|
- window, |
| 1844 |
|
- &ConfigureWindowAux::new().x(new_x as i32).y(new_y as i32), |
| 1845 |
|
- )?; |
| 1846 |
|
- self.connection.flush()?; |
|
2560 |
+ if e.time.wrapping_sub(last_time) <= 16 { |
|
2561 |
+ continue; |
|
2562 |
+ } |
|
2563 |
+ last_time = e.time; |
|
2564 |
+ |
|
2565 |
+ let mut new_x = orig_x as i32 + (e.root_x as i32 - start_x); |
|
2566 |
+ let mut new_y = orig_y as i32 + (e.root_y as i32 - start_y); |
|
2567 |
+ |
|
2568 |
+ if (monitor.window_area_x - new_x).abs() < snap { |
|
2569 |
+ new_x = monitor.window_area_x; |
|
2570 |
+ } else if ((monitor.window_area_x + monitor.window_area_width) - (new_x + width as i32)).abs() < snap { |
|
2571 |
+ new_x = monitor.window_area_x + monitor.window_area_width - width as i32; |
|
2572 |
+ } |
|
2573 |
+ |
|
2574 |
+ if (monitor.window_area_y - new_y).abs() < snap { |
|
2575 |
+ new_y = monitor.window_area_y; |
|
2576 |
+ } else if ((monitor.window_area_y + monitor.window_area_height) - (new_y + height as i32)).abs() < snap { |
|
2577 |
+ new_y = monitor.window_area_y + monitor.window_area_height - height as i32; |
|
2578 |
+ } |
|
2579 |
+ |
|
2580 |
+ let should_resize = is_normie || self.clients |
|
2581 |
+ .get(&window) |
|
2582 |
+ .map(|c| c.is_floating) |
|
2583 |
+ .unwrap_or(false); |
|
2584 |
+ |
|
2585 |
+ if should_resize { |
|
2586 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
2587 |
+ client.x_position = new_x as i16; |
|
2588 |
+ client.y_position = new_y as i16; |
|
2589 |
+ } |
|
2590 |
+ |
|
2591 |
+ self.connection.configure_window( |
|
2592 |
+ window, |
|
2593 |
+ &ConfigureWindowAux::new() |
|
2594 |
+ .x(new_x) |
|
2595 |
+ .y(new_y), |
|
2596 |
+ )?; |
|
2597 |
+ self.connection.flush()?; |
|
2598 |
+ } |
| 1847 |
2599 |
} |
| 1848 |
2600 |
Event::ButtonRelease(_) => break, |
| 1849 |
2601 |
_ => {} |
| 1850 |
2602 |
} |
| 1851 |
2603 |
} |
| 1852 |
2604 |
|
| 1853 |
|
- self.connection |
| 1854 |
|
- .ungrab_pointer(x11rb::CURRENT_TIME)? |
| 1855 |
|
- .check()?; |
| 1856 |
|
- self.connection |
| 1857 |
|
- .allow_events(Allow::REPLAY_POINTER, x11rb::CURRENT_TIME)? |
| 1858 |
|
- .check()?; |
|
2605 |
+ self.connection.ungrab_pointer(x11rb::CURRENT_TIME)?.check()?; |
|
2606 |
+ |
|
2607 |
+ let final_client = self.clients.get(&window).map(|c| { |
|
2608 |
+ (c.x_position, c.y_position, c.width, c.height) |
|
2609 |
+ }); |
|
2610 |
+ |
|
2611 |
+ if let Some((x, y, w, h)) = final_client { |
|
2612 |
+ let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32); |
|
2613 |
+ if new_monitor != monitor_idx { |
|
2614 |
+ self.move_window_to_monitor(window, new_monitor)?; |
|
2615 |
+ self.selected_monitor = new_monitor; |
|
2616 |
+ self.focus(None)?; |
|
2617 |
+ } |
|
2618 |
+ } |
| 1859 |
2619 |
|
| 1860 |
2620 |
Ok(()) |
| 1861 |
2621 |
} |
| 1862 |
2622 |
|
| 1863 |
|
- fn resize_mouse(&mut self, window: Window) -> WmResult<()> { |
| 1864 |
|
- self.floating_windows.insert(window); |
|
2623 |
+ fn resize_window_with_mouse(&mut self, window: Window) -> WmResult<()> { |
|
2624 |
+ let is_fullscreen = self.clients |
|
2625 |
+ .get(&window) |
|
2626 |
+ .map(|c| c.is_fullscreen) |
|
2627 |
+ .unwrap_or(false); |
| 1865 |
2628 |
|
| 1866 |
|
- let geometry = self.connection.get_geometry(window)?.reply()?; |
|
2629 |
+ if is_fullscreen { |
|
2630 |
+ return Ok(()); |
|
2631 |
+ } |
|
2632 |
+ |
|
2633 |
+ let client_info = self.clients.get(&window).map(|c| { |
|
2634 |
+ (c.x_position, c.y_position, c.width, c.height, c.border_width, c.is_floating, c.monitor_index) |
|
2635 |
+ }); |
|
2636 |
+ |
|
2637 |
+ let Some((orig_x, orig_y, orig_width, orig_height, border_width, was_floating, monitor_idx)) = client_info else { |
|
2638 |
+ return Ok(()); |
|
2639 |
+ }; |
|
2640 |
+ |
|
2641 |
+ let monitor = self.monitors.get(monitor_idx).cloned(); |
|
2642 |
+ let Some(monitor) = monitor else { |
|
2643 |
+ return Ok(()); |
|
2644 |
+ }; |
|
2645 |
+ |
|
2646 |
+ let snap = 32; |
|
2647 |
+ let is_normie = self.layout.name() == "normie"; |
| 1867 |
2648 |
|
| 1868 |
2649 |
self.connection.warp_pointer( |
| 1869 |
2650 |
x11rb::NONE, |
|
|
@@ -1872,54 +2653,115 @@ impl WindowManager { |
| 1872 |
2653 |
0, |
| 1873 |
2654 |
0, |
| 1874 |
2655 |
0, |
| 1875 |
|
- geometry.width as i16, |
| 1876 |
|
- geometry.height as i16, |
|
2656 |
+ (orig_width + border_width - 1) as i16, |
|
2657 |
+ (orig_height + border_width - 1) as i16, |
| 1877 |
2658 |
)?; |
| 1878 |
2659 |
|
| 1879 |
|
- self.connection |
| 1880 |
|
- .grab_pointer( |
| 1881 |
|
- false, |
| 1882 |
|
- self.root, |
| 1883 |
|
- (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE).into(), |
| 1884 |
|
- GrabMode::ASYNC, |
| 1885 |
|
- GrabMode::ASYNC, |
| 1886 |
|
- x11rb::NONE, |
| 1887 |
|
- x11rb::NONE, |
| 1888 |
|
- x11rb::CURRENT_TIME, |
| 1889 |
|
- )? |
| 1890 |
|
- .reply()?; |
|
2660 |
+ self.connection.grab_pointer( |
|
2661 |
+ false, |
|
2662 |
+ self.root, |
|
2663 |
+ (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | |
|
2664 |
+ EventMask::BUTTON_PRESS).into(), |
|
2665 |
+ GrabMode::ASYNC, |
|
2666 |
+ GrabMode::ASYNC, |
|
2667 |
+ x11rb::NONE, |
|
2668 |
+ x11rb::NONE, |
|
2669 |
+ x11rb::CURRENT_TIME, |
|
2670 |
+ )?.reply()?; |
| 1891 |
2671 |
|
| 1892 |
|
- self.connection.configure_window( |
| 1893 |
|
- window, |
| 1894 |
|
- &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), |
| 1895 |
|
- )?; |
|
2672 |
+ let mut last_time = 0u32; |
| 1896 |
2673 |
|
| 1897 |
2674 |
loop { |
| 1898 |
2675 |
let event = self.connection.wait_for_event()?; |
| 1899 |
2676 |
match event { |
|
2677 |
+ Event::ConfigureRequest(_) | Event::MapRequest(_) | Event::Expose(_) => {} |
| 1900 |
2678 |
Event::MotionNotify(e) => { |
| 1901 |
|
- let new_width = (e.root_x - geometry.x).max(1) as u32; |
| 1902 |
|
- let new_height = (e.root_y - geometry.y).max(1) as u32; |
|
2679 |
+ if e.time.wrapping_sub(last_time) <= 16 { |
|
2680 |
+ continue; |
|
2681 |
+ } |
|
2682 |
+ last_time = e.time; |
|
2683 |
+ |
|
2684 |
+ let new_width = ((e.root_x as i32 - orig_x as i32 - 2 * border_width as i32 + 1).max(1)) as u32; |
|
2685 |
+ let new_height = ((e.root_y as i32 - orig_y as i32 - 2 * border_width as i32 + 1).max(1)) as u32; |
|
2686 |
+ |
|
2687 |
+ let in_monitor_bounds = |
|
2688 |
+ monitor.window_area_x + new_width as i32 >= monitor.window_area_x && |
|
2689 |
+ monitor.window_area_x + new_width as i32 <= monitor.window_area_x + monitor.window_area_width && |
|
2690 |
+ monitor.window_area_y + new_height as i32 >= monitor.window_area_y && |
|
2691 |
+ monitor.window_area_y + new_height as i32 <= monitor.window_area_y + monitor.window_area_height; |
|
2692 |
+ |
|
2693 |
+ if in_monitor_bounds { |
|
2694 |
+ if !was_floating && !is_normie && |
|
2695 |
+ ((new_width as i32 - orig_width as i32).abs() > snap || |
|
2696 |
+ (new_height as i32 - orig_height as i32).abs() > snap) { |
|
2697 |
+ self.toggle_floating()?; |
|
2698 |
+ } |
|
2699 |
+ } |
| 1903 |
2700 |
|
| 1904 |
|
- self.connection.configure_window( |
| 1905 |
|
- window, |
| 1906 |
|
- &ConfigureWindowAux::new() |
| 1907 |
|
- .width(new_width) |
| 1908 |
|
- .height(new_height), |
| 1909 |
|
- )?; |
| 1910 |
|
- self.connection.flush()?; |
|
2701 |
+ let should_resize = is_normie || self.clients |
|
2702 |
+ .get(&window) |
|
2703 |
+ .map(|c| c.is_floating) |
|
2704 |
+ .unwrap_or(false); |
|
2705 |
+ |
|
2706 |
+ if should_resize { |
|
2707 |
+ if let Some(client) = self.clients.get(&window) { |
|
2708 |
+ let (hint_width, hint_height) = self.apply_size_hints( |
|
2709 |
+ client, |
|
2710 |
+ new_width as i32, |
|
2711 |
+ new_height as i32, |
|
2712 |
+ ); |
|
2713 |
+ |
|
2714 |
+ if let Some(client_mut) = self.clients.get_mut(&window) { |
|
2715 |
+ client_mut.width = hint_width as u16; |
|
2716 |
+ client_mut.height = hint_height as u16; |
|
2717 |
+ } |
|
2718 |
+ |
|
2719 |
+ self.connection.configure_window( |
|
2720 |
+ window, |
|
2721 |
+ &ConfigureWindowAux::new() |
|
2722 |
+ .width(hint_width as u32) |
|
2723 |
+ .height(hint_height as u32), |
|
2724 |
+ )?; |
|
2725 |
+ self.connection.flush()?; |
|
2726 |
+ } |
|
2727 |
+ } |
| 1911 |
2728 |
} |
| 1912 |
2729 |
Event::ButtonRelease(_) => break, |
| 1913 |
2730 |
_ => {} |
| 1914 |
2731 |
} |
| 1915 |
2732 |
} |
| 1916 |
2733 |
|
| 1917 |
|
- self.connection |
| 1918 |
|
- .ungrab_pointer(x11rb::CURRENT_TIME)? |
| 1919 |
|
- .check()?; |
| 1920 |
|
- self.connection |
| 1921 |
|
- .allow_events(Allow::REPLAY_POINTER, x11rb::CURRENT_TIME)? |
| 1922 |
|
- .check()?; |
|
2734 |
+ let final_client = self.clients.get(&window).map(|c| { |
|
2735 |
+ (c.width, c.border_width) |
|
2736 |
+ }); |
|
2737 |
+ |
|
2738 |
+ if let Some((w, bw)) = final_client { |
|
2739 |
+ self.connection.warp_pointer( |
|
2740 |
+ x11rb::NONE, |
|
2741 |
+ window, |
|
2742 |
+ 0, |
|
2743 |
+ 0, |
|
2744 |
+ 0, |
|
2745 |
+ 0, |
|
2746 |
+ (w + bw - 1) as i16, |
|
2747 |
+ (w + bw - 1) as i16, |
|
2748 |
+ )?; |
|
2749 |
+ } |
|
2750 |
+ |
|
2751 |
+ self.connection.ungrab_pointer(x11rb::CURRENT_TIME)?.check()?; |
|
2752 |
+ |
|
2753 |
+ let final_client_pos = self.clients.get(&window).map(|c| { |
|
2754 |
+ (c.x_position, c.y_position, c.width, c.height) |
|
2755 |
+ }); |
|
2756 |
+ |
|
2757 |
+ if let Some((x, y, w, h)) = final_client_pos { |
|
2758 |
+ let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32); |
|
2759 |
+ if new_monitor != monitor_idx { |
|
2760 |
+ self.move_window_to_monitor(window, new_monitor)?; |
|
2761 |
+ self.selected_monitor = new_monitor; |
|
2762 |
+ self.focus(None)?; |
|
2763 |
+ } |
|
2764 |
+ } |
| 1923 |
2765 |
|
| 1924 |
2766 |
Ok(()) |
| 1925 |
2767 |
} |
|
|
@@ -2000,88 +2842,8 @@ impl WindowManager { |
| 2000 |
2842 |
return Ok(None); |
| 2001 |
2843 |
} |
| 2002 |
2844 |
|
| 2003 |
|
- if self.windows.contains(&event.window) { |
| 2004 |
|
- return Ok(None); |
| 2005 |
|
- } |
| 2006 |
|
- |
| 2007 |
|
- self.connection.map_window(event.window)?; |
| 2008 |
|
- self.connection.change_window_attributes( |
| 2009 |
|
- event.window, |
| 2010 |
|
- &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE), |
| 2011 |
|
- )?; |
| 2012 |
|
- |
| 2013 |
|
- let selected_tags = self |
| 2014 |
|
- .monitors |
| 2015 |
|
- .get(self.selected_monitor) |
| 2016 |
|
- .map(|m| m.selected_tags) |
| 2017 |
|
- .unwrap_or(tag_mask(0)); |
| 2018 |
|
- |
| 2019 |
|
- self.windows.push(event.window); |
| 2020 |
|
- self.window_tags.insert(event.window, selected_tags); |
| 2021 |
|
- self.window_monitor |
| 2022 |
|
- .insert(event.window, self.selected_monitor); |
| 2023 |
|
- self.set_wm_state(event.window, 1)?; |
| 2024 |
|
- if let Err(error) = self.save_client_tag(event.window, selected_tags) { |
| 2025 |
|
- eprintln!("Failed to save client tag for new window: {:?}", error); |
| 2026 |
|
- } |
| 2027 |
|
- |
| 2028 |
|
- let is_transient = self.is_transient_window(event.window); |
| 2029 |
|
- if is_transient { |
| 2030 |
|
- self.floating_windows.insert(event.window); |
| 2031 |
|
- } |
| 2032 |
|
- |
| 2033 |
|
- let is_normie_layout = self.layout.name() == "normie"; |
| 2034 |
|
- if is_normie_layout && !is_transient { |
| 2035 |
|
- let mut pointer_x: i32 = 0; |
| 2036 |
|
- let mut pointer_y: i32 = 0; |
| 2037 |
|
- let mut root_return: x11::xlib::Window = 0; |
| 2038 |
|
- let mut child_return: x11::xlib::Window = 0; |
| 2039 |
|
- let mut win_x: i32 = 0; |
| 2040 |
|
- let mut win_y: i32 = 0; |
| 2041 |
|
- let mut mask_return: u32 = 0; |
| 2042 |
|
- |
| 2043 |
|
- let pointer_queried = unsafe { |
| 2044 |
|
- x11::xlib::XQueryPointer( |
| 2045 |
|
- self.display, |
| 2046 |
|
- self.root as x11::xlib::Window, |
| 2047 |
|
- &mut root_return, |
| 2048 |
|
- &mut child_return, |
| 2049 |
|
- &mut pointer_x, |
| 2050 |
|
- &mut pointer_y, |
| 2051 |
|
- &mut win_x, |
| 2052 |
|
- &mut win_y, |
| 2053 |
|
- &mut mask_return, |
| 2054 |
|
- ) != 0 |
| 2055 |
|
- }; |
| 2056 |
|
- |
| 2057 |
|
- if pointer_queried { |
| 2058 |
|
- let window_width = (self.screen.width_in_pixels as f32 * 0.6) as u32; |
| 2059 |
|
- let window_height = (self.screen.height_in_pixels as f32 * 0.6) as u32; |
| 2060 |
|
- |
| 2061 |
|
- let spawn_x = pointer_x - (window_width as i32 / 2); |
| 2062 |
|
- let spawn_y = pointer_y - (window_height as i32 / 2); |
| 2063 |
|
- |
| 2064 |
|
- self.connection.configure_window( |
| 2065 |
|
- event.window, |
| 2066 |
|
- &ConfigureWindowAux::new() |
| 2067 |
|
- .x(spawn_x) |
| 2068 |
|
- .y(spawn_y) |
| 2069 |
|
- .width(window_width) |
| 2070 |
|
- .height(window_height) |
| 2071 |
|
- .border_width(self.config.border_width) |
| 2072 |
|
- .stack_mode(StackMode::ABOVE), |
| 2073 |
|
- )?; |
| 2074 |
|
- |
| 2075 |
|
- self.floating_windows.insert(event.window); |
| 2076 |
|
- } |
| 2077 |
|
- } |
| 2078 |
|
- |
| 2079 |
|
- self.apply_layout()?; |
| 2080 |
|
- self.update_bar()?; |
| 2081 |
|
- self.set_focus(event.window)?; |
| 2082 |
|
- |
| 2083 |
|
- if self.layout.name() == "tabbed" { |
| 2084 |
|
- self.update_tab_bars()?; |
|
2845 |
+ if !self.windows.contains(&event.window) { |
|
2846 |
+ self.manage_window(event.window)?; |
| 2085 |
2847 |
} |
| 2086 |
2848 |
} |
| 2087 |
2849 |
Event::UnmapNotify(event) => { |
|
|
@@ -2094,12 +2856,65 @@ impl WindowManager { |
| 2094 |
2856 |
self.remove_window(event.window)?; |
| 2095 |
2857 |
} |
| 2096 |
2858 |
} |
|
2859 |
+ Event::PropertyNotify(event) => { |
|
2860 |
+ if event.state == x11rb::protocol::xproto::Property::DELETE { |
|
2861 |
+ return Ok(None); |
|
2862 |
+ } |
|
2863 |
+ |
|
2864 |
+ if !self.clients.contains_key(&event.window) { |
|
2865 |
+ return Ok(None); |
|
2866 |
+ } |
|
2867 |
+ |
|
2868 |
+ if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() { |
|
2869 |
+ let is_floating = self.clients |
|
2870 |
+ .get(&event.window) |
|
2871 |
+ .map(|c| c.is_floating) |
|
2872 |
+ .unwrap_or(false); |
|
2873 |
+ |
|
2874 |
+ if !is_floating { |
|
2875 |
+ if let Some(transient_parent) = self.get_transient_parent(event.window) { |
|
2876 |
+ if self.clients.contains_key(&transient_parent) { |
|
2877 |
+ if let Some(client) = self.clients.get_mut(&event.window) { |
|
2878 |
+ client.is_floating = true; |
|
2879 |
+ } |
|
2880 |
+ self.floating_windows.insert(event.window); |
|
2881 |
+ self.apply_layout()?; |
|
2882 |
+ } |
|
2883 |
+ } |
|
2884 |
+ } |
|
2885 |
+ } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() { |
|
2886 |
+ if let Some(client) = self.clients.get_mut(&event.window) { |
|
2887 |
+ client.hints_valid = false; |
|
2888 |
+ } |
|
2889 |
+ } else if event.atom == AtomEnum::WM_HINTS.into() { |
|
2890 |
+ self.update_window_hints(event.window)?; |
|
2891 |
+ self.update_bar()?; |
|
2892 |
+ } |
|
2893 |
+ |
|
2894 |
+ if event.atom == self.atoms.wm_name || event.atom == self.atoms.net_wm_name { |
|
2895 |
+ let _ = self.update_window_title(event.window); |
|
2896 |
+ if self.layout.name() == "tabbed" { |
|
2897 |
+ self.update_tab_bars()?; |
|
2898 |
+ } |
|
2899 |
+ } |
|
2900 |
+ |
|
2901 |
+ if event.atom == self.atoms.net_wm_window_type { |
|
2902 |
+ self.update_window_type(event.window)?; |
|
2903 |
+ } |
|
2904 |
+ } |
| 2097 |
2905 |
Event::EnterNotify(event) => { |
| 2098 |
2906 |
if event.mode != x11rb::protocol::xproto::NotifyMode::NORMAL { |
| 2099 |
2907 |
return Ok(None); |
| 2100 |
2908 |
} |
| 2101 |
2909 |
if self.windows.contains(&event.event) { |
| 2102 |
|
- self.set_focus(event.event)?; |
|
2910 |
+ if let Some(client) = self.clients.get(&event.event) { |
|
2911 |
+ if client.monitor_index != self.selected_monitor { |
|
2912 |
+ self.selected_monitor = client.monitor_index; |
|
2913 |
+ self.update_bar()?; |
|
2914 |
+ } |
|
2915 |
+ } |
|
2916 |
+ self.focus(Some(event.event))?; |
|
2917 |
+ self.update_tab_bars()?; |
| 2103 |
2918 |
} |
| 2104 |
2919 |
} |
| 2105 |
2920 |
Event::MotionNotify(event) => { |
|
|
@@ -2116,7 +2931,8 @@ impl WindowManager { |
| 2116 |
2931 |
|
| 2117 |
2932 |
let visible = self.visible_windows_on_monitor(monitor_index); |
| 2118 |
2933 |
if let Some(&win) = visible.first() { |
| 2119 |
|
- self.set_focus(win)?; |
|
2934 |
+ self.focus(Some(win))?; |
|
2935 |
+ self.update_tab_bars()?; |
| 2120 |
2936 |
} |
| 2121 |
2937 |
} |
| 2122 |
2938 |
} |
|
|
@@ -2150,12 +2966,17 @@ impl WindowManager { |
| 2150 |
2966 |
Err(err) => { |
| 2151 |
2967 |
eprintln!("Config reload error: {}", err); |
| 2152 |
2968 |
self.error_message = Some(err.clone()); |
| 2153 |
|
- let screen_width = self.screen.width_in_pixels; |
| 2154 |
|
- let screen_height = self.screen.height_in_pixels; |
|
2969 |
+ let monitor = &self.monitors[self.selected_monitor]; |
|
2970 |
+ let monitor_x = monitor.screen_x as i16; |
|
2971 |
+ let monitor_y = monitor.screen_y as i16; |
|
2972 |
+ let screen_width = monitor.screen_width as u16; |
|
2973 |
+ let screen_height = monitor.screen_height as u16; |
| 2155 |
2974 |
match self.overlay.show_error( |
| 2156 |
2975 |
&self.connection, |
| 2157 |
2976 |
&self.font, |
| 2158 |
2977 |
&err, |
|
2978 |
+ monitor_x, |
|
2979 |
+ monitor_y, |
| 2159 |
2980 |
screen_width, |
| 2160 |
2981 |
screen_height, |
| 2161 |
2982 |
) { |
|
|
@@ -2217,25 +3038,24 @@ impl WindowManager { |
| 2217 |
3038 |
self.selected_monitor = monitor_index; |
| 2218 |
3039 |
} |
| 2219 |
3040 |
|
| 2220 |
|
- let visible_windows: Vec<Window> = self |
|
3041 |
+ let visible_windows: Vec<(Window, String)> = self |
| 2221 |
3042 |
.windows |
| 2222 |
3043 |
.iter() |
| 2223 |
|
- .filter(|&&window| { |
| 2224 |
|
- let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); |
| 2225 |
|
- if window_monitor_index != monitor_index |
| 2226 |
|
- || self.floating_windows.contains(&window) |
| 2227 |
|
- || self.fullscreen_windows.contains(&window) |
| 2228 |
|
- { |
| 2229 |
|
- return false; |
| 2230 |
|
- } |
| 2231 |
|
- let monitor_tags = self.monitors.get(monitor_index).map(|m| m.selected_tags).unwrap_or(0); |
| 2232 |
|
- if let Some(&tags) = self.window_tags.get(&window) { |
| 2233 |
|
- (tags & monitor_tags) != 0 |
| 2234 |
|
- } else { |
| 2235 |
|
- false |
|
3044 |
+ .filter_map(|&window| { |
|
3045 |
+ if let Some(client) = self.clients.get(&window) { |
|
3046 |
+ if client.monitor_index != monitor_index |
|
3047 |
+ || self.floating_windows.contains(&window) |
|
3048 |
+ || self.fullscreen_windows.contains(&window) |
|
3049 |
+ { |
|
3050 |
+ return None; |
|
3051 |
+ } |
|
3052 |
+ let monitor_tags = self.monitors.get(monitor_index).map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); |
|
3053 |
+ if (client.tags & monitor_tags) != 0 { |
|
3054 |
+ return Some((window, client.name.clone())); |
|
3055 |
+ } |
| 2236 |
3056 |
} |
|
3057 |
+ None |
| 2237 |
3058 |
}) |
| 2238 |
|
- .copied() |
| 2239 |
3059 |
.collect(); |
| 2240 |
3060 |
|
| 2241 |
3061 |
if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) { |
|
|
@@ -2243,16 +3063,17 @@ impl WindowManager { |
| 2243 |
3063 |
clicked_window, |
| 2244 |
3064 |
&ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), |
| 2245 |
3065 |
)?; |
| 2246 |
|
- self.set_focus(clicked_window)?; |
|
3066 |
+ self.focus(Some(clicked_window))?; |
| 2247 |
3067 |
self.update_tab_bars()?; |
| 2248 |
3068 |
} |
| 2249 |
3069 |
} else if event.child != x11rb::NONE { |
| 2250 |
|
- self.set_focus(event.child)?; |
|
3070 |
+ self.focus(Some(event.child))?; |
|
3071 |
+ self.update_tab_bars()?; |
| 2251 |
3072 |
|
| 2252 |
3073 |
if event.detail == ButtonIndex::M1.into() { |
| 2253 |
|
- self.move_mouse(event.child)?; |
|
3074 |
+ self.drag_window(event.child)?; |
| 2254 |
3075 |
} else if event.detail == ButtonIndex::M3.into() { |
| 2255 |
|
- self.resize_mouse(event.child)?; |
|
3076 |
+ self.resize_window_with_mouse(event.child)?; |
| 2256 |
3077 |
} |
| 2257 |
3078 |
} |
| 2258 |
3079 |
} |
|
|
@@ -2264,15 +3085,137 @@ impl WindowManager { |
| 2264 |
3085 |
self.update_bar()?; |
| 2265 |
3086 |
break; |
| 2266 |
3087 |
} |
| 2267 |
|
- } |
| 2268 |
|
- for _tab_bar in &self.tab_bars { |
| 2269 |
|
- if event.window == _tab_bar.window() { |
| 2270 |
|
- self.update_tab_bars()?; |
| 2271 |
|
- break; |
|
3088 |
+ } |
|
3089 |
+ for _tab_bar in &self.tab_bars { |
|
3090 |
+ if event.window == _tab_bar.window() { |
|
3091 |
+ self.update_tab_bars()?; |
|
3092 |
+ break; |
|
3093 |
+ } |
|
3094 |
+ } |
|
3095 |
+ } |
|
3096 |
+ Event::ConfigureRequest(event) => { |
|
3097 |
+ if self.windows.contains(&event.window) { |
|
3098 |
+ let monitor_index = self.clients.get(&event.window) |
|
3099 |
+ .map(|c| c.monitor_index) |
|
3100 |
+ .unwrap_or(self.selected_monitor); |
|
3101 |
+ let monitor = &self.monitors[monitor_index]; |
|
3102 |
+ let is_floating = self.floating_windows.contains(&event.window); |
|
3103 |
+ let is_tiling_layout = self.layout.name() != "normie"; |
|
3104 |
+ |
|
3105 |
+ if is_floating || !is_tiling_layout { |
|
3106 |
+ let cached_geom = self.window_geometry_cache.get(&event.window); |
|
3107 |
+ let border_width = self.config.border_width as u16; |
|
3108 |
+ |
|
3109 |
+ let mut config = ConfigureWindowAux::new(); |
|
3110 |
+ let value_mask = event.value_mask; |
|
3111 |
+ |
|
3112 |
+ if value_mask.contains(ConfigWindow::BORDER_WIDTH) { |
|
3113 |
+ config = config.border_width(event.border_width as u32); |
|
3114 |
+ } |
|
3115 |
+ |
|
3116 |
+ if value_mask.contains(ConfigWindow::X) { |
|
3117 |
+ let mut x = event.x as i32; |
|
3118 |
+ x = x.max(monitor.screen_x); |
|
3119 |
+ if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { |
|
3120 |
+ x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; |
|
3121 |
+ } |
|
3122 |
+ config = config.x(x); |
|
3123 |
+ } |
|
3124 |
+ |
|
3125 |
+ if value_mask.contains(ConfigWindow::Y) { |
|
3126 |
+ let mut y = event.y as i32; |
|
3127 |
+ y = y.max(monitor.screen_y); |
|
3128 |
+ if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 { |
|
3129 |
+ y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32; |
|
3130 |
+ } |
|
3131 |
+ config = config.y(y); |
|
3132 |
+ } |
|
3133 |
+ |
|
3134 |
+ if value_mask.contains(ConfigWindow::WIDTH) { |
|
3135 |
+ config = config.width(event.width as u32); |
|
3136 |
+ } |
|
3137 |
+ |
|
3138 |
+ if value_mask.contains(ConfigWindow::HEIGHT) { |
|
3139 |
+ config = config.height(event.height as u32); |
|
3140 |
+ } |
|
3141 |
+ |
|
3142 |
+ if value_mask.contains(ConfigWindow::SIBLING) { |
|
3143 |
+ config = config.sibling(event.sibling); |
|
3144 |
+ } |
|
3145 |
+ |
|
3146 |
+ if value_mask.contains(ConfigWindow::STACK_MODE) { |
|
3147 |
+ config = config.stack_mode(event.stack_mode); |
|
3148 |
+ } |
|
3149 |
+ |
|
3150 |
+ self.connection.configure_window(event.window, &config)?; |
|
3151 |
+ |
|
3152 |
+ let final_x = if value_mask.contains(ConfigWindow::X) { |
|
3153 |
+ let mut x = event.x as i32; |
|
3154 |
+ x = x.max(monitor.screen_x); |
|
3155 |
+ if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { |
|
3156 |
+ x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; |
|
3157 |
+ } |
|
3158 |
+ x as i16 |
|
3159 |
+ } else { |
|
3160 |
+ cached_geom.map(|g| g.x_position).unwrap_or(0) |
|
3161 |
+ }; |
|
3162 |
+ |
|
3163 |
+ let final_y = if value_mask.contains(ConfigWindow::Y) { |
|
3164 |
+ let mut y = event.y as i32; |
|
3165 |
+ y = y.max(monitor.screen_y); |
|
3166 |
+ if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 { |
|
3167 |
+ y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32; |
|
3168 |
+ } |
|
3169 |
+ y as i16 |
|
3170 |
+ } else { |
|
3171 |
+ cached_geom.map(|g| g.y_position).unwrap_or(0) |
|
3172 |
+ }; |
|
3173 |
+ |
|
3174 |
+ let final_width = if value_mask.contains(ConfigWindow::WIDTH) { event.width } else { cached_geom.map(|g| g.width).unwrap_or(1) }; |
|
3175 |
+ let final_height = if value_mask.contains(ConfigWindow::HEIGHT) { event.height } else { cached_geom.map(|g| g.height).unwrap_or(1) }; |
|
3176 |
+ |
|
3177 |
+ self.update_geometry_cache(event.window, CachedGeometry { |
|
3178 |
+ x_position: final_x, |
|
3179 |
+ y_position: final_y, |
|
3180 |
+ width: final_width, |
|
3181 |
+ height: final_height, |
|
3182 |
+ border_width: if value_mask.contains(ConfigWindow::BORDER_WIDTH) { event.border_width } else { border_width }, |
|
3183 |
+ }); |
|
3184 |
+ |
|
3185 |
+ if is_floating { |
|
3186 |
+ let new_monitor = self.get_monitor_for_rect(final_x as i32, final_y as i32, final_width as i32, final_height as i32); |
|
3187 |
+ |
|
3188 |
+ if new_monitor != monitor_index { |
|
3189 |
+ self.move_window_to_monitor(event.window, new_monitor)?; |
|
3190 |
+ } |
|
3191 |
+ } |
|
3192 |
+ } else { |
|
3193 |
+ self.send_configure_notify(event.window)?; |
|
3194 |
+ } |
|
3195 |
+ } else { |
|
3196 |
+ let mut config = ConfigureWindowAux::new() |
|
3197 |
+ .x(event.x as i32) |
|
3198 |
+ .y(event.y as i32) |
|
3199 |
+ .width(event.width as u32) |
|
3200 |
+ .height(event.height as u32) |
|
3201 |
+ .border_width(event.border_width as u32); |
|
3202 |
+ |
|
3203 |
+ if event.value_mask.contains(ConfigWindow::SIBLING) { |
|
3204 |
+ config = config.sibling(event.sibling); |
|
3205 |
+ } |
|
3206 |
+ |
|
3207 |
+ if event.value_mask.contains(ConfigWindow::STACK_MODE) { |
|
3208 |
+ config = config.stack_mode(event.stack_mode); |
| 2272 |
3209 |
} |
|
3210 |
+ |
|
3211 |
+ self.connection.configure_window(event.window, &config)?; |
| 2273 |
3212 |
} |
| 2274 |
3213 |
} |
| 2275 |
3214 |
Event::ClientMessage(event) => { |
|
3215 |
+ if !self.clients.contains_key(&event.window) { |
|
3216 |
+ return Ok(None); |
|
3217 |
+ } |
|
3218 |
+ |
| 2276 |
3219 |
if event.type_ == self.atoms.net_wm_state { |
| 2277 |
3220 |
if let Some(data) = event.data.as_data32().get(1) { |
| 2278 |
3221 |
if *data == self.atoms.net_wm_state_fullscreen { |
|
|
@@ -2286,6 +3229,46 @@ impl WindowManager { |
| 2286 |
3229 |
self.set_window_fullscreen(event.window, fullscreen)?; |
| 2287 |
3230 |
} |
| 2288 |
3231 |
} |
|
3232 |
+ } else if event.type_ == self.atoms.net_active_window { |
|
3233 |
+ let selected_window = self.monitors |
|
3234 |
+ .get(self.selected_monitor) |
|
3235 |
+ .and_then(|m| m.selected_client); |
|
3236 |
+ |
|
3237 |
+ let is_urgent = self.clients |
|
3238 |
+ .get(&event.window) |
|
3239 |
+ .map(|c| c.is_urgent) |
|
3240 |
+ .unwrap_or(false); |
|
3241 |
+ |
|
3242 |
+ if Some(event.window) != selected_window && !is_urgent { |
|
3243 |
+ self.set_urgent(event.window, true)?; |
|
3244 |
+ } |
|
3245 |
+ } |
|
3246 |
+ } |
|
3247 |
+ Event::FocusIn(event) => { |
|
3248 |
+ let selected_window = self.monitors |
|
3249 |
+ .get(self.selected_monitor) |
|
3250 |
+ .and_then(|m| m.selected_client); |
|
3251 |
+ |
|
3252 |
+ if let Some(sel_win) = selected_window { |
|
3253 |
+ if event.event != sel_win { |
|
3254 |
+ self.set_focus(sel_win)?; |
|
3255 |
+ } |
|
3256 |
+ } |
|
3257 |
+ } |
|
3258 |
+ Event::MappingNotify(event) => { |
|
3259 |
+ if event.request == x11rb::protocol::xproto::Mapping::KEYBOARD { |
|
3260 |
+ keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
|
3261 |
+ } |
|
3262 |
+ } |
|
3263 |
+ Event::ConfigureNotify(event) => { |
|
3264 |
+ if event.window == self.root { |
|
3265 |
+ let old_width = self.screen.width_in_pixels; |
|
3266 |
+ let old_height = self.screen.height_in_pixels; |
|
3267 |
+ |
|
3268 |
+ if event.width != old_width || event.height != old_height { |
|
3269 |
+ self.screen = self.connection.setup().roots[self.screen_number].clone(); |
|
3270 |
+ self.apply_layout()?; |
|
3271 |
+ } |
| 2289 |
3272 |
} |
| 2290 |
3273 |
} |
| 2291 |
3274 |
_ => {} |
|
|
@@ -2294,12 +3277,11 @@ impl WindowManager { |
| 2294 |
3277 |
} |
| 2295 |
3278 |
|
| 2296 |
3279 |
fn apply_layout(&mut self) -> WmResult<()> { |
| 2297 |
|
- if self.layout.name() == LayoutType::Normie.as_str() { |
| 2298 |
|
- return Ok(()); |
| 2299 |
|
- } |
|
3280 |
+ let is_normie = self.layout.name() == LayoutType::Normie.as_str(); |
| 2300 |
3281 |
|
| 2301 |
|
- let monitor_count = self.monitors.len(); |
| 2302 |
|
- for monitor_index in 0..monitor_count { |
|
3282 |
+ if !is_normie { |
|
3283 |
+ let monitor_count = self.monitors.len(); |
|
3284 |
+ for monitor_index in 0..monitor_count { |
| 2303 |
3285 |
let monitor = &self.monitors[monitor_index]; |
| 2304 |
3286 |
let border_width = self.config.border_width; |
| 2305 |
3287 |
|
|
|
@@ -2319,31 +3301,21 @@ impl WindowManager { |
| 2319 |
3301 |
} |
| 2320 |
3302 |
}; |
| 2321 |
3303 |
|
| 2322 |
|
- let monitor_selected_tags = monitor.selected_tags; |
| 2323 |
|
- let monitor_x = monitor.x; |
| 2324 |
|
- let monitor_y = monitor.y; |
| 2325 |
|
- let monitor_width = monitor.width; |
| 2326 |
|
- let monitor_height = monitor.height; |
| 2327 |
|
- |
| 2328 |
|
- let visible: Vec<Window> = self |
| 2329 |
|
- .windows |
| 2330 |
|
- .iter() |
| 2331 |
|
- .filter(|&&window| { |
| 2332 |
|
- let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); |
| 2333 |
|
- if window_monitor_index != monitor_index |
| 2334 |
|
- || self.floating_windows.contains(&window) |
| 2335 |
|
- || self.fullscreen_windows.contains(&window) |
| 2336 |
|
- { |
| 2337 |
|
- return false; |
| 2338 |
|
- } |
| 2339 |
|
- if let Some(&tags) = self.window_tags.get(&window) { |
| 2340 |
|
- (tags & monitor_selected_tags) != 0 |
| 2341 |
|
- } else { |
| 2342 |
|
- false |
| 2343 |
|
- } |
| 2344 |
|
- }) |
| 2345 |
|
- .copied() |
| 2346 |
|
- .collect(); |
|
3304 |
+ let monitor_x = monitor.screen_x; |
|
3305 |
+ let monitor_y = monitor.screen_y; |
|
3306 |
+ let monitor_width = monitor.screen_width; |
|
3307 |
+ let monitor_height = monitor.screen_height; |
|
3308 |
+ |
|
3309 |
+ let mut visible: Vec<Window> = Vec::new(); |
|
3310 |
+ let mut current = self.next_tiled(monitor.clients_head, monitor); |
|
3311 |
+ while let Some(window) = current { |
|
3312 |
+ visible.push(window); |
|
3313 |
+ if let Some(client) = self.clients.get(&window) { |
|
3314 |
+ current = self.next_tiled(client.next, monitor); |
|
3315 |
+ } else { |
|
3316 |
+ break; |
|
3317 |
+ } |
|
3318 |
+ } |
| 2347 |
3319 |
|
| 2348 |
3320 |
let bar_height = if self.show_bar { |
| 2349 |
3321 |
self.bars |
|
|
@@ -2353,19 +3325,47 @@ impl WindowManager { |
| 2353 |
3325 |
} else { |
| 2354 |
3326 |
0 |
| 2355 |
3327 |
}; |
| 2356 |
|
- let usable_height = monitor_height.saturating_sub(bar_height); |
| 2357 |
|
- |
| 2358 |
|
- let geometries = self |
| 2359 |
|
- .layout |
| 2360 |
|
- .arrange(&visible, monitor_width, usable_height, &gaps); |
|
3328 |
+ let usable_height = monitor_height.saturating_sub(bar_height as i32); |
|
3329 |
+ let master_factor = monitor.master_factor; |
|
3330 |
+ let num_master = monitor.num_master; |
|
3331 |
+ let smartgaps_enabled = self.config.smartgaps_enabled; |
|
3332 |
+ |
|
3333 |
+ let geometries = self.layout.arrange( |
|
3334 |
+ &visible, |
|
3335 |
+ monitor_width as u32, |
|
3336 |
+ usable_height as u32, |
|
3337 |
+ &gaps, |
|
3338 |
+ master_factor, |
|
3339 |
+ num_master, |
|
3340 |
+ smartgaps_enabled, |
|
3341 |
+ ); |
| 2361 |
3342 |
|
| 2362 |
3343 |
for (window, geometry) in visible.iter().zip(geometries.iter()) { |
| 2363 |
|
- let adjusted_width = geometry.width.saturating_sub(2 * border_width); |
| 2364 |
|
- let adjusted_height = geometry.height.saturating_sub(2 * border_width); |
|
3344 |
+ let mut adjusted_width = geometry.width.saturating_sub(2 * border_width); |
|
3345 |
+ let mut adjusted_height = geometry.height.saturating_sub(2 * border_width); |
|
3346 |
+ |
|
3347 |
+ if let Some(client) = self.clients.get(window) { |
|
3348 |
+ if !client.is_floating { |
|
3349 |
+ let (hint_width, hint_height) = self.apply_size_hints( |
|
3350 |
+ client, |
|
3351 |
+ adjusted_width as i32, |
|
3352 |
+ adjusted_height as i32, |
|
3353 |
+ ); |
|
3354 |
+ adjusted_width = hint_width as u32; |
|
3355 |
+ adjusted_height = hint_height as u32; |
|
3356 |
+ } |
|
3357 |
+ } |
| 2365 |
3358 |
|
| 2366 |
3359 |
let adjusted_x = geometry.x_coordinate + monitor_x; |
| 2367 |
3360 |
let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32; |
| 2368 |
3361 |
|
|
3362 |
+ if let Some(client) = self.clients.get_mut(window) { |
|
3363 |
+ client.x_position = adjusted_x as i16; |
|
3364 |
+ client.y_position = adjusted_y as i16; |
|
3365 |
+ client.width = adjusted_width as u16; |
|
3366 |
+ client.height = adjusted_height as u16; |
|
3367 |
+ } |
|
3368 |
+ |
| 2369 |
3369 |
self.connection.configure_window( |
| 2370 |
3370 |
*window, |
| 2371 |
3371 |
&ConfigureWindowAux::new() |
|
|
@@ -2384,6 +3384,12 @@ impl WindowManager { |
| 2384 |
3384 |
border_width: border_width as u16, |
| 2385 |
3385 |
}); |
| 2386 |
3386 |
} |
|
3387 |
+ } |
|
3388 |
+ } |
|
3389 |
+ |
|
3390 |
+ for monitor_index in 0..self.monitors.len() { |
|
3391 |
+ let stack_head = self.monitors[monitor_index].stack_head; |
|
3392 |
+ self.showhide(stack_head)?; |
| 2387 |
3393 |
} |
| 2388 |
3394 |
|
| 2389 |
3395 |
self.connection.flush()?; |
|
|
@@ -2413,9 +3419,9 @@ impl WindowManager { |
| 2413 |
3419 |
0.0 |
| 2414 |
3420 |
}; |
| 2415 |
3421 |
|
| 2416 |
|
- let tab_bar_x = (monitor.x + outer_horizontal as i32) as i16; |
| 2417 |
|
- let tab_bar_y = (monitor.y as f32 + bar_height + outer_vertical as f32) as i16; |
| 2418 |
|
- let tab_bar_width = monitor.width.saturating_sub(2 * outer_horizontal) as u16; |
|
3422 |
+ let tab_bar_x = (monitor.screen_x + outer_horizontal as i32) as i16; |
|
3423 |
+ let tab_bar_y = (monitor.screen_y as f32 + bar_height + outer_vertical as f32) as i16; |
|
3424 |
+ let tab_bar_width = monitor.screen_width.saturating_sub(2 * outer_horizontal as i32) as u16; |
| 2419 |
3425 |
|
| 2420 |
3426 |
if let Err(e) = self.tab_bars[monitor_index].reposition( |
| 2421 |
3427 |
&self.connection, |
|
|
@@ -2434,16 +3440,15 @@ impl WindowManager { |
| 2434 |
3440 |
.windows |
| 2435 |
3441 |
.iter() |
| 2436 |
3442 |
.any(|&window| { |
| 2437 |
|
- let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); |
| 2438 |
|
- if window_monitor_index != monitor_index |
| 2439 |
|
- || self.floating_windows.contains(&window) |
| 2440 |
|
- || self.fullscreen_windows.contains(&window) |
| 2441 |
|
- { |
| 2442 |
|
- return false; |
| 2443 |
|
- } |
| 2444 |
|
- if let Some(monitor) = self.monitors.get(monitor_index) { |
| 2445 |
|
- if let Some(&tags) = self.window_tags.get(&window) { |
| 2446 |
|
- return (tags & monitor.selected_tags) != 0; |
|
3443 |
+ if let Some(client) = self.clients.get(&window) { |
|
3444 |
+ if client.monitor_index != monitor_index |
|
3445 |
+ || self.floating_windows.contains(&window) |
|
3446 |
+ || self.fullscreen_windows.contains(&window) |
|
3447 |
+ { |
|
3448 |
+ return false; |
|
3449 |
+ } |
|
3450 |
+ if let Some(monitor) = self.monitors.get(monitor_index) { |
|
3451 |
+ return (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0; |
| 2447 |
3452 |
} |
| 2448 |
3453 |
} |
| 2449 |
3454 |
false |
|
|
@@ -2498,26 +3503,484 @@ impl WindowManager { |
| 2498 |
3503 |
Ok(cached) |
| 2499 |
3504 |
} |
| 2500 |
3505 |
|
|
3506 |
+ fn send_configure_notify(&mut self, window: Window) -> WmResult<()> { |
|
3507 |
+ let geometry = self.get_or_query_geometry(window)?; |
|
3508 |
+ |
|
3509 |
+ let event = x11rb::protocol::xproto::ConfigureNotifyEvent { |
|
3510 |
+ response_type: x11rb::protocol::xproto::CONFIGURE_NOTIFY_EVENT, |
|
3511 |
+ sequence: 0, |
|
3512 |
+ event: window, |
|
3513 |
+ window, |
|
3514 |
+ above_sibling: x11rb::NONE, |
|
3515 |
+ x: geometry.x_position, |
|
3516 |
+ y: geometry.y_position, |
|
3517 |
+ width: geometry.width, |
|
3518 |
+ height: geometry.height, |
|
3519 |
+ border_width: geometry.border_width, |
|
3520 |
+ override_redirect: false, |
|
3521 |
+ }; |
|
3522 |
+ |
|
3523 |
+ self.connection.send_event( |
|
3524 |
+ false, |
|
3525 |
+ window, |
|
3526 |
+ x11rb::protocol::xproto::EventMask::STRUCTURE_NOTIFY, |
|
3527 |
+ event, |
|
3528 |
+ )?; |
|
3529 |
+ |
|
3530 |
+ Ok(()) |
|
3531 |
+ } |
|
3532 |
+ |
|
3533 |
+ fn update_size_hints(&mut self, window: Window) -> WmResult<()> { |
|
3534 |
+ let size_hints = self.connection |
|
3535 |
+ .get_property( |
|
3536 |
+ false, |
|
3537 |
+ window, |
|
3538 |
+ x11rb::protocol::xproto::AtomEnum::WM_NORMAL_HINTS, |
|
3539 |
+ x11rb::protocol::xproto::AtomEnum::WM_SIZE_HINTS, |
|
3540 |
+ 0, |
|
3541 |
+ 18, |
|
3542 |
+ )? |
|
3543 |
+ .reply()?; |
|
3544 |
+ |
|
3545 |
+ if size_hints.value.is_empty() { |
|
3546 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3547 |
+ client.hints_valid = false; |
|
3548 |
+ } |
|
3549 |
+ return Ok(()); |
|
3550 |
+ } |
|
3551 |
+ |
|
3552 |
+ if size_hints.value.len() < 18 * 4 { |
|
3553 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3554 |
+ client.hints_valid = false; |
|
3555 |
+ } |
|
3556 |
+ return Ok(()); |
|
3557 |
+ } |
|
3558 |
+ |
|
3559 |
+ let read_u32 = |offset: usize| -> u32 { |
|
3560 |
+ let bytes = &size_hints.value[offset * 4..(offset + 1) * 4]; |
|
3561 |
+ u32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) |
|
3562 |
+ }; |
|
3563 |
+ |
|
3564 |
+ let flags = read_u32(0); |
|
3565 |
+ |
|
3566 |
+ const P_SIZE: u32 = 1 << 3; |
|
3567 |
+ const P_MIN_SIZE: u32 = 1 << 4; |
|
3568 |
+ const P_MAX_SIZE: u32 = 1 << 5; |
|
3569 |
+ const P_RESIZE_INC: u32 = 1 << 6; |
|
3570 |
+ const P_ASPECT: u32 = 1 << 7; |
|
3571 |
+ const P_BASE_SIZE: u32 = 1 << 8; |
|
3572 |
+ |
|
3573 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3574 |
+ if flags & P_BASE_SIZE != 0 { |
|
3575 |
+ client.base_width = read_u32(8) as i32; |
|
3576 |
+ client.base_height = read_u32(9) as i32; |
|
3577 |
+ } else if flags & P_MIN_SIZE != 0 { |
|
3578 |
+ client.base_width = read_u32(5) as i32; |
|
3579 |
+ client.base_height = read_u32(6) as i32; |
|
3580 |
+ } else { |
|
3581 |
+ client.base_width = 0; |
|
3582 |
+ client.base_height = 0; |
|
3583 |
+ } |
|
3584 |
+ |
|
3585 |
+ if flags & P_RESIZE_INC != 0 { |
|
3586 |
+ client.increment_width = read_u32(10) as i32; |
|
3587 |
+ client.increment_height = read_u32(11) as i32; |
|
3588 |
+ } else { |
|
3589 |
+ client.increment_width = 0; |
|
3590 |
+ client.increment_height = 0; |
|
3591 |
+ } |
|
3592 |
+ |
|
3593 |
+ if flags & P_MAX_SIZE != 0 { |
|
3594 |
+ client.max_width = read_u32(7) as i32; |
|
3595 |
+ client.max_height = read_u32(8) as i32; |
|
3596 |
+ } else { |
|
3597 |
+ client.max_width = 0; |
|
3598 |
+ client.max_height = 0; |
|
3599 |
+ } |
|
3600 |
+ |
|
3601 |
+ if flags & P_MIN_SIZE != 0 { |
|
3602 |
+ client.min_width = read_u32(5) as i32; |
|
3603 |
+ client.min_height = read_u32(6) as i32; |
|
3604 |
+ } else if flags & P_SIZE != 0 { |
|
3605 |
+ client.min_width = read_u32(3) as i32; |
|
3606 |
+ client.min_height = read_u32(4) as i32; |
|
3607 |
+ } else { |
|
3608 |
+ client.min_width = 0; |
|
3609 |
+ client.min_height = 0; |
|
3610 |
+ } |
|
3611 |
+ |
|
3612 |
+ if flags & P_ASPECT != 0 { |
|
3613 |
+ client.min_aspect = (read_u32(12) as f32) / (read_u32(13) as f32).max(1.0); |
|
3614 |
+ client.max_aspect = (read_u32(14) as f32) / (read_u32(15) as f32).max(1.0); |
|
3615 |
+ } else { |
|
3616 |
+ client.min_aspect = 0.0; |
|
3617 |
+ client.max_aspect = 0.0; |
|
3618 |
+ } |
|
3619 |
+ |
|
3620 |
+ client.is_fixed = client.max_width > 0 |
|
3621 |
+ && client.max_height > 0 |
|
3622 |
+ && client.max_width == client.min_width |
|
3623 |
+ && client.max_height == client.min_height; |
|
3624 |
+ |
|
3625 |
+ client.hints_valid = true; |
|
3626 |
+ } |
|
3627 |
+ Ok(()) |
|
3628 |
+ } |
|
3629 |
+ |
|
3630 |
+ fn update_window_title(&mut self, window: Window) -> WmResult<()> { |
|
3631 |
+ let net_name = self.connection |
|
3632 |
+ .get_property( |
|
3633 |
+ false, |
|
3634 |
+ window, |
|
3635 |
+ self.atoms.net_wm_name, |
|
3636 |
+ self.atoms.utf8_string, |
|
3637 |
+ 0, |
|
3638 |
+ 256, |
|
3639 |
+ ) |
|
3640 |
+ .ok() |
|
3641 |
+ .and_then(|cookie| cookie.reply().ok()); |
|
3642 |
+ |
|
3643 |
+ if let Some(name) = net_name { |
|
3644 |
+ if !name.value.is_empty() { |
|
3645 |
+ if let Ok(title) = String::from_utf8(name.value.clone()) { |
|
3646 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3647 |
+ client.name = title; |
|
3648 |
+ return Ok(()); |
|
3649 |
+ } |
|
3650 |
+ } |
|
3651 |
+ } |
|
3652 |
+ } |
|
3653 |
+ |
|
3654 |
+ let wm_name = self.connection |
|
3655 |
+ .get_property( |
|
3656 |
+ false, |
|
3657 |
+ window, |
|
3658 |
+ self.atoms.wm_name, |
|
3659 |
+ x11rb::protocol::xproto::AtomEnum::STRING, |
|
3660 |
+ 0, |
|
3661 |
+ 256, |
|
3662 |
+ )? |
|
3663 |
+ .reply()?; |
|
3664 |
+ |
|
3665 |
+ if !wm_name.value.is_empty() { |
|
3666 |
+ if let Ok(title) = String::from_utf8(wm_name.value.clone()) { |
|
3667 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3668 |
+ client.name = title; |
|
3669 |
+ } |
|
3670 |
+ } |
|
3671 |
+ } |
|
3672 |
+ |
|
3673 |
+ Ok(()) |
|
3674 |
+ } |
|
3675 |
+ |
|
3676 |
+ fn update_window_hints(&mut self, window: Window) -> WmResult<()> { |
|
3677 |
+ let hints_reply = self.connection.get_property( |
|
3678 |
+ false, |
|
3679 |
+ window, |
|
3680 |
+ AtomEnum::WM_HINTS, |
|
3681 |
+ AtomEnum::WM_HINTS, |
|
3682 |
+ 0, |
|
3683 |
+ 9, |
|
3684 |
+ )?.reply(); |
|
3685 |
+ |
|
3686 |
+ if let Ok(hints) = hints_reply { |
|
3687 |
+ if hints.value.len() >= 4 { |
|
3688 |
+ let flags = u32::from_ne_bytes([ |
|
3689 |
+ hints.value[0], |
|
3690 |
+ hints.value[1], |
|
3691 |
+ hints.value[2], |
|
3692 |
+ hints.value[3], |
|
3693 |
+ ]); |
|
3694 |
+ |
|
3695 |
+ let selected_window = self.monitors |
|
3696 |
+ .get(self.selected_monitor) |
|
3697 |
+ .and_then(|m| m.selected_client); |
|
3698 |
+ |
|
3699 |
+ if Some(window) == selected_window && (flags & 256) != 0 { |
|
3700 |
+ let new_flags = flags & !256; |
|
3701 |
+ let mut new_hints = hints.value.clone(); |
|
3702 |
+ new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes()); |
|
3703 |
+ |
|
3704 |
+ self.connection.change_property( |
|
3705 |
+ x11rb::protocol::xproto::PropMode::REPLACE, |
|
3706 |
+ window, |
|
3707 |
+ AtomEnum::WM_HINTS, |
|
3708 |
+ AtomEnum::WM_HINTS, |
|
3709 |
+ 32, |
|
3710 |
+ 9, |
|
3711 |
+ &new_hints, |
|
3712 |
+ )?; |
|
3713 |
+ } else { |
|
3714 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3715 |
+ client.is_urgent = (flags & 256) != 0; |
|
3716 |
+ } |
|
3717 |
+ } |
|
3718 |
+ |
|
3719 |
+ if hints.value.len() >= 8 && (flags & 1) != 0 { |
|
3720 |
+ let input = i32::from_ne_bytes([ |
|
3721 |
+ hints.value[4], |
|
3722 |
+ hints.value[5], |
|
3723 |
+ hints.value[6], |
|
3724 |
+ hints.value[7], |
|
3725 |
+ ]); |
|
3726 |
+ |
|
3727 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3728 |
+ client.never_focus = input == 0; |
|
3729 |
+ } |
|
3730 |
+ } else { |
|
3731 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3732 |
+ client.never_focus = false; |
|
3733 |
+ } |
|
3734 |
+ } |
|
3735 |
+ } |
|
3736 |
+ } |
|
3737 |
+ |
|
3738 |
+ Ok(()) |
|
3739 |
+ } |
|
3740 |
+ |
|
3741 |
+ fn update_window_type(&mut self, window: Window) -> WmResult<()> { |
|
3742 |
+ if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) { |
|
3743 |
+ if state_atom == self.atoms.net_wm_state_fullscreen { |
|
3744 |
+ self.set_window_fullscreen(window, true)?; |
|
3745 |
+ } |
|
3746 |
+ } |
|
3747 |
+ |
|
3748 |
+ if let Ok(Some(type_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_window_type) { |
|
3749 |
+ if type_atom == self.atoms.net_wm_window_type_dialog { |
|
3750 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3751 |
+ client.is_floating = true; |
|
3752 |
+ } |
|
3753 |
+ self.floating_windows.insert(window); |
|
3754 |
+ } |
|
3755 |
+ } |
|
3756 |
+ |
|
3757 |
+ Ok(()) |
|
3758 |
+ } |
|
3759 |
+ |
|
3760 |
+ fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) { |
|
3761 |
+ if !client.hints_valid { |
|
3762 |
+ return (width.max(1), height.max(1)); |
|
3763 |
+ } |
|
3764 |
+ |
|
3765 |
+ if client.min_width > 0 { |
|
3766 |
+ width = width.max(client.min_width); |
|
3767 |
+ } |
|
3768 |
+ if client.min_height > 0 { |
|
3769 |
+ height = height.max(client.min_height); |
|
3770 |
+ } |
|
3771 |
+ |
|
3772 |
+ if client.max_width > 0 { |
|
3773 |
+ width = width.min(client.max_width); |
|
3774 |
+ } |
|
3775 |
+ if client.max_height > 0 { |
|
3776 |
+ height = height.min(client.max_height); |
|
3777 |
+ } |
|
3778 |
+ |
|
3779 |
+ if client.increment_width > 0 { |
|
3780 |
+ width -= client.base_width; |
|
3781 |
+ width -= width % client.increment_width; |
|
3782 |
+ width += client.base_width; |
|
3783 |
+ } |
|
3784 |
+ if client.increment_height > 0 { |
|
3785 |
+ height -= client.base_height; |
|
3786 |
+ height -= height % client.increment_height; |
|
3787 |
+ height += client.base_height; |
|
3788 |
+ } |
|
3789 |
+ |
|
3790 |
+ if client.min_aspect > 0.0 || client.max_aspect > 0.0 { |
|
3791 |
+ let actual_aspect = width as f32 / height as f32; |
|
3792 |
+ |
|
3793 |
+ if client.max_aspect > 0.0 && actual_aspect > client.max_aspect { |
|
3794 |
+ width = (height as f32 * client.max_aspect) as i32; |
|
3795 |
+ } else if client.min_aspect > 0.0 && actual_aspect < client.min_aspect { |
|
3796 |
+ height = (width as f32 / client.min_aspect) as i32; |
|
3797 |
+ } |
|
3798 |
+ } |
|
3799 |
+ |
|
3800 |
+ (width.max(1), height.max(1)) |
|
3801 |
+ } |
|
3802 |
+ |
|
3803 |
+ fn next_tiled(&self, start: Option<Window>, monitor: &Monitor) -> Option<Window> { |
|
3804 |
+ let mut current = start; |
|
3805 |
+ while let Some(window) = current { |
|
3806 |
+ if let Some(client) = self.clients.get(&window) { |
|
3807 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
3808 |
+ if visible_tags != 0 && !client.is_floating { |
|
3809 |
+ return Some(window); |
|
3810 |
+ } |
|
3811 |
+ current = client.next; |
|
3812 |
+ } else { |
|
3813 |
+ break; |
|
3814 |
+ } |
|
3815 |
+ } |
|
3816 |
+ None |
|
3817 |
+ } |
|
3818 |
+ |
|
3819 |
+ fn next_tagged(&self, start: Option<Window>, tags: u32) -> Option<Window> { |
|
3820 |
+ let mut current = start; |
|
3821 |
+ while let Some(window) = current { |
|
3822 |
+ if let Some(client) = self.clients.get(&window) { |
|
3823 |
+ let visible_on_tags = (client.tags & tags) != 0; |
|
3824 |
+ if !client.is_floating && visible_on_tags { |
|
3825 |
+ return Some(window); |
|
3826 |
+ } |
|
3827 |
+ current = client.next; |
|
3828 |
+ } else { |
|
3829 |
+ break; |
|
3830 |
+ } |
|
3831 |
+ } |
|
3832 |
+ None |
|
3833 |
+ } |
|
3834 |
+ |
|
3835 |
+ fn attach(&mut self, window: Window, monitor_index: usize) { |
|
3836 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
3837 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3838 |
+ client.next = monitor.clients_head; |
|
3839 |
+ monitor.clients_head = Some(window); |
|
3840 |
+ } |
|
3841 |
+ } |
|
3842 |
+ } |
|
3843 |
+ |
|
3844 |
+ fn attach_aside(&mut self, window: Window, monitor_index: usize) { |
|
3845 |
+ let monitor = match self.monitors.get(monitor_index) { |
|
3846 |
+ Some(m) => m, |
|
3847 |
+ None => return, |
|
3848 |
+ }; |
|
3849 |
+ |
|
3850 |
+ let new_window_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(0); |
|
3851 |
+ let first_tagged = self.next_tagged(monitor.clients_head, new_window_tags); |
|
3852 |
+ |
|
3853 |
+ if first_tagged.is_none() { |
|
3854 |
+ self.attach(window, monitor_index); |
|
3855 |
+ return; |
|
3856 |
+ } |
|
3857 |
+ |
|
3858 |
+ if let Some(insert_after_window) = first_tagged { |
|
3859 |
+ if let Some(after_client) = self.clients.get(&insert_after_window) { |
|
3860 |
+ let old_next = after_client.next; |
|
3861 |
+ if let Some(new_client) = self.clients.get_mut(&window) { |
|
3862 |
+ new_client.next = old_next; |
|
3863 |
+ } |
|
3864 |
+ if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) { |
|
3865 |
+ after_client_mut.next = Some(window); |
|
3866 |
+ } |
|
3867 |
+ } |
|
3868 |
+ } |
|
3869 |
+ } |
|
3870 |
+ |
|
3871 |
+ fn detach(&mut self, window: Window) { |
|
3872 |
+ let monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
|
3873 |
+ if let Some(monitor_index) = monitor_index { |
|
3874 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
3875 |
+ if monitor.clients_head == Some(window) { |
|
3876 |
+ if let Some(client) = self.clients.get(&window) { |
|
3877 |
+ monitor.clients_head = client.next; |
|
3878 |
+ } |
|
3879 |
+ } else { |
|
3880 |
+ let mut current = monitor.clients_head; |
|
3881 |
+ while let Some(current_window) = current { |
|
3882 |
+ if let Some(current_client) = self.clients.get(¤t_window) { |
|
3883 |
+ if current_client.next == Some(window) { |
|
3884 |
+ let new_next = self.clients.get(&window).and_then(|c| c.next); |
|
3885 |
+ if let Some(current_client_mut) = self.clients.get_mut(¤t_window) { |
|
3886 |
+ current_client_mut.next = new_next; |
|
3887 |
+ } |
|
3888 |
+ break; |
|
3889 |
+ } |
|
3890 |
+ current = current_client.next; |
|
3891 |
+ } else { |
|
3892 |
+ break; |
|
3893 |
+ } |
|
3894 |
+ } |
|
3895 |
+ } |
|
3896 |
+ } |
|
3897 |
+ } |
|
3898 |
+ } |
|
3899 |
+ |
|
3900 |
+ fn attach_stack(&mut self, window: Window, monitor_index: usize) { |
|
3901 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
3902 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
3903 |
+ client.stack_next = monitor.stack_head; |
|
3904 |
+ monitor.stack_head = Some(window); |
|
3905 |
+ } |
|
3906 |
+ } |
|
3907 |
+ } |
|
3908 |
+ |
|
3909 |
+ fn detach_stack(&mut self, window: Window) { |
|
3910 |
+ let monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
|
3911 |
+ if let Some(monitor_index) = monitor_index { |
|
3912 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
3913 |
+ if monitor.stack_head == Some(window) { |
|
3914 |
+ if let Some(client) = self.clients.get(&window) { |
|
3915 |
+ monitor.stack_head = client.stack_next; |
|
3916 |
+ } |
|
3917 |
+ let should_update_selected = monitor.selected_client == Some(window); |
|
3918 |
+ let mut new_selected: Option<Window> = None; |
|
3919 |
+ if should_update_selected { |
|
3920 |
+ let mut stack_current = monitor.stack_head; |
|
3921 |
+ while let Some(stack_window) = stack_current { |
|
3922 |
+ if let Some(stack_client) = self.clients.get(&stack_window) { |
|
3923 |
+ if self.is_window_visible(stack_window) { |
|
3924 |
+ new_selected = Some(stack_window); |
|
3925 |
+ break; |
|
3926 |
+ } |
|
3927 |
+ stack_current = stack_client.stack_next; |
|
3928 |
+ } else { |
|
3929 |
+ break; |
|
3930 |
+ } |
|
3931 |
+ } |
|
3932 |
+ } |
|
3933 |
+ if should_update_selected { |
|
3934 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
3935 |
+ monitor.selected_client = new_selected; |
|
3936 |
+ } |
|
3937 |
+ } |
|
3938 |
+ } else { |
|
3939 |
+ let mut current = monitor.stack_head; |
|
3940 |
+ while let Some(current_window) = current { |
|
3941 |
+ if let Some(current_client) = self.clients.get(¤t_window) { |
|
3942 |
+ if current_client.stack_next == Some(window) { |
|
3943 |
+ let new_stack_next = self.clients.get(&window).and_then(|c| c.stack_next); |
|
3944 |
+ if let Some(current_client_mut) = self.clients.get_mut(¤t_window) { |
|
3945 |
+ current_client_mut.stack_next = new_stack_next; |
|
3946 |
+ } |
|
3947 |
+ break; |
|
3948 |
+ } |
|
3949 |
+ current = current_client.stack_next; |
|
3950 |
+ } else { |
|
3951 |
+ break; |
|
3952 |
+ } |
|
3953 |
+ } |
|
3954 |
+ } |
|
3955 |
+ } |
|
3956 |
+ } |
|
3957 |
+ } |
|
3958 |
+ |
| 2501 |
3959 |
fn remove_window(&mut self, window: Window) -> WmResult<()> { |
| 2502 |
3960 |
let initial_count = self.windows.len(); |
| 2503 |
3961 |
|
|
3962 |
+ let focused = self |
|
3963 |
+ .monitors |
|
3964 |
+ .get(self.selected_monitor) |
|
3965 |
+ .and_then(|m| m.selected_client); |
|
3966 |
+ |
|
3967 |
+ if self.clients.contains_key(&window) { |
|
3968 |
+ self.detach(window); |
|
3969 |
+ self.detach_stack(window); |
|
3970 |
+ self.clients.remove(&window); |
|
3971 |
+ } |
|
3972 |
+ |
| 2504 |
3973 |
self.windows.retain(|&w| w != window); |
| 2505 |
|
- self.window_tags.remove(&window); |
| 2506 |
|
- self.window_monitor.remove(&window); |
| 2507 |
3974 |
self.window_geometry_cache.remove(&window); |
| 2508 |
3975 |
self.floating_windows.remove(&window); |
| 2509 |
3976 |
|
| 2510 |
3977 |
if self.windows.len() < initial_count { |
| 2511 |
|
- let focused = self |
| 2512 |
|
- .monitors |
| 2513 |
|
- .get(self.selected_monitor) |
| 2514 |
|
- .and_then(|m| m.focused_window); |
| 2515 |
3978 |
if focused == Some(window) { |
| 2516 |
3979 |
let visible = self.visible_windows_on_monitor(self.selected_monitor); |
| 2517 |
3980 |
if let Some(&new_win) = visible.last() { |
| 2518 |
|
- self.set_focus(new_win)?; |
|
3981 |
+ self.focus(Some(new_win))?; |
| 2519 |
3982 |
} else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 2520 |
|
- monitor.focused_window = None; |
|
3983 |
+ monitor.selected_client = None; |
| 2521 |
3984 |
} |
| 2522 |
3985 |
} |
| 2523 |
3986 |
|