diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-20 12:04:10 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-09-01 23:47:19 -0700 |
| commit | 30b213601a4f71d65a2227fa68ffb1ab2a69f671 (patch) | |
| tree | e68d9db212c6a4ac610ec0f80bb3e5db83950a67 /src/layout | |
| parent | 8eb34b2e185aa0e0affea450226369cd3f9e6a78 (diff) | |
| download | niri-30b213601a4f71d65a2227fa68ffb1ab2a69f671.tar.gz niri-30b213601a4f71d65a2227fa68ffb1ab2a69f671.tar.bz2 niri-30b213601a4f71d65a2227fa68ffb1ab2a69f671.zip | |
Implement the event stream IPC
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/mod.rs | 64 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 11 |
2 files changed, 42 insertions, 33 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index ac46d5b8..20c63d28 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -42,6 +42,7 @@ use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; use smithay::output::{self, Output}; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform}; +use workspace::WorkspaceId; pub use self::monitor::MonitorRenderElement; use self::monitor::{Monitor, WorkspaceSwitch}; @@ -1094,13 +1095,13 @@ impl<W: LayoutElement> Layout<W> { mon.workspaces.iter().flat_map(|ws| ws.windows()) } - pub fn with_windows(&self, mut f: impl FnMut(&W, Option<&Output>)) { + pub fn with_windows(&self, mut f: impl FnMut(&W, Option<&Output>, WorkspaceId)) { match &self.monitor_set { MonitorSet::Normal { monitors, .. } => { for mon in monitors { for ws in &mon.workspaces { for win in ws.windows() { - f(win, Some(&mon.output)); + f(win, Some(&mon.output), ws.id()); } } } @@ -1108,7 +1109,7 @@ impl<W: LayoutElement> Layout<W> { MonitorSet::NoOutputs { workspaces } => { for ws in workspaces { for win in ws.windows() { - f(win, None); + f(win, None, ws.id()); } } } @@ -2484,39 +2485,38 @@ impl<W: LayoutElement> Layout<W> { } } - pub fn ipc_workspaces(&self) -> Vec<niri_ipc::Workspace> { + pub fn workspaces( + &self, + ) -> impl Iterator<Item = (Option<&Monitor<W>>, usize, &Workspace<W>)> + '_ { + let iter_normal; + let iter_no_outputs; + match &self.monitor_set { - MonitorSet::Normal { - monitors, - primary_idx: _, - active_monitor_idx: _, - } => { - let mut workspaces = Vec::new(); - - for monitor in monitors { - for (idx, workspace) in monitor.workspaces.iter().enumerate() { - workspaces.push(niri_ipc::Workspace { - idx: u8::try_from(idx + 1).unwrap_or(u8::MAX), - name: workspace.name.clone(), - output: Some(monitor.output.name()), - is_active: monitor.active_workspace_idx == idx, - }) - } - } + MonitorSet::Normal { monitors, .. } => { + let it = monitors.iter().flat_map(|mon| { + mon.workspaces + .iter() + .enumerate() + .map(move |(idx, ws)| (Some(mon), idx, ws)) + }); - workspaces + iter_normal = Some(it); + iter_no_outputs = None; + } + MonitorSet::NoOutputs { workspaces } => { + let it = workspaces + .iter() + .enumerate() + .map(|(idx, ws)| (None, idx, ws)); + + iter_normal = None; + iter_no_outputs = Some(it); } - MonitorSet::NoOutputs { workspaces } => workspaces - .iter() - .enumerate() - .map(|(idx, ws)| niri_ipc::Workspace { - idx: u8::try_from(idx + 1).unwrap_or(u8::MAX), - name: ws.name.clone(), - output: None, - is_active: false, - }) - .collect(), } + + let iter_normal = iter_normal.into_iter().flatten(); + let iter_no_outputs = iter_no_outputs.into_iter().flatten(); + iter_normal.chain(iter_no_outputs) } } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index c948bdf2..17ce9a33 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -123,7 +123,7 @@ pub struct OutputId(String); static WORKSPACE_ID_COUNTER: IdCounter = IdCounter::new(); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct WorkspaceId(u32); +pub struct WorkspaceId(pub u32); impl WorkspaceId { fn next() -> WorkspaceId { @@ -528,6 +528,15 @@ impl<W: LayoutElement> Workspace<W> { self.output.as_ref() } + pub fn active_window(&self) -> Option<&W> { + if self.columns.is_empty() { + return None; + } + + let col = &self.columns[self.active_column_idx]; + Some(col.tiles[col.active_tile_idx].window()) + } + pub fn set_output(&mut self, output: Option<Output>) { if self.output == output { return; |
