@@ -3,7 +3,7 @@ use std::os::fd::OwnedFd;
33use std:: sync:: Mutex ;
44
55use itertools:: Itertools ;
6- use sctk:: data_device_manager:: data_offer:: receive_to_fd;
6+ use sctk:: data_device_manager:: { data_device :: DataDeviceData , data_offer:: receive_to_fd} ;
77use sctk:: delegate_subcompositor;
88use sctk:: reexports:: client:: protocol:: wl_data_device_manager:: DndAction as ClientDndAction ;
99use sctk:: shm:: multi:: MultiPool ;
@@ -192,6 +192,48 @@ impl DataDeviceHandler for GlobalState {
192192 ) -> & mut smithay:: wayland:: selection:: data_device:: DataDeviceState {
193193 & mut self . server_state . data_device_state
194194 }
195+
196+ fn action_choice (
197+ & mut self ,
198+ available : smithay:: reexports:: wayland_server:: protocol:: wl_data_device_manager:: DndAction ,
199+ preferred : smithay:: reexports:: wayland_server:: protocol:: wl_data_device_manager:: DndAction ,
200+ ) -> smithay:: reexports:: wayland_server:: protocol:: wl_data_device_manager:: DndAction {
201+ use smithay:: reexports:: wayland_server:: protocol:: wl_data_device_manager:: DndAction as WlDndAction ;
202+ let dnd_seat =
203+ match self . server_state . seats . iter_mut ( ) . find ( |s| s. client . dnd_source . is_some ( ) ) {
204+ Some ( s) => s,
205+ None => return preferred,
206+ } ;
207+
208+ let offer = match dnd_seat. client . data_device . data ( ) . drag_offer ( ) {
209+ Some ( offer) => offer,
210+ None => return preferred,
211+ } ;
212+
213+ let mut client_actions = ClientDndAction :: empty ( ) ;
214+ if available. contains ( WlDndAction :: Copy ) {
215+ client_actions |= ClientDndAction :: Copy ;
216+ }
217+ if available. contains ( WlDndAction :: Move ) {
218+ client_actions |= ClientDndAction :: Move ;
219+ }
220+ if available. contains ( WlDndAction :: Ask ) {
221+ client_actions |= ClientDndAction :: Ask ;
222+ }
223+ let mut client_preferred = ClientDndAction :: empty ( ) ;
224+ if preferred. contains ( WlDndAction :: Copy ) {
225+ client_preferred |= ClientDndAction :: Copy ;
226+ }
227+ if preferred. contains ( WlDndAction :: Move ) {
228+ client_preferred |= ClientDndAction :: Move ;
229+ }
230+ if preferred. contains ( WlDndAction :: Ask ) {
231+ client_preferred |= ClientDndAction :: Ask ;
232+ }
233+ offer. set_actions ( client_actions, client_preferred) ;
234+ dbg ! ( "set actions" , client_actions, client_preferred) ;
235+ preferred
236+ }
195237}
196238
197239impl DndGrabHandler for GlobalState {
@@ -231,13 +273,15 @@ impl WaylandDndGrabHandler for GlobalState {
231273 ) {
232274 // TODO icon
233275
234- println ! ( "dnd_requested" ) ;
276+ println ! ( "FOO dnd_requested" ) ;
235277
236278 let seat = match self . server_state . seats . iter_mut ( ) . find ( |s| s. server . seat == seat) {
237279 Some ( s) => s,
238280 None => return ,
239281 } ;
240282
283+ dbg ! ( "FOO DND REQUESTED 2" ) ;
284+
241285 if let Some ( metadata) = source. metadata ( ) {
242286 seat. client . next_dnd_offer_is_mine = true ;
243287 let mut actions = ClientDndAction :: empty ( ) ;
@@ -250,6 +294,7 @@ impl WaylandDndGrabHandler for GlobalState {
250294 if metadata. dnd_actions . contains ( & DndAction :: Ask ) {
251295 actions |= ClientDndAction :: Ask ;
252296 }
297+ dbg ! ( & metadata. mime_types) ;
253298
254299 let dnd_source = self . client_state . data_device_manager . create_drag_and_drop_source (
255300 & self . client_state . queue_handle ,
@@ -264,13 +309,16 @@ impl WaylandDndGrabHandler for GlobalState {
264309 . compositor_state
265310 . create_surface ( & self . client_state . queue_handle )
266311 } ) ;
312+
313+ dbg ! ( "FOO DND CLIENT START" ) ;
267314 dnd_source. start_drag (
268315 & seat. client . data_device ,
269316 & focus. 0 ,
270317 c_icon_surface. as_ref ( ) ,
271318 seat. client . get_serial_of_last_seat_event ( ) ,
272319 ) ;
273320 if let Some ( client_surface) = c_icon_surface. as_ref ( ) {
321+ dbg ! ( "FOO DND ICON SURFACE CREATED" ) ;
274322 client_surface. frame ( & self . client_state . queue_handle , client_surface. clone ( ) ) ;
275323 client_surface. commit ( ) ;
276324
@@ -286,12 +334,14 @@ impl WaylandDndGrabHandler for GlobalState {
286334 seat. client . dnd_source = Some ( dnd_source) ;
287335 }
288336
337+ dbg ! ( "FOO DND REQUESTED 3" ) ;
289338 //seat.server.dnd_source = source;
290339 seat. server . dnd_icon = icon;
291340
292341 let seat = seat. server . seat . clone ( ) ;
293342 match type_ {
294343 GrabType :: Pointer => {
344+ dbg ! ( "Starting server pointer grab for DND" ) ;
295345 let pointer = seat. get_pointer ( ) . unwrap ( ) ;
296346 let start_data = pointer. grab_start_data ( ) . unwrap ( ) ;
297347 pointer. set_grab (
@@ -384,19 +434,20 @@ pub(crate) struct ServerGrabSource {
384434
385435impl smithay:: utils:: IsAlive for ServerGrabSource {
386436 fn alive ( & self ) -> bool {
387- println ! ( "FOO" ) ;
437+ println ! ( "FOO ALIVE " ) ;
388438 //todo!()
389439 true
390440 }
391441}
392442
393443impl smithay:: input:: dnd:: Source for ServerGrabSource {
394444 fn metadata ( & self ) -> Option < SourceMetadata > {
445+ println ! ( "FOO METADATA" ) ;
395446 Some ( self . metadata . clone ( ) )
396447 }
397448
398449 fn choose_action ( & self , action : smithay:: input:: dnd:: DndAction ) {
399- println ! ( "CHOOSE_ACTION?" ) ;
450+ println ! ( "FOO CHOOSE_ACTION?" ) ;
400451 // XXX actions?
401452 //
402453 let mut c_action = ClientDndAction :: empty ( ) ;
@@ -414,22 +465,21 @@ impl smithay::input::dnd::Source for ServerGrabSource {
414465 }
415466
416467 fn send ( & self , mime_type : & str , fd : OwnedFd ) {
417- println ! ( "FOO" ) ;
468+ println ! ( "FOO SEND " ) ;
418469 receive_to_fd ( self . dnd_offer . inner ( ) , mime_type. to_owned ( ) , fd)
419470 }
420471
421472 fn drop_performed ( & self ) {
422- println ! ( "FOO" ) ;
423- println ! ( "DROP_PERFORMED?" ) ;
473+ println ! ( "FOO DROP_PERFORMED" ) ;
424474 }
425475
426476 fn cancel ( & self ) {
427- println ! ( "FOO" ) ;
477+ println ! ( "FOO CANCEL " ) ;
428478 self . dnd_offer . destroy ( ) ;
429479 }
430480
431481 fn finished ( & self ) {
432- println ! ( "FOO" ) ;
482+ println ! ( "FOO FINISHED " ) ;
433483 self . dnd_offer . finish ( ) ;
434484 }
435485}
0 commit comments