Skip to content

Commit bf4be88

Browse files
committed
some cleanup
1 parent 05dba44 commit bf4be88

File tree

7 files changed

+84
-88
lines changed

7 files changed

+84
-88
lines changed

src/wayland/input_method/input_method.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,38 @@ void InputMethodHandle::sendPreeditString(
2727
void InputMethodHandle::deleteText(int before, int after) {
2828
zwp_input_method_v2::delete_surrounding_text(before, after);
2929
}
30-
void InputMethodHandle::commit() { zwp_input_method_v2::commit(serial++); }
30+
void InputMethodHandle::commit() { zwp_input_method_v2::commit(this->serial++); }
3131

3232
QPointer<InputMethodKeyboardGrab> InputMethodHandle::grabKeyboard() {
33-
if (keyboard) return keyboard;
33+
if (this->keyboard) return this->keyboard;
3434

35-
keyboard = new InputMethodKeyboardGrab(this, grab_keyboard());
35+
this->keyboard = new InputMethodKeyboardGrab(this, grab_keyboard());
3636

37-
return keyboard;
37+
return this->keyboard;
3838
}
3939
void InputMethodHandle::releaseKeyboard() {
40-
if (!keyboard) return;
41-
keyboard->deleteLater();
42-
keyboard = nullptr;
40+
if (!this->keyboard) return;
41+
this->keyboard->deleteLater();
42+
this->keyboard = nullptr;
4343
}
4444

4545
bool InputMethodHandle::isActive() const { return this->mActivated; }
4646
bool InputMethodHandle::isAvailable() const { return this->mAvailable; }
4747

48-
void InputMethodHandle::zwp_input_method_v2_activate() { mNewActive = true; }
48+
void InputMethodHandle::zwp_input_method_v2_activate() { this->mNewActive = true; }
4949

50-
void InputMethodHandle::zwp_input_method_v2_deactivate() { mNewActive = false; }
50+
void InputMethodHandle::zwp_input_method_v2_deactivate() { this->mNewActive = false; }
5151

5252
void InputMethodHandle::zwp_input_method_v2_done() {
53-
if (mActivated == mNewActive) return;
54-
mActivated = mNewActive;
55-
if (mActivated) emit activated();
53+
if (this->mActivated == this->mNewActive) return;
54+
this->mActivated = this->mNewActive;
55+
if (this->mActivated) emit activated();
5656
else emit deactivated();
5757
}
5858

5959
void InputMethodHandle::zwp_input_method_v2_unavailable() {
60-
if (!mAvailable) return;
61-
mAvailable = false;
60+
if (!this->mAvailable) return;
61+
this->mAvailable = false;
6262
deleteLater();
6363
qDebug(
6464
) << "Compositor denied input method request, likely due to one already existing elsewhere";

src/wayland/input_method/key_map_state.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ KeyMapState& KeyMapState::operator=(KeyMapState&& state) noexcept {
3232
return *this;
3333
}
3434
KeyMapState::~KeyMapState() {
35-
xkb_keymap_unref(std::exchange(xkbKeymap, nullptr));
36-
xkb_state_unref(std::exchange(xkbState, nullptr));
35+
xkb_keymap_unref(std::exchange(this->xkbKeymap, nullptr));
36+
xkb_state_unref(std::exchange(this->xkbState, nullptr));
3737
}
3838

3939
uniqueCString KeyMapState::keyMapAsString() const {
40-
return uniqueCString(xkb_keymap_get_as_string(xkbKeymap, XKB_KEYMAP_FORMAT_TEXT_V1));
40+
return uniqueCString(xkb_keymap_get_as_string(this->xkbKeymap, XKB_KEYMAP_FORMAT_TEXT_V1));
4141
}
4242

4343
bool KeyMapState::operator==(const KeyMapState& other) const {
44-
return xkbKeymap == other.xkbKeymap && xkbState == other.xkbState;
44+
return this->xkbKeymap == other.xkbKeymap && this->xkbState == other.xkbState;
4545
}
46-
KeyMapState::operator bool() const { return xkbKeymap != nullptr && xkbState != nullptr; }
46+
KeyMapState::operator bool() const { return this->xkbKeymap != nullptr && this->xkbState != nullptr; }
4747

4848
namespace {
4949
const char* getName(char key);
@@ -57,22 +57,23 @@ xkb_keycode_t KeyMapState::toKey(QChar character) const {
5757
}
5858

5959
const char* KeyMapState::keyName(xkb_keycode_t key) const {
60-
return xkb_keymap_key_get_name(xkbKeymap, key);
60+
return xkb_keymap_key_get_name(this->xkbKeymap, key);
6161
}
6262

63-
xkb_keycode_t KeyMapState::maxKeycode() const { return xkb_keymap_max_keycode(xkbKeymap); }
63+
xkb_keycode_t KeyMapState::maxKeycode() const { return xkb_keymap_max_keycode(this->xkbKeymap); }
64+
xkb_keycode_t KeyMapState::minKeycode() const { return xkb_keymap_min_keycode(this->xkbKeymap); }
6465

6566
xkb_keysym_t KeyMapState::getOneSym(xkb_keycode_t key) const {
66-
return xkb_state_key_get_one_sym(xkbState, key);
67+
return xkb_state_key_get_one_sym(this->xkbState, key);
6768
}
6869
QChar KeyMapState::getChar(xkb_keycode_t key) const {
69-
return QChar(xkb_state_key_get_utf32(xkbState, key));
70+
return QChar(xkb_state_key_get_utf32(this->xkbState, key));
7071
}
7172

7273
void KeyMapState::setModifiers(ModifierState modifierState) {
7374
if (!*this) return;
7475
xkb_state_update_mask(
75-
xkbState,
76+
this->xkbState,
7677
modifierState.depressed,
7778
modifierState.latched,
7879
modifierState.locked,
@@ -84,20 +85,22 @@ void KeyMapState::setModifiers(ModifierState modifierState) {
8485

8586
KeyMapState::ModifierState KeyMapState::serialiseMods() const {
8687
return {
87-
xkb_state_serialize_mods(xkbState, XKB_STATE_MODS_DEPRESSED),
88-
xkb_state_serialize_mods(xkbState, XKB_STATE_MODS_LATCHED),
89-
xkb_state_serialize_mods(xkbState, XKB_STATE_MODS_LOCKED),
90-
xkb_state_serialize_mods(xkbState, XKB_STATE_LAYOUT_DEPRESSED),
91-
xkb_state_serialize_mods(xkbState, XKB_STATE_LAYOUT_LATCHED),
92-
xkb_state_serialize_mods(xkbState, XKB_STATE_LAYOUT_LOCKED),
88+
xkb_state_serialize_mods(this->xkbState, XKB_STATE_MODS_DEPRESSED),
89+
xkb_state_serialize_mods(this->xkbState, XKB_STATE_MODS_LATCHED),
90+
xkb_state_serialize_mods(this->xkbState, XKB_STATE_MODS_LOCKED),
91+
xkb_state_serialize_mods(this->xkbState, XKB_STATE_LAYOUT_DEPRESSED),
92+
xkb_state_serialize_mods(this->xkbState, XKB_STATE_LAYOUT_LATCHED),
93+
xkb_state_serialize_mods(this->xkbState, XKB_STATE_LAYOUT_LOCKED),
9394
};
9495
}
9596

9697
std::string_view KeyMapState::keyStateName(wl_keyboard_key_state state) {
9798
switch (state) {
9899
case WL_KEYBOARD_KEY_STATE_RELEASED: return "released";
99100
case WL_KEYBOARD_KEY_STATE_PRESSED: return "pressed";
101+
#ifndef WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION
100102
case WL_KEYBOARD_KEY_STATE_REPEATED: return "repeated";
103+
#endif
101104
default: return "unknown state";
102105
}
103106
}

src/wayland/input_method/key_map_state.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class KeyMapState {
3030
[[nodiscard]] xkb_keycode_t toKey(QChar character) const;
3131
[[nodiscard]] const char* keyName(xkb_keycode_t key) const;
3232
[[nodiscard]] xkb_keycode_t maxKeycode() const;
33+
[[nodiscard]] xkb_keycode_t minKeycode() const;
3334

3435
[[nodiscard]] xkb_keysym_t getOneSym(xkb_keycode_t key) const;
3536
[[nodiscard]] QChar getChar(xkb_keycode_t key) const;

src/wayland/input_method/keyboard_grab.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ InputMethodKeyboardGrab::~InputMethodKeyboardGrab() {
2121
this->release();
2222

2323
// Release forward the pressed keys to the text input
24-
for (xkb_keycode_t key = 0; key < mKeyState.size(); ++key) {
25-
if (mKeyState[key] == KeyState::PRESSED) {
26-
mVirturalKeyboard->sendKey(key, WL_KEYBOARD_KEY_STATE_PRESSED);
24+
for (xkb_keycode_t key = 0; key < this->mKeyState.size(); ++key) {
25+
if (this->mKeyState[key] == KeyState::PRESSED) {
26+
this->mVirturalKeyboard->sendKey(key + this->mKeyMapState.minKeycode(), WL_KEYBOARD_KEY_STATE_PRESSED);
2727
}
2828
}
2929
}
@@ -44,12 +44,12 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_keymap(
4444
munmap(mapShm, size);
4545
close(fd);
4646

47-
mVirturalKeyboard = VirtualKeyboardManager::instance()->createVirtualKeyboard(mKeyMapState);
48-
mKeyState = std::vector<KeyState>(mKeyMapState.maxKeycode() - 8, KeyState::RELEASED);
47+
this->mVirturalKeyboard = VirtualKeyboardManager::instance()->createVirtualKeyboard(this->mKeyMapState);
48+
this->mKeyState = std::vector<KeyState>(this->mKeyMapState.maxKeycode() - this->mKeyMapState.minKeycode() - 8, KeyState::RELEASED);
4949

5050
// Tell the text input to release all the keys
51-
for (xkb_keycode_t key = 0; key < mKeyState.size(); ++key) {
52-
mVirturalKeyboard->sendKey(key, WL_KEYBOARD_KEY_STATE_RELEASED);
51+
for (xkb_keycode_t key = 0; key < this->mKeyState.size(); ++key) {
52+
this->mVirturalKeyboard->sendKey(key + this->mKeyMapState.minKeycode(), WL_KEYBOARD_KEY_STATE_RELEASED);
5353
}
5454
}
5555

@@ -68,10 +68,14 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_key(
6868
<< this->mKeyMapState.keyName(key) << "[" << key << "]"
6969
<< this->mKeyMapState.getChar(key);
7070

71-
if (state == WL_KEYBOARD_KEY_STATE_PRESSED || state == WL_KEYBOARD_KEY_STATE_REPEATED) {
72-
this->mKeyState[key] = KeyState::PRESSED;
71+
if (state == WL_KEYBOARD_KEY_STATE_PRESSED
72+
#ifndef WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION
73+
|| state == WL_KEYBOARD_KEY_STATE_REPEATED
74+
#endif
75+
) {
76+
this->mKeyState[key - this->mKeyMapState.minKeycode()] = KeyState::PRESSED;
7377
} else if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
74-
this->mKeyState[key] = KeyState::RELEASED;
78+
this->mKeyState[key - this->mKeyMapState.minKeycode()] = KeyState::RELEASED;
7579
}
7680

7781
xkb_keysym_t sym = this->mKeyMapState.getOneSym(key);
@@ -134,8 +138,8 @@ void InputMethodKeyboardGrab::zwp_input_method_keyboard_grab_v2_repeat_info(
134138
int32_t rate,
135139
int32_t delay
136140
) {
137-
mRate = rate;
138-
mDelay = delay;
141+
this->mRate = rate;
142+
this->mDelay = delay;
139143
}
140144

141145
} // namespace qs::wayland::input_method::impl

src/wayland/input_method/qml.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ namespace qs::wayland::input_method {
99

1010
using namespace impl;
1111

12-
InputMethod::InputMethod(QObject* parent): QObject(parent) { getInput(); }
12+
InputMethod::InputMethod(QObject* parent): QObject(parent) { this->getInput(); }
1313

1414
void InputMethod::sendString(const QString& text) {
15-
if (!isActive()) return;
15+
if (!this->isActive()) return;
1616

17-
handle->commitString(text);
18-
handle->commit();
17+
this->handle->commitString(text);
18+
this->handle->commit();
1919
}
2020

2121

2222
void InputMethod::sendPreeditString(const QString& text, int32_t cursorBegin, int32_t cursorEnd) {
23-
if (!isActive()) return;
23+
if (!this->isActive()) return;
2424

25-
handle->sendPreeditString(text, cursorBegin, cursorEnd);
26-
handle->commit();
25+
this->handle->sendPreeditString(text, cursorBegin, cursorEnd);
26+
this->handle->commit();
2727
}
2828

2929
void InputMethod::deleteText(int before, int after) {
30-
if (!isActive()) return;
30+
if (!this->isActive()) return;
3131

32-
handle->deleteText(before, after);
33-
handle->commit();
32+
this->handle->deleteText(before, after);
33+
this->handle->commit();
3434
}
3535

36-
bool InputMethod::isActive() const { return hasInput() && handle->isActive(); }
36+
bool InputMethod::isActive() const { return this->hasInput() && this->handle->isActive(); }
3737

3838
bool InputMethod::keyboardOnActive() const { return this->mKeyboardOnActive; }
3939
void InputMethod::setKeyboardOnActive(bool value) {
@@ -53,24 +53,24 @@ void InputMethod::setKeyboardComponent(QQmlComponent* keyboardComponent) {
5353
this->keyboard = nullptr;
5454
}
5555

56-
handleKeyboardActive();
56+
this->handleKeyboardActive();
5757
}
5858

5959
bool InputMethod::hasInput() const { return handle && handle->isAvailable(); }
6060

6161
void InputMethod::getInput() {
62-
if (hasInput()) return;
62+
if (this->hasInput()) return;
6363

64-
handle = InputMethodManager::instance()->acquireInput();
64+
this->handle = InputMethodManager::instance()->acquireInput();
6565

6666
QObject::connect(
67-
handle.get(),
67+
this->handle.get(),
6868
&InputMethodHandle::activated,
6969
this,
7070
&InputMethod::onHandleActiveChanged
7171
);
7272
QObject::connect(
73-
handle.get(),
73+
this->handle.get(),
7474
&InputMethodHandle::deactivated,
7575
this,
7676
&InputMethod::onHandleActiveChanged
@@ -80,9 +80,9 @@ void InputMethod::getInput() {
8080
}
8181

8282
void InputMethod::releaseInput() {
83-
if (!handle) return;
84-
handle->deleteLater();
85-
handle = nullptr;
83+
if (!this->handle) return;
84+
this->handle->deleteLater();
85+
this->handle = nullptr;
8686
emit hasInputChanged();
8787
}
8888

@@ -92,7 +92,7 @@ bool InputMethod::hasKeyboard() const {
9292
}
9393

9494
void InputMethod::grabKeyboard() {
95-
if (hasKeyboard()) return;
95+
if (this->hasKeyboard()) return;
9696
auto* instanceObj =
9797
this->mKeyboardComponent->create(QQmlEngine::contextForObject(this->mKeyboardComponent));
9898
auto* instance = qobject_cast<Keyboard*>(instanceObj);
@@ -113,7 +113,7 @@ void InputMethod::grabKeyboard() {
113113
}
114114

115115
void InputMethod::releaseKeyboard() {
116-
if(!hasKeyboard()) return;
116+
if(!this->hasKeyboard()) return;
117117
this->keyboard->deleteLater();
118118
this->keyboard = nullptr;
119119
this->handle->releaseKeyboard();
@@ -123,31 +123,31 @@ void InputMethod::releaseKeyboard() {
123123

124124
void InputMethod::handleKeyboardActive() {
125125
if (!this->mKeyboardComponent) return;
126-
if (isActive() && this->mKeyboardOnActive) {
127-
grabKeyboard();
126+
if (this->isActive() && this->mKeyboardOnActive) {
127+
this->grabKeyboard();
128128
} else if (this->keyboard) {
129129
this->releaseKeyboard();
130130
}
131131
}
132132

133133
void InputMethod::onHandleActiveChanged() {
134-
handleKeyboardActive();
134+
this->handleKeyboardActive();
135135
emit activeChanged();
136136
}
137137

138138
Keyboard::Keyboard(QObject* parent): QObject(parent) {}
139139

140140
void Keyboard::setKeyboard(QPointer<InputMethodKeyboardGrab> keyboard) {
141-
if (mKeyboard == keyboard) return;
141+
if (this->mKeyboard == keyboard) return;
142142
if (keyboard == nullptr) return;
143143
this->mKeyboard = std::move(keyboard);
144144

145-
QObject::connect(mKeyboard, &InputMethodKeyboardGrab::keyPress, this, &Keyboard::keyPress);
146-
QObject::connect(mKeyboard, &InputMethodKeyboardGrab::escapePress, this, &Keyboard::escapePress);
147-
QObject::connect(mKeyboard, &InputMethodKeyboardGrab::returnPress, this, &Keyboard::returnPress);
148-
QObject::connect(mKeyboard, &InputMethodKeyboardGrab::directionPress, this, &Keyboard::directionPress);
149-
QObject::connect(mKeyboard, &InputMethodKeyboardGrab::backspacePress, this, &Keyboard::backspacePress);
150-
QObject::connect(mKeyboard, &InputMethodKeyboardGrab::deletePress, this, &Keyboard::deletePress);
145+
QObject::connect(this->mKeyboard, &InputMethodKeyboardGrab::keyPress, this, &Keyboard::keyPress);
146+
QObject::connect(this->mKeyboard, &InputMethodKeyboardGrab::escapePress, this, &Keyboard::escapePress);
147+
QObject::connect(this->mKeyboard, &InputMethodKeyboardGrab::returnPress, this, &Keyboard::returnPress);
148+
QObject::connect(this->mKeyboard, &InputMethodKeyboardGrab::directionPress, this, &Keyboard::directionPress);
149+
QObject::connect(this->mKeyboard, &InputMethodKeyboardGrab::backspacePress, this, &Keyboard::backspacePress);
150+
QObject::connect(this->mKeyboard, &InputMethodKeyboardGrab::deletePress, this, &Keyboard::deletePress);
151151
}
152152

153153
} // namespace qs::wayland::input_method

src/wayland/input_method/types.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ struct FreeDeleter{
1414
};
1515
// Dont use this for literals, only c strings that were allocated
1616
using uniqueCString = std::unique_ptr<const char, FreeDeleter>;
17-
18-
#ifndef WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION
19-
// Hack to get old wayland version to build
20-
#define WL_KEYBOARD_KEY_STATE_REPEATED 2;
21-
#endif
22-
2317
}
2418

2519
} // namespace qs::wayland::input_method

src/wayland/input_method/virtual_keyboard.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,17 @@ void VirtualKeyboardHandle::setKeymapState(const KeyMapState& keymap) {
5757

5858
this->zwp_virtual_keyboard_v1::keymap(WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, fd, size);
5959

60-
good = true;
60+
this->good = true;
6161
}
6262

6363
void VirtualKeyboardHandle::sendKey(xkb_keycode_t keycode, wl_keyboard_key_state state) {
64-
if (!good) return;
64+
if (!this->good) return;
6565
if (keycode == XKB_KEYCODE_INVALID) return;
66-
67-
#ifndef WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION
68-
// Protocol version does not support
69-
if (state == WL_KEYBOARD_KEY_STATE_REPEATED) return;
70-
#endif
71-
7266
this->zwp_virtual_keyboard_v1::key(now(), keycode - 8, state);
7367
}
7468

7569
void VirtualKeyboardHandle::sendModifiers() {
76-
auto mods = mKeyMapState.serialiseMods();
70+
auto mods = this->mKeyMapState.serialiseMods();
7771
modifiers(mods.depressed, mods.latched, mods.locked, mods.depressedLayout);
7872
}
7973

0 commit comments

Comments
 (0)