tony / oxwm

Merge branch 'master' into update/mainfile Browse files
ScottADeJong committed 2025-12-24 parents 0522a39 84f46f6 commit be0a1a38198322d1ca7b3e241301520f5ab02094
Showing 20 changed files with 860 additions and 744 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -291,7 +291,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
291 291
292 292 [[package]]
293 293 name = "oxwm"
294 -version = "0.9.0"
294 +version = "0.9.1"
295 295 dependencies = [
296 296 "chrono",
297 297 "dirs",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 1 [package]
2 2 name = "oxwm"
3 -version = "0.9.0"
3 +version = "0.9.1"
4 4 edition = "2024"
5 5
6 6 [lib]
+5 −2 resources/test-config.lua
@@ -28,6 +28,8 @@ local colors = {
28 28 blue = 0x6dade3,
29 29 }
30 30
31 +asdf
32 +
31 33 local modkey = "Mod1"
32 34
33 35 oxwm.set_terminal("st")
@@ -56,13 +58,14 @@ oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12")
56 58 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, 0x444444)
57 59 oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan)
58 60 oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
61 +oxwm.bar.set_scheme_urgent(colors.red, colors.bg, colors.red)
59 62
60 63 oxwm.key.chord({
61 64 { { modkey }, "Space" },
62 65 { {}, "T" }
63 -}, oxwm.spawn("st"))
66 +}, oxwm.spawn_terminal())
64 67
65 -oxwm.key.bind({ modkey }, "Return", oxwm.spawn("st"))
68 +oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal())
66 69 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
67 70 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
68 71 oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
+36 −46 src/bar/bar.rs
@@ -1,5 +1,5 @@
1 1 use super::blocks::Block;
2 -use super::font::{Font, FontDraw};
2 +use super::font::{DrawingSurface, Font};
3 3 use crate::Config;
4 4 use crate::errors::X11Error;
5 5 use std::time::Instant;
@@ -13,10 +13,7 @@ pub struct Bar {
13 13 width: u16,
14 14 height: u16,
15 15 graphics_context: Gcontext,
16 - pixmap: x11::xlib::Pixmap,
17 - display: *mut x11::xlib::Display,
18 -
19 - font_draw: FontDraw,
16 + surface: DrawingSurface,
20 17
21 18 tag_widths: Vec<u16>,
22 19 needs_redraw: bool,
@@ -30,6 +27,7 @@ pub struct Bar {
30 27 scheme_normal: crate::ColorScheme,
31 28 scheme_occupied: crate::ColorScheme,
32 29 scheme_selected: crate::ColorScheme,
30 + scheme_urgent: crate::ColorScheme,
33 31 }
34 32
35 33 impl Bar {
@@ -79,19 +77,15 @@ impl Bar {
79 77
80 78 let visual = unsafe { x11::xlib::XDefaultVisual(display, screen_num as i32) };
81 79 let colormap = unsafe { x11::xlib::XDefaultColormap(display, screen_num as i32) };
82 - let depth = unsafe { x11::xlib::XDefaultDepth(display, screen_num as i32) };
83 -
84 - let pixmap = unsafe {
85 - x11::xlib::XCreatePixmap(
86 - display,
87 - window as x11::xlib::Drawable,
88 - width as u32,
89 - height as u32,
90 - depth as u32,
91 - )
92 - };
93 80
94 - let font_draw = FontDraw::new(display, pixmap, visual, colormap)?;
81 + let surface = DrawingSurface::new(
82 + display,
83 + window as x11::xlib::Drawable,
84 + width as u32,
85 + height as u32,
86 + visual,
87 + colormap,
88 + )?;
95 89
96 90 let horizontal_padding = (font.height() as f32 * 0.4) as u16;
97 91
@@ -123,9 +117,7 @@ impl Bar {
123 117 width,
124 118 height,
125 119 graphics_context,
126 - pixmap,
127 - display,
128 - font_draw,
120 + surface,
129 121 tag_widths,
130 122 needs_redraw: true,
131 123 blocks,
@@ -136,6 +128,7 @@ impl Bar {
136 128 scheme_normal: config.scheme_normal,
137 129 scheme_occupied: config.scheme_occupied,
138 130 scheme_selected: config.scheme_selected,
131 + scheme_urgent: config.scheme_urgent,
139 132 })
140 133 }
141 134
@@ -158,11 +151,9 @@ impl Bar {
158 151 for (i, block) in self.blocks.iter_mut().enumerate() {
159 152 let elapsed = now.duration_since(self.block_last_updates[i]);
160 153
161 - if elapsed >= block.interval() {
162 - if block.content().is_ok() {
163 - self.block_last_updates[i] = now;
164 - changed = true;
165 - }
154 + if elapsed >= block.interval() && block.content().is_ok() {
155 + self.block_last_updates[i] = now;
156 + changed = true;
166 157 }
167 158 }
168 159
@@ -185,6 +176,7 @@ impl Bar {
185 176 display: *mut x11::xlib::Display,
186 177 current_tags: u32,
187 178 occupied_tags: u32,
179 + urgent_tags: u32,
188 180 draw_blocks: bool,
189 181 layout_symbol: &str,
190 182 keychord_indicator: Option<&str>,
@@ -200,11 +192,11 @@ impl Bar {
200 192 connection.flush()?;
201 193
202 194 unsafe {
203 - let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
195 + let gc = x11::xlib::XCreateGC(display, self.surface.pixmap(), 0, std::ptr::null_mut());
204 196 x11::xlib::XSetForeground(display, gc, self.scheme_normal.background as u64);
205 197 x11::xlib::XFillRectangle(
206 198 display,
207 - self.pixmap,
199 + self.surface.pixmap(),
208 200 gc,
209 201 0,
210 202 0,
@@ -220,11 +212,14 @@ impl Bar {
220 212 let tag_mask = 1 << tag_index;
221 213 let is_selected = (current_tags & tag_mask) != 0;
222 214 let is_occupied = (occupied_tags & tag_mask) != 0;
215 + let is_urgent = (urgent_tags & tag_mask) != 0;
223 216
224 217 let tag_width = self.tag_widths[tag_index];
225 218
226 219 let scheme = if is_selected {
227 220 &self.scheme_selected
221 + } else if is_urgent {
222 + &self.scheme_urgent
228 223 } else if is_occupied {
229 224 &self.scheme_occupied
230 225 } else {
@@ -237,10 +232,11 @@ impl Bar {
237 232 let top_padding = 4;
238 233 let text_y = top_padding + font.ascent();
239 234
240 - self.font_draw
235 + self.surface
236 + .font_draw()
241 237 .draw_text(font, scheme.foreground, text_x, text_y, tag);
242 238
243 - if is_selected {
239 + if is_selected || is_urgent {
244 240 let font_height = font.height();
245 241 let underline_height = font_height / 8;
246 242 let bottom_gap = 3;
@@ -251,11 +247,11 @@ impl Bar {
251 247 let underline_x = x_position + (underline_padding / 2) as i16;
252 248
253 249 unsafe {
254 - let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
250 + let gc = x11::xlib::XCreateGC(display, self.surface.pixmap(), 0, std::ptr::null_mut());
255 251 x11::xlib::XSetForeground(display, gc, scheme.underline as u64);
256 252 x11::xlib::XFillRectangle(
257 253 display,
258 - self.pixmap,
254 + self.surface.pixmap(),
259 255 gc,
260 256 underline_x as i32,
261 257 underline_y as i32,
@@ -275,7 +271,7 @@ impl Bar {
275 271 let top_padding = 4;
276 272 let text_y = top_padding + font.ascent();
277 273
278 - self.font_draw.draw_text(
274 + self.surface.font_draw().draw_text(
279 275 font,
280 276 self.scheme_normal.foreground,
281 277 text_x,
@@ -291,7 +287,7 @@ impl Bar {
291 287 let text_x = x_position;
292 288 let text_y = top_padding + font.ascent();
293 289
294 - self.font_draw.draw_text(
290 + self.surface.font_draw().draw_text(
295 291 font,
296 292 self.scheme_selected.foreground,
297 293 text_x,
@@ -312,7 +308,8 @@ impl Bar {
312 308 let top_padding = 4;
313 309 let text_y = top_padding + font.ascent();
314 310
315 - self.font_draw
311 + self.surface
312 + .font_draw()
316 313 .draw_text(font, block.color(), x_position, text_y, &text);
317 314
318 315 if self.block_underlines[i] {
@@ -327,11 +324,11 @@ impl Bar {
327 324
328 325 unsafe {
329 326 let gc =
330 - x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
327 + x11::xlib::XCreateGC(display, self.surface.pixmap(), 0, std::ptr::null_mut());
331 328 x11::xlib::XSetForeground(display, gc, block.color() as u64);
332 329 x11::xlib::XFillRectangle(
333 330 display,
334 - self.pixmap,
331 + self.surface.pixmap(),
335 332 gc,
336 333 underline_x as i32,
337 334 underline_y as i32,
@@ -354,7 +351,7 @@ impl Bar {
354 351 );
355 352 x11::xlib::XCopyArea(
356 353 display,
357 - self.pixmap,
354 + self.surface.pixmap(),
358 355 self.window as x11::xlib::Drawable,
359 356 gc,
360 357 0,
@@ -365,7 +362,7 @@ impl Bar {
365 362 0,
366 363 );
367 364 x11::xlib::XFreeGC(display, gc);
368 - x11::xlib::XSync(display, 0);
365 + x11::xlib::XSync(display, 1);
369 366 }
370 367
371 368 self.needs_redraw = false;
@@ -408,16 +405,9 @@ impl Bar {
408 405 self.scheme_normal = config.scheme_normal;
409 406 self.scheme_occupied = config.scheme_occupied;
410 407 self.scheme_selected = config.scheme_selected;
408 + self.scheme_urgent = config.scheme_urgent;
411 409
412 410 self.status_text.clear();
413 411 self.needs_redraw = true;
414 412 }
415 413 }
416 -
417 -impl Drop for Bar {
418 - fn drop(&mut self) {
419 - unsafe {
420 - x11::xlib::XFreePixmap(self.display, self.pixmap);
421 - }
422 - }
423 -}
+29 −5 src/bar/blocks/shell.rs
@@ -1,13 +1,15 @@
1 1 use super::Block;
2 2 use crate::errors::BlockError;
3 3 use std::process::Command;
4 -use std::time::Duration;
4 +use std::time::{Duration, Instant};
5 5
6 6 pub struct ShellBlock {
7 7 format: String,
8 8 command: String,
9 9 interval: Duration,
10 10 color: u32,
11 + cached_output: Option<String>,
12 + last_run: Option<Instant>,
11 13 }
12 14
13 15 impl ShellBlock {
@@ -17,12 +19,12 @@ impl ShellBlock {
17 19 command: command.to_string(),
18 20 interval: Duration::from_secs(interval_secs),
19 21 color,
22 + cached_output: None,
23 + last_run: None,
20 24 }
21 25 }
22 -}
23 26
24 -impl Block for ShellBlock {
25 - fn content(&mut self) -> Result<String, BlockError> {
27 + fn execute(&mut self) -> Result<String, BlockError> {
26 28 let output = Command::new("sh")
27 29 .arg("-c")
28 30 .arg(&self.command)
@@ -37,7 +39,29 @@ impl Block for ShellBlock {
37 39 }
38 40
39 41 let result = String::from_utf8_lossy(&output.stdout).trim().to_string();
40 - Ok(self.format.replace("{}", &result))
42 + let formatted = self.format.replace("{}", &result);
43 +
44 + self.cached_output = Some(formatted.clone());
45 + self.last_run = Some(Instant::now());
46 +
47 + Ok(formatted)
48 + }
49 +}
50 +
51 +impl Block for ShellBlock {
52 + fn content(&mut self) -> Result<String, BlockError> {
53 + let should_refresh = match self.last_run {
54 + None => true,
55 + Some(last) => last.elapsed() >= self.interval,
56 + };
57 +
58 + if should_refresh {
59 + return self.execute();
60 + }
61 +
62 + self.cached_output
63 + .clone()
64 + .ok_or_else(|| BlockError::CommandFailed("No cached output".to_string()))
41 65 }
42 66
43 67 fn interval(&self) -> Duration {
+49 −1 src/bar/font.rs
@@ -135,7 +135,7 @@ impl FontDraw {
135 135 pub fn sync(&self) {
136 136 unsafe {
137 137 let display = x11::xft::XftDrawDisplay(self.xft_draw);
138 - x11::xlib::XSync(display, 0);
138 + x11::xlib::XSync(display, 1);
139 139 }
140 140 }
141 141 }
@@ -149,3 +149,51 @@ impl Drop for FontDraw {
149 149 }
150 150 }
151 151 }
152 +
153 +pub struct DrawingSurface {
154 + font_draw: FontDraw,
155 + pixmap: x11::xlib::Pixmap,
156 + display: *mut Display,
157 +}
158 +
159 +impl DrawingSurface {
160 + pub fn new(
161 + display: *mut Display,
162 + window: x11::xlib::Drawable,
163 + width: u32,
164 + height: u32,
165 + visual: *mut Visual,
166 + colormap: Colormap,
167 + ) -> Result<Self, crate::errors::X11Error> {
168 + let depth = unsafe { x11::xlib::XDefaultDepth(display, 0) };
169 + let pixmap = unsafe {
170 + x11::xlib::XCreatePixmap(display, window, width, height, depth as u32)
171 + };
172 +
173 + let font_draw = FontDraw::new(display, pixmap, visual, colormap)?;
174 +
175 + Ok(Self {
176 + font_draw,
177 + pixmap,
178 + display,
179 + })
180 + }
181 +
182 + pub fn pixmap(&self) -> x11::xlib::Pixmap {
183 + self.pixmap
184 + }
185 +
186 + pub fn font_draw(&self) -> &FontDraw {
187 + &self.font_draw
188 + }
189 +}
190 +
191 +impl Drop for DrawingSurface {
192 + fn drop(&mut self) {
193 + unsafe {
194 + x11::xft::XftDrawDestroy(self.font_draw.xft_draw);
195 + self.font_draw.xft_draw = std::ptr::null_mut();
196 + x11::xlib::XFreePixmap(self.display, self.pixmap);
197 + }
198 + }
199 +}
+5 −3 src/bin/main.rs
@@ -26,9 +26,11 @@ fn main() -> Result<(), MainError> {
26 26 Err(e) => return Err(MainError::CouldNotStartWm(e)),
27 27 };
28 28
29 - if let Some(warning) = config_warning {
30 - eprintln!("{warning}");
31 - window_manager.show_migration_overlay();
29 + if let Some(error) = config_error {
30 + // Change show_startup_config_error to accept a ConfigError instead of
31 + // a string slice.
32 + let error = format!("{error}");
33 + window_manager.show_startup_config_error(&error);
32 34 }
33 35
34 36 let should_restart = match window_manager.run() {
+10 −9 src/config/lua.rs
@@ -9,13 +9,13 @@ pub fn parse_lua_config(
9 9 ) -> Result<crate::Config, ConfigError> {
10 10 let lua = Lua::new();
11 11
12 - if let Some(dir) = config_dir {
13 - if let Some(dir_str) = dir.to_str() {
14 - let setup_code = format!("package.path = '{}/?.lua;' .. package.path", dir_str);
15 - lua.load(&setup_code)
16 - .exec()
17 - .map_err(|e| ConfigError::LuaError(format!("Failed to set package.path: {}", e)))?;
18 - }
12 + if let Some(dir) = config_dir
13 + && let Some(dir_str) = dir.to_str()
14 + {
15 + let setup_code = format!("package.path = '{}/?.lua;' .. package.path", dir_str);
16 + lua.load(&setup_code)
17 + .exec()
18 + .map_err(|e| ConfigError::LuaError(format!("Failed to set package.path: {}", e)))?;
19 19 }
20 20
21 21 let builder = lua_api::register_api(&lua)?;
@@ -26,7 +26,7 @@ pub fn parse_lua_config(
26 26
27 27 let builder_data = builder.borrow().clone();
28 28
29 - return Ok(crate::Config {
29 + Ok(crate::Config {
30 30 border_width: builder_data.border_width,
31 31 border_focused: builder_data.border_focused,
32 32 border_unfocused: builder_data.border_unfocused,
@@ -48,8 +48,9 @@ pub fn parse_lua_config(
48 48 scheme_normal: builder_data.scheme_normal,
49 49 scheme_occupied: builder_data.scheme_occupied,
50 50 scheme_selected: builder_data.scheme_selected,
51 + scheme_urgent: builder_data.scheme_urgent,
51 52 autostart: builder_data.autostart,
52 53 auto_tile: builder_data.auto_tile,
53 54 path: None,
54 - });
55 + })
55 56 }
+37 −15 src/config/lua_api.rs
@@ -32,6 +32,7 @@ pub struct ConfigBuilder {
32 32 pub scheme_normal: ColorScheme,
33 33 pub scheme_occupied: ColorScheme,
34 34 pub scheme_selected: ColorScheme,
35 + pub scheme_urgent: ColorScheme,
35 36 pub autostart: Vec<String>,
36 37 pub auto_tile: bool,
37 38 }
@@ -72,6 +73,11 @@ impl Default for ConfigBuilder {
72 73 background: 0x000000,
73 74 underline: 0x444444,
74 75 },
76 + scheme_urgent: ColorScheme {
77 + foreground: 0xff5555,
78 + background: 0x000000,
79 + underline: 0xff5555,
80 + },
75 81 autostart: Vec::new(),
76 82 auto_tile: false,
77 83 }
@@ -85,17 +91,17 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
85 91
86 92 let oxwm_table = lua.create_table()?;
87 93
88 - register_spawn(&lua, &oxwm_table, builder.clone())?;
89 - register_key_module(&lua, &oxwm_table, builder.clone())?;
90 - register_gaps_module(&lua, &oxwm_table, builder.clone())?;
91 - register_border_module(&lua, &oxwm_table, builder.clone())?;
92 - register_client_module(&lua, &oxwm_table)?;
93 - register_layout_module(&lua, &oxwm_table)?;
94 - register_tag_module(&lua, &oxwm_table, builder.clone())?;
95 - register_monitor_module(&lua, &oxwm_table)?;
96 - register_rule_module(&lua, &oxwm_table, builder.clone())?;
97 - register_bar_module(&lua, &oxwm_table, builder.clone())?;
98 - register_misc(&lua, &oxwm_table, builder.clone())?;
94 + register_spawn(lua, &oxwm_table, builder.clone())?;
95 + register_key_module(lua, &oxwm_table, builder.clone())?;
96 + register_gaps_module(lua, &oxwm_table, builder.clone())?;
97 + register_border_module(lua, &oxwm_table, builder.clone())?;
98 + register_client_module(lua, &oxwm_table)?;
99 + register_layout_module(lua, &oxwm_table)?;
100 + register_tag_module(lua, &oxwm_table, builder.clone())?;
101 + register_monitor_module(lua, &oxwm_table)?;
102 + register_rule_module(lua, &oxwm_table, builder.clone())?;
103 + register_bar_module(lua, &oxwm_table, builder.clone())?;
104 + register_misc(lua, &oxwm_table, builder.clone())?;
99 105
100 106 lua.globals().set("oxwm", oxwm_table)?;
101 107
@@ -705,6 +711,21 @@ fn register_bar_module(
705 711 Ok(())
706 712 })?;
707 713
714 + let builder_clone = builder.clone();
715 + let set_scheme_urgent =
716 + lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
717 + let foreground = parse_color_value(fg)?;
718 + let background = parse_color_value(bg)?;
719 + let underline = parse_color_value(ul)?;
720 +
721 + builder_clone.borrow_mut().scheme_urgent = ColorScheme {
722 + foreground,
723 + background,
724 + underline,
725 + };
726 + Ok(())
727 + })?;
728 +
708 729 bar_table.set("set_font", set_font)?;
709 730 bar_table.set("block", block_table)?;
710 731 bar_table.set("add_block", add_block)?; // Deprecated, for backwards compatibility
@@ -712,6 +733,7 @@ fn register_bar_module(
712 733 bar_table.set("set_scheme_normal", set_scheme_normal)?;
713 734 bar_table.set("set_scheme_occupied", set_scheme_occupied)?;
714 735 bar_table.set("set_scheme_selected", set_scheme_selected)?;
736 + bar_table.set("set_scheme_urgent", set_scheme_urgent)?;
715 737 parent.set("bar", bar_table)?;
716 738 Ok(())
717 739 }
@@ -934,15 +956,15 @@ fn parse_color_value(value: Value) -> mlua::Result<u32> {
934 956 Value::Number(n) => Ok(n as u32),
935 957 Value::String(s) => {
936 958 let s = s.to_str()?;
937 - if s.starts_with('#') {
938 - u32::from_str_radix(&s[1..], 16).map_err(|e| {
959 + if let Some(hex) = s.strip_prefix('#') {
960 + u32::from_str_radix(hex, 16).map_err(|e| {
939 961 mlua::Error::RuntimeError(format!(
940 962 "invalid hex color '{}': {}. use format like #ff0000 or 0xff0000",
941 963 s, e
942 964 ))
943 965 })
944 - } else if s.starts_with("0x") {
945 - u32::from_str_radix(&s[2..], 16).map_err(|e| {
966 + } else if let Some(hex) = s.strip_prefix("0x") {
967 + u32::from_str_radix(hex, 16).map_err(|e| {
946 968 mlua::Error::RuntimeError(format!(
947 969 "invalid hex color '{}': {}. use format like 0xff0000 or #ff0000",
948 970 s, e
+15 −16 src/keyboard/handlers.rs
@@ -146,10 +146,10 @@ impl KeyboardMapping {
146 146 ) -> Option<Keycode> {
147 147 for keycode in min_keycode..=max_keycode {
148 148 let index = (keycode - self.min_keycode) as usize * self.keysyms_per_keycode as usize;
149 - if let Some(&sym) = self.syms.get(index) {
150 - if sym == keysym {
151 - return Some(keycode);
152 - }
149 + if let Some(&sym) = self.syms.get(index)
150 + && sym == keysym
151 + {
152 + return Some(keycode);
153 153 }
154 154 }
155 155 None
@@ -218,19 +218,18 @@ pub fn grab_keys(
218 218 }
219 219 }
220 220
221 - if current_key > 0 {
222 - if let Some(escape_keycode) =
221 + if current_key > 0
222 + && let Some(escape_keycode) =
223 223 mapping.find_keycode(keysyms::XK_ESCAPE, min_keycode, max_keycode)
224 - {
225 - connection.grab_key(
226 - true,
227 - root,
228 - ModMask::ANY,
229 - escape_keycode,
230 - GrabMode::ASYNC,
231 - GrabMode::ASYNC,
232 - )?;
233 - }
224 + {
225 + connection.grab_key(
226 + true,
227 + root,
228 + ModMask::ANY,
229 + escape_keycode,
230 + GrabMode::ASYNC,
231 + GrabMode::ASYNC,
232 + )?;
234 233 }
235 234
236 235 connection.flush()?;
+197 −6 src/keyboard/keysyms.rs
@@ -76,12 +76,75 @@ pub const XK_COMMA: Keysym = 0x002c;
76 76 pub const XK_PERIOD: Keysym = 0x002e;
77 77 pub const XK_SLASH: Keysym = 0x002f;
78 78 pub const XK_PRINT: Keysym = 0xff61;
79 -
79 +pub const XK_AMPERSAND: Keysym = 0x26;
80 +pub const XK_AGRAVE: Keysym = 0xe0;
81 +pub const XK_CCEDILLA: Keysym = 0xe7;
82 +pub const XK_EGRAVE: Keysym = 0xe8;
83 +pub const XK_EACUTE: Keysym = 0xe9;
84 +pub const XK_PARENLEFT: Keysym = 0x28;
85 +pub const XK_PARENRIGHT: Keysym = 0x29;
86 +pub const XK_QUOTEDBL: Keysym = 0x22;
87 +pub const XK_UNDERSCORE: Keysym = 0x5f;
88 +pub const XK_HYPHEN: Keysym = 0xad;
89 +pub const XF86_AUDIO_MEDIA: Keysym = 0x1008ff32;
90 +pub const XF86_AUDIO_NEXT: Keysym = 0x1008ff17;
91 +pub const XF86_AUDIO_PAUSE: Keysym = 0x1008ff31;
92 +pub const XF86_AUDIO_PLAY: Keysym = 0x1008ff14;
93 +pub const XF86_AUDIO_PREV: Keysym = 0x1008ff16;
80 94 pub const XF86_AUDIO_RAISE_VOLUME: Keysym = 0x1008ff13;
81 95 pub const XF86_AUDIO_LOWER_VOLUME: Keysym = 0x1008ff11;
82 96 pub const XF86_AUDIO_MUTE: Keysym = 0x1008ff12;
97 +pub const XF86_AUDIO_MIC_MUTE: Keysym = 0x1008ffb2;
98 +pub const XF86_AUDIO_RECORD: Keysym = 0x1008ff1c;
99 +pub const XF86_AUDIO_REWIND: Keysym = 0x1008ff3e;
100 +pub const XF86_AUDIO_STOP: Keysym = 0x1008ff15;
101 +pub const XF86_BACK: Keysym = 0x1008ff26;
102 +pub const XF86_CALCULATOR: Keysym = 0x1008ff1d;
103 +pub const XF86_CLOSE: Keysym = 0x1008ff56;
104 +pub const XF86_COPY: Keysym = 0x1008ff57;
105 +pub const XF86_CUT: Keysym = 0x1008ff58;
106 +pub const XF86_DOS: Keysym = 0x1008ff5a;
107 +pub const XF86_DISPLAY: Keysym = 0x1008ff59;
108 +pub const XF86_DOCUMENTS: Keysym = 0x1008ff5b;
109 +pub const XF86_EJECT: Keysym = 0x1008ff2c;
110 +pub const XF86_EXPLORER: Keysym = 0x1008ff5d;
111 +pub const XF86_FAVORITES: Keysym = 0x1008ff30;
112 +pub const XF86_FINANCE: Keysym = 0x1008ff3c;
113 +pub const XF86_FORWARD: Keysym = 0x1008ff27;
114 +pub const XF86_GAME: Keysym = 0x1008ff5e;
115 +pub const XF86_GO: Keysym = 0x1008ff5f;
116 +pub const XF86_HOME_PAGE: Keysym = 0x1008ff18;
117 +pub const XF86_MAIL: Keysym = 0x1008ff19;
118 +pub const XF86_MAIL_FORWARD: Keysym = 0x1008ff90;
119 +pub const XF86_MENU_KB: Keysym = 0x1008ff65;
120 +pub const XF86_MESSENGER: Keysym = 0x1008ff8e;
83 121 pub const XF86_MON_BRIGHTNESS_UP: Keysym = 0x1008ff02;
84 122 pub const XF86_MON_BRIGHTNESS_DOWN: Keysym = 0x1008ff03;
123 +pub const XF86_MY_COMPUTER: Keysym = 0x1008ff33;
124 +pub const XF86_NEW: Keysym = 0x1008ff68;
125 +pub const XF86_NEXT_VMODE: Keysym = 0x1008fe22;
126 +pub const XF86_PREV_VMODE: Keysym = 0x1008fe23;
127 +pub const XF86_OPEN: Keysym = 0x1008ff6b;
128 +pub const XF86_PASTE: Keysym = 0x1008ff6d;
129 +pub const XF86_PHONE: Keysym = 0x1008ff6e;
130 +pub const XF86_POWER_OFF: Keysym = 0x1008ff2a;
131 +pub const XF86_RELOAD: Keysym = 0x1008ff73;
132 +pub const XF86_REPLY: Keysym = 0x1008ff72;
133 +pub const XF86_ROTATE_WINDOWS: Keysym = 0x1008ff74;
134 +pub const XF86_SAVE: Keysym = 0x1008ff77;
135 +pub const XF86_SCREEN_SAVER: Keysym = 0x1008ff2d;
136 +pub const XF86_SCROLL_DOWN: Keysym = 0x1008ff79;
137 +pub const XF86_SCROLL_UP: Keysym = 0x1008ff78;
138 +pub const XF86_SEARCH: Keysym = 0x1008ff1b;
139 +pub const XF86_SEND: Keysym = 0x1008ff7b;
140 +pub const XF86_SHOP: Keysym = 0x1008ff36;
141 +pub const XF86_SLEEP: Keysym = 0x1008ff2f;
142 +pub const XF86_TASK_PANE: Keysym = 0x1008ff7f;
143 +pub const XF86_TOOLS: Keysym = 0x1008ff81;
144 +pub const XF86_WWW: Keysym = 0x1008ff2e;
145 +pub const XF86_WAKE_UP: Keysym = 0x1008ff2b;
146 +pub const XF86_WEBCAM: Keysym = 0x1008ff8f;
147 +pub const XF86_XFER: Keysym = 0x1008ff8a;
85 148
86 149 pub fn keysym_from_str(s: &str) -> Option<Keysym> {
87 150 match s {
@@ -160,11 +223,75 @@ pub fn keysym_from_str(s: &str) -> Option<Keysym> {
160 223 "Period" => Some(XK_PERIOD),
161 224 "Slash" => Some(XK_SLASH),
162 225 "Print" => Some(XK_PRINT),
163 - "AudioRaiseVolume" => Some(XF86_AUDIO_RAISE_VOLUME),
164 - "AudioLowerVolume" => Some(XF86_AUDIO_LOWER_VOLUME),
165 - "AudioMute" => Some(XF86_AUDIO_MUTE),
166 - "MonBrightnessUp" => Some(XF86_MON_BRIGHTNESS_UP),
167 - "MonBrightnessDown" => Some(XF86_MON_BRIGHTNESS_DOWN),
226 + "Ampersand" => Some(XK_AMPERSAND),
227 + "Agrave" => Some(XK_AGRAVE),
228 + "Ccedilla" => Some(XK_CCEDILLA),
229 + "Egrave" => Some(XK_EGRAVE),
230 + "Eacute" => Some(XK_EACUTE),
231 + "ParenLeft" => Some(XK_PARENLEFT),
232 + "ParenRight" => Some(XK_PARENRIGHT),
233 + "QuoteDouble" => Some(XK_QUOTEDBL),
234 + "Underscore" => Some(XK_UNDERSCORE),
235 + "Hyphen" => Some(XK_HYPHEN),
236 + "AudioMedia" | "XF86AudioMedia" => Some(XF86_AUDIO_MEDIA),
237 + "XF86AudioNext" => Some(XF86_AUDIO_NEXT),
238 + "XF86AudioPause" => Some(XF86_AUDIO_PAUSE),
239 + "XF86AudioPlay" => Some(XF86_AUDIO_PLAY),
240 + "XF86AudioPrev" => Some(XF86_AUDIO_PREV),
241 + "AudioRaiseVolume" | "XF86AudioRaiseVolume" => Some(XF86_AUDIO_RAISE_VOLUME),
242 + "AudioLowerVolume" | "XF86AudioLowerVolume" => Some(XF86_AUDIO_LOWER_VOLUME),
243 + "AudioMute" | "XF86AudioMute" => Some(XF86_AUDIO_MUTE),
244 + "XF86AudioMicMute" => Some(XF86_AUDIO_MIC_MUTE),
245 + "XF86AudioRecord" => Some(XF86_AUDIO_RECORD),
246 + "XF86AudioRewind" => Some(XF86_AUDIO_REWIND),
247 + "XF86AudioStop" => Some(XF86_AUDIO_STOP),
248 + "XF86Back" => Some(XF86_BACK),
249 + "XF86Calculator" => Some(XF86_CALCULATOR),
250 + "XF86Close" => Some(XF86_CLOSE),
251 + "XF86Copy" => Some(XF86_COPY),
252 + "XF86Cut" => Some(XF86_CUT),
253 + "XF86DOS" => Some(XF86_DOS),
254 + "XF86Display" => Some(XF86_DISPLAY),
255 + "XF86Documents" => Some(XF86_DOCUMENTS),
256 + "XF86Eject" => Some(XF86_EJECT),
257 + "XF86Explorer" => Some(XF86_EXPLORER),
258 + "XF86Favorites" => Some(XF86_FAVORITES),
259 + "XF86Finance" => Some(XF86_FINANCE),
260 + "XF86Forward" => Some(XF86_FORWARD),
261 + "XF86Game" => Some(XF86_GAME),
262 + "XF86Go" => Some(XF86_GO),
263 + "XF86HomePage" => Some(XF86_HOME_PAGE),
264 + "XF86Mail" => Some(XF86_MAIL),
265 + "XF86MailForward" => Some(XF86_MAIL_FORWARD),
266 + "XF86MenuKB" => Some(XF86_MENU_KB),
267 + "XF86Messenger" => Some(XF86_MESSENGER),
268 + "MonBrightnessUp" | "XF86MonBrightnessUp" => Some(XF86_MON_BRIGHTNESS_UP),
269 + "MonBrightnessDown" | "XF86MonBrightnessDown" => Some(XF86_MON_BRIGHTNESS_DOWN),
270 + "XF86MyComputer" => Some(XF86_MY_COMPUTER),
271 + "XF86New" => Some(XF86_NEW),
272 + "XF86Next_VMode" => Some(XF86_NEXT_VMODE),
273 + "XF86Prev_VMode" => Some(XF86_PREV_VMODE),
274 + "XF86Open" => Some(XF86_OPEN),
275 + "XF86Paste" => Some(XF86_PASTE),
276 + "XF86Phone" => Some(XF86_PHONE),
277 + "XF86PowerOff" => Some(XF86_POWER_OFF),
278 + "XF86Reload" => Some(XF86_RELOAD),
279 + "XF86Reply" => Some(XF86_REPLY),
280 + "XF86RotateWindows" => Some(XF86_ROTATE_WINDOWS),
281 + "XF86Save" => Some(XF86_SAVE),
282 + "XF86ScreenSaver" => Some(XF86_SCREEN_SAVER),
283 + "XF86ScrollDown" => Some(XF86_SCROLL_DOWN),
284 + "XF86ScrollUp" => Some(XF86_SCROLL_UP),
285 + "XF86Search" => Some(XF86_SEARCH),
286 + "XF86Send" => Some(XF86_SEND),
287 + "XF86Shop" => Some(XF86_SHOP),
288 + "XF86Sleep" => Some(XF86_SLEEP),
289 + "XF86TaskPane" => Some(XF86_TASK_PANE),
290 + "XF86Tools" => Some(XF86_TOOLS),
291 + "XF86WWW" => Some(XF86_WWW),
292 + "XF86WakeUp" => Some(XF86_WAKE_UP),
293 + "XF86WebCam" => Some(XF86_WEBCAM),
294 + "XF86Xfer" => Some(XF86_XFER),
168 295 _ => None,
169 296 }
170 297 }
@@ -210,11 +337,75 @@ pub fn format_keysym(keysym: Keysym) -> String {
210 337 XK_APOSTROPHE => "'".to_string(),
211 338 XK_BACKSLASH => "\\".to_string(),
212 339 XK_PRINT => "Print".to_string(),
340 + XK_AMPERSAND => "&".to_string(),
341 + XK_AGRAVE => "à".to_string(),
342 + XK_CCEDILLA => "ç".to_string(),
343 + XK_EGRAVE => "è".to_string(),
344 + XK_EACUTE => "é".to_string(),
345 + XK_PARENLEFT => "(".to_string(),
346 + XK_PARENRIGHT => ")".to_string(),
347 + XK_QUOTEDBL => "\"".to_string(),
348 + XK_UNDERSCORE => "_".to_string(),
349 + XK_HYPHEN => "-".to_string(),
350 + XF86_AUDIO_MEDIA => "Media".to_string(),
351 + XF86_AUDIO_NEXT => "Next".to_string(),
352 + XF86_AUDIO_PAUSE => "Pause".to_string(),
353 + XF86_AUDIO_PLAY => "Play".to_string(),
354 + XF86_AUDIO_PREV => "Prev".to_string(),
213 355 XF86_AUDIO_RAISE_VOLUME => "Vol+".to_string(),
214 356 XF86_AUDIO_LOWER_VOLUME => "Vol-".to_string(),
215 357 XF86_AUDIO_MUTE => "Mute".to_string(),
358 + XF86_AUDIO_MIC_MUTE => "MicMute".to_string(),
359 + XF86_AUDIO_RECORD => "Record".to_string(),
360 + XF86_AUDIO_REWIND => "Rewind".to_string(),
361 + XF86_AUDIO_STOP => "Stop".to_string(),
362 + XF86_BACK => "Back".to_string(),
363 + XF86_CALCULATOR => "Calculator".to_string(),
364 + XF86_CLOSE => "Close".to_string(),
365 + XF86_COPY => "Copy".to_string(),
366 + XF86_CUT => "Cut".to_string(),
367 + XF86_DOS => "DOS".to_string(),
368 + XF86_DISPLAY => "Display".to_string(),
369 + XF86_DOCUMENTS => "Documents".to_string(),
370 + XF86_EJECT => "Eject".to_string(),
371 + XF86_EXPLORER => "Explorer".to_string(),
372 + XF86_FAVORITES => "Favorites".to_string(),
373 + XF86_FINANCE => "Finance".to_string(),
374 + XF86_FORWARD => "Forward".to_string(),
375 + XF86_GAME => "Game".to_string(),
376 + XF86_GO => "Go".to_string(),
377 + XF86_HOME_PAGE => "HomePage".to_string(),
378 + XF86_MAIL => "Mail".to_string(),
379 + XF86_MAIL_FORWARD => "MailForward".to_string(),
380 + XF86_MENU_KB => "MenuKB".to_string(),
381 + XF86_MESSENGER => "Messenger".to_string(),
216 382 XF86_MON_BRIGHTNESS_UP => "Bright+".to_string(),
217 383 XF86_MON_BRIGHTNESS_DOWN => "Bright-".to_string(),
384 + XF86_MY_COMPUTER => "MyComputer".to_string(),
385 + XF86_NEW => "New".to_string(),
386 + XF86_NEXT_VMODE => "NextVMode".to_string(),
387 + XF86_PREV_VMODE => "PrevVMode".to_string(),
388 + XF86_OPEN => "Open".to_string(),
389 + XF86_PASTE => "Paste".to_string(),
390 + XF86_PHONE => "Phone".to_string(),
391 + XF86_POWER_OFF => "PowerOff".to_string(),
392 + XF86_RELOAD => "Reload".to_string(),
393 + XF86_REPLY => "Reply".to_string(),
394 + XF86_ROTATE_WINDOWS => "RotateWindows".to_string(),
395 + XF86_SAVE => "Save".to_string(),
396 + XF86_SCREEN_SAVER => "ScreenSaver".to_string(),
397 + XF86_SCROLL_DOWN => "ScrollDown".to_string(),
398 + XF86_SCROLL_UP => "ScrollUp".to_string(),
399 + XF86_SEARCH => "Search".to_string(),
400 + XF86_SEND => "Send".to_string(),
401 + XF86_SHOP => "Shop".to_string(),
402 + XF86_SLEEP => "Sleep".to_string(),
403 + XF86_TASK_PANE => "TaskPane".to_string(),
404 + XF86_TOOLS => "Tools".to_string(),
405 + XF86_WWW => "WWW".to_string(),
406 + XF86_WAKE_UP => "WakeUp".to_string(),
407 + XF86_WEBCAM => "WebCam".to_string(),
408 + XF86_XFER => "Xfer".to_string(),
218 409 XK_A..=XK_Z => {
219 410 let ch = (keysym - XK_A + b'A' as u32) as u8 as char;
220 411 ch.to_string()
+9 −3 src/layout/mod.rs
@@ -4,6 +4,8 @@ pub mod normie;
4 4 pub mod tabbed;
5 5 pub mod tiling;
6 6
7 +use std::str::FromStr;
8 +
7 9 use x11rb::protocol::xproto::Window;
8 10
9 11 pub type LayoutBox = Box<dyn Layout>;
@@ -24,7 +26,7 @@ pub enum LayoutType {
24 26 }
25 27
26 28 impl LayoutType {
27 - pub fn new(&self) -> LayoutBox {
29 + pub fn to_boxed_layout(&self) -> LayoutBox {
28 30 match self {
29 31 Self::Tiling => Box::new(tiling::TilingLayout),
30 32 Self::Normie => Box::new(normie::NormieLayout),
@@ -53,8 +55,12 @@ impl LayoutType {
53 55 Self::Tabbed => "tabbed",
54 56 }
55 57 }
58 +}
59 +
60 +impl FromStr for LayoutType {
61 + type Err = String;
56 62
57 - pub fn from_str(s: &str) -> Result<Self, String> {
63 + fn from_str(s: &str) -> Result<Self, String> {
58 64 match s.to_lowercase().as_str() {
59 65 "tiling" => Ok(Self::Tiling),
60 66 "normie" | "floating" => Ok(Self::Normie),
@@ -68,7 +74,7 @@ impl LayoutType {
68 74
69 75 pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
70 76 let layout_type = LayoutType::from_str(s)?;
71 - Ok(layout_type.new())
77 + Ok(layout_type.to_boxed_layout())
72 78 }
73 79
74 80 pub fn next_layout(current_name: &str) -> &'static str {
+3 −9 src/layout/tiling.rs
@@ -54,10 +54,8 @@ impl TilingLayout {
54 54 for i in 0..window_count {
55 55 if i < num_master {
56 56 master_total += (master_size as f32 / master_facts) as i32;
57 - } else {
58 - if stack_facts > 0.0 {
59 - stack_total += (stack_size as f32 / stack_facts) as i32;
60 - }
57 + } else if stack_facts > 0.0 {
58 + stack_total += (stack_size as f32 / stack_facts) as i32;
61 59 }
62 60 }
63 61
@@ -108,11 +106,7 @@ impl Layout for TilingLayout {
108 106
109 107 let num_master_usize = num_master.max(0) as usize;
110 108 let master_count = window_count.min(num_master_usize);
111 - let stack_count = if window_count > num_master_usize {
112 - window_count - num_master_usize
113 - } else {
114 - 0
115 - };
109 + let stack_count = window_count.saturating_sub(num_master_usize);
116 110
117 111 let master_height = (screen_height as i32)
118 112 - (2 * outer_gap_horizontal) as i32
+9 −3 src/lib.rs
@@ -43,15 +43,15 @@ impl WindowRule {
43 43 let class_matches = self
44 44 .class
45 45 .as_ref()
46 - .map_or(true, |c| class.contains(c.as_str()));
46 + .is_none_or(|c| class.contains(c.as_str()));
47 47 let instance_matches = self
48 48 .instance
49 49 .as_ref()
50 - .map_or(true, |i| instance.contains(i.as_str()));
50 + .is_none_or(|i| instance.contains(i.as_str()));
51 51 let title_matches = self
52 52 .title
53 53 .as_ref()
54 - .map_or(true, |t| title.contains(t.as_str()));
54 + .is_none_or(|t| title.contains(t.as_str()));
55 55 class_matches && instance_matches && title_matches
56 56 }
57 57 }
@@ -99,6 +99,7 @@ pub struct Config {
99 99 pub scheme_normal: ColorScheme,
100 100 pub scheme_occupied: ColorScheme,
101 101 pub scheme_selected: ColorScheme,
102 + pub scheme_urgent: ColorScheme,
102 103
103 104 pub autostart: Vec<String>,
104 105 pub auto_tile: bool,
@@ -345,6 +346,11 @@ impl Default for Config {
345 346 background: 0x1a1b26,
346 347 underline: 0xad8ee6,
347 348 },
349 + scheme_urgent: ColorScheme {
350 + foreground: 0xff5555,
351 + background: 0x1a1b26,
352 + underline: 0xff5555,
353 + },
348 354 autostart: vec![],
349 355 auto_tile: false,
350 356 }
+1 −1 src/monitor.rs
@@ -102,7 +102,7 @@ pub fn detect_monitors(
102 102 .xinerama_is_active()
103 103 .ok()
104 104 .and_then(|cookie| cookie.reply().ok())
105 - .map_or(false, |reply| reply.state != 0);
105 + .is_some_and(|reply| reply.state != 0);
106 106
107 107 if xinerama_active {
108 108 let Ok(xinerama_cookie) = connection.xinerama_query_screens() else {
+6 −6 src/overlay/keybind.rs
@@ -168,12 +168,12 @@ impl KeybindOverlay {
168 168 .filter(|kb| kb.func == action)
169 169 .min_by_key(|kb| kb.keys.len());
170 170
171 - if let Some(binding) = binding {
172 - if !binding.keys.is_empty() {
173 - let key_str = self.format_key_combo(&binding.keys[0]);
174 - let action_str = self.action_description(binding);
175 - result.push((key_str, action_str));
176 - }
171 + if let Some(binding) = binding
172 + && !binding.keys.is_empty()
173 + {
174 + let key_str = self.format_key_combo(&binding.keys[0]);
175 + let action_str = self.action_description(binding);
176 + result.push((key_str, action_str));
177 177 }
178 178 }
179 179
+27 −47 src/tab_bar.rs
@@ -1,5 +1,5 @@
1 1 use crate::ColorScheme;
2 -use crate::bar::font::{Font, FontDraw};
2 +use crate::bar::font::{DrawingSurface, Font};
3 3 use crate::errors::X11Error;
4 4 use crate::layout::tabbed::TAB_BAR_HEIGHT;
5 5 use x11rb::COPY_DEPTH_FROM_PARENT;
@@ -14,9 +14,8 @@ pub struct TabBar {
14 14 x_offset: i16,
15 15 y_offset: i16,
16 16 graphics_context: Gcontext,
17 - pixmap: x11::xlib::Pixmap,
18 17 display: *mut x11::xlib::Display,
19 - font_draw: FontDraw,
18 + surface: DrawingSurface,
20 19 scheme_normal: ColorScheme,
21 20 scheme_selected: ColorScheme,
22 21 }
@@ -69,19 +68,15 @@ impl TabBar {
69 68
70 69 let visual = unsafe { x11::xlib::XDefaultVisual(display, screen_num as i32) };
71 70 let colormap = unsafe { x11::xlib::XDefaultColormap(display, screen_num as i32) };
72 - let depth = unsafe { x11::xlib::XDefaultDepth(display, screen_num as i32) };
73 71
74 - let pixmap = unsafe {
75 - x11::xlib::XCreatePixmap(
76 - display,
77 - window as x11::xlib::Drawable,
78 - width as u32,
79 - height as u32,
80 - depth as u32,
81 - )
82 - };
83 -
84 - let font_draw = FontDraw::new(display, pixmap, visual, colormap)?;
72 + let surface = DrawingSurface::new(
73 + display,
74 + window as x11::xlib::Drawable,
75 + width as u32,
76 + height as u32,
77 + visual,
78 + colormap,
79 + )?;
85 80
86 81 Ok(Self {
87 82 window,
@@ -90,9 +85,8 @@ impl TabBar {
90 85 x_offset: x,
91 86 y_offset: y,
92 87 graphics_context,
93 - pixmap,
94 88 display,
95 - font_draw,
89 + surface,
96 90 scheme_normal,
97 91 scheme_selected,
98 92 })
@@ -116,11 +110,11 @@ impl TabBar {
116 110 connection.flush()?;
117 111
118 112 unsafe {
119 - let gc = x11::xlib::XCreateGC(self.display, self.pixmap, 0, std::ptr::null_mut());
113 + let gc = x11::xlib::XCreateGC(self.display, self.surface.pixmap(), 0, std::ptr::null_mut());
120 114 x11::xlib::XSetForeground(self.display, gc, self.scheme_normal.background as u64);
121 115 x11::xlib::XFillRectangle(
122 116 self.display,
123 - self.pixmap,
117 + self.surface.pixmap(),
124 118 gc,
125 119 0,
126 120 0,
@@ -158,7 +152,8 @@ impl TabBar {
158 152 let top_padding = 6;
159 153 let text_y = top_padding + font.ascent();
160 154
161 - self.font_draw
155 + self.surface
156 + .font_draw()
162 157 .draw_text(font, scheme.foreground, text_x, text_y, &display_title);
163 158
164 159 if is_focused {
@@ -167,11 +162,11 @@ impl TabBar {
167 162
168 163 unsafe {
169 164 let gc =
170 - x11::xlib::XCreateGC(self.display, self.pixmap, 0, std::ptr::null_mut());
165 + x11::xlib::XCreateGC(self.display, self.surface.pixmap(), 0, std::ptr::null_mut());
171 166 x11::xlib::XSetForeground(self.display, gc, scheme.underline as u64);
172 167 x11::xlib::XFillRectangle(
173 168 self.display,
174 - self.pixmap,
169 + self.surface.pixmap(),
175 170 gc,
176 171 x_position as i32,
177 172 underline_y as i32,
@@ -195,7 +190,7 @@ impl TabBar {
195 190 x11::xlib::XCreateGC(self.display, self.window as u64, 0, std::ptr::null_mut());
196 191 x11::xlib::XCopyArea(
197 192 self.display,
198 - self.pixmap,
193 + self.surface.pixmap(),
199 194 self.window as u64,
200 195 gc,
201 196 0,
@@ -239,24 +234,17 @@ impl TabBar {
239 234 .width(width as u32),
240 235 )?;
241 236
242 - unsafe {
243 - x11::xlib::XFreePixmap(self.display, self.pixmap);
244 - }
245 -
246 - let depth = unsafe { x11::xlib::XDefaultDepth(self.display, 0) };
247 - self.pixmap = unsafe {
248 - x11::xlib::XCreatePixmap(
249 - self.display,
250 - self.window as x11::xlib::Drawable,
251 - width as u32,
252 - self.height as u32,
253 - depth as u32,
254 - )
255 - };
256 -
257 237 let visual = unsafe { x11::xlib::XDefaultVisual(self.display, 0) };
258 238 let colormap = unsafe { x11::xlib::XDefaultColormap(self.display, 0) };
259 - self.font_draw = FontDraw::new(self.display, self.pixmap, visual, colormap)?;
239 +
240 + self.surface = DrawingSurface::new(
241 + self.display,
242 + self.window as x11::xlib::Drawable,
243 + width as u32,
244 + self.height as u32,
245 + visual,
246 + colormap,
247 + )?;
260 248
261 249 connection.flush()?;
262 250 Ok(())
@@ -274,11 +262,3 @@ impl TabBar {
274 262 Ok(())
275 263 }
276 264 }
277 -
278 -impl Drop for TabBar {
279 - fn drop(&mut self) {
280 - unsafe {
281 - x11::xlib::XFreePixmap(self.display, self.pixmap);
282 - }
283 - }
284 -}
+411 −570 src/window_manager.rs Large diff collapsed, click to expand
@@ -127,11 +127,9 @@ pub struct WindowManager {
127 127 gaps_enabled: bool,
128 128 floating_windows: HashSet<Window>,
129 129 fullscreen_windows: HashSet<Window>,
130 - floating_geometry_before_fullscreen: HashMap<Window, (i16, i16, u16, u16, u16)>,
131 130 bars: Vec<Bar>,
132 131 tab_bars: Vec<crate::tab_bar::TabBar>,
133 132 show_bar: bool,
134 - last_layout: Option<&'static str>,
135 133 monitors: Vec<Monitor>,
136 134 selected_monitor: usize,
137 135 atoms: AtomCache,
@@ -286,11 +284,9 @@ impl WindowManager {
286 284 gaps_enabled,
287 285 floating_windows: HashSet::new(),
288 286 fullscreen_windows: HashSet::new(),
289 - floating_geometry_before_fullscreen: HashMap::new(),
290 287 bars,
291 288 tab_bars,
292 289 show_bar: true,
293 - last_layout: None,
294 290 monitors,
295 291 selected_monitor: 0,
296 292 atoms,
@@ -316,16 +312,7 @@ impl WindowManager {
316 312 Ok(window_manager)
317 313 }
318 314
319 - pub fn show_migration_overlay(&mut self) {
320 - let message = "We are on version 0.8.0 now.\n\n\
321 - Your config file has been deprecated once again.\n\
322 - Backup your current config, and run oxwm --init to generate a new one with correct values.\n\n\
323 - Please reach out to Tony, or check out the\n\
324 - documentation for help with migration.\n\n\
325 - We appreciate you testing oxwm!\n\n\
326 - Press Mod+Shift+/ to see keybinds\n\
327 - Press Mod+Shift+R to reload after fixing your config";
328 -
315 + pub fn show_startup_config_error(&mut self, error: &str) {
329 316 let monitor = &self.monitors[self.selected_monitor];
330 317 let monitor_x = monitor.screen_x as i16;
331 318 let monitor_y = monitor.screen_y as i16;
@@ -335,19 +322,19 @@ impl WindowManager {
335 322 if let Err(e) = self.overlay.show_error(
336 323 &self.connection,
337 324 &self.font,
338 - message,
325 + error,
339 326 monitor_x,
340 327 monitor_y,
341 328 screen_width,
342 329 screen_height,
343 330 ) {
344 - eprintln!("Failed to show migration overlay: {:?}", e);
331 + eprintln!("Failed to show config error overlay: {:?}", e);
345 332 }
346 333 }
347 334
348 335 fn try_reload_config(&mut self) -> Result<(), String> {
349 336 let lua_path =
350 - self.config.path.take().ok_or(
337 + self.config.path.as_ref().ok_or(
351 338 "Could not find config file. Config path should've been set while loading",
352 339 )?;
353 340
@@ -355,7 +342,7 @@ impl WindowManager {
355 342 return Err("Could not find config file, has it been moved?".to_string());
356 343 }
357 344
358 - let config_str = std::fs::read_to_string(&lua_path)
345 + let config_str = std::fs::read_to_string(lua_path)
359 346 .map_err(|e| format!("Failed to read config: {}", e))?;
360 347
361 348 let config_dir = lua_path.parent();
@@ -363,8 +350,10 @@ impl WindowManager {
363 350 let new_config = crate::config::parse_lua_config(&config_str, config_dir)
364 351 .map_err(|e| format!("{}", e))?;
365 352
353 + let lua_path = self.config.path.take();
354 +
366 355 self.config = new_config;
367 - self.config.path = Some(lua_path);
356 + self.config.path = lua_path;
368 357 self.error_message = None;
369 358
370 359 for bar in &mut self.bars {
@@ -546,10 +535,10 @@ impl WindowManager {
546 535 }
547 536 let focused = focused.unwrap();
548 537
549 - if let Some(client) = self.clients.get(&focused) {
550 - if client.is_fullscreen {
551 - return Ok(());
552 - }
538 + if let Some(client) = self.clients.get(&focused)
539 + && client.is_fullscreen
540 + {
541 + return Ok(());
553 542 }
554 543
555 544 let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) {
@@ -594,7 +583,7 @@ impl WindowManager {
594 583
595 584 fn set_master_factor(&mut self, delta: f32) -> WmResult<()> {
596 585 if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
597 - let new_mfact = (monitor.master_factor + delta).max(0.05).min(0.95);
586 + let new_mfact = (monitor.master_factor + delta).clamp(0.05, 0.95);
598 587 monitor.master_factor = new_mfact;
599 588 self.apply_layout()?;
600 589 }
@@ -670,9 +659,13 @@ impl WindowManager {
670 659 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
671 660 if let Some(bar) = self.bars.get_mut(monitor_index) {
672 661 let mut occupied_tags: TagMask = 0;
662 + let mut urgent_tags: TagMask = 0;
673 663 for client in self.clients.values() {
674 664 if client.monitor_index == monitor_index {
675 665 occupied_tags |= client.tags;
666 + if client.is_urgent {
667 + urgent_tags |= client.tags;
668 + }
676 669 }
677 670 }
678 671
@@ -684,6 +677,7 @@ impl WindowManager {
684 677 self.display,
685 678 monitor.tagset[monitor.selected_tags_index],
686 679 occupied_tags,
680 + urgent_tags,
687 681 draw_blocks,
688 682 &layout_symbol,
689 683 keychord_indicator.as_deref(),
@@ -744,13 +738,6 @@ impl WindowManager {
744 738 }
745 739 }
746 740 KeyAction::ToggleFullScreen => {
747 - // Disable gaps and save previous state in config if not already in fullscreen
748 - if self.fullscreen_windows.is_empty() {
749 - self.config.gaps_enabled = std::mem::take(&mut self.gaps_enabled);
750 - } else {
751 - self.gaps_enabled = self.config.gaps_enabled;
752 - }
753 -
754 741 self.fullscreen()?;
755 742 self.restack()?;
756 743 }
@@ -794,11 +781,13 @@ impl WindowManager {
794 781 KeyAction::FocusStack => {
795 782 if let Arg::Int(direction) = arg {
796 783 self.focusstack(*direction)?;
784 + self.restack()?;
797 785 }
798 786 }
799 787 KeyAction::MoveStack => {
800 788 if let Arg::Int(direction) = arg {
801 789 self.move_stack(*direction)?;
790 + self.restack()?;
802 791 }
803 792 }
804 793 KeyAction::Quit | KeyAction::Restart => {
@@ -993,10 +982,10 @@ impl WindowManager {
993 982 ) -> WmResult<()> {
994 983 let current_monitor_index = self.clients.get(&window).map(|c| c.monitor_index);
995 984
996 - if let Some(current_idx) = current_monitor_index {
997 - if current_idx == target_monitor_index {
998 - return Ok(());
999 - }
985 + if let Some(current_idx) = current_monitor_index
986 + && current_idx == target_monitor_index
987 + {
988 + return Ok(());
1000 989 }
1001 990
1002 991 self.unfocus(window)?;
@@ -1030,12 +1019,10 @@ impl WindowManager {
1030 1019 } else {
1031 1020 Some(0)
1032 1021 }
1022 + } else if self.selected_monitor == 0 {
1023 + Some(self.monitors.len() - 1)
1033 1024 } else {
1034 - if self.selected_monitor == 0 {
1035 - Some(self.monitors.len() - 1)
1036 - } else {
1037 - Some(self.selected_monitor - 1)
1038 - }
1025 + Some(self.selected_monitor - 1)
1039 1026 }
1040 1027 }
1041 1028
@@ -1405,34 +1392,34 @@ impl WindowManager {
1405 1392 .get_property(false, window, AtomEnum::WM_HINTS, AtomEnum::WM_HINTS, 0, 9)?
1406 1393 .reply();
1407 1394
1408 - if let Ok(hints) = hints_reply {
1409 - if hints.value.len() >= 4 {
1410 - let mut flags = u32::from_ne_bytes([
1411 - hints.value[0],
1412 - hints.value[1],
1413 - hints.value[2],
1414 - hints.value[3],
1415 - ]);
1416 -
1417 - if urgent {
1418 - flags |= 256;
1419 - } else {
1420 - flags &= !256;
1421 - }
1395 + if let Ok(hints) = hints_reply
1396 + && hints.value.len() >= 4
1397 + {
1398 + let mut flags = u32::from_ne_bytes([
1399 + hints.value[0],
1400 + hints.value[1],
1401 + hints.value[2],
1402 + hints.value[3],
1403 + ]);
1404 +
1405 + if urgent {
1406 + flags |= 256;
1407 + } else {
1408 + flags &= !256;
1409 + }
1422 1410
1423 - let mut new_hints = hints.value.clone();
1424 - new_hints[0..4].copy_from_slice(&flags.to_ne_bytes());
1411 + let mut new_hints = hints.value.clone();
1412 + new_hints[0..4].copy_from_slice(&flags.to_ne_bytes());
1425 1413
1426 - self.connection.change_property(
1427 - PropMode::REPLACE,
1428 - window,
1429 - AtomEnum::WM_HINTS,
1430 - AtomEnum::WM_HINTS,
1431 - 32,
1432 - new_hints.len() as u32 / 4,
1433 - &new_hints,
1434 - )?;
1435 - }
1414 + self.connection.change_property(
1415 + PropMode::REPLACE,
1416 + window,
1417 + AtomEnum::WM_HINTS,
1418 + AtomEnum::WM_HINTS,
1419 + 32,
1420 + new_hints.len() as u32 / 4,
1421 + &new_hints,
1422 + )?;
1436 1423 }
1437 1424
1438 1425 Ok(())
@@ -1459,163 +1446,16 @@ impl WindowManager {
1459 1446 }
1460 1447
1461 1448 fn fullscreen(&mut self) -> WmResult<()> {
1462 - if self.show_bar {
1463 - let Some(focused_window) = self
1464 - .monitors
1465 - .get(self.selected_monitor)
1466 - .and_then(|m| m.selected_client)
1467 - else {
1468 - return Ok(());
1469 - };
1470 -
1471 - self.fullscreen_windows.insert(focused_window);
1472 -
1473 - let windows: Vec<Window> = self
1474 - .windows
1475 - .iter()
1476 - .filter(|&&w| self.is_window_visible(w))
1477 - .copied()
1478 - .collect();
1479 -
1480 - for window in &windows {
1481 - if let Ok(geom) = self.connection.get_geometry(*window)?.reply() {
1482 - self.floating_geometry_before_fullscreen.insert(
1483 - *window,
1484 - (
1485 - geom.x,
1486 - geom.y,
1487 - geom.width,
1488 - geom.height,
1489 - geom.border_width as u16,
1490 - ),
1491 - );
1492 - }
1493 - }
1494 -
1495 - self.last_layout = Some(self.layout.name());
1496 - if let Ok(layout) = layout_from_str("monocle") {
1497 - self.layout = layout;
1498 - }
1499 - self.toggle_bar()?;
1500 - self.apply_layout()?;
1501 -
1502 - for window in &windows {
1503 - self.connection.configure_window(
1504 - *window,
1505 - &x11rb::protocol::xproto::ConfigureWindowAux::new().border_width(0),
1506 - )?;
1507 - }
1508 -
1509 - let border_width = self.config.border_width;
1510 - let floating_windows: Vec<Window> = windows
1511 - .iter()
1512 - .filter(|&&w| self.floating_windows.contains(&w))
1513 - .copied()
1514 - .collect();
1515 -
1516 - for window in floating_windows {
1517 - let monitor_idx = self
1518 - .clients
1519 - .get(&window)
1520 - .map(|c| c.monitor_index)
1521 - .unwrap_or(self.selected_monitor);
1522 - let monitor = &self.monitors[monitor_idx];
1523 -
1524 - let (outer_gap_h, outer_gap_v) = if self.gaps_enabled {
1525 - (
1526 - self.config.gap_outer_horizontal,
1527 - self.config.gap_outer_vertical,
1528 - )
1529 - } else {
1530 - (0, 0)
1531 - };
1532 -
1533 - let window_x = monitor.screen_x + outer_gap_h as i32;
1534 - let window_y = monitor.screen_y + outer_gap_v as i32;
1535 - let window_width = monitor
1536 - .screen_width
1537 - .saturating_sub(2 * outer_gap_h as i32)
1538 - .saturating_sub(2 * border_width as i32);
1539 - let window_height = monitor
1540 - .screen_height
1541 - .saturating_sub(2 * outer_gap_v as i32)
1542 - .saturating_sub(2 * border_width as i32);
1543 -
1544 - self.connection.configure_window(
1545 - window,
1546 - &x11rb::protocol::xproto::ConfigureWindowAux::new()
1547 - .x(window_x)
1548 - .y(window_y)
1549 - .width(window_width as u32)
1550 - .height(window_height as u32),
1551 - )?;
1552 - }
1553 - self.connection.flush()?;
1554 - } else {
1555 - let Some(focused_window) = self
1556 - .monitors
1557 - .get(self.selected_monitor)
1558 - .and_then(|m| m.selected_client)
1559 - else {
1560 - return Ok(());
1561 - };
1562 -
1563 - self.fullscreen_windows.remove(&focused_window);
1564 -
1565 - if let Some(last) = self.last_layout {
1566 - if let Ok(layout) = layout_from_str(last) {
1567 - self.layout = layout;
1568 - }
1569 - }
1570 -
1571 - let windows_to_restore: Vec<Window> = self
1572 - .floating_geometry_before_fullscreen
1573 - .keys()
1574 - .copied()
1575 - .collect();
1576 -
1577 - for window in windows_to_restore {
1578 - if let Some(&(x, y, width, height, border_width)) =
1579 - self.floating_geometry_before_fullscreen.get(&window)
1580 - {
1581 - self.connection.configure_window(
1582 - window,
1583 - &ConfigureWindowAux::new()
1584 - .x(x as i32)
1585 - .y(y as i32)
1586 - .width(width as u32)
1587 - .height(height as u32)
1588 - .border_width(border_width as u32),
1589 - )?;
1590 -
1591 - if let Some(c) = self.clients.get_mut(&window) {
1592 - c.x_position = x;
1593 - c.y_position = y;
1594 - c.width = width;
1595 - c.height = height;
1596 - c.border_width = border_width;
1597 - }
1598 -
1599 - self.floating_geometry_before_fullscreen.remove(&window);
1600 - }
1601 - }
1602 - self.connection.flush()?;
1603 -
1604 - self.toggle_bar()?;
1449 + let Some(focused_window) = self
1450 + .monitors
1451 + .get(self.selected_monitor)
1452 + .and_then(|m| m.selected_client)
1453 + else {
1454 + return Ok(());
1455 + };
1605 1456
1606 - if self.layout.name() != "normie" {
1607 - self.apply_layout()?;
1608 - } else {
1609 - if let Some(bar) = self.bars.get(self.selected_monitor) {
1610 - self.connection.configure_window(
1611 - bar.window(),
1612 - &x11rb::protocol::xproto::ConfigureWindowAux::new()
1613 - .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE),
1614 - )?;
1615 - self.connection.flush()?;
1616 - }
1617 - }
1618 - }
1457 + let is_fullscreen = self.fullscreen_windows.contains(&focused_window);
1458 + self.set_window_fullscreen(focused_window, !is_fullscreen)?;
1619 1459 Ok(())
1620 1460 }
1621 1461
@@ -1643,11 +1483,15 @@ impl WindowManager {
1643 1483 client.is_fullscreen = true;
1644 1484 client.old_state = client.is_floating;
1645 1485 client.old_border_width = client.border_width;
1486 + client.old_x_position = client.x_position;
1487 + client.old_y_position = client.y_position;
1488 + client.old_width = client.width;
1489 + client.old_height = client.height;
1646 1490 client.border_width = 0;
1647 - client.is_floating = true;
1648 1491 }
1649 1492
1650 1493 self.fullscreen_windows.insert(window);
1494 + self.floating_windows.insert(window);
1651 1495
1652 1496 self.connection.configure_window(
1653 1497 window,
@@ -1674,26 +1518,20 @@ impl WindowManager {
1674 1518
1675 1519 self.fullscreen_windows.remove(&window);
1676 1520
1521 + let was_floating = self
1522 + .clients
1523 + .get(&window)
1524 + .map(|c| c.old_state)
1525 + .unwrap_or(false);
1526 +
1527 + if !was_floating {
1528 + self.floating_windows.remove(&window);
1529 + }
1530 +
1677 1531 if let Some(client) = self.clients.get_mut(&window) {
1678 1532 client.is_fullscreen = false;
1679 1533 client.is_floating = client.old_state;
1680 1534 client.border_width = client.old_border_width;
1681 -
1682 - let x = client.old_x_position;
1683 - let y = client.old_y_position;
1684 - let w = client.old_width;
1685 - let h = client.old_height;
1686 - let bw = client.border_width;
1687 -
1688 - self.connection.configure_window(
1689 - window,
1690 - &x11rb::protocol::xproto::ConfigureWindowAux::new()
1691 - .x(x as i32)
1692 - .y(y as i32)
1693 - .width(w as u32)
1694 - .height(h as u32)
1695 - .border_width(bw as u32),
1696 - )?;
1697 1535 }
1698 1536
1699 1537 self.apply_layout()?;
@@ -1702,20 +1540,6 @@ impl WindowManager {
1702 1540 Ok(())
1703 1541 }
1704 1542
1705 - fn toggle_bar(&mut self) -> WmResult<()> {
1706 - self.show_bar = !self.show_bar;
1707 - if let Some(bar) = self.bars.get(self.selected_monitor) {
1708 - if self.show_bar {
1709 - self.connection.map_window(bar.window())?;
1710 - } else {
1711 - self.connection.unmap_window(bar.window())?;
1712 - }
1713 - self.connection.flush()?;
1714 - }
1715 - self.apply_layout()?;
1716 - Ok(())
1717 - }
1718 -
1719 1543 fn get_transient_parent(&self, window: Window) -> Option<Window> {
1720 1544 self.connection
1721 1545 .get_property(
@@ -1751,15 +1575,14 @@ impl WindowManager {
1751 1575 .ok()
1752 1576 .and_then(|cookie| cookie.reply().ok());
1753 1577
1754 - if let Some(reply) = reply {
1755 - if !reply.value.is_empty() {
1756 - if let Ok(text) = std::str::from_utf8(&reply.value) {
1757 - let parts: Vec<&str> = text.split('\0').collect();
1758 - let instance = parts.get(0).unwrap_or(&"").to_string();
1759 - let class = parts.get(1).unwrap_or(&"").to_string();
1760 - return (instance, class);
1761 - }
1762 - }
1578 + if let Some(reply) = reply
1579 + && !reply.value.is_empty()
1580 + && let Ok(text) = std::str::from_utf8(&reply.value)
1581 + {
1582 + let parts: Vec<&str> = text.split('\0').collect();
1583 + let instance = parts.first().unwrap_or(&"").to_string();
1584 + let class = parts.get(1).unwrap_or(&"").to_string();
1585 + return (instance, class);
1763 1586 }
1764 1587
1765 1588 (String::new(), String::new())
@@ -1801,10 +1624,10 @@ impl WindowManager {
1801 1624 }
1802 1625 }
1803 1626
1804 - if let Some(monitor_index) = rule_monitor {
1805 - if monitor_index < self.monitors.len() {
1806 - client.monitor_index = monitor_index;
1807 - }
1627 + if let Some(monitor_index) = rule_monitor
1628 + && monitor_index < self.monitors.len()
1629 + {
1630 + client.monitor_index = monitor_index;
1808 1631 }
1809 1632
1810 1633 let tags = rule_tags.unwrap_or_else(|| {
@@ -1937,11 +1760,11 @@ impl WindowManager {
1937 1760 .get(&window)
1938 1761 .map(|c| c.is_fixed)
1939 1762 .unwrap_or(false);
1940 - if let Some(c) = self.clients.get_mut(&window) {
1941 - if !c.is_floating {
1942 - c.is_floating = is_transient || is_fixed;
1943 - c.old_state = c.is_floating;
1944 - }
1763 + if let Some(c) = self.clients.get_mut(&window)
1764 + && !c.is_floating
1765 + {
1766 + c.is_floating = is_transient || is_fixed;
1767 + c.old_state = c.is_floating;
1945 1768 }
1946 1769
1947 1770 if self
@@ -1976,14 +1799,13 @@ impl WindowManager {
1976 1799 let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(tags);
1977 1800 let _ = self.save_client_tag(window, final_tags);
1978 1801
1979 - if client_monitor == self.selected_monitor {
1980 - if let Some(old_sel) = self
1802 + if client_monitor == self.selected_monitor
1803 + && let Some(old_sel) = self
1981 1804 .monitors
1982 1805 .get(self.selected_monitor)
1983 1806 .and_then(|m| m.selected_client)
1984 - {
1985 - self.unfocus(old_sel)?;
1986 - }
1807 + {
1808 + self.unfocus(old_sel)?;
1987 1809 }
1988 1810
1989 1811 if let Some(m) = self.monitors.get_mut(client_monitor) {
@@ -2036,7 +1858,7 @@ impl WindowManager {
2036 1858 self.connection.grab_button(
2037 1859 false,
2038 1860 window,
2039 - EventMask::BUTTON_PRESS.into(),
1861 + EventMask::BUTTON_PRESS,
2040 1862 GrabMode::SYNC,
2041 1863 GrabMode::SYNC,
2042 1864 x11rb::NONE,
@@ -2052,10 +1874,10 @@ impl WindowManager {
2052 1874 let monitor = self.monitors.get_mut(self.selected_monitor).unwrap();
2053 1875 let old_selected = monitor.selected_client;
2054 1876
2055 - if let Some(old_win) = old_selected {
2056 - if old_selected != window {
2057 - self.unfocus(old_win)?;
2058 - }
1877 + if let Some(old_win) = old_selected
1878 + && old_selected != window
1879 + {
1880 + self.unfocus(old_win)?;
2059 1881 }
2060 1882
2061 1883 let mut win = window;
@@ -2079,6 +1901,10 @@ impl WindowManager {
2079 1901 return Ok(());
2080 1902 }
2081 1903
1904 + if self.clients.get(&win).is_some_and(|c| c.is_urgent) {
1905 + self.set_urgent(win, false)?;
1906 + }
1907 +
2082 1908 let monitor_idx = self
2083 1909 .clients
2084 1910 .get(&win)
@@ -2132,18 +1958,19 @@ impl WindowManager {
2132 1958
2133 1959 let mut windows_to_restack: Vec<Window> = Vec::new();
2134 1960
2135 - if let Some(selected) = monitor.selected_client {
2136 - if self.floating_windows.contains(&selected) {
2137 - windows_to_restack.push(selected);
2138 - }
1961 + if let Some(selected) = monitor.selected_client
1962 + && self.floating_windows.contains(&selected)
1963 + {
1964 + windows_to_restack.push(selected);
2139 1965 }
2140 1966
2141 1967 let mut current = monitor.stack_head;
2142 1968 while let Some(win) = current {
2143 - if self.windows.contains(&win) && self.floating_windows.contains(&win) {
2144 - if Some(win) != monitor.selected_client {
2145 - windows_to_restack.push(win);
2146 - }
1969 + if self.windows.contains(&win)
1970 + && self.floating_windows.contains(&win)
1971 + && Some(win) != monitor.selected_client
1972 + {
1973 + windows_to_restack.push(win);
2147 1974 }
2148 1975 current = self.clients.get(&win).and_then(|c| c.stack_next);
2149 1976 }
@@ -2214,12 +2041,10 @@ impl WindowManager {
2214 2041 } else {
2215 2042 stack_windows[0]
2216 2043 }
2044 + } else if idx > 0 {
2045 + stack_windows[idx - 1]
2217 2046 } else {
2218 - if idx > 0 {
2219 - stack_windows[idx - 1]
2220 - } else {
2221 - stack_windows[stack_windows.len() - 1]
2222 - }
2047 + stack_windows[stack_windows.len() - 1]
2223 2048 }
2224 2049 } else {
2225 2050 return Ok(());
@@ -2337,20 +2162,18 @@ impl WindowManager {
2337 2162 client.next = temp;
2338 2163 }
2339 2164
2340 - if let Some(prev) = prev_selected {
2341 - if prev != target {
2342 - if let Some(client) = self.clients.get_mut(&prev) {
2343 - client.next = Some(target);
2344 - }
2345 - }
2165 + if let Some(prev) = prev_selected
2166 + && prev != target
2167 + && let Some(client) = self.clients.get_mut(&prev)
2168 + {
2169 + client.next = Some(target);
2346 2170 }
2347 2171
2348 - if let Some(prev) = prev_target {
2349 - if prev != selected {
2350 - if let Some(client) = self.clients.get_mut(&prev) {
2351 - client.next = Some(selected);
2352 - }
2353 - }
2172 + if let Some(prev) = prev_target
2173 + && prev != selected
2174 + && let Some(client) = self.clients.get_mut(&prev)
2175 + {
2176 + client.next = Some(selected);
2354 2177 }
2355 2178
2356 2179 if let Some(monitor) = self.monitors.get_mut(monitor_index) {
@@ -2420,18 +2243,18 @@ impl WindowManager {
2420 2243 old_focused: Option<Window>,
2421 2244 new_focused: Window,
2422 2245 ) -> WmResult<()> {
2423 - if let Some(old_win) = old_focused {
2424 - if old_win != new_focused {
2425 - self.connection.configure_window(
2426 - old_win,
2427 - &ConfigureWindowAux::new().border_width(self.config.border_width),
2428 - )?;
2246 + if let Some(old_win) = old_focused
2247 + && old_win != new_focused
2248 + {
2249 + self.connection.configure_window(
2250 + old_win,
2251 + &ConfigureWindowAux::new().border_width(self.config.border_width),
2252 + )?;
2429 2253
2430 - self.connection.change_window_attributes(
2431 - old_win,
2432 - &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused),
2433 - )?;
2434 - }
2254 + self.connection.change_window_attributes(
2255 + old_win,
2256 + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused),
2257 + )?;
2435 2258 }
2436 2259
2437 2260 self.connection.configure_window(
@@ -2490,8 +2313,7 @@ impl WindowManager {
2490 2313 .grab_pointer(
2491 2314 false,
2492 2315 self.root,
2493 - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS)
2494 - .into(),
2316 + EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS,
2495 2317 GrabMode::ASYNC,
2496 2318 GrabMode::ASYNC,
2497 2319 x11rb::NONE,
@@ -2748,8 +2570,7 @@ impl WindowManager {
2748 2570 .grab_pointer(
2749 2571 false,
2750 2572 self.root,
2751 - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS)
2752 - .into(),
2573 + EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS,
2753 2574 GrabMode::ASYNC,
2754 2575 GrabMode::ASYNC,
2755 2576 x11rb::NONE,
@@ -2784,29 +2605,27 @@ impl WindowManager {
2784 2605 .map(|c| c.is_floating)
2785 2606 .unwrap_or(false);
2786 2607
2787 - if should_resize {
2788 - if let Some(client) = self.clients.get(&window).cloned() {
2789 - let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
2790 - window,
2791 - client.x_position as i32,
2792 - client.y_position as i32,
2793 - new_width as i32,
2794 - new_height as i32,
2795 - );
2796 -
2797 - if let Some(client_mut) = self.clients.get_mut(&window) {
2798 - client_mut.width = hint_width as u16;
2799 - client_mut.height = hint_height as u16;
2800 - }
2801 -
2802 - self.connection.configure_window(
2803 - window,
2804 - &ConfigureWindowAux::new()
2805 - .width(hint_width as u32)
2806 - .height(hint_height as u32),
2807 - )?;
2808 - self.connection.flush()?;
2608 + if should_resize && let Some(client) = self.clients.get(&window).cloned() {
2609 + let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
2610 + window,
2611 + client.x_position as i32,
2612 + client.y_position as i32,
2613 + new_width as i32,
2614 + new_height as i32,
2615 + );
2616 +
2617 + if let Some(client_mut) = self.clients.get_mut(&window) {
2618 + client_mut.width = hint_width as u16;
2619 + client_mut.height = hint_height as u16;
2809 2620 }
2621 +
2622 + self.connection.configure_window(
2623 + window,
2624 + &ConfigureWindowAux::new()
2625 + .width(hint_width as u32)
2626 + .height(hint_height as u32),
2627 + )?;
2628 + self.connection.flush()?;
2810 2629 }
2811 2630 }
2812 2631 Event::ButtonRelease(_) => break,
@@ -2861,26 +2680,26 @@ impl WindowManager {
2861 2680 fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> {
2862 2681 match event {
2863 2682 Event::KeyPress(ref key_event) if key_event.event == self.overlay.window() => {
2864 - if self.overlay.is_visible() {
2865 - if let Err(error) = self.overlay.hide(&self.connection) {
2866 - eprintln!("Failed to hide overlay: {:?}", error);
2867 - }
2683 + if self.overlay.is_visible()
2684 + && let Err(error) = self.overlay.hide(&self.connection)
2685 + {
2686 + eprintln!("Failed to hide overlay: {:?}", error);
2868 2687 }
2869 2688 return Ok(None);
2870 2689 }
2871 2690 Event::ButtonPress(ref button_event) if button_event.event == self.overlay.window() => {
2872 - if self.overlay.is_visible() {
2873 - if let Err(error) = self.overlay.hide(&self.connection) {
2874 - eprintln!("Failed to hide overlay: {:?}", error);
2875 - }
2691 + if self.overlay.is_visible()
2692 + && let Err(error) = self.overlay.hide(&self.connection)
2693 + {
2694 + eprintln!("Failed to hide overlay: {:?}", error);
2876 2695 }
2877 2696 return Ok(None);
2878 2697 }
2879 2698 Event::Expose(ref expose_event) if expose_event.window == self.overlay.window() => {
2880 - if self.overlay.is_visible() {
2881 - if let Err(error) = self.overlay.draw(&self.connection, &self.font) {
2882 - eprintln!("Failed to draw overlay: {:?}", error);
2883 - }
2699 + if self.overlay.is_visible()
2700 + && let Err(error) = self.overlay.draw(&self.connection, &self.font)
2701 + {
2702 + eprintln!("Failed to draw overlay: {:?}", error);
2884 2703 }
2885 2704 return Ok(None);
2886 2705 }
@@ -2893,10 +2712,10 @@ impl WindowManager {
2893 2712 let keysym = mapping.keycode_to_keysym(e.detail);
2894 2713 let is_escape = keysym == keysyms::XK_ESCAPE;
2895 2714 let is_q = keysym == keysyms::XK_Q || keysym == 0x0051;
2896 - if is_escape || is_q {
2897 - if let Err(error) = self.keybind_overlay.hide(&self.connection) {
2898 - eprintln!("Failed to hide keybind overlay: {:?}", error);
2899 - }
2715 + if (is_escape || is_q)
2716 + && let Err(error) = self.keybind_overlay.hide(&self.connection)
2717 + {
2718 + eprintln!("Failed to hide keybind overlay: {:?}", error);
2900 2719 }
2901 2720 }
2902 2721 }
@@ -2910,10 +2729,10 @@ impl WindowManager {
2910 2729 Event::Expose(ref expose_event)
2911 2730 if expose_event.window == self.keybind_overlay.window() =>
2912 2731 {
2913 - if self.keybind_overlay.is_visible() {
2914 - if let Err(error) = self.keybind_overlay.draw(&self.connection, &self.font) {
2915 - eprintln!("Failed to draw keybind overlay: {:?}", error);
2916 - }
2732 + if self.keybind_overlay.is_visible()
2733 + && let Err(error) = self.keybind_overlay.draw(&self.connection, &self.font)
2734 + {
2735 + eprintln!("Failed to draw keybind overlay: {:?}", error);
2917 2736 }
2918 2737 return Ok(None);
2919 2738 }
@@ -2956,16 +2775,15 @@ impl WindowManager {
2956 2775 .get(&event.window)
2957 2776 .map(|c| c.is_floating)
2958 2777 .unwrap_or(false);
2959 - if !is_floating {
2960 - if let Some(parent) = self.get_transient_parent(event.window) {
2961 - if self.clients.contains_key(&parent) {
2962 - if let Some(c) = self.clients.get_mut(&event.window) {
2963 - c.is_floating = true;
2964 - }
2965 - self.floating_windows.insert(event.window);
2966 - self.apply_layout()?;
2967 - }
2778 + if !is_floating
2779 + && let Some(parent) = self.get_transient_parent(event.window)
2780 + && self.clients.contains_key(&parent)
2781 + {
2782 + if let Some(c) = self.clients.get_mut(&event.window) {
2783 + c.is_floating = true;
2968 2784 }
2785 + self.floating_windows.insert(event.window);
2786 + self.apply_layout()?;
2969 2787 }
2970 2788 } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() {
2971 2789 if let Some(c) = self.clients.get_mut(&event.window) {
@@ -2992,11 +2810,11 @@ impl WindowManager {
2992 2810 return Ok(None);
2993 2811 }
2994 2812 if self.windows.contains(&event.event) {
2995 - if let Some(client) = self.clients.get(&event.event) {
2996 - if client.monitor_index != self.selected_monitor {
2997 - self.selected_monitor = client.monitor_index;
2998 - self.update_bar()?;
2999 - }
2813 + if let Some(client) = self.clients.get(&event.event)
2814 + && client.monitor_index != self.selected_monitor
2815 + {
2816 + self.selected_monitor = client.monitor_index;
2817 + self.update_bar()?;
3000 2818 }
3001 2819 self.focus(Some(event.event))?;
3002 2820 self.update_tab_bars()?;
@@ -3009,16 +2827,15 @@ impl WindowManager {
3009 2827
3010 2828 if let Some(monitor_index) =
3011 2829 self.get_monitor_at_point(event.root_x as i32, event.root_y as i32)
2830 + && monitor_index != self.selected_monitor
3012 2831 {
3013 - if monitor_index != self.selected_monitor {
3014 - self.selected_monitor = monitor_index;
3015 - self.update_bar()?;
2832 + self.selected_monitor = monitor_index;
2833 + self.update_bar()?;
3016 2834
3017 - let visible = self.visible_windows_on_monitor(monitor_index);
3018 - if let Some(&win) = visible.first() {
3019 - self.focus(Some(win))?;
3020 - self.update_tab_bars()?;
3021 - }
2835 + let visible = self.visible_windows_on_monitor(monitor_index);
2836 + if let Some(&win) = visible.first() {
2837 + self.focus(Some(win))?;
2838 + self.update_tab_bars()?;
3022 2839 }
3023 2840 }
3024 2841 }
@@ -3100,11 +2917,11 @@ impl WindowManager {
3100 2917 }
3101 2918 }
3102 2919 Event::ButtonPress(event) => {
3103 - if self.keybind_overlay.is_visible() && event.event != self.keybind_overlay.window()
2920 + if self.keybind_overlay.is_visible()
2921 + && event.event != self.keybind_overlay.window()
2922 + && let Err(error) = self.keybind_overlay.hide(&self.connection)
3104 2923 {
3105 - if let Err(error) = self.keybind_overlay.hide(&self.connection) {
3106 - eprintln!("Failed to hide keybind overlay: {:?}", error);
3107 - }
2924 + eprintln!("Failed to hide keybind overlay: {:?}", error);
3108 2925 }
3109 2926
3110 2927 let is_bar_click = self
@@ -3278,14 +3095,13 @@ impl WindowManager {
3278 3095 let width_with_border = w + 2 * bw;
3279 3096 let height_with_border = h + 2 * bw;
3280 3097
3281 - if (x + w) > monitor.screen_x + monitor.screen_width as i32 && is_floating {
3098 + if (x + w) > monitor.screen_x + monitor.screen_width && is_floating {
3282 3099 x = monitor.screen_x
3283 - + (monitor.screen_width as i32 / 2 - width_with_border / 2);
3100 + + (monitor.screen_width / 2 - width_with_border / 2);
3284 3101 }
3285 - if (y + h) > monitor.screen_y + monitor.screen_height as i32 && is_floating
3286 - {
3102 + if (y + h) > monitor.screen_y + monitor.screen_height && is_floating {
3287 3103 y = monitor.screen_y
3288 - + (monitor.screen_height as i32 / 2 - height_with_border / 2);
3104 + + (monitor.screen_height / 2 - height_with_border / 2);
3289 3105 }
3290 3106
3291 3107 if let Some(c) = self.clients.get_mut(&event.window) {
@@ -3349,17 +3165,17 @@ impl WindowManager {
3349 3165 }
3350 3166
3351 3167 if event.type_ == self.atoms.net_wm_state {
3352 - if let Some(data) = event.data.as_data32().get(1) {
3353 - if *data == self.atoms.net_wm_state_fullscreen {
3354 - let action = event.data.as_data32()[0];
3355 - let fullscreen = match action {
3356 - 1 => true,
3357 - 0 => false,
3358 - 2 => !self.fullscreen_windows.contains(&event.window),
3359 - _ => return Ok(None),
3360 - };
3361 - self.set_window_fullscreen(event.window, fullscreen)?;
3362 - }
3168 + if let Some(data) = event.data.as_data32().get(1)
3169 + && *data == self.atoms.net_wm_state_fullscreen
3170 + {
3171 + let action = event.data.as_data32()[0];
3172 + let fullscreen = match action {
3173 + 1 => true,
3174 + 0 => false,
3175 + 2 => !self.fullscreen_windows.contains(&event.window),
3176 + _ => return Ok(None),
3177 + };
3178 + self.set_window_fullscreen(event.window, fullscreen)?;
3363 3179 }
3364 3180 } else if event.type_ == self.atoms.net_active_window {
3365 3181 let selected_window = self
@@ -3384,10 +3200,10 @@ impl WindowManager {
3384 3200 .get(self.selected_monitor)
3385 3201 .and_then(|m| m.selected_client);
3386 3202
3387 - if let Some(sel_win) = selected_window {
3388 - if event.event != sel_win {
3389 - self.set_focus(sel_win)?;
3390 - }
3203 + if let Some(sel_win) = selected_window
3204 + && event.event != sel_win
3205 + {
3206 + self.set_focus(sel_win)?;
3391 3207 }
3392 3208 }
3393 3209 Event::MappingNotify(event) => {
@@ -3484,18 +3300,18 @@ impl WindowManager {
3484 3300 let mut adjusted_width = geometry.width.saturating_sub(2 * border_width);
3485 3301 let mut adjusted_height = geometry.height.saturating_sub(2 * border_width);
3486 3302
3487 - if let Some(client) = self.clients.get(window).cloned() {
3488 - if !client.is_floating {
3489 - let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
3490 - *window,
3491 - geometry.x_coordinate as i32,
3492 - geometry.y_coordinate as i32,
3493 - adjusted_width as i32,
3494 - adjusted_height as i32,
3495 - );
3496 - adjusted_width = hint_width as u32;
3497 - adjusted_height = hint_height as u32;
3498 - }
3303 + if let Some(client) = self.clients.get(window).cloned()
3304 + && !client.is_floating
3305 + {
3306 + let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
3307 + *window,
3308 + geometry.x_coordinate,
3309 + geometry.y_coordinate,
3310 + adjusted_width as i32,
3311 + adjusted_height as i32,
3312 + );
3313 + adjusted_width = hint_width as u32;
3314 + adjusted_height = hint_height as u32;
3499 3315 }
3500 3316
3501 3317 let adjusted_x = geometry.x_coordinate + monitor_x;
@@ -3534,6 +3350,44 @@ impl WindowManager {
3534 3350 self.showhide(stack_head)?;
3535 3351 }
3536 3352
3353 + for monitor_index in 0..self.monitors.len() {
3354 + let monitor = &self.monitors[monitor_index];
3355 + let tags = monitor.tagset[monitor.selected_tags_index];
3356 +
3357 + let has_visible_fullscreen = self.fullscreen_windows.iter().any(|&w| {
3358 + self.clients.get(&w).map_or(false, |c| {
3359 + c.monitor_index == monitor_index && (c.tags & tags) != 0
3360 + })
3361 + });
3362 +
3363 + if has_visible_fullscreen {
3364 + if let Some(bar) = self.bars.get(monitor_index) {
3365 + self.connection.unmap_window(bar.window())?;
3366 + }
3367 +
3368 + for &window in &self.fullscreen_windows {
3369 + if let Some(client) = self.clients.get(&window) {
3370 + if client.monitor_index == monitor_index && (client.tags & tags) != 0 {
3371 + self.connection.configure_window(
3372 + window,
3373 + &ConfigureWindowAux::new()
3374 + .border_width(0)
3375 + .x(monitor.screen_x)
3376 + .y(monitor.screen_y)
3377 + .width(monitor.screen_width as u32)
3378 + .height(monitor.screen_height as u32)
3379 + .stack_mode(StackMode::ABOVE),
3380 + )?;
3381 + }
3382 + }
3383 + }
3384 + } else if self.show_bar {
3385 + if let Some(bar) = self.bars.get(monitor_index) {
3386 + self.connection.map_window(bar.window())?;
3387 + }
3388 + }
3389 + }
3390 +
3537 3391 self.connection.flush()?;
3538 3392
3539 3393 let is_tabbed = self.layout.name() == LayoutType::Tabbed.as_str();
@@ -3601,10 +3455,8 @@ impl WindowManager {
3601 3455 if let Err(e) = self.tab_bars[monitor_index].show(&self.connection) {
3602 3456 eprintln!("Failed to show tab bar: {:?}", e);
3603 3457 }
3604 - } else {
3605 - if let Err(e) = self.tab_bars[monitor_index].hide(&self.connection) {
3606 - eprintln!("Failed to hide tab bar: {:?}", e);
3607 - }
3458 + } else if let Err(e) = self.tab_bars[monitor_index].hide(&self.connection) {
3459 + eprintln!("Failed to hide tab bar: {:?}", e);
3608 3460 }
3609 3461 }
3610 3462
@@ -3765,15 +3617,13 @@ impl WindowManager {
3765 3617 .ok()
3766 3618 .and_then(|cookie| cookie.reply().ok());
3767 3619
3768 - if let Some(name) = net_name {
3769 - if !name.value.is_empty() {
3770 - if let Ok(title) = String::from_utf8(name.value.clone()) {
3771 - if let Some(client) = self.clients.get_mut(&window) {
3772 - client.name = title;
3773 - return Ok(());
3774 - }
3775 - }
3776 - }
3620 + if let Some(name) = net_name
3621 + && !name.value.is_empty()
3622 + && let Ok(title) = String::from_utf8(name.value.clone())
3623 + && let Some(client) = self.clients.get_mut(&window)
3624 + {
3625 + client.name = title;
3626 + return Ok(());
3777 3627 }
3778 3628
3779 3629 let wm_name = self
@@ -3788,12 +3638,11 @@ impl WindowManager {
3788 3638 )?
3789 3639 .reply()?;
3790 3640
3791 - if !wm_name.value.is_empty() {
3792 - if let Ok(title) = String::from_utf8(wm_name.value.clone()) {
3793 - if let Some(client) = self.clients.get_mut(&window) {
3794 - client.name = title;
3795 - }
3796 - }
3641 + if !wm_name.value.is_empty()
3642 + && let Ok(title) = String::from_utf8(wm_name.value.clone())
3643 + && let Some(client) = self.clients.get_mut(&window)
3644 + {
3645 + client.name = title;
3797 3646 }
3798 3647
3799 3648 Ok(())
@@ -3805,56 +3654,52 @@ impl WindowManager {
3805 3654 .get_property(false, window, AtomEnum::WM_HINTS, AtomEnum::WM_HINTS, 0, 9)?
3806 3655 .reply();
3807 3656
3808 - if let Ok(hints) = hints_reply {
3809 - if hints.value.len() >= 4 {
3810 - let flags = u32::from_ne_bytes([
3811 - hints.value[0],
3812 - hints.value[1],
3813 - hints.value[2],
3814 - hints.value[3],
3815 - ]);
3816 -
3817 - let selected_window = self
3818 - .monitors
3819 - .get(self.selected_monitor)
3820 - .and_then(|m| m.selected_client);
3657 + if let Ok(hints) = hints_reply
3658 + && hints.value.len() >= 4
3659 + {
3660 + let flags = u32::from_ne_bytes([
3661 + hints.value[0],
3662 + hints.value[1],
3663 + hints.value[2],
3664 + hints.value[3],
3665 + ]);
3666 +
3667 + let selected_window = self
3668 + .monitors
3669 + .get(self.selected_monitor)
3670 + .and_then(|m| m.selected_client);
3821 3671
3822 - if Some(window) == selected_window && (flags & 256) != 0 {
3823 - let new_flags = flags & !256;
3824 - let mut new_hints = hints.value.clone();
3825 - new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes());
3672 + if Some(window) == selected_window && (flags & 256) != 0 {
3673 + let new_flags = flags & !256;
3674 + let mut new_hints = hints.value.clone();
3675 + new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes());
3826 3676
3827 - self.connection.change_property(
3828 - x11rb::protocol::xproto::PropMode::REPLACE,
3829 - window,
3830 - AtomEnum::WM_HINTS,
3831 - AtomEnum::WM_HINTS,
3832 - 32,
3833 - 9,
3834 - &new_hints,
3835 - )?;
3836 - } else {
3837 - if let Some(client) = self.clients.get_mut(&window) {
3838 - client.is_urgent = (flags & 256) != 0;
3839 - }
3840 - }
3677 + self.connection.change_property(
3678 + x11rb::protocol::xproto::PropMode::REPLACE,
3679 + window,
3680 + AtomEnum::WM_HINTS,
3681 + AtomEnum::WM_HINTS,
3682 + 32,
3683 + 9,
3684 + &new_hints,
3685 + )?;
3686 + } else if let Some(client) = self.clients.get_mut(&window) {
3687 + client.is_urgent = (flags & 256) != 0;
3688 + }
3841 3689
3842 - if hints.value.len() >= 8 && (flags & 1) != 0 {
3843 - let input = i32::from_ne_bytes([
3844 - hints.value[4],
3845 - hints.value[5],
3846 - hints.value[6],
3847 - hints.value[7],
3848 - ]);
3690 + if hints.value.len() >= 8 && (flags & 1) != 0 {
3691 + let input = i32::from_ne_bytes([
3692 + hints.value[4],
3693 + hints.value[5],
3694 + hints.value[6],
3695 + hints.value[7],
3696 + ]);
3849 3697
3850 - if let Some(client) = self.clients.get_mut(&window) {
3851 - client.never_focus = input == 0;
3852 - }
3853 - } else {
3854 - if let Some(client) = self.clients.get_mut(&window) {
3855 - client.never_focus = false;
3856 - }
3698 + if let Some(client) = self.clients.get_mut(&window) {
3699 + client.never_focus = input == 0;
3857 3700 }
3701 + } else if let Some(client) = self.clients.get_mut(&window) {
3702 + client.never_focus = false;
3858 3703 }
3859 3704 }
3860 3705
@@ -3863,21 +3708,19 @@ impl WindowManager {
3863 3708
3864 3709 fn update_window_type(&mut self, window: Window) -> WmResult<()> {
3865 3710 if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state)
3711 + && state_atom == self.atoms.net_wm_state_fullscreen
3866 3712 {
3867 - if state_atom == self.atoms.net_wm_state_fullscreen {
3868 - self.set_window_fullscreen(window, true)?;
3869 - }
3713 + self.set_window_fullscreen(window, true)?;
3870 3714 }
3871 3715
3872 3716 if let Ok(Some(type_atom)) =
3873 3717 self.get_window_atom_property(window, self.atoms.net_wm_window_type)
3718 + && type_atom == self.atoms.net_wm_window_type_dialog
3874 3719 {
3875 - if type_atom == self.atoms.net_wm_window_type_dialog {
3876 - if let Some(client) = self.clients.get_mut(&window) {
3877 - client.is_floating = true;
3878 - }
3879 - self.floating_windows.insert(window);
3720 + if let Some(client) = self.clients.get_mut(&window) {
3721 + client.is_floating = true;
3880 3722 }
3723 + self.floating_windows.insert(window);
3881 3724 }
3882 3725
3883 3726 Ok(())
@@ -4060,11 +3903,11 @@ impl WindowManager {
4060 3903 }
4061 3904
4062 3905 fn attach(&mut self, window: Window, monitor_index: usize) {
4063 - if let Some(monitor) = self.monitors.get_mut(monitor_index) {
4064 - if let Some(client) = self.clients.get_mut(&window) {
4065 - client.next = monitor.clients_head;
4066 - monitor.clients_head = Some(window);
4067 - }
3906 + if let Some(monitor) = self.monitors.get_mut(monitor_index)
3907 + && let Some(client) = self.clients.get_mut(&window)
3908 + {
3909 + client.next = monitor.clients_head;
3910 + monitor.clients_head = Some(window);
4068 3911 }
4069 3912 }
4070 3913
@@ -4082,44 +3925,43 @@ impl WindowManager {
4082 3925 return;
4083 3926 }
4084 3927
4085 - if let Some(insert_after_window) = first_tagged {
4086 - if let Some(after_client) = self.clients.get(&insert_after_window) {
4087 - let old_next = after_client.next;
4088 - if let Some(new_client) = self.clients.get_mut(&window) {
4089 - new_client.next = old_next;
4090 - }
4091 - if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) {
4092 - after_client_mut.next = Some(window);
4093 - }
3928 + if let Some(insert_after_window) = first_tagged
3929 + && let Some(after_client) = self.clients.get(&insert_after_window)
3930 + {
3931 + let old_next = after_client.next;
3932 + if let Some(new_client) = self.clients.get_mut(&window) {
3933 + new_client.next = old_next;
3934 + }
3935 + if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) {
3936 + after_client_mut.next = Some(window);
4094 3937 }
4095 3938 }
4096 3939 }
4097 3940
4098 3941 fn detach(&mut self, window: Window) {
4099 3942 let monitor_index = self.clients.get(&window).map(|c| c.monitor_index);
4100 - if let Some(monitor_index) = monitor_index {
4101 - if let Some(monitor) = self.monitors.get_mut(monitor_index) {
4102 - if monitor.clients_head == Some(window) {
4103 - if let Some(client) = self.clients.get(&window) {
4104 - monitor.clients_head = client.next;
4105 - }
4106 - } else {
4107 - let mut current = monitor.clients_head;
4108 - while let Some(current_window) = current {
4109 - if let Some(current_client) = self.clients.get(&current_window) {
4110 - if current_client.next == Some(window) {
4111 - let new_next = self.clients.get(&window).and_then(|c| c.next);
4112 - if let Some(current_client_mut) =
4113 - self.clients.get_mut(&current_window)
4114 - {
4115 - current_client_mut.next = new_next;
4116 - }
4117 - break;
3943 + if let Some(monitor_index) = monitor_index
3944 + && let Some(monitor) = self.monitors.get_mut(monitor_index)
3945 + {
3946 + if monitor.clients_head == Some(window) {
3947 + if let Some(client) = self.clients.get(&window) {
3948 + monitor.clients_head = client.next;
3949 + }
3950 + } else {
3951 + let mut current = monitor.clients_head;
3952 + while let Some(current_window) = current {
3953 + if let Some(current_client) = self.clients.get(&current_window) {
3954 + if current_client.next == Some(window) {
3955 + let new_next = self.clients.get(&window).and_then(|c| c.next);
3956 + if let Some(current_client_mut) = self.clients.get_mut(&current_window)
3957 + {
3958 + current_client_mut.next = new_next;
4118 3959 }
4119 - current = current_client.next;
4120 - } else {
4121 3960 break;
4122 3961 }
3962 + current = current_client.next;
3963 + } else {
3964 + break;
4123 3965 }
4124 3966 }
4125 3967 }
@@ -4127,61 +3969,60 @@ impl WindowManager {
4127 3969 }
4128 3970
4129 3971 fn attach_stack(&mut self, window: Window, monitor_index: usize) {
4130 - if let Some(monitor) = self.monitors.get_mut(monitor_index) {
4131 - if let Some(client) = self.clients.get_mut(&window) {
4132 - client.stack_next = monitor.stack_head;
4133 - monitor.stack_head = Some(window);
4134 - }
3972 + if let Some(monitor) = self.monitors.get_mut(monitor_index)
3973 + && let Some(client) = self.clients.get_mut(&window)
3974 + {
3975 + client.stack_next = monitor.stack_head;
3976 + monitor.stack_head = Some(window);
4135 3977 }
4136 3978 }
4137 3979
4138 3980 fn detach_stack(&mut self, window: Window) {
4139 3981 let monitor_index = self.clients.get(&window).map(|c| c.monitor_index);
4140 - if let Some(monitor_index) = monitor_index {
4141 - if let Some(monitor) = self.monitors.get_mut(monitor_index) {
4142 - if monitor.stack_head == Some(window) {
4143 - if let Some(client) = self.clients.get(&window) {
4144 - monitor.stack_head = client.stack_next;
4145 - }
4146 - let should_update_selected = monitor.selected_client == Some(window);
4147 - let mut new_selected: Option<Window> = None;
4148 - if should_update_selected {
4149 - let mut stack_current = monitor.stack_head;
4150 - while let Some(stack_window) = stack_current {
4151 - if let Some(stack_client) = self.clients.get(&stack_window) {
4152 - if self.is_window_visible(stack_window) {
4153 - new_selected = Some(stack_window);
4154 - break;
4155 - }
4156 - stack_current = stack_client.stack_next;
4157 - } else {
3982 + if let Some(monitor_index) = monitor_index
3983 + && let Some(monitor) = self.monitors.get_mut(monitor_index)
3984 + {
3985 + if monitor.stack_head == Some(window) {
3986 + if let Some(client) = self.clients.get(&window) {
3987 + monitor.stack_head = client.stack_next;
3988 + }
3989 + let should_update_selected = monitor.selected_client == Some(window);
3990 + let mut new_selected: Option<Window> = None;
3991 + if should_update_selected {
3992 + let mut stack_current = monitor.stack_head;
3993 + while let Some(stack_window) = stack_current {
3994 + if let Some(stack_client) = self.clients.get(&stack_window) {
3995 + if self.is_window_visible(stack_window) {
3996 + new_selected = Some(stack_window);
4158 3997 break;
4159 3998 }
3999 + stack_current = stack_client.stack_next;
4000 + } else {
4001 + break;
4160 4002 }
4161 4003 }
4162 - if should_update_selected {
4163 - if let Some(monitor) = self.monitors.get_mut(monitor_index) {
4164 - monitor.selected_client = new_selected;
4165 - }
4166 - }
4167 - } else {
4168 - let mut current = monitor.stack_head;
4169 - while let Some(current_window) = current {
4170 - if let Some(current_client) = self.clients.get(&current_window) {
4171 - if current_client.stack_next == Some(window) {
4172 - let new_stack_next =
4173 - self.clients.get(&window).and_then(|c| c.stack_next);
4174 - if let Some(current_client_mut) =
4175 - self.clients.get_mut(&current_window)
4176 - {
4177 - current_client_mut.stack_next = new_stack_next;
4178 - }
4179 - break;
4004 + }
4005 + if should_update_selected
4006 + && let Some(monitor) = self.monitors.get_mut(monitor_index)
4007 + {
4008 + monitor.selected_client = new_selected;
4009 + }
4010 + } else {
4011 + let mut current = monitor.stack_head;
4012 + while let Some(current_window) = current {
4013 + if let Some(current_client) = self.clients.get(&current_window) {
4014 + if current_client.stack_next == Some(window) {
4015 + let new_stack_next =
4016 + self.clients.get(&window).and_then(|c| c.stack_next);
4017 + if let Some(current_client_mut) = self.clients.get_mut(&current_window)
4018 + {
4019 + current_client_mut.stack_next = new_stack_next;
4180 4020 }
4181 - current = current_client.stack_next;
4182 - } else {
4183 4021 break;
4184 4022 }
4023 + current = current_client.stack_next;
4024 + } else {
4025 + break;
4185 4026 }
4186 4027 }
4187 4028 }
+3 −0 templates/config.lua
@@ -145,6 +145,7 @@ oxwm.gaps.set_outer(5, 5)
145 145 -- Examples (uncomment to use):
146 146 oxwm.rule.add({ instance = "gimp", floating = true })
147 147 -- oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
148 +-- oxwm.rule.add({ class = "firefox", tag = 2 })
148 149 -- oxwm.rule.add({ instance = "mpv", floating = true })
149 150
150 151 -- To find window properties, use xprop and click on the window
@@ -168,6 +169,8 @@ oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444")
168 169 oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan)
169 170 -- Currently selected tag
170 171 oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
172 +-- Urgent tags (windows requesting attention)
173 +oxwm.bar.set_scheme_urgent(colors.red, colors.bg, colors.red)
171 174
172 175 -------------------------------------------------------------------------------
173 176 -- Keybindings
+6 −0 templates/oxwm.lua
@@ -309,6 +309,12 @@ function oxwm.bar.set_scheme_occupied(foreground, background, underline) end
309 309 ---@param underline string|integer Underline color
310 310 function oxwm.bar.set_scheme_selected(foreground, background, underline) end
311 311
312 +---Set urgent tag color scheme (tags with urgent windows)
313 +---@param foreground string|integer Foreground color
314 +---@param background string|integer Background color
315 +---@param underline string|integer Underline color
316 +function oxwm.bar.set_scheme_urgent(foreground, background, underline) end
317 +
312 318 ---Add an autostart command
313 319 ---@param cmd string Command to run at startup
314 320 function oxwm.autostart(cmd) end