Extract print_window()
Browse files at this commit7d11ef0abb88f18b4c5380aa9bea6c684fc39765Parent: dcb29ef1 changed file +26 -35
- src/ipc/client.rs +26 -35
src/ipc/client.rsmodified+26 -35
| @@ -3,7 +3,7 @@ use niri_config::OutputName; | ||
| 3 | 3 | use niri_ipc::socket::Socket; |
| 4 | 4 | use niri_ipc::{ |
| 5 | 5 | Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Request, Response, |
| 6 | - Transform, | |
| 6 | + Transform, Window, | |
| 7 | 7 | }; |
| 8 | 8 | use serde_json::json; |
| 9 | 9 | |
| @@ -144,19 +144,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | ||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if let Some(window) = window { |
| 147 | - println!("Focused window:"); | |
| 148 | - | |
| 149 | - if let Some(title) = window.title { | |
| 150 | - println!(" Title: \"{title}\""); | |
| 151 | - } else { | |
| 152 | - println!(" Title: (unset)"); | |
| 153 | - } | |
| 154 | - | |
| 155 | - if let Some(app_id) = window.app_id { | |
| 156 | - println!(" App ID: \"{app_id}\""); | |
| 157 | - } else { | |
| 158 | - println!(" App ID: (unset)"); | |
| 159 | - } | |
| 147 | + print_window(&window); | |
| 160 | 148 | } else { |
| 161 | 149 | println!("No window is focused."); |
| 162 | 150 | } |
| @@ -176,27 +164,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | ||
| 176 | 164 | windows.sort_unstable_by(|a, b| a.id.cmp(&b.id)); |
| 177 | 165 | |
| 178 | 166 | for window in windows { |
| 179 | - let focused = if window.is_focused { " (focused)" } else { "" }; | |
| 180 | - println!("Window ID {}:{focused}", window.id); | |
| 181 | - | |
| 182 | - if let Some(title) = window.title { | |
| 183 | - println!(" Title: \"{title}\""); | |
| 184 | - } else { | |
| 185 | - println!(" Title: (unset)"); | |
| 186 | - } | |
| 187 | - | |
| 188 | - if let Some(app_id) = window.app_id { | |
| 189 | - println!(" App ID: \"{app_id}\""); | |
| 190 | - } else { | |
| 191 | - println!(" App ID: (unset)"); | |
| 192 | - } | |
| 193 | - | |
| 194 | - if let Some(workspace_id) = window.workspace_id { | |
| 195 | - println!(" Workspace ID: {workspace_id}"); | |
| 196 | - } else { | |
| 197 | - println!(" Workspace ID: (none)"); | |
| 198 | - } | |
| 199 | - | |
| 167 | + print_window(&window); | |
| 200 | 168 | println!(); |
| 201 | 169 | } |
| 202 | 170 | } |
| @@ -464,3 +432,26 @@ fn print_output(output: Output) -> anyhow::Result<()> { | ||
| 464 | 432 | } |
| 465 | 433 | Ok(()) |
| 466 | 434 | } |
| 435 | + | |
| 436 | +fn print_window(window: &Window) { | |
| 437 | + let focused = if window.is_focused { " (focused)" } else { "" }; | |
| 438 | + println!("Window ID {}:{focused}", window.id); | |
| 439 | + | |
| 440 | + if let Some(title) = &window.title { | |
| 441 | + println!(" Title: \"{title}\""); | |
| 442 | + } else { | |
| 443 | + println!(" Title: (unset)"); | |
| 444 | + } | |
| 445 | + | |
| 446 | + if let Some(app_id) = &window.app_id { | |
| 447 | + println!(" App ID: \"{app_id}\""); | |
| 448 | + } else { | |
| 449 | + println!(" App ID: (unset)"); | |
| 450 | + } | |
| 451 | + | |
| 452 | + if let Some(workspace_id) = window.workspace_id { | |
| 453 | + println!(" Workspace ID: {workspace_id}"); | |
| 454 | + } else { | |
| 455 | + println!(" Workspace ID: (none)"); | |
| 456 | + } | |
| 457 | +} |