Skip to content

Commit

Permalink
Change cursor to crosshairs when taking a screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Oct 31, 2023
1 parent 25e701d commit d854c2d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::thread;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::renderer::ImportDma;
use smithay::desktop::{PopupKind, PopupManager};
use smithay::input::pointer::CursorImageStatus;
use smithay::input::pointer::{CursorIcon, CursorImageStatus};
use smithay::input::{Seat, SeatHandler, SeatState};
use smithay::output::Output;
use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
Expand Down Expand Up @@ -52,7 +52,12 @@ impl SeatHandler for State {
&mut self.niri.seat_state
}

fn cursor_image(&mut self, _seat: &Seat<Self>, image: CursorImageStatus) {
fn cursor_image(&mut self, _seat: &Seat<Self>, mut image: CursorImageStatus) {
// FIXME: this hack should be removable once the screenshot UI is tracked with a
// PointerFocus properly.
if self.niri.screenshot_ui.is_open() {
image = CursorImageStatus::Named(CursorIcon::Crosshair);
}
self.niri.cursor_manager.set_cursor_image(image);
// FIXME: more granular
self.niri.queue_redraw_all();
Expand Down
12 changes: 9 additions & 3 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use smithay::backend::input::{
use smithay::backend::libinput::LibinputInputBackend;
use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};
use smithay::input::pointer::{
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent,
GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent,
GestureSwipeUpdateEvent, MotionEvent, RelativeMotionEvent,
AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent,
GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent,
GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent, RelativeMotionEvent,
};
use smithay::utils::SERIAL_COUNTER;
use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
Expand Down Expand Up @@ -146,10 +146,16 @@ impl State {
}

self.niri.screenshot_ui.close();
self.niri
.cursor_manager
.set_cursor_image(CursorImageStatus::default_named());
self.niri.queue_redraw_all();
}
Action::CancelScreenshot => {
self.niri.screenshot_ui.close();
self.niri
.cursor_manager
.set_cursor_image(CursorImageStatus::default_named());
self.niri.queue_redraw_all();
}
Action::Screenshot => {
Expand Down
10 changes: 9 additions & 1 deletion src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use smithay::desktop::utils::{
};
use smithay::desktop::{layer_map_for_output, PopupManager, Space, Window, WindowSurfaceType};
use smithay::input::keyboard::XkbConfig;
use smithay::input::pointer::{CursorImageAttributes, CursorImageStatus, MotionEvent};
use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent};
use smithay::input::{Seat, SeatState};
use smithay::output::Output;
use smithay::reexports::calloop::generic::Generic;
Expand Down Expand Up @@ -844,6 +844,8 @@ impl Niri {
}

if self.screenshot_ui.close() {
self.cursor_manager
.set_cursor_image(CursorImageStatus::default_named());
self.queue_redraw_all();
}
}
Expand Down Expand Up @@ -873,6 +875,8 @@ impl Niri {
let size = output_transform.transform_size(output_mode.size);
if old_size != size {
self.screenshot_ui.close();
self.cursor_manager
.set_cursor_image(CursorImageStatus::default_named());
self.queue_redraw_all();
return;
}
Expand Down Expand Up @@ -1958,6 +1962,8 @@ impl Niri {

self.screenshot_ui
.open(renderer, screenshots, default_output);
self.cursor_manager
.set_cursor_image(CursorImageStatus::Named(CursorIcon::Crosshair));
self.queue_redraw_all();
}

Expand Down Expand Up @@ -2116,6 +2122,8 @@ impl Niri {
info!("locking session");

self.screenshot_ui.close();
self.cursor_manager
.set_cursor_image(CursorImageStatus::default_named());

self.lock_state = LockState::Locking(confirmation);
self.queue_redraw_all();
Expand Down

0 comments on commit d854c2d

Please sign in to comment.