Skip to content

Commit 085c1a0

Browse files
committed
Focus window when clicked
1 parent 403a952 commit 085c1a0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

gui-daemon/xside.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,21 @@ static void dump_mapped(Ghandles * g)
13991399
}
14001400
#endif
14011401

1402+
static void process_xievent_focus(Ghandles * g, const XILeaveEvent * ev);
1403+
1404+
static void focus_if_not_focused(Ghandles * g, const XButtonEvent * ev) {
1405+
Window focused;
1406+
int revertTo;
1407+
XGetInputFocus(g->display, &focused, &revertTo);
1408+
if (focused != ev->window) {
1409+
XILeaveEvent mock;
1410+
mock.type = XI_FocusIn;
1411+
mock.mode = NotifyNormal;
1412+
mock.detail = NotifyNonlinear;
1413+
process_xievent_focus(g, &mock);
1414+
}
1415+
}
1416+
14021417
/* handle local Xserver event: XButtonEvent
14031418
* same as XKeyEvent - send to relevant window in VM */
14041419
static void process_xevent_button(Ghandles * g, const XButtonEvent * ev)
@@ -1408,8 +1423,11 @@ static void process_xevent_button(Ghandles * g, const XButtonEvent * ev)
14081423
CHECK_NONMANAGED_WINDOW(g, ev->window);
14091424
update_wm_user_time(g, ev->window, ev->time);
14101425

1411-
k.type = ev->type;
1426+
if (ev->type == ButtonPress) {
1427+
focus_if_not_focused(g, ev);
1428+
}
14121429

1430+
k.type = ev->type;
14131431
k.x = ev->x;
14141432
k.y = ev->y;
14151433
k.state = ev->state;

0 commit comments

Comments
 (0)