aboutsummaryrefslogtreecommitdiff
path: root/src/ipc
diff options
context:
space:
mode:
authorbbb651 🇮🇱 <53972231+bbb651@users.noreply.github.com>2025-02-26 14:22:27 +0200
committerGitHub <noreply@github.com>2025-02-26 15:22:27 +0300
commit16405b9b2b99edaf9388df6a7228ca07f110769d (patch)
treed05734655900336c809bb212230cb4d34a6325b2 /src/ipc
parent4719cc6d5942c70f43ae167d66d2383708ae3536 (diff)
downloadniri-16405b9b2b99edaf9388df6a7228ca07f110769d.tar.gz
niri-16405b9b2b99edaf9388df6a7228ca07f110769d.tar.bz2
niri-16405b9b2b99edaf9388df6a7228ca07f110769d.zip
Implement `niri msg pick-window`
* feat: `niri msg pick-window` * fixes --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
Diffstat (limited to 'src/ipc')
-rw-r--r--src/ipc/client.rs18
-rw-r--r--src/ipc/server.rs34
2 files changed, 52 insertions, 0 deletions
diff --git a/src/ipc/client.rs b/src/ipc/client.rs
index 8682d8d3..66cdaf7d 100644
--- a/src/ipc/client.rs
+++ b/src/ipc/client.rs
@@ -19,6 +19,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
Msg::Outputs => Request::Outputs,
Msg::FocusedWindow => Request::FocusedWindow,
Msg::FocusedOutput => Request::FocusedOutput,
+ Msg::PickWindow => Request::PickWindow,
Msg::Action { action } => Request::Action(action.clone()),
Msg::Output { output, action } => Request::Output {
output: output.clone(),
@@ -252,6 +253,23 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
println!("No output is focused.");
}
}
+ Msg::PickWindow => {
+ let Response::PickedWindow(window) = response else {
+ bail!("unexpected response: expected PickedWindow, got {response:?}");
+ };
+
+ if json {
+ let window = serde_json::to_string(&window).context("error formatting response")?;
+ println!("{window}");
+ return Ok(());
+ }
+
+ if let Some(window) = window {
+ print_window(&window);
+ } else {
+ println!("No window selected.");
+ }
+ }
Msg::Action { .. } => {
let Response::Handled = response else {
bail!("unexpected response: expected Handled, got {response:?}");
diff --git a/src/ipc/server.rs b/src/ipc/server.rs
index 6706928a..c8f8edcf 100644
--- a/src/ipc/server.rs
+++ b/src/ipc/server.rs
@@ -18,12 +18,17 @@ use niri_config::OutputName;
use niri_ipc::state::{EventStreamState, EventStreamStatePart as _};
use niri_ipc::{Event, KeyboardLayouts, OutputConfigChanged, Reply, Request, Response, Workspace};
use smithay::desktop::layer_map_for_output;
+use smithay::input::pointer::{
+ CursorIcon, CursorImageStatus, Focus, GrabStartData as PointerGrabStartData,
+};
use smithay::reexports::calloop::generic::Generic;
use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
use smithay::reexports::rustix::fs::unlink;
+use smithay::utils::SERIAL_COUNTER;
use smithay::wayland::shell::wlr_layer::{KeyboardInteractivity, Layer};
use crate::backend::IpcOutputMap;
+use crate::input::pick_window_grab::PickWindowGrab;
use crate::layout::workspace::WorkspaceId;
use crate::niri::State;
use crate::utils::{version, with_toplevel_role};
@@ -322,6 +327,35 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
let window = windows.values().find(|win| win.is_focused).cloned();
Response::FocusedWindow(window)
}
+ Request::PickWindow => {
+ let (tx, rx) = async_channel::bounded(1);
+ ctx.event_loop.insert_idle(move |state| {
+ let pointer = state.niri.seat.get_pointer().unwrap();
+ let start_data = PointerGrabStartData {
+ focus: None,
+ button: 0,
+ location: pointer.current_location(),
+ };
+ let grab = PickWindowGrab::new(start_data);
+ // The `WindowPickGrab` ungrab handler will cancel the previous ongoing pick, if
+ // any.
+ pointer.set_grab(state, grab, SERIAL_COUNTER.next_serial(), Focus::Clear);
+ state.niri.pick_window = Some(tx);
+ state
+ .niri
+ .cursor_manager
+ .set_cursor_image(CursorImageStatus::Named(CursorIcon::Crosshair));
+ // Redraw to update the cursor.
+ state.niri.queue_redraw_all();
+ });
+ let result = rx.recv().await;
+ let id = result.map_err(|_| String::from("error getting picked window info"))?;
+ let window = id.and_then(|id| {
+ let state = ctx.event_stream_state.borrow();
+ state.windows.windows.get(&id.get()).cloned()
+ });
+ Response::PickedWindow(window)
+ }
Request::Action(action) => {
let (tx, rx) = async_channel::bounded(1);