Skip to content

Commit

Permalink
Support multiple clients for niri msg pick-window
Browse files Browse the repository at this point in the history
WIP: Currently the ipc server gets stuck waiting for niri to return the
picked window, and if the ipc client closes it doesn't realize that until
niri returns the picked window leading to "ghost" window picking.

In general having `self.niri.pick_window.retain(|tx| !tx.is_closed());`
to cleanup closed clients in input events feels like the wrong place,
but should work since having stale senders doesn't effect anything else.

[skip ci]
  • Loading branch information
bbb651 committed Jan 22, 2025
1 parent 60dc758 commit 368d47d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,12 @@ impl State {
}
}

if let Some(tx) = this
.niri
.pick_window
.take_if(move |_| raw == Some(Keysym::Escape))
{
let _ = tx.send_blocking(None);
return FilterResult::Intercept(None);
if pressed && raw == Some(Keysym::Escape) {
this.niri.pick_window.retain(|tx| !tx.is_closed());
if let Some(tx) = this.niri.pick_window.pop_front() {
let _ = tx.send_blocking(None);
return FilterResult::Intercept(None);
}
}

should_intercept_key(
Expand Down Expand Up @@ -1842,12 +1841,13 @@ impl State {
self.niri.pointer_hidden = false;
self.niri.tablet_cursor_location = None;

if let Some(tx) = self.niri.pick_window.take() {
self.niri.pick_window.retain(|tx| !tx.is_closed());
if !self.niri.pick_window.is_empty() {
if let Some(mapped_id) = self.niri.window_under_cursor().map(|mapped| mapped.id()) {
let tx = self.niri.pick_window.pop_front().unwrap();
let _ = tx.send_blocking(Some(mapped_id));
return;
}
self.niri.pick_window = Some(tx);
}

if let Some(mapped) = self.niri.window_under_cursor() {
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ 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);
state.niri.pick_window.push_back(tx);
});
let result = rx.recv().await;
let id = result.map_err(|_| String::from("error getting picked window info"))?;
Expand Down
6 changes: 3 additions & 3 deletions src/niri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cell::{Cell, OnceCell, RefCell};
use std::collections::{HashMap, HashSet};
use std::collections::{HashMap, HashSet, VecDeque};
use std::ffi::OsString;
use std::path::PathBuf;
use std::rc::Rc;
Expand Down Expand Up @@ -333,7 +333,7 @@ pub struct Niri {
pub hotkey_overlay: HotkeyOverlay,
pub exit_confirm_dialog: Option<ExitConfirmDialog>,

pub pick_window: Option<async_channel::Sender<Option<MappedId>>>,
pub pick_window: VecDeque<async_channel::Sender<Option<MappedId>>>,

pub debug_draw_opaque_regions: bool,
pub debug_draw_damage: bool,
Expand Down Expand Up @@ -2078,7 +2078,7 @@ impl Niri {
hotkey_overlay,
exit_confirm_dialog,

pick_window: None,
pick_window: VecDeque::new(),

debug_draw_opaque_regions: false,
debug_draw_damage: false,
Expand Down

0 comments on commit 368d47d

Please sign in to comment.