gardesk/gar / 34fe404

Browse files

Fix i3 IPC workspace list to only include active workspaces

Only report workspaces that are visible or have windows to polybar,
matching i3 behavior. Empty invisible workspaces are now filtered out.
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
34fe4046a5e60eb565cfadcead83ff0d239f8f7a
Parents
59cb2b5
Tree
50ba5a0

1 changed file

StatusFile+-
M gar/src/x11/events.rs 20 11
gar/src/x11/events.rsmodified
@@ -1932,13 +1932,21 @@ impl WindowManager {
19321932
     }
19331933
 
19341934
     /// Build i3-compatible workspace list
1935
+    /// Only includes workspaces that are visible or have windows (like i3)
19351936
     fn build_i3_workspaces(&self) -> Vec<crate::ipc::I3WorkspaceInfo> {
19361937
         use crate::ipc::{I3WorkspaceInfo, I3Rect};
19371938
 
1938
-        self.workspaces.iter().enumerate().map(|(i, ws)| {
1939
+        self.workspaces.iter().enumerate().filter_map(|(i, ws)| {
19391940
             // Find which monitor this workspace is on (if visible)
19401941
             let monitor = self.monitors.iter().find(|m| m.active_workspace == i);
19411942
             let visible = monitor.is_some();
1943
+            let has_windows = ws.has_windows();
1944
+
1945
+            // Only include workspaces that are visible OR have windows
1946
+            if !visible && !has_windows {
1947
+                return None;
1948
+            }
1949
+
19421950
             let focused = self.focused_monitor < self.monitors.len()
19431951
                 && self.monitors[self.focused_monitor].active_workspace == i;
19441952
 
@@ -1947,7 +1955,8 @@ impl WindowManager {
19471955
                 .filter(|w| w.workspace == i)
19481956
                 .any(|w| w.urgent);
19491957
 
1950
-            // Get geometry from monitor if visible, else use first monitor's geometry
1958
+            // Get geometry and output from monitor
1959
+            // For non-visible workspaces with windows, assign to focused monitor
19511960
             let (rect, output) = if let Some(mon) = monitor {
19521961
                 (
19531962
                     I3Rect {
@@ -1959,20 +1968,20 @@ impl WindowManager {
19591968
                     mon.name.clone(),
19601969
                 )
19611970
             } else {
1962
-                // Not visible - use first monitor as fallback
1963
-                let fallback = &self.monitors[0];
1971
+                // Not visible but has windows - assign to focused monitor
1972
+                let mon = &self.monitors[self.focused_monitor];
19641973
                 (
19651974
                     I3Rect {
1966
-                        x: fallback.geometry.x as i32,
1967
-                        y: fallback.geometry.y as i32,
1968
-                        width: fallback.geometry.width as i32,
1969
-                        height: fallback.geometry.height as i32,
1975
+                        x: mon.geometry.x as i32,
1976
+                        y: mon.geometry.y as i32,
1977
+                        width: mon.geometry.width as i32,
1978
+                        height: mon.geometry.height as i32,
19701979
                     },
1971
-                    fallback.name.clone(),
1980
+                    mon.name.clone(),
19721981
                 )
19731982
             };
19741983
 
1975
-            I3WorkspaceInfo {
1984
+            Some(I3WorkspaceInfo {
19761985
                 id: (i + 1) as i64 * 1000000, // Generate unique ID
19771986
                 num: (i + 1) as i32,
19781987
                 name: ws.name.clone(),
@@ -1981,7 +1990,7 @@ impl WindowManager {
19811990
                 urgent,
19821991
                 rect,
19831992
                 output,
1984
-            }
1993
+            })
19851994
         }).collect()
19861995
     }
19871996