diff options
| author | Christian Meissl <meissl.christian@gmail.com> | 2024-02-24 18:17:51 +0100 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-09-30 05:04:58 -0700 |
| commit | eb190e3f9447e4d49cfdcb5a0093443ca8b684fe (patch) | |
| tree | 7845bc23b9ed43bb75464d2dff5442d2d02285c5 /src/handlers | |
| parent | 80bb0d5876f8fae43791a8d6e52a38d3c1e01a72 (diff) | |
| download | niri-eb190e3f9447e4d49cfdcb5a0093443ca8b684fe.tar.gz niri-eb190e3f9447e4d49cfdcb5a0093443ca8b684fe.tar.bz2 niri-eb190e3f9447e4d49cfdcb5a0093443ca8b684fe.zip | |
handle role specific buffer offset
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/compositor.rs | 43 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 26 |
2 files changed, 63 insertions, 6 deletions
diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index 57be5ad3..ceb22b78 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -1,7 +1,7 @@ use std::collections::hash_map::Entry; use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state}; -use smithay::input::pointer::CursorImageStatus; +use smithay::input::pointer::{CursorImageStatus, CursorImageSurfaceData}; use smithay::reexports::calloop::Interest; use smithay::reexports::wayland_server::protocol::wl_buffer; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; @@ -297,13 +297,52 @@ impl CompositorHandler for State { &self.niri.cursor_manager.cursor_image(), CursorImageStatus::Surface(s) if s == &root_surface ) { + // In case the cursor surface has been committed handle the role specific + // buffer offset by applying the offset on the cursor image hotspot + if surface == &root_surface { + with_states(surface, |states| { + let cursor_image_attributes = states.data_map.get::<CursorImageSurfaceData>(); + + if let Some(mut cursor_image_attributes) = + cursor_image_attributes.map(|attrs| attrs.lock().unwrap()) + { + let buffer_delta = states + .cached_state + .get::<SurfaceAttributes>() + .current() + .buffer_delta + .take(); + if let Some(buffer_delta) = buffer_delta { + cursor_image_attributes.hotspot -= buffer_delta; + } + } + }); + } + // FIXME: granular redraws for cursors. self.niri.queue_redraw_all(); return; } // This might be a DnD icon surface. - if self.niri.dnd_icon.as_ref() == Some(&root_surface) { + if matches!(&self.niri.dnd_icon, Some(icon) if icon.surface == root_surface) { + let dnd_icon = self.niri.dnd_icon.as_mut().unwrap(); + + // In case the dnd surface has been committed handle the role specific + // buffer offset by applying the offset on the dnd icon offset + if surface == &dnd_icon.surface { + with_states(&dnd_icon.surface, |states| { + let buffer_delta = states + .cached_state + .get::<SurfaceAttributes>() + .current() + .buffer_delta + .take() + .unwrap_or_default(); + dnd_icon.offset += buffer_delta; + }); + } + // FIXME: granular redraws for cursors. self.niri.queue_redraw_all(); return; diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 3e0bb18f..63bde132 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -12,7 +12,9 @@ use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::drm::DrmNode; use smithay::backend::input::TabletToolDescriptor; use smithay::desktop::{PopupKind, PopupManager}; -use smithay::input::pointer::{CursorIcon, CursorImageStatus, PointerHandle}; +use smithay::input::pointer::{ + CursorIcon, CursorImageStatus, CursorImageSurfaceData, PointerHandle, +}; use smithay::input::{keyboard, Seat, SeatHandler, SeatState}; use smithay::output::Output; use smithay::reexports::rustix::fs::{fcntl_setfl, OFlags}; @@ -22,7 +24,7 @@ use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource; use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::Resource; -use smithay::utils::{Logical, Rectangle, Size}; +use smithay::utils::{Logical, Point, Rectangle, Size}; use smithay::wayland::compositor::with_states; use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier}; use smithay::wayland::drm_lease::{ @@ -64,7 +66,7 @@ use smithay::{ }; pub use crate::handlers::xdg_shell::KdeDecorationsModeState; -use crate::niri::{ClientState, State}; +use crate::niri::{ClientState, DndIcon, State}; use crate::protocols::foreign_toplevel::{ self, ForeignToplevelHandler, ForeignToplevelManagerState, }; @@ -225,7 +227,23 @@ impl ClientDndGrabHandler for State { icon: Option<WlSurface>, _seat: Seat<Self>, ) { - self.niri.dnd_icon = icon; + let offset = if let CursorImageStatus::Surface(ref surface) = + self.niri.cursor_manager.cursor_image() + { + with_states(surface, |states| { + let hotspot = states + .data_map + .get::<CursorImageSurfaceData>() + .unwrap() + .lock() + .unwrap() + .hotspot; + Point::from((-hotspot.x, -hotspot.y)) + }) + } else { + (0, 0).into() + }; + self.niri.dnd_icon = icon.map(|surface| DndIcon { surface, offset }); // FIXME: more granular self.niri.queue_redraw_all(); } |
