| @@ -1,7 +1,7 @@ |
|
|
1 |
+use crate::config::{BORDER_FOCUSED, BORDER_UNFOCUSED, BORDER_WIDTH, TAG_COUNT}; |
| 1 |
use crate::keyboard::{self, Arg, KeyAction}; |
2 |
use crate::keyboard::{self, Arg, KeyAction}; |
| 2 |
use crate::layout::Layout; |
3 |
use crate::layout::Layout; |
| 3 |
use crate::layout::tiling::TilingLayout; |
4 |
use crate::layout::tiling::TilingLayout; |
| 4 |
- |
|
|
| 5 |
use anyhow::Result; |
5 |
use anyhow::Result; |
| 6 |
|
6 |
|
| 7 |
use x11rb::connection::Connection; |
7 |
use x11rb::connection::Connection; |
| @@ -9,11 +9,7 @@ use x11rb::protocol::Event; |
| 9 |
use x11rb::protocol::xproto::*; |
9 |
use x11rb::protocol::xproto::*; |
| 10 |
use x11rb::rust_connection::RustConnection; |
10 |
use x11rb::rust_connection::RustConnection; |
| 11 |
|
11 |
|
| 12 |
-// TODO: move this to its own file? (tag.rs?) |
|
|
| 13 |
pub type TagMask = u32; |
12 |
pub type TagMask = u32; |
| 14 |
- |
|
|
| 15 |
-pub const TAG_COUNT: usize = 9; |
|
|
| 16 |
- |
|
|
| 17 |
pub fn tag_mask(tag: usize) -> TagMask { |
13 |
pub fn tag_mask(tag: usize) -> TagMask { |
| 18 |
1 << tag |
14 |
1 << tag |
| 19 |
} |
15 |
} |
| @@ -68,7 +64,6 @@ impl WindowManager { |
| 68 |
|
64 |
|
| 69 |
loop { |
65 |
loop { |
| 70 |
let event = self.connection.wait_for_event()?; |
66 |
let event = self.connection.wait_for_event()?; |
| 71 |
- println!("event: {:?}", event); |
|
|
| 72 |
self.handle_event(event)?; |
67 |
self.handle_event(event)?; |
| 73 |
} |
68 |
} |
| 74 |
} |
69 |
} |
| @@ -77,35 +72,27 @@ impl WindowManager { |
| 77 |
match action { |
72 |
match action { |
| 78 |
KeyAction::Spawn => { |
73 |
KeyAction::Spawn => { |
| 79 |
if let Arg::Str(command) = arg { |
74 |
if let Arg::Str(command) = arg { |
| 80 |
- println!("Spawning: {}", command); |
|
|
| 81 |
std::process::Command::new(command).spawn()?; |
75 |
std::process::Command::new(command).spawn()?; |
| 82 |
} |
76 |
} |
| 83 |
} |
77 |
} |
| 84 |
KeyAction::KillClient => { |
78 |
KeyAction::KillClient => { |
| 85 |
- println!("Closing focused window"); |
|
|
| 86 |
if let Some(focused) = self.focused_window { |
79 |
if let Some(focused) = self.focused_window { |
| 87 |
match self.connection.kill_client(focused) { |
80 |
match self.connection.kill_client(focused) { |
| 88 |
Ok(_) => { |
81 |
Ok(_) => { |
| 89 |
self.connection.flush()?; |
82 |
self.connection.flush()?; |
| 90 |
- println!("Killed window {}", focused); |
|
|
| 91 |
} |
83 |
} |
| 92 |
Err(e) => { |
84 |
Err(e) => { |
| 93 |
- println!("Failed to kill window {}: {}", focused, e); |
85 |
+ eprintln!("Failed to kill window {}: {}", focused, e); |
| 94 |
} |
86 |
} |
| 95 |
} |
87 |
} |
| 96 |
} |
88 |
} |
| 97 |
} |
89 |
} |
| 98 |
KeyAction::FocusStack => { |
90 |
KeyAction::FocusStack => { |
| 99 |
if let Arg::Int(direction) = arg { |
91 |
if let Arg::Int(direction) = arg { |
| 100 |
- println!("FocusStack called with direction: {}", direction); |
|
|
| 101 |
- println!("Windows: {:?}", self.windows); |
|
|
| 102 |
- println!("Current focused: {:?}", self.focused_window); |
|
|
| 103 |
self.cycle_focus(*direction)?; |
92 |
self.cycle_focus(*direction)?; |
| 104 |
- println!("New focused: {:?}", self.focused_window); |
|
|
| 105 |
} |
93 |
} |
| 106 |
} |
94 |
} |
| 107 |
KeyAction::Quit => { |
95 |
KeyAction::Quit => { |
| 108 |
- println!("Quitting window manager"); |
|
|
| 109 |
std::process::exit(0); |
96 |
std::process::exit(0); |
| 110 |
} |
97 |
} |
| 111 |
KeyAction::ViewTag => { |
98 |
KeyAction::ViewTag => { |
| @@ -159,8 +146,6 @@ impl WindowManager { |
| 159 |
} |
146 |
} |
| 160 |
|
147 |
|
| 161 |
self.selected_tags = tag_mask(tag_index); |
148 |
self.selected_tags = tag_mask(tag_index); |
| 162 |
- println!("Viewing tag {}", tag_index + 1); |
|
|
| 163 |
- |
|
|
| 164 |
self.update_window_visibility()?; |
149 |
self.update_window_visibility()?; |
| 165 |
self.apply_layout()?; |
150 |
self.apply_layout()?; |
| 166 |
|
151 |
|
| @@ -178,9 +163,6 @@ impl WindowManager { |
| 178 |
if let Some(focused) = self.focused_window { |
163 |
if let Some(focused) = self.focused_window { |
| 179 |
let mask = tag_mask(tag_index); |
164 |
let mask = tag_mask(tag_index); |
| 180 |
self.window_tags.insert(focused, mask); |
165 |
self.window_tags.insert(focused, mask); |
| 181 |
- |
|
|
| 182 |
- println!("Moved window {} to tag {}", focused, tag_index + 1); |
|
|
| 183 |
- |
|
|
| 184 |
self.update_window_visibility()?; |
166 |
self.update_window_visibility()?; |
| 185 |
self.apply_layout()?; |
167 |
self.apply_layout()?; |
| 186 |
} |
168 |
} |
| @@ -215,7 +197,6 @@ impl WindowManager { |
| 215 |
} |
197 |
} |
| 216 |
|
198 |
|
| 217 |
pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> { |
199 |
pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> { |
| 218 |
- println!("set_focus called with: {:?}", window); |
|
|
| 219 |
self.focused_window = window; |
200 |
self.focused_window = window; |
| 220 |
|
201 |
|
| 221 |
if let Some(win) = window { |
202 |
if let Some(win) = window { |
| @@ -229,14 +210,11 @@ impl WindowManager { |
| 229 |
} |
210 |
} |
| 230 |
|
211 |
|
| 231 |
fn update_focus_visuals(&self) -> Result<()> { |
212 |
fn update_focus_visuals(&self) -> Result<()> { |
| 232 |
- println!("Updating focus visuals for {} windows", self.windows.len()); |
|
|
| 233 |
for &window in &self.windows { |
213 |
for &window in &self.windows { |
| 234 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
214 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
| 235 |
- println!("Window {} is FOCUSED (red border)", window); |
215 |
+ (BORDER_FOCUSED, BORDER_WIDTH) |
| 236 |
- (0xff0000, 2) |
|
|
| 237 |
} else { |
216 |
} else { |
| 238 |
- println!("Window {} is unfocused (gray border)", window); |
217 |
+ (BORDER_UNFOCUSED, BORDER_WIDTH) |
| 239 |
- (0x888888, 2) |
|
|
| 240 |
}; |
218 |
}; |
| 241 |
|
219 |
|
| 242 |
self.connection.configure_window( |
220 |
self.connection.configure_window( |
| @@ -263,27 +241,19 @@ impl WindowManager { |
| 263 |
self.set_focus(Some(event.window))?; |
241 |
self.set_focus(Some(event.window))?; |
| 264 |
} |
242 |
} |
| 265 |
Event::UnmapNotify(event) => { |
243 |
Event::UnmapNotify(event) => { |
| 266 |
- if self.windows.contains(&event.window) { |
244 |
+ if self.windows.contains(&event.window) && self.is_window_visible(event.window) { |
| 267 |
- if self.is_window_visible(event.window) { |
245 |
+ self.remove_window(event.window)?; |
| 268 |
- println!("Visible window {} unmapped, removing", event.window); |
|
|
| 269 |
- self.remove_window(event.window)?; |
|
|
| 270 |
- } else { |
|
|
| 271 |
- println!( |
|
|
| 272 |
- "Hidden window {} unmapped (expected), ignoring", |
|
|
| 273 |
- event.window |
|
|
| 274 |
- ); |
|
|
| 275 |
- } |
|
|
| 276 |
} |
246 |
} |
| 277 |
} |
247 |
} |
| 278 |
// Event::UnmapNotify(event) => { |
248 |
// Event::UnmapNotify(event) => { |
| 279 |
// if self.windows.contains(&event.window) { |
249 |
// if self.windows.contains(&event.window) { |
| 280 |
- // println!("Window {} unmapped, removing from layout", event.window); |
250 |
+ // if self.is_window_visible(event.window) { |
| 281 |
- // self.remove_window(event.window)?; |
251 |
+ // self.remove_window(event.window)?; |
|
|
252 |
+ // } |
| 282 |
// } |
253 |
// } |
| 283 |
// } |
254 |
// } |
| 284 |
Event::DestroyNotify(event) => { |
255 |
Event::DestroyNotify(event) => { |
| 285 |
if self.windows.contains(&event.window) { |
256 |
if self.windows.contains(&event.window) { |
| 286 |
- println!("Window {} destroyed, removing from layout", event.window); |
|
|
| 287 |
self.remove_window(event.window)?; |
257 |
self.remove_window(event.window)?; |
| 288 |
} |
258 |
} |
| 289 |
} |
259 |
} |
| @@ -299,7 +269,7 @@ impl WindowManager { |
| 299 |
fn apply_layout(&self) -> Result<()> { |
269 |
fn apply_layout(&self) -> Result<()> { |
| 300 |
let screen_width = self.screen.width_in_pixels as u32; |
270 |
let screen_width = self.screen.width_in_pixels as u32; |
| 301 |
let screen_height = self.screen.height_in_pixels as u32; |
271 |
let screen_height = self.screen.height_in_pixels as u32; |
| 302 |
- let border_width = 2u32; |
272 |
+ let border_width = BORDER_WIDTH; |
| 303 |
|
273 |
|
| 304 |
let visible = self.visible_windows(); |
274 |
let visible = self.visible_windows(); |
| 305 |
let geometries = self.layout.arrange(&visible, screen_width, screen_height); |
275 |
let geometries = self.layout.arrange(&visible, screen_width, screen_height); |
| @@ -327,8 +297,6 @@ impl WindowManager { |
| 327 |
self.window_tags.remove(&window); |
297 |
self.window_tags.remove(&window); |
| 328 |
|
298 |
|
| 329 |
if self.windows.len() < initial_count { |
299 |
if self.windows.len() < initial_count { |
| 330 |
- println!("Removed window {} from management", window); |
|
|
| 331 |
- |
|
|
| 332 |
if self.focused_window == Some(window) { |
300 |
if self.focused_window == Some(window) { |
| 333 |
let new_focus = if self.windows.is_empty() { |
301 |
let new_focus = if self.windows.is_empty() { |
| 334 |
None |
302 |
None |