aboutsummaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/input')
-rw-r--r--src/input/mod.rs15
-rw-r--r--src/input/pick_window_grab.rs167
2 files changed, 181 insertions, 1 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index 51555a96..8e22098c 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -48,6 +48,7 @@ use crate::utils::{center, get_monotonic_time, ResizeEdge};
pub mod backend_ext;
pub mod move_grab;
+pub mod pick_window_grab;
pub mod resize_grab;
pub mod scroll_tracker;
pub mod spatial_movement_grab;
@@ -367,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();
@@ -383,6 +383,19 @@ impl State {
}
}
+ if pressed && raw == Some(Keysym::Escape) && this.niri.pick_window.is_some() {
+ // We window picking state so the pick window grab must be active.
+ // Unsetting it cancels window picking.
+ this.niri
+ .seat
+ .get_pointer()
+ .unwrap()
+ .unset_grab(this, serial, time);
+ this.niri.suppressed_keys.insert(key_code);
+ return FilterResult::Intercept(None);
+ }
+
+ let bindings = &this.niri.config.borrow().binds;
should_intercept_key(
&mut this.niri.suppressed_keys,
bindings,
diff --git a/src/input/pick_window_grab.rs b/src/input/pick_window_grab.rs
new file mode 100644
index 00000000..9a3b22ae
--- /dev/null
+++ b/src/input/pick_window_grab.rs
@@ -0,0 +1,167 @@
+use smithay::backend::input::ButtonState;
+use smithay::input::pointer::{
+ AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent,
+ GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent,
+ GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData,
+ MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent,
+};
+use smithay::input::SeatHandler;
+use smithay::utils::{Logical, Point};
+
+use crate::niri::State;
+use crate::window::Mapped;
+
+pub struct PickWindowGrab {
+ start_data: PointerGrabStartData<State>,
+}
+
+impl PickWindowGrab {
+ pub fn new(start_data: PointerGrabStartData<State>) -> Self {
+ Self { start_data }
+ }
+
+ fn on_ungrab(&mut self, state: &mut State) {
+ if let Some(tx) = state.niri.pick_window.take() {
+ let _ = tx.send_blocking(None);
+ }
+ state
+ .niri
+ .cursor_manager
+ .set_cursor_image(CursorImageStatus::default_named());
+ // Redraw to update the cursor.
+ state.niri.queue_redraw_all();
+ }
+}
+
+impl PointerGrab<State> for PickWindowGrab {
+ fn motion(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
+ event: &MotionEvent,
+ ) {
+ handle.motion(data, None, event);
+ }
+
+ fn relative_motion(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
+ event: &RelativeMotionEvent,
+ ) {
+ handle.relative_motion(data, None, event);
+ }
+
+ fn button(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &ButtonEvent,
+ ) {
+ if event.state == ButtonState::Pressed {
+ if let Some(tx) = data.niri.pick_window.take() {
+ let _ = tx.send_blocking(
+ data.niri
+ .window_under(handle.current_location())
+ .map(Mapped::id),
+ );
+ }
+ handle.unset_grab(self, data, event.serial, event.time, true);
+ }
+ }
+
+ fn axis(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ details: AxisFrame,
+ ) {
+ handle.axis(data, details);
+ }
+
+ fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) {
+ handle.frame(data);
+ }
+
+ fn gesture_swipe_begin(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GestureSwipeBeginEvent,
+ ) {
+ handle.gesture_swipe_begin(data, event);
+ }
+
+ fn gesture_swipe_update(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GestureSwipeUpdateEvent,
+ ) {
+ handle.gesture_swipe_update(data, event);
+ }
+
+ fn gesture_swipe_end(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GestureSwipeEndEvent,
+ ) {
+ handle.gesture_swipe_end(data, event);
+ }
+
+ fn gesture_pinch_begin(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GesturePinchBeginEvent,
+ ) {
+ handle.gesture_pinch_begin(data, event);
+ }
+
+ fn gesture_pinch_update(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GesturePinchUpdateEvent,
+ ) {
+ handle.gesture_pinch_update(data, event);
+ }
+
+ fn gesture_pinch_end(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GesturePinchEndEvent,
+ ) {
+ handle.gesture_pinch_end(data, event);
+ }
+
+ fn gesture_hold_begin(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GestureHoldBeginEvent,
+ ) {
+ handle.gesture_hold_begin(data, event);
+ }
+
+ fn gesture_hold_end(
+ &mut self,
+ data: &mut State,
+ handle: &mut PointerInnerHandle<'_, State>,
+ event: &GestureHoldEndEvent,
+ ) {
+ handle.gesture_hold_end(data, event);
+ }
+
+ fn start_data(&self) -> &PointerGrabStartData<State> {
+ &self.start_data
+ }
+
+ fn unset(&mut self, data: &mut State) {
+ self.on_ungrab(data);
+ }
+}