33#include < cstddef>
44#include < vector>
55
6- #include < qlogging .h>
6+ #include < qdebug .h>
77#include < qobject.h>
88#include < qtmetamacros.h>
99#include < qwayland-input-method-unstable-v2.h>
@@ -25,7 +25,12 @@ InputMethodKeyboardGrab::InputMethodKeyboardGrab(
2525 ::zwp_input_method_keyboard_grab_v2* keyboard
2626)
2727 : QObject(parent)
28- , zwp_input_method_keyboard_grab_v2(keyboard) {}
28+ , zwp_input_method_keyboard_grab_v2(keyboard) {
29+ this ->mRepeatTimer .callOnTimeout (this , [&](){
30+ this ->mRepeatTimer .setInterval (1000 / this ->mRepeatRate );
31+ handleKey (mRepeatKey );
32+ });
33+ }
2934
3035InputMethodKeyboardGrab::~InputMethodKeyboardGrab () {
3136 this ->release ();
@@ -108,38 +113,58 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_key(
108113 this ->mKeyState [key - this ->mKeyMapState .minKeycode ()] = KeyState::RELEASED;
109114 }
110115
116+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
117+ bool keyHandled = handleKey (key);
118+ if (keyHandled){
119+ if (this ->mKeyMapState .keyRepeats (key) && this ->mRepeatRate > 0 ) {
120+ this ->mRepeatKey = key;
121+ this ->mRepeatTimer .setInterval (this ->mRepeatDelay );
122+ this ->mRepeatTimer .start ();
123+ }
124+ return ;
125+ }
126+ }
127+
128+ if (this ->mRepeatKey == key) {
129+ this ->mRepeatTimer .stop ();
130+ }
131+
132+ this ->mVirturalKeyboard ->sendKey (key, static_cast <wl_keyboard_key_state>(state));
133+ }
134+
135+ bool InputMethodKeyboardGrab::handleKey (xkb_keycode_t key){
136+ const xkb_keysym_t sym = this ->mKeyMapState .getOneSym (key);
111137 if (sym == XKB_KEY_Up) {
112- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit directionPress (DirectionKey::UP);
113- return ;
138+ emit directionPress (DirectionKey::UP);
139+ return true ;
114140 }
115141 if (sym == XKB_KEY_Down) {
116- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit directionPress (DirectionKey::DOWN);
117- return ;
142+ emit directionPress (DirectionKey::DOWN);
143+ return true ;
118144 }
119145 if (sym == XKB_KEY_Left) {
120- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit directionPress (DirectionKey::LEFT);
121- return ;
146+ emit directionPress (DirectionKey::LEFT);
147+ return true ;
122148 }
123149 if (sym == XKB_KEY_Right) {
124- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit directionPress (DirectionKey::RIGHT);
125- return ;
150+ emit directionPress (DirectionKey::RIGHT);
151+ return true ;
126152 }
127153 if (sym == XKB_KEY_BackSpace) {
128- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit backspacePress ();
129- return ;
154+ emit backspacePress ();
155+ return true ;
130156 }
131157 if (sym == XKB_KEY_Delete) {
132- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit deletePress ();
133- return ;
158+ emit deletePress ();
159+ return true ;
134160 }
135161
136162 const QChar character = this ->mKeyMapState .getChar (key);
137163 if (character != ' \0 ' ) {
138- if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit keyPress (character);
139- return ;
140- } else {
141- this ->mVirturalKeyboard ->sendKey (key, static_cast <wl_keyboard_key_state>(state));
164+ emit keyPress (character);
165+ return true ;
142166 }
167+ return false ;
143168}
144169
145170void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_modifiers (
@@ -158,8 +183,11 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_modifiers(
158183}
159184
160185void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_repeat_info (
161- int32_t /* rate*/ ,
162- int32_t /* delay*/
163- ) {}
186+ int32_t rate,
187+ int32_t delay
188+ ) {
189+ mRepeatRate = rate;
190+ mRepeatDelay = delay;
191+ }
164192
165193} // namespace qs::wayland::input_method::impl
0 commit comments