Add niri msg windows
Browse files at this commit64a935192143286d59b94de00ba4726dadf0fd79Parent: 332af8b4 changed files +51 -0
- niri-ipc/src/lib.rs +4 -0
- src/cli.rs +2 -0
- src/ipc/client.rs +40 -0
- src/ipc/server.rs +5 -0
niri-ipc/src/lib.rsmodified+4 -0
| @@ -21,6 +21,8 @@ pub enum Request { | ||
| 21 | 21 | Outputs, |
| 22 | 22 | /// Request information about workspaces. |
| 23 | 23 | Workspaces, |
| 24 | + /// Request information about open windows. | |
| 25 | + Windows, | |
| 24 | 26 | /// Request information about the configured keyboard layouts. |
| 25 | 27 | KeyboardLayouts, |
| 26 | 28 | /// Request information about the focused output. |
| @@ -73,6 +75,8 @@ pub enum Response { | ||
| 73 | 75 | Outputs(HashMap<String, Output>), |
| 74 | 76 | /// Information about workspaces. |
| 75 | 77 | Workspaces(Vec<Workspace>), |
| 78 | + /// Information about open windows. | |
| 79 | + Windows(Vec<Window>), | |
| 76 | 80 | /// Information about the keyboard layout. |
| 77 | 81 | KeyboardLayouts(KeyboardLayouts), |
| 78 | 82 | /// Information about the focused output. |
src/cli.rsmodified+2 -0
| @@ -62,6 +62,8 @@ pub enum Msg { | ||
| 62 | 62 | Outputs, |
| 63 | 63 | /// List workspaces. |
| 64 | 64 | Workspaces, |
| 65 | + /// List open windows. | |
| 66 | + Windows, | |
| 65 | 67 | /// Get the configured keyboard layouts. |
| 66 | 68 | KeyboardLayouts, |
| 67 | 69 | /// 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<()> { | ||
| 20 | 20 | action: action.clone(), |
| 21 | 21 | }, |
| 22 | 22 | Msg::Workspaces => Request::Workspaces, |
| 23 | + Msg::Windows => Request::Windows, | |
| 23 | 24 | Msg::KeyboardLayouts => Request::KeyboardLayouts, |
| 24 | 25 | Msg::EventStream => Request::EventStream, |
| 25 | 26 | Msg::RequestError => Request::ReturnError, |
| @@ -155,6 +156,45 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | ||
| 155 | 156 | println!("No window is focused."); |
| 156 | 157 | } |
| 157 | 158 | } |
| 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 | + } | |
| 158 | 198 | Msg::FocusedOutput => { |
| 159 | 199 | let Response::FocusedOutput(output) = response else { |
| 160 | 200 | 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 { | ||
| 260 | 260 | let workspaces = state.workspaces.workspaces.values().cloned().collect(); |
| 261 | 261 | Response::Workspaces(workspaces) |
| 262 | 262 | } |
| 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 | + } | |
| 263 | 268 | Request::KeyboardLayouts => { |
| 264 | 269 | let state = ctx.event_stream_state.borrow(); |
| 265 | 270 | let layout = state.keyboard_layouts.keyboard_layouts.clone(); |