Skip to content

Commit 1c5b880

Browse files
committed
Focus window before clicked
1 parent 485ebae commit 1c5b880

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

gui-agent/vmside.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,8 @@ static void handle_keypress(Ghandles * g, XID UNUSED(winid))
16711671
if (!is_mod_key) feed_xdriver(g, 'K', key.keycode, is_press);
16721672
}
16731673

1674+
static void handle_focus_helper(Ghandles * g, XID winid, struct msg_focus msg);
1675+
16741676
static void handle_button(Ghandles * g, XID winid)
16751677
{
16761678
struct msg_button msg;
@@ -1688,7 +1690,24 @@ static void handle_button(Ghandles * g, XID winid)
16881690
fprintf(stderr,
16891691
"send buttonevent, win 0x%x type=%d button=%d\n",
16901692
(int) winid, msg.type, msg.button);
1691-
feed_xdriver(g, 'B', msg.button, msg.type == ButtonPress ? 1 : 0);
1693+
1694+
bool is_button_press = msg.type == ButtonPress;
1695+
1696+
// Fake a "focus in" when mouse down on unfocused window.
1697+
if (is_button_press) {
1698+
int _return_to;
1699+
XID focused_winid;
1700+
XGetInputFocus(g->display, &focused_winid, &_return_to);
1701+
if (focused_winid != winid) {
1702+
struct msg_focus msg_focusin;
1703+
msg_focusin.type = FocusIn;
1704+
msg_focusin.mode = NotifyNormal;
1705+
msg_focusin.detail = NotifyAncestor;
1706+
handle_focus_helper(g, winid, msg_focusin);
1707+
}
1708+
}
1709+
1710+
feed_xdriver(g, 'B', msg.button, is_button_press ? 1 : 0);
16921711
}
16931712

16941713
static void handle_motion(Ghandles * g, XID winid)

0 commit comments

Comments
 (0)