tony / oxwm

Added pertag mfacts, layouts, etc Browse files
tonybtw committed 2026-01-11 parent e120f6b commit bea7eeb63b2558d0a94a22bacf5652dd353e015f
Showing 3 changed files with 150 additions and 24 deletions. UnifiedSplit
+2 −2 justfile
@@ -3,13 +3,13 @@ build:
3 3
4 4 install: build
5 5 cp target/release/oxwm /usr/bin/oxwm
6 - cp resources/oxwm.desktop /usr/share/xsessions/oxwm.desktop
6 + cp resources/oxwm.desktop /usr/share/xsessions/oxwm.desktop
7 7 chmod +x /usr/bin/oxwm
8 8 @echo "✓ oxwm installed to /usr/bin/oxwm"
9 9 @echo " Run 'oxwm --init' to create your config"
10 10
11 11 checkinstall:
12 - checkinstall --pkgname oxwm --exclude /root -y just install
12 + checkinstall --pkgname oxwm --exclude /root -y just install
13 13
14 14 uninstall:
15 15 rm -f /usr/bin/oxwm
+36 −0 src/monitor.rs
@@ -6,6 +6,30 @@ use x11rb::rust_connection::RustConnection;
6 6
7 7 type WmResult<T> = Result<T, WmError>;
8 8
9 +#[derive(Debug, Clone)]
10 +pub struct Pertag {
11 + pub current_tag: usize,
12 + pub previous_tag: usize,
13 + pub num_masters: Vec<i32>,
14 + pub master_factors: Vec<f32>,
15 + pub layouts: Vec<String>,
16 + pub show_bars: Vec<bool>,
17 +}
18 +
19 +impl Pertag {
20 + pub fn new(num_tags: usize, default_num_master: i32, default_master_factor: f32, default_show_bar: bool, default_layout: &str) -> Self {
21 + let len = num_tags + 1;
22 + Self {
23 + current_tag: 1,
24 + previous_tag: 1,
25 + num_masters: vec![default_num_master; len],
26 + master_factors: vec![default_master_factor; len],
27 + layouts: vec![default_layout.to_string(); len],
28 + show_bars: vec![default_show_bar; len],
29 + }
30 + }
31 +}
32 +
9 33 #[derive(Debug, Clone)]
10 34 pub struct Monitor {
11 35 pub layout_symbol: String,
@@ -35,6 +59,7 @@ pub struct Monitor {
35 59 pub stack_head: Option<Window>,
36 60 pub bar_window: Option<Window>,
37 61 pub layout_indices: [usize; 2],
62 + pub pertag: Option<Pertag>,
38 63 }
39 64
40 65 impl Monitor {
@@ -67,9 +92,20 @@ impl Monitor {
67 92 stack_head: None,
68 93 bar_window: None,
69 94 layout_indices: [0, 1],
95 + pertag: None,
70 96 }
71 97 }
72 98
99 + pub fn init_pertag(&mut self, num_tags: usize, default_layout: &str) {
100 + self.pertag = Some(Pertag::new(
101 + num_tags,
102 + self.num_master,
103 + self.master_factor,
104 + self.show_bar,
105 + default_layout,
106 + ));
107 + }
108 +
73 109 pub fn contains_point(&self, x: i32, y: i32) -> bool {
74 110 x >= self.screen_x
75 111 && x < self.screen_x + self.screen_width
+112 −22 src/window_manager.rs
@@ -243,7 +243,10 @@ impl WindowManager {
243 243 )?;
244 244 }
245 245
246 - let monitors = detect_monitors(&connection, &screen, root)?;
246 + let mut monitors = detect_monitors(&connection, &screen, root)?;
247 + for monitor in monitors.iter_mut() {
248 + monitor.init_pertag(config.tags.len(), "tiling");
249 + }
247 250
248 251 let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) };
249 252 if display.is_null() {
@@ -710,6 +713,9 @@ impl WindowManager {
710 713 if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
711 714 let new_mfact = (monitor.master_factor + delta).clamp(0.05, 0.95);
712 715 monitor.master_factor = new_mfact;
716 + if let Some(ref mut pertag) = monitor.pertag {
717 + pertag.master_factors[pertag.current_tag] = new_mfact;
718 + }
713 719 self.apply_layout()?;
714 720 }
715 721 Ok(())
@@ -719,11 +725,27 @@ impl WindowManager {
719 725 if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
720 726 let new_nmaster = (monitor.num_master + delta).max(0);
721 727 monitor.num_master = new_nmaster;
728 + if let Some(ref mut pertag) = monitor.pertag {
729 + pertag.num_masters[pertag.current_tag] = new_nmaster;
730 + }
722 731 self.apply_layout()?;
723 732 }
724 733 Ok(())
725 734 }
726 735
736 + fn toggle_bar(&mut self) -> WmResult<()> {
737 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
738 + monitor.show_bar = !monitor.show_bar;
739 + self.show_bar = monitor.show_bar;
740 + if let Some(ref mut pertag) = monitor.pertag {
741 + pertag.show_bars[pertag.current_tag] = monitor.show_bar;
742 + }
743 + }
744 + self.apply_layout()?;
745 + self.update_bar()?;
746 + Ok(())
747 + }
748 +
727 749 fn get_layout_symbol(&self) -> String {
728 750 let layout_name = self.layout.name();
729 751 self.config
@@ -871,6 +893,11 @@ impl WindowManager {
871 893 match layout_from_str(layout_name) {
872 894 Ok(layout) => {
873 895 self.layout = layout;
896 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
897 + if let Some(ref mut pertag) = monitor.pertag {
898 + pertag.layouts[pertag.current_tag] = layout_name.to_string();
899 + }
900 + }
874 901 if layout_name != "normie" && layout_name != "floating" {
875 902 self.floating_windows.clear();
876 903 }
@@ -888,6 +915,11 @@ impl WindowManager {
888 915 match layout_from_str(next_name) {
889 916 Ok(layout) => {
890 917 self.layout = layout;
918 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
919 + if let Some(ref mut pertag) = monitor.pertag {
920 + pertag.layouts[pertag.current_tag] = next_name.to_string();
921 + }
922 + }
891 923 if next_name != "normie" && next_name != "floating" {
892 924 self.floating_windows.clear();
893 925 }
@@ -1243,21 +1275,48 @@ impl WindowManager {
1243 1275 return Ok(());
1244 1276 }
1245 1277
1246 - let monitor = match self.monitors.get_mut(self.selected_monitor) {
1247 - Some(m) => m,
1248 - None => return Ok(()),
1249 - };
1250 -
1251 1278 let new_tagset = tag_mask(tag_index);
1279 + let mut layout_name: Option<String> = None;
1280 + let mut toggle_bar = false;
1252 1281
1253 - if new_tagset == monitor.tagset[monitor.selected_tags_index] {
1254 - if !self.config.tag_back_and_forth {
1255 - return Ok(());
1282 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
1283 + if new_tagset == monitor.tagset[monitor.selected_tags_index] {
1284 + if !self.config.tag_back_and_forth {
1285 + return Ok(());
1286 + }
1287 + monitor.tagset.swap(0, 1);
1288 + if let Some(ref mut pertag) = monitor.pertag {
1289 + let tmp = pertag.previous_tag;
1290 + pertag.previous_tag = pertag.current_tag;
1291 + pertag.current_tag = tmp;
1292 + }
1293 + } else {
1294 + monitor.selected_tags_index ^= 1;
1295 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1296 + if let Some(ref mut pertag) = monitor.pertag {
1297 + pertag.previous_tag = pertag.current_tag;
1298 + pertag.current_tag = tag_index + 1;
1299 + }
1256 1300 }
1257 - monitor.tagset.swap(0, 1);
1258 - } else {
1259 - monitor.selected_tags_index ^= 1;
1260 - monitor.tagset[monitor.selected_tags_index] = new_tagset;
1301 +
1302 + if let Some(ref pertag) = monitor.pertag {
1303 + monitor.num_master = pertag.num_masters[pertag.current_tag];
1304 + monitor.master_factor = pertag.master_factors[pertag.current_tag];
1305 + layout_name = Some(pertag.layouts[pertag.current_tag].clone());
1306 + if monitor.show_bar != pertag.show_bars[pertag.current_tag] {
1307 + toggle_bar = true;
1308 + }
1309 + }
1310 + }
1311 +
1312 + if let Some(name) = layout_name {
1313 + if let Ok(layout) = layout_from_str(&name) {
1314 + self.layout = layout;
1315 + }
1316 + }
1317 +
1318 + if toggle_bar {
1319 + self.toggle_bar()?;
1261 1320 }
1262 1321
1263 1322 self.save_selected_tags()?;
@@ -1273,19 +1332,50 @@ impl WindowManager {
1273 1332 return Ok(());
1274 1333 }
1275 1334
1276 - let monitor = match self.monitors.get_mut(self.selected_monitor) {
1277 - Some(m) => m,
1278 - None => return Ok(()),
1279 - };
1335 + let num_tags = self.config.tags.len();
1336 + let all_tags_mask = (1u32 << num_tags) - 1;
1337 + let mut layout_name: Option<String> = None;
1338 + let mut toggle_bar = false;
1280 1339
1281 - let mask = tag_mask(tag_index);
1282 - let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask;
1340 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
1341 + let mask = tag_mask(tag_index);
1342 + let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask;
1283 1343
1284 - if new_tagset == 0 {
1285 - return Ok(());
1344 + if new_tagset == 0 {
1345 + return Ok(());
1346 + }
1347 +
1348 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1349 +
1350 + if let Some(ref mut pertag) = monitor.pertag {
1351 + if new_tagset == all_tags_mask {
1352 + pertag.previous_tag = pertag.current_tag;
1353 + pertag.current_tag = 0;
1354 + }
1355 +
1356 + if pertag.current_tag > 0 && (new_tagset & (1 << (pertag.current_tag - 1))) == 0 {
1357 + pertag.previous_tag = pertag.current_tag;
1358 + pertag.current_tag = (new_tagset.trailing_zeros() as usize) + 1;
1359 + }
1360 +
1361 + monitor.num_master = pertag.num_masters[pertag.current_tag];
1362 + monitor.master_factor = pertag.master_factors[pertag.current_tag];
1363 + layout_name = Some(pertag.layouts[pertag.current_tag].clone());
1364 + if monitor.show_bar != pertag.show_bars[pertag.current_tag] {
1365 + toggle_bar = true;
1366 + }
1367 + }
1286 1368 }
1287 1369
1288 - monitor.tagset[monitor.selected_tags_index] = new_tagset;
1370 + if let Some(name) = layout_name {
1371 + if let Ok(layout) = layout_from_str(&name) {
1372 + self.layout = layout;
1373 + }
1374 + }
1375 +
1376 + if toggle_bar {
1377 + self.toggle_bar()?;
1378 + }
1289 1379
1290 1380 self.save_selected_tags()?;
1291 1381 self.focus(None)?;