forge
Explore
Log in

Don't you dare go Hollow

Extract print_window()

Browse files at this commit

7d11ef0abb88f18b4c5380aa9bea6c684fc39765Ivan MolodetskikhParent: dcb29ef
src/ipc/client.rsmodified+26 -35
@@ -3,7 +3,7 @@ use niri_config::OutputName;
33 use niri_ipc::socket::Socket;
44 use niri_ipc::{
55 Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Request, Response,
6- Transform,
6+ Transform, Window,
77 };
88 use serde_json::json;
99
@@ -144,19 +144,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
144144 }
145145
146146 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);
160148 } else {
161149 println!("No window is focused.");
162150 }
@@ -176,27 +164,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
176164 windows.sort_unstable_by(|a, b| a.id.cmp(&b.id));
177165
178166 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);
200168 println!();
201169 }
202170 }
@@ -464,3 +432,26 @@ fn print_output(output: Output) -> anyhow::Result<()> {
464432 }
465433 Ok(())
466434 }
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+}