Skip to content

Commit 9eba22a

Browse files
committed
skip releaying control keys that we consume and some more cleanup
1 parent cd02df7 commit 9eba22a

File tree

3 files changed

+8
-101
lines changed

3 files changed

+8
-101
lines changed

src/wayland/input_method/key_map_state.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ KeyMapState::operator bool() const {
4747
return this->xkbKeymap != nullptr && this->xkbState != nullptr;
4848
}
4949

50-
namespace {
51-
const char* getName(char key);
52-
}
53-
xkb_keycode_t KeyMapState::toKey(QChar character) const {
54-
if (!*this) return XKB_KEYCODE_INVALID;
55-
auto keycode = xkb_keymap_key_by_name(this->xkbKeymap, getName(character.toLatin1()));
56-
if (keycode == XKB_KEYCODE_INVALID)
57-
qDebug() << character << ":" << getName(character.toLatin1()) << "was not found in the keymap.";
58-
return keycode;
59-
}
60-
6150
const char* KeyMapState::keyName(xkb_keycode_t key) const {
6251
return xkb_keymap_key_get_name(this->xkbKeymap, key);
6352
}
@@ -100,86 +89,10 @@ std::string_view KeyMapState::keyStateName(wl_keyboard_key_state state) {
10089
switch (state) {
10190
case WL_KEYBOARD_KEY_STATE_RELEASED: return "released";
10291
case WL_KEYBOARD_KEY_STATE_PRESSED: return "pressed";
103-
#ifndef WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION
104-
case WL_KEYBOARD_KEY_STATE_REPEATED: return "repeated";
105-
#endif
10692
default: return "unknown state";
10793
}
10894
}
10995

11096
xkb_context* KeyMapState::xkbContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
11197

112-
namespace {
113-
const char* getName(char key) {
114-
switch (key) {
115-
case 13: return "RTRN";
116-
case 8: return "BKSP";
117-
case '1': return "AE01";
118-
case '2': return "AE02";
119-
case '3': return "AE03";
120-
case '4': return "AE04";
121-
case '5': return "AE05";
122-
case '6': return "AE06";
123-
case '7': return "AE07";
124-
case '8': return "AE08";
125-
case '9': return "AE09";
126-
case '0': return "AE10";
127-
case 'a':
128-
case 'A': return "LatA";
129-
case 'b':
130-
case 'B': return "LatB";
131-
case 'c':
132-
case 'C': return "LatC";
133-
case 'd':
134-
case 'D': return "LatD";
135-
case 'e':
136-
case 'E': return "LatE";
137-
case 'f':
138-
case 'F': return "LatF";
139-
case 'g':
140-
case 'G': return "LatG";
141-
case 'h':
142-
case 'H': return "LatH";
143-
case 'i':
144-
case 'I': return "LatI";
145-
case 'j':
146-
case 'J': return "LatJ";
147-
case 'k':
148-
case 'K': return "LatK";
149-
case 'l':
150-
case 'L': return "LatL";
151-
case 'm':
152-
case 'M': return "LatM";
153-
case 'n':
154-
case 'N': return "LatN";
155-
case 'o':
156-
case 'O': return "LatO";
157-
case 'p':
158-
case 'P': return "LatP";
159-
case 'q':
160-
case 'Q': return "LatQ";
161-
case 'r':
162-
case 'R': return "LatR";
163-
case 's':
164-
case 'S': return "LatS";
165-
case 't':
166-
case 'T': return "LatT";
167-
case 'u':
168-
case 'U': return "LatU";
169-
case 'v':
170-
case 'V': return "LatV";
171-
case 'w':
172-
case 'W': return "LatW";
173-
case 'x':
174-
case 'X': return "LatX";
175-
case 'y':
176-
case 'Y': return "LatY";
177-
case 'z':
178-
case 'Z': return "LatZ";
179-
}
180-
qDebug() << "Did not know the key name of character:" << key;
181-
return "";
182-
}
183-
} // namespace
184-
18598
} // namespace qs::wayland::input_method::impl

src/wayland/input_method/key_map_state.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class KeyMapState {
2626
[[nodiscard]] bool operator==(const KeyMapState& other) const;
2727
[[nodiscard]] operator bool() const;
2828

29-
// RETURNS XKB_KEYCODE_INVALID if it wasn't found in the map
30-
[[nodiscard]] xkb_keycode_t toKey(QChar character) const;
3129
[[nodiscard]] const char* keyName(xkb_keycode_t key) const;
3230
[[nodiscard]] xkb_keycode_t maxKeycode() const;
3331
[[nodiscard]] xkb_keycode_t minKeycode() const;

src/wayland/input_method/keyboard_grab.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_key(
7878
<< this->mKeyMapState.keyName(key) << "[" << key << "]"
7979
<< this->mKeyMapState.getChar(key);
8080

81-
if (
82-
state == WL_KEYBOARD_KEY_STATE_PRESSED
83-
#ifndef WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION
84-
|| state == WL_KEYBOARD_KEY_STATE_REPEATED
85-
#endif
86-
)
87-
{
88-
this->mKeyState[key - this->mKeyMapState.minKeycode()] = KeyState::PRESSED;
89-
} else if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
90-
this->mKeyState[key - this->mKeyMapState.minKeycode()] = KeyState::RELEASED;
91-
}
92-
9381
xkb_keysym_t sym = this->mKeyMapState.getOneSym(key);
9482

9583
if (sym == XKB_KEY_Escape) {
@@ -124,6 +112,14 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_key(
124112
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit deletePress();
125113
return;
126114
}
115+
116+
// Skip adding the control keys because we've consumed them
117+
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
118+
this->mKeyState[key - this->mKeyMapState.minKeycode()] = KeyState::PRESSED;
119+
} else if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
120+
this->mKeyState[key - this->mKeyMapState.minKeycode()] = KeyState::RELEASED;
121+
}
122+
127123
QChar character = this->mKeyMapState.getChar(key);
128124
if (character != '\0') {
129125
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) emit keyPress(character);

0 commit comments

Comments
 (0)