Skip to content

Commit

Permalink
feat: niri msg pick-window
Browse files Browse the repository at this point in the history
Fixes #589.

[skip ci]
  • Loading branch information
bbb651 committed Feb 16, 2025
1 parent 24c8fbf commit a130828
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
2 changes: 0 additions & 2 deletions niri-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ pub enum Response {
/// Information about the focused window.
FocusedWindow(Option<Window>),
/// Information about the picked window.
///
/// `None` if the request was cancelled by the user.
PickedWindow(Option<Window>),
/// Output configuration change result.
OutputConfigChanged(OutputConfigChanged),
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum Msg {
FocusedOutput,
/// Print information about the focused window.
FocusedWindow,
/// Request picking a window.
/// Pick a window with the mouse and print information about it.
PickWindow,
/// Perform an action.
Action {
Expand Down
5 changes: 5 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ impl SeatHandler for State {
}

fn cursor_image(&mut self, _seat: &Seat<Self>, mut image: CursorImageStatus) {
// FIXME: this discards the cursor image so we cannot twice back to it once we
// exit window picking mode
if self.niri.pick_window.is_some() {
image = CursorImageStatus::Named(CursorIcon::Crosshair);
}
// FIXME: this hack should be removable once the screenshot UI is tracked with a
// PointerFocus properly.
if self.niri.screenshot_ui.is_open() {
Expand Down
11 changes: 5 additions & 6 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::niri::State;
use crate::ui::screenshot_ui::ScreenshotUi;
use crate::utils::spawning::spawn;
use crate::utils::{center, get_monotonic_time, ResizeEdge};
use crate::window::Mapped;

pub mod backend_ext;
pub mod move_grab;
Expand Down Expand Up @@ -391,8 +392,9 @@ impl State {
if let Some(tx) = this
.niri
.pick_window
.take_if(move |_| raw == Some(Keysym::Escape))
.take_if(|_| pressed && raw == Some(Keysym::Escape))
{
this.niri.suppressed_keys.insert(key_code);
let _ = tx.send_blocking(None);
return FilterResult::Intercept(None);
}
Expand Down Expand Up @@ -2036,11 +2038,8 @@ impl State {
self.niri.tablet_cursor_location = None;

if let Some(tx) = self.niri.pick_window.take() {
if let Some(mapped_id) = self.niri.window_under_cursor().map(|mapped| mapped.id()) {
let _ = tx.send_blocking(Some(mapped_id));
return;
}
self.niri.pick_window = Some(tx);
let _ = tx.send_blocking(self.niri.window_under_cursor().map(Mapped::id));
return;
}

if let Some(mapped) = self.niri.window_under_cursor() {
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
if let Some(window) = window {
print_window(&window);
} else {
println!("Picking window was cancelled.");
println!("No window selected.");
}
}
Msg::Action { .. } => {
Expand Down
4 changes: 3 additions & 1 deletion src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
Request::PickWindow => {
let (tx, rx) = async_channel::bounded(1);
ctx.event_loop.insert_idle(move |state| {
state.niri.pick_window = Some(tx);
if let Some(tx) = state.niri.pick_window.replace(tx) {
let _ = tx.send_blocking(None);
}
});
let result = rx.recv().await;
let id = result.map_err(|_| String::from("error getting picked window info"))?;
Expand Down
18 changes: 17 additions & 1 deletion src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2996,7 +2996,23 @@ impl Niri {

// Get the render cursor to draw.
let cursor_scale = output_scale.integer_scale();
let render_cursor = self.cursor_manager.get_render_cursor(cursor_scale);
let render_cursor = if self.pick_window.is_some() {
// FIXME: override the cursor without repeating the logic of `get_render_cursor`
self.cursor_manager
.get_cursor_with_name(CursorIcon::Crosshair, cursor_scale)
.map(|cursor| RenderCursor::Named {
icon: CursorIcon::Crosshair,
scale: cursor_scale,
cursor,
})
.unwrap_or_else(|| RenderCursor::Named {
icon: Default::default(),
scale: cursor_scale,
cursor: self.cursor_manager.get_default_cursor(cursor_scale),
})
} else {
self.cursor_manager.get_render_cursor(cursor_scale)
};

let output_scale = Scale::from(output.current_scale().fractional_scale());

Expand Down

0 comments on commit a130828

Please sign in to comment.