tony / oxwm

added size hints constant file to remove magic numbers from size hints / min aspect / max aspect function Browse files
tonybtw committed 2025-12-10 parent d7dbcfd commit 9039bf29a8b657251d7bc24c054022d6dd76f321
Showing 3 changed files with 43 additions and 21 deletions. UnifiedSplit
+1 −0 src/lib.rs
@@ -6,6 +6,7 @@ pub mod keyboard;
6 pub mod layout; 6 pub mod layout;
7 pub mod monitor; 7 pub mod monitor;
8 pub mod overlay; 8 pub mod overlay;
9 +pub mod size_hints;
9 pub mod tab_bar; 10 pub mod tab_bar;
10 pub mod window_manager; 11 pub mod window_manager;
11 12
+25 −0 src/size_hints.rs new file mode 100644
@@ -0,0 +1,25 @@
1 +#![allow(dead_code)]
2 +
3 +pub mod flags {
4 + pub const P_MIN_SIZE: u32 = 1 << 4;
5 + pub const P_MAX_SIZE: u32 = 1 << 5;
6 + pub const P_RESIZE_INC: u32 = 1 << 6;
7 + pub const P_ASPECT: u32 = 1 << 7;
8 + pub const P_BASE_SIZE: u32 = 1 << 8;
9 +}
10 +
11 +pub mod offset {
12 + pub const FLAGS: usize = 0;
13 + pub const MIN_WIDTH: usize = 5;
14 + pub const MIN_HEIGHT: usize = 6;
15 + pub const MAX_WIDTH: usize = 7;
16 + pub const MAX_HEIGHT: usize = 8;
17 + pub const WIDTH_INC: usize = 9;
18 + pub const HEIGHT_INC: usize = 10;
19 + pub const MIN_ASPECT_X: usize = 11;
20 + pub const MIN_ASPECT_Y: usize = 12;
21 + pub const MAX_ASPECT_X: usize = 13;
22 + pub const MAX_ASPECT_Y: usize = 14;
23 + pub const BASE_WIDTH: usize = 15;
24 + pub const BASE_HEIGHT: usize = 16;
25 +}
+17 −21 src/window_manager.rs
@@ -3309,61 +3309,57 @@ impl WindowManager {
3309 return Ok(()); 3309 return Ok(());
3310 } 3310 }
3311 3311
3312 + use crate::size_hints::{flags::*, offset::*};
3313 +
3312 let read_u32 = |offset: usize| -> u32 { 3314 let read_u32 = |offset: usize| -> u32 {
3313 let bytes = &size_hints.value[offset * 4..(offset + 1) * 4]; 3315 let bytes = &size_hints.value[offset * 4..(offset + 1) * 4];
3314 u32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) 3316 u32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
3315 }; 3317 };
3316 3318
3317 - let flags = read_u32(0); 3319 + let flags = read_u32(FLAGS);
3318 -
3319 - const P_MIN_SIZE: u32 = 1 << 4;
3320 - const P_MAX_SIZE: u32 = 1 << 5;
3321 - const P_RESIZE_INC: u32 = 1 << 6;
3322 - const P_ASPECT: u32 = 1 << 7;
3323 - const P_BASE_SIZE: u32 = 1 << 8;
3324 3320
3325 if let Some(client) = self.clients.get_mut(&window) { 3321 if let Some(client) = self.clients.get_mut(&window) {
3326 if flags & P_BASE_SIZE != 0 { 3322 if flags & P_BASE_SIZE != 0 {
3327 - client.base_width = read_u32(15) as i32; 3323 + client.base_width = read_u32(BASE_WIDTH) as i32;
3328 - client.base_height = read_u32(16) as i32; 3324 + client.base_height = read_u32(BASE_HEIGHT) as i32;
3329 } else if flags & P_MIN_SIZE != 0 { 3325 } else if flags & P_MIN_SIZE != 0 {
3330 - client.base_width = read_u32(5) as i32; 3326 + client.base_width = read_u32(MIN_WIDTH) as i32;
3331 - client.base_height = read_u32(6) as i32; 3327 + client.base_height = read_u32(MIN_HEIGHT) as i32;
3332 } else { 3328 } else {
3333 client.base_width = 0; 3329 client.base_width = 0;
3334 client.base_height = 0; 3330 client.base_height = 0;
3335 } 3331 }
3336 3332
3337 if flags & P_RESIZE_INC != 0 { 3333 if flags & P_RESIZE_INC != 0 {
3338 - client.increment_width = read_u32(9) as i32; 3334 + client.increment_width = read_u32(WIDTH_INC) as i32;
3339 - client.increment_height = read_u32(10) as i32; 3335 + client.increment_height = read_u32(HEIGHT_INC) as i32;
3340 } else { 3336 } else {
3341 client.increment_width = 0; 3337 client.increment_width = 0;
3342 client.increment_height = 0; 3338 client.increment_height = 0;
3343 } 3339 }
3344 3340
3345 if flags & P_MAX_SIZE != 0 { 3341 if flags & P_MAX_SIZE != 0 {
3346 - client.max_width = read_u32(7) as i32; 3342 + client.max_width = read_u32(MAX_WIDTH) as i32;
3347 - client.max_height = read_u32(8) as i32; 3343 + client.max_height = read_u32(MAX_HEIGHT) as i32;
3348 } else { 3344 } else {
3349 client.max_width = 0; 3345 client.max_width = 0;
3350 client.max_height = 0; 3346 client.max_height = 0;
3351 } 3347 }
3352 3348
3353 if flags & P_MIN_SIZE != 0 { 3349 if flags & P_MIN_SIZE != 0 {
3354 - client.min_width = read_u32(5) as i32; 3350 + client.min_width = read_u32(MIN_WIDTH) as i32;
3355 - client.min_height = read_u32(6) as i32; 3351 + client.min_height = read_u32(MIN_HEIGHT) as i32;
3356 } else if flags & P_BASE_SIZE != 0 { 3352 } else if flags & P_BASE_SIZE != 0 {
3357 - client.min_width = read_u32(15) as i32; 3353 + client.min_width = read_u32(BASE_WIDTH) as i32;
3358 - client.min_height = read_u32(16) as i32; 3354 + client.min_height = read_u32(BASE_HEIGHT) as i32;
3359 } else { 3355 } else {
3360 client.min_width = 0; 3356 client.min_width = 0;
3361 client.min_height = 0; 3357 client.min_height = 0;
3362 } 3358 }
3363 3359
3364 if flags & P_ASPECT != 0 { 3360 if flags & P_ASPECT != 0 {
3365 - client.min_aspect = (read_u32(12) as f32) / (read_u32(11) as f32).max(1.0); 3361 + client.min_aspect = (read_u32(MIN_ASPECT_Y) as f32) / (read_u32(MIN_ASPECT_X) as f32).max(1.0);
3366 - client.max_aspect = (read_u32(13) as f32) / (read_u32(14) as f32).max(1.0); 3362 + client.max_aspect = (read_u32(MAX_ASPECT_X) as f32) / (read_u32(MAX_ASPECT_Y) as f32).max(1.0);
3367 } else { 3363 } else {
3368 client.min_aspect = 0.0; 3364 client.min_aspect = 0.0;
3369 client.max_aspect = 0.0; 3365 client.max_aspect = 0.0;