@@ -10,9 +10,8 @@ use wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboar
1010 self , ZwpVirtualKeyboardV1 ,
1111} ;
1212use 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 ,
1615} ;
1716use xkbcommon:: xkb;
1817
@@ -23,7 +22,9 @@ use crate::{
2322 wayland:: seat:: { keyboard:: for_each_focused_kbds, WaylandFocus } ,
2423} ;
2524
26- use super :: VirtualKeyboardManagerState ;
25+ use crate :: backend:: input:: { KeyState , Keycode } ;
26+
27+ use super :: { VirtualKeyboardHandler , VirtualKeyboardManagerState } ;
2728
2829#[ derive( Debug , Default ) ]
2930pub ( crate ) struct VirtualKeyboard {
@@ -71,10 +72,18 @@ impl<D: SeatHandler> fmt::Debug for VirtualKeyboardUserData<D> {
7172 }
7273}
7374
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+
7482impl < D > Dispatch < ZwpVirtualKeyboardV1 , VirtualKeyboardUserData < D > , D > for VirtualKeyboardManagerState
7583where
7684 D : Dispatch < ZwpVirtualKeyboardV1 , VirtualKeyboardUserData < D > > ,
7785 D : SeatHandler + ' static ,
86+ D : VirtualKeyboardHandler ,
7887 <D as SeatHandler >:: KeyboardFocus : WaylandFocus ,
7988{
8089 fn request (
@@ -100,25 +109,30 @@ where
100109 return ;
101110 }
102111 } ;
103-
104112 // Ensure virtual keyboard's keymap is active.
105113 let keyboard_handle = data. seat . get_keyboard ( ) . unwrap ( ) ;
106114 let mut internal = keyboard_handle. arc . internal . lock ( ) . unwrap ( ) ;
107115 let focus = internal. focus . as_mut ( ) . map ( |( focus, _) | focus) ;
108116 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+ }
122136 }
123137 }
124138 zwp_virtual_keyboard_v1:: Request :: Modifiers {
0 commit comments