@@ -7,6 +7,11 @@ use std::{
7
7
time:: Instant ,
8
8
} ;
9
9
10
+ use smithay_client_toolkit:: reexports:: protocols:: unstable:: relative_pointer:: v1:: client:: {
11
+ zwp_relative_pointer_manager_v1:: ZwpRelativePointerManagerV1 ,
12
+ zwp_relative_pointer_v1:: ZwpRelativePointerV1 ,
13
+ } ;
14
+
10
15
use crate :: {
11
16
dpi:: { PhysicalPosition , PhysicalSize } ,
12
17
event:: ModifiersState ,
@@ -15,7 +20,7 @@ use crate::{
15
20
platform_impl:: platform:: sticky_exit_callback,
16
21
} ;
17
22
18
- use super :: { window:: WindowStore , WindowId } ;
23
+ use super :: { window:: WindowStore , DeviceId , WindowId } ;
19
24
20
25
use smithay_client_toolkit:: {
21
26
output:: OutputMgr ,
@@ -26,33 +31,37 @@ use smithay_client_toolkit::{
26
31
Environment ,
27
32
} ;
28
33
29
- pub struct WindowEventsSink {
30
- buffer : VecDeque < ( crate :: event:: WindowEvent , crate :: window :: WindowId ) > ,
34
+ pub struct WindowEventsSink < T > {
35
+ buffer : VecDeque < crate :: event:: Event < T > > ,
31
36
}
32
37
33
- impl WindowEventsSink {
34
- pub fn new ( ) -> WindowEventsSink {
38
+ impl < T > WindowEventsSink < T > {
39
+ pub fn new ( ) -> WindowEventsSink < T > {
35
40
WindowEventsSink {
36
41
buffer : VecDeque :: new ( ) ,
37
42
}
38
43
}
39
44
40
- pub fn send_event ( & mut self , evt : crate :: event:: WindowEvent , wid : WindowId ) {
41
- self . buffer . push_back ( (
42
- evt,
43
- crate :: window:: WindowId ( crate :: platform_impl:: WindowId :: Wayland ( wid) ) ,
44
- ) ) ;
45
+ pub fn send_window_event ( & mut self , evt : crate :: event:: WindowEvent , wid : WindowId ) {
46
+ self . buffer . push_back ( crate :: event:: Event :: WindowEvent {
47
+ event : evt,
48
+ window_id : crate :: window:: WindowId ( crate :: platform_impl:: WindowId :: Wayland ( wid) ) ,
49
+ } ) ;
50
+ }
51
+
52
+ pub fn send_device_event ( & mut self , evt : crate :: event:: DeviceEvent , dev_id : DeviceId ) {
53
+ self . buffer . push_back ( crate :: event:: Event :: DeviceEvent {
54
+ event : evt,
55
+ device_id : crate :: event:: DeviceId ( crate :: platform_impl:: DeviceId :: Wayland ( dev_id) ) ,
56
+ } ) ;
45
57
}
46
58
47
- fn empty_with < F , T > ( & mut self , mut callback : F )
59
+ fn empty_with < F > ( & mut self , mut callback : F )
48
60
where
49
61
F : FnMut ( crate :: event:: Event < T > ) ,
50
62
{
51
- for ( evt, wid) in self . buffer . drain ( ..) {
52
- callback ( crate :: event:: Event :: WindowEvent {
53
- event : evt,
54
- window_id : wid,
55
- } )
63
+ for evt in self . buffer . drain ( ..) {
64
+ callback ( evt)
56
65
}
57
66
}
58
67
}
@@ -65,7 +74,7 @@ pub struct EventLoop<T: 'static> {
65
74
// the output manager
66
75
pub outputs : OutputMgr ,
67
76
// our sink, shared with some handlers, buffering the events
68
- sink : Arc < Mutex < WindowEventsSink > > ,
77
+ sink : Arc < Mutex < WindowEventsSink < T > > > ,
69
78
pending_user_events : Rc < RefCell < VecDeque < T > > > ,
70
79
_user_source : :: calloop:: Source < :: calloop:: channel:: Channel < T > > ,
71
80
user_sender : :: calloop:: channel:: Sender < T > ,
@@ -122,13 +131,14 @@ impl<T: 'static> EventLoop<T> {
122
131
. handle ( )
123
132
. insert_source ( kbd_channel, move |evt, & mut ( ) | {
124
133
if let :: calloop:: channel:: Event :: Msg ( ( evt, wid) ) = evt {
125
- kbd_sink. lock ( ) . unwrap ( ) . send_event ( evt, wid) ;
134
+ kbd_sink. lock ( ) . unwrap ( ) . send_window_event ( evt, wid) ;
126
135
}
127
136
} )
128
137
. unwrap ( ) ;
129
138
130
139
let mut seat_manager = SeatManager {
131
140
sink : sink. clone ( ) ,
141
+ relative_pointer_manager_proxy : None ,
132
142
store : store. clone ( ) ,
133
143
seats : seats. clone ( ) ,
134
144
kbd_sender,
@@ -143,6 +153,15 @@ impl<T: 'static> EventLoop<T> {
143
153
ref interface,
144
154
version,
145
155
} => {
156
+ if interface == "zwp_relative_pointer_manager_v1" {
157
+ seat_manager. relative_pointer_manager_proxy = Some (
158
+ registry
159
+ . bind ( version, id, move |pointer_manager| {
160
+ pointer_manager. implement_closure ( |_, _| ( ) , ( ) )
161
+ } )
162
+ . unwrap ( ) ,
163
+ )
164
+ }
146
165
if interface == "wl_seat" {
147
166
seat_manager. add_seat ( id, version, registry)
148
167
}
@@ -392,7 +411,7 @@ impl<T> EventLoop<T> {
392
411
let pruned = window_target. store . lock ( ) . unwrap ( ) . cleanup ( ) ;
393
412
* cleanup_needed = false ;
394
413
for wid in pruned {
395
- sink. send_event ( crate :: event:: WindowEvent :: Destroyed , wid) ;
414
+ sink. send_window_event ( crate :: event:: WindowEvent :: Destroyed , wid) ;
396
415
}
397
416
}
398
417
}
@@ -404,7 +423,10 @@ impl<T> EventLoop<T> {
404
423
frame. resize ( w, h) ;
405
424
frame. refresh ( ) ;
406
425
let logical_size = crate :: dpi:: LogicalSize :: new ( w as f64 , h as f64 ) ;
407
- sink. send_event ( crate :: event:: WindowEvent :: Resized ( logical_size) , wid) ;
426
+ sink. send_window_event (
427
+ crate :: event:: WindowEvent :: Resized ( logical_size) ,
428
+ wid,
429
+ ) ;
408
430
* size = ( w, h) ;
409
431
} else if frame_refresh {
410
432
frame. refresh ( ) ;
@@ -414,16 +436,16 @@ impl<T> EventLoop<T> {
414
436
}
415
437
}
416
438
if let Some ( dpi) = new_dpi {
417
- sink. send_event (
439
+ sink. send_window_event (
418
440
crate :: event:: WindowEvent :: HiDpiFactorChanged ( dpi as f64 ) ,
419
441
wid,
420
442
) ;
421
443
}
422
444
if refresh {
423
- sink. send_event ( crate :: event:: WindowEvent :: RedrawRequested , wid) ;
445
+ sink. send_window_event ( crate :: event:: WindowEvent :: RedrawRequested , wid) ;
424
446
}
425
447
if closed {
426
- sink. send_event ( crate :: event:: WindowEvent :: CloseRequested , wid) ;
448
+ sink. send_window_event ( crate :: event:: WindowEvent :: CloseRequested , wid) ;
427
449
}
428
450
} ,
429
451
)
@@ -434,21 +456,24 @@ impl<T> EventLoop<T> {
434
456
* Wayland protocol implementations
435
457
*/
436
458
437
- struct SeatManager {
438
- sink : Arc < Mutex < WindowEventsSink > > ,
459
+ struct SeatManager < T : ' static > {
460
+ sink : Arc < Mutex < WindowEventsSink < T > > > ,
439
461
store : Arc < Mutex < WindowStore > > ,
440
462
seats : Arc < Mutex < Vec < ( u32 , wl_seat:: WlSeat ) > > > ,
441
463
kbd_sender : :: calloop:: channel:: Sender < ( crate :: event:: WindowEvent , super :: WindowId ) > ,
464
+ relative_pointer_manager_proxy : Option < ZwpRelativePointerManagerV1 > ,
442
465
}
443
466
444
- impl SeatManager {
467
+ impl < T : ' static > SeatManager < T > {
445
468
fn add_seat ( & mut self , id : u32 , version : u32 , registry : wl_registry:: WlRegistry ) {
446
469
use std:: cmp:: min;
447
470
448
471
let mut seat_data = SeatData {
449
472
sink : self . sink . clone ( ) ,
450
473
store : self . store . clone ( ) ,
451
474
pointer : None ,
475
+ relative_pointer : None ,
476
+ relative_pointer_manager_proxy : self . relative_pointer_manager_proxy . as_ref ( ) . cloned ( ) ,
452
477
keyboard : None ,
453
478
touch : None ,
454
479
kbd_sender : self . kbd_sender . clone ( ) ,
@@ -474,17 +499,19 @@ impl SeatManager {
474
499
}
475
500
}
476
501
477
- struct SeatData {
478
- sink : Arc < Mutex < WindowEventsSink > > ,
502
+ struct SeatData < T > {
503
+ sink : Arc < Mutex < WindowEventsSink < T > > > ,
479
504
store : Arc < Mutex < WindowStore > > ,
480
505
kbd_sender : :: calloop:: channel:: Sender < ( crate :: event:: WindowEvent , super :: WindowId ) > ,
481
506
pointer : Option < wl_pointer:: WlPointer > ,
507
+ relative_pointer : Option < ZwpRelativePointerV1 > ,
508
+ relative_pointer_manager_proxy : Option < ZwpRelativePointerManagerV1 > ,
482
509
keyboard : Option < wl_keyboard:: WlKeyboard > ,
483
510
touch : Option < wl_touch:: WlTouch > ,
484
511
modifiers_tracker : Arc < Mutex < ModifiersState > > ,
485
512
}
486
513
487
- impl SeatData {
514
+ impl < T : ' static > SeatData < T > {
488
515
fn receive ( & mut self , evt : wl_seat:: Event , seat : wl_seat:: WlSeat ) {
489
516
match evt {
490
517
wl_seat:: Event :: Name { .. } => ( ) ,
@@ -496,7 +523,19 @@ impl SeatData {
496
523
self . sink . clone ( ) ,
497
524
self . store . clone ( ) ,
498
525
self . modifiers_tracker . clone ( ) ,
499
- ) )
526
+ ) ) ;
527
+
528
+ self . relative_pointer =
529
+ self . relative_pointer_manager_proxy
530
+ . as_ref ( )
531
+ . and_then ( |manager| {
532
+ super :: pointer:: implement_relative_pointer (
533
+ self . sink . clone ( ) ,
534
+ self . pointer . as_ref ( ) . unwrap ( ) ,
535
+ manager,
536
+ )
537
+ . ok ( )
538
+ } )
500
539
}
501
540
// destroy pointer if applicable
502
541
if !capabilities. contains ( wl_seat:: Capability :: Pointer ) {
@@ -544,7 +583,7 @@ impl SeatData {
544
583
}
545
584
}
546
585
547
- impl Drop for SeatData {
586
+ impl < T > Drop for SeatData < T > {
548
587
fn drop ( & mut self ) {
549
588
if let Some ( pointer) = self . pointer . take ( ) {
550
589
if pointer. as_ref ( ) . version ( ) >= 3 {
0 commit comments