| @@ -2,7 +2,7 @@ use crate::Config; |
| 2 |
use crate::animations::{AnimationConfig, ScrollAnimation}; |
2 |
use crate::animations::{AnimationConfig, ScrollAnimation}; |
| 3 |
use crate::bar::Bar; |
3 |
use crate::bar::Bar; |
| 4 |
use crate::client::{Client, TagMask}; |
4 |
use crate::client::{Client, TagMask}; |
| 5 |
-use crate::errors::WmError; |
5 |
+use crate::errors::{ConfigError, WmError}; |
| 6 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
6 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
| 7 |
use crate::layout::GapConfig; |
7 |
use crate::layout::GapConfig; |
| 8 |
use crate::layout::tiling::TilingLayout; |
8 |
use crate::layout::tiling::TilingLayout; |
| @@ -17,17 +17,22 @@ use x11rb::protocol::Event; |
| 17 |
use x11rb::protocol::xproto::*; |
17 |
use x11rb::protocol::xproto::*; |
| 18 |
use x11rb::rust_connection::RustConnection; |
18 |
use x11rb::rust_connection::RustConnection; |
| 19 |
|
19 |
|
|
|
20 |
+enum Control { |
|
|
21 |
+ Continue, |
|
|
22 |
+ Quit, |
|
|
23 |
+} |
|
|
24 |
+ |
| 20 |
pub fn tag_mask(tag: usize) -> TagMask { |
25 |
pub fn tag_mask(tag: usize) -> TagMask { |
| 21 |
1 << tag |
26 |
1 << tag |
| 22 |
} |
27 |
} |
| 23 |
|
28 |
|
| 24 |
-/// Get back a tag index from a [`TagMask`] |
|
|
| 25 |
pub fn unmask_tag(mask: TagMask) -> usize { |
29 |
pub fn unmask_tag(mask: TagMask) -> usize { |
| 26 |
- // mask only has one bit set, so this works. |
|
|
| 27 |
mask.trailing_zeros() as usize |
30 |
mask.trailing_zeros() as usize |
| 28 |
} |
31 |
} |
| 29 |
|
32 |
|
| 30 |
struct AtomCache { |
33 |
struct AtomCache { |
|
|
34 |
+ net_supported: Atom, |
|
|
35 |
+ net_supporting_wm_check: Atom, |
| 31 |
net_current_desktop: Atom, |
36 |
net_current_desktop: Atom, |
| 32 |
net_client_info: Atom, |
37 |
net_client_info: Atom, |
| 33 |
wm_state: Atom, |
38 |
wm_state: Atom, |
| @@ -41,10 +46,22 @@ struct AtomCache { |
| 41 |
net_wm_name: Atom, |
46 |
net_wm_name: Atom, |
| 42 |
utf8_string: Atom, |
47 |
utf8_string: Atom, |
| 43 |
net_active_window: Atom, |
48 |
net_active_window: Atom, |
|
|
49 |
+ wm_take_focus: Atom, |
|
|
50 |
+ net_client_list: Atom, |
| 44 |
} |
51 |
} |
| 45 |
|
52 |
|
| 46 |
impl AtomCache { |
53 |
impl AtomCache { |
| 47 |
fn new(connection: &RustConnection) -> WmResult<Self> { |
54 |
fn new(connection: &RustConnection) -> WmResult<Self> { |
|
|
55 |
+ let net_supported = connection |
|
|
56 |
+ .intern_atom(false, b"_NET_SUPPORTED")? |
|
|
57 |
+ .reply()? |
|
|
58 |
+ .atom; |
|
|
59 |
+ |
|
|
60 |
+ let net_supporting_wm_check = connection |
|
|
61 |
+ .intern_atom(false, b"_NET_SUPPORTING_WM_CHECK")? |
|
|
62 |
+ .reply()? |
|
|
63 |
+ .atom; |
|
|
64 |
+ |
| 48 |
let net_current_desktop = connection |
65 |
let net_current_desktop = connection |
| 49 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
66 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| 50 |
.reply()? |
67 |
.reply()? |
| @@ -98,7 +115,19 @@ impl AtomCache { |
| 98 |
.reply()? |
115 |
.reply()? |
| 99 |
.atom; |
116 |
.atom; |
| 100 |
|
117 |
|
|
|
118 |
+ let wm_take_focus = connection |
|
|
119 |
+ .intern_atom(false, b"WM_TAKE_FOCUS")? |
|
|
120 |
+ .reply()? |
|
|
121 |
+ .atom; |
|
|
122 |
+ |
|
|
123 |
+ let net_client_list = connection |
|
|
124 |
+ .intern_atom(false, b"_NET_CLIENT_LIST")? |
|
|
125 |
+ .reply()? |
|
|
126 |
+ .atom; |
|
|
127 |
+ |
| 101 |
Ok(Self { |
128 |
Ok(Self { |
|
|
129 |
+ net_supported, |
|
|
130 |
+ net_supporting_wm_check, |
| 102 |
net_current_desktop, |
131 |
net_current_desktop, |
| 103 |
net_client_info, |
132 |
net_client_info, |
| 104 |
wm_state, |
133 |
wm_state, |
| @@ -112,6 +141,8 @@ impl AtomCache { |
| 112 |
net_wm_name, |
141 |
net_wm_name, |
| 113 |
utf8_string, |
142 |
utf8_string, |
| 114 |
net_active_window, |
143 |
net_active_window, |
|
|
144 |
+ wm_take_focus, |
|
|
145 |
+ net_client_list, |
| 115 |
}) |
146 |
}) |
| 116 |
} |
147 |
} |
| 117 |
} |
148 |
} |
| @@ -121,6 +152,7 @@ pub struct WindowManager { |
| 121 |
connection: RustConnection, |
152 |
connection: RustConnection, |
| 122 |
screen_number: usize, |
153 |
screen_number: usize, |
| 123 |
root: Window, |
154 |
root: Window, |
|
|
155 |
+ _wm_check_window: Window, |
| 124 |
screen: Screen, |
156 |
screen: Screen, |
| 125 |
windows: Vec<Window>, |
157 |
windows: Vec<Window>, |
| 126 |
clients: HashMap<Window, Client>, |
158 |
clients: HashMap<Window, Client>, |
| @@ -128,11 +160,9 @@ pub struct WindowManager { |
| 128 |
gaps_enabled: bool, |
160 |
gaps_enabled: bool, |
| 129 |
floating_windows: HashSet<Window>, |
161 |
floating_windows: HashSet<Window>, |
| 130 |
fullscreen_windows: HashSet<Window>, |
162 |
fullscreen_windows: HashSet<Window>, |
| 131 |
- floating_geometry_before_fullscreen: HashMap<Window, (i16, i16, u16, u16, u16)>, |
|
|
| 132 |
bars: Vec<Bar>, |
163 |
bars: Vec<Bar>, |
| 133 |
tab_bars: Vec<crate::tab_bar::TabBar>, |
164 |
tab_bars: Vec<crate::tab_bar::TabBar>, |
| 134 |
show_bar: bool, |
165 |
show_bar: bool, |
| 135 |
- last_layout: Option<&'static str>, |
|
|
| 136 |
monitors: Vec<Monitor>, |
166 |
monitors: Vec<Monitor>, |
| 137 |
selected_monitor: usize, |
167 |
selected_monitor: usize, |
| 138 |
atoms: AtomCache, |
168 |
atoms: AtomCache, |
| @@ -216,7 +246,10 @@ impl WindowManager { |
| 216 |
)?; |
246 |
)?; |
| 217 |
} |
247 |
} |
| 218 |
|
248 |
|
| 219 |
- let monitors = detect_monitors(&connection, &screen, root)?; |
249 |
+ let mut monitors = detect_monitors(&connection, &screen, root)?; |
|
|
250 |
+ for monitor in monitors.iter_mut() { |
|
|
251 |
+ monitor.init_pertag(config.tags.len(), "tiling"); |
|
|
252 |
+ } |
| 220 |
|
253 |
|
| 221 |
let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) }; |
254 |
let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) }; |
| 222 |
if display.is_null() { |
255 |
if display.is_null() { |
| @@ -265,6 +298,78 @@ impl WindowManager { |
| 265 |
|
298 |
|
| 266 |
let atoms = AtomCache::new(&connection)?; |
299 |
let atoms = AtomCache::new(&connection)?; |
| 267 |
|
300 |
|
|
|
301 |
+ let supported_atoms: Vec<Atom> = vec![ |
|
|
302 |
+ atoms.net_supported, |
|
|
303 |
+ atoms.net_supporting_wm_check, |
|
|
304 |
+ atoms.net_wm_state, |
|
|
305 |
+ atoms.net_wm_state_fullscreen, |
|
|
306 |
+ atoms.net_wm_window_type, |
|
|
307 |
+ atoms.net_wm_window_type_dialog, |
|
|
308 |
+ atoms.net_active_window, |
|
|
309 |
+ atoms.net_wm_name, |
|
|
310 |
+ atoms.net_current_desktop, |
|
|
311 |
+ atoms.net_client_info, |
|
|
312 |
+ atoms.net_client_list, |
|
|
313 |
+ ]; |
|
|
314 |
+ let supported_bytes: Vec<u8> = supported_atoms |
|
|
315 |
+ .iter() |
|
|
316 |
+ .flat_map(|a| a.to_ne_bytes()) |
|
|
317 |
+ .collect(); |
|
|
318 |
+ connection.change_property( |
|
|
319 |
+ PropMode::REPLACE, |
|
|
320 |
+ root, |
|
|
321 |
+ atoms.net_supported, |
|
|
322 |
+ AtomEnum::ATOM, |
|
|
323 |
+ 32, |
|
|
324 |
+ supported_atoms.len() as u32, |
|
|
325 |
+ &supported_bytes, |
|
|
326 |
+ )?; |
|
|
327 |
+ |
|
|
328 |
+ let wm_check_window = connection.generate_id()?; |
|
|
329 |
+ connection.create_window( |
|
|
330 |
+ screen.root_depth, |
|
|
331 |
+ wm_check_window, |
|
|
332 |
+ root, |
|
|
333 |
+ 0, |
|
|
334 |
+ 0, |
|
|
335 |
+ 1, |
|
|
336 |
+ 1, |
|
|
337 |
+ 0, |
|
|
338 |
+ WindowClass::INPUT_OUTPUT, |
|
|
339 |
+ 0, |
|
|
340 |
+ &CreateWindowAux::new(), |
|
|
341 |
+ )?; |
|
|
342 |
+ |
|
|
343 |
+ connection.change_property( |
|
|
344 |
+ PropMode::REPLACE, |
|
|
345 |
+ wm_check_window, |
|
|
346 |
+ atoms.net_supporting_wm_check, |
|
|
347 |
+ AtomEnum::WINDOW, |
|
|
348 |
+ 32, |
|
|
349 |
+ 1, |
|
|
350 |
+ &wm_check_window.to_ne_bytes(), |
|
|
351 |
+ )?; |
|
|
352 |
+ |
|
|
353 |
+ connection.change_property( |
|
|
354 |
+ PropMode::REPLACE, |
|
|
355 |
+ wm_check_window, |
|
|
356 |
+ atoms.net_wm_name, |
|
|
357 |
+ atoms.utf8_string, |
|
|
358 |
+ 8, |
|
|
359 |
+ 4, |
|
|
360 |
+ b"oxwm", |
|
|
361 |
+ )?; |
|
|
362 |
+ |
|
|
363 |
+ connection.change_property( |
|
|
364 |
+ PropMode::REPLACE, |
|
|
365 |
+ root, |
|
|
366 |
+ atoms.net_supporting_wm_check, |
|
|
367 |
+ AtomEnum::WINDOW, |
|
|
368 |
+ 32, |
|
|
369 |
+ 1, |
|
|
370 |
+ &wm_check_window.to_ne_bytes(), |
|
|
371 |
+ )?; |
|
|
372 |
+ |
| 268 |
let overlay = ErrorOverlay::new( |
373 |
let overlay = ErrorOverlay::new( |
| 269 |
&connection, |
374 |
&connection, |
| 270 |
&screen, |
375 |
&screen, |
| @@ -282,6 +387,7 @@ impl WindowManager { |
| 282 |
connection, |
387 |
connection, |
| 283 |
screen_number, |
388 |
screen_number, |
| 284 |
root, |
389 |
root, |
|
|
390 |
+ _wm_check_window: wm_check_window, |
| 285 |
screen, |
391 |
screen, |
| 286 |
windows: Vec::new(), |
392 |
windows: Vec::new(), |
| 287 |
clients: HashMap::new(), |
393 |
clients: HashMap::new(), |
| @@ -289,11 +395,9 @@ impl WindowManager { |
| 289 |
gaps_enabled, |
395 |
gaps_enabled, |
| 290 |
floating_windows: HashSet::new(), |
396 |
floating_windows: HashSet::new(), |
| 291 |
fullscreen_windows: HashSet::new(), |
397 |
fullscreen_windows: HashSet::new(), |
| 292 |
- floating_geometry_before_fullscreen: HashMap::new(), |
|
|
| 293 |
bars, |
398 |
bars, |
| 294 |
tab_bars, |
399 |
tab_bars, |
| 295 |
show_bar: true, |
400 |
show_bar: true, |
| 296 |
- last_layout: None, |
|
|
| 297 |
monitors, |
401 |
monitors, |
| 298 |
selected_monitor: 0, |
402 |
selected_monitor: 0, |
| 299 |
atoms, |
403 |
atoms, |
| @@ -321,16 +425,7 @@ impl WindowManager { |
| 321 |
Ok(window_manager) |
425 |
Ok(window_manager) |
| 322 |
} |
426 |
} |
| 323 |
|
427 |
|
| 324 |
- pub fn show_migration_overlay(&mut self) { |
428 |
+ pub fn show_startup_config_error(&mut self, error: ConfigError) { |
| 325 |
- let message = "We are on version 0.8.0 now.\n\n\ |
|
|
| 326 |
- Your config file has been deprecated once again.\n\ |
|
|
| 327 |
- Backup your current config, and run oxwm --init to generate a new one with correct values.\n\n\ |
|
|
| 328 |
- Please reach out to Tony, or check out the\n\ |
|
|
| 329 |
- documentation for help with migration.\n\n\ |
|
|
| 330 |
- We appreciate you testing oxwm!\n\n\ |
|
|
| 331 |
- Press Mod+Shift+/ to see keybinds\n\ |
|
|
| 332 |
- Press Mod+Shift+R to reload after fixing your config"; |
|
|
| 333 |
- |
|
|
| 334 |
let monitor = &self.monitors[self.selected_monitor]; |
429 |
let monitor = &self.monitors[self.selected_monitor]; |
| 335 |
let monitor_x = monitor.screen_x as i16; |
430 |
let monitor_x = monitor.screen_x as i16; |
| 336 |
let monitor_y = monitor.screen_y as i16; |
431 |
let monitor_y = monitor.screen_y as i16; |
| @@ -340,36 +435,38 @@ impl WindowManager { |
| 340 |
if let Err(e) = self.overlay.show_error( |
435 |
if let Err(e) = self.overlay.show_error( |
| 341 |
&self.connection, |
436 |
&self.connection, |
| 342 |
&self.font, |
437 |
&self.font, |
| 343 |
- message, |
438 |
+ error, |
| 344 |
monitor_x, |
439 |
monitor_x, |
| 345 |
monitor_y, |
440 |
monitor_y, |
| 346 |
screen_width, |
441 |
screen_width, |
| 347 |
screen_height, |
442 |
screen_height, |
| 348 |
) { |
443 |
) { |
| 349 |
- eprintln!("Failed to show migration overlay: {:?}", e); |
444 |
+ eprintln!("Failed to show config error overlay: {:?}", e); |
| 350 |
} |
445 |
} |
| 351 |
} |
446 |
} |
| 352 |
|
447 |
|
| 353 |
- fn try_reload_config(&mut self) -> Result<(), String> { |
448 |
+ fn try_reload_config(&mut self) -> Result<(), ConfigError> { |
| 354 |
- let lua_path = |
449 |
+ let lua_path = self |
| 355 |
- self.config.path.take().ok_or( |
450 |
+ .config |
| 356 |
- "Could not find config file. Config path should've been set while loading", |
451 |
+ .path |
| 357 |
- )?; |
452 |
+ .as_ref() |
|
|
453 |
+ .ok_or(ConfigError::NoConfigPathSet)?; |
| 358 |
|
454 |
|
| 359 |
if !lua_path.exists() { |
455 |
if !lua_path.exists() { |
| 360 |
- return Err("Could not find config file, has it been moved?".to_string()); |
456 |
+ return Err(ConfigError::NoConfigAtPath); |
| 361 |
} |
457 |
} |
| 362 |
|
458 |
|
| 363 |
- let config_str = std::fs::read_to_string(&lua_path) |
459 |
+ let config_str = |
| 364 |
- .map_err(|e| format!("Failed to read config: {}", e))?; |
460 |
+ std::fs::read_to_string(lua_path).map_err(|e| ConfigError::CouldNotReadConfig(e))?; |
| 365 |
|
461 |
|
| 366 |
let config_dir = lua_path.parent(); |
462 |
let config_dir = lua_path.parent(); |
| 367 |
|
463 |
|
| 368 |
- let new_config = crate::config::parse_lua_config(&config_str, config_dir) |
464 |
+ let new_config = crate::config::parse_lua_config(&config_str, config_dir)?; |
| 369 |
- .map_err(|e| format!("{}", e))?; |
465 |
+ |
|
|
466 |
+ let lua_path = self.config.path.take(); |
| 370 |
|
467 |
|
| 371 |
self.config = new_config; |
468 |
self.config = new_config; |
| 372 |
- self.config.path = Some(lua_path); |
469 |
+ self.config.path = lua_path; |
| 373 |
self.error_message = None; |
470 |
self.error_message = None; |
| 374 |
|
471 |
|
| 375 |
for bar in &mut self.bars { |
472 |
for bar in &mut self.bars { |
| @@ -506,7 +603,27 @@ impl WindowManager { |
| 506 |
Ok(()) |
603 |
Ok(()) |
| 507 |
} |
604 |
} |
| 508 |
|
605 |
|
| 509 |
- pub fn run(&mut self) -> WmResult<bool> { |
606 |
+ fn update_client_list(&self) -> WmResult<()> { |
|
|
607 |
+ let window_bytes: Vec<u8> = self |
|
|
608 |
+ .windows |
|
|
609 |
+ .iter() |
|
|
610 |
+ .flat_map(|window| window.to_ne_bytes()) |
|
|
611 |
+ .collect(); |
|
|
612 |
+ |
|
|
613 |
+ self.connection.change_property( |
|
|
614 |
+ PropMode::REPLACE, |
|
|
615 |
+ self.root, |
|
|
616 |
+ self.atoms.net_client_list, |
|
|
617 |
+ AtomEnum::WINDOW, |
|
|
618 |
+ 32, |
|
|
619 |
+ self.windows.len() as u32, |
|
|
620 |
+ &window_bytes, |
|
|
621 |
+ )?; |
|
|
622 |
+ |
|
|
623 |
+ Ok(()) |
|
|
624 |
+ } |
|
|
625 |
+ |
|
|
626 |
+ pub fn run(&mut self) -> WmResult<()> { |
| 510 |
println!("oxwm started on display {}", self.screen_number); |
627 |
println!("oxwm started on display {}", self.screen_number); |
| 511 |
|
628 |
|
| 512 |
self.grab_keys()?; |
629 |
self.grab_keys()?; |
| @@ -518,8 +635,8 @@ impl WindowManager { |
| 518 |
loop { |
635 |
loop { |
| 519 |
match self.connection.poll_for_event_with_sequence()? { |
636 |
match self.connection.poll_for_event_with_sequence()? { |
| 520 |
Some((event, _sequence)) => { |
637 |
Some((event, _sequence)) => { |
| 521 |
- if let Some(should_restart) = self.handle_event(event)? { |
638 |
+ if matches!(self.handle_event(event)?, Control::Quit) { |
| 522 |
- return Ok(should_restart); |
639 |
+ return Ok(()); |
| 523 |
} |
640 |
} |
| 524 |
} |
641 |
} |
| 525 |
None => { |
642 |
None => { |
| @@ -603,6 +720,9 @@ impl WindowManager { |
| 603 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
720 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 604 |
let new_mfact = (monitor.master_factor + delta).clamp(0.05, 0.95); |
721 |
let new_mfact = (monitor.master_factor + delta).clamp(0.05, 0.95); |
| 605 |
monitor.master_factor = new_mfact; |
722 |
monitor.master_factor = new_mfact; |
|
|
723 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
724 |
+ pertag.master_factors[pertag.current_tag] = new_mfact; |
|
|
725 |
+ } |
| 606 |
self.apply_layout()?; |
726 |
self.apply_layout()?; |
| 607 |
} |
727 |
} |
| 608 |
Ok(()) |
728 |
Ok(()) |
| @@ -612,6 +732,9 @@ impl WindowManager { |
| 612 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
732 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 613 |
let new_nmaster = (monitor.num_master + delta).max(0); |
733 |
let new_nmaster = (monitor.num_master + delta).max(0); |
| 614 |
monitor.num_master = new_nmaster; |
734 |
monitor.num_master = new_nmaster; |
|
|
735 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
736 |
+ pertag.num_masters[pertag.current_tag] = new_nmaster; |
|
|
737 |
+ } |
| 615 |
self.apply_layout()?; |
738 |
self.apply_layout()?; |
| 616 |
} |
739 |
} |
| 617 |
Ok(()) |
740 |
Ok(()) |
| @@ -775,6 +898,19 @@ impl WindowManager { |
| 775 |
Ok(()) |
898 |
Ok(()) |
| 776 |
} |
899 |
} |
| 777 |
|
900 |
|
|
|
901 |
+ fn toggle_bar(&mut self) -> WmResult<()> { |
|
|
902 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
|
903 |
+ monitor.show_bar = !monitor.show_bar; |
|
|
904 |
+ self.show_bar = monitor.show_bar; |
|
|
905 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
906 |
+ pertag.show_bars[pertag.current_tag] = monitor.show_bar; |
|
|
907 |
+ } |
|
|
908 |
+ } |
|
|
909 |
+ self.apply_layout()?; |
|
|
910 |
+ self.update_bar()?; |
|
|
911 |
+ Ok(()) |
|
|
912 |
+ } |
|
|
913 |
+ |
| 778 |
fn get_layout_symbol(&self) -> String { |
914 |
fn get_layout_symbol(&self) -> String { |
| 779 |
let layout_name = self.layout.name(); |
915 |
let layout_name = self.layout.name(); |
| 780 |
|
916 |
|
| @@ -967,13 +1103,6 @@ impl WindowManager { |
| 967 |
} |
1103 |
} |
| 968 |
} |
1104 |
} |
| 969 |
KeyAction::ToggleFullScreen => { |
1105 |
KeyAction::ToggleFullScreen => { |
| 970 |
- // Disable gaps and save previous state in config if not already in fullscreen |
|
|
| 971 |
- if self.fullscreen_windows.is_empty() { |
|
|
| 972 |
- self.config.gaps_enabled = std::mem::take(&mut self.gaps_enabled); |
|
|
| 973 |
- } else { |
|
|
| 974 |
- self.gaps_enabled = self.config.gaps_enabled; |
|
|
| 975 |
- } |
|
|
| 976 |
- |
|
|
| 977 |
self.fullscreen()?; |
1106 |
self.fullscreen()?; |
| 978 |
self.restack()?; |
1107 |
self.restack()?; |
| 979 |
} |
1108 |
} |
| @@ -982,6 +1111,11 @@ impl WindowManager { |
| 982 |
match layout_from_str(layout_name) { |
1111 |
match layout_from_str(layout_name) { |
| 983 |
Ok(layout) => { |
1112 |
Ok(layout) => { |
| 984 |
self.layout = layout; |
1113 |
self.layout = layout; |
|
|
1114 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
|
1115 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
1116 |
+ pertag.layouts[pertag.current_tag] = layout_name.to_string(); |
|
|
1117 |
+ } |
|
|
1118 |
+ } |
| 985 |
if layout_name != "normie" && layout_name != "floating" { |
1119 |
if layout_name != "normie" && layout_name != "floating" { |
| 986 |
self.floating_windows.clear(); |
1120 |
self.floating_windows.clear(); |
| 987 |
} |
1121 |
} |
| @@ -999,6 +1133,11 @@ impl WindowManager { |
| 999 |
match layout_from_str(next_name) { |
1133 |
match layout_from_str(next_name) { |
| 1000 |
Ok(layout) => { |
1134 |
Ok(layout) => { |
| 1001 |
self.layout = layout; |
1135 |
self.layout = layout; |
|
|
1136 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
|
1137 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
1138 |
+ pertag.layouts[pertag.current_tag] = next_name.to_string(); |
|
|
1139 |
+ } |
|
|
1140 |
+ } |
| 1002 |
if next_name != "normie" && next_name != "floating" { |
1141 |
if next_name != "normie" && next_name != "floating" { |
| 1003 |
self.floating_windows.clear(); |
1142 |
self.floating_windows.clear(); |
| 1004 |
} |
1143 |
} |
| @@ -1026,9 +1165,7 @@ impl WindowManager { |
| 1026 |
self.restack()?; |
1165 |
self.restack()?; |
| 1027 |
} |
1166 |
} |
| 1028 |
} |
1167 |
} |
| 1029 |
- KeyAction::Quit | KeyAction::Restart => { |
1168 |
+ KeyAction::Quit | KeyAction::Restart => {} |
| 1030 |
- // Handled in handle_event |
|
|
| 1031 |
- } |
|
|
| 1032 |
KeyAction::ViewTag => { |
1169 |
KeyAction::ViewTag => { |
| 1033 |
if let Arg::Int(tag_index) = arg { |
1170 |
if let Arg::Int(tag_index) = arg { |
| 1034 |
self.view_tag(*tag_index as usize)?; |
1171 |
self.view_tag(*tag_index as usize)?; |
| @@ -1230,7 +1367,7 @@ impl WindowManager { |
| 1230 |
return Ok(()); |
1367 |
return Ok(()); |
| 1231 |
} |
1368 |
} |
| 1232 |
|
1369 |
|
| 1233 |
- self.unfocus(window)?; |
1370 |
+ self.unfocus(window, false)?; |
| 1234 |
self.detach(window); |
1371 |
self.detach(window); |
| 1235 |
self.detach_stack(window); |
1372 |
self.detach_stack(window); |
| 1236 |
|
1373 |
|
| @@ -1362,21 +1499,48 @@ impl WindowManager { |
| 1362 |
return Ok(()); |
1499 |
return Ok(()); |
| 1363 |
} |
1500 |
} |
| 1364 |
|
1501 |
|
| 1365 |
- let monitor = match self.monitors.get_mut(self.selected_monitor) { |
|
|
| 1366 |
- Some(m) => m, |
|
|
| 1367 |
- None => return Ok(()), |
|
|
| 1368 |
- }; |
|
|
| 1369 |
- |
|
|
| 1370 |
let new_tagset = tag_mask(tag_index); |
1502 |
let new_tagset = tag_mask(tag_index); |
|
|
1503 |
+ let mut layout_name: Option<String> = None; |
|
|
1504 |
+ let mut toggle_bar = false; |
| 1371 |
|
1505 |
|
| 1372 |
- if new_tagset == monitor.tagset[monitor.selected_tags_index] { |
1506 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 1373 |
- if !self.config.tag_back_and_forth { |
1507 |
+ if new_tagset == monitor.tagset[monitor.selected_tags_index] { |
| 1374 |
- return Ok(()); |
1508 |
+ if !self.config.tag_back_and_forth { |
|
|
1509 |
+ return Ok(()); |
|
|
1510 |
+ } |
|
|
1511 |
+ monitor.tagset.swap(0, 1); |
|
|
1512 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
1513 |
+ let tmp = pertag.previous_tag; |
|
|
1514 |
+ pertag.previous_tag = pertag.current_tag; |
|
|
1515 |
+ pertag.current_tag = tmp; |
|
|
1516 |
+ } |
|
|
1517 |
+ } else { |
|
|
1518 |
+ monitor.selected_tags_index ^= 1; |
|
|
1519 |
+ monitor.tagset[monitor.selected_tags_index] = new_tagset; |
|
|
1520 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
1521 |
+ pertag.previous_tag = pertag.current_tag; |
|
|
1522 |
+ pertag.current_tag = tag_index + 1; |
|
|
1523 |
+ } |
|
|
1524 |
+ } |
|
|
1525 |
+ |
|
|
1526 |
+ if let Some(ref pertag) = monitor.pertag { |
|
|
1527 |
+ monitor.num_master = pertag.num_masters[pertag.current_tag]; |
|
|
1528 |
+ monitor.master_factor = pertag.master_factors[pertag.current_tag]; |
|
|
1529 |
+ layout_name = Some(pertag.layouts[pertag.current_tag].clone()); |
|
|
1530 |
+ if monitor.show_bar != pertag.show_bars[pertag.current_tag] { |
|
|
1531 |
+ toggle_bar = true; |
|
|
1532 |
+ } |
| 1375 |
} |
1533 |
} |
| 1376 |
- monitor.tagset.swap(0, 1); |
1534 |
+ } |
| 1377 |
- } else { |
1535 |
+ |
| 1378 |
- monitor.selected_tags_index ^= 1; |
1536 |
+ if let Some(name) = layout_name { |
| 1379 |
- monitor.tagset[monitor.selected_tags_index] = new_tagset; |
1537 |
+ if let Ok(layout) = layout_from_str(&name) { |
|
|
1538 |
+ self.layout = layout; |
|
|
1539 |
+ } |
|
|
1540 |
+ } |
|
|
1541 |
+ |
|
|
1542 |
+ if toggle_bar { |
|
|
1543 |
+ self.toggle_bar()?; |
| 1380 |
} |
1544 |
} |
| 1381 |
|
1545 |
|
| 1382 |
self.save_selected_tags()?; |
1546 |
self.save_selected_tags()?; |
| @@ -1392,19 +1556,50 @@ impl WindowManager { |
| 1392 |
return Ok(()); |
1556 |
return Ok(()); |
| 1393 |
} |
1557 |
} |
| 1394 |
|
1558 |
|
| 1395 |
- let monitor = match self.monitors.get_mut(self.selected_monitor) { |
1559 |
+ let num_tags = self.config.tags.len(); |
| 1396 |
- Some(m) => m, |
1560 |
+ let all_tags_mask = (1u32 << num_tags) - 1; |
| 1397 |
- None => return Ok(()), |
1561 |
+ let mut layout_name: Option<String> = None; |
| 1398 |
- }; |
1562 |
+ let mut toggle_bar = false; |
| 1399 |
|
1563 |
|
| 1400 |
- let mask = tag_mask(tag_index); |
1564 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 1401 |
- let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask; |
1565 |
+ let mask = tag_mask(tag_index); |
|
|
1566 |
+ let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask; |
| 1402 |
|
1567 |
|
| 1403 |
- if new_tagset == 0 { |
1568 |
+ if new_tagset == 0 { |
| 1404 |
- return Ok(()); |
1569 |
+ return Ok(()); |
|
|
1570 |
+ } |
|
|
1571 |
+ |
|
|
1572 |
+ monitor.tagset[monitor.selected_tags_index] = new_tagset; |
|
|
1573 |
+ |
|
|
1574 |
+ if let Some(ref mut pertag) = monitor.pertag { |
|
|
1575 |
+ if new_tagset == all_tags_mask { |
|
|
1576 |
+ pertag.previous_tag = pertag.current_tag; |
|
|
1577 |
+ pertag.current_tag = 0; |
|
|
1578 |
+ } |
|
|
1579 |
+ |
|
|
1580 |
+ if pertag.current_tag > 0 && (new_tagset & (1 << (pertag.current_tag - 1))) == 0 { |
|
|
1581 |
+ pertag.previous_tag = pertag.current_tag; |
|
|
1582 |
+ pertag.current_tag = (new_tagset.trailing_zeros() as usize) + 1; |
|
|
1583 |
+ } |
|
|
1584 |
+ |
|
|
1585 |
+ monitor.num_master = pertag.num_masters[pertag.current_tag]; |
|
|
1586 |
+ monitor.master_factor = pertag.master_factors[pertag.current_tag]; |
|
|
1587 |
+ layout_name = Some(pertag.layouts[pertag.current_tag].clone()); |
|
|
1588 |
+ if monitor.show_bar != pertag.show_bars[pertag.current_tag] { |
|
|
1589 |
+ toggle_bar = true; |
|
|
1590 |
+ } |
|
|
1591 |
+ } |
| 1405 |
} |
1592 |
} |
| 1406 |
|
1593 |
|
| 1407 |
- monitor.tagset[monitor.selected_tags_index] = new_tagset; |
1594 |
+ if let Some(name) = layout_name { |
|
|
1595 |
+ if let Ok(layout) = layout_from_str(&name) { |
|
|
1596 |
+ self.layout = layout; |
|
|
1597 |
+ } |
|
|
1598 |
+ } |
|
|
1599 |
+ |
|
|
1600 |
+ if toggle_bar { |
|
|
1601 |
+ self.toggle_bar()?; |
|
|
1602 |
+ } |
| 1408 |
|
1603 |
|
| 1409 |
self.save_selected_tags()?; |
1604 |
self.save_selected_tags()?; |
| 1410 |
self.focus(None)?; |
1605 |
self.focus(None)?; |
| @@ -1687,156 +1882,36 @@ impl WindowManager { |
| 1687 |
} |
1882 |
} |
| 1688 |
} |
1883 |
} |
| 1689 |
|
1884 |
|
| 1690 |
- fn fullscreen(&mut self) -> WmResult<()> { |
1885 |
+ fn get_window_atom_list_property(&self, window: Window, property: Atom) -> WmResult<Vec<Atom>> { |
| 1691 |
- if self.show_bar { |
1886 |
+ let reply = self |
| 1692 |
- let Some(focused_window) = self |
1887 |
+ .connection |
| 1693 |
- .monitors |
1888 |
+ .get_property(false, window, property, AtomEnum::ATOM, 0, 32)? |
| 1694 |
- .get(self.selected_monitor) |
1889 |
+ .reply(); |
| 1695 |
- .and_then(|m| m.selected_client) |
|
|
| 1696 |
- else { |
|
|
| 1697 |
- return Ok(()); |
|
|
| 1698 |
- }; |
|
|
| 1699 |
- |
|
|
| 1700 |
- self.fullscreen_windows.insert(focused_window); |
|
|
| 1701 |
- |
|
|
| 1702 |
- let windows: Vec<Window> = self |
|
|
| 1703 |
- .windows |
|
|
| 1704 |
- .iter() |
|
|
| 1705 |
- .filter(|&&w| self.is_window_visible(w)) |
|
|
| 1706 |
- .copied() |
|
|
| 1707 |
- .collect(); |
|
|
| 1708 |
- |
|
|
| 1709 |
- for window in &windows { |
|
|
| 1710 |
- if let Ok(geom) = self.connection.get_geometry(*window)?.reply() { |
|
|
| 1711 |
- self.floating_geometry_before_fullscreen.insert( |
|
|
| 1712 |
- *window, |
|
|
| 1713 |
- (geom.x, geom.y, geom.width, geom.height, geom.border_width), |
|
|
| 1714 |
- ); |
|
|
| 1715 |
- } |
|
|
| 1716 |
- } |
|
|
| 1717 |
- |
|
|
| 1718 |
- self.last_layout = Some(self.layout.name()); |
|
|
| 1719 |
- if let Ok(layout) = layout_from_str("monocle") { |
|
|
| 1720 |
- self.layout = layout; |
|
|
| 1721 |
- } |
|
|
| 1722 |
- self.toggle_bar()?; |
|
|
| 1723 |
- self.apply_layout()?; |
|
|
| 1724 |
- |
|
|
| 1725 |
- for window in &windows { |
|
|
| 1726 |
- self.connection.configure_window( |
|
|
| 1727 |
- *window, |
|
|
| 1728 |
- &x11rb::protocol::xproto::ConfigureWindowAux::new().border_width(0), |
|
|
| 1729 |
- )?; |
|
|
| 1730 |
- } |
|
|
| 1731 |
- |
|
|
| 1732 |
- let border_width = self.config.border_width; |
|
|
| 1733 |
- let floating_windows: Vec<Window> = windows |
|
|
| 1734 |
- .iter() |
|
|
| 1735 |
- .filter(|&&w| self.floating_windows.contains(&w)) |
|
|
| 1736 |
- .copied() |
|
|
| 1737 |
- .collect(); |
|
|
| 1738 |
- |
|
|
| 1739 |
- for window in floating_windows { |
|
|
| 1740 |
- let monitor_idx = self |
|
|
| 1741 |
- .clients |
|
|
| 1742 |
- .get(&window) |
|
|
| 1743 |
- .map(|c| c.monitor_index) |
|
|
| 1744 |
- .unwrap_or(self.selected_monitor); |
|
|
| 1745 |
- let monitor = &self.monitors[monitor_idx]; |
|
|
| 1746 |
- |
|
|
| 1747 |
- let (outer_gap_h, outer_gap_v) = if self.gaps_enabled { |
|
|
| 1748 |
- ( |
|
|
| 1749 |
- self.config.gap_outer_horizontal, |
|
|
| 1750 |
- self.config.gap_outer_vertical, |
|
|
| 1751 |
- ) |
|
|
| 1752 |
- } else { |
|
|
| 1753 |
- (0, 0) |
|
|
| 1754 |
- }; |
|
|
| 1755 |
- |
|
|
| 1756 |
- let window_x = monitor.screen_x + outer_gap_h as i32; |
|
|
| 1757 |
- let window_y = monitor.screen_y + outer_gap_v as i32; |
|
|
| 1758 |
- let window_width = monitor |
|
|
| 1759 |
- .screen_width |
|
|
| 1760 |
- .saturating_sub(2 * outer_gap_h as i32) |
|
|
| 1761 |
- .saturating_sub(2 * border_width as i32); |
|
|
| 1762 |
- let window_height = monitor |
|
|
| 1763 |
- .screen_height |
|
|
| 1764 |
- .saturating_sub(2 * outer_gap_v as i32) |
|
|
| 1765 |
- .saturating_sub(2 * border_width as i32); |
|
|
| 1766 |
- |
|
|
| 1767 |
- self.connection.configure_window( |
|
|
| 1768 |
- window, |
|
|
| 1769 |
- &x11rb::protocol::xproto::ConfigureWindowAux::new() |
|
|
| 1770 |
- .x(window_x) |
|
|
| 1771 |
- .y(window_y) |
|
|
| 1772 |
- .width(window_width as u32) |
|
|
| 1773 |
- .height(window_height as u32), |
|
|
| 1774 |
- )?; |
|
|
| 1775 |
- } |
|
|
| 1776 |
- self.connection.flush()?; |
|
|
| 1777 |
- } else { |
|
|
| 1778 |
- let Some(focused_window) = self |
|
|
| 1779 |
- .monitors |
|
|
| 1780 |
- .get(self.selected_monitor) |
|
|
| 1781 |
- .and_then(|m| m.selected_client) |
|
|
| 1782 |
- else { |
|
|
| 1783 |
- return Ok(()); |
|
|
| 1784 |
- }; |
|
|
| 1785 |
- |
|
|
| 1786 |
- self.fullscreen_windows.remove(&focused_window); |
|
|
| 1787 |
- |
|
|
| 1788 |
- if let Some(last) = self.last_layout |
|
|
| 1789 |
- && let Ok(layout) = layout_from_str(last) |
|
|
| 1790 |
- { |
|
|
| 1791 |
- self.layout = layout; |
|
|
| 1792 |
- } |
|
|
| 1793 |
- |
|
|
| 1794 |
- let windows_to_restore: Vec<Window> = self |
|
|
| 1795 |
- .floating_geometry_before_fullscreen |
|
|
| 1796 |
- .keys() |
|
|
| 1797 |
- .copied() |
|
|
| 1798 |
- .collect(); |
|
|
| 1799 |
- |
|
|
| 1800 |
- for window in windows_to_restore { |
|
|
| 1801 |
- if let Some(&(x, y, width, height, border_width)) = |
|
|
| 1802 |
- self.floating_geometry_before_fullscreen.get(&window) |
|
|
| 1803 |
- { |
|
|
| 1804 |
- self.connection.configure_window( |
|
|
| 1805 |
- window, |
|
|
| 1806 |
- &ConfigureWindowAux::new() |
|
|
| 1807 |
- .x(x as i32) |
|
|
| 1808 |
- .y(y as i32) |
|
|
| 1809 |
- .width(width as u32) |
|
|
| 1810 |
- .height(height as u32) |
|
|
| 1811 |
- .border_width(border_width as u32), |
|
|
| 1812 |
- )?; |
|
|
| 1813 |
- |
|
|
| 1814 |
- if let Some(c) = self.clients.get_mut(&window) { |
|
|
| 1815 |
- c.x_position = x; |
|
|
| 1816 |
- c.y_position = y; |
|
|
| 1817 |
- c.width = width; |
|
|
| 1818 |
- c.height = height; |
|
|
| 1819 |
- c.border_width = border_width; |
|
|
| 1820 |
- } |
|
|
| 1821 |
|
1890 |
|
| 1822 |
- self.floating_geometry_before_fullscreen.remove(&window); |
1891 |
+ match reply { |
| 1823 |
- } |
1892 |
+ Ok(prop) if !prop.value.is_empty() => { |
|
|
1893 |
+ let atoms: Vec<Atom> = prop |
|
|
1894 |
+ .value |
|
|
1895 |
+ .chunks_exact(4) |
|
|
1896 |
+ .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])) |
|
|
1897 |
+ .collect(); |
|
|
1898 |
+ Ok(atoms) |
| 1824 |
} |
1899 |
} |
| 1825 |
- self.connection.flush()?; |
1900 |
+ _ => Ok(Vec::new()), |
|
|
1901 |
+ } |
|
|
1902 |
+ } |
| 1826 |
|
1903 |
|
| 1827 |
- self.toggle_bar()?; |
1904 |
+ fn fullscreen(&mut self) -> WmResult<()> { |
|
|
1905 |
+ let Some(focused_window) = self |
|
|
1906 |
+ .monitors |
|
|
1907 |
+ .get(self.selected_monitor) |
|
|
1908 |
+ .and_then(|m| m.selected_client) |
|
|
1909 |
+ else { |
|
|
1910 |
+ return Ok(()); |
|
|
1911 |
+ }; |
| 1828 |
|
1912 |
|
| 1829 |
- if self.layout.name() != "normie" { |
1913 |
+ let is_fullscreen = self.fullscreen_windows.contains(&focused_window); |
| 1830 |
- self.apply_layout()?; |
1914 |
+ self.set_window_fullscreen(focused_window, !is_fullscreen)?; |
| 1831 |
- } else if let Some(bar) = self.bars.get(self.selected_monitor) { |
|
|
| 1832 |
- self.connection.configure_window( |
|
|
| 1833 |
- bar.window(), |
|
|
| 1834 |
- &x11rb::protocol::xproto::ConfigureWindowAux::new() |
|
|
| 1835 |
- .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), |
|
|
| 1836 |
- )?; |
|
|
| 1837 |
- self.connection.flush()?; |
|
|
| 1838 |
- } |
|
|
| 1839 |
- } |
|
|
| 1840 |
Ok(()) |
1915 |
Ok(()) |
| 1841 |
} |
1916 |
} |
| 1842 |
|
1917 |
|
| @@ -1864,11 +1939,16 @@ impl WindowManager { |
| 1864 |
client.is_fullscreen = true; |
1939 |
client.is_fullscreen = true; |
| 1865 |
client.old_state = client.is_floating; |
1940 |
client.old_state = client.is_floating; |
| 1866 |
client.old_border_width = client.border_width; |
1941 |
client.old_border_width = client.border_width; |
|
|
1942 |
+ client.old_x_position = client.x_position; |
|
|
1943 |
+ client.old_y_position = client.y_position; |
|
|
1944 |
+ client.old_width = client.width; |
|
|
1945 |
+ client.old_height = client.height; |
| 1867 |
client.border_width = 0; |
1946 |
client.border_width = 0; |
| 1868 |
client.is_floating = true; |
1947 |
client.is_floating = true; |
| 1869 |
} |
1948 |
} |
| 1870 |
|
1949 |
|
| 1871 |
self.fullscreen_windows.insert(window); |
1950 |
self.fullscreen_windows.insert(window); |
|
|
1951 |
+ self.floating_windows.insert(window); |
| 1872 |
|
1952 |
|
| 1873 |
self.connection.configure_window( |
1953 |
self.connection.configure_window( |
| 1874 |
window, |
1954 |
window, |
| @@ -1895,48 +1975,51 @@ impl WindowManager { |
| 1895 |
|
1975 |
|
| 1896 |
self.fullscreen_windows.remove(&window); |
1976 |
self.fullscreen_windows.remove(&window); |
| 1897 |
|
1977 |
|
|
|
1978 |
+ let (was_floating, restored_x, restored_y, restored_width, restored_height, restored_border) = self |
|
|
1979 |
+ .clients |
|
|
1980 |
+ .get(&window) |
|
|
1981 |
+ .map(|client| { |
|
|
1982 |
+ ( |
|
|
1983 |
+ client.old_state, |
|
|
1984 |
+ client.old_x_position, |
|
|
1985 |
+ client.old_y_position, |
|
|
1986 |
+ client.old_width, |
|
|
1987 |
+ client.old_height, |
|
|
1988 |
+ client.old_border_width, |
|
|
1989 |
+ ) |
|
|
1990 |
+ }) |
|
|
1991 |
+ .unwrap_or((false, 0, 0, 100, 100, 0)); |
|
|
1992 |
+ |
|
|
1993 |
+ if !was_floating { |
|
|
1994 |
+ self.floating_windows.remove(&window); |
|
|
1995 |
+ } |
|
|
1996 |
+ |
| 1898 |
if let Some(client) = self.clients.get_mut(&window) { |
1997 |
if let Some(client) = self.clients.get_mut(&window) { |
| 1899 |
client.is_fullscreen = false; |
1998 |
client.is_fullscreen = false; |
| 1900 |
client.is_floating = client.old_state; |
1999 |
client.is_floating = client.old_state; |
| 1901 |
client.border_width = client.old_border_width; |
2000 |
client.border_width = client.old_border_width; |
| 1902 |
- |
2001 |
+ client.x_position = client.old_x_position; |
| 1903 |
- let x = client.old_x_position; |
2002 |
+ client.y_position = client.old_y_position; |
| 1904 |
- let y = client.old_y_position; |
2003 |
+ client.width = client.old_width; |
| 1905 |
- let w = client.old_width; |
2004 |
+ client.height = client.old_height; |
| 1906 |
- let h = client.old_height; |
|
|
| 1907 |
- let bw = client.border_width; |
|
|
| 1908 |
- |
|
|
| 1909 |
- self.connection.configure_window( |
|
|
| 1910 |
- window, |
|
|
| 1911 |
- &x11rb::protocol::xproto::ConfigureWindowAux::new() |
|
|
| 1912 |
- .x(x as i32) |
|
|
| 1913 |
- .y(y as i32) |
|
|
| 1914 |
- .width(w as u32) |
|
|
| 1915 |
- .height(h as u32) |
|
|
| 1916 |
- .border_width(bw as u32), |
|
|
| 1917 |
- )?; |
|
|
| 1918 |
} |
2005 |
} |
| 1919 |
|
2006 |
|
|
|
2007 |
+ self.connection.configure_window( |
|
|
2008 |
+ window, |
|
|
2009 |
+ &ConfigureWindowAux::new() |
|
|
2010 |
+ .x(restored_x as i32) |
|
|
2011 |
+ .y(restored_y as i32) |
|
|
2012 |
+ .width(restored_width as u32) |
|
|
2013 |
+ .height(restored_height as u32) |
|
|
2014 |
+ .border_width(restored_border as u32), |
|
|
2015 |
+ )?; |
|
|
2016 |
+ |
| 1920 |
self.apply_layout()?; |
2017 |
self.apply_layout()?; |
| 1921 |
} |
2018 |
} |
| 1922 |
|
2019 |
|
| 1923 |
Ok(()) |
2020 |
Ok(()) |
| 1924 |
} |
2021 |
} |
| 1925 |
|
2022 |
|
| 1926 |
- fn toggle_bar(&mut self) -> WmResult<()> { |
|
|
| 1927 |
- self.show_bar = !self.show_bar; |
|
|
| 1928 |
- if let Some(bar) = self.bars.get(self.selected_monitor) { |
|
|
| 1929 |
- if self.show_bar { |
|
|
| 1930 |
- self.connection.map_window(bar.window())?; |
|
|
| 1931 |
- } else { |
|
|
| 1932 |
- self.connection.unmap_window(bar.window())?; |
|
|
| 1933 |
- } |
|
|
| 1934 |
- self.connection.flush()?; |
|
|
| 1935 |
- } |
|
|
| 1936 |
- self.apply_layout()?; |
|
|
| 1937 |
- Ok(()) |
|
|
| 1938 |
- } |
|
|
| 1939 |
- |
|
|
| 1940 |
fn get_transient_parent(&self, window: Window) -> Option<Window> { |
2023 |
fn get_transient_parent(&self, window: Window) -> Option<Window> { |
| 1941 |
self.connection |
2024 |
self.connection |
| 1942 |
.get_property( |
2025 |
.get_property( |
| @@ -1996,6 +2079,7 @@ impl WindowManager { |
| 1996 |
let mut rule_tags: Option<u32> = None; |
2079 |
let mut rule_tags: Option<u32> = None; |
| 1997 |
let mut rule_floating: Option<bool> = None; |
2080 |
let mut rule_floating: Option<bool> = None; |
| 1998 |
let mut rule_monitor: Option<usize> = None; |
2081 |
let mut rule_monitor: Option<usize> = None; |
|
|
2082 |
+ let mut rule_focus = false; |
| 1999 |
|
2083 |
|
| 2000 |
for rule in &self.config.window_rules { |
2084 |
for rule in &self.config.window_rules { |
| 2001 |
if rule.matches(&class, &instance, &title) { |
2085 |
if rule.matches(&class, &instance, &title) { |
| @@ -2008,6 +2092,7 @@ impl WindowManager { |
| 2008 |
if rule.monitor.is_some() { |
2092 |
if rule.monitor.is_some() { |
| 2009 |
rule_monitor = rule.monitor; |
2093 |
rule_monitor = rule.monitor; |
| 2010 |
} |
2094 |
} |
|
|
2095 |
+ rule_focus = rule.focus.unwrap_or(false); |
| 2011 |
} |
2096 |
} |
| 2012 |
} |
2097 |
} |
| 2013 |
|
2098 |
|
| @@ -2027,14 +2112,23 @@ impl WindowManager { |
| 2027 |
client.monitor_index = monitor_index; |
2112 |
client.monitor_index = monitor_index; |
| 2028 |
} |
2113 |
} |
| 2029 |
|
2114 |
|
| 2030 |
- let tags = rule_tags.unwrap_or_else(|| { |
2115 |
+ if let Some(tags) = rule_tags { |
| 2031 |
- self.monitors |
2116 |
+ client.tags = tags; |
| 2032 |
- .get(client.monitor_index) |
|
|
| 2033 |
- .map(|m| m.tagset[m.selected_tags_index]) |
|
|
| 2034 |
- .unwrap_or(tag_mask(0)) |
|
|
| 2035 |
- }); |
|
|
| 2036 |
|
2117 |
|
| 2037 |
- client.tags = tags; |
2118 |
+ if rule_focus { |
|
|
2119 |
+ let tag_index = unmask_tag(tags); |
|
|
2120 |
+ let monitor_tagset = self |
|
|
2121 |
+ .monitors |
|
|
2122 |
+ .get(client.monitor_index) |
|
|
2123 |
+ .map(|monitor| monitor.get_selected_tag()) |
|
|
2124 |
+ .unwrap_or(tag_mask(0)); |
|
|
2125 |
+ let is_tag_focused = monitor_tagset & tags == tags; |
|
|
2126 |
+ |
|
|
2127 |
+ if !is_tag_focused { |
|
|
2128 |
+ self.view_tag(tag_index)?; |
|
|
2129 |
+ } |
|
|
2130 |
+ } |
|
|
2131 |
+ } |
| 2038 |
} |
2132 |
} |
| 2039 |
|
2133 |
|
| 2040 |
Ok(()) |
2134 |
Ok(()) |
| @@ -2054,7 +2148,7 @@ impl WindowManager { |
| 2054 |
let tags = self |
2148 |
let tags = self |
| 2055 |
.monitors |
2149 |
.monitors |
| 2056 |
.get(self.selected_monitor) |
2150 |
.get(self.selected_monitor) |
| 2057 |
- .map(|m| m.tagset[m.selected_tags_index]) |
2151 |
+ .map(|monitor| monitor.tagset[monitor.selected_tags_index]) |
| 2058 |
.unwrap_or(tag_mask(0)); |
2152 |
.unwrap_or(tag_mask(0)); |
| 2059 |
(self.selected_monitor, tags) |
2153 |
(self.selected_monitor, tags) |
| 2060 |
} |
2154 |
} |
| @@ -2062,7 +2156,7 @@ impl WindowManager { |
| 2062 |
let tags = self |
2156 |
let tags = self |
| 2063 |
.monitors |
2157 |
.monitors |
| 2064 |
.get(self.selected_monitor) |
2158 |
.get(self.selected_monitor) |
| 2065 |
- .map(|m| m.tagset[m.selected_tags_index]) |
2159 |
+ .map(|monitor| monitor.tagset[monitor.selected_tags_index]) |
| 2066 |
.unwrap_or(tag_mask(0)); |
2160 |
.unwrap_or(tag_mask(0)); |
| 2067 |
(self.selected_monitor, tags) |
2161 |
(self.selected_monitor, tags) |
| 2068 |
}; |
2162 |
}; |
| @@ -2200,6 +2294,7 @@ impl WindowManager { |
| 2200 |
)?; |
2294 |
)?; |
| 2201 |
|
2295 |
|
| 2202 |
self.set_wm_state(window, 1)?; |
2296 |
self.set_wm_state(window, 1)?; |
|
|
2297 |
+ self.update_client_list()?; |
| 2203 |
|
2298 |
|
| 2204 |
let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(tags); |
2299 |
let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(tags); |
| 2205 |
let _ = self.save_client_tag(window, final_tags); |
2300 |
let _ = self.save_client_tag(window, final_tags); |
| @@ -2210,7 +2305,7 @@ impl WindowManager { |
| 2210 |
.get(self.selected_monitor) |
2305 |
.get(self.selected_monitor) |
| 2211 |
.and_then(|m| m.selected_client) |
2306 |
.and_then(|m| m.selected_client) |
| 2212 |
{ |
2307 |
{ |
| 2213 |
- self.unfocus(old_sel)?; |
2308 |
+ self.unfocus(old_sel, false)?; |
| 2214 |
} |
2309 |
} |
| 2215 |
|
2310 |
|
| 2216 |
if let Some(m) = self.monitors.get_mut(client_monitor) { |
2311 |
if let Some(m) = self.monitors.get_mut(client_monitor) { |
| @@ -2223,7 +2318,7 @@ impl WindowManager { |
| 2223 |
|
2318 |
|
| 2224 |
self.apply_layout()?; |
2319 |
self.apply_layout()?; |
| 2225 |
self.connection.map_window(window)?; |
2320 |
self.connection.map_window(window)?; |
| 2226 |
- self.focus(Some(window))?; |
2321 |
+ self.focus(None)?; |
| 2227 |
self.update_bar()?; |
2322 |
self.update_bar()?; |
| 2228 |
|
2323 |
|
| 2229 |
if self.layout.name() == "tabbed" { |
2324 |
if self.layout.name() == "tabbed" { |
| @@ -2234,108 +2329,190 @@ impl WindowManager { |
| 2234 |
} |
2329 |
} |
| 2235 |
|
2330 |
|
| 2236 |
pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
2331 |
pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
| 2237 |
- let old_focused = self.previous_focused; |
2332 |
+ let never_focus = self |
|
|
2333 |
+ .clients |
|
|
2334 |
+ .get(&window) |
|
|
2335 |
+ .map(|c| c.never_focus) |
|
|
2336 |
+ .unwrap_or(false); |
| 2238 |
|
2337 |
|
| 2239 |
- if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
2338 |
+ if !never_focus { |
| 2240 |
- monitor.selected_client = Some(window); |
2339 |
+ self.connection |
|
|
2340 |
+ .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?; |
|
|
2341 |
+ |
|
|
2342 |
+ self.connection.change_property( |
|
|
2343 |
+ PropMode::REPLACE, |
|
|
2344 |
+ self.root, |
|
|
2345 |
+ self.atoms.net_active_window, |
|
|
2346 |
+ AtomEnum::WINDOW, |
|
|
2347 |
+ 32, |
|
|
2348 |
+ 1, |
|
|
2349 |
+ &window.to_ne_bytes(), |
|
|
2350 |
+ )?; |
| 2241 |
} |
2351 |
} |
| 2242 |
|
2352 |
|
| 2243 |
- self.connection |
2353 |
+ let _ = self.send_event(window, self.atoms.wm_take_focus); |
| 2244 |
- .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?; |
|
|
| 2245 |
self.connection.flush()?; |
2354 |
self.connection.flush()?; |
| 2246 |
|
2355 |
|
| 2247 |
- self.update_focus_visuals(old_focused, window)?; |
2356 |
+ Ok(()) |
| 2248 |
- self.previous_focused = Some(window); |
2357 |
+ } |
| 2249 |
|
2358 |
|
| 2250 |
- if self.layout.name() == "tabbed" { |
2359 |
+ fn grabbuttons(&self, window: Window, focused: bool) -> WmResult<()> { |
| 2251 |
- self.update_tab_bars()?; |
2360 |
+ self.connection.ungrab_button(ButtonIndex::ANY, window, ModMask::ANY)?; |
|
|
2361 |
+ |
|
|
2362 |
+ if !focused { |
|
|
2363 |
+ self.connection.grab_button( |
|
|
2364 |
+ false, |
|
|
2365 |
+ window, |
|
|
2366 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
|
2367 |
+ GrabMode::SYNC, |
|
|
2368 |
+ GrabMode::SYNC, |
|
|
2369 |
+ x11rb::NONE, |
|
|
2370 |
+ x11rb::NONE, |
|
|
2371 |
+ ButtonIndex::ANY, |
|
|
2372 |
+ ModMask::ANY, |
|
|
2373 |
+ )?; |
|
|
2374 |
+ } |
|
|
2375 |
+ |
|
|
2376 |
+ let ignore_modifiers = [ |
|
|
2377 |
+ 0u16, |
|
|
2378 |
+ u16::from(ModMask::LOCK), |
|
|
2379 |
+ u16::from(ModMask::M2), |
|
|
2380 |
+ u16::from(ModMask::LOCK | ModMask::M2), |
|
|
2381 |
+ ]; |
|
|
2382 |
+ |
|
|
2383 |
+ for &ignore_mask in &ignore_modifiers { |
|
|
2384 |
+ let grab_mask = u16::from(self.config.modkey) | ignore_mask; |
|
|
2385 |
+ |
|
|
2386 |
+ self.connection.grab_button( |
|
|
2387 |
+ false, |
|
|
2388 |
+ window, |
|
|
2389 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
|
2390 |
+ GrabMode::ASYNC, |
|
|
2391 |
+ GrabMode::SYNC, |
|
|
2392 |
+ x11rb::NONE, |
|
|
2393 |
+ x11rb::NONE, |
|
|
2394 |
+ ButtonIndex::M1, |
|
|
2395 |
+ grab_mask.into(), |
|
|
2396 |
+ )?; |
|
|
2397 |
+ |
|
|
2398 |
+ self.connection.grab_button( |
|
|
2399 |
+ false, |
|
|
2400 |
+ window, |
|
|
2401 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
|
2402 |
+ GrabMode::ASYNC, |
|
|
2403 |
+ GrabMode::SYNC, |
|
|
2404 |
+ x11rb::NONE, |
|
|
2405 |
+ x11rb::NONE, |
|
|
2406 |
+ ButtonIndex::M3, |
|
|
2407 |
+ grab_mask.into(), |
|
|
2408 |
+ )?; |
| 2252 |
} |
2409 |
} |
| 2253 |
|
2410 |
|
| 2254 |
Ok(()) |
2411 |
Ok(()) |
| 2255 |
} |
2412 |
} |
| 2256 |
|
2413 |
|
| 2257 |
- fn unfocus(&self, window: Window) -> WmResult<()> { |
2414 |
+ fn unfocus(&self, window: Window, reset_input_focus: bool) -> WmResult<()> { |
| 2258 |
if !self.windows.contains(&window) { |
2415 |
if !self.windows.contains(&window) { |
| 2259 |
return Ok(()); |
2416 |
return Ok(()); |
| 2260 |
} |
2417 |
} |
| 2261 |
|
2418 |
|
|
|
2419 |
+ self.grabbuttons(window, false)?; |
|
|
2420 |
+ |
| 2262 |
self.connection.change_window_attributes( |
2421 |
self.connection.change_window_attributes( |
| 2263 |
window, |
2422 |
window, |
| 2264 |
&ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused), |
2423 |
&ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused), |
| 2265 |
)?; |
2424 |
)?; |
| 2266 |
|
2425 |
|
| 2267 |
- self.connection.grab_button( |
2426 |
+ if reset_input_focus { |
| 2268 |
- false, |
2427 |
+ self.connection.set_input_focus( |
| 2269 |
- window, |
2428 |
+ InputFocus::POINTER_ROOT, |
| 2270 |
- EventMask::BUTTON_PRESS, |
2429 |
+ self.root, |
| 2271 |
- GrabMode::SYNC, |
2430 |
+ x11rb::CURRENT_TIME, |
| 2272 |
- GrabMode::SYNC, |
2431 |
+ )?; |
| 2273 |
- x11rb::NONE, |
2432 |
+ self.connection.delete_property(self.root, self.atoms.net_active_window)?; |
| 2274 |
- x11rb::NONE, |
2433 |
+ } |
| 2275 |
- ButtonIndex::ANY, |
|
|
| 2276 |
- ModMask::ANY, |
|
|
| 2277 |
- )?; |
|
|
| 2278 |
|
2434 |
|
| 2279 |
Ok(()) |
2435 |
Ok(()) |
| 2280 |
} |
2436 |
} |
| 2281 |
|
2437 |
|
| 2282 |
fn focus(&mut self, window: Option<Window>) -> WmResult<()> { |
2438 |
fn focus(&mut self, window: Option<Window>) -> WmResult<()> { |
| 2283 |
- let monitor = self.monitors.get_mut(self.selected_monitor).unwrap(); |
2439 |
+ let old_selected = self |
| 2284 |
- let old_selected = monitor.selected_client; |
2440 |
+ .monitors |
|
|
2441 |
+ .get(self.selected_monitor) |
|
|
2442 |
+ .and_then(|m| m.selected_client); |
| 2285 |
|
2443 |
|
| 2286 |
- if let Some(old_win) = old_selected |
2444 |
+ let mut focus_client = window; |
| 2287 |
- && old_selected != window |
2445 |
+ if focus_client.is_none() |
|
|
2446 |
+ || focus_client.is_some_and(|w| !self.is_visible(w)) |
| 2288 |
{ |
2447 |
{ |
| 2289 |
- self.unfocus(old_win)?; |
|
|
| 2290 |
- } |
|
|
| 2291 |
- |
|
|
| 2292 |
- let mut win = window; |
|
|
| 2293 |
- if win.is_none() || !self.is_visible(win.unwrap()) { |
|
|
| 2294 |
let mut current = self |
2448 |
let mut current = self |
| 2295 |
.monitors |
2449 |
.monitors |
| 2296 |
.get(self.selected_monitor) |
2450 |
.get(self.selected_monitor) |
| 2297 |
.and_then(|m| m.stack_head); |
2451 |
.and_then(|m| m.stack_head); |
| 2298 |
|
2452 |
|
|
|
2453 |
+ focus_client = None; |
| 2299 |
while let Some(w) = current { |
2454 |
while let Some(w) = current { |
| 2300 |
if self.is_visible(w) { |
2455 |
if self.is_visible(w) { |
| 2301 |
- win = Some(w); |
2456 |
+ focus_client = Some(w); |
| 2302 |
break; |
2457 |
break; |
| 2303 |
} |
2458 |
} |
| 2304 |
current = self.clients.get(&w).and_then(|c| c.stack_next); |
2459 |
current = self.clients.get(&w).and_then(|c| c.stack_next); |
| 2305 |
} |
2460 |
} |
| 2306 |
} |
2461 |
} |
| 2307 |
|
2462 |
|
| 2308 |
- if let Some(win) = win { |
2463 |
+ if old_selected != focus_client { |
| 2309 |
- if !self.windows.contains(&win) { |
2464 |
+ if let Some(old_win) = old_selected { |
| 2310 |
- return Ok(()); |
2465 |
+ self.unfocus(old_win, false)?; |
| 2311 |
- } |
|
|
| 2312 |
- |
|
|
| 2313 |
- if self.clients.get(&win).is_some_and(|c| c.is_urgent) { |
|
|
| 2314 |
- self.set_urgent(win, false)?; |
|
|
| 2315 |
} |
2466 |
} |
|
|
2467 |
+ } |
| 2316 |
|
2468 |
|
|
|
2469 |
+ if let Some(win) = focus_client { |
| 2317 |
let monitor_idx = self |
2470 |
let monitor_idx = self |
| 2318 |
.clients |
2471 |
.clients |
| 2319 |
.get(&win) |
2472 |
.get(&win) |
| 2320 |
.map(|c| c.monitor_index) |
2473 |
.map(|c| c.monitor_index) |
| 2321 |
.unwrap_or(self.selected_monitor); |
2474 |
.unwrap_or(self.selected_monitor); |
|
|
2475 |
+ |
| 2322 |
if monitor_idx != self.selected_monitor { |
2476 |
if monitor_idx != self.selected_monitor { |
| 2323 |
self.selected_monitor = monitor_idx; |
2477 |
self.selected_monitor = monitor_idx; |
| 2324 |
} |
2478 |
} |
| 2325 |
|
2479 |
|
|
|
2480 |
+ if self.clients.get(&win).is_some_and(|c| c.is_urgent) { |
|
|
2481 |
+ self.set_urgent(win, false)?; |
|
|
2482 |
+ } |
|
|
2483 |
+ |
| 2326 |
self.detach_stack(win); |
2484 |
self.detach_stack(win); |
| 2327 |
self.attach_stack(win, monitor_idx); |
2485 |
self.attach_stack(win, monitor_idx); |
| 2328 |
|
2486 |
|
|
|
2487 |
+ self.grabbuttons(win, true)?; |
|
|
2488 |
+ |
| 2329 |
self.connection.change_window_attributes( |
2489 |
self.connection.change_window_attributes( |
| 2330 |
win, |
2490 |
win, |
| 2331 |
&ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused), |
2491 |
&ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused), |
| 2332 |
)?; |
2492 |
)?; |
| 2333 |
|
2493 |
|
| 2334 |
- self.connection |
2494 |
+ let never_focus = self |
| 2335 |
- .ungrab_button(ButtonIndex::ANY, win, ModMask::ANY)?; |
2495 |
+ .clients |
|
|
2496 |
+ .get(&win) |
|
|
2497 |
+ .map(|client| client.never_focus) |
|
|
2498 |
+ .unwrap_or(false); |
| 2336 |
|
2499 |
|
| 2337 |
- self.connection |
2500 |
+ if !never_focus { |
| 2338 |
- .set_input_focus(InputFocus::POINTER_ROOT, win, x11rb::CURRENT_TIME)?; |
2501 |
+ self.connection |
|
|
2502 |
+ .set_input_focus(InputFocus::POINTER_ROOT, win, x11rb::CURRENT_TIME)?; |
|
|
2503 |
+ |
|
|
2504 |
+ self.connection.change_property( |
|
|
2505 |
+ PropMode::REPLACE, |
|
|
2506 |
+ self.root, |
|
|
2507 |
+ self.atoms.net_active_window, |
|
|
2508 |
+ AtomEnum::WINDOW, |
|
|
2509 |
+ 32, |
|
|
2510 |
+ 1, |
|
|
2511 |
+ &win.to_ne_bytes(), |
|
|
2512 |
+ )?; |
|
|
2513 |
+ } |
|
|
2514 |
+ |
|
|
2515 |
+ let _ = self.send_event(win, self.atoms.wm_take_focus); |
| 2339 |
|
2516 |
|
| 2340 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
2517 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 2341 |
monitor.selected_client = Some(win); |
2518 |
monitor.selected_client = Some(win); |
| @@ -2349,6 +2526,9 @@ impl WindowManager { |
| 2349 |
x11rb::CURRENT_TIME, |
2526 |
x11rb::CURRENT_TIME, |
| 2350 |
)?; |
2527 |
)?; |
| 2351 |
|
2528 |
|
|
|
2529 |
+ self.connection |
|
|
2530 |
+ .delete_property(self.root, self.atoms.net_active_window)?; |
|
|
2531 |
+ |
| 2352 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
2532 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 2353 |
monitor.selected_client = None; |
2533 |
monitor.selected_client = None; |
| 2354 |
} |
2534 |
} |
| @@ -2413,25 +2593,35 @@ impl WindowManager { |
| 2413 |
|
2593 |
|
| 2414 |
fn focusstack(&mut self, direction: i32) -> WmResult<()> { |
2594 |
fn focusstack(&mut self, direction: i32) -> WmResult<()> { |
| 2415 |
let monitor = match self.monitors.get(self.selected_monitor) { |
2595 |
let monitor = match self.monitors.get(self.selected_monitor) { |
| 2416 |
- Some(m) => m, |
2596 |
+ Some(monitor) => monitor, |
| 2417 |
None => return Ok(()), |
2597 |
None => return Ok(()), |
| 2418 |
}; |
2598 |
}; |
| 2419 |
|
2599 |
|
| 2420 |
- let selected = match monitor.selected_client { |
2600 |
+ let selected_window = match monitor.selected_client { |
| 2421 |
- Some(win) => win, |
2601 |
+ Some(window) => window, |
| 2422 |
None => return Ok(()), |
2602 |
None => return Ok(()), |
| 2423 |
}; |
2603 |
}; |
| 2424 |
|
2604 |
|
|
|
2605 |
+ let selected_is_fullscreen = self |
|
|
2606 |
+ .clients |
|
|
2607 |
+ .get(&selected_window) |
|
|
2608 |
+ .map(|client| client.is_fullscreen) |
|
|
2609 |
+ .unwrap_or(false); |
|
|
2610 |
+ |
|
|
2611 |
+ if selected_is_fullscreen { |
|
|
2612 |
+ return Ok(()); |
|
|
2613 |
+ } |
|
|
2614 |
+ |
| 2425 |
let selected_tags = monitor.tagset[monitor.selected_tags_index]; |
2615 |
let selected_tags = monitor.tagset[monitor.selected_tags_index]; |
| 2426 |
|
2616 |
|
| 2427 |
let mut stack_windows: Vec<Window> = Vec::new(); |
2617 |
let mut stack_windows: Vec<Window> = Vec::new(); |
| 2428 |
- let mut current = monitor.clients_head; |
2618 |
+ let mut current_window = monitor.clients_head; |
| 2429 |
- while let Some(win) = current { |
2619 |
+ while let Some(window) = current_window { |
| 2430 |
- if let Some(client) = self.clients.get(&win) { |
2620 |
+ if let Some(client) = self.clients.get(&window) { |
| 2431 |
if client.tags & selected_tags != 0 && !client.is_floating { |
2621 |
if client.tags & selected_tags != 0 && !client.is_floating { |
| 2432 |
- stack_windows.push(win); |
2622 |
+ stack_windows.push(window); |
| 2433 |
} |
2623 |
} |
| 2434 |
- current = client.next; |
2624 |
+ current_window = client.next; |
| 2435 |
} else { |
2625 |
} else { |
| 2436 |
break; |
2626 |
break; |
| 2437 |
} |
2627 |
} |
| @@ -2441,17 +2631,19 @@ impl WindowManager { |
| 2441 |
return Ok(()); |
2631 |
return Ok(()); |
| 2442 |
} |
2632 |
} |
| 2443 |
|
2633 |
|
| 2444 |
- let current_idx = stack_windows.iter().position(|&w| w == selected); |
2634 |
+ let current_index = stack_windows |
|
|
2635 |
+ .iter() |
|
|
2636 |
+ .position(|&window| window == selected_window); |
| 2445 |
|
2637 |
|
| 2446 |
- let next_window = if let Some(idx) = current_idx { |
2638 |
+ let next_window = if let Some(index) = current_index { |
| 2447 |
if direction > 0 { |
2639 |
if direction > 0 { |
| 2448 |
- if idx + 1 < stack_windows.len() { |
2640 |
+ if index + 1 < stack_windows.len() { |
| 2449 |
- stack_windows[idx + 1] |
2641 |
+ stack_windows[index + 1] |
| 2450 |
} else { |
2642 |
} else { |
| 2451 |
stack_windows[0] |
2643 |
stack_windows[0] |
| 2452 |
} |
2644 |
} |
| 2453 |
- } else if idx > 0 { |
2645 |
+ } else if index > 0 { |
| 2454 |
- stack_windows[idx - 1] |
2646 |
+ stack_windows[index - 1] |
| 2455 |
} else { |
2647 |
} else { |
| 2456 |
stack_windows[stack_windows.len() - 1] |
2648 |
stack_windows[stack_windows.len() - 1] |
| 2457 |
} |
2649 |
} |
| @@ -2465,6 +2657,7 @@ impl WindowManager { |
| 2465 |
self.scroll_to_window(next_window, true)?; |
2657 |
self.scroll_to_window(next_window, true)?; |
| 2466 |
} |
2658 |
} |
| 2467 |
|
2659 |
|
|
|
2660 |
+ self.restack()?; |
| 2468 |
self.update_tab_bars()?; |
2661 |
self.update_tab_bars()?; |
| 2469 |
|
2662 |
|
| 2470 |
Ok(()) |
2663 |
Ok(()) |
| @@ -2618,7 +2811,7 @@ impl WindowManager { |
| 2618 |
.and_then(|m| m.selected_client); |
2811 |
.and_then(|m| m.selected_client); |
| 2619 |
|
2812 |
|
| 2620 |
if let Some(win) = old_selected { |
2813 |
if let Some(win) = old_selected { |
| 2621 |
- self.unfocus(win)?; |
2814 |
+ self.unfocus(win, true)?; |
| 2622 |
} |
2815 |
} |
| 2623 |
|
2816 |
|
| 2624 |
self.selected_monitor = target_monitor; |
2817 |
self.selected_monitor = target_monitor; |
| @@ -2652,39 +2845,6 @@ impl WindowManager { |
| 2652 |
Ok(()) |
2845 |
Ok(()) |
| 2653 |
} |
2846 |
} |
| 2654 |
|
2847 |
|
| 2655 |
- fn update_focus_visuals( |
|
|
| 2656 |
- &self, |
|
|
| 2657 |
- old_focused: Option<Window>, |
|
|
| 2658 |
- new_focused: Window, |
|
|
| 2659 |
- ) -> WmResult<()> { |
|
|
| 2660 |
- if let Some(old_win) = old_focused |
|
|
| 2661 |
- && old_win != new_focused |
|
|
| 2662 |
- { |
|
|
| 2663 |
- self.connection.configure_window( |
|
|
| 2664 |
- old_win, |
|
|
| 2665 |
- &ConfigureWindowAux::new().border_width(self.config.border_width), |
|
|
| 2666 |
- )?; |
|
|
| 2667 |
- |
|
|
| 2668 |
- self.connection.change_window_attributes( |
|
|
| 2669 |
- old_win, |
|
|
| 2670 |
- &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused), |
|
|
| 2671 |
- )?; |
|
|
| 2672 |
- } |
|
|
| 2673 |
- |
|
|
| 2674 |
- self.connection.configure_window( |
|
|
| 2675 |
- new_focused, |
|
|
| 2676 |
- &ConfigureWindowAux::new().border_width(self.config.border_width), |
|
|
| 2677 |
- )?; |
|
|
| 2678 |
- |
|
|
| 2679 |
- self.connection.change_window_attributes( |
|
|
| 2680 |
- new_focused, |
|
|
| 2681 |
- &ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused), |
|
|
| 2682 |
- )?; |
|
|
| 2683 |
- |
|
|
| 2684 |
- self.connection.flush()?; |
|
|
| 2685 |
- Ok(()) |
|
|
| 2686 |
- } |
|
|
| 2687 |
- |
|
|
| 2688 |
fn drag_window(&mut self, window: Window) -> WmResult<()> { |
2848 |
fn drag_window(&mut self, window: Window) -> WmResult<()> { |
| 2689 |
let is_fullscreen = self |
2849 |
let is_fullscreen = self |
| 2690 |
.clients |
2850 |
.clients |
| @@ -3091,7 +3251,7 @@ impl WindowManager { |
| 3091 |
Ok(()) |
3251 |
Ok(()) |
| 3092 |
} |
3252 |
} |
| 3093 |
|
3253 |
|
| 3094 |
- fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> { |
3254 |
+ fn handle_event(&mut self, event: Event) -> WmResult<Control> { |
| 3095 |
match event { |
3255 |
match event { |
| 3096 |
Event::KeyPress(ref key_event) if key_event.event == self.overlay.window() => { |
3256 |
Event::KeyPress(ref key_event) if key_event.event == self.overlay.window() => { |
| 3097 |
if self.overlay.is_visible() |
3257 |
if self.overlay.is_visible() |
| @@ -3099,7 +3259,7 @@ impl WindowManager { |
| 3099 |
{ |
3259 |
{ |
| 3100 |
eprintln!("Failed to hide overlay: {:?}", error); |
3260 |
eprintln!("Failed to hide overlay: {:?}", error); |
| 3101 |
} |
3261 |
} |
| 3102 |
- return Ok(None); |
3262 |
+ return Ok(Control::Continue); |
| 3103 |
} |
3263 |
} |
| 3104 |
Event::ButtonPress(ref button_event) if button_event.event == self.overlay.window() => { |
3264 |
Event::ButtonPress(ref button_event) if button_event.event == self.overlay.window() => { |
| 3105 |
if self.overlay.is_visible() |
3265 |
if self.overlay.is_visible() |
| @@ -3107,7 +3267,7 @@ impl WindowManager { |
| 3107 |
{ |
3267 |
{ |
| 3108 |
eprintln!("Failed to hide overlay: {:?}", error); |
3268 |
eprintln!("Failed to hide overlay: {:?}", error); |
| 3109 |
} |
3269 |
} |
| 3110 |
- return Ok(None); |
3270 |
+ return Ok(Control::Continue); |
| 3111 |
} |
3271 |
} |
| 3112 |
Event::Expose(ref expose_event) if expose_event.window == self.overlay.window() => { |
3272 |
Event::Expose(ref expose_event) if expose_event.window == self.overlay.window() => { |
| 3113 |
if self.overlay.is_visible() |
3273 |
if self.overlay.is_visible() |
| @@ -3115,7 +3275,7 @@ impl WindowManager { |
| 3115 |
{ |
3275 |
{ |
| 3116 |
eprintln!("Failed to draw overlay: {:?}", error); |
3276 |
eprintln!("Failed to draw overlay: {:?}", error); |
| 3117 |
} |
3277 |
} |
| 3118 |
- return Ok(None); |
3278 |
+ return Ok(Control::Continue); |
| 3119 |
} |
3279 |
} |
| 3120 |
Event::KeyPress(ref e) if e.event == self.keybind_overlay.window() => { |
3280 |
Event::KeyPress(ref e) if e.event == self.keybind_overlay.window() => { |
| 3121 |
if self.keybind_overlay.is_visible() |
3281 |
if self.keybind_overlay.is_visible() |
| @@ -3133,12 +3293,12 @@ impl WindowManager { |
| 3133 |
} |
3293 |
} |
| 3134 |
} |
3294 |
} |
| 3135 |
} |
3295 |
} |
| 3136 |
- return Ok(None); |
3296 |
+ return Ok(Control::Continue); |
| 3137 |
} |
3297 |
} |
| 3138 |
Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => { |
3298 |
Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => { |
| 3139 |
self.connection |
3299 |
self.connection |
| 3140 |
.allow_events(Allow::REPLAY_POINTER, e.time)?; |
3300 |
.allow_events(Allow::REPLAY_POINTER, e.time)?; |
| 3141 |
- return Ok(None); |
3301 |
+ return Ok(Control::Continue); |
| 3142 |
} |
3302 |
} |
| 3143 |
Event::Expose(ref expose_event) |
3303 |
Event::Expose(ref expose_event) |
| 3144 |
if expose_event.window == self.keybind_overlay.window() => |
3304 |
if expose_event.window == self.keybind_overlay.window() => |
| @@ -3148,16 +3308,16 @@ impl WindowManager { |
| 3148 |
{ |
3308 |
{ |
| 3149 |
eprintln!("Failed to draw keybind overlay: {:?}", error); |
3309 |
eprintln!("Failed to draw keybind overlay: {:?}", error); |
| 3150 |
} |
3310 |
} |
| 3151 |
- return Ok(None); |
3311 |
+ return Ok(Control::Continue); |
| 3152 |
} |
3312 |
} |
| 3153 |
Event::MapRequest(event) => { |
3313 |
Event::MapRequest(event) => { |
| 3154 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
3314 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
| 3155 |
Ok(attrs) => attrs, |
3315 |
Ok(attrs) => attrs, |
| 3156 |
- Err(_) => return Ok(None), |
3316 |
+ Err(_) => return Ok(Control::Continue), |
| 3157 |
}; |
3317 |
}; |
| 3158 |
|
3318 |
|
| 3159 |
if attrs.override_redirect { |
3319 |
if attrs.override_redirect { |
| 3160 |
- return Ok(None); |
3320 |
+ return Ok(Control::Continue); |
| 3161 |
} |
3321 |
} |
| 3162 |
|
3322 |
|
| 3163 |
if !self.windows.contains(&event.window) { |
3323 |
if !self.windows.contains(&event.window) { |
| @@ -3166,21 +3326,21 @@ impl WindowManager { |
| 3166 |
} |
3326 |
} |
| 3167 |
Event::UnmapNotify(event) => { |
3327 |
Event::UnmapNotify(event) => { |
| 3168 |
if self.windows.contains(&event.window) && self.is_window_visible(event.window) { |
3328 |
if self.windows.contains(&event.window) && self.is_window_visible(event.window) { |
| 3169 |
- self.remove_window(event.window)?; |
3329 |
+ self.remove_window(event.window, false)?; |
| 3170 |
} |
3330 |
} |
| 3171 |
} |
3331 |
} |
| 3172 |
Event::DestroyNotify(event) => { |
3332 |
Event::DestroyNotify(event) => { |
| 3173 |
if self.windows.contains(&event.window) { |
3333 |
if self.windows.contains(&event.window) { |
| 3174 |
- self.remove_window(event.window)?; |
3334 |
+ self.remove_window(event.window, true)?; |
| 3175 |
} |
3335 |
} |
| 3176 |
} |
3336 |
} |
| 3177 |
Event::PropertyNotify(event) => { |
3337 |
Event::PropertyNotify(event) => { |
| 3178 |
if event.state == Property::DELETE { |
3338 |
if event.state == Property::DELETE { |
| 3179 |
- return Ok(None); |
3339 |
+ return Ok(Control::Continue); |
| 3180 |
} |
3340 |
} |
| 3181 |
|
3341 |
|
| 3182 |
if !self.clients.contains_key(&event.window) { |
3342 |
if !self.clients.contains_key(&event.window) { |
| 3183 |
- return Ok(None); |
3343 |
+ return Ok(Control::Continue); |
| 3184 |
} |
3344 |
} |
| 3185 |
|
3345 |
|
| 3186 |
if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() { |
3346 |
if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() { |
| @@ -3220,13 +3380,22 @@ impl WindowManager { |
| 3220 |
} |
3380 |
} |
| 3221 |
} |
3381 |
} |
| 3222 |
Event::EnterNotify(event) => { |
3382 |
Event::EnterNotify(event) => { |
| 3223 |
- if event.mode != x11rb::protocol::xproto::NotifyMode::NORMAL { |
3383 |
+ if event.mode != x11rb::protocol::xproto::NotifyMode::NORMAL |
| 3224 |
- return Ok(None); |
3384 |
+ || event.detail == x11rb::protocol::xproto::NotifyDetail::INFERIOR |
|
|
3385 |
+ { |
|
|
3386 |
+ return Ok(Control::Continue); |
| 3225 |
} |
3387 |
} |
| 3226 |
if self.windows.contains(&event.event) { |
3388 |
if self.windows.contains(&event.event) { |
| 3227 |
if let Some(client) = self.clients.get(&event.event) |
3389 |
if let Some(client) = self.clients.get(&event.event) |
| 3228 |
&& client.monitor_index != self.selected_monitor |
3390 |
&& client.monitor_index != self.selected_monitor |
| 3229 |
{ |
3391 |
{ |
|
|
3392 |
+ if let Some(old_selected) = self |
|
|
3393 |
+ .monitors |
|
|
3394 |
+ .get(self.selected_monitor) |
|
|
3395 |
+ .and_then(|monitor| monitor.selected_client) |
|
|
3396 |
+ { |
|
|
3397 |
+ self.unfocus(old_selected, false)?; |
|
|
3398 |
+ } |
| 3230 |
self.selected_monitor = client.monitor_index; |
3399 |
self.selected_monitor = client.monitor_index; |
| 3231 |
self.update_bar()?; |
3400 |
self.update_bar()?; |
| 3232 |
} |
3401 |
} |
| @@ -3236,26 +3405,30 @@ impl WindowManager { |
| 3236 |
} |
3405 |
} |
| 3237 |
Event::MotionNotify(event) => { |
3406 |
Event::MotionNotify(event) => { |
| 3238 |
if event.event != self.root { |
3407 |
if event.event != self.root { |
| 3239 |
- return Ok(None); |
3408 |
+ return Ok(Control::Continue); |
| 3240 |
} |
3409 |
} |
| 3241 |
|
3410 |
|
| 3242 |
if let Some(monitor_index) = |
3411 |
if let Some(monitor_index) = |
| 3243 |
self.get_monitor_at_point(event.root_x as i32, event.root_y as i32) |
3412 |
self.get_monitor_at_point(event.root_x as i32, event.root_y as i32) |
| 3244 |
&& monitor_index != self.selected_monitor |
3413 |
&& monitor_index != self.selected_monitor |
| 3245 |
{ |
3414 |
{ |
|
|
3415 |
+ if let Some(old_selected) = self |
|
|
3416 |
+ .monitors |
|
|
3417 |
+ .get(self.selected_monitor) |
|
|
3418 |
+ .and_then(|monitor| monitor.selected_client) |
|
|
3419 |
+ { |
|
|
3420 |
+ self.unfocus(old_selected, true)?; |
|
|
3421 |
+ } |
|
|
3422 |
+ |
| 3246 |
self.selected_monitor = monitor_index; |
3423 |
self.selected_monitor = monitor_index; |
|
|
3424 |
+ self.focus(None)?; |
| 3247 |
self.update_bar()?; |
3425 |
self.update_bar()?; |
| 3248 |
- |
3426 |
+ self.update_tab_bars()?; |
| 3249 |
- let visible = self.visible_windows_on_monitor(monitor_index); |
|
|
| 3250 |
- if let Some(&win) = visible.first() { |
|
|
| 3251 |
- self.focus(Some(win))?; |
|
|
| 3252 |
- self.update_tab_bars()?; |
|
|
| 3253 |
- } |
|
|
| 3254 |
} |
3427 |
} |
| 3255 |
} |
3428 |
} |
| 3256 |
Event::KeyPress(event) => { |
3429 |
Event::KeyPress(event) => { |
| 3257 |
let Some(mapping) = &self.keyboard_mapping else { |
3430 |
let Some(mapping) = &self.keyboard_mapping else { |
| 3258 |
- return Ok(None); |
3431 |
+ return Ok(Control::Continue); |
| 3259 |
}; |
3432 |
}; |
| 3260 |
|
3433 |
|
| 3261 |
let result = keyboard::handle_key_press( |
3434 |
let result = keyboard::handle_key_press( |
| @@ -3273,7 +3446,7 @@ impl WindowManager { |
| 3273 |
self.update_bar()?; |
3446 |
self.update_bar()?; |
| 3274 |
|
3447 |
|
| 3275 |
match action { |
3448 |
match action { |
| 3276 |
- KeyAction::Quit => return Ok(Some(false)), |
3449 |
+ KeyAction::Quit => return Ok(Control::Quit), |
| 3277 |
KeyAction::Restart => match self.try_reload_config() { |
3450 |
KeyAction::Restart => match self.try_reload_config() { |
| 3278 |
Ok(()) => { |
3451 |
Ok(()) => { |
| 3279 |
self.gaps_enabled = self.config.gaps_enabled; |
3452 |
self.gaps_enabled = self.config.gaps_enabled; |
| @@ -3289,7 +3462,7 @@ impl WindowManager { |
| 3289 |
} |
3462 |
} |
| 3290 |
Err(err) => { |
3463 |
Err(err) => { |
| 3291 |
eprintln!("Config reload error: {}", err); |
3464 |
eprintln!("Config reload error: {}", err); |
| 3292 |
- self.error_message = Some(err.clone()); |
3465 |
+ self.error_message = Some(err.to_string()); |
| 3293 |
let monitor = &self.monitors[self.selected_monitor]; |
3466 |
let monitor = &self.monitors[self.selected_monitor]; |
| 3294 |
let monitor_x = monitor.screen_x as i16; |
3467 |
let monitor_x = monitor.screen_x as i16; |
| 3295 |
let monitor_y = monitor.screen_y as i16; |
3468 |
let monitor_y = monitor.screen_y as i16; |
| @@ -3298,7 +3471,7 @@ impl WindowManager { |
| 3298 |
match self.overlay.show_error( |
3471 |
match self.overlay.show_error( |
| 3299 |
&self.connection, |
3472 |
&self.connection, |
| 3300 |
&self.font, |
3473 |
&self.font, |
| 3301 |
- &err, |
3474 |
+ err, |
| 3302 |
monitor_x, |
3475 |
monitor_x, |
| 3303 |
monitor_y, |
3476 |
monitor_y, |
| 3304 |
screen_width, |
3477 |
screen_width, |
| @@ -3468,12 +3641,15 @@ impl WindowManager { |
| 3468 |
if let Some(client) = self.clients.get(&event.window) { |
3641 |
if let Some(client) = self.clients.get(&event.window) { |
| 3469 |
let monitor = &self.monitors[client.monitor_index]; |
3642 |
let monitor = &self.monitors[client.monitor_index]; |
| 3470 |
let is_floating = client.is_floating; |
3643 |
let is_floating = client.is_floating; |
|
|
3644 |
+ let is_fullscreen = client.is_fullscreen; |
| 3471 |
let has_layout = self.layout.name() != "normie"; |
3645 |
let has_layout = self.layout.name() != "normie"; |
| 3472 |
|
3646 |
|
| 3473 |
if event.value_mask.contains(ConfigWindow::BORDER_WIDTH) { |
3647 |
if event.value_mask.contains(ConfigWindow::BORDER_WIDTH) { |
| 3474 |
if let Some(c) = self.clients.get_mut(&event.window) { |
3648 |
if let Some(c) = self.clients.get_mut(&event.window) { |
| 3475 |
c.border_width = event.border_width; |
3649 |
c.border_width = event.border_width; |
| 3476 |
} |
3650 |
} |
|
|
3651 |
+ } else if is_fullscreen { |
|
|
3652 |
+ self.send_configure_notify(event.window)?; |
| 3477 |
} else if is_floating || !has_layout { |
3653 |
} else if is_floating || !has_layout { |
| 3478 |
let mut x = client.x_position as i32; |
3654 |
let mut x = client.x_position as i32; |
| 3479 |
let mut y = client.y_position as i32; |
3655 |
let mut y = client.y_position as i32; |
| @@ -3575,21 +3751,26 @@ impl WindowManager { |
| 3575 |
} |
3751 |
} |
| 3576 |
Event::ClientMessage(event) => { |
3752 |
Event::ClientMessage(event) => { |
| 3577 |
if !self.clients.contains_key(&event.window) { |
3753 |
if !self.clients.contains_key(&event.window) { |
| 3578 |
- return Ok(None); |
3754 |
+ return Ok(Control::Continue); |
| 3579 |
} |
3755 |
} |
| 3580 |
|
3756 |
|
| 3581 |
if event.type_ == self.atoms.net_wm_state { |
3757 |
if event.type_ == self.atoms.net_wm_state { |
| 3582 |
- if let Some(data) = event.data.as_data32().get(1) |
3758 |
+ let data = event.data.as_data32(); |
| 3583 |
- && *data == self.atoms.net_wm_state_fullscreen |
3759 |
+ let atom1 = data.get(1).copied().unwrap_or(0); |
|
|
3760 |
+ let atom2 = data.get(2).copied().unwrap_or(0); |
|
|
3761 |
+ |
|
|
3762 |
+ if atom1 == self.atoms.net_wm_state_fullscreen |
|
|
3763 |
+ || atom2 == self.atoms.net_wm_state_fullscreen |
| 3584 |
{ |
3764 |
{ |
| 3585 |
- let action = event.data.as_data32()[0]; |
3765 |
+ let action = data[0]; |
| 3586 |
let fullscreen = match action { |
3766 |
let fullscreen = match action { |
| 3587 |
1 => true, |
3767 |
1 => true, |
| 3588 |
0 => false, |
3768 |
0 => false, |
| 3589 |
2 => !self.fullscreen_windows.contains(&event.window), |
3769 |
2 => !self.fullscreen_windows.contains(&event.window), |
| 3590 |
- _ => return Ok(None), |
3770 |
+ _ => return Ok(Control::Continue), |
| 3591 |
}; |
3771 |
}; |
| 3592 |
self.set_window_fullscreen(event.window, fullscreen)?; |
3772 |
self.set_window_fullscreen(event.window, fullscreen)?; |
|
|
3773 |
+ self.restack()?; |
| 3593 |
} |
3774 |
} |
| 3594 |
} else if event.type_ == self.atoms.net_active_window { |
3775 |
} else if event.type_ == self.atoms.net_active_window { |
| 3595 |
let selected_window = self |
3776 |
let selected_window = self |
| @@ -3609,15 +3790,25 @@ impl WindowManager { |
| 3609 |
} |
3790 |
} |
| 3610 |
} |
3791 |
} |
| 3611 |
Event::FocusIn(event) => { |
3792 |
Event::FocusIn(event) => { |
| 3612 |
- let selected_window = self |
3793 |
+ if !self.windows.contains(&event.event) { |
| 3613 |
- .monitors |
3794 |
+ return Ok(Control::Continue); |
| 3614 |
- .get(self.selected_monitor) |
3795 |
+ } |
| 3615 |
- .and_then(|m| m.selected_client); |
|
|
| 3616 |
|
3796 |
|
| 3617 |
- if let Some(sel_win) = selected_window |
3797 |
+ let event_window_visible = self.is_visible(event.event); |
| 3618 |
- && event.event != sel_win |
3798 |
+ |
| 3619 |
- { |
3799 |
+ if !event_window_visible { |
| 3620 |
- self.set_focus(sel_win)?; |
3800 |
+ self.focus(None)?; |
|
|
3801 |
+ } else { |
|
|
3802 |
+ let selected_window = self |
|
|
3803 |
+ .monitors |
|
|
3804 |
+ .get(self.selected_monitor) |
|
|
3805 |
+ .and_then(|monitor| monitor.selected_client); |
|
|
3806 |
+ |
|
|
3807 |
+ if let Some(focused_window) = selected_window |
|
|
3808 |
+ && event.event != focused_window |
|
|
3809 |
+ { |
|
|
3810 |
+ self.set_focus(focused_window)?; |
|
|
3811 |
+ } |
| 3621 |
} |
3812 |
} |
| 3622 |
} |
3813 |
} |
| 3623 |
Event::MappingNotify(event) => { |
3814 |
Event::MappingNotify(event) => { |
| @@ -3632,13 +3823,45 @@ impl WindowManager { |
| 3632 |
|
3823 |
|
| 3633 |
if event.width != old_width || event.height != old_height { |
3824 |
if event.width != old_width || event.height != old_height { |
| 3634 |
self.screen = self.connection.setup().roots[self.screen_number].clone(); |
3825 |
self.screen = self.connection.setup().roots[self.screen_number].clone(); |
|
|
3826 |
+ |
|
|
3827 |
+ for monitor_index in 0..self.monitors.len() { |
|
|
3828 |
+ let monitor = &self.monitors[monitor_index]; |
|
|
3829 |
+ let monitor_x = monitor.screen_x; |
|
|
3830 |
+ let monitor_y = monitor.screen_y; |
|
|
3831 |
+ let monitor_width = monitor.screen_width as u32; |
|
|
3832 |
+ let monitor_height = monitor.screen_height as u32; |
|
|
3833 |
+ |
|
|
3834 |
+ let fullscreen_on_monitor: Vec<Window> = self |
|
|
3835 |
+ .fullscreen_windows |
|
|
3836 |
+ .iter() |
|
|
3837 |
+ .filter(|&&window| { |
|
|
3838 |
+ self.clients |
|
|
3839 |
+ .get(&window) |
|
|
3840 |
+ .map(|client| client.monitor_index == monitor_index) |
|
|
3841 |
+ .unwrap_or(false) |
|
|
3842 |
+ }) |
|
|
3843 |
+ .copied() |
|
|
3844 |
+ .collect(); |
|
|
3845 |
+ |
|
|
3846 |
+ for window in fullscreen_on_monitor { |
|
|
3847 |
+ self.connection.configure_window( |
|
|
3848 |
+ window, |
|
|
3849 |
+ &ConfigureWindowAux::new() |
|
|
3850 |
+ .x(monitor_x) |
|
|
3851 |
+ .y(monitor_y) |
|
|
3852 |
+ .width(monitor_width) |
|
|
3853 |
+ .height(monitor_height), |
|
|
3854 |
+ )?; |
|
|
3855 |
+ } |
|
|
3856 |
+ } |
|
|
3857 |
+ |
| 3635 |
self.apply_layout()?; |
3858 |
self.apply_layout()?; |
| 3636 |
} |
3859 |
} |
| 3637 |
} |
3860 |
} |
| 3638 |
} |
3861 |
} |
| 3639 |
_ => {} |
3862 |
_ => {} |
| 3640 |
} |
3863 |
} |
| 3641 |
- Ok(None) |
3864 |
+ Ok(Control::Continue) |
| 3642 |
} |
3865 |
} |
| 3643 |
|
3866 |
|
| 3644 |
fn apply_layout(&mut self) -> WmResult<()> { |
3867 |
fn apply_layout(&mut self) -> WmResult<()> { |
| @@ -3770,6 +3993,44 @@ impl WindowManager { |
| 3770 |
self.showhide(stack_head)?; |
3993 |
self.showhide(stack_head)?; |
| 3771 |
} |
3994 |
} |
| 3772 |
|
3995 |
|
|
|
3996 |
+ for monitor_index in 0..self.monitors.len() { |
|
|
3997 |
+ let monitor = &self.monitors[monitor_index]; |
|
|
3998 |
+ let tags = monitor.tagset[monitor.selected_tags_index]; |
|
|
3999 |
+ |
|
|
4000 |
+ let has_visible_fullscreen = self.fullscreen_windows.iter().any(|&w| { |
|
|
4001 |
+ self.clients.get(&w).map_or(false, |c| { |
|
|
4002 |
+ c.monitor_index == monitor_index && (c.tags & tags) != 0 |
|
|
4003 |
+ }) |
|
|
4004 |
+ }); |
|
|
4005 |
+ |
|
|
4006 |
+ if has_visible_fullscreen { |
|
|
4007 |
+ if let Some(bar) = self.bars.get(monitor_index) { |
|
|
4008 |
+ self.connection.unmap_window(bar.window())?; |
|
|
4009 |
+ } |
|
|
4010 |
+ |
|
|
4011 |
+ for &window in &self.fullscreen_windows { |
|
|
4012 |
+ if let Some(client) = self.clients.get(&window) { |
|
|
4013 |
+ if client.monitor_index == monitor_index && (client.tags & tags) != 0 { |
|
|
4014 |
+ self.connection.configure_window( |
|
|
4015 |
+ window, |
|
|
4016 |
+ &ConfigureWindowAux::new() |
|
|
4017 |
+ .border_width(0) |
|
|
4018 |
+ .x(monitor.screen_x) |
|
|
4019 |
+ .y(monitor.screen_y) |
|
|
4020 |
+ .width(monitor.screen_width as u32) |
|
|
4021 |
+ .height(monitor.screen_height as u32) |
|
|
4022 |
+ .stack_mode(StackMode::ABOVE), |
|
|
4023 |
+ )?; |
|
|
4024 |
+ } |
|
|
4025 |
+ } |
|
|
4026 |
+ } |
|
|
4027 |
+ } else if self.show_bar { |
|
|
4028 |
+ if let Some(bar) = self.bars.get(monitor_index) { |
|
|
4029 |
+ self.connection.map_window(bar.window())?; |
|
|
4030 |
+ } |
|
|
4031 |
+ } |
|
|
4032 |
+ } |
|
|
4033 |
+ |
| 3773 |
self.connection.flush()?; |
4034 |
self.connection.flush()?; |
| 3774 |
|
4035 |
|
| 3775 |
let is_tabbed = self.layout.name() == LayoutType::Tabbed.as_str(); |
4036 |
let is_tabbed = self.layout.name() == LayoutType::Tabbed.as_str(); |
| @@ -4089,10 +4350,11 @@ impl WindowManager { |
| 4089 |
} |
4350 |
} |
| 4090 |
|
4351 |
|
| 4091 |
fn update_window_type(&mut self, window: Window) -> WmResult<()> { |
4352 |
fn update_window_type(&mut self, window: Window) -> WmResult<()> { |
| 4092 |
- if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) |
4353 |
+ if let Ok(state_atoms) = self.get_window_atom_list_property(window, self.atoms.net_wm_state) |
| 4093 |
- && state_atom == self.atoms.net_wm_state_fullscreen |
|
|
| 4094 |
{ |
4354 |
{ |
| 4095 |
- self.set_window_fullscreen(window, true)?; |
4355 |
+ if state_atoms.contains(&self.atoms.net_wm_state_fullscreen) { |
|
|
4356 |
+ self.set_window_fullscreen(window, true)?; |
|
|
4357 |
+ } |
| 4096 |
} |
4358 |
} |
| 4097 |
|
4359 |
|
| 4098 |
if let Ok(Some(type_atom)) = |
4360 |
if let Ok(Some(type_atom)) = |
| @@ -4425,7 +4687,7 @@ impl WindowManager { |
| 4425 |
} |
4687 |
} |
| 4426 |
} |
4688 |
} |
| 4427 |
|
4689 |
|
| 4428 |
- fn remove_window(&mut self, window: Window) -> WmResult<()> { |
4690 |
+ fn remove_window(&mut self, window: Window, destroyed: bool) -> WmResult<()> { |
| 4429 |
let initial_count = self.windows.len(); |
4691 |
let initial_count = self.windows.len(); |
| 4430 |
|
4692 |
|
| 4431 |
let focused = self |
4693 |
let focused = self |
| @@ -4433,6 +4695,17 @@ impl WindowManager { |
| 4433 |
.get(self.selected_monitor) |
4695 |
.get(self.selected_monitor) |
| 4434 |
.and_then(|m| m.selected_client); |
4696 |
.and_then(|m| m.selected_client); |
| 4435 |
|
4697 |
|
|
|
4698 |
+ if !destroyed { |
|
|
4699 |
+ if let Some(client) = self.clients.get(&window) { |
|
|
4700 |
+ let old_border_width = client.old_border_width; |
|
|
4701 |
+ self.connection.configure_window( |
|
|
4702 |
+ window, |
|
|
4703 |
+ &ConfigureWindowAux::new().border_width(old_border_width as u32), |
|
|
4704 |
+ )?; |
|
|
4705 |
+ } |
|
|
4706 |
+ self.set_wm_state(window, 0)?; |
|
|
4707 |
+ } |
|
|
4708 |
+ |
| 4436 |
if self.clients.contains_key(&window) { |
4709 |
if self.clients.contains_key(&window) { |
| 4437 |
self.detach(window); |
4710 |
self.detach(window); |
| 4438 |
self.detach_stack(window); |
4711 |
self.detach_stack(window); |
| @@ -4441,6 +4714,7 @@ impl WindowManager { |
| 4441 |
|
4714 |
|
| 4442 |
self.windows.retain(|&w| w != window); |
4715 |
self.windows.retain(|&w| w != window); |
| 4443 |
self.floating_windows.remove(&window); |
4716 |
self.floating_windows.remove(&window); |
|
|
4717 |
+ self.update_client_list()?; |
| 4444 |
|
4718 |
|
| 4445 |
if self.windows.len() < initial_count { |
4719 |
if self.windows.len() < initial_count { |
| 4446 |
if focused == Some(window) { |
4720 |
if focused == Some(window) { |
| @@ -4469,7 +4743,6 @@ impl WindowManager { |
| 4469 |
|
4743 |
|
| 4470 |
let mut current = monitor.clients_head; |
4744 |
let mut current = monitor.clients_head; |
| 4471 |
while let Some(window) = current { |
4745 |
while let Some(window) = current { |
| 4472 |
- // A window should always have a client attatched to it. |
|
|
| 4473 |
let Some(client) = self.clients.get(&window) else { |
4746 |
let Some(client) = self.clients.get(&window) else { |
| 4474 |
break; |
4747 |
break; |
| 4475 |
}; |
4748 |
}; |