Add dnd icon support
Browse files at this commit162c74c259910cc889efab2c3c6e8aa3f62c99c2Parent: 2465bba2 changed files +55 -22
- src/handlers/mod.rs +22 -1
- src/niri.rs +33 -21
src/handlers/mod.rsmodified+22 -1
| @@ -4,6 +4,7 @@ mod xdg_shell; | |||
| 4 | 4 | ||
| 5 | use smithay::input::pointer::CursorImageStatus; | 5 | use smithay::input::pointer::CursorImageStatus; |
| 6 | use smithay::input::{Seat, SeatHandler, SeatState}; | 6 | use smithay::input::{Seat, SeatHandler, SeatState}; |
| 7 | +use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource; | ||
| 7 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 8 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 8 | use smithay::reexports::wayland_server::Resource; | 9 | use smithay::reexports::wayland_server::Resource; |
| 9 | use smithay::wayland::data_device::{ | 10 | use smithay::wayland::data_device::{ |
| @@ -42,8 +43,28 @@ impl DataDeviceHandler for Niri { | |||
| 42 | &self.data_device_state | 43 | &self.data_device_state |
| 43 | } | 44 | } |
| 44 | } | 45 | } |
| 45 | -impl ClientDndGrabHandler for Niri {} | 46 | + |
| 47 | +impl ClientDndGrabHandler for Niri { | ||
| 48 | + fn started( | ||
| 49 | + &mut self, | ||
| 50 | + _source: Option<WlDataSource>, | ||
| 51 | + icon: Option<WlSurface>, | ||
| 52 | + _seat: Seat<Self>, | ||
| 53 | + ) { | ||
| 54 | + self.dnd_icon = icon; | ||
| 55 | + // FIXME: more granular | ||
| 56 | + self.queue_redraw_all(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + fn dropped(&mut self, _seat: Seat<Self>) { | ||
| 60 | + self.dnd_icon = None; | ||
| 61 | + // FIXME: more granular | ||
| 62 | + self.queue_redraw_all(); | ||
| 63 | + } | ||
| 64 | +} | ||
| 65 | + | ||
| 46 | impl ServerDndGrabHandler for Niri {} | 66 | impl ServerDndGrabHandler for Niri {} |
| 67 | + | ||
| 47 | delegate_data_device!(Niri); | 68 | delegate_data_device!(Niri); |
| 48 | 69 | ||
| 49 | delegate_output!(Niri); | 70 | delegate_output!(Niri); |
src/niri.rsmodified+33 -21
| @@ -72,6 +72,7 @@ pub struct Niri { | |||
| 72 | 72 | ||
| 73 | pub pointer_buffer: SolidColorBuffer, | 73 | pub pointer_buffer: SolidColorBuffer, |
| 74 | pub cursor_image: CursorImageStatus, | 74 | pub cursor_image: CursorImageStatus, |
| 75 | + pub dnd_icon: Option<WlSurface>, | ||
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | pub struct OutputState { | 78 | pub struct OutputState { |
| @@ -176,6 +177,7 @@ impl Niri { | |||
| 176 | seat, | 177 | seat, |
| 177 | pointer_buffer, | 178 | pointer_buffer, |
| 178 | cursor_image: CursorImageStatus::Default, | 179 | cursor_image: CursorImageStatus::Default, |
| 180 | + dnd_icon: None, | ||
| 179 | } | 181 | } |
| 180 | } | 182 | } |
| 181 | 183 | ||
| @@ -332,24 +334,9 @@ impl Niri { | |||
| 332 | let output_pos = self.global_space.output_geometry(output).unwrap().loc; | 334 | let output_pos = self.global_space.output_geometry(output).unwrap().loc; |
| 333 | let pointer_pos = self.seat.get_pointer().unwrap().current_location() - output_pos.to_f64(); | 335 | let pointer_pos = self.seat.get_pointer().unwrap().current_location() - output_pos.to_f64(); |
| 334 | 336 | ||
| 335 | - if let CursorImageStatus::Surface(surface) = &mut self.cursor_image { | 337 | + let hotspot = if let CursorImageStatus::Surface(surface) = &mut self.cursor_image { |
| 336 | - if !surface.alive() { | 338 | + if surface.alive() { |
| 337 | - self.cursor_image = CursorImageStatus::Default; | 339 | + with_states(surface, |states| { |
| 338 | - } | ||
| 339 | - } | ||
| 340 | - | ||
| 341 | - match &self.cursor_image { | ||
| 342 | - CursorImageStatus::Hidden => vec![], | ||
| 343 | - CursorImageStatus::Default => vec![OutputRenderElements::DefaultPointer( | ||
| 344 | - SolidColorRenderElement::from_buffer( | ||
| 345 | - &self.pointer_buffer, | ||
| 346 | - pointer_pos.to_physical_precise_round(1.), | ||
| 347 | - 1., | ||
| 348 | - 1., | ||
| 349 | - ), | ||
| 350 | - )], | ||
| 351 | - CursorImageStatus::Surface(surface) => { | ||
| 352 | - let hotspot = with_states(surface, |states| { | ||
| 353 | states | 340 | states |
| 354 | .data_map | 341 | .data_map |
| 355 | .get::<Mutex<CursorImageAttributes>>() | 342 | .get::<Mutex<CursorImageAttributes>>() |
| @@ -357,12 +344,37 @@ impl Niri { | |||
| 357 | .lock() | 344 | .lock() |
| 358 | .unwrap() | 345 | .unwrap() |
| 359 | .hotspot | 346 | .hotspot |
| 360 | - }); | 347 | + }) |
| 361 | - let pos = (pointer_pos - hotspot.to_f64()).to_physical_precise_round(1.); | 348 | + } else { |
| 349 | + self.cursor_image = CursorImageStatus::Default; | ||
| 350 | + (0, 0).into() | ||
| 351 | + } | ||
| 352 | + } else { | ||
| 353 | + (0, 0).into() | ||
| 354 | + }; | ||
| 355 | + let pointer_pos = (pointer_pos - hotspot.to_f64()).to_physical_precise_round(1.); | ||
| 362 | 356 | ||
| 363 | - render_elements_from_surface_tree(renderer, surface, pos, 1., 1.) | 357 | + let mut pointer_elements = match &self.cursor_image { |
| 358 | + CursorImageStatus::Hidden => vec![], | ||
| 359 | + CursorImageStatus::Default => vec![OutputRenderElements::DefaultPointer( | ||
| 360 | + SolidColorRenderElement::from_buffer(&self.pointer_buffer, pointer_pos, 1., 1.), | ||
| 361 | + )], | ||
| 362 | + CursorImageStatus::Surface(surface) => { | ||
| 363 | + render_elements_from_surface_tree(renderer, surface, pointer_pos, 1., 1.) | ||
| 364 | } | 364 | } |
| 365 | + }; | ||
| 366 | + | ||
| 367 | + if let Some(dnd_icon) = &self.dnd_icon { | ||
| 368 | + pointer_elements.extend(render_elements_from_surface_tree( | ||
| 369 | + renderer, | ||
| 370 | + dnd_icon, | ||
| 371 | + pointer_pos, | ||
| 372 | + 1., | ||
| 373 | + 1., | ||
| 374 | + )); | ||
| 365 | } | 375 | } |
| 376 | + | ||
| 377 | + pointer_elements | ||
| 366 | } | 378 | } |
| 367 | 379 | ||
| 368 | fn redraw(&mut self, backend: &mut dyn Backend, output: &Output) { | 380 | fn redraw(&mut self, backend: &mut dyn Backend, output: &Output) { |