@@ -10,9 +10,8 @@ use wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboar
10
10
self , ZwpVirtualKeyboardV1 ,
11
11
} ;
12
12
use wayland_server:: {
13
- backend:: ClientId ,
14
- protocol:: wl_keyboard:: { KeyState , KeymapFormat } ,
15
- Client , DataInit , Dispatch , DisplayHandle , Resource ,
13
+ backend:: ClientId , protocol:: wl_keyboard:: KeymapFormat , Client , DataInit , Dispatch , DisplayHandle ,
14
+ Resource ,
16
15
} ;
17
16
use xkbcommon:: xkb;
18
17
@@ -23,7 +22,9 @@ use crate::{
23
22
wayland:: seat:: { keyboard:: for_each_focused_kbds, WaylandFocus } ,
24
23
} ;
25
24
26
- use super :: VirtualKeyboardManagerState ;
25
+ use crate :: backend:: input:: { KeyState , Keycode } ;
26
+
27
+ use super :: { VirtualKeyboardHandler , VirtualKeyboardManagerState } ;
27
28
28
29
#[ derive( Debug , Default ) ]
29
30
pub ( crate ) struct VirtualKeyboard {
@@ -71,10 +72,18 @@ impl<D: SeatHandler> fmt::Debug for VirtualKeyboardUserData<D> {
71
72
}
72
73
}
73
74
75
+ #[ cfg( not( feature = "virtual_keyboard_not_use_default_handler" ) ) ]
76
+ impl < T : SeatHandler + ' static > VirtualKeyboardHandler for T {
77
+ fn process_wm ( & mut self , keycode : Keycode , state : KeyState , time : u32 ) -> bool {
78
+ true
79
+ }
80
+ }
81
+
74
82
impl < D > Dispatch < ZwpVirtualKeyboardV1 , VirtualKeyboardUserData < D > , D > for VirtualKeyboardManagerState
75
83
where
76
84
D : Dispatch < ZwpVirtualKeyboardV1 , VirtualKeyboardUserData < D > > ,
77
85
D : SeatHandler + ' static ,
86
+ D : VirtualKeyboardHandler ,
78
87
<D as SeatHandler >:: KeyboardFocus : WaylandFocus ,
79
88
{
80
89
fn request (
@@ -100,25 +109,30 @@ where
100
109
return ;
101
110
}
102
111
} ;
103
-
104
112
// Ensure virtual keyboard's keymap is active.
105
113
let keyboard_handle = data. seat . get_keyboard ( ) . unwrap ( ) ;
106
114
let mut internal = keyboard_handle. arc . internal . lock ( ) . unwrap ( ) ;
107
115
let focus = internal. focus . as_mut ( ) . map ( |( focus, _) | focus) ;
108
116
keyboard_handle. send_keymap ( user_data, & focus, & vk_state. keymap , vk_state. mods ) ;
109
-
110
- if let Some ( wl_surface) = focus. and_then ( |f| f. wl_surface ( ) ) {
111
- for_each_focused_kbds ( & data. seat , & wl_surface, |kbd| {
112
- // This should be wl_keyboard::KeyState, but the protocol does not state
113
- // the parameter is an enum.
114
- let key_state = if state == 1 {
115
- KeyState :: Pressed
116
- } else {
117
- KeyState :: Released
118
- } ;
119
-
120
- kbd. key ( SERIAL_COUNTER . next_serial ( ) . 0 , time, key, key_state) ;
121
- } ) ;
117
+ let keystate = if state == 1 {
118
+ KeyState :: Pressed
119
+ } else {
120
+ KeyState :: Released
121
+ } ;
122
+ if user_data. process_wm ( ( key + 8 ) . into ( ) , keystate, time) {
123
+ if let Some ( wl_surface) = focus. and_then ( |f| f. wl_surface ( ) ) {
124
+ for_each_focused_kbds ( & data. seat , & wl_surface, |kbd| {
125
+ // This should be wl_keyboard::KeyState, but the protocol does not state
126
+ // the parameter is an enum.
127
+ use wayland_server:: protocol:: wl_keyboard:: KeyState ;
128
+ let key_state = if state == 1 {
129
+ KeyState :: Pressed
130
+ } else {
131
+ KeyState :: Released
132
+ } ;
133
+ kbd. key ( SERIAL_COUNTER . next_serial ( ) . 0 , time, key, key_state) ;
134
+ } ) ;
135
+ }
122
136
}
123
137
}
124
138
zwp_virtual_keyboard_v1:: Request :: Modifiers {
0 commit comments