@@ -16,18 +16,12 @@ use wayland_client::protocol::wl_registry::WlRegistry;
16
16
use wayland_client:: protocol:: wl_seat:: WlSeat ;
17
17
use wayland_client:: {
18
18
delegate_dispatch, event_created_child, ConnectError , Dispatch , DispatchError , EventQueue ,
19
- Proxy ,
20
- } ;
21
- use wayland_protocols_wlr:: data_control:: v1:: client:: zwlr_data_control_device_v1:: {
22
- self , ZwlrDataControlDeviceV1 ,
23
- } ;
24
- use wayland_protocols_wlr:: data_control:: v1:: client:: zwlr_data_control_manager_v1:: ZwlrDataControlManagerV1 ;
25
- use wayland_protocols_wlr:: data_control:: v1:: client:: zwlr_data_control_offer_v1:: ZwlrDataControlOfferV1 ;
26
- use wayland_protocols_wlr:: data_control:: v1:: client:: zwlr_data_control_source_v1:: {
27
- self , ZwlrDataControlSourceV1 ,
28
19
} ;
29
20
30
21
use crate :: common:: { self , initialize} ;
22
+ use crate :: data_control:: {
23
+ self , impl_dispatch_device, impl_dispatch_manager, impl_dispatch_offer, impl_dispatch_source,
24
+ } ;
31
25
use crate :: seat_data:: SeatData ;
32
26
use crate :: utils:: is_text;
33
27
@@ -40,8 +34,8 @@ pub enum ClipboardType {
40
34
Regular ,
41
35
/// The "primary" clipboard.
42
36
///
43
- /// Working with the "primary" clipboard requires the compositor to support the data-control
44
- /// protocol of version 2 or above.
37
+ /// Working with the "primary" clipboard requires the compositor to support ext- data-control,
38
+ /// or wlr-data-control version 2 or above.
45
39
Primary ,
46
40
/// Operate on both clipboards at once.
47
41
///
@@ -144,7 +138,7 @@ pub struct Options {
144
138
pub struct PreparedCopy {
145
139
queue : EventQueue < State > ,
146
140
state : State ,
147
- sources : Vec < ZwlrDataControlSourceV1 > ,
141
+ sources : Vec < data_control :: Source > ,
148
142
}
149
143
150
144
/// Errors that can occur for copying the source data to a temporary file.
@@ -194,11 +188,10 @@ pub enum Error {
194
188
WaylandCommunication ( #[ source] DispatchError ) ,
195
189
196
190
#[ error(
197
- "A required Wayland protocol ({} version {}) is not supported by the compositor" ,
198
- name,
199
- version
191
+ "A required Wayland protocol (ext-data-control, or wlr-data-control version {version}) \
192
+ is not supported by the compositor"
200
193
) ]
201
- MissingProtocol { name : & ' static str , version : u32 } ,
194
+ MissingProtocol { version : u32 } ,
202
195
203
196
#[ error( "The compositor does not support primary selection" ) ]
204
197
PrimarySelectionUnsupported ,
@@ -227,7 +220,7 @@ impl From<common::Error> for Error {
227
220
SocketOpenError ( err) => Error :: SocketOpenError ( err) ,
228
221
WaylandConnection ( err) => Error :: WaylandConnection ( err) ,
229
222
WaylandCommunication ( err) => Error :: WaylandCommunication ( err. into ( ) ) ,
230
- MissingProtocol { name , version } => Error :: MissingProtocol { name , version } ,
223
+ MissingProtocol { version } => Error :: MissingProtocol { version } ,
231
224
}
232
225
}
233
226
}
@@ -273,115 +266,75 @@ impl Dispatch<WlRegistry, GlobalListContents> for State {
273
266
}
274
267
}
275
268
276
- impl Dispatch < ZwlrDataControlManagerV1 , ( ) > for State {
277
- fn event (
278
- _state : & mut Self ,
279
- _proxy : & ZwlrDataControlManagerV1 ,
280
- _event : <ZwlrDataControlManagerV1 as wayland_client:: Proxy >:: Event ,
281
- _data : & ( ) ,
282
- _conn : & wayland_client:: Connection ,
283
- _qhandle : & wayland_client:: QueueHandle < Self > ,
284
- ) {
285
- }
286
- }
269
+ impl_dispatch_manager ! ( State ) ;
287
270
288
- impl Dispatch < ZwlrDataControlDeviceV1 , WlSeat > for State {
289
- fn event (
290
- state : & mut Self ,
291
- _device : & ZwlrDataControlDeviceV1 ,
292
- event : <ZwlrDataControlDeviceV1 as Proxy >:: Event ,
293
- seat : & WlSeat ,
294
- _conn : & wayland_client:: Connection ,
295
- _qhandle : & wayland_client:: QueueHandle < Self > ,
296
- ) {
297
- match event {
298
- zwlr_data_control_device_v1:: Event :: DataOffer { id } => id. destroy ( ) ,
299
- zwlr_data_control_device_v1:: Event :: Finished => {
300
- state. common . seats . get_mut ( seat) . unwrap ( ) . set_device ( None ) ;
301
- }
302
- zwlr_data_control_device_v1:: Event :: PrimarySelection { .. } => {
303
- state. got_primary_selection = true ;
304
- }
305
- _ => ( ) ,
271
+ impl_dispatch_device ! ( State , WlSeat , |state: & mut Self , event, seat| {
272
+ match event {
273
+ Event :: DataOffer { id } => id. destroy( ) ,
274
+ Event :: Finished => {
275
+ state. common. seats. get_mut( seat) . unwrap( ) . set_device( None ) ;
306
276
}
277
+ Event :: PrimarySelection { .. } => {
278
+ state. got_primary_selection = true ;
279
+ }
280
+ _ => ( ) ,
307
281
}
282
+ } ) ;
283
+
284
+ impl_dispatch_offer ! ( State ) ;
285
+
286
+ impl_dispatch_source ! ( State , |state: & mut Self ,
287
+ source: data_control:: Source ,
288
+ event| {
289
+ match event {
290
+ Event :: Send { mime_type, fd } => {
291
+ // Check if some other source already handled a paste request and indicated that we should
292
+ // quit.
293
+ if state. should_quit {
294
+ source. destroy( ) ;
295
+ return ;
296
+ }
308
297
309
- event_created_child ! ( State , ZwlrDataControlDeviceV1 , [
310
- zwlr_data_control_device_v1:: EVT_DATA_OFFER_OPCODE => ( ZwlrDataControlOfferV1 , ( ) ) ,
311
- ] ) ;
312
- }
313
-
314
- impl Dispatch < ZwlrDataControlOfferV1 , ( ) > for State {
315
- fn event (
316
- _state : & mut Self ,
317
- _offer : & ZwlrDataControlOfferV1 ,
318
- _event : <ZwlrDataControlOfferV1 as wayland_client:: Proxy >:: Event ,
319
- _data : & ( ) ,
320
- _conn : & wayland_client:: Connection ,
321
- _qhandle : & wayland_client:: QueueHandle < Self > ,
322
- ) {
323
- }
324
- }
325
-
326
- impl Dispatch < ZwlrDataControlSourceV1 , ( ) > for State {
327
- fn event (
328
- state : & mut Self ,
329
- source : & ZwlrDataControlSourceV1 ,
330
- event : <ZwlrDataControlSourceV1 as Proxy >:: Event ,
331
- _data : & ( ) ,
332
- _conn : & wayland_client:: Connection ,
333
- _qhandle : & wayland_client:: QueueHandle < Self > ,
334
- ) {
335
- match event {
336
- zwlr_data_control_source_v1:: Event :: Send { mime_type, fd } => {
337
- // Check if some other source already handled a paste request and indicated that we should
338
- // quit.
339
- if state. should_quit {
340
- source. destroy ( ) ;
341
- return ;
342
- }
298
+ // I'm not sure if it's the compositor's responsibility to check that the mime type is
299
+ // valid. Let's check here just in case.
300
+ if !state. data_paths. contains_key( & mime_type) {
301
+ return ;
302
+ }
343
303
344
- // I'm not sure if it's the compositor's responsibility to check that the mime type is
345
- // valid. Let's check here just in case.
346
- if !state. data_paths . contains_key ( & mime_type) {
347
- return ;
348
- }
304
+ let data_path = & state. data_paths[ & mime_type] ;
349
305
350
- let data_path = & state. data_paths [ & mime_type] ;
306
+ let file = File :: open( data_path) . map_err( DataSourceError :: FileOpen ) ;
307
+ let result = file. and_then( |mut data_file| {
308
+ // Clear O_NONBLOCK, otherwise io::copy() will stop halfway.
309
+ fcntl_setfl( & fd, OFlags :: empty( ) )
310
+ . map_err( io:: Error :: from)
311
+ . map_err( DataSourceError :: Copy ) ?;
351
312
352
- let file = File :: open ( data_path) . map_err ( DataSourceError :: FileOpen ) ;
353
- let result = file. and_then ( |mut data_file| {
354
- // Clear O_NONBLOCK, otherwise io::copy() will stop halfway.
355
- fcntl_setfl ( & fd, OFlags :: empty ( ) )
356
- . map_err ( io:: Error :: from)
357
- . map_err ( DataSourceError :: Copy ) ?;
313
+ let mut target_file = File :: from( fd) ;
314
+ io:: copy( & mut data_file, & mut target_file) . map_err( DataSourceError :: Copy )
315
+ } ) ;
358
316
359
- let mut target_file = File :: from ( fd ) ;
360
- io :: copy ( & mut data_file , & mut target_file ) . map_err ( DataSourceError :: Copy )
361
- } ) ;
317
+ if let Err ( err ) = result {
318
+ state . error = Some ( err ) ;
319
+ }
362
320
363
- if let Err ( err) = result {
364
- state. error = Some ( err) ;
365
- }
321
+ let done = if let ServeRequests :: Only ( left) = state. serve_requests {
322
+ let left = left. checked_sub( 1 ) . unwrap( ) ;
323
+ state. serve_requests = ServeRequests :: Only ( left) ;
324
+ left == 0
325
+ } else {
326
+ false
327
+ } ;
366
328
367
- let done = if let ServeRequests :: Only ( left) = state. serve_requests {
368
- let left = left. checked_sub ( 1 ) . unwrap ( ) ;
369
- state. serve_requests = ServeRequests :: Only ( left) ;
370
- left == 0
371
- } else {
372
- false
373
- } ;
374
-
375
- if done || state. error . is_some ( ) {
376
- state. should_quit = true ;
377
- source. destroy ( ) ;
378
- }
329
+ if done || state. error. is_some( ) {
330
+ state. should_quit = true ;
331
+ source. destroy( ) ;
379
332
}
380
- zwlr_data_control_source_v1:: Event :: Cancelled => source. destroy ( ) ,
381
- _ => ( ) ,
382
333
}
334
+ Event :: Cancelled => source. destroy( ) ,
335
+ _ => ( ) ,
383
336
}
384
- }
337
+ } ) ;
385
338
386
339
impl Options {
387
340
/// Creates a blank new set of options ready for configuration.
@@ -676,7 +629,7 @@ fn get_devices(
676
629
primary : bool ,
677
630
seat : Seat ,
678
631
socket_name : Option < OsString > ,
679
- ) -> Result < ( EventQueue < State > , State , Vec < ZwlrDataControlDeviceV1 > ) , Error > {
632
+ ) -> Result < ( EventQueue < State > , State , Vec < data_control :: Device > ) , Error > {
680
633
let ( mut queue, mut common) = initialize ( primary, socket_name) ?;
681
634
682
635
// Check if there are no seats.
@@ -980,7 +933,7 @@ fn prepare_copy_internal(
980
933
let data_source = state
981
934
. common
982
935
. clipboard_manager
983
- . create_data_source ( & queue. handle ( ) , ( ) ) ;
936
+ . create_data_source ( & queue. handle ( ) ) ;
984
937
985
938
for mime_type in state. data_paths . keys ( ) {
986
939
data_source. offer ( mime_type. clone ( ) ) ;
0 commit comments