From 5c93094574b31800caaa27255caac4a7253f24ad Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 19 Aug 2026 12:40:05 +0200 Subject: [PATCH 01/37] chore: update smithay --- Cargo.lock | 53 +++------- Cargo.toml | 2 +- src/config/mod.rs | 8 +- src/input/actions.rs | 5 +- src/input/mod.rs | 107 ++++++++++---------- src/shell/element/mod.rs | 4 +- src/shell/element/stack.rs | 6 +- src/shell/element/surface.rs | 3 +- src/shell/element/window.rs | 6 +- src/shell/focus/mod.rs | 5 +- src/shell/focus/target.rs | 15 +-- src/shell/grabs/menu/default.rs | 13 +-- src/shell/grabs/moving.rs | 4 +- src/shell/layout/tiling/grabs/resize.rs | 4 +- src/shell/layout/tiling/grabs/swap.rs | 4 +- src/shell/zoom.rs | 4 +- src/utils/iced/mod.rs | 6 +- src/wayland/handlers/compositor.rs | 17 ++-- src/wayland/handlers/pointer_constraints.rs | 52 ++++++---- src/wayland/handlers/pointer_warp.rs | 2 +- src/wayland/handlers/toplevel_management.rs | 3 +- src/xwayland.rs | 10 +- 22 files changed, 168 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8be66ca..859203e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1189,7 +1189,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1503,7 +1503,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2690,7 +2690,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde_core", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2813,7 +2813,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a1886916523694cd6ea3d175f03a1e5010699a2a4cc13696d83d7bea1d80638" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3429,7 +3429,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -4167,20 +4167,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", + "rand_chacha", "rand_core 0.6.4", ] -[[package]] -name = "rand" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" -dependencies = [ - "rand_chacha 0.9.0", - "rand_core 0.9.5", -] - [[package]] name = "rand" version = "0.10.0" @@ -4202,16 +4192,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core 0.9.5", -] - [[package]] name = "rand_core" version = "0.6.4" @@ -4221,15 +4201,6 @@ dependencies = [ "getrandom 0.2.17", ] -[[package]] -name = "rand_core" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" -dependencies = [ - "getrandom 0.3.4", -] - [[package]] name = "rand_core" version = "0.10.0" @@ -4525,7 +4496,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -4820,7 +4791,7 @@ checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" [[package]] name = "smithay" version = "0.7.0" -source = "git+https://github.com/smithay/smithay.git?rev=5fb12b8#5fb12b87407b3680135c45d94214c5f1b1d0fbea" +source = "git+https://github.com/smithay/smithay.git?rev=e3d461a#e3d461a057ba244d213a8498ec372b0799cca103" dependencies = [ "aliasable", "appendlist", @@ -4849,7 +4820,7 @@ dependencies = [ "pkg-config", "portable-atomic", "profiling", - "rand 0.9.2", + "rand 0.10.0", "reis", "rustix 1.1.4", "scopeguard", @@ -5115,7 +5086,7 @@ dependencies = [ "getrandom 0.4.1", "once_cell", "rustix 1.1.4", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -5414,7 +5385,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5f7c95348f20c1c913d72157b3c6dee6ea3e30b3d19502c5a7f6d3f160dacbf" dependencies = [ "cc", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -6134,7 +6105,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d807d369..23fe2775 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,4 +146,4 @@ lto = "fat" cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch = "main" } [patch.crates-io] -smithay = { git = "https://github.com/smithay/smithay.git", rev = "5fb12b8" } +smithay = { git = "https://github.com/smithay/smithay.git", rev = "e3d461a" } diff --git a/src/config/mod.rs b/src/config/mod.rs index 93b53374..abef562b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -14,8 +14,11 @@ use cosmic_config::{ConfigGet, CosmicConfigEntry}; use cosmic_settings_config::window_rules::ApplicationException; use cosmic_settings_config::{Shortcuts, shortcuts, window_rules}; use serde::{Deserialize, Serialize}; -use smithay::utils::{Clock, Monotonic}; use smithay::wayland::xdg_activation::XdgActivationState; +use smithay::{ + backend::input::InputTime, + utils::{Clock, Monotonic}, +}; pub use smithay::{ backend::input::{self as smithay_input, KeyState}, input::keyboard::{Keysym, ModifiersState, keysyms as KeySyms}, @@ -770,13 +773,12 @@ pub fn change_modifier_state( const X11_KEYCODE_OFFSET: u32 = 8; let mut input = |key_state, scan_code| { - let time = state.common.clock.now().as_millis(); let _ = keyboard.input( state, smithay_input::Keycode::new(scan_code + X11_KEYCODE_OFFSET), key_state, SERIAL_COUNTER.next_serial(), - time, + InputTime::now(), |_, _, _| smithay::input::keyboard::FilterResult::<()>::Forward, ); }; diff --git a/src/input/actions.rs b/src/input/actions.rs index 8a5ef84c..8639ba62 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -18,6 +18,7 @@ use cosmic_config::ConfigSet; use cosmic_settings_config::shortcuts; use cosmic_settings_config::shortcuts::action::{Direction, FocusDirection}; use smithay::{ + backend::input::InputTime, input::{Seat, pointer::MotionEvent}, utils::{Point, Serial}, }; @@ -45,7 +46,7 @@ impl State { backend_id: &InputBackendId, seat: &Seat, serial: Serial, - time: u32, + time: InputTime, pattern: shortcuts::Binding, direction: Option, ) { @@ -150,7 +151,7 @@ impl State { backend_id: &InputBackendId, seat: &Seat, serial: Serial, - time: u32, + time: InputTime, pattern: shortcuts::Binding, direction: Option, propagate: bool, diff --git a/src/input/mod.rs b/src/input/mod.rs index 0e307079..d619a525 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -42,9 +42,9 @@ use smithay::{ backend::input::{ AbsolutePositionEvent, Axis, AxisRelativeDirection, AxisSource, Device, DeviceCapability, GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, - GestureSwipeUpdateEvent as _, InputBackend, InputEvent, KeyState, PointerAxisEvent, - ProximityState, TabletToolButtonEvent, TabletToolEvent, TabletToolProximityEvent, - TabletToolTipEvent, TabletToolTipState, TouchEvent, + GestureSwipeUpdateEvent as _, InputBackend, InputEvent, InputTime, KeyState, + PointerAxisEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent, + TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent, }, desktop::{PopupKeyboardGrab, WindowSurfaceType, utils::under_from_surface_tree}, input::{ @@ -271,7 +271,7 @@ impl State { trace!(?keycode, ?state, "key"); let serial = SERIAL_COUNTER.next_serial(); - let time = Event::time_msec(&event); + let time = Event::time(&event); let keyboard = seat.get_keyboard().unwrap(); let previous_modifiers = keyboard.modifier_state(); if let Some((action, pattern)) = keyboard @@ -397,7 +397,7 @@ impl State { &RelativeMotionEvent { delta: event.delta(), delta_unaccel: event.delta_unaccel(), - utime: event.time(), + time: event.time(), }, ); @@ -638,7 +638,7 @@ impl State { &MotionEvent { location: position.as_logical(), serial, - time: event.time_msec(), + time: event.time(), }, ); ptr.frame(self); @@ -753,7 +753,7 @@ impl State { &MotionEvent { location: position.as_logical(), serial, - time: event.time_msec(), + time: event.time(), }, ); ptr.frame(self); @@ -1005,7 +1005,7 @@ impl State { button, event.state(), serial, - event.time_msec(), + event.time(), ); } @@ -1017,12 +1017,12 @@ impl State { button, state: event.state(), serial, - time: event.time_msec(), + time: event.time(), }, ); ptr.frame(self); } else if event.state() == ButtonState::Released { - ptr.unset_grab(self, serial, event.time_msec()) + ptr.unset_grab(self, serial, event.time()) } } InputEvent::PointerAxis { event, .. } => { @@ -1073,7 +1073,7 @@ impl State { self.update_zoom(&seat, change, event.source() == AxisSource::Wheel); } } else { - let mut frame = AxisFrame::new(event.time_msec()).source(event.source()); + let mut frame = AxisFrame::new(event.time()).source(event.source()); let horizontal_amount = event .amount(Axis::Horizontal) .or_else(|| Some(event.amount_v120(Axis::Horizontal)? * 15.0 / 120.)); @@ -1142,7 +1142,7 @@ impl State { self, &GestureSwipeBeginEvent { serial, - time: event.time_msec(), + time: event.time(), fingers: event.fingers(), }, ); @@ -1163,7 +1163,7 @@ impl State { if let Some(ref mut gesture_state) = self.common.gesture_state { let first_update = gesture_state.update( event.delta(), - Duration::from_millis(event.time_msec() as u64), + Duration::from_millis(event.time().millis() as u64), ); // Decide on action if first update if first_update { @@ -1239,7 +1239,7 @@ impl State { pointer.gesture_swipe_update( self, &GestureSwipeUpdateEvent { - time: event.time_msec(), + time: event.time(), delta: event.delta(), }, ); @@ -1288,7 +1288,7 @@ impl State { self, &GestureSwipeEndEvent { serial, - time: event.time_msec(), + time: event.time(), cancelled: event.cancelled(), }, ); @@ -1311,7 +1311,7 @@ impl State { self, &GesturePinchBeginEvent { serial, - time: event.time_msec(), + time: event.time(), fingers: event.fingers(), }, ); @@ -1331,7 +1331,7 @@ impl State { pointer.gesture_pinch_update( self, &GesturePinchUpdateEvent { - time: event.time_msec(), + time: event.time(), delta: event.delta(), scale: event.scale(), rotation: event.rotation(), @@ -1355,7 +1355,7 @@ impl State { self, &GesturePinchEndEvent { serial, - time: event.time_msec(), + time: event.time(), cancelled: event.cancelled(), }, ); @@ -1377,7 +1377,7 @@ impl State { self, &GestureHoldBeginEvent { serial, - time: event.time_msec(), + time: event.time(), fingers: event.fingers(), }, ); @@ -1399,7 +1399,7 @@ impl State { self, &GestureHoldEndEvent { serial, - time: event.time_msec(), + time: event.time(), cancelled: event.cancelled(), }, ); @@ -1456,7 +1456,7 @@ impl State { slot: event.slot(), location: position.as_logical(), serial, - time: event.time_msec(), + time: event.time(), }, ); } @@ -1505,7 +1505,7 @@ impl State { &TouchMotionEvent { slot: event.slot(), location: position.as_logical(), - time: event.time_msec(), + time: event.time(), }, ); } @@ -1531,7 +1531,7 @@ impl State { self, &UpEvent { slot: event.slot(), - time: event.time_msec(), + time: event.time(), serial, }, ); @@ -1596,7 +1596,7 @@ impl State { &MotionEvent { location: position.as_logical(), serial: SERIAL_COUNTER.next_serial(), - time: self.common.clock.now().as_millis(), + time: InputTime::now(), }, ); @@ -1627,11 +1627,11 @@ impl State { &tool::MotionEvent { location: position.as_logical(), serial: SERIAL_COUNTER.next_serial(), - time: event.time_msec(), + time: event.time(), }, ); - tool.frame(self, event.time_msec()); + tool.frame(self, event.time()); } } } @@ -1665,7 +1665,7 @@ impl State { &MotionEvent { location: position.as_logical(), serial: SERIAL_COUNTER.next_serial(), - time: self.common.clock.now().as_millis(), + time: InputTime::now(), }, ); @@ -1706,7 +1706,7 @@ impl State { location: position.as_logical(), axis: Some(frame), serial: SERIAL_COUNTER.next_serial(), - time: event.time_msec(), + time: event.time(), }, ) } @@ -1714,12 +1714,12 @@ impl State { self, &tool::ProximityOutEvent { serial, - time: event.time_msec(), + time: event.time(), }, ), } - tool.frame(self, event.time_msec()); + tool.frame(self, event.time()); } } } @@ -1742,7 +1742,7 @@ impl State { self, &tool::DownEvent { serial, - time: event.time_msec(), + time: event.time(), }, ); } @@ -1751,13 +1751,13 @@ impl State { self, &tool::UpEvent { serial, - time: event.time_msec(), + time: event.time(), }, ); } } - tool.frame(self, event.time_msec()); + tool.frame(self, event.time()); } } } @@ -1779,11 +1779,11 @@ impl State { button: event.button(), state: event.button_state(), serial: SERIAL_COUNTER.next_serial(), - time: event.time_msec(), + time: event.time(), }, ); - tool.frame(self, event.time_msec()); + tool.frame(self, event.time()); } } } @@ -1886,7 +1886,7 @@ impl State { let Some(pointer) = seat.get_pointer() else { return; }; - let time = self.common.clock.now().as_millis(); + let time = InputTime::now(); for button in buttons { let serial = SERIAL_COUNTER.next_serial(); pointer.button( @@ -1948,7 +1948,7 @@ impl State { modifiers: &ModifiersState, handle: KeysymHandle<'_>, serial: Serial, - time: u32, + time: InputTime, keycode: Keycode, key_state: KeyState, previous_modifiers: ModifiersState, @@ -2008,7 +2008,7 @@ impl State { return; }; let serial = SERIAL_COUNTER.next_serial(); - let time = self.common.clock.now().as_millis(); + let time = InputTime::now(); let previous_modifiers = keyboard.modifier_state(); let result = keyboard .input_from_source( @@ -2157,7 +2157,7 @@ impl State { serial: Serial, keycode: Keycode, key_state: KeyState, - time: u32, + time: InputTime, ) -> FilterResult> { // Pre-compute for layout-agnostic shortcut matching let raw_syms = handle.raw_syms(); @@ -2322,7 +2322,9 @@ impl State { &backend_id_clone, &seat_clone, serial, - time.overflowing_add(duration as u32).0, + InputTime::from_millis( + time.millis().overflowing_add(duration as u32).0, + ), key_pattern_clone.clone(), None, ); @@ -2374,7 +2376,7 @@ impl State { self.common.event_loop_handle.insert_idle(move |state| { if let Some(keyboard) = seat.get_keyboard() { let serial = SERIAL_COUNTER.next_serial(); - let time = state.common.clock.now().as_millis(); + let time = InputTime::now(); keyboard.input( state, key_code, @@ -2900,6 +2902,7 @@ impl State { surface: &WlSurface, pointer: &PointerHandle, mut location: Point, + constraint: Option<&PointerConstraint>, ) { let Some(client) = surface.client() else { return; @@ -2924,15 +2927,13 @@ impl State { return false; } - with_pointer_constraint(surface, pointer, |constraint| { - if let Some(constraint) = constraint - && let Some(region) = constraint.region() - { - let point_in_surface = (p - surface_offset.to_f64()).to_i32_floor(); - return region.contains(point_in_surface); - } - true - }) + if let Some(constraint) = constraint + && let Some(region) = constraint.region() + { + let point_in_surface = (p - surface_offset.to_f64()).to_i32_floor(); + return region.contains(point_in_surface); + } + true }; let workspace_origin = output.geometry().loc.to_f64(); @@ -2956,14 +2957,14 @@ impl State { let serial = SERIAL_COUNTER.next_serial(); let under = State::surface_under(point, &output, &self.common.shell.write()) .map(|(target, pos)| (target, pos.as_logical())); - let time = self.common.clock.now(); + let time = InputTime::now(); pointer.relative_motion( self, under.clone(), &RelativeMotionEvent { delta: (0., 0.).into(), delta_unaccel: (0., 0.).into(), - utime: time.as_micros(), + time, }, ); pointer.motion( @@ -2972,7 +2973,7 @@ impl State { &MotionEvent { location: point.as_logical(), serial, - time: time.as_millis(), + time, }, ); pointer.frame(self); diff --git a/src/shell/element/mod.rs b/src/shell/element/mod.rs index 14736719..d4743b7f 100644 --- a/src/shell/element/mod.rs +++ b/src/shell/element/mod.rs @@ -12,7 +12,7 @@ use id_tree::NodeId; use smithay::{ backend::{ drm::DrmNode, - input::KeyState, + input::{InputTime, KeyState}, renderer::{ element::{ Element, Kind, RenderElement, UnderlyingStorage, @@ -1012,7 +1012,7 @@ impl KeyboardTarget for CosmicMapped { key: KeysymHandle<'_>, state: KeyState, serial: Serial, - time: u32, + time: InputTime, ) { match &self.element { CosmicMappedInternal::Stack(s) => { diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index d466f4e0..2fed0977 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -38,7 +38,7 @@ use shortcuts::action::{Direction, FocusDirection}; use smithay::{ backend::{ drm::DrmNode, - input::KeyState, + input::{InputTime, KeyState}, renderer::{ ImportAll, ImportMem, Renderer, element::{Element, Id as RendererId, Kind, RenderElement, UnderlyingStorage}, @@ -1557,7 +1557,7 @@ impl KeyboardTarget for CosmicStack { key: KeysymHandle<'_>, state: KeyState, serial: Serial, - time: u32, + time: InputTime, ) { let active = self.keyboard_leave_if_previous(seat, data, serial); self.0.with_program(|p| { @@ -1726,7 +1726,7 @@ impl PointerTarget for CosmicStack { } } - fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: u32) { + fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: InputTime) { self.0.with_program(|p| { let mut cursor_state = seat .user_data() diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index 99bb2f78..a7fd922d 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -21,6 +21,7 @@ use std::{ use smithay::{ backend::{ drm::DrmNode, + input::InputTime, renderer::{ ImportAll, Renderer, buffer_has_alpha, element::{Kind, RenderElementStates, surface::KindEvaluation}, @@ -1084,7 +1085,7 @@ impl KeyboardTarget for CosmicSurface { key: KeysymHandle<'_>, state: smithay::backend::input::KeyState, serial: smithay::utils::Serial, - time: u32, + time: InputTime, ) { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => { diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 86c2ce7f..53b2caee 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -21,7 +21,7 @@ use cosmic_comp_config::AppearanceConfig; use smithay::{ backend::{ drm::DrmNode, - input::KeyState, + input::{InputTime, KeyState}, renderer::{ ImportAll, ImportMem, Renderer, element::{Element, Id as RendererId, Kind, RenderElement, UnderlyingStorage}, @@ -985,7 +985,7 @@ impl KeyboardTarget for CosmicWindow { key: KeysymHandle<'_>, state: KeyState, serial: Serial, - time: u32, + time: InputTime, ) { self.0 .with_program(|p| KeyboardTarget::key(&p.window, seat, data, key, state, serial, time)) @@ -1124,7 +1124,7 @@ impl PointerTarget for CosmicWindow { } } - fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: u32) { + fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: InputTime) { self.0.with_program(|p| { let cursor_state = seat.user_data().get::().unwrap(); cursor_state.lock().unwrap().unset_shape(); diff --git a/src/shell/focus/mod.rs b/src/shell/focus/mod.rs index cab37a85..f631372e 100644 --- a/src/shell/focus/mod.rs +++ b/src/shell/focus/mod.rs @@ -6,6 +6,7 @@ use crate::{ }; use indexmap::IndexSet; use smithay::{ + backend::input::InputTime, desktop::{PopupUngrabStrategy, layer_map_for_output}, input::{Seat, pointer::MotionEvent}, output::Output, @@ -419,7 +420,7 @@ fn update_focus_state( &MotionEvent { location: new_pos.as_logical(), serial: SERIAL_COUNTER.next_serial(), - time: 0, + time: InputTime::now(), }, ); } @@ -768,7 +769,7 @@ fn update_pointer_focus(state: &mut State, seat: &Seat) { &MotionEvent { location: pointer.current_location(), serial: SERIAL_COUNTER.next_serial(), - time: state.common.clock.now().as_millis(), + time: InputTime::now(), }, ); } diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index 80b1a34f..56af0ccc 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -16,7 +16,7 @@ use crate::{ }; use id_tree::NodeId; use smithay::{ - backend::input::KeyState, + backend::input::{InputTime, KeyState}, desktop::{LayerSurface, PopupKind, WindowSurface, WindowSurfaceType, space::SpaceElement}, input::{ Seat, @@ -272,9 +272,10 @@ impl PointerFocusTarget { None }; - let cursor_hotspot = if let Some(CursorGeometry { hotspot, .. }) = - seat.cursor_geometry((0.0, 0.0), Duration::from_millis(event.time as u64).into()) - { + let cursor_hotspot = if let Some(CursorGeometry { hotspot, .. }) = seat.cursor_geometry( + (0.0, 0.0), + Duration::from_millis(event.time.millis() as u64).into(), + ) { hotspot } else { Point::from((0, 0)) @@ -417,7 +418,7 @@ impl PointerTarget for PointerFocusTarget { fn frame(&self, seat: &Seat, data: &mut State) { self.inner_pointer_target().frame(seat, data); } - fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: u32) { + fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: InputTime) { let toplevel = self.toplevel(&data.common.shell.read()); if let Some(element) = toplevel { for session in element.cursor_sessions() { @@ -593,7 +594,7 @@ impl DndFocus for PointerFocusTarget { offer: Option<&mut CosmicOfferData>, seat: &Seat, location: Point, - time: u32, + time: InputTime, ) { match self { PointerFocusTarget::WlSurface { surface, .. } => { @@ -695,7 +696,7 @@ impl KeyboardTarget for KeyboardFocusTarget { key: KeysymHandle<'_>, state: KeyState, serial: Serial, - time: u32, + time: InputTime, ) { if let Some(inner) = self.inner_keyboard_target() { inner.key(seat, data, key, state, serial, time); diff --git a/src/shell/grabs/menu/default.rs b/src/shell/grabs/menu/default.rs index c7418b6d..81673efd 100644 --- a/src/shell/grabs/menu/default.rs +++ b/src/shell/grabs/menu/default.rs @@ -1,7 +1,8 @@ use cosmic_settings_config::shortcuts::Action; use smithay::{ - input::pointer::MotionEvent, reexports::wayland_server::protocol::wl_surface::WlSurface, - utils::SERIAL_COUNTER, wayland::seat::WaylandFocus, + backend::input::InputTime, input::pointer::MotionEvent, + reexports::wayland_server::protocol::wl_surface::WlSurface, utils::SERIAL_COUNTER, + wayland::seat::WaylandFocus, }; use crate::{ @@ -398,7 +399,7 @@ pub fn window_items( &MotionEvent { location: loc.as_logical().to_f64(), serial, - time: state.common.clock.now().as_millis(), + time: InputTime::now(), }, ); pointer.frame(state); @@ -433,7 +434,7 @@ pub fn window_items( &MotionEvent { location: loc.as_logical().to_f64(), serial, - time: state.common.clock.now().as_millis(), + time: InputTime::now(), }, ); pointer.frame(state); @@ -468,7 +469,7 @@ pub fn window_items( &MotionEvent { location: loc.as_logical().to_f64(), serial, - time: state.common.clock.now().as_millis(), + time: InputTime::now(), }, ); pointer.frame(state); @@ -503,7 +504,7 @@ pub fn window_items( &MotionEvent { location: loc.as_logical().to_f64(), serial, - time: state.common.clock.now().as_millis(), + time: InputTime::now(), }, ); pointer.frame(state); diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index d8714830..05923bc7 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -20,7 +20,7 @@ use smallvec::SmallVec; use smithay::{ backend::{ drm::DrmNode, - input::ButtonState, + input::{ButtonState, InputTime}, renderer::{ ImportAll, ImportMem, element::{RenderElement, utils::RescaleRenderElement}, @@ -956,7 +956,7 @@ impl Drop for MoveGrab { &MotionEvent { location: pointer.current_location(), serial, - time: state.common.clock.now().as_millis(), + time: InputTime::now(), }, ); } diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 9b135119..91873793 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -11,7 +11,7 @@ use crate::{ }; use id_tree::{NodeId, Tree}; use smithay::{ - backend::input::ButtonState, + backend::input::{ButtonState, InputTime}, input::{ Seat, pointer::{ @@ -65,7 +65,7 @@ impl PointerTarget for ResizeForkTarget { seat: &Seat, _data: &mut State, _serial: smithay::utils::Serial, - _time: u32, + _time: InputTime, ) { let user_data = seat.user_data(); let cursor_state = user_data.get::().unwrap(); diff --git a/src/shell/layout/tiling/grabs/swap.rs b/src/shell/layout/tiling/grabs/swap.rs index afe93cf0..9ac531d3 100644 --- a/src/shell/layout/tiling/grabs/swap.rs +++ b/src/shell/layout/tiling/grabs/swap.rs @@ -1,6 +1,6 @@ use cosmic_settings_config::shortcuts; use smithay::{ - backend::input::{KeyState, Keycode}, + backend::input::{InputTime, KeyState, Keycode}, input::{ Seat, SeatHandler, keyboard::{ @@ -38,7 +38,7 @@ impl KeyboardGrab for SwapWindowGrab { state: KeyState, modifiers: Option, serial: Serial, - time: u32, + time: InputTime, ) { if !matches!(&data.common.shell.read().overview_mode.active_trigger(), Some(Trigger::KeyboardSwap(_, d)) if d == &self.desc) { diff --git a/src/shell/zoom.rs b/src/shell/zoom.rs index 0c0e9340..cfe84f06 100644 --- a/src/shell/zoom.rs +++ b/src/shell/zoom.rs @@ -11,7 +11,7 @@ use cosmic_comp_config::{ZoomConfig, ZoomMovement}; use cosmic_config::ConfigSet; use keyframe::{ease, functions::Linear}; use smithay::{ - backend::renderer::ImportMem, + backend::{input::InputTime, renderer::ImportMem}, desktop::space::SpaceElement, input::{ Seat, @@ -1023,7 +1023,7 @@ impl PointerTarget for ZoomFocusTarget { } } - fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: u32) { + fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: InputTime) { match self { ZoomFocusTarget::Main(elem) => PointerTarget::leave(elem, seat, data, serial, time), ZoomFocusTarget::Menu(elem) => PointerTarget::leave(elem, seat, data, serial, time), diff --git a/src/utils/iced/mod.rs b/src/utils/iced/mod.rs index 2bfe888d..94b27ea7 100644 --- a/src/utils/iced/mod.rs +++ b/src/utils/iced/mod.rs @@ -31,7 +31,7 @@ use ordered_float::OrderedFloat; use smithay::{ backend::{ allocator::Fourcc, - input::{ButtonState, KeyState}, + input::{ButtonState, InputTime, KeyState}, renderer::{ ImportMem, element::{ @@ -581,7 +581,7 @@ impl PointerTarget for IcedEle _seat: &Seat, _data: &mut crate::state::State, _serial: Serial, - _time: u32, + _time: InputTime, ) { let mut internal = self.0.lock().unwrap(); internal @@ -784,7 +784,7 @@ impl KeyboardTarget for IcedEl _key: KeysymHandle<'_>, _state: KeyState, _serial: Serial, - _time: u32, + _time: InputTime, ) { // TODO convert keys } diff --git a/src/wayland/handlers/compositor.rs b/src/wayland/handlers/compositor.rs index 12bc2e56..ed40448b 100644 --- a/src/wayland/handlers/compositor.rs +++ b/src/wayland/handlers/compositor.rs @@ -3,9 +3,12 @@ use crate::{shell::grabs::SeatMoveGrabState, state::ClientState, utils::prelude::*}; use calloop::Interest; use smithay::{ - backend::renderer::{ - element::{Kind, surface::KindEvaluation}, - utils::{on_commit_buffer_handler, with_renderer_surface_state}, + backend::{ + input::InputTime, + renderer::{ + element::{Kind, surface::KindEvaluation}, + utils::{on_commit_buffer_handler, with_renderer_surface_state}, + }, }, desktop::{LayerSurface, PopupKind, WindowSurfaceType, layer_map_for_output}, reexports::wayland_server::{Client, Resource, protocol::wl_surface::WlSurface}, @@ -325,9 +328,11 @@ impl CompositorHandler for State { } } else { std::mem::drop(shell); - seat.get_pointer() - .unwrap() - .unset_grab(self, SERIAL_COUNTER.next_serial(), 0); + seat.get_pointer().unwrap().unset_grab( + self, + SERIAL_COUNTER.next_serial(), + InputTime::now(), + ); return; } } diff --git a/src/wayland/handlers/pointer_constraints.rs b/src/wayland/handlers/pointer_constraints.rs index 9ce5f63a..e024bb40 100644 --- a/src/wayland/handlers/pointer_constraints.rs +++ b/src/wayland/handlers/pointer_constraints.rs @@ -5,7 +5,10 @@ use smithay::{ input::pointer::PointerHandle, reexports::wayland_server::protocol::wl_surface::WlSurface, utils::{Logical, Point}, - wayland::{pointer_constraints::PointerConstraintsHandler, seat::WaylandFocus}, + wayland::{ + pointer_constraints::{ConstraintRemove, PointerConstraintsHandler}, + seat::WaylandFocus, + }, }; pub use smithay::wayland::pointer_constraints::{PointerConstraintRef, with_pointer_constraint}; @@ -76,23 +79,38 @@ impl PointerConstraintsHandler for State { } } - fn remove_constraint(&mut self, surface: &WlSurface, pointer: &PointerHandle) { - if with_pointer_constraint(surface, pointer, |constraint| constraint.is_none()) { - let seat = self - .common - .shell - .read() - .seats - .iter() - .find(|s| s.get_pointer().as_ref() == Some(pointer)) - .cloned(); + fn remove_constraint( + &mut self, + surface: &WlSurface, + pointer: &PointerHandle, + constraint_remove: ConstraintRemove, + ) { + match constraint_remove { + ConstraintRemove::PointerLeave(_) => { + // If the constraint was broken by the pointer forcibly leaving the surface, then it doesn't + // make much sense to warp it. + return; + } + ConstraintRemove::Destroyed(constraint) => { + let Some(seat) = self + .common + .shell + .read() + .seats + .iter() + .find(|s| s.get_pointer().as_ref() == Some(pointer)) + .cloned() + else { + return; + }; + let Some((hint_surface, hint_location)) = seat.pointer_constraint_hint() else { + return; + }; - if let Some(seat) = seat - && let Some((hint_surface, hint_location)) = seat.pointer_constraint_hint() - && hint_surface == *surface - { - self.apply_cursor_hint(surface, pointer, hint_location); - seat.set_pointer_constraint_hint(None); + if hint_surface == *surface { + self.apply_cursor_hint(surface, pointer, hint_location, Some(&constraint)); + seat.set_pointer_constraint_hint(None); + } } } } diff --git a/src/wayland/handlers/pointer_warp.rs b/src/wayland/handlers/pointer_warp.rs index 971ab583..634817cf 100644 --- a/src/wayland/handlers/pointer_warp.rs +++ b/src/wayland/handlers/pointer_warp.rs @@ -38,7 +38,7 @@ impl PointerWarpHandler for State { drop(shell); if let Some(pointer_handle) = pointer_handle { - self.apply_cursor_hint(&surface, &pointer_handle, pos); + self.apply_cursor_hint(&surface, &pointer_handle, pos, None); } } } diff --git a/src/wayland/handlers/toplevel_management.rs b/src/wayland/handlers/toplevel_management.rs index 3da39952..b1616bca 100644 --- a/src/wayland/handlers/toplevel_management.rs +++ b/src/wayland/handlers/toplevel_management.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only use smithay::{ + backend::input::InputTime, desktop::{WindowSurfaceType, layer_map_for_output}, input::{Seat, pointer::MotionEvent}, output::Output, @@ -124,7 +125,7 @@ impl ToplevelManagementHandler for State { &MotionEvent { location: new_pos.to_f64().as_logical(), serial, - time: self.common.clock.now().as_millis(), + time: InputTime::now(), }, ); ptr.frame(self); diff --git a/src/xwayland.rs b/src/xwayland.rs index da3fb36b..68fb95b3 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -20,7 +20,7 @@ use smithay::{ backend::{ allocator::Fourcc, drm::DrmNode, - input::{ButtonState, KeyState, Keycode}, + input::{ButtonState, InputTime, KeyState, Keycode}, renderer::{ Bind, Frame, Offscreen, Renderer, element::{ @@ -396,7 +396,7 @@ impl Common { state: KeyState, modifiers: ModifiersState, serial: Serial, - time: u32, + time: InputTime, ) { let config = self.config.cosmic_conf.xwayland_eavesdropping.keyboard; if config == EavesdroppingKeyboardMode::None { @@ -458,7 +458,7 @@ impl Common { tracing::trace!("Forwaring key {} {:?} to xwayland", code.raw() - 8, state); for wl_keyboard in keyboard.client_keyboards(&xstate.client) { - wl_keyboard.key(serial.into(), time, code.raw() - 8, state.into()); + wl_keyboard.key(serial.into(), time.millis(), code.raw() - 8, state.into()); if xstate.last_modifier_state != Some(modifiers) { xstate.last_modifier_state = Some(modifiers); wl_keyboard.modifiers( @@ -478,7 +478,7 @@ impl Common { button: u32, state: ButtonState, serial: Serial, - time: u32, + time: InputTime, ) { if !self.config.cosmic_conf.xwayland_eavesdropping.pointer { return; @@ -518,7 +518,7 @@ impl Common { tracing::trace!("Forwaring ptr button {} {:?} to Xwayland", button, state); for wl_pointer in pointer.client_pointers(&xstate.client) { - wl_pointer.button(serial.into(), time, button, state.into()); + wl_pointer.button(serial.into(), time.millis(), button, state.into()); } } From 158e2b7f91e3e6b3a569a7ea26251182a1e40627 Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Tue, 25 Aug 2026 19:21:49 +0200 Subject: [PATCH 02/37] i18n: translation updates from weblate Co-authored-by: Kurt Harren Catindig --- resources/i18n/fil/cosmic_comp.ftl | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 resources/i18n/fil/cosmic_comp.ftl diff --git a/resources/i18n/fil/cosmic_comp.ftl b/resources/i18n/fil/cosmic_comp.ftl new file mode 100644 index 00000000..e69de29b From 94178034ddc3386bf256fcc952f72ddb55997d49 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Mon, 27 Jul 2026 20:53:57 +0200 Subject: [PATCH 03/37] feat: allow XWayland window to start minimized --- src/shell/mod.rs | 13 +++++++++++-- src/wayland/handlers/xdg_shell/mod.rs | 1 + src/xwayland.rs | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 009c98dc..3fa863d3 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -254,6 +254,7 @@ pub struct PendingWindow { pub surface: CosmicSurface, pub seat: Seat, pub fullscreen: Option, + pub minimized: bool, pub maximized: bool, pub sticky: bool, } @@ -2856,6 +2857,7 @@ impl Shell { surface: window, seat, fullscreen: output, + minimized: should_be_minimized, maximized: should_be_maximized, sticky: mut should_be_sticky, } = self.pending_windows.remove(pos); @@ -2939,6 +2941,7 @@ impl Shell { if let Some(FocusTarget::Window(focused)) = maybe_focused && let Some(stack) = focused.stack_ref() && !is_dialog + && !should_be_minimized && !should_be_maximized && !(workspace.is_tiled(&focused.active_window()) && floating_exception) { @@ -2988,8 +2991,13 @@ impl Shell { self.maximize_request(&mapped, &seat, false, loop_handle); } - let new_target = if (workspace_output == seat.active_output() - && active_handle == workspace_handle) + if should_be_minimized { + self.minimize_request(&window); + } + + let new_target = if should_be_minimized { + None + } else if (workspace_output == seat.active_output() && active_handle == workspace_handle) || should_be_sticky { // TODO: enforce focus stealing prevention by also checking the same rules as for the else case. @@ -3113,6 +3121,7 @@ impl Shell { surface, seat: seat.clone(), fullscreen: None, + minimized: false, maximized: false, sticky: false, }); diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index b4f16c4c..c9fb926f 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -50,6 +50,7 @@ impl XdgShellHandler for State { surface, seat, fullscreen: None, + minimized: false, maximized: false, sticky: false, }) diff --git a/src/xwayland.rs b/src/xwayland.rs index 68fb95b3..78193d13 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -808,6 +808,7 @@ impl XwmHandler for State { ); } let fullscreen = window.is_fullscreen().then(|| seat.active_output()); + let minimized = window.is_hidden(); let maximized = window.is_maximized(); if let Some(pending) = shell .pending_windows @@ -816,6 +817,7 @@ impl XwmHandler for State { { pending.seat = seat; pending.fullscreen = fullscreen; + pending.minimized = minimized; pending.maximized = maximized; } else { let surface = CosmicSurface::from(window); @@ -823,6 +825,7 @@ impl XwmHandler for State { surface, seat, fullscreen, + minimized, maximized, sticky: false, }) From 9fe22c86b600ca13ac2d31fa4d5eb924b3443227 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Thu, 27 Aug 2026 15:24:25 -0600 Subject: [PATCH 04/37] fix(corner-radius): use layer surface size for radius validation --- src/wayland/protocols/corner_radius.rs | 34 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/wayland/protocols/corner_radius.rs b/src/wayland/protocols/corner_radius.rs index 51dc1153..479f890a 100644 --- a/src/wayland/protocols/corner_radius.rs +++ b/src/wayland/protocols/corner_radius.rs @@ -5,16 +5,15 @@ use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v use cosmic_protocols::corner_radius::v1::server::{ cosmic_corner_radius_manager_v1, cosmic_corner_radius_toplevel_v1, }; -use smithay::desktop::utils::bbox_from_surface_tree; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_popup::XdgPopup; use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::server::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1; use smithay::reexports::wayland_server::New; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; -use smithay::utils::{HookId, Logical, Point, Rectangle}; +use smithay::utils::{HookId, Logical, Rectangle}; use smithay::wayland::compositor::Cacheable; use smithay::wayland::compositor::add_pre_commit_hook; use smithay::wayland::compositor::with_states; -use smithay::wayland::shell::wlr_layer::WlrLayerShellHandler; +use smithay::wayland::shell::wlr_layer::{LayerSurfaceAttributes, WlrLayerShellHandler}; use smithay::wayland::shell::xdg::{SurfaceCachedState, XdgShellSurfaceUserData}; use smithay::{ reexports::{ @@ -655,7 +654,6 @@ fn pad_rect( } fn layer_radius_hook(_state: &mut D, _dh: &DisplayHandle, surface: &WlSurface) { - let bbox = bbox_from_surface_tree(surface, Point::default()); with_states(surface, |surface_data| { let corners = *surface_data .cached_state @@ -665,8 +663,34 @@ fn layer_radius_hook(_state: &mut D, _dh: &DisplayHandle, surface: & .cached_state .get::() .pending(); + + // The radius and padding is relative to the size of `zwlr_layer_surface_v1` (according to + // the protocol). That is the configure the client acked. + // + // `last_acked` is the becomes current as part of this commit, + // so it is staged consistently with the pending radius/padding above. + // + // Until the client acks a configure there is no defined size, and nothing to check. + let Some(size) = surface_data + .data_map + .get::>() + .and_then(|attrs| { + attrs + .lock() + .unwrap() + .last_acked + .as_ref() + .and_then(|configure| configure.state.size) + }) + else { + return; + }; + let empty = Padding::default(); - let Some(padded_box) = pad_rect(bbox, padding.0.as_ref().unwrap_or(&empty)) else { + let Some(padded_box) = pad_rect( + Rectangle::from_size(size), + padding.0.as_ref().unwrap_or(&empty), + ) else { if let Some(hook) = surface_data.data_map.get::() { let hook_ref = hook.lock().unwrap(); if let Some((_, obj)) = hook_ref.as_ref() From b407ed560a4ac179d0289d231095ff20739fb919 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 14 Aug 2026 18:25:41 +0200 Subject: [PATCH 05/37] wayland/decoration: Make default decoration mode configurable --- cosmic-comp-config/src/lib.rs | 9 +++ src/config/mod.rs | 11 ++- src/wayland/handlers/decoration.rs | 108 +++++++++++++++++++++++++++-- 3 files changed, 120 insertions(+), 8 deletions(-) diff --git a/cosmic-comp-config/src/lib.rs b/cosmic-comp-config/src/lib.rs index 853ba447..510927f9 100644 --- a/cosmic-comp-config/src/lib.rs +++ b/cosmic-comp-config/src/lib.rs @@ -66,6 +66,13 @@ impl Default for AppearanceConfig { } } +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +pub enum DecorationPreference { + #[default] + ClientSide, + ServerSide, +} + #[derive(Clone, Debug, PartialEq, CosmicConfigEntry)] #[version = 1] pub struct CosmicCompConfig { @@ -104,6 +111,7 @@ pub struct CosmicCompConfig { /// Briefly magnify the cursor when the pointer is shaken, to help locate it pub cursor_shake_to_find: bool, pub activation_policy: ActivationPolicy, + pub decoration_preference: DecorationPreference, } impl Default for CosmicCompConfig { @@ -143,6 +151,7 @@ impl Default for CosmicCompConfig { cursor_hide_timeout: None, cursor_shake_to_find: true, activation_policy: ActivationPolicy::default(), + decoration_preference: DecorationPreference::default(), } } } diff --git a/src/config/mod.rs b/src/config/mod.rs index abef562b..9db9a9bb 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -49,8 +49,8 @@ mod types; use cosmic::config::CosmicTk; pub use cosmic_comp_config::EdidProduct; use cosmic_comp_config::{ - ActivationPolicy, AppearanceConfig, CosmicCompConfig, KeyboardConfig, TileBehavior, XkbConfig, - XwaylandDescaling, XwaylandEavesdropping, ZoomConfig, + ActivationPolicy, AppearanceConfig, CosmicCompConfig, DecorationPreference, KeyboardConfig, + TileBehavior, XkbConfig, XwaylandDescaling, XwaylandEavesdropping, ZoomConfig, input::{DeviceState as InputDeviceState, InputConfig, TouchpadOverride}, output::comp::{ OutputConfig, OutputInfo, OutputState, OutputsConfig, TransformDef, load_outputs, @@ -1000,6 +1000,13 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut state.common.config.cosmic_conf.activation_policy = new; } } + "decoration_preference" => { + let new = get_config::(&config, "decoration_preference"); + if new != state.common.config.cosmic_conf.decoration_preference { + state.common.config.cosmic_conf.decoration_preference = new; + state.update_decorations(); + } + } _ => {} } } diff --git a/src/wayland/handlers/decoration.rs b/src/wayland/handlers/decoration.rs index 90ec5855..ae58d338 100644 --- a/src/wayland/handlers/decoration.rs +++ b/src/wayland/handlers/decoration.rs @@ -1,5 +1,6 @@ use std::{cell::RefCell, sync::Mutex}; +use cosmic_comp_config::DecorationPreference; use smithay::{ desktop::Window, reexports::{ @@ -20,7 +21,7 @@ use smithay::{ }; use wayland_backend::protocol::WEnum; -use crate::state::State; +use crate::{shell::CosmicMapped, state::State}; pub struct PreferredDecorationMode(RefCell>); @@ -29,7 +30,7 @@ impl PreferredDecorationMode { window .user_data() .get::() - .is_none() + .is_none_or(|mode| mode.0.borrow().is_none()) } pub fn mode(window: &Window) -> Option { @@ -53,6 +54,73 @@ impl PreferredDecorationMode { } } +impl State { + pub fn default_decoration(&self) -> DecorationPreference { + self.common.config.cosmic_conf.decoration_preference + } + + pub fn update_decorations(&self) { + let shell = self.common.shell.read(); + + let update = |mapped: &CosmicMapped| { + let mode = if mapped.is_stack() { + XdgMode::ServerSide + } else { + XdgMode::from_preference(self.default_decoration()) + }; + for (window, _) in mapped.windows() { + if PreferredDecorationMode::is_unset(&window.0) { + if let Some(toplevel) = window.0.toplevel() { + if toplevel.with_committed_state(|state| { + state.is_some_and(|state| state.decoration_mode.is_some()) + }) { + toplevel.with_pending_state(|state| { + state.decoration_mode = Some(mode); + }); + toplevel.send_configure(); + } + } + } + } + }; + + for set in shell.workspaces.sets.values() { + set.sticky_layer.mapped().for_each(update); + } + + for space in shell.workspaces.spaces() { + space.mapped().for_each(update); + space + .minimized_windows + .iter() + .filter_map(|m| m.mapped()) + .for_each(update); + } + } +} + +trait FromDecorationPreference { + fn from_preference(preference: DecorationPreference) -> Self; +} + +impl FromDecorationPreference for XdgMode { + fn from_preference(preference: DecorationPreference) -> Self { + match preference { + DecorationPreference::ClientSide => XdgMode::ClientSide, + DecorationPreference::ServerSide => XdgMode::ServerSide, + } + } +} + +impl FromDecorationPreference for KdeMode { + fn from_preference(preference: DecorationPreference) -> Self { + match preference { + DecorationPreference::ClientSide => KdeMode::Client, + DecorationPreference::ServerSide => KdeMode::Server, + } + } +} + pub type KdeDecorationData = Mutex; #[derive(Debug, Default)] pub struct KdeDecorationSurfaceState { @@ -67,7 +135,7 @@ impl XdgDecorationHandler for State { let mode = if mapped.is_stack() { XdgMode::ServerSide } else { - XdgMode::ClientSide + XdgMode::from_preference(self.default_decoration()) }; if let Some((window, _)) = mapped @@ -80,6 +148,10 @@ impl XdgDecorationHandler for State { }); toplevel.send_configure(); } + } else { + toplevel.with_pending_state(|state| { + state.decoration_mode = Some(XdgMode::from_preference(self.default_decoration())) + }) } } @@ -99,6 +171,13 @@ impl XdgDecorationHandler for State { } } else { toplevel.with_pending_state(|state| state.decoration_mode = Some(mode)); + if let Some(pending) = shell + .pending_windows + .iter() + .find(|pending| pending.surface.0.toplevel().is_some_and(|t| t == &toplevel)) + { + PreferredDecorationMode::update(&pending.surface.0, Some(mode)); + } } } @@ -110,11 +189,28 @@ impl XdgDecorationHandler for State { .find(|(window, _)| window.wl_surface().as_deref() == Some(toplevel.wl_surface())) && let Some(toplevel) = window.0.toplevel() { + let mode = if mapped.is_stack() { + XdgMode::ServerSide + } else { + XdgMode::from_preference(self.default_decoration()) + }; + PreferredDecorationMode::update(&window.0, None); toplevel.with_pending_state(|state| { - state.decoration_mode = None; + state.decoration_mode = Some(mode); }); toplevel.send_configure(); + } else { + toplevel.with_pending_state(|state| { + state.decoration_mode = Some(XdgMode::from_preference(self.default_decoration())) + }); + if let Some(pending) = shell + .pending_windows + .iter() + .find(|pending| pending.surface.0.toplevel().is_some_and(|t| t == &toplevel)) + { + PreferredDecorationMode::update(&pending.surface.0, None); + } } } } @@ -129,10 +225,10 @@ impl KdeDecorationHandler for State { if mapped.is_stack() { KdeMode::Server } else { - KdeMode::Client + KdeMode::from_preference(self.default_decoration()) } } else { - KdeMode::Client + KdeMode::from_preference(self.default_decoration()) }; with_states(surface, |states| { From a7d31a75d293e98fe75151c167451d5da50397a8 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 24 Jul 2026 14:14:15 +0200 Subject: [PATCH 06/37] backend/kms: Check all connectors for primary gpu --- src/backend/kms/mod.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 6da04aac..36c6407c 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -32,7 +32,11 @@ use smithay::{ calloop::{Dispatcher, EventLoop, LoopHandle}, drm::{ Device as _, - control::{Device as _, connector::Interface, crtc}, + control::{ + Device as _, + connector::{Interface, State as ConnectorState}, + crtc, + }, }, input::{self, Libinput}, wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags, @@ -250,13 +254,18 @@ fn determine_primary_gpu( // try to find builtin display for dev in drm_devices.values() { - if dev.inner.surfaces.values().any(|s| { - if let Ok(conn_info) = dev.drm.device().get_connector(s.connector, false) { - let i = conn_info.interface(); - i == Interface::EmbeddedDisplayPort || i == Interface::LVDS || i == Interface::DSI - } else { - false - } + let drm = dev.drm.device(); + let res_handles = drm.resource_handles()?; + let connectors = res_handles.connectors(); + if connectors.iter().any(|conn| { + let Ok(conn_info) = drm.get_connector(*conn, false) else { + return false; + }; + let i = conn_info.interface(); + conn_info.state() == ConnectorState::Connected + && (i == Interface::EmbeddedDisplayPort + || i == Interface::LVDS + || i == Interface::DSI) }) { return Ok(Some(dev.inner.render_node)); } From e93ec67a117126ce445abf1588a7d2f8180bf3b0 Mon Sep 17 00:00:00 2001 From: Shehriyar Qureshi Date: Tue, 1 Sep 2026 21:05:18 +0500 Subject: [PATCH 07/37] fix(kms): typo in log message --- src/backend/kms/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/kms/device.rs b/src/backend/kms/device.rs index 418a16f3..c58450bc 100644 --- a/src/backend/kms/device.rs +++ b/src/backend/kms/device.rs @@ -693,7 +693,7 @@ impl Device { ) .with_context(|| { format!( - "Failed to optain file descriptor for drm device: {}", + "Failed to obtain file descriptor for drm device: {}", path.display() ) })?, From 9059873c84c79c8d14f54464f2a126d8c9491ceb Mon Sep 17 00:00:00 2001 From: Konstantinos Date: Fri, 28 Aug 2026 22:22:53 +0300 Subject: [PATCH 08/37] fix: Do not magnify cursor when there is an active grab. --- src/input/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/input/mod.rs b/src/input/mod.rs index d619a525..6055ad33 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -338,6 +338,9 @@ impl State { let current_output = seat.active_output(); if self.common.config.cosmic_conf.cursor_shake_to_find + && seat + .get_pointer() + .is_some_and(|pointer| !pointer.is_grabbed()) && let Some(cursor_state) = seat.user_data() .get::() From 86919566440fffbb437aff9c000774a7c32ce6b4 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Wed, 2 Sep 2026 13:45:28 -0600 Subject: [PATCH 09/37] fix: validate layer radius against the pending surface size --- src/wayland/protocols/corner_radius.rs | 49 +++++++++++++++----------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/wayland/protocols/corner_radius.rs b/src/wayland/protocols/corner_radius.rs index 479f890a..5c1a200c 100644 --- a/src/wayland/protocols/corner_radius.rs +++ b/src/wayland/protocols/corner_radius.rs @@ -5,16 +5,19 @@ use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v use cosmic_protocols::corner_radius::v1::server::{ cosmic_corner_radius_manager_v1, cosmic_corner_radius_toplevel_v1, }; +use smithay::backend::renderer::buffer_dimensions; +use smithay::backend::renderer::utils::RendererSurfaceStateUserData; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_popup::XdgPopup; use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::server::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1; use smithay::reexports::wayland_server::New; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{HookId, Logical, Rectangle}; -use smithay::wayland::compositor::Cacheable; use smithay::wayland::compositor::add_pre_commit_hook; use smithay::wayland::compositor::with_states; -use smithay::wayland::shell::wlr_layer::{LayerSurfaceAttributes, WlrLayerShellHandler}; +use smithay::wayland::compositor::{BufferAssignment, Cacheable, SurfaceAttributes}; +use smithay::wayland::shell::wlr_layer::WlrLayerShellHandler; use smithay::wayland::shell::xdg::{SurfaceCachedState, XdgShellSurfaceUserData}; +use smithay::wayland::viewporter::ViewportCachedState; use smithay::{ reexports::{ wayland_protocols::xdg::shell::server::xdg_toplevel::XdgToplevel, @@ -664,25 +667,31 @@ fn layer_radius_hook(_state: &mut D, _dh: &DisplayHandle, surface: & .get::() .pending(); - // The radius and padding is relative to the size of `zwlr_layer_surface_v1` (according to - // the protocol). That is the configure the client acked. - // - // `last_acked` is the becomes current as part of this commit, - // so it is staged consistently with the pending radius/padding above. - // - // Until the client acks a configure there is no defined size, and nothing to check. - let Some(size) = surface_data - .data_map - .get::>() - .and_then(|attrs| { - attrs - .lock() - .unwrap() - .last_acked - .as_ref() - .and_then(|configure| configure.state.size) + // The wl_surface size after this commit is: + // - viewport destination if set + // - else the logical size of the buffer that will be current attached now + // - else existing + let size = surface_data + .cached_state + .get::() + .pending() + .size() + .or_else(|| { + let mut guard = surface_data.cached_state.get::(); + let attrs = guard.pending(); + match &attrs.buffer { + Some(BufferAssignment::NewBuffer(buffer)) => buffer_dimensions(buffer) + .map(|d| d.to_logical(attrs.buffer_scale, attrs.buffer_transform.into())), + _ => None, + } }) - else { + .or_else(|| { + surface_data + .data_map + .get::() + .and_then(|state| state.lock().unwrap().surface_size()) + }); + let Some(size) = size else { return; }; From e62e35e5cc6bfa5cd5ba9dee718245497667037d Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Mon, 31 Aug 2026 20:23:45 +0200 Subject: [PATCH 10/37] fix: keep Xwayland frame callbacks progressing --- src/state.rs | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/state.rs b/src/state.rs index 5ccc7a7b..76c4c098 100644 --- a/src/state.rs +++ b/src/state.rs @@ -139,6 +139,14 @@ struct Localizations; pub static LANG_LOADER: LazyLock = LazyLock::new(|| fluent_language_loader!()); +fn xwayland_frame_throttle(throttle: Option, is_xwayland: bool) -> Option { + if is_xwayland { + Some(Duration::ZERO) + } else { + throttle + } +} + #[macro_export] macro_rules! fl { ($message_id:literal) => {{ @@ -1365,7 +1373,9 @@ impl Common { && let Some(grab_state) = move_grab.lock().unwrap().as_ref() { for (window, _) in grab_state.element().windows() { - window.send_frame(output, time, throttle(&window), should_send); + let throttle = + xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + window.send_frame(output, time, throttle, should_send); } } @@ -1389,25 +1399,34 @@ impl Common { .mapped() .for_each(|mapped| { for (window, _) in mapped.windows() { - window.send_frame(output, time, throttle(&window), should_send); + let throttle = + xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + window.send_frame(output, time, throttle, should_send); } }); if let Some(active) = shell.active_space(output) { if let Some(fs) = active.get_fullscreen(shell.seats.last_active()) { - fs.surface - .send_frame(output, time, throttle(&fs.surface), should_send); + let throttle = xwayland_frame_throttle( + throttle(&fs.surface), + fs.surface.x11_surface().is_some(), + ); + fs.surface.send_frame(output, time, throttle, should_send); } active.mapped().for_each(|mapped| { for (window, _) in mapped.windows() { - window.send_frame(output, time, throttle(&window), should_send); + let throttle = + xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + window.send_frame(output, time, throttle, should_send); } }); // other (throttled) windows active.minimized_windows.iter().for_each(|m| { for window in m.windows() { - window.send_frame(output, time, throttle(&window), |_, _| None); + let throttle = + xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + window.send_frame(output, time, throttle, |_, _| None); } }); @@ -1418,17 +1437,25 @@ impl Common { { if let Some(fs) = space.get_fullscreen(shell.seats.last_active()) { let throttle = min(throttle(space), throttle(&fs.surface)); + let throttle = + xwayland_frame_throttle(throttle, fs.surface.x11_surface().is_some()); fs.surface.send_frame(output, time, throttle, |_, _| None); } space.mapped().for_each(|mapped| { for (window, _) in mapped.windows() { let throttle = min(throttle(space), throttle(&window)); + let throttle = + xwayland_frame_throttle(throttle, window.x11_surface().is_some()); window.send_frame(output, time, throttle, |_, _| None); } }); space.minimized_windows.iter().for_each(|m| { for window in m.windows() { - window.send_frame(output, time, throttle(&window), |_, _| None); + let throttle = xwayland_frame_throttle( + throttle(&window), + window.x11_surface().is_some(), + ); + window.send_frame(output, time, throttle, |_, _| None); } }) } From 0d7592857964fe1061440b2b4504dbc4d3ec826d Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Tue, 1 Sep 2026 21:04:55 +0200 Subject: [PATCH 11/37] chore: refactor throttle function --- src/state.rs | 52 ++++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/src/state.rs b/src/state.rs index 76c4c098..28ed8fd4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -139,14 +139,6 @@ struct Localizations; pub static LANG_LOADER: LazyLock = LazyLock::new(|| fluent_language_loader!()); -fn xwayland_frame_throttle(throttle: Option, is_xwayland: bool) -> Option { - if is_xwayland { - Some(Duration::ZERO) - } else { - throttle - } -} - #[macro_export] macro_rules! fl { ($message_id:literal) => {{ @@ -1336,8 +1328,12 @@ impl Common { const THROTTLE: Option = Some(Duration::from_millis(995)); const SCREENCOPY_THROTTLE: Option = Some(Duration::from_nanos(16_666_666)); - fn throttle(session_holder: &impl SessionHolder) -> Option { - if session_holder.sessions().is_empty() && session_holder.cursor_sessions().is_empty() { + fn throttle(session_holder: &impl SessionHolder, is_xwayland: bool) -> Option { + if is_xwayland { + Some(Duration::ZERO) + } else if session_holder.sessions().is_empty() + && session_holder.cursor_sessions().is_empty() + { THROTTLE } else { SCREENCOPY_THROTTLE @@ -1373,8 +1369,7 @@ impl Common { && let Some(grab_state) = move_grab.lock().unwrap().as_ref() { for (window, _) in grab_state.element().windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, should_send); } } @@ -1399,24 +1394,19 @@ impl Common { .mapped() .for_each(|mapped| { for (window, _) in mapped.windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, should_send); } }); if let Some(active) = shell.active_space(output) { if let Some(fs) = active.get_fullscreen(shell.seats.last_active()) { - let throttle = xwayland_frame_throttle( - throttle(&fs.surface), - fs.surface.x11_surface().is_some(), - ); + let throttle = throttle(&fs.surface, fs.surface.x11_surface().is_some()); fs.surface.send_frame(output, time, throttle, should_send); } active.mapped().for_each(|mapped| { for (window, _) in mapped.windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, should_send); } }); @@ -1424,8 +1414,7 @@ impl Common { // other (throttled) windows active.minimized_windows.iter().for_each(|m| { for window in m.windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, |_, _| None); } }); @@ -1436,25 +1425,24 @@ impl Common { .filter(|w| w.handle != active.handle) { if let Some(fs) = space.get_fullscreen(shell.seats.last_active()) { - let throttle = min(throttle(space), throttle(&fs.surface)); - let throttle = - xwayland_frame_throttle(throttle, fs.surface.x11_surface().is_some()); + let throttle = min( + throttle(space, false), + throttle(&fs.surface, fs.surface.x11_surface().is_some()), + ); fs.surface.send_frame(output, time, throttle, |_, _| None); } space.mapped().for_each(|mapped| { for (window, _) in mapped.windows() { - let throttle = min(throttle(space), throttle(&window)); - let throttle = - xwayland_frame_throttle(throttle, window.x11_surface().is_some()); + let throttle = min( + throttle(space, false), + throttle(&window, window.x11_surface().is_some()), + ); window.send_frame(output, time, throttle, |_, _| None); } }); space.minimized_windows.iter().for_each(|m| { for window in m.windows() { - let throttle = xwayland_frame_throttle( - throttle(&window), - window.x11_surface().is_some(), - ); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, |_, _| None); } }) From 8ec1ffb740dfbd02ccc6cdaa431dd3438ec51f68 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 2 Sep 2026 12:49:01 -0700 Subject: [PATCH 12/37] protocols/keyboard-layout: Send ei `modifiers` on group change This makes `cosmic-osk` show a group change on `super+space`. Previously a change like that wouldn't be sent until a keyboard input changed the modifier state, for instance releasing the shift key. --- src/config/mod.rs | 4 +++- src/input/mod.rs | 11 +++-------- src/libei.rs | 4 +++- src/wayland/handlers/keyboard_layout.rs | 6 ++++++ src/wayland/protocols/keyboard_layout.rs | 5 ++++- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 9db9a9bb..d3d2919b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -842,7 +842,9 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut } if !state.common.ei_seats.is_empty() { let seat = state.common.shell.read().seats.last_active().clone(); - state.broadcast_ei_keyboard_modifiers(&seat); + if let Some(keyboard) = seat.get_keyboard() { + state.broadcast_ei_keyboard_modifiers(&keyboard); + } } state.common.config.cosmic_conf.xkb_config = value; } diff --git a/src/input/mod.rs b/src/input/mod.rs index 6055ad33..0228d3cb 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -49,6 +49,7 @@ use smithay::{ desktop::{PopupKeyboardGrab, WindowSurfaceType, utils::under_from_surface_tree}, input::{ Seat, + keyboard::KeyboardHandle, keyboard::{FilterResult, KeyboardSource, KeysymHandle, ModifiersState}, pointer::{ AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, @@ -1907,13 +1908,7 @@ impl State { /// Mirror the seat's current modifier state to every libei sender with a keyboard via /// `ei_keyboard.modifiers` - pub(crate) fn broadcast_ei_keyboard_modifiers(&self, seat: &Seat) { - if self.common.ei_seats.is_empty() { - return; - } - let Some(keyboard) = seat.get_keyboard() else { - return; - }; + pub(crate) fn broadcast_ei_keyboard_modifiers(&self, keyboard: &KeyboardHandle) { let s = keyboard.modifier_state().serialized; for ei_seat in self.common.ei_seats.values() { ei_seat.keyboard_modifiers(s.depressed, s.locked, s.latched, s.layout_effective); @@ -1958,7 +1953,7 @@ impl State { ) -> FilterResult> { if previous_modifiers != *modifiers { seat.set_last_modifier_change(backend_id, serial); - self.broadcast_ei_keyboard_modifiers(seat); + self.broadcast_ei_keyboard_modifiers(&seat.get_keyboard().unwrap()); } let current_focus = seat.get_keyboard().unwrap().current_focus(); diff --git a/src/libei.rs b/src/libei.rs index ad3a674d..487f0387 100644 --- a/src/libei.rs +++ b/src/libei.rs @@ -124,7 +124,9 @@ pub fn setup_ei( data.update_ei_input_method(); // Notify the remaining libei clients of the now-cleared modifier state let seat = data.common.shell.read().seats.last_active().clone(); - data.broadcast_ei_keyboard_modifiers(&seat); + if let Some(keyboard) = seat.get_keyboard() { + data.broadcast_ei_keyboard_modifiers(&keyboard); + } } EiInputEvent::Event(event) => { use smithay::backend::input::{InputEvent, KeyboardKeyEvent}; diff --git a/src/wayland/handlers/keyboard_layout.rs b/src/wayland/handlers/keyboard_layout.rs index ac1fda87..2477f93b 100644 --- a/src/wayland/handlers/keyboard_layout.rs +++ b/src/wayland/handlers/keyboard_layout.rs @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only +use smithay::input::keyboard::KeyboardHandle; + use crate::state::State; use crate::wayland::protocols::keyboard_layout::{KeyboardLayoutHandler, KeyboardLayoutState}; @@ -7,4 +9,8 @@ impl KeyboardLayoutHandler for State { fn keyboard_layout_state(&mut self) -> &mut KeyboardLayoutState { &mut self.common.keyboard_layout_state } + + fn group_changed(&mut self, keyboard: &KeyboardHandle) { + self.broadcast_ei_keyboard_modifiers(keyboard); + } } diff --git a/src/wayland/protocols/keyboard_layout.rs b/src/wayland/protocols/keyboard_layout.rs index f3a44f0a..8a8840b6 100644 --- a/src/wayland/protocols/keyboard_layout.rs +++ b/src/wayland/protocols/keyboard_layout.rs @@ -17,8 +17,10 @@ use smithay::{ use std::mem; use wayland_backend::server::{ClientId, GlobalId}; -pub trait KeyboardLayoutHandler { +pub trait KeyboardLayoutHandler: SeatHandler { fn keyboard_layout_state(&mut self) -> &mut KeyboardLayoutState; + /// Group has been changed through the protocol + fn group_changed(&mut self, keyboard: &KeyboardHandle); } #[derive(Debug)] @@ -57,6 +59,7 @@ impl KeyboardLayoutState { let active_layout = handle.with_xkb_state(state, |context| { context.xkb().lock().unwrap().active_layout() }); + state.group_changed(handle); if *last_layout != Some(active_layout) { keyboard_layout.group(active_layout.0); *last_layout = Some(active_layout); From ca9dd27350635b95532821cfb00f2e826aa22fc8 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 28 Aug 2026 14:42:17 +0200 Subject: [PATCH 13/37] chore: Fix debug feature by updating smithay-egui --- Cargo.lock | 26 ++------------------------ Cargo.toml | 1 + 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 859203e4..d0a95294 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,15 +121,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f47b57fc4521e3cae26a4d45b5227f8fadee4c345be0fefd8d5d1711afb8aeb9" -[[package]] -name = "approx" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" -dependencies = [ - "num-traits", -] - [[package]] name = "approx" version = "0.5.1" @@ -583,16 +574,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" -[[package]] -name = "cgmath" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" -dependencies = [ - "approx 0.4.0", - "num-traits", -] - [[package]] name = "chacha20" version = "0.10.0" @@ -3737,7 +3718,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cbf71184cc5ecc2e4e1baccdb21026c20e5fc3dcf63028a086131b3ab00b6e6" dependencies = [ - "approx 0.5.1", + "approx", "fast-srgb8", "palette_derive", "phf 0.11.3", @@ -4884,16 +4865,13 @@ dependencies = [ [[package]] name = "smithay-egui" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6794c95b83518f9f91ae8c2faee52302d521c0d541d016b4ed632374041d9c42" +source = "git+https://github.com/Smithay/smithay-egui.git?rev=6511552#65115521c756f356a7bcac8f1eeb715817a4666f" dependencies = [ - "cgmath", "egui", "egui_extras", "egui_glow", "image", "log", - "memoffset", "smithay", "xkbcommon 0.8.0", ] diff --git a/Cargo.toml b/Cargo.toml index 23fe2775..feb02259 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -147,3 +147,4 @@ cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch [patch.crates-io] smithay = { git = "https://github.com/smithay/smithay.git", rev = "e3d461a" } +smithay-egui = { git = "https://github.com/Smithay/smithay-egui.git", rev = "6511552" } From 6467f79025e2ffc32ed7df659c597beb4baa08b2 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 11 Aug 2026 18:18:02 +0200 Subject: [PATCH 14/37] shell: Add tablet grabs --- src/input/mod.rs | 70 ++--- src/shell/element/stack.rs | 198 +++++++++++--- src/shell/element/window.rs | 153 +++++++++-- src/shell/focus/target.rs | 132 ++++++++- src/shell/grabs/delay.rs | 161 +++++++++-- src/shell/grabs/menu/default.rs | 216 +++++++++------ src/shell/grabs/menu/mod.rs | 304 +++++++++++++++++++-- src/shell/grabs/mod.rs | 315 ++++++++++++++++++++-- src/shell/grabs/moving.rs | 152 +++++++++-- src/shell/layout/floating/grabs/resize.rs | 150 +++++++++-- src/shell/layout/tiling/grabs/resize.rs | 284 ++++++++++++++++--- src/shell/layout/tiling/mod.rs | 20 +- src/shell/mod.rs | 12 +- src/shell/zoom.rs | 217 +++++++++++++-- src/utils/iced/mod.rs | 166 +++++++++++- src/wayland/handlers/tablet_manager.rs | 6 +- src/wayland/handlers/xdg_shell/mod.rs | 39 ++- src/xwayland.rs | 58 ++-- 18 files changed, 2262 insertions(+), 391 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 0228d3cb..cbf99cae 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -52,10 +52,11 @@ use smithay::{ keyboard::KeyboardHandle, keyboard::{FilterResult, KeyboardSource, KeysymHandle, ModifiersState}, pointer::{ - AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent, - PointerGrab, PointerHandle, RelativeMotionEvent, + AxisFrame, ButtonEvent as PointerButtonEvent, GestureHoldBeginEvent, + GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, + GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, + GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, PointerGrab, PointerHandle, + RelativeMotionEvent, }, tablet::{TabletDescriptor, TabletSeatTrait, tool}, touch::{DownEvent, MotionEvent as TouchMotionEvent, UpEvent}, @@ -326,7 +327,7 @@ impl State { } InputEvent::PointerMotion { event, .. } => { - use smithay::backend::input::PointerMotionEvent; + use smithay::backend::input::PointerMotionEvent as _; let shell = self.common.shell.write(); if let Some(seat) = shell @@ -639,7 +640,7 @@ impl State { ptr.motion( self, under, - &MotionEvent { + &PointerMotionEvent { location: position.as_logical(), serial, time: event.time(), @@ -754,7 +755,7 @@ impl State { ptr.motion( self, under, - &MotionEvent { + &PointerMotionEvent { location: position.as_logical(), serial, time: event.time(), @@ -781,9 +782,8 @@ impl State { } } InputEvent::PointerButton { event, .. } => { - use smithay::backend::input::{ButtonState, PointerButtonEvent}; + use smithay::backend::input::{ButtonState, PointerButtonEvent as _}; - // let Some(seat) = self .common .shell @@ -857,7 +857,7 @@ impl State { && !shortcuts_inhibited { let seat_clone = seat.clone(); - let mouse_button = PointerButtonEvent::button(&event); + let mouse_button = event.button(); let mut supress_button = || { // If the logo is held then the pointer event is @@ -1017,7 +1017,7 @@ impl State { if pass_event { ptr.button( self, - &ButtonEvent { + &PointerButtonEvent { button, state: event.state(), serial, @@ -1597,7 +1597,7 @@ impl State { pointer.motion( self, under.clone(), - &MotionEvent { + &PointerMotionEvent { location: position.as_logical(), serial: SERIAL_COUNTER.next_serial(), time: InputTime::now(), @@ -1626,8 +1626,7 @@ impl State { tool.motion( self, - under - .and_then(|(f, loc)| f.wl_surface().map(|s| (s.into_owned(), loc))), + under, &tool::MotionEvent { location: position.as_logical(), serial: SERIAL_COUNTER.next_serial(), @@ -1666,7 +1665,7 @@ impl State { pointer.motion( self, under.clone(), - &MotionEvent { + &PointerMotionEvent { location: position.as_logical(), serial: SERIAL_COUNTER.next_serial(), time: InputTime::now(), @@ -1698,22 +1697,17 @@ impl State { }; match event.state() { - ProximityState::In => { - let under = under.and_then(|(f, loc)| { - f.wl_surface().map(|s| (s.into_owned(), loc)) - }); - tool.proximity_in( - self, - under, - tablet, - &tool::ProximityInEvent { - location: position.as_logical(), - axis: Some(frame), - serial: SERIAL_COUNTER.next_serial(), - time: event.time(), - }, - ) - } + ProximityState::In => tool.proximity_in( + self, + under, + tablet, + &tool::ProximityInEvent { + location: position.as_logical(), + axis: Some(frame), + serial: SERIAL_COUNTER.next_serial(), + time: event.time(), + }, + ), ProximityState::Out => tool.proximity_out( self, &tool::ProximityOutEvent { @@ -1728,6 +1722,18 @@ impl State { } } InputEvent::TabletToolTip { event, .. } => { + { + let mut shell = self.common.shell.write(); + if let Some(Trigger::Tool(desc, trigger)) = + shell.overview_mode().0.active_trigger() + && event.tool() == *desc + && matches!(*trigger, tool::GrabTrigger::Tip) + && event.tip_state() == TabletToolTipState::Up + { + shell.set_overview_mode(None, self.common.event_loop_handle.clone()); + } + } + let maybe_seat = self .common .shell @@ -2968,7 +2974,7 @@ impl State { pointer.motion( self, under, - &MotionEvent { + &PointerMotionEvent { location: point.as_logical(), serial, time, diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 2fed0977..34e6f876 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -11,7 +11,7 @@ use crate::{ shell::{ element::{CosmicMappedKey, CosmicMappedKeyInner}, focus::target::PointerFocusTarget, - grabs::{ReleaseMode, ResizeEdge}, + grabs::{GrabType, ReleaseMode, ResizeEdge}, layout::tiling::NodeDesc, }, state::State, @@ -38,7 +38,7 @@ use shortcuts::action::{Direction, FocusDirection}; use smithay::{ backend::{ drm::DrmNode, - input::{InputTime, KeyState}, + input::{InputTime, KeyState, TabletToolDescriptor}, renderer::{ ImportAll, ImportMem, Renderer, element::{Element, Id as RendererId, Kind, RenderElement, UnderlyingStorage}, @@ -52,14 +52,23 @@ use smithay::{ Seat, keyboard::{KeyboardTarget, KeysymHandle, ModifiersState}, pointer::{ - AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, CursorImageStatus, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, PointerTarget, RelativeMotionEvent, }, + tablet::{ + Tablet, TabletSeatTrait, + tool::{ + AxisFrame as ToolAxisFrame, ButtonEvent as ToolButtonEvent, + DownEvent as ToolDownEvent, MotionEvent as ToolMotionEvent, TabletToolTarget, + UpEvent as ToolUpEvent, + }, + }, touch::{ - DownEvent, FrameMarker, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, - TouchTarget, UpEvent, + DownEvent as TouchDownEvent, FrameMarker, MotionEvent as TouchMotionEvent, + OrientationEvent, ShapeEvent, TouchTarget, UpEvent as TouchUpEvent, }, }, output::Output, @@ -909,12 +918,19 @@ impl CosmicStack { false, ); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(state, grab, serial, focus); + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -1089,12 +1105,19 @@ impl Program for CosmicStackInternal { false, ); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(state, grab, serial, focus); + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -1597,7 +1620,7 @@ impl KeyboardTarget for CosmicStack { } impl PointerTarget for CosmicStack { - fn enter(&self, seat: &Seat, data: &mut State, event: &MotionEvent) { + fn enter(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { let mut event = event.clone(); self.0.with_program(|p| { let active_window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]; @@ -1625,7 +1648,7 @@ impl PointerTarget for CosmicStack { PointerTarget::enter(&self.0, seat, data, &event) } - fn motion(&self, seat: &Seat, data: &mut State, event: &MotionEvent) { + fn motion(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { let mut event = event.clone(); self.0.with_program(|p| { let active = p.active.load(Ordering::SeqCst); @@ -1668,7 +1691,7 @@ impl PointerTarget for CosmicStack { ) { } - fn button(&self, seat: &Seat, data: &mut State, event: &ButtonEvent) { + fn button(&self, seat: &Seat, data: &mut State, event: &PointerButtonEvent) { match self.0.with_program(|p| p.current_focus()) { Some(Focus::Header) => PointerTarget::button(&self.0, seat, data, event), Some(x) => { @@ -1700,12 +1723,19 @@ impl PointerTarget for CosmicStack { false, ); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(state, grab, serial, focus); + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -1714,7 +1744,7 @@ impl PointerTarget for CosmicStack { } } - fn axis(&self, seat: &Seat, data: &mut State, frame: AxisFrame) { + fn axis(&self, seat: &Seat, data: &mut State, frame: PointerAxisFrame) { if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { PointerTarget::axis(&self.0, seat, data, frame) } @@ -1763,12 +1793,19 @@ impl PointerTarget for CosmicStack { false, ); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(state, grab, serial, focus); + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -1842,7 +1879,7 @@ impl PointerTarget for CosmicStack { } impl TouchTarget for CosmicStack { - fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent) { + fn down(&self, seat: &Seat, data: &mut State, event: &TouchDownEvent) { let mut event = event.clone(); let active_window_geo = self.0.with_program(|p| { p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].geometry() @@ -1853,7 +1890,7 @@ impl TouchTarget for CosmicStack { TouchTarget::down(&self.0, seat, data, &event) } - fn up(&self, seat: &Seat, data: &mut State, event: &UpEvent) { + fn up(&self, seat: &Seat, data: &mut State, event: &TouchUpEvent) { TouchTarget::up(&self.0, seat, data, event) } @@ -1901,6 +1938,101 @@ impl TouchTarget for CosmicStack { } } +impl TabletToolTarget for CosmicStack { + fn proximity_in( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + tablet: &Tablet, + serial: Serial, + ) { + TabletToolTarget::proximity_in(&self.0, seat, data, tool_descriptor, tablet, serial) + } + + fn proximity_out( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + ) { + TabletToolTarget::proximity_out(&self.0, seat, data, tool_descriptor) + } + + fn down( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolDownEvent, + ) { + TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) + } + + fn up( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolUpEvent, + ) { + TabletToolTarget::up(&self.0, seat, data, tool_descriptor, event) + } + + fn motion( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolMotionEvent, + ) { + let mut event = event.clone(); + let active_window_geo = self.0.with_program(|p| { + p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].geometry() + }); + event.location -= active_window_geo.loc.to_f64(); + TabletToolTarget::motion(&self.0, seat, data, tool_descriptor, &event); + + if event.location.y < 0.0 + || event.location.y > TAB_HEIGHT as f64 + || event.location.x < 64.0 + || event.location.x > (active_window_geo.size.w as f64 - 64.0) + { + self.start_drag(data, seat, event.serial); + } + } + + fn axis( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + frame: ToolAxisFrame, + ) { + TabletToolTarget::axis(&self.0, seat, data, tool_descriptor, frame) + } + + fn button( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolButtonEvent, + ) { + TabletToolTarget::button(&self.0, seat, data, tool_descriptor, event) + } + + fn frame( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + time: InputTime, + ) { + TabletToolTarget::frame(&self.0, seat, data, tool_descriptor, time) + } +} + pub enum CosmicStackRenderElement { Header(IcedRenderElement), Shadow(PixelShaderElement), diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 53b2caee..846d9da4 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -7,7 +7,7 @@ use crate::{ shell::{ element::{CosmicMappedKey, CosmicMappedKeyInner}, focus::target::PointerFocusTarget, - grabs::{ReleaseMode, ResizeEdge}, + grabs::{GrabType, ReleaseMode, ResizeEdge}, }, state::State, utils::{ @@ -21,7 +21,7 @@ use cosmic_comp_config::AppearanceConfig; use smithay::{ backend::{ drm::DrmNode, - input::{InputTime, KeyState}, + input::{InputTime, KeyState, TabletToolDescriptor}, renderer::{ ImportAll, ImportMem, Renderer, element::{Element, Id as RendererId, Kind, RenderElement, UnderlyingStorage}, @@ -35,14 +35,23 @@ use smithay::{ Seat, keyboard::{KeyboardTarget, KeysymHandle, ModifiersState}, pointer::{ - AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, GestureHoldBeginEvent, - GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, - GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, - GestureSwipeUpdateEvent, MotionEvent, PointerTarget, RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, CursorIcon, + CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, + PointerTarget, RelativeMotionEvent, + }, + tablet::{ + Tablet, TabletSeatTrait, + tool::{ + AxisFrame as ToolAxisFrame, ButtonEvent as ToolButtonEvent, + DownEvent as ToolDownEvent, MotionEvent as ToolMotionEvent, TabletToolTarget, + UpEvent as ToolUpEvent, + }, }, touch::{ - DownEvent, FrameMarker, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, - TouchTarget, UpEvent, + DownEvent as TouchDownEvent, FrameMarker, MotionEvent as TouchMotionEvent, + OrientationEvent, ShapeEvent, TouchTarget, UpEvent as TouchUpEvent, }, }, output::Output, @@ -746,12 +755,19 @@ impl Program for CosmicWindowInternal { false, ); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(state, grab, serial, focus); + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -1003,7 +1019,7 @@ impl KeyboardTarget for CosmicWindow { } impl PointerTarget for CosmicWindow { - fn enter(&self, seat: &Seat, data: &mut State, event: &MotionEvent) { + fn enter(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { let mut event = event.clone(); self.0.with_program(|p| { let has_ssd = p.has_ssd(false); @@ -1029,7 +1045,7 @@ impl PointerTarget for CosmicWindow { PointerTarget::enter(&self.0, seat, data, &event) } - fn motion(&self, seat: &Seat, data: &mut State, event: &MotionEvent) { + fn motion(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { let mut event = event.clone(); self.0.with_program(|p| { let has_ssd = p.has_ssd(false); @@ -1061,7 +1077,7 @@ impl PointerTarget for CosmicWindow { ) { } - fn button(&self, seat: &Seat, data: &mut State, event: &ButtonEvent) { + fn button(&self, seat: &Seat, data: &mut State, event: &PointerButtonEvent) { match self.0.with_program(|p| p.current_focus()) { Some(Focus::Header) => PointerTarget::button(&self.0, seat, data, event), Some(x) => { @@ -1098,12 +1114,19 @@ impl PointerTarget for CosmicWindow { ); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(state, grab, serial, focus); + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -1112,7 +1135,7 @@ impl PointerTarget for CosmicWindow { } } - fn axis(&self, seat: &Seat, data: &mut State, frame: AxisFrame) { + fn axis(&self, seat: &Seat, data: &mut State, frame: PointerAxisFrame) { if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { PointerTarget::axis(&self.0, seat, data, frame) } @@ -1199,7 +1222,7 @@ impl PointerTarget for CosmicWindow { } impl TouchTarget for CosmicWindow { - fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent) { + fn down(&self, seat: &Seat, data: &mut State, event: &TouchDownEvent) { let mut event = event.clone(); self.0.with_program(|p| { event.location -= p.window.geometry().loc.to_f64(); @@ -1207,7 +1230,7 @@ impl TouchTarget for CosmicWindow { TouchTarget::down(&self.0, seat, data, &event) } - fn up(&self, seat: &Seat, data: &mut State, event: &UpEvent) { + fn up(&self, seat: &Seat, data: &mut State, event: &TouchUpEvent) { TouchTarget::up(&self.0, seat, data, event) } @@ -1238,6 +1261,88 @@ impl TouchTarget for CosmicWindow { } } +impl TabletToolTarget for CosmicWindow { + fn proximity_in( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + tablet: &Tablet, + serial: Serial, + ) { + TabletToolTarget::proximity_in(&self.0, seat, data, tool_descriptor, tablet, serial) + } + + fn proximity_out( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + ) { + TabletToolTarget::proximity_out(&self.0, seat, data, tool_descriptor) + } + + fn down( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolDownEvent, + ) { + TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) + } + + fn up( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolUpEvent, + ) { + TabletToolTarget::up(&self.0, seat, data, tool_descriptor, event) + } + + fn motion( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolMotionEvent, + ) { + TabletToolTarget::motion(&self.0, seat, data, tool_descriptor, event) + } + + fn axis( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + frame: ToolAxisFrame, + ) { + TabletToolTarget::axis(&self.0, seat, data, tool_descriptor, frame) + } + + fn button( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolButtonEvent, + ) { + TabletToolTarget::button(&self.0, seat, data, tool_descriptor, event) + } + + fn frame( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + time: InputTime, + ) { + TabletToolTarget::frame(&self.0, seat, data, tool_descriptor, time) + } +} + impl WaylandFocus for CosmicWindow { fn wl_surface(&self) -> Option> { self.0.with_program(|p| { diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index 56af0ccc..6ca13279 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -16,21 +16,30 @@ use crate::{ }; use id_tree::NodeId; use smithay::{ - backend::input::{InputTime, KeyState}, + backend::input::{InputTime, KeyState, TabletToolDescriptor}, desktop::{LayerSurface, PopupKind, WindowSurface, WindowSurfaceType, space::SpaceElement}, input::{ Seat, dnd::{DndFocus, OfferData, Source}, keyboard::{KeyboardTarget, KeysymHandle, ModifiersState}, pointer::{ - AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - MotionEvent as PointerMotionEvent, PointerTarget, RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, + PointerTarget, RelativeMotionEvent, + }, + tablet::{ + Tablet, + tool::{ + AxisFrame as ToolAxisFrame, ButtonEvent as ToolButtonEvent, + DownEvent as ToolDownEvent, MotionEvent as ToolMotionEvent, TabletToolTarget, + UpEvent as ToolUpEvent, + }, }, touch::{ - DownEvent, FrameMarker, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, - TouchTarget, UpEvent, + DownEvent as TouchDownEvent, FrameMarker, MotionEvent as TouchMotionEvent, + OrientationEvent, ShapeEvent, TouchTarget, UpEvent as TouchUpEvent, }, }, reexports::wayland_server::{ @@ -164,6 +173,17 @@ impl PointerFocusTarget { } } + fn inner_tablet_tool_target(&self) -> &dyn TabletToolTarget { + match self { + PointerFocusTarget::WlSurface { surface, .. } => surface, + PointerFocusTarget::X11Surface { surface, .. } => surface, + PointerFocusTarget::StackUI(u) => u, + PointerFocusTarget::WindowUI(u) => u, + PointerFocusTarget::ResizeFork(f) => f, + PointerFocusTarget::ZoomUI(e) => e, + } + } + pub fn under_surface>>( surface: &CosmicSurface, point: P, @@ -409,10 +429,10 @@ impl PointerTarget for PointerFocusTarget { self.inner_pointer_target() .relative_motion(seat, data, event); } - fn button(&self, seat: &Seat, data: &mut State, event: &ButtonEvent) { + fn button(&self, seat: &Seat, data: &mut State, event: &PointerButtonEvent) { self.inner_pointer_target().button(seat, data, event); } - fn axis(&self, seat: &Seat, data: &mut State, frame: AxisFrame) { + fn axis(&self, seat: &Seat, data: &mut State, frame: PointerAxisFrame) { self.inner_pointer_target().axis(seat, data, frame); } fn frame(&self, seat: &Seat, data: &mut State) { @@ -498,12 +518,102 @@ impl PointerTarget for PointerFocusTarget { } } +impl TabletToolTarget for PointerFocusTarget { + fn proximity_in( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + tablet: &Tablet, + serial: Serial, + ) { + self.inner_tablet_tool_target() + .proximity_in(seat, data, tool_descriptor, tablet, serial); + } + + fn proximity_out( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + ) { + self.inner_tablet_tool_target() + .proximity_out(seat, data, tool_descriptor); + } + + fn down( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolDownEvent, + ) { + self.inner_tablet_tool_target() + .down(seat, data, tool_descriptor, event); + } + + fn up( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolUpEvent, + ) { + self.inner_tablet_tool_target() + .up(seat, data, tool_descriptor, event); + } + + fn motion( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolMotionEvent, + ) { + self.inner_tablet_tool_target() + .motion(seat, data, tool_descriptor, event); + } + + fn axis( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + frame: ToolAxisFrame, + ) { + self.inner_tablet_tool_target() + .axis(seat, data, tool_descriptor, frame); + } + + fn button( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &ToolButtonEvent, + ) { + self.inner_tablet_tool_target() + .button(seat, data, tool_descriptor, event); + } + + fn frame( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + time: InputTime, + ) { + self.inner_tablet_tool_target() + .frame(seat, data, tool_descriptor, time); + } +} + impl TouchTarget for PointerFocusTarget { - fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent) { + fn down(&self, seat: &Seat, data: &mut State, event: &TouchDownEvent) { self.inner_touch_target().down(seat, data, event); } - fn up(&self, seat: &Seat, data: &mut State, event: &UpEvent) { + fn up(&self, seat: &Seat, data: &mut State, event: &TouchUpEvent) { self.inner_touch_target().up(seat, data, event); } diff --git a/src/shell/grabs/delay.rs b/src/shell/grabs/delay.rs index 96d33dc6..ca19e4cb 100644 --- a/src/shell/grabs/delay.rs +++ b/src/shell/grabs/delay.rs @@ -1,22 +1,34 @@ use smithay::{ + backend::input::{InputTime, TabletToolDescriptor}, input::{ Seat, SeatHandler, pointer::{ - AxisFrame, ButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - GrabStartData as PointerGrabStartData, MotionEvent as PointerMotionEvent, PointerGrab, - PointerInnerHandle, RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, Focus, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, + MotionEvent as PointerMotionEvent, PointerGrab, PointerInnerHandle, + RelativeMotionEvent, + }, + tablet::{ + TabletSeatHandler, TabletSeatTrait, + tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, GrabStartData as TabletGrabStartData, + MotionEvent as TabletMotionEvent, ProximityInEvent, ProximityOutEvent, + TabletToolGrab, TabletToolInnerHandle, UpEvent as TabletUpEvent, + }, }, touch::{ - DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, - OrientationEvent, ShapeEvent, TouchGrab, TouchInnerHandle, UpEvent, + DownEvent as TouchDownEvent, GrabStartData as TouchGrabStartData, + MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchGrab, + TouchInnerHandle, UpEvent as TouchUpEvent, }, }, utils::{Logical, Point, SERIAL_COUNTER, Serial}, }; -use crate::state::State; +use crate::{shell::grabs::GrabType, state::State}; use super::GrabStartData; @@ -44,10 +56,15 @@ impl DelayGrab { } } - pub fn is_touch_grab(&self) -> bool { - match self.start_data { - GrabStartData::Touch(_) => true, - GrabStartData::Pointer(_) => false, + pub fn grab_type(&self) -> GrabType { + self.start_data.type_() + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + if let GrabStartData::TabletTool { tool, .. } = &self.start_data { + Some(tool) + } else { + None } } } @@ -92,7 +109,7 @@ impl> PointerGrab for DelayGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { handle.button(data, event); if handle.current_pressed().is_empty() { @@ -104,7 +121,7 @@ impl> PointerGrab for DelayGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { handle.axis(data, details); } @@ -201,12 +218,17 @@ impl> TouchGrab for DelayGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, focus: Option<(::TouchFocus, Point)>, - event: &DownEvent, + event: &TouchDownEvent, ) { handle.down(data, focus, event); } - fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) { + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &TouchUpEvent, + ) { handle.up(data, event); if event.slot == TouchGrab::start_data(self).slot { @@ -273,3 +295,110 @@ impl> TouchGrab for DelayGrab { fn unset(&mut self, _data: &mut State) {} } + +impl> TabletToolGrab for DelayGrab { + fn start_data(&self) -> &TabletGrabStartData { + match &self.start_data { + GrabStartData::TabletTool { data, .. } => data, + _ => unreachable!(), + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + handle.proximity_out(data, event); + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(::ToolFocus, Point)>, + event: &TabletMotionEvent, + ) { + handle.motion(data, focus, event); + + let distance = self.start_data.distance(event.location); + if distance >= 1. + && let Some(factory) = self.grab_factory.take() + { + let seat = self.seat.clone(); + let serial = self.serial.unwrap_or_else(|| SERIAL_COUNTER.next_serial()); + let time = InputTime::now(); + let Some(tool) = self.tool().cloned() else { + handle.unset_grab(self, data, serial, time, true); + return; + }; + data.common.event_loop_handle.insert_idle(move |data| { + if let Some((grab, focus)) = factory(data) { + seat.tablet_seat() + .get_tool(&tool) + .unwrap() + .set_grab(data, grab, time, serial, focus); + } + }); + } + } + + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + handle.down(data, event) + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + handle.up(data, event); + handle.unset_grab(self, data, event.serial, event.time, false); + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + handle.button(data, event); + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + frame: TabletAxisFrame, + ) { + handle.axis(data, frame) + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + time: InputTime, + ) { + handle.frame(data, time) + } + + fn unset(&mut self, _data: &mut State) {} + + fn proximity_in( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(::ToolFocus, Point)>, + event: &ProximityInEvent, + ) { + handle.proximity_in(data, focus, event); + } +} diff --git a/src/shell/grabs/menu/default.rs b/src/shell/grabs/menu/default.rs index 81673efd..26cca2f5 100644 --- a/src/shell/grabs/menu/default.rs +++ b/src/shell/grabs/menu/default.rs @@ -1,7 +1,9 @@ use cosmic_settings_config::shortcuts::Action; use smithay::{ - backend::input::InputTime, input::pointer::MotionEvent, - reexports::wayland_server::protocol::wl_surface::WlSurface, utils::SERIAL_COUNTER, + backend::input::InputTime, + input::{pointer::MotionEvent, tablet::TabletSeatTrait}, + reexports::wayland_server::protocol::wl_surface::WlSurface, + utils::SERIAL_COUNTER, wayland::seat::WaylandFocus, }; @@ -11,7 +13,7 @@ use crate::{ shell::{ CosmicSurface, PointGlobalExt, Shell, element::{CosmicMapped, CosmicWindow}, - grabs::ReleaseMode, + grabs::{GrabType, ReleaseMode}, }, state::State, utils::{prelude::SeatExt, screenshot::screenshot_window}, @@ -353,19 +355,20 @@ pub fn window_items( std::mem::drop(shell); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab( - state, - grab, - SERIAL_COUNTER.next_serial(), - ) - } else { - seat.get_pointer().unwrap().set_grab( - state, - grab, - SERIAL_COUNTER.next_serial(), - focus, - ); + let serial = SERIAL_COUNTER.next_serial(); + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() + .unwrap() + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } } @@ -389,21 +392,29 @@ pub fn window_items( std::mem::drop(shell); if let Some(((target, loc), (grab, focus))) = res { let serial = SERIAL_COUNTER.next_serial(); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - let pointer = seat.get_pointer().unwrap(); - pointer.motion( - state, - target, - &MotionEvent { - location: loc.as_logical().to_f64(), - serial, - time: InputTime::now(), - }, - ); - pointer.frame(state); - pointer.set_grab(state, grab, serial, focus); + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), + GrabType::Pointer => { + let pointer = seat.get_pointer().unwrap(); + pointer.motion( + state, + target, + &MotionEvent { + location: loc.as_logical().to_f64(), + serial, + time: InputTime::now(), + }, + ); + pointer.frame(state); + pointer.set_grab(state, grab, serial, focus); + } } } }); @@ -424,21 +435,30 @@ pub fn window_items( std::mem::drop(shell); if let Some(((target, loc), (grab, focus))) = res { let serial = SERIAL_COUNTER.next_serial(); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - let pointer = seat.get_pointer().unwrap(); - pointer.motion( - state, - target, - &MotionEvent { - location: loc.as_logical().to_f64(), - serial, - time: InputTime::now(), - }, - ); - pointer.frame(state); - pointer.set_grab(state, grab, serial, focus); + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => { + let pointer = seat.get_pointer().unwrap(); + pointer.motion( + state, + target, + &MotionEvent { + location: loc.as_logical().to_f64(), + serial, + time: InputTime::now(), + }, + ); + pointer.frame(state); + pointer.set_grab(state, grab, serial, focus); + } + GrabType::TabletTool => { + seat.tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus); + } } } }); @@ -459,21 +479,30 @@ pub fn window_items( std::mem::drop(shell); if let Some(((target, loc), (grab, focus))) = res { let serial = SERIAL_COUNTER.next_serial(); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - let pointer = seat.get_pointer().unwrap(); - pointer.motion( - state, - target, - &MotionEvent { - location: loc.as_logical().to_f64(), - serial, - time: InputTime::now(), - }, - ); - pointer.frame(state); - pointer.set_grab(state, grab, serial, focus); + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => { + let pointer = seat.get_pointer().unwrap(); + pointer.motion( + state, + target, + &MotionEvent { + location: loc.as_logical().to_f64(), + serial, + time: InputTime::now(), + }, + ); + pointer.frame(state); + pointer.set_grab(state, grab, serial, focus); + } + GrabType::TabletTool => { + seat.tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus); + } } } }); @@ -494,21 +523,29 @@ pub fn window_items( std::mem::drop(shell); if let Some(((target, loc), (grab, focus))) = res { let serial = SERIAL_COUNTER.next_serial(); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - let pointer = seat.get_pointer().unwrap(); - pointer.motion( - state, - target, - &MotionEvent { - location: loc.as_logical().to_f64(), - serial, - time: InputTime::now(), - }, - ); - pointer.frame(state); - pointer.set_grab(state, grab, serial, focus); + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => { + let pointer = seat.get_pointer().unwrap(); + pointer.motion( + state, + target, + &MotionEvent { + location: loc.as_logical().to_f64(), + serial, + time: InputTime::now(), + }, + ); + pointer.frame(state); + pointer.set_grab(state, grab, serial, focus); + } + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } }); @@ -628,19 +665,20 @@ pub fn fullscreen_items(window: &CosmicSurface, config: &Config) -> impl Iterato std::mem::drop(shell); if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab( - state, - grab, - SERIAL_COUNTER.next_serial(), - ) - } else { - seat.get_pointer().unwrap().set_grab( - state, - grab, - SERIAL_COUNTER.next_serial(), - focus, - ); + let serial = SERIAL_COUNTER.next_serial(); + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat + .get_pointer() + .unwrap() + .set_grab(state, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus), } } } diff --git a/src/shell/grabs/menu/mod.rs b/src/shell/grabs/menu/mod.rs index 72ea065b..dafbd6cc 100644 --- a/src/shell/grabs/menu/mod.rs +++ b/src/shell/grabs/menu/mod.rs @@ -19,22 +19,33 @@ use cosmic::{ }; use smithay::{ backend::{ - input::{ButtonState, TouchSlot}, + input::{ButtonState, InputTime, TabletToolDescriptor, TouchSlot}, renderer::ImportMem, }, desktop::space::SpaceElement, input::{ Seat, pointer::{ - AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - GrabStartData as PointerGrabStartData, MotionEvent as PointerMotionEvent, PointerGrab, - PointerInnerHandle, PointerTarget, RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, + MotionEvent as PointerMotionEvent, PointerGrab, PointerInnerHandle, PointerTarget, + RelativeMotionEvent, + }, + tablet::{ + TabletSeatHandler, + tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, GrabStartData as TabletGrabStartData, + MotionEvent as TabletMotionEvent, ProximityInEvent, ProximityOutEvent, + TabletToolGrab, TabletToolInnerHandle, TabletToolTarget, UpEvent as TabletUpEvent, + }, }, touch::{ - DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, - TouchGrab, TouchInnerHandle, TouchTarget, UpEvent, + DownEvent as TouchDownEvent, GrabStartData as TouchGrabStartData, + MotionEvent as TouchMotionEvent, TouchGrab, TouchInnerHandle, TouchTarget, + UpEvent as TouchUpEvent, }, }, output::Output, @@ -43,7 +54,7 @@ use smithay::{ use crate::{ backend::render::element::AsGlowRenderer, - shell::{SeatExt, focus::target::PointerFocusTarget}, + shell::{SeatExt, focus::target::PointerFocusTarget, grabs::GrabType}, state::State, utils::{ iced::{IcedElement, IcedRenderElement, Program}, @@ -350,6 +361,7 @@ impl Program for ContextMenu { position, pointer_entered: false, touch_entered: None, + tablet_entered: None, }) } }); @@ -508,6 +520,7 @@ pub struct Element { position: Point, pointer_entered: bool, touch_entered: Option, + tablet_entered: Option, } pub struct MenuGrab { @@ -516,6 +529,7 @@ pub struct MenuGrab { seat: Seat, screen_space_relative: Option, scale: Arc>, + last_tablet_idx: Option, } impl PointerGrab for MenuGrab { @@ -598,7 +612,7 @@ impl PointerGrab for MenuGrab { &mut self, state: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { let any_entered = self .elements @@ -632,7 +646,7 @@ impl PointerGrab for MenuGrab { &mut self, state: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { handle.axis(state, details); } @@ -729,7 +743,7 @@ impl TouchGrab for MenuGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &DownEvent, + event: &TouchDownEvent, ) { { let mut guard = self.elements.lock().unwrap(); @@ -757,7 +771,7 @@ impl TouchGrab for MenuGrab { }) { let element = &mut elements[i]; - let new_event = DownEvent { + let new_event = TouchDownEvent { slot: event.slot, location: event_location - element.position.as_logical().to_f64(), serial: event.serial, @@ -772,7 +786,12 @@ impl TouchGrab for MenuGrab { handle.down(data, None, event); } - fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) { + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &TouchUpEvent, + ) { { let elements = self.elements.lock().unwrap(); for element in elements.iter().filter(|elem| { @@ -848,6 +867,248 @@ impl TouchGrab for MenuGrab { fn unset(&mut self, _data: &mut State) {} } +impl TabletToolGrab for MenuGrab { + fn start_data(&self) -> &TabletGrabStartData { + match &self.start_data { + GrabStartData::TabletTool { data, .. } => data, + _ => unreachable!(), + } + } + + fn proximity_in( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + _focus: Option<(::ToolFocus, Point)>, + event: &ProximityInEvent, + ) { + { + let location = if let Some(output) = self.screen_space_relative.as_ref() { + if data.common.shell.read().zoom_state().is_some() { + event + .location + .as_global() + .to_zoomed(output) + .to_global(output) + .as_logical() + } else { + event.location + } + } else { + event.location + }; + + let mut elements = self.elements.lock().unwrap(); + if let Some(i) = elements.iter().position(|elem| { + let mut bbox = elem.iced.bbox(); + bbox.loc = elem.position.as_logical(); + + bbox.contains(location.to_i32_floor()) + }) { + let element = &mut elements[i]; + + let new_event = TabletMotionEvent { + location: location - element.position.as_logical().to_f64(), + serial: event.serial, + time: event.time, + }; + + TabletToolTarget::proximity_in( + &element.iced, + &self.seat, + data, + handle.descriptor(), + &handle.current_tablet(), + event.serial, + ); + element.tablet_entered = Some(handle.descriptor().clone()); + TabletToolTarget::motion( + &element.iced, + &self.seat, + data, + handle.descriptor(), + &new_event, + ); + self.last_tablet_idx = Some(i); + } + } + handle.proximity_in(data, None, event); + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + { + let mut elements = self.elements.lock().unwrap(); + for element in elements.iter_mut().filter(|elem| { + elem.tablet_entered + .as_ref() + .is_some_and(|tool| tool == handle.descriptor()) + }) { + TabletToolTarget::proximity_out( + &element.iced, + &self.seat, + data, + handle.descriptor(), + ); + element.tablet_entered.take(); + } + self.last_tablet_idx.take(); + } + handle.unset_grab(self, data, event.serial, event.time, true); + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + _focus: Option<(::ToolFocus, Point)>, + event: &TabletMotionEvent, + ) { + { + let location = if let Some(output) = self.screen_space_relative.as_ref() { + if data.common.shell.read().zoom_state().is_some() { + event + .location + .as_global() + .to_zoomed(output) + .to_global(output) + .as_logical() + } else { + event.location + } + } else { + event.location + }; + + let mut elements = self.elements.lock().unwrap(); + if let Some(i) = elements.iter().position(|elem| { + let mut bbox = elem.iced.bbox(); + bbox.loc = elem.position.as_logical(); + + bbox.contains(location.to_i32_floor()) + }) { + let element = &mut elements[i]; + + let new_event = TabletMotionEvent { + location: location - element.position.as_logical().to_f64(), + serial: event.serial, + time: event.time, + }; + + if element.tablet_entered.is_none() { + TabletToolTarget::proximity_in( + &element.iced, + &self.seat, + data, + handle.descriptor(), + &handle.current_tablet(), + event.serial, + ); + element.tablet_entered = Some(handle.descriptor().clone()); + } + TabletToolTarget::motion( + &element.iced, + &self.seat, + data, + handle.descriptor(), + &new_event, + ); + self.last_tablet_idx = Some(i); + } else { + elements + .iter_mut() + .filter(|element| element.tablet_entered.is_some()) + .skip(1) + .for_each(|element| { + TabletToolTarget::proximity_out( + &element.iced, + &self.seat, + data, + handle.descriptor(), + ); + }); + self.last_tablet_idx.take(); + } + } + handle.motion(data, None, event); + } + + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + let mut guard = self.elements.lock().unwrap(); + let elements = &mut *guard; + + if let Some(elem) = self.last_tablet_idx.and_then(|i| elements.get_mut(i)) + && elem + .tablet_entered + .as_ref() + .is_some_and(|desc| desc == handle.descriptor()) + { + TabletToolTarget::down(&elem.iced, &self.seat, data, handle.descriptor(), event); + } else { + handle.down(data, event); + } + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + let mut guard = self.elements.lock().unwrap(); + let elements = &mut *guard; + + if let Some(elem) = self.last_tablet_idx.and_then(|i| elements.get_mut(i)) + && elem + .tablet_entered + .as_ref() + .is_some_and(|desc| desc == handle.descriptor()) + { + TabletToolTarget::up(&elem.iced, &self.seat, data, handle.descriptor(), event); + } else { + handle.up(data, event); + } + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + handle.button(data, event); + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + frame: TabletAxisFrame, + ) { + handle.axis(data, frame); + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + time: InputTime, + ) { + handle.frame(data, time); + } + + fn unset(&mut self, _data: &mut State) {} +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct MenuAlignment { pub x: AxisAlignment, @@ -1051,6 +1312,7 @@ impl MenuGrab { position, pointer_entered: false, touch_entered: None, + tablet_entered: None, }])); let scale = Arc::new(Mutex::new(screen_space_relative.unwrap_or(1.))); @@ -1075,6 +1337,7 @@ impl MenuGrab { seat: seat.clone(), screen_space_relative, scale, + last_tablet_idx: None, } } @@ -1085,10 +1348,15 @@ impl MenuGrab { } } - pub fn is_touch_grab(&self) -> bool { - match self.start_data { - GrabStartData::Touch(_) => true, - GrabStartData::Pointer(_) => false, + pub fn grab_type(&self) -> GrabType { + self.start_data.type_() + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + if let GrabStartData::TabletTool { tool, .. } = &self.start_data { + Some(tool) + } else { + None } } } diff --git a/src/shell/grabs/mod.rs b/src/shell/grabs/mod.rs index 515916fd..9524f425 100644 --- a/src/shell/grabs/mod.rs +++ b/src/shell/grabs/mod.rs @@ -1,18 +1,26 @@ use calloop::LoopHandle; use cosmic_settings_config::shortcuts; use smithay::{ + backend::input::{InputTime, TabletToolDescriptor}, input::{ Seat, pointer::{ - AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, - RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, + MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, + }, + tablet::tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, GrabStartData as TabletGrabStartData, + MotionEvent as TabletMotionEvent, ProximityOutEvent, TabletToolGrab, + TabletToolInnerHandle, UpEvent as TabletUpEvent, }, touch::{ - DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, - OrientationEvent, ShapeEvent, TouchGrab, TouchInnerHandle, UpEvent, + DownEvent as TouchDownEvent, GrabStartData as TouchGrabStartData, + MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchGrab, + TouchInnerHandle, UpEvent as TouchUpEvent, }, }, output::Output, @@ -39,6 +47,17 @@ use super::{ pub enum GrabStartData { Touch(TouchGrabStartData), Pointer(PointerGrabStartData), + TabletTool { + tool: TabletToolDescriptor, + data: TabletGrabStartData, + }, +} + +#[derive(Debug, Clone)] +pub enum GrabType { + Touch, + Pointer, + TabletTool, } impl GrabStartData { @@ -46,6 +65,7 @@ impl GrabStartData { match self { Self::Touch(touch) => touch.focus.as_ref(), Self::Pointer(pointer) => pointer.focus.as_ref(), + Self::TabletTool { data, .. } => data.focus.as_ref(), } } @@ -53,6 +73,7 @@ impl GrabStartData { match self { Self::Touch(touch) => touch.focus = focus, Self::Pointer(pointer) => pointer.focus = focus, + Self::TabletTool { data, .. } => data.focus = focus, } } @@ -60,6 +81,7 @@ impl GrabStartData { match self { Self::Touch(touch) => touch.location, Self::Pointer(pointer) => pointer.location, + Self::TabletTool { data, .. } => data.location, } } @@ -67,6 +89,7 @@ impl GrabStartData { match self { Self::Touch(touch) => touch.location = location, Self::Pointer(pointer) => pointer.location = location, + Self::TabletTool { data, .. } => data.location = location, } } @@ -76,6 +99,14 @@ impl GrabStartData { ((new.x - old.x).powi(2) + (new.y - old.y).powi(2)).sqrt() } + + pub fn type_(&self) -> GrabType { + match self { + Self::Pointer(_) => GrabType::Pointer, + Self::Touch(_) => GrabType::Touch, + Self::TabletTool { .. } => GrabType::TabletTool, + } + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -203,10 +234,17 @@ impl From for ResizeGrab { } impl ResizeGrab { - pub fn is_touch_grab(&self) -> bool { + pub fn grab_type(&self) -> GrabType { match self { - ResizeGrab::Floating(grab) => grab.is_touch_grab(), - ResizeGrab::Tiling(grab) => grab.is_touch_grab(), + ResizeGrab::Floating(grab) => grab.grab_type(), + ResizeGrab::Tiling(grab) => grab.grab_type(), + } + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + match self { + ResizeGrab::Floating(grab) => grab.tool(), + ResizeGrab::Tiling(grab) => grab.tool(), } } } @@ -242,11 +280,11 @@ impl PointerGrab for ResizeGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { match self { - ResizeGrab::Floating(grab) => grab.button(data, handle, event), - ResizeGrab::Tiling(grab) => grab.button(data, handle, event), + ResizeGrab::Floating(grab) => PointerGrab::button(grab, data, handle, event), + ResizeGrab::Tiling(grab) => PointerGrab::button(grab, data, handle, event), } } @@ -254,11 +292,11 @@ impl PointerGrab for ResizeGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { match self { - ResizeGrab::Floating(grab) => grab.axis(data, handle, details), - ResizeGrab::Tiling(grab) => grab.axis(data, handle, details), + ResizeGrab::Floating(grab) => PointerGrab::axis(grab, data, handle, details), + ResizeGrab::Tiling(grab) => PointerGrab::axis(grab, data, handle, details), } } @@ -386,7 +424,7 @@ impl TouchGrab for ResizeGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, focus: Option<(PointerFocusTarget, Point)>, - event: &DownEvent, + event: &TouchDownEvent, ) { match self { ResizeGrab::Floating(grab) => TouchGrab::down(grab, data, handle, focus, event), @@ -394,7 +432,12 @@ impl TouchGrab for ResizeGrab { } } - fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) { + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &TouchUpEvent, + ) { match self { ResizeGrab::Floating(grab) => TouchGrab::up(grab, data, handle, event), ResizeGrab::Tiling(grab) => TouchGrab::up(grab, data, handle, event), @@ -467,6 +510,107 @@ impl TouchGrab for ResizeGrab { } } +impl TabletToolGrab for ResizeGrab { + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::down(grab, data, handle, event), + ResizeGrab::Tiling(grab) => TabletToolGrab::down(grab, data, handle, event), + } + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::up(grab, data, handle, event), + ResizeGrab::Tiling(grab) => TabletToolGrab::up(grab, data, handle, event), + } + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(PointerFocusTarget, Point)>, + event: &TabletMotionEvent, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::motion(grab, data, handle, focus, event), + ResizeGrab::Tiling(grab) => TabletToolGrab::motion(grab, data, handle, focus, event), + } + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + serial: InputTime, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::frame(grab, data, handle, serial), + ResizeGrab::Tiling(grab) => TabletToolGrab::frame(grab, data, handle, serial), + } + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::button(grab, data, handle, event), + ResizeGrab::Tiling(grab) => TabletToolGrab::button(grab, data, handle, event), + } + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + details: TabletAxisFrame, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::axis(grab, data, handle, details), + ResizeGrab::Tiling(grab) => TabletToolGrab::axis(grab, data, handle, details), + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::proximity_out(grab, data, handle, event), + ResizeGrab::Tiling(grab) => TabletToolGrab::proximity_out(grab, data, handle, event), + } + } + + fn start_data(&self) -> &TabletGrabStartData { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::start_data(grab), + ResizeGrab::Tiling(grab) => TabletToolGrab::start_data(grab), + } + } + + fn unset(&mut self, data: &mut State) { + match self { + ResizeGrab::Floating(grab) => TabletToolGrab::unset(grab, data), + ResizeGrab::Tiling(grab) => TabletToolGrab::unset(grab, data), + } + } +} + pub enum MoveGrab { Move(moving::MoveGrab), Delayed(delay::DelayGrab), @@ -536,10 +680,17 @@ impl MoveGrab { } } - pub fn is_touch_grab(&self) -> bool { + pub fn grab_type(&self) -> GrabType { match self { - MoveGrab::Move(m) => m.is_touch_grab(), - MoveGrab::Delayed(d) => d.is_touch_grab(), + MoveGrab::Move(m) => m.grab_type(), + MoveGrab::Delayed(d) => d.grab_type(), + } + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + match self { + MoveGrab::Move(m) => m.tool(), + MoveGrab::Delayed(d) => d.tool(), } } } @@ -574,11 +725,11 @@ impl PointerGrab for MoveGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { match self { - MoveGrab::Move(grab) => grab.button(data, handle, event), - MoveGrab::Delayed(grab) => grab.button(data, handle, event), + MoveGrab::Move(grab) => PointerGrab::button(grab, data, handle, event), + MoveGrab::Delayed(grab) => PointerGrab::button(grab, data, handle, event), } } @@ -586,11 +737,11 @@ impl PointerGrab for MoveGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { match self { - MoveGrab::Move(grab) => grab.axis(data, handle, details), - MoveGrab::Delayed(grab) => grab.axis(data, handle, details), + MoveGrab::Move(grab) => PointerGrab::axis(grab, data, handle, details), + MoveGrab::Delayed(grab) => PointerGrab::axis(grab, data, handle, details), } } @@ -718,7 +869,7 @@ impl TouchGrab for MoveGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, focus: Option<(PointerFocusTarget, Point)>, - event: &DownEvent, + event: &TouchDownEvent, ) { match self { MoveGrab::Move(grab) => TouchGrab::down(grab, data, handle, focus, event), @@ -726,7 +877,12 @@ impl TouchGrab for MoveGrab { } } - fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) { + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &TouchUpEvent, + ) { match self { MoveGrab::Move(grab) => TouchGrab::up(grab, data, handle, event), MoveGrab::Delayed(grab) => TouchGrab::up(grab, data, handle, event), @@ -798,3 +954,104 @@ impl TouchGrab for MoveGrab { } } } + +impl TabletToolGrab for MoveGrab { + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::down(grab, data, handle, event), + MoveGrab::Delayed(grab) => TabletToolGrab::down(grab, data, handle, event), + } + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::up(grab, data, handle, event), + MoveGrab::Delayed(grab) => TabletToolGrab::up(grab, data, handle, event), + } + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(PointerFocusTarget, Point)>, + event: &TabletMotionEvent, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::motion(grab, data, handle, focus, event), + MoveGrab::Delayed(grab) => TabletToolGrab::motion(grab, data, handle, focus, event), + } + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + serial: InputTime, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::frame(grab, data, handle, serial), + MoveGrab::Delayed(grab) => TabletToolGrab::frame(grab, data, handle, serial), + } + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::button(grab, data, handle, event), + MoveGrab::Delayed(grab) => TabletToolGrab::button(grab, data, handle, event), + } + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + details: TabletAxisFrame, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::axis(grab, data, handle, details), + MoveGrab::Delayed(grab) => TabletToolGrab::axis(grab, data, handle, details), + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::proximity_out(grab, data, handle, event), + MoveGrab::Delayed(grab) => TabletToolGrab::proximity_out(grab, data, handle, event), + } + } + + fn start_data(&self) -> &TabletGrabStartData { + match self { + MoveGrab::Move(grab) => TabletToolGrab::start_data(grab), + MoveGrab::Delayed(grab) => TabletToolGrab::start_data(grab), + } + } + + fn unset(&mut self, data: &mut State) { + match self { + MoveGrab::Move(grab) => TabletToolGrab::unset(grab, data), + MoveGrab::Delayed(grab) => TabletToolGrab::unset(grab, data), + } + } +} diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 05923bc7..15225212 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -8,6 +8,7 @@ use crate::{ CosmicMapped, CosmicSurface, Direction, ManagedLayer, element::{CosmicMappedRenderElement, stack_hover::StackHover}, focus::target::{KeyboardFocusTarget, PointerFocusTarget}, + grabs::GrabType, layout::floating::TiledCorners, }, utils::prelude::*, @@ -20,7 +21,7 @@ use smallvec::SmallVec; use smithay::{ backend::{ drm::DrmNode, - input::{ButtonState, InputTime}, + input::{ButtonState, InputTime, TabletToolDescriptor}, renderer::{ ImportAll, ImportMem, element::{RenderElement, utils::RescaleRenderElement}, @@ -30,13 +31,27 @@ use smithay::{ input::{ Seat, pointer::{ - AxisFrame, ButtonEvent, CursorIcon, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, CursorIcon, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, + MotionEvent as PointerMotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, }, - touch::{self, GrabStartData as TouchGrabStartData, TouchGrab, TouchInnerHandle}, + tablet::{ + TabletSeatHandler, + tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, GrabStartData as TabletGrabStartData, + MotionEvent as TabletMotionEvent, ProximityInEvent, ProximityOutEvent, + TabletToolGrab, TabletToolInnerHandle, UpEvent as TabletUpEvent, + }, + }, + touch::{ + DownEvent as TouchDownEvent, GrabStartData as TouchGrabStartData, + MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchGrab, + TouchInnerHandle, UpEvent as TouchUpEvent, + }, }, output::Output, utils::{IsAlive, Logical, Point, Rectangle, SERIAL_COUNTER, Scale}, @@ -503,7 +518,7 @@ impl PointerGrab for MoveGrab { state: &mut State, handle: &mut PointerInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &MotionEvent, + event: &PointerMotionEvent, ) { self.update_location(state, event.location); @@ -529,7 +544,7 @@ impl PointerGrab for MoveGrab { &mut self, state: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { handle.button(state, event); match self.release { @@ -550,7 +565,7 @@ impl PointerGrab for MoveGrab { &mut self, state: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { handle.axis(state, details); } @@ -647,7 +662,7 @@ impl TouchGrab for MoveGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &touch::DownEvent, + event: &TouchDownEvent, ) { handle.down(data, None, event) } @@ -656,7 +671,7 @@ impl TouchGrab for MoveGrab { &mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, - event: &touch::UpEvent, + event: &TouchUpEvent, ) { if event.slot == >::start_data(self).slot { handle.unset_grab(self, data); @@ -670,7 +685,7 @@ impl TouchGrab for MoveGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &touch::MotionEvent, + event: &TouchMotionEvent, ) { if event.slot == >::start_data(self).slot { self.update_location(data, event.location); @@ -691,7 +706,7 @@ impl TouchGrab for MoveGrab { &mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, - event: &touch::ShapeEvent, + event: &ShapeEvent, ) { handle.shape(data, event) } @@ -700,7 +715,7 @@ impl TouchGrab for MoveGrab { &mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, - event: &touch::OrientationEvent, + event: &OrientationEvent, ) { handle.orientation(data, event) } @@ -715,6 +730,100 @@ impl TouchGrab for MoveGrab { fn unset(&mut self, _data: &mut State) {} } +impl TabletToolGrab for MoveGrab { + fn start_data(&self) -> &TabletGrabStartData { + match &self.start_data { + GrabStartData::TabletTool { data, .. } => data, + _ => unreachable!(), + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + handle.proximity_out(data, event); + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + _focus: Option<(::ToolFocus, Point)>, + event: &TabletMotionEvent, + ) { + handle.motion(data, None, event); + + self.update_location(data, event.location); + if !self.window.alive() { + handle.unset_grab(self, data, event.serial, event.time, true); + } + } + + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + handle.down(data, event) + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + if self.tool().is_some_and(|tool| tool == handle.descriptor()) { + handle.unset_grab(self, data, event.serial, event.time, false); + } + + handle.up(data, event); + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + handle.button(data, event) + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + frame: TabletAxisFrame, + ) { + handle.axis(data, frame) + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + time: InputTime, + ) { + handle.frame(data, time) + } + + fn proximity_in( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(::ToolFocus, Point)>, + event: &ProximityInEvent, + ) { + handle.proximity_in(data, focus, event); + } + + fn unset(&mut self, _data: &mut State) {} +} + impl MoveGrab { pub fn new( start_data: GrabStartData, @@ -778,10 +887,15 @@ impl MoveGrab { self.previous == ManagedLayer::Tiling } - pub fn is_touch_grab(&self) -> bool { - match self.start_data { - GrabStartData::Touch(_) => true, - GrabStartData::Pointer(_) => false, + pub fn grab_type(&self) -> GrabType { + self.start_data.type_() + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + if let GrabStartData::TabletTool { tool, .. } = &self.start_data { + Some(tool) + } else { + None } } } @@ -953,7 +1067,7 @@ impl Drop for MoveGrab { position.as_logical().to_f64() - window.geometry().loc.to_f64() + offset, )), - &MotionEvent { + &PointerMotionEvent { location: pointer.current_location(), serial, time: InputTime::now(), diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index f9e5cbfd..9d767671 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -7,25 +7,36 @@ use crate::{ shell::{ element::CosmicMapped, focus::target::PointerFocusTarget, - grabs::{GrabStartData, ReleaseMode, ResizeEdge}, + grabs::{GrabStartData, GrabType, ReleaseMode, ResizeEdge}, }, utils::prelude::*, }; use smithay::{ - backend::input::ButtonState, + backend::input::{ButtonState, InputTime, TabletToolDescriptor}, desktop::{WindowSurface, space::SpaceElement}, input::{ Seat, pointer::{ - AxisFrame, ButtonEvent, CursorIcon, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, CursorIcon, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, + MotionEvent as PointerMotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, }, + tablet::{ + TabletSeatHandler, + tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, GrabStartData as TabletGrabStartData, + MotionEvent as TabletMotionEvent, ProximityInEvent, ProximityOutEvent, + TabletToolGrab, TabletToolInnerHandle, UpEvent as TabletUpEvent, + }, + }, touch::{ - DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, - OrientationEvent, ShapeEvent, TouchGrab, TouchInnerHandle, UpEvent, + DownEvent as TouchDownEvent, GrabStartData as TouchGrabStartData, + MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchGrab, + TouchInnerHandle, UpEvent as TouchUpEvent, }, }, output::Output, @@ -170,10 +181,19 @@ impl ResizeSurfaceGrab { false } - pub fn is_touch_grab(&self) -> bool { + pub fn grab_type(&self) -> GrabType { match self.start_data { - GrabStartData::Touch(_) => true, - GrabStartData::Pointer(_) => false, + GrabStartData::Pointer(_) => GrabType::Pointer, + GrabStartData::Touch(_) => GrabType::Touch, + GrabStartData::TabletTool { .. } => GrabType::TabletTool, + } + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + if let GrabStartData::TabletTool { tool, .. } = &self.start_data { + Some(tool) + } else { + None } } } @@ -184,7 +204,7 @@ impl PointerGrab for ResizeSurfaceGrab { data: &mut State, handle: &mut PointerInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &MotionEvent, + event: &PointerMotionEvent, ) { // While the grab is active, no client has pointer focus handle.motion(data, None, event); @@ -209,7 +229,7 @@ impl PointerGrab for ResizeSurfaceGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { handle.button(data, event); match self.release { @@ -230,7 +250,7 @@ impl PointerGrab for ResizeSurfaceGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { handle.axis(data, details) } @@ -329,12 +349,17 @@ impl TouchGrab for ResizeSurfaceGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &DownEvent, + event: &TouchDownEvent, ) { handle.down(data, None, event) } - fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) { + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &TouchUpEvent, + ) { if event.slot == >::start_data(self).slot { handle.unset_grab(self, data); } @@ -396,6 +421,99 @@ impl TouchGrab for ResizeSurfaceGrab { } } +impl TabletToolGrab for ResizeSurfaceGrab { + fn start_data(&self) -> &TabletGrabStartData { + match &self.start_data { + GrabStartData::TabletTool { data, .. } => data, + _ => unreachable!(), + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + handle.unset_grab(self, data, event.serial, event.time, true); + handle.proximity_out(data, event); + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + _focus: Option<(::ToolFocus, Point)>, + event: &TabletMotionEvent, + ) { + if self.update_location(event.location.as_global()) { + handle.unset_grab(self, data, event.serial, event.time, true); + } + + handle.motion(data, None, event); + } + + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + handle.down(data, event) + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + handle.unset_grab(self, data, event.serial, event.time, true); + handle.up(data, event); + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + handle.button(data, event) + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + frame: TabletAxisFrame, + ) { + handle.axis(data, frame) + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + time: InputTime, + ) { + handle.frame(data, time) + } + + fn unset(&mut self, _data: &mut State) { + self.ungrab() + } + + fn proximity_in( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + _focus: Option<(::ToolFocus, Point)>, + event: &ProximityInEvent, + ) { + handle.proximity_in(data, None, event); + } +} + pub struct ResizeGrabMarker(AtomicBool); impl ResizeGrabMarker { diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 91873793..b6452168 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -1,34 +1,47 @@ // SPDX-License-Identifier: GPL-3.0-only +use std::cell::Cell; + use crate::{ backend::render::cursor::CursorState, shell::{ focus::target::PointerFocusTarget, - grabs::{GrabStartData, ReleaseMode}, + grabs::{GrabStartData, GrabType, ReleaseMode}, layout::Orientation, }, utils::prelude::*, }; use id_tree::{NodeId, Tree}; use smithay::{ - backend::input::{ButtonState, InputTime}, + backend::input::{ButtonState, InputTime, TabletToolDescriptor}, input::{ Seat, pointer::{ - AxisFrame, ButtonEvent, CursorIcon, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, - PointerTarget, RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, CursorIcon, Focus, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, + MotionEvent as PointerMotionEvent, PointerGrab, PointerInnerHandle, PointerTarget, + RelativeMotionEvent, + }, + tablet::{ + Tablet, TabletSeatHandler, TabletSeatTrait, + tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, GrabStartData as TabletToolGrabStartData, + GrabTrigger as TabletToolGrabTrigger, MotionEvent as TabletMotionEvent, + ProximityInEvent, ProximityOutEvent, TabletToolGrab, TabletToolInnerHandle, + TabletToolTarget, UpEvent as TabletUpEvent, + }, }, touch::{ - DownEvent, FrameMarker, GrabStartData as TouchGrabStartData, + DownEvent as TouchDownEvent, FrameMarker, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, TouchGrab, - TouchInnerHandle, TouchTarget, UpEvent, + TouchInnerHandle, TouchTarget, UpEvent as TouchUpEvent, }, }, output::WeakOutput, - utils::{IsAlive, Logical, Point}, + utils::{IsAlive, Logical, Point, Serial}, }; use super::super::{Data, TilingLayout}; @@ -39,6 +52,7 @@ pub struct ResizeForkTarget { pub output: WeakOutput, pub left_up_idx: usize, pub orientation: Orientation, + pub last_tablet_location: Cell>>, } impl IsAlive for ResizeForkTarget { @@ -48,7 +62,7 @@ impl IsAlive for ResizeForkTarget { } impl PointerTarget for ResizeForkTarget { - fn enter(&self, seat: &Seat, _data: &mut State, _event: &MotionEvent) { + fn enter(&self, seat: &Seat, _data: &mut State, _event: &PointerMotionEvent) { let user_data = seat.user_data(); let cursor_state = user_data.get::().unwrap(); cursor_state @@ -60,19 +74,13 @@ impl PointerTarget for ResizeForkTarget { }); } - fn leave( - &self, - seat: &Seat, - _data: &mut State, - _serial: smithay::utils::Serial, - _time: InputTime, - ) { + fn leave(&self, seat: &Seat, _data: &mut State, _serial: Serial, _time: InputTime) { let user_data = seat.user_data(); let cursor_state = user_data.get::().unwrap(); cursor_state.lock().unwrap().unset_shape(); } - fn button(&self, seat: &Seat, data: &mut State, event: &ButtonEvent) { + fn button(&self, seat: &Seat, data: &mut State, event: &PointerButtonEvent) { if event.button == 0x110 && event.state == ButtonState::Pressed { let seat = seat.clone(); let node = self.node.clone(); @@ -106,7 +114,7 @@ impl PointerTarget for ResizeForkTarget { } } - fn motion(&self, _seat: &Seat, _data: &mut State, _event: &MotionEvent) {} + fn motion(&self, _seat: &Seat, _data: &mut State, _event: &PointerMotionEvent) {} fn relative_motion( &self, _seat: &Seat, @@ -114,7 +122,7 @@ impl PointerTarget for ResizeForkTarget { _event: &RelativeMotionEvent, ) { } - fn axis(&self, _seat: &Seat, _data: &mut State, _frame: AxisFrame) {} + fn axis(&self, _seat: &Seat, _data: &mut State, _frame: PointerAxisFrame) {} fn frame(&self, _seat: &Seat, _data: &mut State) {} fn gesture_swipe_begin(&self, _: &Seat, _: &mut State, _: &GestureSwipeBeginEvent) {} fn gesture_swipe_update(&self, _: &Seat, _: &mut State, _: &GestureSwipeUpdateEvent) {} @@ -127,7 +135,7 @@ impl PointerTarget for ResizeForkTarget { } impl TouchTarget for ResizeForkTarget { - fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent) { + fn down(&self, seat: &Seat, data: &mut State, event: &TouchDownEvent) { let seat = seat.clone(); let node = self.node.clone(); let output = self.output.clone(); @@ -158,7 +166,7 @@ impl TouchTarget for ResizeForkTarget { }); } - fn up(&self, _seat: &Seat, _data: &mut State, _event: &UpEvent) {} + fn up(&self, _seat: &Seat, _data: &mut State, _event: &TouchUpEvent) {} fn motion(&self, _seat: &Seat, _data: &mut State, _event: &TouchMotionEvent) {} fn frame(&self, _seat: &Seat, _data: &mut State, _frame: FrameMarker) {} fn cancel(&self, _seat: &Seat, _data: &mut State, _frame: FrameMarker) {} @@ -169,6 +177,113 @@ impl TouchTarget for ResizeForkTarget { } } +impl TabletToolTarget for ResizeForkTarget { + fn down( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &TabletDownEvent, + ) { + let seat = seat.clone(); + let node = self.node.clone(); + let output = self.output.clone(); + let left_up_idx = self.left_up_idx; + let orientation = self.orientation; + let serial = event.serial; + let time = event.time; + let tool = tool_descriptor.clone(); + let Some(location) = self.last_tablet_location.take() else { + return; + }; + data.common.event_loop_handle.insert_idle(move |state| { + let tablet = seat.tablet_seat().get_tool(&tool).unwrap(); + tablet.set_grab( + state, + ResizeForkGrab::new( + GrabStartData::TabletTool { + tool, + data: TabletToolGrabStartData { + focus: None, + location: location.as_logical(), + trigger: TabletToolGrabTrigger::Tip, + }, + }, + location, + node, + left_up_idx, + orientation, + output, + ReleaseMode::NoMouseButtons, + ), + time, + serial, + Focus::Keep, + ) + }); + } + fn motion( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + event: &TabletMotionEvent, + ) { + self.last_tablet_location + .set(Some(event.location.as_global())) + } + fn proximity_out( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + ) { + self.last_tablet_location.set(None); + } + + fn proximity_in( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + _tablet: &Tablet, + _serial: Serial, + ) { + } + fn up( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + _event: &TabletUpEvent, + ) { + } + fn axis( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + _frame: TabletAxisFrame, + ) { + } + fn button( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + _event: &TabletButtonEvent, + ) { + } + fn frame( + &self, + _seat: &Seat, + _data: &mut State, + _tool_descriptor: &TabletToolDescriptor, + _time: InputTime, + ) { + } +} + pub struct ResizeForkGrab { start_data: GrabStartData, last_loc: Point, @@ -338,10 +453,19 @@ impl ResizeForkGrab { false } - pub fn is_touch_grab(&self) -> bool { + pub fn grab_type(&self) -> GrabType { match self.start_data { - GrabStartData::Touch(_) => true, - GrabStartData::Pointer(_) => false, + GrabStartData::Pointer(_) => GrabType::Pointer, + GrabStartData::Touch(_) => GrabType::Touch, + GrabStartData::TabletTool { .. } => GrabType::TabletTool, + } + } + + pub fn tool(&self) -> Option<&TabletToolDescriptor> { + if let GrabStartData::TabletTool { tool, .. } = &self.start_data { + Some(tool) + } else { + None } } } @@ -352,7 +476,7 @@ impl PointerGrab for ResizeForkGrab { data: &mut State, handle: &mut PointerInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &MotionEvent, + event: &PointerMotionEvent, ) { // While the grab is active, no client has pointer focus handle.motion(data, None, event); @@ -377,7 +501,7 @@ impl PointerGrab for ResizeForkGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { handle.button(data, event); match self.release { @@ -398,7 +522,7 @@ impl PointerGrab for ResizeForkGrab { &mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>, - details: AxisFrame, + details: PointerAxisFrame, ) { handle.axis(data, details) } @@ -497,12 +621,17 @@ impl TouchGrab for ResizeForkGrab { data: &mut State, handle: &mut TouchInnerHandle<'_, State>, _focus: Option<(PointerFocusTarget, Point)>, - event: &DownEvent, + event: &TouchDownEvent, ) { handle.down(data, None, event) } - fn up(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, event: &UpEvent) { + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &TouchUpEvent, + ) { if event.slot == >::start_data(self).slot { handle.unset_grab(self, data); } @@ -563,3 +692,96 @@ impl TouchGrab for ResizeForkGrab { self.update_location(data, self.last_loc.as_logical(), true); } } + +impl TabletToolGrab for ResizeForkGrab { + fn start_data(&self) -> &TabletToolGrabStartData { + match &self.start_data { + GrabStartData::TabletTool { data, .. } => data, + _ => unreachable!(), + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + handle.proximity_out(data, event); + handle.unset_grab(self, data, event.serial, event.time, true); + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + _focus: Option<(::ToolFocus, Point)>, + event: &TabletMotionEvent, + ) { + handle.motion(data, None, event); + + if self.update_location(data, event.location, false) { + handle.unset_grab(self, data, event.serial, event.time, true); + } + } + + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletDownEvent, + ) { + handle.down(data, event); + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletUpEvent, + ) { + handle.up(data, event); + handle.unset_grab(self, data, event.serial, event.time, true); + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &TabletButtonEvent, + ) { + handle.button(data, event) + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + frame: TabletAxisFrame, + ) { + handle.axis(data, frame) + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + time: InputTime, + ) { + handle.frame(data, time) + } + + fn unset(&mut self, data: &mut State) { + self.update_location(data, self.last_loc.as_logical(), true); + } + + fn proximity_in( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(::ToolFocus, Point)>, + event: &ProximityInEvent, + ) { + handle.proximity_in(data, focus, event); + } +} diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 2d95cd27..2f694acd 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -67,6 +67,7 @@ use smithay::{ wayland::{compositor::add_blocker, seat::WaylandFocus}, }; use std::{ + cell::Cell, collections::{HashMap, VecDeque}, sync::{Arc, Weak}, time::{Duration, Instant}, @@ -3348,6 +3349,7 @@ impl TilingLayout { output: self.output.downgrade(), left_up_idx: idx, orientation, + last_tablet_location: Cell::new(None), } .into(), (last_geometry.loc @@ -3381,7 +3383,7 @@ impl TilingLayout { let Some(root) = tree.root_node_id() else { if matches!( overview.active_trigger(), - Some(Trigger::Pointer(_) | Trigger::Touch(_)) + Some(Trigger::Pointer(_) | Trigger::Touch(_) | Trigger::Tool(_, _)) ) && location_f64.is_some() { let mut tree = tree.copy_clone(); @@ -3414,7 +3416,7 @@ impl TilingLayout { if matches!( overview.active_trigger(), - Some(Trigger::Pointer(_) | Trigger::Touch(_)) + Some(Trigger::Pointer(_) | Trigger::Touch(_) | Trigger::Tool(_, _)) ) { let non_exclusive_zone = layer_map_for_output(&self.output) .non_exclusive_zone() @@ -4062,8 +4064,11 @@ impl TilingLayout { let draw_groups = overview.0.alpha(); let is_overview = !matches!(overview.0, OverviewMode::None); - let is_mouse_tiling = (matches!(overview.0.trigger(), Some(Trigger::Pointer(_)))) - .then(|| self.last_overview_hover.as_ref().map(|(_, zone)| zone)); + let is_mouse_tiling = (matches!( + overview.0.trigger(), + Some(Trigger::Pointer(_) | Trigger::Tool(_, _)) + )) + .then(|| self.last_overview_hover.as_ref().map(|(_, zone)| zone)); let swap_desc = if let Some(Trigger::KeyboardSwap(_, desc)) = overview.0.trigger() { Some(desc.clone()) } else { @@ -4216,8 +4221,11 @@ impl TilingLayout { }; let draw_groups = overview.0.alpha(); - let is_mouse_tiling = (matches!(overview.0.trigger(), Some(Trigger::Pointer(_)))) - .then(|| self.last_overview_hover.as_ref().map(|(_, zone)| zone)); + let is_mouse_tiling = (matches!( + overview.0.trigger(), + Some(Trigger::Pointer(_) | Trigger::Tool(_, _)) + )) + .then(|| self.last_overview_hover.as_ref().map(|(_, zone)| zone)); let swap_desc = if let Some(Trigger::KeyboardSwap(_, desc)) = overview.0.trigger() { Some(desc.clone()) } else { diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 3fa863d3..b10d9d63 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -32,7 +32,10 @@ use cosmic_settings_config::shortcuts::action::{Direction, FocusDirection, Resiz use cosmic_settings_config::{shortcuts, window_rules::ApplicationException}; use keyframe::{ease, functions::EaseInOutCubic}; use smithay::{ - backend::{input::TouchSlot, renderer::element::RenderElementStates}, + backend::{ + input::{TabletToolDescriptor, TouchSlot}, + renderer::element::RenderElementStates, + }, desktop::{ LayerSurface, PopupKind, WindowSurface, WindowSurfaceType, layer_map_for_output, space::SpaceElement, @@ -46,6 +49,7 @@ use smithay::{ pointer::{ CursorImageStatus, CursorImageSurfaceData, Focus, GrabStartData as PointerGrabStartData, }, + tablet::tool::GrabTrigger as TabletGrabTrigger, }, output::{Output, WeakOutput}, reexports::{ @@ -130,6 +134,7 @@ pub enum Trigger { KeyboardMove(shortcuts::Modifiers), Pointer(u32), Touch(TouchSlot), + Tool(TabletToolDescriptor, TabletGrabTrigger), } #[derive(Debug, Clone)] @@ -1755,7 +1760,7 @@ impl Shell { if let Some(set) = self.workspaces.sets.get_mut(output) { if matches!( self.overview_mode.active_trigger(), - Some(Trigger::Pointer(_) | Trigger::Touch(_)) + Some(Trigger::Pointer(_) | Trigger::Touch(_) | Trigger::Tool(_, _)) ) { set.workspaces[set.active].tiling_layer.cleanup_drag(); } @@ -1806,7 +1811,7 @@ impl Shell { if let Some(set) = self.workspaces.sets.get_mut(output) { if matches!( self.overview_mode.active_trigger(), - Some(Trigger::Pointer(_) | Trigger::Touch(_)) + Some(Trigger::Pointer(_) | Trigger::Touch(_) | Trigger::Tool(_, _)) ) { set.workspaces[set.active].tiling_layer.cleanup_drag(); } @@ -3840,6 +3845,7 @@ impl Shell { let trigger = match &start_data { GrabStartData::Pointer(start_data) => Trigger::Pointer(start_data.button), GrabStartData::Touch(start_data) => Trigger::Touch(start_data.slot), + GrabStartData::TabletTool { tool, data } => Trigger::Tool(tool.clone(), data.trigger), }; let active_hint = if config.cosmic_conf.active_hint { self.theme.cosmic().active_hint as u8 diff --git a/src/shell/zoom.rs b/src/shell/zoom.rs index cfe84f06..b3a795e7 100644 --- a/src/shell/zoom.rs +++ b/src/shell/zoom.rs @@ -11,19 +11,31 @@ use cosmic_comp_config::{ZoomConfig, ZoomMovement}; use cosmic_config::ConfigSet; use keyframe::{ease, functions::Linear}; use smithay::{ - backend::{input::InputTime, renderer::ImportMem}, + backend::{ + input::{InputTime, TabletToolDescriptor}, + renderer::ImportMem, + }, desktop::space::SpaceElement, input::{ Seat, pointer::{ - AxisFrame, ButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, - MotionEvent as PointerMotionEvent, PointerTarget, RelativeMotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, Focus, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, + PointerTarget, RelativeMotionEvent, + }, + tablet::{ + Tablet, TabletSeatTrait, + tool::{ + AxisFrame as TabletAxisFrame, ButtonEvent as TabletButtonEvent, + DownEvent as TabletDownEvent, MotionEvent as TabletMotionEvent, TabletToolTarget, + UpEvent as TabletUpEvent, + }, }, touch::{ - DownEvent, FrameMarker, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, - TouchTarget, UpEvent, + DownEvent as TouchDownEvent, FrameMarker, MotionEvent as TouchMotionEvent, + OrientationEvent, ShapeEvent, TouchTarget, UpEvent as TouchUpEvent, }, }, output::Output, @@ -33,6 +45,7 @@ use tracing::error; use crate::{ backend::render::element::AsGlowRenderer, + shell::grabs::GrabType, state::State, utils::{ iced::{IcedElement, IcedRenderElement, Program}, @@ -698,15 +711,27 @@ impl Program for ZoomProgram { ); std::mem::drop(shell); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer().unwrap().set_grab( + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat.get_pointer().unwrap().set_grab( state, grab, serial, Focus::Clear, - ); + ), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab( + state, + grab, + InputTime::now(), + serial, + Focus::Clear, + ), } } } @@ -785,15 +810,27 @@ impl Program for ZoomProgram { ); std::mem::drop(shell); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer().unwrap().set_grab( + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch().unwrap().set_grab(state, grab, serial) + } + GrabType::Pointer => seat.get_pointer().unwrap().set_grab( state, grab, serial, Focus::Clear, - ); + ), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab( + state, + grab, + InputTime::now(), + serial, + Focus::Clear, + ), } } } @@ -883,14 +920,14 @@ impl PointerTarget for ZoomFocusTarget { } } - fn button(&self, seat: &Seat, data: &mut State, event: &ButtonEvent) { + fn button(&self, seat: &Seat, data: &mut State, event: &PointerButtonEvent) { match self { ZoomFocusTarget::Main(elem) => PointerTarget::button(elem, seat, data, event), ZoomFocusTarget::Menu(elem) => PointerTarget::button(elem, seat, data, event), } } - fn axis(&self, seat: &Seat, data: &mut State, frame: AxisFrame) { + fn axis(&self, seat: &Seat, data: &mut State, frame: PointerAxisFrame) { match self { ZoomFocusTarget::Main(elem) => PointerTarget::axis(elem, seat, data, frame), ZoomFocusTarget::Menu(elem) => PointerTarget::axis(elem, seat, data, frame), @@ -1032,14 +1069,14 @@ impl PointerTarget for ZoomFocusTarget { } impl TouchTarget for ZoomFocusTarget { - fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent) { + fn down(&self, seat: &Seat, data: &mut State, event: &TouchDownEvent) { match self { ZoomFocusTarget::Main(elem) => TouchTarget::down(elem, seat, data, event), ZoomFocusTarget::Menu(elem) => TouchTarget::down(elem, seat, data, event), } } - fn up(&self, seat: &Seat, data: &mut State, event: &UpEvent) { + fn up(&self, seat: &Seat, data: &mut State, event: &TouchUpEvent) { match self { ZoomFocusTarget::Main(elem) => TouchTarget::up(elem, seat, data, event), ZoomFocusTarget::Menu(elem) => TouchTarget::up(elem, seat, data, event), @@ -1089,6 +1126,144 @@ impl TouchTarget for ZoomFocusTarget { } } +impl TabletToolTarget for ZoomFocusTarget { + fn proximity_in( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + tablet: &Tablet, + serial: Serial, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::proximity_in(elem, seat, data, tool_descriptor, tablet, serial) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::proximity_in(elem, seat, data, tool_descriptor, tablet, serial) + } + } + } + + fn proximity_out( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::proximity_out(elem, seat, data, tool_descriptor) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::proximity_out(elem, seat, data, tool_descriptor) + } + } + } + + fn down( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &TabletDownEvent, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::down(elem, seat, data, tool_descriptor, event) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::down(elem, seat, data, tool_descriptor, event) + } + } + } + + fn up( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &TabletUpEvent, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::up(elem, seat, data, tool_descriptor, event) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::up(elem, seat, data, tool_descriptor, event) + } + } + } + + fn motion( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &TabletMotionEvent, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::motion(elem, seat, data, tool_descriptor, event) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::motion(elem, seat, data, tool_descriptor, event) + } + } + } + + fn axis( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + frame: TabletAxisFrame, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::axis(elem, seat, data, tool_descriptor, frame) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::axis(elem, seat, data, tool_descriptor, frame) + } + } + } + + fn button( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + event: &TabletButtonEvent, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::button(elem, seat, data, tool_descriptor, event) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::button(elem, seat, data, tool_descriptor, event) + } + } + } + + fn frame( + &self, + seat: &Seat, + data: &mut State, + tool_descriptor: &TabletToolDescriptor, + time: InputTime, + ) { + match self { + ZoomFocusTarget::Main(elem) => { + TabletToolTarget::frame(elem, seat, data, tool_descriptor, time) + } + ZoomFocusTarget::Menu(elem) => { + TabletToolTarget::frame(elem, seat, data, tool_descriptor, time) + } + } + } +} + impl IsAlive for ZoomFocusTarget { fn alive(&self) -> bool { match self { diff --git a/src/utils/iced/mod.rs b/src/utils/iced/mod.rs index 94b27ea7..8680bed3 100644 --- a/src/utils/iced/mod.rs +++ b/src/utils/iced/mod.rs @@ -31,7 +31,7 @@ use ordered_float::OrderedFloat; use smithay::{ backend::{ allocator::Fourcc, - input::{ButtonState, InputTime, KeyState}, + input::{ButtonState, InputTime, KeyState, TabletToolDescriptor}, renderer::{ ImportMem, element::{ @@ -45,14 +45,23 @@ use smithay::{ Seat, keyboard::{KeyboardTarget, KeysymHandle, ModifiersState}, pointer::{ - AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent, + AxisFrame as PointerAxisFrame, ButtonEvent as PointerButtonEvent, + GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, + GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, + GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, PointerTarget, RelativeMotionEvent, }, + tablet::{ + Tablet, + tool::{ + AxisFrame as ToolAxisFrame, ButtonEvent as ToolButtonEvent, + DownEvent as ToolDownEvent, MotionEvent as ToolMotionEvent, TabletToolTarget, + UpEvent as ToolUpEvent, + }, + }, touch::{ - DownEvent, FrameMarker, MotionEvent as TouchMotionEvent, OrientationEvent, ShapeEvent, - TouchTarget, UpEvent, + DownEvent as TouchDownEvent, FrameMarker, MotionEvent as TouchMotionEvent, + OrientationEvent, ShapeEvent, TouchTarget, UpEvent as TouchUpEvent, }, }, output::Output, @@ -189,6 +198,7 @@ pub(crate) struct IcedElementInternal { touch_map: HashMap, last_touch_frame: Option, last_touch_serial: Option, + last_tablet_serial: Option, // iced theme: Theme, @@ -240,6 +250,7 @@ impl Clone for IcedElementInternal

{ touch_map: self.touch_map.clone(), last_touch_frame: None, last_touch_serial: None, + last_tablet_serial: None, theme: self.theme.clone(), renderer, state, @@ -267,6 +278,7 @@ impl fmt::Debug for IcedElementInternal

{ .field("touch_map", &self.touch_map) .field("last_touch_frame", &self.last_touch_frame) .field("last_touch_serial", &self.last_touch_serial) + .field("last_tablet_serial", &self.last_tablet_serial) .field("theme", &"...") .field("renderer", &"...") .field("state", &"...") @@ -326,6 +338,7 @@ impl IcedElement

{ touch_map: HashMap::new(), last_touch_frame: None, last_touch_serial: None, + last_tablet_serial: None, theme, renderer, state, @@ -481,12 +494,141 @@ impl IcedElementInternal

{ } } +impl TabletToolTarget for IcedElement

{ + fn proximity_in( + &self, + _seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + _tablet: &Tablet, + _serial: Serial, + ) { + let mut internal = self.0.lock().unwrap(); + internal + .state + .queue_event(Event::Mouse(MouseEvent::CursorEntered)); + internal.update(false); + } + + fn proximity_out( + &self, + _seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + ) { + let mut internal = self.0.lock().unwrap(); + internal + .state + .queue_event(Event::Mouse(MouseEvent::CursorLeft)); + internal.update(false); + } + + fn down( + &self, + seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + event: &ToolDownEvent, + ) { + let mut internal = self.0.lock().unwrap(); + let id = Finger(0); + let Some(event_location) = internal.cursor_pos else { + return; + }; + let position = IcedPoint::new(event_location.x as f32, event_location.y as f32); + internal + .state + .queue_event(Event::Touch(TouchEvent::FingerPressed { id, position })); + internal.last_tablet_serial = Some(event.serial); + *internal.last_seat.lock().unwrap() = Some((seat.clone(), event.serial)); + internal.update(false); + } + + fn up( + &self, + seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + _event: &ToolUpEvent, + ) { + let mut internal = self.0.lock().unwrap(); + let id = Finger(0); + if let Some(event_location) = internal.cursor_pos { + *internal.last_seat.lock().unwrap() = + Some((seat.clone(), internal.last_tablet_serial.unwrap())); + let position = IcedPoint::new(event_location.x as f32, event_location.y as f32); + internal + .state + .queue_event(Event::Touch(TouchEvent::FingerLifted { id, position })); + internal.update(false); + } + } + + fn motion( + &self, + seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + event: &ToolMotionEvent, + ) { + let mut internal = self.0.lock().unwrap(); + let event_location = event.location.downscale(internal.additional_scale); + let position = IcedPoint::new(event_location.x as f32, event_location.y as f32); + internal + .state + .queue_event(Event::Mouse(MouseEvent::CursorMoved { position })); + internal.cursor_pos = Some(event_location); + *internal.last_seat.lock().unwrap() = Some((seat.clone(), event.serial)); + internal.update(false); + } + + fn axis( + &self, + _seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + _frame: ToolAxisFrame, + ) { + } + + fn button( + &self, + seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + event: &ToolButtonEvent, + ) { + let mut internal = self.0.lock().unwrap(); + let button = match event.button { + 0x110 => MouseButton::Left, + 0x111 => MouseButton::Right, + 0x112 => MouseButton::Middle, + x => MouseButton::Other(x as u16), + }; + internal.state.queue_event(Event::Mouse(match event.state { + ButtonState::Pressed => MouseEvent::ButtonPressed(button), + ButtonState::Released => MouseEvent::ButtonReleased(button), + })); + *internal.last_seat.lock().unwrap() = Some((seat.clone(), event.serial)); + internal.update(false); + } + + fn frame( + &self, + _seat: &Seat, + _data: &mut crate::state::State, + _tool_descriptor: &TabletToolDescriptor, + _time: InputTime, + ) { + } +} + impl PointerTarget for IcedElement

{ fn enter( &self, seat: &Seat, _data: &mut crate::state::State, - event: &MotionEvent, + event: &PointerMotionEvent, ) { let mut internal = self.0.lock().unwrap(); internal @@ -507,7 +649,7 @@ impl PointerTarget for IcedEle &self, seat: &Seat, _data: &mut crate::state::State, - event: &MotionEvent, + event: &PointerMotionEvent, ) { let mut internal = self.0.lock().unwrap(); let event_location = event.location.downscale(internal.additional_scale); @@ -532,7 +674,7 @@ impl PointerTarget for IcedEle &self, seat: &Seat, _data: &mut crate::state::State, - event: &ButtonEvent, + event: &PointerButtonEvent, ) { let mut internal = self.0.lock().unwrap(); let button = match event.button { @@ -553,7 +695,7 @@ impl PointerTarget for IcedEle &self, _seat: &Seat, _data: &mut crate::state::State, - frame: AxisFrame, + frame: PointerAxisFrame, ) { let mut internal = self.0.lock().unwrap(); internal @@ -653,7 +795,7 @@ impl TouchTarget for IcedEleme &self, seat: &Seat, _data: &mut crate::state::State, - event: &DownEvent, + event: &TouchDownEvent, ) { let mut internal = self.0.lock().unwrap(); let id = Finger(i32::from(event.slot) as u64); @@ -673,7 +815,7 @@ impl TouchTarget for IcedEleme &self, seat: &Seat, _data: &mut crate::state::State, - event: &UpEvent, + event: &TouchUpEvent, ) { let mut internal = self.0.lock().unwrap(); let id = Finger(i32::from(event.slot) as u64); diff --git a/src/wayland/handlers/tablet_manager.rs b/src/wayland/handlers/tablet_manager.rs index e4b84434..7cf2b8cb 100644 --- a/src/wayland/handlers/tablet_manager.rs +++ b/src/wayland/handlers/tablet_manager.rs @@ -1,13 +1,13 @@ // SPDX-License-Identifier: GPL-3.0-only -use crate::state::State; +use crate::{shell::focus::target::PointerFocusTarget, state::State}; use smithay::{ backend::input::TabletToolDescriptor, input::pointer::CursorImageStatus, - input::tablet::TabletSeatHandler, reexports::wayland_server::protocol::wl_surface, + input::tablet::TabletSeatHandler, }; impl TabletSeatHandler for State { - type ToolFocus = wl_surface::WlSurface; + type ToolFocus = PointerFocusTarget; fn tablet_tool_image(&mut self, _tool: &TabletToolDescriptor, _image: CursorImageStatus) { // TODO display cursor for each tablet tool diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index c9fb926f..be7084dd 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -1,11 +1,15 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::{ - shell::{CosmicSurface, PendingWindow, focus::target::KeyboardFocusTarget, grabs::ReleaseMode}, + shell::{ + CosmicSurface, PendingWindow, + focus::target::KeyboardFocusTarget, + grabs::{GrabType, ReleaseMode}, + }, utils::prelude::*, }; -use smithay::desktop::layer_map_for_output; use smithay::{ + backend::input::InputTime, desktop::{ PopupGrab, PopupKeyboardGrab, PopupKind, PopupPointerGrab, PopupUngrabStrategy, WindowSurfaceType, find_popup_root_surface, @@ -26,6 +30,7 @@ use smithay::{ }, }, }; +use smithay::{desktop::layer_map_for_output, input::tablet::TabletSeatTrait}; use std::cell::Cell; use tracing::warn; @@ -190,12 +195,17 @@ impl XdgShellHandler for State { true, ) { std::mem::drop(shell); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(self, grab, serial); - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => seat.get_touch().unwrap().set_grab(self, grab, serial), + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(self, grab, serial, focus) + .set_grab(self, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(self, grab, InputTime::now(), serial, focus), } } } @@ -218,12 +228,17 @@ impl XdgShellHandler for State { true, ) { std::mem::drop(shell); - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(self, grab, serial) - } else { - seat.get_pointer() + match grab.grab_type() { + GrabType::Touch => seat.get_touch().unwrap().set_grab(self, grab, serial), + GrabType::Pointer => seat + .get_pointer() .unwrap() - .set_grab(self, grab, serial, focus) + .set_grab(self, grab, serial, focus), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(self, grab, InputTime::now(), serial, focus), } } } diff --git a/src/xwayland.rs b/src/xwayland.rs index 78193d13..cc6be3b4 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -9,7 +9,9 @@ use std::{ use crate::{ backend::render::cursor::{Cursor, load_cursor_env, load_cursor_theme}, shell::{ - CosmicSurface, PendingWindow, Shell, focus::target::KeyboardFocusTarget, grabs::ReleaseMode, + CosmicSurface, PendingWindow, Shell, + focus::target::KeyboardFocusTarget, + grabs::{GrabType, ReleaseMode}, }, state::State, utils::prelude::*, @@ -32,7 +34,7 @@ use smithay::{ }, }, desktop::space::SpaceElement, - input::{keyboard::ModifiersState, pointer::CursorIcon}, + input::{keyboard::ModifiersState, pointer::CursorIcon, tablet::TabletSeatTrait}, reexports::{wayland_server::Client, x11rb::protocol::xproto::Window as X11Window}, utils::{ Buffer as BufferCoords, Logical, Point, Rectangle, SERIAL_COUNTER, Serial, Size, Transform, @@ -1045,17 +1047,29 @@ impl XwmHandler for State { true, ) { std::mem::drop(shell); - if grab.is_touch_grab() { - seat.get_touch() - .unwrap() - .set_grab(self, grab, SERIAL_COUNTER.next_serial()) - } else { - seat.get_pointer().unwrap().set_grab( + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch() + .unwrap() + .set_grab(self, grab, SERIAL_COUNTER.next_serial()) + } + GrabType::Pointer => seat.get_pointer().unwrap().set_grab( self, grab, SERIAL_COUNTER.next_serial(), focus, - ) + ), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab( + self, + grab, + InputTime::now(), + SERIAL_COUNTER.next_serial(), + focus, + ), } } } @@ -1076,17 +1090,29 @@ impl XwmHandler for State { true, ) { std::mem::drop(shell); - if grab.is_touch_grab() { - seat.get_touch() - .unwrap() - .set_grab(self, grab, SERIAL_COUNTER.next_serial()) - } else { - seat.get_pointer().unwrap().set_grab( + match grab.grab_type() { + GrabType::Touch => { + seat.get_touch() + .unwrap() + .set_grab(self, grab, SERIAL_COUNTER.next_serial()) + } + GrabType::Pointer => seat.get_pointer().unwrap().set_grab( self, grab, SERIAL_COUNTER.next_serial(), focus, - ) + ), + GrabType::TabletTool => seat + .tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab( + self, + grab, + InputTime::now(), + SERIAL_COUNTER.next_serial(), + focus, + ), } } } From 9125f8a2a73fc87a5697b07b71f54611e099b711 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:12:06 +0200 Subject: [PATCH 15/37] input: Add pointer-emulation grab for tablet tools --- src/input/mod.rs | 100 ++++++++++++--- src/input/tablet_emu.rs | 260 ++++++++++++++++++++++++++++++++++++++ src/shell/focus/target.rs | 14 +- 3 files changed, 351 insertions(+), 23 deletions(-) create mode 100644 src/input/tablet_emu.rs diff --git a/src/input/mod.rs b/src/input/mod.rs index cbf99cae..28877356 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -9,7 +9,10 @@ use crate::{ cosmic_modifiers_from_smithay, }, }, - input::gestures::{GestureState, SwipeAction}, + input::{ + gestures::{GestureState, SwipeAction}, + tablet_emu::PointerEmulationGrab, + }, shell::{ SeatExt, Trigger, focus::{ @@ -52,7 +55,7 @@ use smithay::{ keyboard::KeyboardHandle, keyboard::{FilterResult, KeyboardSource, KeysymHandle, ModifiersState}, pointer::{ - AxisFrame, ButtonEvent as PointerButtonEvent, GestureHoldBeginEvent, + AxisFrame, ButtonEvent as PointerButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, MotionEvent as PointerMotionEvent, PointerGrab, PointerHandle, @@ -89,6 +92,7 @@ use std::{ pub mod actions; pub mod gestures; +pub mod tablet_emu; /// Identifies the input backend instance an event came from, used to disambiguate device ids /// (which are only unique within a single backend instance, see @@ -1609,6 +1613,26 @@ impl State { let tool = tablet_seat.get_tool(&event.tool()); if let Some(tool) = tool { + let serial = SERIAL_COUNTER.next_serial(); + if !tool.is_grabbed() + && under + .as_ref() + .is_some_and(|(target, _)| !target.supports_tool(&tool)) + { + let start_data = tool::GrabStartData { + focus: under.clone(), + trigger: tool::GrabTrigger::Proximity, + location: position.as_logical(), + }; + tool.set_grab( + self, + PointerEmulationGrab::new(start_data, seat.clone()), + event.time(), + serial, + Focus::Keep, + ); + } + let frame = tool::AxisFrame { pressure: event.pressure_has_changed().then(|| event.pressure()), distance: event.distance_has_changed().then(|| event.distance()), @@ -1629,7 +1653,7 @@ impl State { under, &tool::MotionEvent { location: position.as_logical(), - serial: SERIAL_COUNTER.next_serial(), + serial, time: event.time(), }, ); @@ -1683,6 +1707,25 @@ impl State { if let Some(tablet) = tablet { let serial = SERIAL_COUNTER.next_serial(); + if !tool.is_grabbed() + && under + .as_ref() + .is_some_and(|(target, _)| !target.supports_tool(&tool)) + { + let start_data = tool::GrabStartData { + focus: under.clone(), + trigger: tool::GrabTrigger::Proximity, + location: position.as_logical(), + }; + tool.set_grab( + self, + PointerEmulationGrab::new(start_data, seat.clone()), + event.time(), + serial, + Focus::Keep, + ); + } + let frame = tool::AxisFrame { pressure: event.pressure_has_changed().then(|| event.pressure()), distance: event.distance_has_changed().then(|| event.distance()), @@ -1697,24 +1740,39 @@ impl State { }; match event.state() { - ProximityState::In => tool.proximity_in( - self, - under, - tablet, - &tool::ProximityInEvent { - location: position.as_logical(), - axis: Some(frame), - serial: SERIAL_COUNTER.next_serial(), - time: event.time(), - }, - ), - ProximityState::Out => tool.proximity_out( - self, - &tool::ProximityOutEvent { - serial, - time: event.time(), - }, - ), + ProximityState::In => { + tool.proximity_in( + self, + under, + tablet, + &tool::ProximityInEvent { + location: position.as_logical(), + axis: Some(frame), + serial, + time: event.time(), + }, + ); + } + ProximityState::Out => { + tool.proximity_out( + self, + &tool::ProximityOutEvent { + serial, + time: event.time(), + }, + ); + if let Some(pointer) = seat.get_pointer() { + pointer.motion( + self, + None, + &PointerMotionEvent { + location: position.as_logical(), + serial, + time: event.time(), + }, + ); + } + } } tool.frame(self, event.time()); diff --git a/src/input/tablet_emu.rs b/src/input/tablet_emu.rs new file mode 100644 index 00000000..94d31d89 --- /dev/null +++ b/src/input/tablet_emu.rs @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-3.0-only + +//! Pointer Emulating TabletTool grab. + +use crate::{shell::focus::target::PointerFocusTarget, state::State}; +use smithay::{ + backend::input::{ButtonState, InputTime, MouseButton}, + input::{ + Seat, pointer, + tablet::{ + self, + tool::{ + AxisFrame, ButtonEvent, DownEvent, GrabStartData, ProximityInEvent, + ProximityOutEvent, TabletToolGrab, TabletToolInnerHandle, UpEvent, + }, + }, + }, + utils::{Logical, Point, SERIAL_COUNTER}, +}; + +// from https://gitlab.freedesktop.org/libinput/libinput/-/blob/main/include/linux/linux/input-event-codes.h +const BTN_STYLUS: u32 = 0x14b; +const BTN_STYLUS_2: u32 = 0x14c; +const BTN_LEFT: u32 = 0x110; +const BTN_RIGHT: u32 = 0x111; +const BTN_MIDDLE: u32 = 0x112; +const BTN_FORWARD: u32 = 0x115; +const BTN_BACK: u32 = 0x116; + +pub struct PointerEmulationGrab { + start_data: GrabStartData, + seat: Seat, + + above_source: bool, + tip_down: bool, + button_down: Vec, +} + +impl PointerEmulationGrab { + pub fn new(start_data: GrabStartData, seat: Seat) -> Self { + Self { + start_data, + seat, + + above_source: true, + tip_down: false, + button_down: Vec::new(), + } + } + + fn button_to_mouse(&self, button: u32) -> Option { + // FIXME: This should be configurable. + if button == BTN_STYLUS { + Some(MouseButton::Right) + } else if button == BTN_STYLUS_2 { + Some(MouseButton::Middle) + } else { + None + } + } + + fn pointer_button(&self, data: &mut State, button: MouseButton, state: ButtonState) { + if let Some(pointer) = self.seat.get_pointer() { + let button = match button { + MouseButton::Left => BTN_LEFT, + MouseButton::Right => BTN_RIGHT, + MouseButton::Middle => BTN_MIDDLE, + MouseButton::Back => BTN_BACK, + MouseButton::Forward => BTN_FORWARD, + _ => return, + }; + + pointer.button( + data, + &pointer::ButtonEvent { + serial: SERIAL_COUNTER.next_serial(), + button, + state, + time: InputTime::now(), + }, + ); + + pointer.frame(data); + } + } +} + +type Type = tablet::tool::MotionEvent; + +impl TabletToolGrab for PointerEmulationGrab { + fn proximity_in( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(PointerFocusTarget, Point)>, + event: &ProximityInEvent, + ) { + handle.proximity_in(data, focus.clone(), event); + + if !self.above_source && !self.tip_down && self.button_down.is_empty() { + handle.unset_grab( + self, + data, + SERIAL_COUNTER.next_serial(), + InputTime::now(), + true, + ); + } else { + if let Some(pointer) = self.seat.get_pointer() { + pointer.motion( + data, + focus, + &pointer::MotionEvent { + location: event.location, + serial: SERIAL_COUNTER.next_serial(), + time: InputTime::now(), + }, + ); + pointer.frame(data); + } + } + } + + fn proximity_out( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ProximityOutEvent, + ) { + handle.proximity_out(data, event); + + handle.unset_grab(self, data, event.serial, event.time, true); + } + + fn down( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &DownEvent, + ) { + handle.down(data, event); + self.tip_down = true; + + self.pointer_button(data, MouseButton::Left, ButtonState::Pressed); + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &UpEvent, + ) { + handle.up(data, event); + + self.pointer_button(data, MouseButton::Left, ButtonState::Released); + self.tip_down = false; + + if !self.above_source && !self.tip_down && self.button_down.is_empty() { + handle.unset_grab(self, data, event.serial, event.time, true); + } + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + focus: Option<(PointerFocusTarget, Point)>, + event: &Type, + ) { + self.above_source = focus.as_ref().map(|(target, _)| target) + == self.start_data.focus.as_ref().map(|(target, _)| target); + handle.motion(data, self.start_data.focus.clone(), event); + + if !self.above_source && !self.tip_down && self.button_down.is_empty() { + handle.unset_grab( + self, + data, + SERIAL_COUNTER.next_serial(), + InputTime::now(), + true, + ); + } else { + if let Some(pointer) = self.seat.get_pointer() { + pointer.motion( + data, + focus, + &pointer::MotionEvent { + location: event.location, + serial: SERIAL_COUNTER.next_serial(), + time: InputTime::now(), + }, + ); + pointer.frame(data); + } + } + } + + fn button( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + event: &ButtonEvent, + ) { + handle.button(data, event); + + self.button_down.retain(|b| b != &event.button); + if matches!(event.state, ButtonState::Pressed) { + self.button_down.push(event.button); + } + + if let Some(button) = self.button_to_mouse(event.button) { + self.pointer_button(data, button, event.state); + } + + if !self.above_source && !self.tip_down && self.button_down.is_empty() { + handle.unset_grab( + self, + data, + SERIAL_COUNTER.next_serial(), + InputTime::now(), + true, + ); + } + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + frame: AxisFrame, + ) { + handle.axis(data, frame); + } + + fn frame( + &mut self, + data: &mut State, + handle: &mut TabletToolInnerHandle<'_, State>, + time: InputTime, + ) { + handle.frame(data, time); + } + + fn unset(&mut self, data: &mut State) { + if self.tip_down { + self.pointer_button(data, MouseButton::Left, ButtonState::Released); + } + + let buttons = std::mem::take(&mut self.button_down); + for button in buttons.into_iter() { + if let Some(button) = self.button_to_mouse(button) { + self.pointer_button(data, button, ButtonState::Released); + } + } + } + + fn start_data(&self) -> &GrabStartData { + &self.start_data + } +} diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index 6ca13279..c914e0fa 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -33,8 +33,8 @@ use smithay::{ Tablet, tool::{ AxisFrame as ToolAxisFrame, ButtonEvent as ToolButtonEvent, - DownEvent as ToolDownEvent, MotionEvent as ToolMotionEvent, TabletToolTarget, - UpEvent as ToolUpEvent, + DownEvent as ToolDownEvent, MotionEvent as ToolMotionEvent, TabletToolHandle, + TabletToolTarget, UpEvent as ToolUpEvent, }, }, touch::{ @@ -306,6 +306,16 @@ impl PointerFocusTarget { session.set_cursor_hotspot(cursor_hotspot); } } + + pub fn supports_tool(&self, tool_handle: &TabletToolHandle) -> bool { + match self { + Self::WlSurface { surface, .. } if surface.client().is_some() => tool_handle + .client_tools(&surface.client().unwrap()) + .next() + .is_some(), + _ => true, + } + } } impl KeyboardFocusTarget { From 67aa6a0c49ae818d10a3662362e9892c1fe9ac89 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:14:28 +0200 Subject: [PATCH 16/37] input: Don't send out pointer events for tool events --- src/input/mod.rs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 28877356..8730e66b 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1598,15 +1598,7 @@ impl State { std::mem::drop(shell); let pointer = seat.get_pointer().unwrap(); - pointer.motion( - self, - under.clone(), - &PointerMotionEvent { - location: position.as_logical(), - serial: SERIAL_COUNTER.next_serial(), - time: InputTime::now(), - }, - ); + pointer.set_location(position.as_logical()); let tablet_seat = seat.tablet_seat(); @@ -1686,15 +1678,7 @@ impl State { std::mem::drop(shell); let pointer = seat.get_pointer().unwrap(); - pointer.motion( - self, - under.clone(), - &PointerMotionEvent { - location: position.as_logical(), - serial: SERIAL_COUNTER.next_serial(), - time: InputTime::now(), - }, - ); + pointer.set_location(position.as_logical()); let tablet_seat = seat.tablet_seat(); From a66f629a4e59c8b2c2a17163bdca126a8dd12666 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:15:03 +0200 Subject: [PATCH 17/37] input: Make sure to update internal pointer position state on tool input --- src/input/mod.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/input/mod.rs b/src/input/mod.rs index 8730e66b..fe210612 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1590,6 +1590,7 @@ impl State { return; }; + let current_output = seat.active_output(); let position = transform_output_mapped_position(&output, &event, shell.zoom_state()); let under = State::surface_under(position, &output, &shell) @@ -1652,6 +1653,29 @@ impl State { tool.frame(self, event.time()); } + + let mut shell = self.common.shell.write(); + shell.update_pointer_position(position.to_local(&output), &output); + shell.update_focal_point( + &seat, + position, + self.common.config.cosmic_conf.accessibility_zoom.view_moves, + ); + + if output != current_output { + for session in cursor_sessions_for_output(&shell, ¤t_output) { + session.set_cursor_pos(None); + } + seat.set_active_output(&output); + } + + update_output_image_copy_cursor_position( + &shell, + &self.common.clock, + &output, + &seat, + position, + ); } } InputEvent::TabletToolProximity { event, .. } => { @@ -1670,6 +1694,7 @@ impl State { return; }; + let current_output = seat.active_output(); let position = transform_output_mapped_position(&output, &event, shell.zoom_state()); let under = State::surface_under(position, &output, &shell) @@ -1761,6 +1786,29 @@ impl State { tool.frame(self, event.time()); } + + let mut shell = self.common.shell.write(); + shell.update_pointer_position(position.to_local(&output), &output); + shell.update_focal_point( + &seat, + position, + self.common.config.cosmic_conf.accessibility_zoom.view_moves, + ); + + if output != current_output { + for session in cursor_sessions_for_output(&shell, ¤t_output) { + session.set_cursor_pos(None); + } + seat.set_active_output(&output); + } + + update_output_image_copy_cursor_position( + &shell, + &self.common.clock, + &output, + &seat, + position, + ); } } InputEvent::TabletToolTip { event, .. } => { From 85564f033699e6371600da552a7ee0e889d8114e Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:15:27 +0200 Subject: [PATCH 18/37] input: Focus on tool tip down --- src/input/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/input/mod.rs b/src/input/mod.rs index fe210612..11466266 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1834,6 +1834,21 @@ impl State { if let Some(seat) = maybe_seat { self.common.idle_notifier_state.notify_activity(&seat); notify_cursor_activity(self, &seat); + + let serial = SERIAL_COUNTER.next_serial(); + let output = seat.active_output(); + let shell = self.common.shell.write(); + let position = + transform_output_mapped_position(&output, &event, shell.zoom_state()); + let under = State::element_under(position, &output, &shell, &seat); + drop(shell); + + if event.tip_state() == TabletToolTipState::Down + && let Some(target) = under.as_ref() + { + Shell::set_focus(self, Some(target), &seat, Some(serial), false); + } + if let Some(tool) = seat.tablet_seat().get_tool(&event.tool()) { let serial = SERIAL_COUNTER.next_serial(); match event.tip_state() { From e65f6608a46f5c8b1250623a9542c2a5214ed285 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:16:23 +0200 Subject: [PATCH 19/37] element: Remove unnecessary grab variants --- src/shell/element/stack.rs | 30 ++++++------------------------ src/shell/element/window.rs | 15 +++------------ 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 34e6f876..17397153 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -1723,19 +1723,10 @@ impl PointerTarget for CosmicStack { false, ); if let Some((grab, focus)) = res { - match grab.grab_type() { - GrabType::Touch => { - seat.get_touch().unwrap().set_grab(state, grab, serial) - } - GrabType::Pointer => seat - .get_pointer() + if let GrabType::Pointer = grab.grab_type() { + seat.get_pointer() .unwrap() - .set_grab(state, grab, serial, focus), - GrabType::TabletTool => seat - .tablet_seat() - .get_tool(grab.tool().unwrap()) - .unwrap() - .set_grab(state, grab, InputTime::now(), serial, focus), + .set_grab(state, grab, serial, focus); } } }); @@ -1793,19 +1784,10 @@ impl PointerTarget for CosmicStack { false, ); if let Some((grab, focus)) = res { - match grab.grab_type() { - GrabType::Touch => { - seat.get_touch().unwrap().set_grab(state, grab, serial) - } - GrabType::Pointer => seat - .get_pointer() + if let GrabType::Pointer = grab.grab_type() { + seat.get_pointer() .unwrap() - .set_grab(state, grab, serial, focus), - GrabType::TabletTool => seat - .tablet_seat() - .get_tool(grab.tool().unwrap()) - .unwrap() - .set_grab(state, grab, InputTime::now(), serial, focus), + .set_grab(state, grab, serial, focus); } } }); diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 846d9da4..903a2c05 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -1114,19 +1114,10 @@ impl PointerTarget for CosmicWindow { ); if let Some((grab, focus)) = res { - match grab.grab_type() { - GrabType::Touch => { - seat.get_touch().unwrap().set_grab(state, grab, serial) - } - GrabType::Pointer => seat - .get_pointer() + if let GrabType::Pointer = grab.grab_type() { + seat.get_pointer() .unwrap() - .set_grab(state, grab, serial, focus), - GrabType::TabletTool => seat - .tablet_seat() - .get_tool(grab.tool().unwrap()) - .unwrap() - .set_grab(state, grab, InputTime::now(), serial, focus), + .set_grab(state, grab, serial, focus) } } }); From b8824128a041ebbf7ceaf660f9a86756cfb4052f Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:17:27 +0200 Subject: [PATCH 20/37] element: Add cursor shape and resize handling on tool input --- src/shell/element/stack.rs | 77 +++++++++++++++++++++++++++++++++++-- src/shell/element/window.rs | 74 +++++++++++++++++++++++++++++++++-- 2 files changed, 144 insertions(+), 7 deletions(-) diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 17397153..5ab022d9 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -1938,7 +1938,17 @@ impl TabletToolTarget for CosmicStack { data: &mut State, tool_descriptor: &TabletToolDescriptor, ) { - TabletToolTarget::proximity_out(&self.0, seat, data, tool_descriptor) + self.0.with_program(|p| { + let mut cursor_state = seat + .user_data() + .get::() + .unwrap() + .lock() + .unwrap(); + cursor_state.unset_shape(); + let _previous = p.swap_focus(None); + }); + TabletToolTarget::proximity_out(&self.0, seat, data, tool_descriptor); } fn down( @@ -1948,7 +1958,50 @@ impl TabletToolTarget for CosmicStack { tool_descriptor: &TabletToolDescriptor, event: &ToolDownEvent, ) { - TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) + match self.0.with_program(|p| p.current_focus()) { + Some(Focus::Header) => { + TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) + } + Some(x) => { + let serial = event.serial; + let seat = seat.clone(); + let Some(surface) = self.0.with_program(|p| { + let window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]; + window.wl_surface().map(Cow::into_owned) + }) else { + return; + }; + self.0.loop_handle().insert_idle(move |state| { + let res = state.common.shell.write().resize_request( + &surface, + &seat, + serial, + match x { + Focus::ResizeTop => ResizeEdge::TOP, + Focus::ResizeTopLeft => ResizeEdge::TOP_LEFT, + Focus::ResizeTopRight => ResizeEdge::TOP_RIGHT, + Focus::ResizeBottom => ResizeEdge::BOTTOM, + Focus::ResizeBottomLeft => ResizeEdge::BOTTOM_LEFT, + Focus::ResizeBottomRight => ResizeEdge::BOTTOM_RIGHT, + Focus::ResizeLeft => ResizeEdge::LEFT, + Focus::ResizeRight => ResizeEdge::RIGHT, + Focus::Header => unreachable!(), + }, + state.common.config.cosmic_conf.edge_snap_threshold, + false, + ); + if let Some((grab, focus)) = res { + if let GrabType::TabletTool = grab.grab_type() { + seat.tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus); + } + } + }); + } + None => {} + } } fn up( @@ -1969,12 +2022,30 @@ impl TabletToolTarget for CosmicStack { event: &ToolMotionEvent, ) { let mut event = event.clone(); + self.0.with_program(|p| { + let active = p.active.load(Ordering::SeqCst); + let active_window = &p.windows.lock().unwrap()[active]; + let Some(next) = Focus::under(active_window, TAB_HEIGHT, event.location) else { + return; + }; + let _previous = p.swap_focus(Some(next)); + + let mut cursor_state = seat + .user_data() + .get::() + .unwrap() + .lock() + .unwrap(); + cursor_state.set_shape(next.cursor_shape()); + seat.set_cursor_image_status(CursorImageStatus::default_named()); + }); + let active_window_geo = self.0.with_program(|p| { p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].geometry() }); event.location -= active_window_geo.loc.to_f64(); - TabletToolTarget::motion(&self.0, seat, data, tool_descriptor, &event); + TabletToolTarget::motion(&self.0, seat, data, tool_descriptor, &event); if event.location.y < 0.0 || event.location.y > TAB_HEIGHT as f64 || event.location.x < 64.0 diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 903a2c05..6488ffa3 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -1032,8 +1032,7 @@ impl PointerTarget for CosmicWindow { return; }; - let old_focus = p.swap_focus(Some(next)); - assert_eq!(old_focus, None); + let _ = p.swap_focus(Some(next)); let cursor_state = seat.user_data().get::().unwrap(); cursor_state.lock().unwrap().set_shape(next.cursor_shape()); @@ -1270,6 +1269,11 @@ impl TabletToolTarget for CosmicWindow { data: &mut State, tool_descriptor: &TabletToolDescriptor, ) { + self.0.with_program(|p| { + let cursor_state = seat.user_data().get::().unwrap(); + cursor_state.lock().unwrap().unset_shape(); + let _previous = p.swap_focus(None); + }); TabletToolTarget::proximity_out(&self.0, seat, data, tool_descriptor) } @@ -1280,7 +1284,49 @@ impl TabletToolTarget for CosmicWindow { tool_descriptor: &TabletToolDescriptor, event: &ToolDownEvent, ) { - TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) + match self.0.with_program(|p| p.current_focus()) { + Some(Focus::Header) => { + TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) + } + Some(x) => { + let serial = event.serial; + let seat = seat.clone(); + let Some(surface) = self.wl_surface().map(Cow::into_owned) else { + return; + }; + + self.0.loop_handle().insert_idle(move |state| { + let res = state.common.shell.write().resize_request( + &surface, + &seat, + serial, + match x { + Focus::ResizeTop => ResizeEdge::TOP, + Focus::ResizeTopLeft => ResizeEdge::TOP_LEFT, + Focus::ResizeTopRight => ResizeEdge::TOP_RIGHT, + Focus::ResizeBottom => ResizeEdge::BOTTOM, + Focus::ResizeBottomLeft => ResizeEdge::BOTTOM_LEFT, + Focus::ResizeBottomRight => ResizeEdge::BOTTOM_RIGHT, + Focus::ResizeLeft => ResizeEdge::LEFT, + Focus::ResizeRight => ResizeEdge::RIGHT, + Focus::Header => unreachable!(), + }, + state.common.config.cosmic_conf.edge_snap_threshold, + false, + ); + + if let Some((grab, focus)) = res { + if let GrabType::TabletTool = grab.grab_type() { + seat.tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus) + } + } + }); + } + None => {} + } } fn up( @@ -1300,7 +1346,27 @@ impl TabletToolTarget for CosmicWindow { tool_descriptor: &TabletToolDescriptor, event: &ToolMotionEvent, ) { - TabletToolTarget::motion(&self.0, seat, data, tool_descriptor, event) + let mut event = event.clone(); + self.0.with_program(|p| { + let has_ssd = p.has_ssd(false); + if has_ssd || p.has_tiled_state() { + let Some(next) = Focus::under( + &p.window, + if has_ssd { SSD_HEIGHT } else { 0 }, + event.location, + ) else { + return; + }; + let _previous = p.swap_focus(Some(next)); + + let cursor_state = seat.user_data().get::().unwrap(); + cursor_state.lock().unwrap().set_shape(next.cursor_shape()); + seat.set_cursor_image_status(CursorImageStatus::default_named()); + } + }); + + event.location -= self.0.with_program(|p| p.window.geometry().loc.to_f64()); + TabletToolTarget::motion(&self.0, seat, data, tool_descriptor, &event) } fn axis( From f00ff834c96f8154dbe11f983afc93b8b7d71c8d Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:18:16 +0200 Subject: [PATCH 21/37] resize/tiling: Fix location for tablet tools --- src/shell/layout/tiling/grabs/resize.rs | 17 +++++------------ src/shell/layout/tiling/mod.rs | 2 -- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index b6452168..6bb24929 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::cell::Cell; - use crate::{ backend::render::cursor::CursorState, shell::{ @@ -52,7 +50,6 @@ pub struct ResizeForkTarget { pub output: WeakOutput, pub left_up_idx: usize, pub orientation: Orientation, - pub last_tablet_location: Cell>>, } impl IsAlive for ResizeForkTarget { @@ -193,10 +190,9 @@ impl TabletToolTarget for ResizeForkTarget { let serial = event.serial; let time = event.time; let tool = tool_descriptor.clone(); - let Some(location) = self.last_tablet_location.take() else { - return; - }; data.common.event_loop_handle.insert_idle(move |state| { + let pointer = seat.get_pointer().unwrap(); + let location = pointer.current_location(); let tablet = seat.tablet_seat().get_tool(&tool).unwrap(); tablet.set_grab( state, @@ -205,11 +201,11 @@ impl TabletToolTarget for ResizeForkTarget { tool, data: TabletToolGrabStartData { focus: None, - location: location.as_logical(), + location: location, trigger: TabletToolGrabTrigger::Tip, }, }, - location, + location.as_global(), node, left_up_idx, orientation, @@ -227,10 +223,8 @@ impl TabletToolTarget for ResizeForkTarget { _seat: &Seat, _data: &mut State, _tool_descriptor: &TabletToolDescriptor, - event: &TabletMotionEvent, + _event: &TabletMotionEvent, ) { - self.last_tablet_location - .set(Some(event.location.as_global())) } fn proximity_out( &self, @@ -238,7 +232,6 @@ impl TabletToolTarget for ResizeForkTarget { _data: &mut State, _tool_descriptor: &TabletToolDescriptor, ) { - self.last_tablet_location.set(None); } fn proximity_in( diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 2f694acd..8706dc59 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -67,7 +67,6 @@ use smithay::{ wayland::{compositor::add_blocker, seat::WaylandFocus}, }; use std::{ - cell::Cell, collections::{HashMap, VecDeque}, sync::{Arc, Weak}, time::{Duration, Instant}, @@ -3349,7 +3348,6 @@ impl TilingLayout { output: self.output.downgrade(), left_up_idx: idx, orientation, - last_tablet_location: Cell::new(None), } .into(), (last_geometry.loc From 87d73dbce32f9571b458f0934f40bff12eb665f5 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:23:22 +0200 Subject: [PATCH 22/37] resize/tiling: Set cursor icons on tool input --- src/shell/layout/tiling/grabs/resize.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 6bb24929..850545be 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -228,20 +228,32 @@ impl TabletToolTarget for ResizeForkTarget { } fn proximity_out( &self, - _seat: &Seat, + seat: &Seat, _data: &mut State, _tool_descriptor: &TabletToolDescriptor, ) { + let user_data = seat.user_data(); + let cursor_state = user_data.get::().unwrap(); + cursor_state.lock().unwrap().unset_shape(); } fn proximity_in( &self, - _seat: &Seat, + seat: &Seat, _data: &mut State, _tool_descriptor: &TabletToolDescriptor, _tablet: &Tablet, _serial: Serial, ) { + let user_data = seat.user_data(); + let cursor_state = user_data.get::().unwrap(); + cursor_state + .lock() + .unwrap() + .set_shape(match self.orientation { + Orientation::Horizontal => CursorIcon::RowResize, + Orientation::Vertical => CursorIcon::ColResize, + }); } fn up( &self, From bb95a57f5a59f594603cd62ba2df43f3ce713a95 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:24:02 +0200 Subject: [PATCH 23/37] move: Make sure to always unset tool grab --- src/shell/grabs/moving.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 15225212..50fc9740 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -745,6 +745,7 @@ impl TabletToolGrab for MoveGrab { event: &ProximityOutEvent, ) { handle.proximity_out(data, event); + handle.unset_grab(self, data, event.serial, event.time, false); } fn motion( @@ -777,11 +778,8 @@ impl TabletToolGrab for MoveGrab { handle: &mut TabletToolInnerHandle<'_, State>, event: &TabletUpEvent, ) { - if self.tool().is_some_and(|tool| tool == handle.descriptor()) { - handle.unset_grab(self, data, event.serial, event.time, false); - } - handle.up(data, event); + handle.unset_grab(self, data, event.serial, event.time, false); } fn button( From 6bf75e1c1006b4be39e473883385e5a9273862dc Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:24:27 +0200 Subject: [PATCH 24/37] shell: Handle Tablet grabs --- src/shell/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index b10d9d63..5bccf797 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -49,7 +49,7 @@ use smithay::{ pointer::{ CursorImageStatus, CursorImageSurfaceData, Focus, GrabStartData as PointerGrabStartData, }, - tablet::tool::GrabTrigger as TabletGrabTrigger, + tablet::{TabletSeatTrait, tool::GrabTrigger as TabletGrabTrigger}, }, output::{Output, WeakOutput}, reexports::{ @@ -5164,10 +5164,19 @@ pub fn check_grab_preconditions( let pointer = seat.get_pointer().unwrap(); let touch = seat.get_touch().unwrap(); + let tablet = seat.tablet_seat(); + let tools = tablet.get_tools(); let start_data = if serial.is_some_and(|serial| touch.has_grab(serial)) { GrabStartData::Touch(touch.grab_start_data().unwrap()) + } else if let Some((desc, tool)) = + serial.and_then(|serial| tools.iter().find(|(_, tool)| tool.has_grab(serial))) + { + GrabStartData::TabletTool { + tool: desc.clone(), + data: tool.grab_start_data().unwrap(), + } } else { GrabStartData::Pointer(pointer.grab_start_data().unwrap_or_else(|| { PointerGrabStartData { From 0e15b14ab29f75da8023efe85a0e5b1e4a293af7 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 18 Aug 2026 19:24:54 +0200 Subject: [PATCH 25/37] utils/iced: Fix tablet serials and buttons --- src/utils/iced/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/utils/iced/mod.rs b/src/utils/iced/mod.rs index 8680bed3..4522644b 100644 --- a/src/utils/iced/mod.rs +++ b/src/utils/iced/mod.rs @@ -497,16 +497,18 @@ impl IcedElementInternal

{ impl TabletToolTarget for IcedElement

{ fn proximity_in( &self, - _seat: &Seat, + seat: &Seat, _data: &mut crate::state::State, _tool_descriptor: &TabletToolDescriptor, _tablet: &Tablet, - _serial: Serial, + serial: Serial, ) { let mut internal = self.0.lock().unwrap(); internal .state .queue_event(Event::Mouse(MouseEvent::CursorEntered)); + internal.last_tablet_serial = Some(serial); + *internal.last_seat.lock().unwrap() = Some((seat.clone(), serial)); internal.update(false); } @@ -578,7 +580,8 @@ impl TabletToolTarget for Iced .state .queue_event(Event::Mouse(MouseEvent::CursorMoved { position })); internal.cursor_pos = Some(event_location); - *internal.last_seat.lock().unwrap() = Some((seat.clone(), event.serial)); + *internal.last_seat.lock().unwrap() = + Some((seat.clone(), internal.last_tablet_serial.unwrap())); internal.update(false); } @@ -600,10 +603,9 @@ impl TabletToolTarget for Iced ) { let mut internal = self.0.lock().unwrap(); let button = match event.button { - 0x110 => MouseButton::Left, - 0x111 => MouseButton::Right, - 0x112 => MouseButton::Middle, - x => MouseButton::Other(x as u16), + 0x14b => MouseButton::Right, + 0x14c => MouseButton::Middle, + _ => return, }; internal.state.queue_event(Event::Mouse(match event.state { ButtonState::Pressed => MouseEvent::ButtonPressed(button), From 2a3b4dca5f0569b01e2daa52e928def4949eeb25 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 19 Aug 2026 17:24:04 +0200 Subject: [PATCH 26/37] shell: fix client initiated tablet grabs --- src/shell/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 5bccf797..47d78851 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -5190,8 +5190,16 @@ pub fn check_grab_preconditions( if let Some(surface) = client_initiated { // Check that this surface has a click or touch down grab. if !match serial { - Some(serial) => pointer.has_grab(serial) || touch.has_grab(serial), - None => pointer.is_grabbed() | touch.is_grabbed(), + Some(serial) => { + pointer.has_grab(serial) + || touch.has_grab(serial) + || tools.values().any(|tool| tool.has_grab(serial)) + } + None => { + pointer.is_grabbed() + || touch.is_grabbed() + || tools.values().any(|tool| tool.is_grabbed()) + } } { return None; } From e563dc85bf28f927db0241c1dc83fd4afce233b2 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 19 Aug 2026 18:07:37 +0200 Subject: [PATCH 27/37] input: Don't update pointer position on proximity_out --- src/input/mod.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 11466266..76d2c355 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1787,28 +1787,30 @@ impl State { tool.frame(self, event.time()); } - let mut shell = self.common.shell.write(); - shell.update_pointer_position(position.to_local(&output), &output); - shell.update_focal_point( - &seat, - position, - self.common.config.cosmic_conf.accessibility_zoom.view_moves, - ); + if event.state() == ProximityState::In { + let mut shell = self.common.shell.write(); + shell.update_pointer_position(position.to_local(&output), &output); + shell.update_focal_point( + &seat, + position, + self.common.config.cosmic_conf.accessibility_zoom.view_moves, + ); - if output != current_output { - for session in cursor_sessions_for_output(&shell, ¤t_output) { - session.set_cursor_pos(None); + if output != current_output { + for session in cursor_sessions_for_output(&shell, ¤t_output) { + session.set_cursor_pos(None); + } + seat.set_active_output(&output); } - seat.set_active_output(&output); - } - update_output_image_copy_cursor_position( - &shell, - &self.common.clock, - &output, - &seat, - position, - ); + update_output_image_copy_cursor_position( + &shell, + &self.common.clock, + &output, + &seat, + position, + ); + } } } InputEvent::TabletToolTip { event, .. } => { From 1c8a0070c023d41326fe8cc8b9367231446492bc Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 19 Aug 2026 18:07:58 +0200 Subject: [PATCH 28/37] element/stack: Handle touch (and tablet) inputs on tabs --- src/shell/element/stack/tab.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shell/element/stack/tab.rs b/src/shell/element/stack/tab.rs index f8fda525..4b2a3292 100644 --- a/src/shell/element/stack/tab.rs +++ b/src/shell/element/stack/tab.rs @@ -8,6 +8,7 @@ use cosmic::{ layout::{Layout, Limits, Node}, mouse, overlay, renderer, text::{Ellipsize, EllipsizeHeightLimit, Shaping, Wrapping}, + touch, widget::{Id, Widget, operation::Operation, tree::Tree}, }, widget::{self, container::draw_background, rule::FillMode, scrollable::AbsoluteOffset}, @@ -377,6 +378,7 @@ where if matches!( event, event::Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) + | event::Event::Touch(touch::Event::FingerPressed { .. }) ) && let Some(message) = self.press_message.clone() { shell.publish(message); @@ -395,6 +397,7 @@ where if matches!( event, event::Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) + | event::Event::Touch(touch::Event::FingerLifted { .. }) ) { shell.publish(Message::activate(self.idx)); shell.capture_event(); From bd0b83412890ec4e126e01c92cfbc87e6e2e78cd Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 19 Aug 2026 18:08:21 +0200 Subject: [PATCH 29/37] element/stack: Use correct serial for tablet grabs --- src/shell/element/stack.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 5ab022d9..a97f5778 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -121,6 +121,7 @@ pub struct CosmicStackInternal { previous_keyboard: AtomicUsize, pointer_entered: AtomicU8, touch_serial: AtomicU32, + tablet_serial: AtomicU32, reenter: AtomicBool, potential_drag: Mutex>, override_alive: AtomicBool, @@ -180,6 +181,7 @@ impl CosmicStack { previous_keyboard: AtomicUsize::new(0), pointer_entered: AtomicU8::new(0), touch_serial: AtomicU32::new(0), + tablet_serial: AtomicU32::new(0), reenter: AtomicBool::new(false), potential_drag: Mutex::new(None), override_alive: AtomicBool::new(true), @@ -1958,12 +1960,19 @@ impl TabletToolTarget for CosmicStack { tool_descriptor: &TabletToolDescriptor, event: &ToolDownEvent, ) { + self.0.with_program(|p| { + p.tablet_serial + .store(event.serial.into(), Ordering::Release) + }); match self.0.with_program(|p| p.current_focus()) { Some(Focus::Header) => { TabletToolTarget::down(&self.0, seat, data, tool_descriptor, event) } Some(x) => { - let serial = event.serial; + let serial = self + .0 + .with_program(|p| p.tablet_serial.load(Ordering::Acquire)) + .into(); let seat = seat.clone(); let Some(surface) = self.0.with_program(|p| { let window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]; @@ -2051,7 +2060,13 @@ impl TabletToolTarget for CosmicStack { || event.location.x < 64.0 || event.location.x > (active_window_geo.size.w as f64 - 64.0) { - self.start_drag(data, seat, event.serial); + self.start_drag( + data, + seat, + self.0 + .with_program(|p| p.tablet_serial.load(Ordering::Acquire)) + .into(), + ); } } From f8344126a16e7f8712fa123076fc34c9238493a7 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 19 Aug 2026 18:12:11 +0200 Subject: [PATCH 30/37] input: Update the pointer state on absolute pointer events as well --- src/input/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 76d2c355..45586b03 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -767,15 +767,25 @@ impl State { ); ptr.frame(self); + let mut shell = self.common.shell.write(); // Keep the seat's active output following the pointer. Click-to- // focus (PointerButton) resolves its target via // `seat.active_output()` let previous_output = seat.active_output(); if previous_output != output { + for session in cursor_sessions_for_output(&shell, &previous_output) { + session.set_cursor_pos(None); + } seat.set_active_output(&output); } - let shell = self.common.shell.read(); + shell.update_pointer_position(position.to_local(&output), &output); + shell.update_focal_point( + &seat, + position, + self.common.config.cosmic_conf.accessibility_zoom.view_moves, + ); + update_output_image_copy_cursor_position( &shell, &self.common.clock, From e8caf335b39a53c0193de005ef913258bcaaac03 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Thu, 3 Sep 2026 11:50:50 -0600 Subject: [PATCH 31/37] refactor: align the corner radii order with the theme It's [TL, TR, BR, BL] everywhere now --- src/backend/render/mod.rs | 4 +-- src/backend/render/shadow.rs | 6 ---- src/backend/render/wayland/blur_effect.rs | 4 +-- src/backend/render/wayland/clipped_surface.rs | 10 +++---- src/shell/element/stack.rs | 8 +++--- src/shell/element/window.rs | 28 +++++++++---------- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index b348640f..1be5b9d4 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -286,10 +286,10 @@ impl IndicatorShader { Uniform::new( "radius", [ - outer_radius[3] as f32, - outer_radius[1] as f32, outer_radius[0] as f32, + outer_radius[1] as f32, outer_radius[2] as f32, + outer_radius[3] as f32, ], ), Uniform::new("scale", scale as f32), diff --git a/src/backend/render/shadow.rs b/src/backend/render/shadow.rs index 37b1fdec..87fdd2e3 100644 --- a/src/backend/render/shadow.rs +++ b/src/backend/render/shadow.rs @@ -86,12 +86,6 @@ impl ShadowShader { let offset = [0., 5.]; let color = [0., 0., 0., if dark_mode { 0.45 } else { 0.35 }]; let radius = radius.map(|r| ceil(r as f64)); - let radius = [ - radius[3], // top_left - radius[1], // top_right - radius[0], // bottom_right - radius[2], // bottom_left - ]; let width = softness; let sigma = width / 2.; diff --git a/src/backend/render/wayland/blur_effect.rs b/src/backend/render/wayland/blur_effect.rs index c4d27fac..b8a7935a 100644 --- a/src/backend/render/wayland/blur_effect.rs +++ b/src/backend/render/wayland/blur_effect.rs @@ -247,10 +247,10 @@ impl BlurElement { Uniform::new( "corner_radius", [ - radii[3] as f32, - radii[1] as f32, radii[0] as f32, + radii[1] as f32, radii[2] as f32, + radii[3] as f32, ], ), Uniform::new( diff --git a/src/backend/render/wayland/clipped_surface.rs b/src/backend/render/wayland/clipped_surface.rs index 8322079e..52535269 100644 --- a/src/backend/render/wayland/clipped_surface.rs +++ b/src/backend/render/wayland/clipped_surface.rs @@ -99,10 +99,10 @@ where Uniform::new( "corner_radius", [ - radius[3] as f32, - radius[1] as f32, radius[0] as f32, + radius[1] as f32, radius[2] as f32, + radius[3] as f32, ], ), Uniform::new( @@ -145,10 +145,10 @@ where geo: Rectangle, radius: [u8; 4], ) -> [Rectangle; 4] { - let top_left = radius[3] as f64; + let top_left = radius[0] as f64; let top_right = radius[1] as f64; - let bottom_right = radius[0] as f64; - let bottom_left = radius[2] as f64; + let bottom_right = radius[2] as f64; + let bottom_left = radius[3] as f64; [ Rectangle::new(geo.loc, Size::from((top_left, top_left))), diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index a97f5778..c973b189 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -842,7 +842,7 @@ impl CosmicStack { ))); }; - let radii = radii.map(|[a, _, c, _]| [a, 0, c, 0]); + let radii = radii.map(|[_, _, c, d]| [0, 0, c, d]); windows[active].push_render_elements( renderer, window_loc, @@ -1015,17 +1015,17 @@ impl CosmicStack { .corner_radius(geometry_size) .unwrap_or([default_radius; 4]); + corners[0] = 0; corners[1] = 0; - corners[3] = 0; corners } else { let mut corners = active_window.corner_radius(geometry_size).unwrap_or(radii); - corners[0] = radii[0].max(corners[0]); + corners[0] = radii[0]; corners[1] = radii[1]; corners[2] = radii[2].max(corners[2]); - corners[3] = radii[3]; + corners[3] = radii[3].max(corners[3]); corners } diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 6488ffa3..91423ca5 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -438,12 +438,12 @@ impl CosmicWindow { .map(|x| (x * scale as f32).round() as u8); if has_ssd && !clip { // bottom corners - radii[0] = 0; radii[2] = 0; + radii[3] = 0; if is_tiled { // top corners + radii[0] = 0; radii[1] = 0; - radii[3] = 0; } } @@ -510,12 +510,12 @@ impl CosmicWindow { && !is_maximized; if has_ssd && !clip { // bottom corners - radii[0] = 0; radii[2] = 0; + radii[3] = 0; if is_tiled { // top corners + radii[0] = 0; radii[1] = 0; - radii[3] = 0; } } @@ -560,8 +560,8 @@ impl CosmicWindow { self.0.with_program(|p| { let mut radii = radii; if has_ssd { + radii[0] = 0; radii[1] = 0; - radii[3] = 0; } let theme = p.theme.lock().unwrap(); let frosted = if theme.cosmic().frosted_windows { @@ -585,8 +585,8 @@ impl CosmicWindow { }); if has_ssd { - radii[0] = 0; radii[2] = 0; + radii[3] = 0; let ssd_loc = location + self .0 @@ -691,26 +691,26 @@ impl CosmicWindow { (has_ssd, true) => { let mut corners = p.window.corner_radius(geometry_size).unwrap_or(radii); - corners[0] = radii[0].max(corners[0]); + corners[0] = if has_ssd { + radii[0] + } else { + radii[0].max(corners[0]) + }; corners[1] = if has_ssd { radii[1] } else { radii[1].max(corners[1]) }; corners[2] = radii[2].max(corners[2]); - corners[3] = if has_ssd { - radii[3] - } else { - radii[3].max(corners[3]) - }; + corners[3] = radii[3].max(corners[3]); corners } (true, false) => p .window .corner_radius(geometry_size) - .map(|[a, _, c, _]| [a, radii[1], c, radii[3]]) - .unwrap_or([default_radius, radii[1], default_radius, radii[3]]), + .map(|[_, _, c, d]| [radii[0], radii[1], c, d]) + .unwrap_or([radii[0], radii[1], default_radius, default_radius]), (false, false) => p .window .corner_radius(geometry_size) From 057e7b72cc0a1da4cbed73c51f30660255ba2ea9 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Thu, 3 Sep 2026 11:51:49 -0600 Subject: [PATCH 32/37] chore: remove the gaurd against large paddings --- src/backend/render/mod.rs | 3 +-- src/wayland/handlers/corner_radius.rs | 11 ++--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index 1be5b9d4..9ad61588 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -899,8 +899,7 @@ where let geometry = geometry.to_local(output).as_logical(); let padded = with_states(layer.wl_surface(), |states| { - surface_padding(states, geometry.size) - .and_then(|padding| pad_rect(geometry, &padding)) + surface_padding(states).and_then(|padding| pad_rect(geometry, &padding)) }) .unwrap_or(geometry); let radii = with_states(layer.wl_surface(), |states| { diff --git a/src/wayland/handlers/corner_radius.rs b/src/wayland/handlers/corner_radius.rs index ded8d923..1a541938 100644 --- a/src/wayland/handlers/corner_radius.rs +++ b/src/wayland/handlers/corner_radius.rs @@ -45,18 +45,11 @@ pub fn surface_corners(states: &SurfaceData, size: Size) -> Option ]) } -pub fn surface_padding(states: &SurfaceData, size: Size) -> Option<[i32; 4]> { +pub fn surface_padding(states: &SurfaceData) -> Option<[i32; 4]> { let mut guard = states.cached_state.get::(); let padding = guard.current().0?; - - // guard against padding being too large - Some([ - padding.top.min(size.h / 2), - padding.right.min(size.w / 2), - padding.bottom.min(size.h / 2), - padding.left.min(size.w / 2), - ]) + Some([padding.top, padding.right, padding.bottom, padding.left]) } pub fn pad_rect( From 0f56d214b9ceaa53ca12ef6ce7043e07626bb42c Mon Sep 17 00:00:00 2001 From: Hojjat Date: Fri, 4 Sep 2026 07:46:03 -0600 Subject: [PATCH 33/37] chore: clippy fixes --- src/input/tablet_emu.rs | 48 ++++++++++----------- src/shell/element/stack.rs | 38 ++++++++-------- src/shell/element/window.rs | 26 +++++------ src/shell/grabs/moving.rs | 2 +- src/shell/layout/tiling/grabs/resize.rs | 2 +- src/wayland/handlers/decoration.rs | 21 +++++---- src/wayland/handlers/pointer_constraints.rs | 1 - 7 files changed, 66 insertions(+), 72 deletions(-) diff --git a/src/input/tablet_emu.rs b/src/input/tablet_emu.rs index 94d31d89..6ab17924 100644 --- a/src/input/tablet_emu.rs +++ b/src/input/tablet_emu.rs @@ -105,19 +105,17 @@ impl TabletToolGrab for PointerEmulationGrab { InputTime::now(), true, ); - } else { - if let Some(pointer) = self.seat.get_pointer() { - pointer.motion( - data, - focus, - &pointer::MotionEvent { - location: event.location, - serial: SERIAL_COUNTER.next_serial(), - time: InputTime::now(), - }, - ); - pointer.frame(data); - } + } else if let Some(pointer) = self.seat.get_pointer() { + pointer.motion( + data, + focus, + &pointer::MotionEvent { + location: event.location, + serial: SERIAL_COUNTER.next_serial(), + time: InputTime::now(), + }, + ); + pointer.frame(data); } } @@ -179,19 +177,17 @@ impl TabletToolGrab for PointerEmulationGrab { InputTime::now(), true, ); - } else { - if let Some(pointer) = self.seat.get_pointer() { - pointer.motion( - data, - focus, - &pointer::MotionEvent { - location: event.location, - serial: SERIAL_COUNTER.next_serial(), - time: InputTime::now(), - }, - ); - pointer.frame(data); - } + } else if let Some(pointer) = self.seat.get_pointer() { + pointer.motion( + data, + focus, + &pointer::MotionEvent { + location: event.location, + serial: SERIAL_COUNTER.next_serial(), + time: InputTime::now(), + }, + ); + pointer.frame(data); } } diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index c973b189..f4a37bfe 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -1724,12 +1724,12 @@ impl PointerTarget for CosmicStack { state.common.config.cosmic_conf.edge_snap_threshold, false, ); - if let Some((grab, focus)) = res { - if let GrabType::Pointer = grab.grab_type() { - seat.get_pointer() - .unwrap() - .set_grab(state, grab, serial, focus); - } + if let Some((grab, focus)) = res + && let GrabType::Pointer = grab.grab_type() + { + seat.get_pointer() + .unwrap() + .set_grab(state, grab, serial, focus); } }); } @@ -1785,12 +1785,12 @@ impl PointerTarget for CosmicStack { &state.common.event_loop_handle, false, ); - if let Some((grab, focus)) = res { - if let GrabType::Pointer = grab.grab_type() { - seat.get_pointer() - .unwrap() - .set_grab(state, grab, serial, focus); - } + if let Some((grab, focus)) = res + && let GrabType::Pointer = grab.grab_type() + { + seat.get_pointer() + .unwrap() + .set_grab(state, grab, serial, focus); } }); } @@ -1999,13 +1999,13 @@ impl TabletToolTarget for CosmicStack { state.common.config.cosmic_conf.edge_snap_threshold, false, ); - if let Some((grab, focus)) = res { - if let GrabType::TabletTool = grab.grab_type() { - seat.tablet_seat() - .get_tool(grab.tool().unwrap()) - .unwrap() - .set_grab(state, grab, InputTime::now(), serial, focus); - } + if let Some((grab, focus)) = res + && let GrabType::TabletTool = grab.grab_type() + { + seat.tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus); } }); } diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 91423ca5..fa4a1872 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -1112,12 +1112,12 @@ impl PointerTarget for CosmicWindow { false, ); - if let Some((grab, focus)) = res { - if let GrabType::Pointer = grab.grab_type() { - seat.get_pointer() - .unwrap() - .set_grab(state, grab, serial, focus) - } + if let Some((grab, focus)) = res + && let GrabType::Pointer = grab.grab_type() + { + seat.get_pointer() + .unwrap() + .set_grab(state, grab, serial, focus) } }); } @@ -1315,13 +1315,13 @@ impl TabletToolTarget for CosmicWindow { false, ); - if let Some((grab, focus)) = res { - if let GrabType::TabletTool = grab.grab_type() { - seat.tablet_seat() - .get_tool(grab.tool().unwrap()) - .unwrap() - .set_grab(state, grab, InputTime::now(), serial, focus) - } + if let Some((grab, focus)) = res + && let GrabType::TabletTool = grab.grab_type() + { + seat.tablet_seat() + .get_tool(grab.tool().unwrap()) + .unwrap() + .set_grab(state, grab, InputTime::now(), serial, focus) } }); } diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 50fc9740..f1fbfa8a 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -905,7 +905,7 @@ impl Drop for MoveGrab { let seat = self.seat.clone(); // false-positive: `Output`s hash is based on it's inner ptr #[allow(clippy::mutable_key_type)] - let window_outputs = self.window_outputs.drain().collect::>(); + let window_outputs = std::mem::take(&mut self.window_outputs); let previous = self.previous; let window = self.window.clone(); let is_touch_grab = matches!(self.start_data, GrabStartData::Touch(_)); diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 850545be..c6f202cf 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -201,7 +201,7 @@ impl TabletToolTarget for ResizeForkTarget { tool, data: TabletToolGrabStartData { focus: None, - location: location, + location, trigger: TabletToolGrabTrigger::Tip, }, }, diff --git a/src/wayland/handlers/decoration.rs b/src/wayland/handlers/decoration.rs index ae58d338..a1efbd0a 100644 --- a/src/wayland/handlers/decoration.rs +++ b/src/wayland/handlers/decoration.rs @@ -69,17 +69,16 @@ impl State { XdgMode::from_preference(self.default_decoration()) }; for (window, _) in mapped.windows() { - if PreferredDecorationMode::is_unset(&window.0) { - if let Some(toplevel) = window.0.toplevel() { - if toplevel.with_committed_state(|state| { - state.is_some_and(|state| state.decoration_mode.is_some()) - }) { - toplevel.with_pending_state(|state| { - state.decoration_mode = Some(mode); - }); - toplevel.send_configure(); - } - } + if PreferredDecorationMode::is_unset(&window.0) + && let Some(toplevel) = window.0.toplevel() + && toplevel.with_committed_state(|state| { + state.is_some_and(|state| state.decoration_mode.is_some()) + }) + { + toplevel.with_pending_state(|state| { + state.decoration_mode = Some(mode); + }); + toplevel.send_configure(); } } }; diff --git a/src/wayland/handlers/pointer_constraints.rs b/src/wayland/handlers/pointer_constraints.rs index e024bb40..743b3b0b 100644 --- a/src/wayland/handlers/pointer_constraints.rs +++ b/src/wayland/handlers/pointer_constraints.rs @@ -89,7 +89,6 @@ impl PointerConstraintsHandler for State { ConstraintRemove::PointerLeave(_) => { // If the constraint was broken by the pointer forcibly leaving the surface, then it doesn't // make much sense to warp it. - return; } ConstraintRemove::Destroyed(constraint) => { let Some(seat) = self From f61c0f9f76caa8640de4e2077ec31b6c37d12866 Mon Sep 17 00:00:00 2001 From: haydonryan Date: Tue, 1 Sep 2026 14:07:30 -0500 Subject: [PATCH 34/37] tabs: avoid two HashSet allocations in tab-change detection Replace the symmetric_difference over two freshly-materialized HashSets with direct contains_key lookups on the existing key sets. Semantically identical (set difference non-empty iff any key is in exactly one set) but removes two heap HashSet allocations plus hashing of every key on each widget update. Also drops the now-unused HashSet import. Implements compact-idiomatic-code-20 from the cosmic-comp optimization report. Created with the help of DeepSeek V4 Flash. --- src/shell/element/stack/tabs.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/shell/element/stack/tabs.rs b/src/shell/element/stack/tabs.rs index 86218db6..9dd5ef81 100644 --- a/src/shell/element/stack/tabs.rs +++ b/src/shell/element/stack/tabs.rs @@ -31,7 +31,7 @@ use keyframe::{ functions::{EaseInOutCubic, EaseOutCubic}, }; use std::{ - collections::{HashMap, HashSet, VecDeque}, + collections::{HashMap, VecDeque}, time::{Duration, Instant}, }; @@ -757,12 +757,10 @@ where state.last_state = Some(current_state.clone()); } let last_state = state.last_state.as_mut().unwrap(); - let unknown_keys = current_state - .keys() - .collect::>() - .symmetric_difference(&last_state.keys().collect::>()) - .next() - .is_some(); + let unknown_keys = current_state.len() != last_state.len() + || current_state + .keys() + .any(|key| !last_state.contains_key(key)); enum Difference { NewOrRemoved, From 8ad541dbe311ccef0e7be8b67df9f6d5f23039d0 Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Tue, 8 Sep 2026 16:51:34 +0200 Subject: [PATCH 35/37] i18n: translation updates from weblate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Quentin PAGÈS Translate-URL: https://hosted.weblate.org/projects/pop-os/cosmic-comp/oc/ Translation: Pop OS/COSMIC Comp --- resources/i18n/oc/cosmic_comp.ftl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/resources/i18n/oc/cosmic_comp.ftl b/resources/i18n/oc/cosmic_comp.ftl index e69de29b..a1238332 100644 --- a/resources/i18n/oc/cosmic_comp.ftl +++ b/resources/i18n/oc/cosmic_comp.ftl @@ -0,0 +1,20 @@ +a11y-zoom-move-continuously = La vista bolega de contunh amb lo ponchador +a11y-zoom-move-onedge = La lista bolega quand lo ponchador atenh un caire +a11y-zoom-move-centered = La vista bolega per gardar lo ponchador al centre +a11y-zoom-settings = Paramètres de la lópia... +unknown-keybinding = +window-menu-tiled = Fenèstras bandejanta +window-menu-screenshot = Prendre una captura d’ecran +window-menu-resize = Redimensionar +window-menu-move-prev-workspace = Desplaçar a l’espaci de trabalh precedent +window-menu-move-next-workspace = Desplaçar a l'espaci de trabalh seguent +window-menu-stack = Crear una pila de fenèstras +window-menu-unstack-all = Desapilar totas las fenèstras +window-menu-unstack = Desapilar la fenèstra +window-menu-sticky = Fenèstra adesiva +window-menu-close = Tampar +window-menu-close-all = Tampar totas las fenèstras +window-menu-resize-edge-top = Amont +window-menu-resize-edge-left = Esquèrra +window-menu-resize-edge-right = Drecha +window-menu-resize-edge-bottom = Aval From 7d1daab7bc5db7ef0c4be64af1e35c8a24acfa9b Mon Sep 17 00:00:00 2001 From: Aleksandr Kosachev Date: Sun, 6 Sep 2026 19:36:12 +0300 Subject: [PATCH 36/37] fix: remove foreign toplevel handle too --- src/wayland/protocols/toplevel_info.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wayland/protocols/toplevel_info.rs b/src/wayland/protocols/toplevel_info.rs index 2dc76347..3146adc3 100644 --- a/src/wayland/protocols/toplevel_info.rs +++ b/src/wayland/protocols/toplevel_info.rs @@ -418,6 +418,12 @@ where handle.closed(); } } + // Remove the foreign handle too, so new subscribers cannot + // discover a toplevel whose window has already been destroyed. + if let Some(handle) = state.foreign_handle.take() { + self.foreign_toplevel_list.remove_toplevel(&handle); + } + *state = Default::default(); dirty = true; false } From a55785993e8ef6aad38862cb1a9e1ccaad3c340d Mon Sep 17 00:00:00 2001 From: apassert <249084898+apassert@users.noreply.github.com> Date: Wed, 2 Sep 2026 21:09:51 +0200 Subject: [PATCH 37/37] config: sort outputs by connector for deterministic fallback layout When no saved configuration matches the current output set, positions were assigned in hotplug/registration order. On hotplug races (e.g. reconnecting monitors through a KVM switch) outputs can appear in arbitrary order, producing a swapped left/right layout that then gets persisted to outputs.ron, poisoning all future reconnects. Sort outputs by connector name before generating fallback positions so the layout is deterministic regardless of arrival order. AI disclosure: implemented with the assistance of an LLM coding agent, directed, reviewed, and tested by the author. Signed-off-by: apassert <249084898+apassert@users.noreply.github.com> --- src/config/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index d3d2919b..4d2fad9b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -541,7 +541,13 @@ impl Config { primary.config_mut().xwayland_primary = true; } } - for output in outputs.iter().filter(|o| o.mirroring().is_none()) { + // sort by connector name for a deterministic layout independent of hotplug order + let mut sorted_outputs = outputs + .iter() + .filter(|o| o.mirroring().is_none()) + .collect::>(); + sorted_outputs.sort_by_key(|o| o.name()); + for output in sorted_outputs { { let mut config = output.config_mut(); config.position = (w, 0);