Skip to content

Commit 9e2f804

Browse files
use WM for unfocusing
1 parent abd8b19 commit 9e2f804

5 files changed

Lines changed: 12 additions & 44 deletions

File tree

include/wayland_app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class WaylandApp : public AppSurface {
105105
bool isSelected() override { return selected; }
106106

107107
void focus(unsigned long /*matrix*/) override { focused = true; }
108-
void unfocus(unsigned long /*matrix*/) override { focused = false; }
108+
void unfocus(unsigned long /*matrix*/) override;
109109
void takeInputFocus() override;
110110
void requestSize(int width, int height);
111111
void setSeat(wlr_seat* seat, wlr_surface* surface)

src/WindowManager/WindowManager.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -994,19 +994,6 @@ void WindowManager::focusApp(entt::entity appEntity) {
994994

995995
void WindowManager::unfocusApp() {
996996
pruneInvalidFocus();
997-
if (waylandMode) {
998-
auto ent = currentlyFocusedApp.has_value() ? (int)entt::to_integral(*currentlyFocusedApp)
999-
: -1;
1000-
size_t wlCount = 0;
1001-
if (registry) {
1002-
auto view = registry->view<WaylandApp::Component>();
1003-
view.each([&](auto /*e*/, auto& /*comp*/) { ++wlCount; });
1004-
}
1005-
WL_WM_LOG("WM: unfocusApp (wayland) ent=%d wlCount=%zu\n", ent, wlCount);
1006-
currentlyFocusedApp = std::nullopt;
1007-
pendingFocusedApp = std::nullopt;
1008-
return;
1009-
}
1010997
logger->debug("unfocusing app");
1011998
if (!currentlyFocusedApp.has_value()) {
1012999
return;
@@ -1016,8 +1003,8 @@ void WindowManager::unfocusApp() {
10161003
currentlyFocusedApp = std::nullopt;
10171004
return;
10181005
}
1019-
auto& app = registry->get<X11App>(ent);
1020-
app.unfocus(matrix);
1006+
auto& appComponent = registry->get<WaylandApp::Component>(ent);
1007+
appComponent.app->unfocus(matrix);
10211008
currentlyFocusedApp = std::nullopt;
10221009
pendingFocusedApp = std::nullopt;
10231010
WL_WM_LOG("WM: unfocusApp (x11) ent=%d\n", (int)entt::to_integral(ent));

src/controls.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ void Controls::pollPressedKeys() {
489489
}
490490
}
491491

492+
493+
// called by the wayland server when input is detected
492494
ControlResponse
493495
Controls::handleKeySym(xkb_keysym_t sym,
494496
bool is_pressed,

src/wayland/WaylandApp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ WaylandApp::~WaylandApp()
173173
}
174174
}
175175

176+
void WaylandApp::unfocus(unsigned long /*matrix*/) {
177+
focused = false;
178+
wlr_seat_keyboard_notify_clear_focus(seat);
179+
wlr_seat_pointer_notify_clear_focus(seat);
180+
}
181+
176182
void
177183
WaylandApp::handle_destroy()
178184
{

src/wayland/wlr_compositor.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,6 @@ currentTimeSeconds()
108108
return elapsed.count();
109109
}
110110

111-
static void
112-
clear_input_forces(WlrServer* server)
113-
{
114-
if (!server) {
115-
return;
116-
}
117-
server->input.forward = false;
118-
server->input.back = false;
119-
server->input.left = false;
120-
server->input.right = false;
121-
server->input.delta_x = 0.0;
122-
server->input.delta_y = 0.0;
123-
}
124-
125111
static size_t
126112
wayland_app_count(WlrServer* server)
127113
{
@@ -860,24 +846,12 @@ process_key_sym(WlrServer* server,
860846
if (server->engine) {
861847
Controls* controls = server->engine->getControls();
862848
uint32_t mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
863-
bool modifierHeld =
864-
(mods & server->hotkeyModifierMask) || server->replayModifierActive;
849+
bool modifierHeld = (mods & server->hotkeyModifierMask);
865850
bool shiftHeld = (mods & WLR_MODIFIER_SHIFT) || server->pendingReplayShift ||
866851
server->replayShiftHeld > 0;
867852
if (controls) {
868853
auto resp =
869854
controls->handleKeySym(sym, pressed, modifierHeld, shiftHeld, waylandFocusActive);
870-
bool handled = resp.consumed || resp.blockClientDelivery || resp.requestQuit ||
871-
resp.clearInputForces || resp.clearSeatFocus;
872-
873-
if (resp.clearInputForces) {
874-
clear_input_forces(server);
875-
}
876-
if (resp.clearSeatFocus && server->seat) {
877-
wlr_seat_keyboard_notify_clear_focus(server->seat);
878-
wlr_seat_pointer_notify_clear_focus(server->seat);
879-
server->replayModifierActive = false;
880-
}
881855
if (resp.requestQuit) {
882856
wl_display_terminate(server->display);
883857
return;
@@ -934,7 +908,6 @@ process_key_sym(WlrServer* server,
934908
if (auto* controls = server->engine->getControls()) {
935909
controls->clearMovementInput();
936910
}
937-
clear_input_forces(server);
938911
}
939912
}
940913
}

0 commit comments

Comments
 (0)