| @@ -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_fullscreen(&mut self) -> Result<()> { |
319 |
+ fn toggle_fullscreen(&mut self) -> WmResult<()> { |
| 319 |
if let Some(focused) = self.focused_window { |
320 |
if let Some(focused) = self.focused_window { |
| 320 |
if self.fullscreen_window == Some(focused) { |
321 |
if self.fullscreen_window == Some(focused) { |
| 321 |
self.fullscreen_window = None; |
322 |
self.fullscreen_window = None; |
| @@ -349,7 +350,7 @@ impl WindowManager { |
| 349 |
Ok(()) |
350 |
Ok(()) |
| 350 |
} |
351 |
} |
| 351 |
|
352 |
|
| 352 |
- fn update_bar(&mut self) -> Result<()> { |
353 |
+ fn update_bar(&mut self) -> WmResult<()> { |
| 353 |
let mut occupied_tags: TagMask = 0; |
354 |
let mut occupied_tags: TagMask = 0; |
| 354 |
for &tags in self.window_tags.values() { |
355 |
for &tags in self.window_tags.values() { |
| 355 |
occupied_tags |= tags; |
356 |
occupied_tags |= tags; |
| @@ -361,7 +362,7 @@ impl WindowManager { |
| 361 |
Ok(()) |
362 |
Ok(()) |
| 362 |
} |
363 |
} |
| 363 |
|
364 |
|
| 364 |
- fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> Result<()> { |
365 |
+ fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { |
| 365 |
match action { |
366 |
match action { |
| 366 |
KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
367 |
KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
| 367 |
KeyAction::KillClient => { |
368 |
KeyAction::KillClient => { |
| @@ -431,7 +432,7 @@ impl WindowManager { |
| 431 |
.collect() |
432 |
.collect() |
| 432 |
} |
433 |
} |
| 433 |
|
434 |
|
| 434 |
- fn update_window_visibility(&self) -> Result<()> { |
435 |
+ fn update_window_visibility(&self) -> WmResult<()> { |
| 435 |
for &window in &self.windows { |
436 |
for &window in &self.windows { |
| 436 |
if self.is_window_visible(window) { |
437 |
if self.is_window_visible(window) { |
| 437 |
self.connection.map_window(window)?; |
438 |
self.connection.map_window(window)?; |
| @@ -443,7 +444,7 @@ impl WindowManager { |
| 443 |
Ok(()) |
444 |
Ok(()) |
| 444 |
} |
445 |
} |
| 445 |
|
446 |
|
| 446 |
- pub fn view_tag(&mut self, tag_index: usize) -> Result<()> { |
447 |
+ pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 447 |
if tag_index >= self.config.tags.len() { |
448 |
if tag_index >= self.config.tags.len() { |
| 448 |
return Ok(()); |
449 |
return Ok(()); |
| 449 |
} |
450 |
} |
| @@ -467,7 +468,7 @@ impl WindowManager { |
| 467 |
Ok(()) |
468 |
Ok(()) |
| 468 |
} |
469 |
} |
| 469 |
|
470 |
|
| 470 |
- fn save_selected_tags(&self) -> Result<()> { |
471 |
+ fn save_selected_tags(&self) -> WmResult<()> { |
| 471 |
let net_current_desktop = self |
472 |
let net_current_desktop = self |
| 472 |
.connection |
473 |
.connection |
| 473 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
474 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| @@ -491,7 +492,7 @@ impl WindowManager { |
| 491 |
Ok(()) |
492 |
Ok(()) |
| 492 |
} |
493 |
} |
| 493 |
|
494 |
|
| 494 |
- pub fn move_to_tag(&mut self, tag_index: usize) -> Result<()> { |
495 |
+ pub fn move_to_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 495 |
if tag_index >= self.config.tags.len() { |
496 |
if tag_index >= self.config.tags.len() { |
| 496 |
return Ok(()); |
497 |
return Ok(()); |
| 497 |
} |
498 |
} |
| @@ -510,7 +511,7 @@ impl WindowManager { |
| 510 |
Ok(()) |
511 |
Ok(()) |
| 511 |
} |
512 |
} |
| 512 |
|
513 |
|
| 513 |
- pub fn cycle_focus(&mut self, direction: i32) -> Result<()> { |
514 |
+ pub fn cycle_focus(&mut self, direction: i32) -> WmResult<()> { |
| 514 |
let visible = self.visible_windows(); |
515 |
let visible = self.visible_windows(); |
| 515 |
|
516 |
|
| 516 |
if visible.is_empty() { |
517 |
if visible.is_empty() { |
| @@ -536,7 +537,7 @@ impl WindowManager { |
| 536 |
Ok(()) |
537 |
Ok(()) |
| 537 |
} |
538 |
} |
| 538 |
|
539 |
|
| 539 |
- pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> { |
540 |
+ pub fn set_focus(&mut self, window: Option<Window>) -> WmResult<()> { |
| 540 |
self.focused_window = window; |
541 |
self.focused_window = window; |
| 541 |
|
542 |
|
| 542 |
if let Some(win) = window { |
543 |
if let Some(win) = window { |
| @@ -549,7 +550,7 @@ impl WindowManager { |
| 549 |
Ok(()) |
550 |
Ok(()) |
| 550 |
} |
551 |
} |
| 551 |
|
552 |
|
| 552 |
- fn update_focus_visuals(&self) -> Result<()> { |
553 |
+ fn update_focus_visuals(&self) -> WmResult<()> { |
| 553 |
for &window in &self.windows { |
554 |
for &window in &self.windows { |
| 554 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
555 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
| 555 |
(self.config.border_focused, self.config.border_width) |
556 |
(self.config.border_focused, self.config.border_width) |
| @@ -571,7 +572,7 @@ impl WindowManager { |
| 571 |
Ok(()) |
572 |
Ok(()) |
| 572 |
} |
573 |
} |
| 573 |
|
574 |
|
| 574 |
- fn move_mouse(&mut self, window: Window) -> Result<()> { |
575 |
+ fn move_mouse(&mut self, window: Window) -> WmResult<()> { |
| 575 |
self.floating_windows.insert(window); |
576 |
self.floating_windows.insert(window); |
| 576 |
|
577 |
|
| 577 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
578 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -624,7 +625,7 @@ impl WindowManager { |
| 624 |
Ok(()) |
625 |
Ok(()) |
| 625 |
} |
626 |
} |
| 626 |
|
627 |
|
| 627 |
- fn resize_mouse(&mut self, window: Window) -> Result<()> { |
628 |
+ fn resize_mouse(&mut self, window: Window) -> WmResult<()> { |
| 628 |
self.floating_windows.insert(window); |
629 |
self.floating_windows.insert(window); |
| 629 |
|
630 |
|
| 630 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
631 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -688,7 +689,7 @@ impl WindowManager { |
| 688 |
Ok(()) |
689 |
Ok(()) |
| 689 |
} |
690 |
} |
| 690 |
|
691 |
|
| 691 |
- fn handle_event(&mut self, event: Event) -> Result<Option<bool>> { |
692 |
+ fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> { |
| 692 |
match event { |
693 |
match event { |
| 693 |
Event::MapRequest(event) => { |
694 |
Event::MapRequest(event) => { |
| 694 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
695 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
| @@ -738,7 +739,7 @@ impl WindowManager { |
| 738 |
} |
739 |
} |
| 739 |
} |
740 |
} |
| 740 |
Event::KeyPress(event) => { |
741 |
Event::KeyPress(event) => { |
| 741 |
- let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?; |
742 |
+ let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings); |
| 742 |
match action { |
743 |
match action { |
| 743 |
KeyAction::Quit => return Ok(Some(false)), |
744 |
KeyAction::Quit => return Ok(Some(false)), |
| 744 |
KeyAction::Restart => return Ok(Some(true)), |
745 |
KeyAction::Restart => return Ok(Some(true)), |
| @@ -771,7 +772,7 @@ impl WindowManager { |
| 771 |
Ok(None) |
772 |
Ok(None) |
| 772 |
} |
773 |
} |
| 773 |
|
774 |
|
| 774 |
- fn apply_layout(&self) -> Result<()> { |
775 |
+ fn apply_layout(&self) -> WmResult<()> { |
| 775 |
if self.fullscreen_window.is_some() { |
776 |
if self.fullscreen_window.is_some() { |
| 776 |
return Ok(()); |
777 |
return Ok(()); |
| 777 |
} |
778 |
} |
| @@ -827,7 +828,7 @@ impl WindowManager { |
| 827 |
Ok(()) |
828 |
Ok(()) |
| 828 |
} |
829 |
} |
| 829 |
|
830 |
|
| 830 |
- fn remove_window(&mut self, window: Window) -> Result<()> { |
831 |
+ fn remove_window(&mut self, window: Window) -> WmResult<()> { |
| 831 |
let initial_count = self.windows.len(); |
832 |
let initial_count = self.windows.len(); |
| 832 |
self.windows.retain(|&w| w != window); |
833 |
self.windows.retain(|&w| w != window); |
| 833 |
self.window_tags.remove(&window); |
834 |
self.window_tags.remove(&window); |