Skip to content

Commit 15803e1

Browse files
committed
Skip nonmanaged window when focusing
1 parent a521f5a commit 15803e1

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

gui-agent/vmside.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,31 @@ static void handle_keypress(Ghandles * g, XID UNUSED(winid))
16731673

16741674
static void handle_focus_helper(Ghandles * g, XID winid, struct msg_focus msg);
16751675

1676+
static void try_to_focus(Ghandles * g, XID window)
1677+
{
1678+
SKIP_NONMANAGED_WINDOW;
1679+
bool parent_has_focus = true;
1680+
1681+
// TODO: check if the parent has focus
1682+
// The window may have hierarchy, where context menu may have focus
1683+
// root
1684+
// +-VS Code
1685+
// +-Context Menu
1686+
1687+
// the commented code is wrong (only works for "decorated" window)
1688+
// int _return_to;
1689+
// XID focused_winid;
1690+
// XGetInputFocus(g->display, &focused_winid, &_return_to);
1691+
1692+
if (!parent_has_focus) {
1693+
struct msg_focus msg_focusin;
1694+
msg_focusin.type = FocusIn;
1695+
msg_focusin.mode = NotifyNormal;
1696+
msg_focusin.detail = NotifyAncestor;
1697+
handle_focus_helper(g, window, msg_focusin);
1698+
}
1699+
}
1700+
16761701
static void handle_button(Ghandles * g, XID winid)
16771702
{
16781703
struct msg_button msg;
@@ -1695,16 +1720,7 @@ static void handle_button(Ghandles * g, XID winid)
16951720

16961721
// Fake a "focus in" when mouse down on unfocused window.
16971722
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-
}
1723+
try_to_focus(g, winid);
17081724
}
17091725

17101726
feed_xdriver(g, 'B', msg.button, is_button_press ? 1 : 0);

0 commit comments

Comments
 (0)