| @@ -1,12 +1,11 @@ |
| 1 |
use crate::Config; |
1 |
use crate::Config; |
| 2 |
use crate::bar::Bar; |
2 |
use crate::bar::Bar; |
|
|
3 |
+use crate::errors::WmError; |
| 3 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
4 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
| 4 |
use crate::layout::GapConfig; |
5 |
use crate::layout::GapConfig; |
| 5 |
use crate::layout::Layout; |
6 |
use crate::layout::Layout; |
| 6 |
use crate::layout::tiling::TilingLayout; |
7 |
use crate::layout::tiling::TilingLayout; |
| 7 |
-use anyhow::Result; |
|
|
| 8 |
use std::collections::HashSet; |
8 |
use std::collections::HashSet; |
| 9 |
-use std::path::PathBuf; |
|
|
| 10 |
use x11rb::cursor::Handle as CursorHandle; |
9 |
use x11rb::cursor::Handle as CursorHandle; |
| 11 |
|
10 |
|
| 12 |
use x11rb::connection::Connection; |
11 |
use x11rb::connection::Connection; |
| @@ -36,8 +35,10 @@ pub struct WindowManager { |
| 36 |
bar: Bar, |
35 |
bar: Bar, |
| 37 |
} |
36 |
} |
| 38 |
|
37 |
|
|
|
38 |
+type WmResult<T> = Result<T, WmError>; |
|
|
39 |
+ |
| 39 |
impl WindowManager { |
40 |
impl WindowManager { |
| 40 |
- pub fn new(config: Config) -> Result<Self> { |
41 |
+ pub fn new(config: Config) -> WmResult<Self> { |
| 41 |
let (connection, screen_number) = x11rb::connect(None)?; |
42 |
let (connection, screen_number) = x11rb::connect(None)?; |
| 42 |
let root = connection.setup().roots[screen_number].root; |
43 |
let root = connection.setup().roots[screen_number].root; |
| 43 |
let screen = connection.setup().roots[screen_number].clone(); |
44 |
let screen = connection.setup().roots[screen_number].clone(); |
| @@ -121,7 +122,7 @@ impl WindowManager { |
| 121 |
connection: &RustConnection, |
122 |
connection: &RustConnection, |
| 122 |
root: Window, |
123 |
root: Window, |
| 123 |
tag_count: usize, |
124 |
tag_count: usize, |
| 124 |
- ) -> Result<TagMask> { |
125 |
+ ) -> WmResult<TagMask> { |
| 125 |
let net_current_desktop = connection |
126 |
let net_current_desktop = connection |
| 126 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
127 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| 127 |
.reply()? |
128 |
.reply()? |
| @@ -151,7 +152,7 @@ impl WindowManager { |
| 151 |
Ok(tag_mask(0)) |
152 |
Ok(tag_mask(0)) |
| 152 |
} |
153 |
} |
| 153 |
|
154 |
|
| 154 |
- fn scan_existing_windows(&mut self) -> Result<()> { |
155 |
+ fn scan_existing_windows(&mut self) -> WmResult<()> { |
| 155 |
let tree = self.connection.query_tree(self.root)?.reply()?; |
156 |
let tree = self.connection.query_tree(self.root)?.reply()?; |
| 156 |
let net_client_info = self |
157 |
let net_client_info = self |
| 157 |
.connection |
158 |
.connection |
| @@ -218,7 +219,7 @@ impl WindowManager { |
| 218 |
Ok(()) |
219 |
Ok(()) |
| 219 |
} |
220 |
} |
| 220 |
|
221 |
|
| 221 |
- fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> Result<TagMask> { |
222 |
+ fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> WmResult<TagMask> { |
| 222 |
match self |
223 |
match self |
| 223 |
.connection |
224 |
.connection |
| 224 |
.get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? |
225 |
.get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? |
| @@ -245,7 +246,7 @@ impl WindowManager { |
| 245 |
Ok(self.selected_tags) |
246 |
Ok(self.selected_tags) |
| 246 |
} |
247 |
} |
| 247 |
|
248 |
|
| 248 |
- fn save_client_tag(&self, window: Window, tag: TagMask) -> Result<()> { |
249 |
+ fn save_client_tag(&self, window: Window, tag: TagMask) -> WmResult<()> { |
| 249 |
let net_client_info = self |
250 |
let net_client_info = self |
| 250 |
.connection |
251 |
.connection |
| 251 |
.intern_atom(false, b"_NET_CLIENT_INFO")? |
252 |
.intern_atom(false, b"_NET_CLIENT_INFO")? |
| @@ -268,7 +269,7 @@ impl WindowManager { |
| 268 |
Ok(()) |
269 |
Ok(()) |
| 269 |
} |
270 |
} |
| 270 |
|
271 |
|
| 271 |
- fn set_wm_state(&self, window: Window, state: u32) -> Result<()> { |
272 |
+ fn set_wm_state(&self, window: Window, state: u32) -> WmResult<()> { |
| 272 |
let wm_state_atom = self |
273 |
let wm_state_atom = self |
| 273 |
.connection |
274 |
.connection |
| 274 |
.intern_atom(false, b"WM_STATE")? |
275 |
.intern_atom(false, b"WM_STATE")? |
| @@ -292,14 +293,14 @@ impl WindowManager { |
| 292 |
Ok(()) |
293 |
Ok(()) |
| 293 |
} |
294 |
} |
| 294 |
|
295 |
|
| 295 |
- pub fn run(&mut self) -> Result<bool> { |
296 |
+ pub fn run(&mut self) -> WmResult<bool> { |
| 296 |
println!("oxwm started on display {}", self.screen_number); |
297 |
println!("oxwm started on display {}", self.screen_number); |
| 297 |
|
298 |
|
| 298 |
keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
299 |
keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
| 299 |
self.update_bar()?; |
300 |
self.update_bar()?; |
| 300 |
|
301 |
|
| 301 |
loop { |
302 |
loop { |
| 302 |
- self.bar.update_blocks()?; |
303 |
+ self.bar.update_blocks(); |
| 303 |
|
304 |
|
| 304 |
if let Ok(Some(event)) = self.connection.poll_for_event() { |
305 |
if let Ok(Some(event)) = self.connection.poll_for_event() { |
| 305 |
if let Some(should_restart) = self.handle_event(event)? { |
306 |
if let Some(should_restart) = self.handle_event(event)? { |
| @@ -315,7 +316,7 @@ impl WindowManager { |
| 315 |
} |
316 |
} |
| 316 |
} |
317 |
} |
| 317 |
|
318 |
|
| 318 |
- fn toggle_floating(&mut self) -> Result<()> { |
319 |
+ fn toggle_floating(&mut self) -> WmResult<()> { |
| 319 |
if let Some(focused) = self.focused_window { |
320 |
if let Some(focused) = self.focused_window { |
| 320 |
if self.floating_windows.contains(&focused) { |
321 |
if self.floating_windows.contains(&focused) { |
| 321 |
self.floating_windows.remove(&focused); |
322 |
self.floating_windows.remove(&focused); |
| @@ -333,7 +334,7 @@ impl WindowManager { |
| 333 |
Ok(()) |
334 |
Ok(()) |
| 334 |
} |
335 |
} |
| 335 |
|
336 |
|
| 336 |
- fn toggle_fullscreen(&mut self) -> Result<()> { |
337 |
+ fn toggle_fullscreen(&mut self) -> WmResult<()> { |
| 337 |
if let Some(focused) = self.focused_window { |
338 |
if let Some(focused) = self.focused_window { |
| 338 |
if self.fullscreen_window == Some(focused) { |
339 |
if self.fullscreen_window == Some(focused) { |
| 339 |
self.fullscreen_window = None; |
340 |
self.fullscreen_window = None; |
| @@ -367,7 +368,7 @@ impl WindowManager { |
| 367 |
Ok(()) |
368 |
Ok(()) |
| 368 |
} |
369 |
} |
| 369 |
|
370 |
|
| 370 |
- fn update_bar(&mut self) -> Result<()> { |
371 |
+ fn update_bar(&mut self) -> WmResult<()> { |
| 371 |
let mut occupied_tags: TagMask = 0; |
372 |
let mut occupied_tags: TagMask = 0; |
| 372 |
for &tags in self.window_tags.values() { |
373 |
for &tags in self.window_tags.values() { |
| 373 |
occupied_tags |= tags; |
374 |
occupied_tags |= tags; |
| @@ -379,7 +380,7 @@ impl WindowManager { |
| 379 |
Ok(()) |
380 |
Ok(()) |
| 380 |
} |
381 |
} |
| 381 |
|
382 |
|
| 382 |
- fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> Result<()> { |
383 |
+ fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { |
| 383 |
match action { |
384 |
match action { |
| 384 |
KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
385 |
KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
| 385 |
KeyAction::KillClient => { |
386 |
KeyAction::KillClient => { |
| @@ -453,7 +454,7 @@ impl WindowManager { |
| 453 |
.collect() |
454 |
.collect() |
| 454 |
} |
455 |
} |
| 455 |
|
456 |
|
| 456 |
- fn update_window_visibility(&self) -> Result<()> { |
457 |
+ fn update_window_visibility(&self) -> WmResult<()> { |
| 457 |
for &window in &self.windows { |
458 |
for &window in &self.windows { |
| 458 |
if self.is_window_visible(window) { |
459 |
if self.is_window_visible(window) { |
| 459 |
self.connection.map_window(window)?; |
460 |
self.connection.map_window(window)?; |
| @@ -465,7 +466,7 @@ impl WindowManager { |
| 465 |
Ok(()) |
466 |
Ok(()) |
| 466 |
} |
467 |
} |
| 467 |
|
468 |
|
| 468 |
- pub fn view_tag(&mut self, tag_index: usize) -> Result<()> { |
469 |
+ pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 469 |
if tag_index >= self.config.tags.len() { |
470 |
if tag_index >= self.config.tags.len() { |
| 470 |
return Ok(()); |
471 |
return Ok(()); |
| 471 |
} |
472 |
} |
| @@ -489,7 +490,7 @@ impl WindowManager { |
| 489 |
Ok(()) |
490 |
Ok(()) |
| 490 |
} |
491 |
} |
| 491 |
|
492 |
|
| 492 |
- fn save_selected_tags(&self) -> Result<()> { |
493 |
+ fn save_selected_tags(&self) -> WmResult<()> { |
| 493 |
let net_current_desktop = self |
494 |
let net_current_desktop = self |
| 494 |
.connection |
495 |
.connection |
| 495 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
496 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| @@ -513,7 +514,7 @@ impl WindowManager { |
| 513 |
Ok(()) |
514 |
Ok(()) |
| 514 |
} |
515 |
} |
| 515 |
|
516 |
|
| 516 |
- pub fn move_to_tag(&mut self, tag_index: usize) -> Result<()> { |
517 |
+ pub fn move_to_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 517 |
if tag_index >= self.config.tags.len() { |
518 |
if tag_index >= self.config.tags.len() { |
| 518 |
return Ok(()); |
519 |
return Ok(()); |
| 519 |
} |
520 |
} |
| @@ -532,7 +533,7 @@ impl WindowManager { |
| 532 |
Ok(()) |
533 |
Ok(()) |
| 533 |
} |
534 |
} |
| 534 |
|
535 |
|
| 535 |
- pub fn cycle_focus(&mut self, direction: i32) -> Result<()> { |
536 |
+ pub fn cycle_focus(&mut self, direction: i32) -> WmResult<()> { |
| 536 |
let visible = self.visible_windows(); |
537 |
let visible = self.visible_windows(); |
| 537 |
|
538 |
|
| 538 |
if visible.is_empty() { |
539 |
if visible.is_empty() { |
| @@ -558,7 +559,7 @@ impl WindowManager { |
| 558 |
Ok(()) |
559 |
Ok(()) |
| 559 |
} |
560 |
} |
| 560 |
|
561 |
|
| 561 |
- pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> { |
562 |
+ pub fn set_focus(&mut self, window: Option<Window>) -> WmResult<()> { |
| 562 |
self.focused_window = window; |
563 |
self.focused_window = window; |
| 563 |
|
564 |
|
| 564 |
if let Some(win) = window { |
565 |
if let Some(win) = window { |
| @@ -571,7 +572,7 @@ impl WindowManager { |
| 571 |
Ok(()) |
572 |
Ok(()) |
| 572 |
} |
573 |
} |
| 573 |
|
574 |
|
| 574 |
- fn update_focus_visuals(&self) -> Result<()> { |
575 |
+ fn update_focus_visuals(&self) -> WmResult<()> { |
| 575 |
for &window in &self.windows { |
576 |
for &window in &self.windows { |
| 576 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
577 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
| 577 |
(self.config.border_focused, self.config.border_width) |
578 |
(self.config.border_focused, self.config.border_width) |
| @@ -593,7 +594,7 @@ impl WindowManager { |
| 593 |
Ok(()) |
594 |
Ok(()) |
| 594 |
} |
595 |
} |
| 595 |
|
596 |
|
| 596 |
- fn move_mouse(&mut self, window: Window) -> Result<()> { |
597 |
+ fn move_mouse(&mut self, window: Window) -> WmResult<()> { |
| 597 |
self.floating_windows.insert(window); |
598 |
self.floating_windows.insert(window); |
| 598 |
|
599 |
|
| 599 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
600 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -646,7 +647,7 @@ impl WindowManager { |
| 646 |
Ok(()) |
647 |
Ok(()) |
| 647 |
} |
648 |
} |
| 648 |
|
649 |
|
| 649 |
- fn resize_mouse(&mut self, window: Window) -> Result<()> { |
650 |
+ fn resize_mouse(&mut self, window: Window) -> WmResult<()> { |
| 650 |
self.floating_windows.insert(window); |
651 |
self.floating_windows.insert(window); |
| 651 |
|
652 |
|
| 652 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
653 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -710,7 +711,7 @@ impl WindowManager { |
| 710 |
Ok(()) |
711 |
Ok(()) |
| 711 |
} |
712 |
} |
| 712 |
|
713 |
|
| 713 |
- fn handle_event(&mut self, event: Event) -> Result<Option<bool>> { |
714 |
+ fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> { |
| 714 |
match event { |
715 |
match event { |
| 715 |
Event::MapRequest(event) => { |
716 |
Event::MapRequest(event) => { |
| 716 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
717 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
| @@ -760,7 +761,7 @@ impl WindowManager { |
| 760 |
} |
761 |
} |
| 761 |
} |
762 |
} |
| 762 |
Event::KeyPress(event) => { |
763 |
Event::KeyPress(event) => { |
| 763 |
- let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?; |
764 |
+ let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings); |
| 764 |
match action { |
765 |
match action { |
| 765 |
KeyAction::Quit => return Ok(Some(false)), |
766 |
KeyAction::Quit => return Ok(Some(false)), |
| 766 |
KeyAction::Restart => return Ok(Some(true)), |
767 |
KeyAction::Restart => return Ok(Some(true)), |
| @@ -793,7 +794,7 @@ impl WindowManager { |
| 793 |
Ok(None) |
794 |
Ok(None) |
| 794 |
} |
795 |
} |
| 795 |
|
796 |
|
| 796 |
- fn apply_layout(&self) -> Result<()> { |
797 |
+ fn apply_layout(&self) -> WmResult<()> { |
| 797 |
if self.fullscreen_window.is_some() { |
798 |
if self.fullscreen_window.is_some() { |
| 798 |
return Ok(()); |
799 |
return Ok(()); |
| 799 |
} |
800 |
} |
| @@ -849,7 +850,7 @@ impl WindowManager { |
| 849 |
Ok(()) |
850 |
Ok(()) |
| 850 |
} |
851 |
} |
| 851 |
|
852 |
|
| 852 |
- fn remove_window(&mut self, window: Window) -> Result<()> { |
853 |
+ fn remove_window(&mut self, window: Window) -> WmResult<()> { |
| 853 |
let initial_count = self.windows.len(); |
854 |
let initial_count = self.windows.len(); |
| 854 |
self.windows.retain(|&w| w != window); |
855 |
self.windows.retain(|&w| w != window); |
| 855 |
self.window_tags.remove(&window); |
856 |
self.window_tags.remove(&window); |