forge
Explore
Log in

Don't you dare go Hollow

handle role specific buffer offset

Browse files at this commit

eb190e3f9447e4d49cfdcb5a0093443ca8b684feChristian MeisslParent: 80bb0d5
Cargo.lockmodified+2 -10
@@ -3346,12 +3346,6 @@ dependencies = [
3346 "winapi-util",3346 "winapi-util",
3347 ]3347 ]
3348 3348
3349-[[package]]
3350-name = "scan_fmt"
3351-version = "0.2.6"
3352-source = "registry+https://github.com/rust-lang/crates.io-index"
3353-checksum = "0b53b0a5db882a8e2fdaae0a43f7b39e7e9082389e978398bdf223a55b581248"
3354-
3355 [[package]]3349 [[package]]
3356 name = "schemars"3350 name = "schemars"
3357 version = "0.8.21"3351 version = "0.8.21"
@@ -3528,7 +3522,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
3528 [[package]]3522 [[package]]
3529 name = "smithay"3523 name = "smithay"
3530 version = "0.3.0"3524 version = "0.3.0"
3531-source = "git+https://github.com/Smithay/smithay.git#f364c73cae953aebfa189075e9f118f9008e100b"3525+source = "git+https://github.com/Smithay/smithay.git#b29ff8fdbfa3a15b777d36a7c5f19f86dfe5c94c"
3532 dependencies = [3526 dependencies = [
3533 "appendlist",3527 "appendlist",
3534 "bitflags 2.6.0",3528 "bitflags 2.6.0",
@@ -3545,7 +3539,6 @@ dependencies = [
3545 "gl_generator",3539 "gl_generator",
3546 "indexmap",3540 "indexmap",
3547 "input",3541 "input",
3548- "lazy_static",
3549 "libc",3542 "libc",
3550 "libloading",3543 "libloading",
3551 "libseat",3544 "libseat",
@@ -3555,7 +3548,6 @@ dependencies = [
3555 "profiling",3548 "profiling",
3556 "rand",3549 "rand",
3557 "rustix 0.38.37",3550 "rustix 0.38.37",
3558- "scan_fmt",
3559 "smallvec",3551 "smallvec",
3560 "tempfile",3552 "tempfile",
3561 "thiserror",3553 "thiserror",
@@ -3602,7 +3594,7 @@ dependencies = [
3602 [[package]]3594 [[package]]
3603 name = "smithay-drm-extras"3595 name = "smithay-drm-extras"
3604 version = "0.1.0"3596 version = "0.1.0"
3605-source = "git+https://github.com/Smithay/smithay.git#f364c73cae953aebfa189075e9f118f9008e100b"3597+source = "git+https://github.com/Smithay/smithay.git#b29ff8fdbfa3a15b777d36a7c5f19f86dfe5c94c"
3606 dependencies = [3598 dependencies = [
3607 "drm",3599 "drm",
3608 "libdisplay-info",3600 "libdisplay-info",
src/handlers/compositor.rsmodified+41 -2
@@ -1,7 +1,7 @@
1 use std::collections::hash_map::Entry;1 use std::collections::hash_map::Entry;
2 2
3 use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state};3 use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state};
4-use smithay::input::pointer::CursorImageStatus;4+use smithay::input::pointer::{CursorImageStatus, CursorImageSurfaceData};
5 use smithay::reexports::calloop::Interest;5 use smithay::reexports::calloop::Interest;
6 use smithay::reexports::wayland_server::protocol::wl_buffer;6 use smithay::reexports::wayland_server::protocol::wl_buffer;
7 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;7 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
@@ -297,13 +297,52 @@ impl CompositorHandler for State {
297 &self.niri.cursor_manager.cursor_image(),297 &self.niri.cursor_manager.cursor_image(),
298 CursorImageStatus::Surface(s) if s == &root_surface298 CursorImageStatus::Surface(s) if s == &root_surface
299 ) {299 ) {
300+ // In case the cursor surface has been committed handle the role specific
301+ // buffer offset by applying the offset on the cursor image hotspot
302+ if surface == &root_surface {
303+ with_states(surface, |states| {
304+ let cursor_image_attributes = states.data_map.get::<CursorImageSurfaceData>();
305+
306+ if let Some(mut cursor_image_attributes) =
307+ cursor_image_attributes.map(|attrs| attrs.lock().unwrap())
308+ {
309+ let buffer_delta = states
310+ .cached_state
311+ .get::<SurfaceAttributes>()
312+ .current()
313+ .buffer_delta
314+ .take();
315+ if let Some(buffer_delta) = buffer_delta {
316+ cursor_image_attributes.hotspot -= buffer_delta;
317+ }
318+ }
319+ });
320+ }
321+
300 // FIXME: granular redraws for cursors.322 // FIXME: granular redraws for cursors.
301 self.niri.queue_redraw_all();323 self.niri.queue_redraw_all();
302 return;324 return;
303 }325 }
304 326
305 // This might be a DnD icon surface.327 // This might be a DnD icon surface.
306- if self.niri.dnd_icon.as_ref() == Some(&root_surface) {328+ if matches!(&self.niri.dnd_icon, Some(icon) if icon.surface == root_surface) {
329+ let dnd_icon = self.niri.dnd_icon.as_mut().unwrap();
330+
331+ // In case the dnd surface has been committed handle the role specific
332+ // buffer offset by applying the offset on the dnd icon offset
333+ if surface == &dnd_icon.surface {
334+ with_states(&dnd_icon.surface, |states| {
335+ let buffer_delta = states
336+ .cached_state
337+ .get::<SurfaceAttributes>()
338+ .current()
339+ .buffer_delta
340+ .take()
341+ .unwrap_or_default();
342+ dnd_icon.offset += buffer_delta;
343+ });
344+ }
345+
307 // FIXME: granular redraws for cursors.346 // FIXME: granular redraws for cursors.
308 self.niri.queue_redraw_all();347 self.niri.queue_redraw_all();
309 return;348 return;
src/handlers/mod.rsmodified+22 -4
@@ -12,7 +12,9 @@ use smithay::backend::allocator::dmabuf::Dmabuf;
12 use smithay::backend::drm::DrmNode;12 use smithay::backend::drm::DrmNode;
13 use smithay::backend::input::TabletToolDescriptor;13 use smithay::backend::input::TabletToolDescriptor;
14 use smithay::desktop::{PopupKind, PopupManager};14 use smithay::desktop::{PopupKind, PopupManager};
15-use smithay::input::pointer::{CursorIcon, CursorImageStatus, PointerHandle};15+use smithay::input::pointer::{
16+ CursorIcon, CursorImageStatus, CursorImageSurfaceData, PointerHandle,
17+};
16 use smithay::input::{keyboard, Seat, SeatHandler, SeatState};18 use smithay::input::{keyboard, Seat, SeatHandler, SeatState};
17 use smithay::output::Output;19 use smithay::output::Output;
18 use smithay::reexports::rustix::fs::{fcntl_setfl, OFlags};20 use smithay::reexports::rustix::fs::{fcntl_setfl, OFlags};
@@ -22,7 +24,7 @@ use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
22 use smithay::reexports::wayland_server::protocol::wl_output::WlOutput;24 use smithay::reexports::wayland_server::protocol::wl_output::WlOutput;
23 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;25 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
24 use smithay::reexports::wayland_server::Resource;26 use smithay::reexports::wayland_server::Resource;
25-use smithay::utils::{Logical, Rectangle, Size};27+use smithay::utils::{Logical, Point, Rectangle, Size};
26 use smithay::wayland::compositor::with_states;28 use smithay::wayland::compositor::with_states;
27 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier};29 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier};
28 use smithay::wayland::drm_lease::{30 use smithay::wayland::drm_lease::{
@@ -64,7 +66,7 @@ use smithay::{
64 };66 };
65 67
66 pub use crate::handlers::xdg_shell::KdeDecorationsModeState;68 pub use crate::handlers::xdg_shell::KdeDecorationsModeState;
67-use crate::niri::{ClientState, State};69+use crate::niri::{ClientState, DndIcon, State};
68 use crate::protocols::foreign_toplevel::{70 use crate::protocols::foreign_toplevel::{
69 self, ForeignToplevelHandler, ForeignToplevelManagerState,71 self, ForeignToplevelHandler, ForeignToplevelManagerState,
70 };72 };
@@ -225,7 +227,23 @@ impl ClientDndGrabHandler for State {
225 icon: Option<WlSurface>,227 icon: Option<WlSurface>,
226 _seat: Seat<Self>,228 _seat: Seat<Self>,
227 ) {229 ) {
228- self.niri.dnd_icon = icon;230+ let offset = if let CursorImageStatus::Surface(ref surface) =
231+ self.niri.cursor_manager.cursor_image()
232+ {
233+ with_states(surface, |states| {
234+ let hotspot = states
235+ .data_map
236+ .get::<CursorImageSurfaceData>()
237+ .unwrap()
238+ .lock()
239+ .unwrap()
240+ .hotspot;
241+ Point::from((-hotspot.x, -hotspot.y))
242+ })
243+ } else {
244+ (0, 0).into()
245+ };
246+ self.niri.dnd_icon = icon.map(|surface| DndIcon { surface, offset });
229 // FIXME: more granular247 // FIXME: more granular
230 self.niri.queue_redraw_all();248 self.niri.queue_redraw_all();
231 }249 }
src/input/mod.rsmodified+7 -7
@@ -11,7 +11,7 @@ use niri_ipc::LayoutSwitchTarget;
11 use smithay::backend::input::{11 use smithay::backend::input::{
12 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,12 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
13 GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,13 GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
14- InputBackend, InputEvent, KeyState, KeyboardKeyEvent, MouseButton, PointerAxisEvent,14+ InputBackend, InputEvent, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent,
15 PointerButtonEvent, PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent,15 PointerButtonEvent, PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent,
16 TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent,16 TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent,
17 };17 };
@@ -2305,10 +2305,10 @@ impl State {
2305 /// to them from being delivered.2305 /// to them from being delivered.
2306 #[allow(clippy::too_many_arguments)]2306 #[allow(clippy::too_many_arguments)]
2307 fn should_intercept_key(2307 fn should_intercept_key(
2308- suppressed_keys: &mut HashSet<u32>,2308+ suppressed_keys: &mut HashSet<Keycode>,
2309 bindings: &Binds,2309 bindings: &Binds,
2310 comp_mod: CompositorMod,2310 comp_mod: CompositorMod,
2311- key_code: u32,2311+ key_code: Keycode,
2312 modified: Keysym,2312 modified: Keysym,
2313 raw: Option<Keysym>,2313 raw: Option<Keysym>,
2314 pressed: bool,2314 pressed: bool,
@@ -2754,8 +2754,8 @@ mod tests {
2754 // The key_code we pick is arbitrary, the only thing2754 // The key_code we pick is arbitrary, the only thing
2755 // that matters is that they are different between cases.2755 // that matters is that they are different between cases.
2756 2756
2757- let close_key_code = close_keysym.into();2757+ let close_key_code = Keycode::from(close_keysym.raw() + 8u32);
2758- let close_key_event = |suppr: &mut HashSet<u32>, mods: ModifiersState, pressed| {2758+ let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
2759 should_intercept_key(2759 should_intercept_key(
2760 suppr,2760 suppr,
2761 &bindings,2761 &bindings,
@@ -2771,12 +2771,12 @@ mod tests {
2771 };2771 };
2772 2772
2773 // Key event with the code which can't trigger any action.2773 // Key event with the code which can't trigger any action.
2774- let none_key_event = |suppr: &mut HashSet<u32>, mods: ModifiersState, pressed| {2774+ let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
2775 should_intercept_key(2775 should_intercept_key(
2776 suppr,2776 suppr,
2777 &bindings,2777 &bindings,
2778 comp_mod,2778 comp_mod,
2779- Keysym::l.into(),2779+ Keycode::from(Keysym::l.raw() + 8),
2780 Keysym::l,2780 Keysym::l,
2781 Some(Keysym::l),2781 Some(Keysym::l),
2782 pressed,2782 pressed,
src/niri.rsmodified+25 -15
@@ -17,6 +17,7 @@ use niri_config::{
17 DEFAULT_BACKGROUND_COLOR,17 DEFAULT_BACKGROUND_COLOR,
18 };18 };
19 use smithay::backend::allocator::Fourcc;19 use smithay::backend::allocator::Fourcc;
20+use smithay::backend::input::Keycode;
20 use smithay::backend::renderer::damage::OutputDamageTracker;21 use smithay::backend::renderer::damage::OutputDamageTracker;
21 use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement;22 use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement;
22 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};23 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
@@ -248,7 +249,7 @@ pub struct Niri {
248 249
249 pub seat: Seat<State>,250 pub seat: Seat<State>,
250 /// Scancodes of the keys to suppress.251 /// Scancodes of the keys to suppress.
251- pub suppressed_keys: HashSet<u32>,252+ pub suppressed_keys: HashSet<Keycode>,
252 pub bind_cooldown_timers: HashMap<Key, RegistrationToken>,253 pub bind_cooldown_timers: HashMap<Key, RegistrationToken>,
253 pub bind_repeat_timer: Option<RegistrationToken>,254 pub bind_repeat_timer: Option<RegistrationToken>,
254 pub keyboard_focus: KeyboardFocus,255 pub keyboard_focus: KeyboardFocus,
@@ -259,7 +260,7 @@ pub struct Niri {
259 pub cursor_manager: CursorManager,260 pub cursor_manager: CursorManager,
260 pub cursor_texture_cache: CursorTextureCache,261 pub cursor_texture_cache: CursorTextureCache,
261 pub cursor_shape_manager_state: CursorShapeManagerState,262 pub cursor_shape_manager_state: CursorShapeManagerState,
262- pub dnd_icon: Option<WlSurface>,263+ pub dnd_icon: Option<DndIcon>,
263 pub pointer_focus: PointerFocus,264 pub pointer_focus: PointerFocus,
264 /// Whether the pointer is hidden, for example due to a previous touch input.265 /// Whether the pointer is hidden, for example due to a previous touch input.
265 ///266 ///
@@ -304,6 +305,12 @@ pub struct Niri {
304 pub mapped_cast_output: HashMap<Window, Output>,305 pub mapped_cast_output: HashMap<Window, Output>,
305 }306 }
306 307
308+#[derive(Debug)]
309+pub struct DndIcon {
310+ pub surface: WlSurface,
311+ pub offset: Point<i32, Logical>,
312+}
313+
307 pub struct OutputState {314 pub struct OutputState {
308 pub global: GlobalId,315 pub global: GlobalId,
309 pub frame_clock: FrameClock,316 pub frame_clock: FrameClock,
@@ -2588,8 +2595,8 @@ impl Niri {
2588 2595
2589 let output_scale = Scale::from(output.current_scale().fractional_scale());2596 let output_scale = Scale::from(output.current_scale().fractional_scale());
2590 2597
2591- let (mut pointer_elements, pointer_pos) = match render_cursor {2598+ let mut pointer_elements = match render_cursor {
2592- RenderCursor::Hidden => (vec![], pointer_pos.to_physical_precise_round(output_scale)),2599+ RenderCursor::Hidden => vec![],
2593 RenderCursor::Surface { surface, hotspot } => {2600 RenderCursor::Surface { surface, hotspot } => {
2594 let pointer_pos =2601 let pointer_pos =
2595 (pointer_pos - hotspot.to_f64()).to_physical_precise_round(output_scale);2602 (pointer_pos - hotspot.to_f64()).to_physical_precise_round(output_scale);
@@ -2603,7 +2610,7 @@ impl Niri {
2603 Kind::Cursor,2610 Kind::Cursor,
2604 );2611 );
2605 2612
2606- (pointer_elements, pointer_pos)2613+ pointer_elements
2607 }2614 }
2608 RenderCursor::Named {2615 RenderCursor::Named {
2609 icon,2616 icon,
@@ -2619,7 +2626,7 @@ impl Niri {
2619 let mut pointer_elements = vec![];2626 let mut pointer_elements = vec![];
2620 let pointer_element = match MemoryRenderBufferRenderElement::from_buffer(2627 let pointer_element = match MemoryRenderBufferRenderElement::from_buffer(
2621 renderer,2628 renderer,
2622- pointer_pos.to_f64(),2629+ pointer_pos,
2623 &texture,2630 &texture,
2624 None,2631 None,
2625 None,2632 None,
@@ -2636,14 +2643,16 @@ impl Niri {
2636 pointer_elements.push(OutputRenderElements::NamedPointer(element));2643 pointer_elements.push(OutputRenderElements::NamedPointer(element));
2637 }2644 }
2638 2645
2639- (pointer_elements, pointer_pos)2646+ pointer_elements
2640 }2647 }
2641 };2648 };
2642 2649
2643- if let Some(dnd_icon) = &self.dnd_icon {2650+ if let Some(dnd_icon) = self.dnd_icon.as_ref() {
2651+ let pointer_pos =
2652+ (pointer_pos + dnd_icon.offset.to_f64()).to_physical_precise_round(output_scale);
2644 pointer_elements.extend(render_elements_from_surface_tree(2653 pointer_elements.extend(render_elements_from_surface_tree(
2645 renderer,2654 renderer,
2646- dnd_icon,2655+ &dnd_icon.surface,
2647 pointer_pos,2656 pointer_pos,
2648 output_scale,2657 output_scale,
2649 1.,2658 1.,
@@ -2684,6 +2693,7 @@ impl Niri {
2684 let dnd = self2693 let dnd = self
2685 .dnd_icon2694 .dnd_icon
2686 .as_ref()2695 .as_ref()
2696+ .map(|icon| &icon.surface)
2687 .map(|surface| (surface, bbox_from_surface_tree(surface, surface_pos)));2697 .map(|surface| (surface, bbox_from_surface_tree(surface, surface_pos)));
2688 2698
2689 // FIXME we basically need to pick the largest scale factor across the overlapping2699 // FIXME we basically need to pick the largest scale factor across the overlapping
@@ -2745,7 +2755,7 @@ impl Niri {
2745 }2755 }
2746 cursor_image => {2756 cursor_image => {
2747 // There's no cursor surface, but there might be a DnD icon.2757 // There's no cursor surface, but there might be a DnD icon.
2748- let Some(surface) = &self.dnd_icon else {2758+ let Some(surface) = self.dnd_icon.as_ref().map(|icon| &icon.surface) else {
2749 return;2759 return;
2750 };2760 };
2751 2761
@@ -3267,7 +3277,7 @@ impl Niri {
3267 );3277 );
3268 }3278 }
3269 3279
3270- if let Some(surface) = &self.dnd_icon {3280+ if let Some(surface) = self.dnd_icon.as_ref().map(|icon| &icon.surface) {
3271 with_surface_tree_downward(3281 with_surface_tree_downward(
3272 surface,3282 surface,
3273 (),3283 (),
@@ -3405,7 +3415,7 @@ impl Niri {
3405 );3415 );
3406 }3416 }
3407 3417
3408- if let Some(surface) = &self.dnd_icon {3418+ if let Some(surface) = self.dnd_icon.as_ref().map(|icon| &icon.surface) {
3409 send_dmabuf_feedback_surface_tree(3419 send_dmabuf_feedback_surface_tree(
3410 surface,3420 surface,
3411 output,3421 output,
@@ -3507,7 +3517,7 @@ impl Niri {
3507 );3517 );
3508 }3518 }
3509 3519
3510- if let Some(surface) = &self.dnd_icon {3520+ if let Some(surface) = self.dnd_icon.as_ref().map(|icon| &icon.surface) {
3511 send_frames_surface_tree(3521 send_frames_surface_tree(
3512 surface,3522 surface,
3513 output,3523 output,
@@ -3575,7 +3585,7 @@ impl Niri {
3575 }3585 }
3576 }3586 }
3577 3587
3578- if let Some(surface) = &self.dnd_icon {3588+ if let Some(surface) = &self.dnd_icon.as_ref().map(|icon| &icon.surface) {
3579 send_frames_surface_tree(3589 send_frames_surface_tree(
3580 surface,3590 surface,
3581 output,3591 output,
@@ -3614,7 +3624,7 @@ impl Niri {
3614 );3624 );
3615 }3625 }
3616 3626
3617- if let Some(surface) = &self.dnd_icon {3627+ if let Some(surface) = self.dnd_icon.as_ref().map(|icon| &icon.surface) {
3618 take_presentation_feedback_surface_tree(3628 take_presentation_feedback_surface_tree(
3619 surface,3629 surface,
3620 &mut feedback,3630 &mut feedback,