Skip to content

Commit

Permalink
Destroy virtual keyboard when it is not activated.
Browse files Browse the repository at this point in the history
This seems to be a good idea to clear up all the xkb state we sent from
vk. This seems also fix the hyprland issue that modifier is pressed when
switch window.
  • Loading branch information
wengxt committed Mar 1, 2024
1 parent 495b8ed commit b2924bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/frontend/waylandim/waylandimserverv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ void WaylandIMServerV2::refreshSeat() {
if (icMap_.count(seat.get())) {
continue;
}
auto *ic = new WaylandIMInputContextV2(
inputContextManager(), this, seat,
virtualKeyboardManagerV1_->createVirtualKeyboard(seat.get()));
auto *ic =
new WaylandIMInputContextV2(inputContextManager(), this, seat);
ic->setFocusGroup(group_);
ic->setCapabilityFlags(baseFlags);
}
Expand All @@ -121,11 +120,10 @@ void WaylandIMServerV2::remove(wayland::WlSeat *seat) {

WaylandIMInputContextV2::WaylandIMInputContextV2(
InputContextManager &inputContextManager, WaylandIMServerV2 *server,
std::shared_ptr<wayland::WlSeat> seat, wayland::ZwpVirtualKeyboardV1 *vk)
std::shared_ptr<wayland::WlSeat> seat)
: VirtualInputContextGlue(inputContextManager), server_(server),
seat_(std::move(seat)),
ic_(server->inputMethodManagerV2()->getInputMethod(seat_.get())),
vk_(vk) {
ic_(server->inputMethodManagerV2()->getInputMethod(seat_.get())) {
server->add(this, seat_.get());
ic_->surroundingText().connect(
[this](const char *text, uint32_t cursor, uint32_t anchor) {
Expand Down Expand Up @@ -162,13 +160,19 @@ WaylandIMInputContextV2::WaylandIMInputContextV2(
Key(FcitxKey_None, KeyStates(), vkkey + 8),
WL_KEYBOARD_KEY_STATE_RELEASED);
}
vk_->modifiers(0, 0, 0, 0);
}
focusOutWrapper();
}
vk_.reset();
vkReady_ = false;
}
if (pendingActivate_) {
pendingActivate_ = false;
vk_.reset();
vkReady_ = false;
vk_.reset(
server_->virtualKeyboardManagerV1()->createVirtualKeyboard(
seat_.get()));
// There can be only one grab. Always release old grab first.
// It is possible when switching between two client, there will be
// two activate. In that case we will have already one grab. The
Expand Down Expand Up @@ -419,7 +423,7 @@ void WaylandIMInputContextV2::keymapCallback(uint32_t format, int32_t fd,
server_->stateMask_.mod5_mask =
1 << xkb_keymap_mod_get_index(server_->keymap_.get(), "Mod5");

if (keymapChanged) {
if (keymapChanged || !vkReady_) {
vk_->keymap(format, scopeFD.fd(), size);
vkReady_ = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/waylandim/waylandimserverv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WaylandIMServerV2 : public WaylandIMServerBase {
FocusGroup *group() { return group_; }
auto *xkbState() { return state_.get(); }
auto *inputMethodManagerV2() { return inputMethodManagerV2_.get(); }
auto *virtualKeyboardManagerV1() { return virtualKeyboardManagerV1_.get(); }

bool hasKeyboardGrab() const;

Expand Down Expand Up @@ -72,8 +73,7 @@ class WaylandIMInputContextV2 : public VirtualInputContextGlue {
public:
WaylandIMInputContextV2(InputContextManager &inputContextManager,
WaylandIMServerV2 *server,
std::shared_ptr<wayland::WlSeat> seat,
wayland::ZwpVirtualKeyboardV1 *vk);
std::shared_ptr<wayland::WlSeat> seat);
~WaylandIMInputContextV2() override;

const char *frontend() const override { return "wayland_v2"; }
Expand Down

0 comments on commit b2924bd

Please sign in to comment.