@@ -1932,13 +1932,21 @@ impl WindowManager { |
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | 1934 | /// Build i3-compatible workspace list |
| 1935 | + /// Only includes workspaces that are visible or have windows (like i3) |
| 1935 | 1936 | fn build_i3_workspaces(&self) -> Vec<crate::ipc::I3WorkspaceInfo> { |
| 1936 | 1937 | use crate::ipc::{I3WorkspaceInfo, I3Rect}; |
| 1937 | 1938 | |
| 1938 | | - self.workspaces.iter().enumerate().map(|(i, ws)| { |
| 1939 | + self.workspaces.iter().enumerate().filter_map(|(i, ws)| { |
| 1939 | 1940 | // Find which monitor this workspace is on (if visible) |
| 1940 | 1941 | let monitor = self.monitors.iter().find(|m| m.active_workspace == i); |
| 1941 | 1942 | 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 | + |
| 1942 | 1950 | let focused = self.focused_monitor < self.monitors.len() |
| 1943 | 1951 | && self.monitors[self.focused_monitor].active_workspace == i; |
| 1944 | 1952 | |
@@ -1947,7 +1955,8 @@ impl WindowManager { |
| 1947 | 1955 | .filter(|w| w.workspace == i) |
| 1948 | 1956 | .any(|w| w.urgent); |
| 1949 | 1957 | |
| 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 |
| 1951 | 1960 | let (rect, output) = if let Some(mon) = monitor { |
| 1952 | 1961 | ( |
| 1953 | 1962 | I3Rect { |
@@ -1959,20 +1968,20 @@ impl WindowManager { |
| 1959 | 1968 | mon.name.clone(), |
| 1960 | 1969 | ) |
| 1961 | 1970 | } 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]; |
| 1964 | 1973 | ( |
| 1965 | 1974 | 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, |
| 1970 | 1979 | }, |
| 1971 | | - fallback.name.clone(), |
| 1980 | + mon.name.clone(), |
| 1972 | 1981 | ) |
| 1973 | 1982 | }; |
| 1974 | 1983 | |
| 1975 | | - I3WorkspaceInfo { |
| 1984 | + Some(I3WorkspaceInfo { |
| 1976 | 1985 | id: (i + 1) as i64 * 1000000, // Generate unique ID |
| 1977 | 1986 | num: (i + 1) as i32, |
| 1978 | 1987 | name: ws.name.clone(), |
@@ -1981,7 +1990,7 @@ impl WindowManager { |
| 1981 | 1990 | urgent, |
| 1982 | 1991 | rect, |
| 1983 | 1992 | output, |
| 1984 | | - } |
| 1993 | + }) |
| 1985 | 1994 | }).collect() |
| 1986 | 1995 | } |
| 1987 | 1996 | |