Skip to content

Commit 4356c14

Browse files
committed
test update to Smithay DnD PR
1 parent cfc01b8 commit 4356c14

File tree

4 files changed

+56
-35
lines changed

4 files changed

+56
-35
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handlers/mod.rs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ use smithay::backend::allocator::dmabuf::Dmabuf;
1313
use smithay::backend::drm::DrmNode;
1414
use smithay::backend::input::{InputEvent, TabletToolDescriptor};
1515
use smithay::desktop::{PopupKind, PopupManager};
16-
use smithay::input::pointer::{CursorIcon, CursorImageStatus, PointerHandle};
16+
use smithay::input::dnd::{self, DnDGrab, DndGrabHandler, DndTarget};
17+
use smithay::input::pointer::{CursorIcon, CursorImageStatus, Focus, PointerHandle};
1718
use smithay::input::{keyboard, Seat, SeatHandler, SeatState};
1819
use smithay::output::Output;
1920
use smithay::reexports::rustix::fs::{fcntl_setfl, OFlags};
2021
use smithay::reexports::wayland_protocols_wlr::screencopy::v1::server::zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1;
21-
use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
2222
use smithay::reexports::wayland_server::protocol::wl_output::WlOutput;
2323
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
2424
use smithay::reexports::wayland_server::Resource;
25-
use smithay::utils::{Logical, Point, Rectangle};
25+
use smithay::utils::{Logical, Point, Rectangle, Serial};
2626
use smithay::wayland::compositor::{get_parent, with_states};
2727
use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier};
2828
use smithay::wayland::drm_lease::{
@@ -41,8 +41,7 @@ use smithay::wayland::security_context::{
4141
SecurityContext, SecurityContextHandler, SecurityContextListenerSource,
4242
};
4343
use smithay::wayland::selection::data_device::{
44-
set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,
45-
ServerDndGrabHandler,
44+
set_data_device_focus, DataDeviceHandler, DataDeviceState, WaylandDndGrabHandler,
4645
};
4746
use smithay::wayland::selection::ext_data_control::{
4847
DataControlHandler as ExtDataControlHandler, DataControlState as ExtDataControlState,
@@ -314,23 +313,51 @@ impl DataDeviceHandler for State {
314313
}
315314
}
316315

317-
impl ClientDndGrabHandler for State {
318-
fn started(
316+
impl WaylandDndGrabHandler for State {
317+
fn dnd_requested<S: dnd::Source>(
319318
&mut self,
320-
_source: Option<WlDataSource>,
319+
source: S,
321320
icon: Option<WlSurface>,
322-
_seat: Seat<Self>,
321+
seat: Seat<Self>,
322+
serial: Serial,
323+
type_: dnd::GrabType,
323324
) {
324325
self.niri.dnd_icon = icon.map(|surface| DndIcon {
325326
surface,
326327
offset: Point::new(0, 0),
327328
});
329+
330+
match type_ {
331+
dnd::GrabType::Pointer => {
332+
let pointer = seat.get_pointer().unwrap();
333+
let start_data = pointer.grab_start_data().unwrap();
334+
let grab =
335+
DnDGrab::new_pointer(&self.niri.display_handle, start_data, source, seat);
336+
pointer.set_grab(self, grab, serial, Focus::Keep);
337+
}
338+
dnd::GrabType::Touch => {
339+
let touch = seat.get_touch().unwrap();
340+
let start_data = touch.grab_start_data().unwrap();
341+
let grab = DnDGrab::new_touch(&self.niri.display_handle, start_data, source, seat);
342+
touch.set_grab(self, grab, serial);
343+
}
344+
}
345+
328346
// FIXME: more granular
329347
self.niri.queue_redraw_all();
330348
}
349+
}
331350

332-
fn dropped(&mut self, target: Option<WlSurface>, validated: bool, _seat: Seat<Self>) {
333-
trace!("client dropped, target: {target:?}, validated: {validated}");
351+
impl DndGrabHandler for State {
352+
fn dropped(
353+
&mut self,
354+
target: Option<DndTarget<'_, Self>>,
355+
validated: bool,
356+
_seat: Seat<Self>,
357+
location: Point<f64, Logical>,
358+
) {
359+
let target: Option<&WlSurface> = target.map(DndTarget::into_inner);
360+
trace!("dnd dropped, target: {target:?}, validated: {validated}");
334361

335362
// End DnD before activating a specific window below so that it takes precedence.
336363
self.niri.layout.dnd_end();
@@ -349,19 +376,10 @@ impl ClientDndGrabHandler for State {
349376
}
350377

351378
if activate_output {
352-
// Find the output from cursor coordinates.
353-
//
354-
// FIXME: uhhh, we can't actually properly tell if the DnD comes from pointer or touch,
355-
// and if it comes from touch, then what the coordinates are. Need to pass more
356-
// parameters from Smithay I guess.
357-
//
358-
// Assume that hidden pointer means touch DnD.
359-
if self.niri.pointer_visibility.is_visible() {
360-
// We can't even get the current pointer location because it's locked (we're deep
361-
// in the grab call stack here). So use the last known one.
362-
if let Some(output) = &self.niri.pointer_contents.output {
363-
self.niri.layout.focus_output(output);
364-
}
379+
// Find the output from drop coordinates.
380+
if let Some((output, _)) = self.niri.output_under(location) {
381+
let output = output.clone();
382+
self.niri.layout.focus_output(&output);
365383
}
366384
}
367385

@@ -371,8 +389,6 @@ impl ClientDndGrabHandler for State {
371389
}
372390
}
373391

374-
impl ServerDndGrabHandler for State {}
375-
376392
delegate_data_device!(State);
377393

378394
impl PrimarySelectionHandler for State {

src/handlers/xdg_shell.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ use smithay::desktop::{
77
PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window,
88
WindowSurfaceType,
99
};
10+
use smithay::input::dnd::DnDGrab;
1011
use smithay::input::pointer::Focus;
1112
use smithay::output::Output;
1213
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
1314
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment;
1415
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self};
1516
use smithay::reexports::wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration;
17+
use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
1618
use smithay::reexports::wayland_server::protocol::wl_output;
1719
use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;
1820
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
@@ -24,7 +26,6 @@ use smithay::wayland::compositor::{
2426
};
2527
use smithay::wayland::dmabuf::get_dmabuf;
2628
use smithay::wayland::input_method::InputMethodSeat;
27-
use smithay::wayland::selection::data_device::DnDGrab;
2829
use smithay::wayland::shell::kde::decoration::{KdeDecorationHandler, KdeDecorationState};
2930
use smithay::wayland::shell::wlr_layer::{self, Layer};
3031
use smithay::wayland::shell::xdg::decoration::XdgDecorationHandler;
@@ -85,7 +86,8 @@ impl XdgShellHandler for State {
8586
if focus.id().same_client_as(&wl_surface.id()) {
8687
// Deny move requests from DnD grabs to work around
8788
// https://gitlab.gnome.org/GNOME/gtk/-/issues/7113
88-
let is_dnd_grab = grab.as_any().is::<DnDGrab<Self>>();
89+
let is_dnd_grab =
90+
grab.as_any().is::<DnDGrab<Self, WlDataSource, WlSurface>>();
8991

9092
if !is_dnd_grab {
9193
grab_start_data =
@@ -105,7 +107,8 @@ impl XdgShellHandler for State {
105107
if focus.id().same_client_as(&wl_surface.id()) {
106108
// Deny move requests from DnD grabs to work around
107109
// https://gitlab.gnome.org/GNOME/gtk/-/issues/7113
108-
let is_dnd_grab = grab.as_any().is::<DnDGrab<Self>>();
110+
let is_dnd_grab =
111+
grab.as_any().is::<DnDGrab<Self, WlDataSource, WlSurface>>();
109112

110113
if !is_dnd_grab {
111114
grab_start_data =

src/input/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use smithay::backend::input::{
1919
TabletToolTipState, TouchEvent,
2020
};
2121
use smithay::backend::libinput::LibinputInputBackend;
22+
use smithay::input::dnd::DnDGrab;
2223
use smithay::input::keyboard::{keysyms, FilterResult, Keysym, Layout, ModifiersState};
2324
use smithay::input::pointer::{
2425
AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
@@ -31,10 +32,11 @@ use smithay::input::touch::{
3132
};
3233
use smithay::input::SeatHandler;
3334
use smithay::output::Output;
35+
use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
36+
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
3437
use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER};
3538
use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor;
3639
use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
37-
use smithay::wayland::selection::data_device::DnDGrab;
3840
use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
3941
use touch_overview_grab::TouchOverviewGrab;
4042

@@ -2585,7 +2587,7 @@ impl State {
25852587
// Inform the layout of an ongoing DnD operation.
25862588
let mut is_dnd_grab = false;
25872589
pointer.with_grab(|_, grab| {
2588-
is_dnd_grab = grab.as_any().is::<DnDGrab<Self>>();
2590+
is_dnd_grab = grab.as_any().is::<DnDGrab<Self, WlDataSource, WlSurface>>();
25892591
});
25902592
if is_dnd_grab {
25912593
if let Some((output, pos_within_output)) = self.niri.output_under(new_pos) {
@@ -2684,7 +2686,7 @@ impl State {
26842686
// Inform the layout of an ongoing DnD operation.
26852687
let mut is_dnd_grab = false;
26862688
pointer.with_grab(|_, grab| {
2687-
is_dnd_grab = grab.as_any().is::<DnDGrab<Self>>();
2689+
is_dnd_grab = grab.as_any().is::<DnDGrab<Self, WlDataSource, WlSurface>>();
26882690
});
26892691
if is_dnd_grab {
26902692
if let Some((output, pos_within_output)) = self.niri.output_under(pos) {
@@ -4199,7 +4201,7 @@ impl State {
41994201
// Inform the layout of an ongoing DnD operation.
42004202
let mut is_dnd_grab = false;
42014203
handle.with_grab(|_, grab| {
4202-
is_dnd_grab = grab.as_any().is::<DnDGrab<Self>>();
4204+
is_dnd_grab = grab.as_any().is::<DnDGrab<Self, WlDataSource, WlSurface>>();
42034205
});
42044206
if is_dnd_grab {
42054207
if let Some((output, pos_within_output)) = self.niri.output_under(pos) {

0 commit comments

Comments
 (0)