forge
Explore
Log in

Don't you dare go Hollow

Add niri msg windows

Browse files at this commit

64a935192143286d59b94de00ba4726dadf0fd79Ivan MolodetskikhParent: 332af8b
niri-ipc/src/lib.rsmodified+4 -0
@@ -21,6 +21,8 @@ pub enum Request {
2121 Outputs,
2222 /// Request information about workspaces.
2323 Workspaces,
24+ /// Request information about open windows.
25+ Windows,
2426 /// Request information about the configured keyboard layouts.
2527 KeyboardLayouts,
2628 /// Request information about the focused output.
@@ -73,6 +75,8 @@ pub enum Response {
7375 Outputs(HashMap<String, Output>),
7476 /// Information about workspaces.
7577 Workspaces(Vec<Workspace>),
78+ /// Information about open windows.
79+ Windows(Vec<Window>),
7680 /// Information about the keyboard layout.
7781 KeyboardLayouts(KeyboardLayouts),
7882 /// Information about the focused output.
src/cli.rsmodified+2 -0
@@ -62,6 +62,8 @@ pub enum Msg {
6262 Outputs,
6363 /// List workspaces.
6464 Workspaces,
65+ /// List open windows.
66+ Windows,
6567 /// Get the configured keyboard layouts.
6668 KeyboardLayouts,
6769 /// Print information about the focused output.
src/ipc/client.rsmodified+40 -0
@@ -20,6 +20,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
2020 action: action.clone(),
2121 },
2222 Msg::Workspaces => Request::Workspaces,
23+ Msg::Windows => Request::Windows,
2324 Msg::KeyboardLayouts => Request::KeyboardLayouts,
2425 Msg::EventStream => Request::EventStream,
2526 Msg::RequestError => Request::ReturnError,
@@ -155,6 +156,45 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
155156 println!("No window is focused.");
156157 }
157158 }
159+ Msg::Windows => {
160+ let Response::Windows(mut windows) = response else {
161+ bail!("unexpected response: expected Windows, got {response:?}");
162+ };
163+
164+ if json {
165+ let windows =
166+ serde_json::to_string(&windows).context("error formatting response")?;
167+ println!("{windows}");
168+ return Ok(());
169+ }
170+
171+ windows.sort_unstable_by(|a, b| a.id.cmp(&b.id));
172+
173+ for window in windows {
174+ let focused = if window.is_focused { " (focused)" } else { "" };
175+ println!("Window ID {}:{focused}", window.id);
176+
177+ if let Some(title) = window.title {
178+ println!(" Title: \"{title}\"");
179+ } else {
180+ println!(" Title: (unset)");
181+ }
182+
183+ if let Some(app_id) = window.app_id {
184+ println!(" App ID: \"{app_id}\"");
185+ } else {
186+ println!(" App ID: (unset)");
187+ }
188+
189+ if let Some(workspace_id) = window.workspace_id {
190+ println!(" Workspace ID: {workspace_id}");
191+ } else {
192+ println!(" Workspace ID: (none)");
193+ }
194+
195+ println!();
196+ }
197+ }
158198 Msg::FocusedOutput => {
159199 let Response::FocusedOutput(output) = response else {
160200 bail!("unexpected response: expected FocusedOutput, got {response:?}");
src/ipc/server.rsmodified+5 -0
@@ -260,6 +260,11 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
260260 let workspaces = state.workspaces.workspaces.values().cloned().collect();
261261 Response::Workspaces(workspaces)
262262 }
263+ Request::Windows => {
264+ let state = ctx.event_stream_state.borrow();
265+ let windows = state.windows.windows.values().cloned().collect();
266+ Response::Windows(windows)
267+ }
263268 Request::KeyboardLayouts => {
264269 let state = ctx.event_stream_state.borrow();
265270 let layout = state.keyboard_layouts.keyboard_layouts.clone();