Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Feb 17, 2025
1 parent 24b3ab5 commit 15bec65
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
27 changes: 15 additions & 12 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,24 @@ impl CursorManager {

RenderCursor::Surface { hotspot, surface }
}
CursorImageStatus::Named(icon) => self
.get_cursor_with_name(icon, scale)
.map(|cursor| RenderCursor::Named {
icon,
scale,
cursor,
})
.unwrap_or_else(|| RenderCursor::Named {
icon: Default::default(),
scale,
cursor: self.get_default_cursor(scale),
}),
CursorImageStatus::Named(icon) => self.get_render_cursor_named(icon, scale),
}
}

pub fn get_render_cursor_named(&self, icon: CursorIcon, scale: i32) -> RenderCursor {
self.get_cursor_with_name(icon, scale)
.map(|cursor| RenderCursor::Named {
icon,
scale,
cursor,
})
.unwrap_or_else(|| RenderCursor::Named {
icon: Default::default(),
scale,
cursor: self.get_default_cursor(scale),
})
}

pub fn is_current_cursor_animated(&self, scale: i32) -> bool {
match &self.current_cursor {
CursorImageStatus::Hidden => false,
Expand Down
20 changes: 11 additions & 9 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ impl State {
serial,
time,
|this, mods, keysym| {
let bindings = &this.niri.config.borrow().binds;
let key_code = event.key_code();
let modified = keysym.modified_sym();
let raw = keysym.raw_latin_sym_or_raw_current_sym();
Expand All @@ -384,16 +383,17 @@ impl State {
}
}

if let Some(tx) = this
.niri
.pick_window
.take_if(|_| pressed && raw == Some(Keysym::Escape))
{
this.niri.suppressed_keys.insert(key_code);
let _ = tx.send_blocking(None);
return FilterResult::Intercept(None);
if pressed && raw == Some(Keysym::Escape) {
if let Some(tx) = this.niri.pick_window.take() {
this.niri.suppressed_keys.insert(key_code);
let _ = tx.send_blocking(None);
// Redraw to update the cursor.
this.niri.queue_redraw_all();
return FilterResult::Intercept(None);
}
}

let bindings = &this.niri.config.borrow().binds;
should_intercept_key(
&mut this.niri.suppressed_keys,
bindings,
Expand Down Expand Up @@ -2034,6 +2034,8 @@ impl State {

if let Some(tx) = self.niri.pick_window.take() {
let _ = tx.send_blocking(self.niri.window_under_cursor().map(Mapped::id));
// Redraw to update the cursor.
self.niri.queue_redraw_all();
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,12 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
let (tx, rx) = async_channel::bounded(1);
ctx.event_loop.insert_idle(move |state| {
if let Some(tx) = state.niri.pick_window.replace(tx) {
// Cancel previous ongoing pick, if any.
let _ = tx.send_blocking(None);
}

// 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"))?;
Expand Down
13 changes: 1 addition & 12 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3013,19 +3013,8 @@ impl Niri {
// Get the render cursor to draw.
let cursor_scale = output_scale.integer_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),
})
.get_render_cursor_named(CursorIcon::Crosshair, cursor_scale)
} else {
self.cursor_manager.get_render_cursor(cursor_scale)
};
Expand Down

0 comments on commit 15bec65

Please sign in to comment.