@@ -1673,6 +1673,31 @@ static void handle_keypress(Ghandles * g, XID UNUSED(winid))
1673
1673
1674
1674
static void handle_focus_helper (Ghandles * g , XID winid , struct msg_focus msg );
1675
1675
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
+
1676
1701
static void handle_button (Ghandles * g , XID winid )
1677
1702
{
1678
1703
struct msg_button msg ;
@@ -1695,16 +1720,7 @@ static void handle_button(Ghandles * g, XID winid)
1695
1720
1696
1721
// Fake a "focus in" when mouse down on unfocused window.
1697
1722
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 );
1708
1724
}
1709
1725
1710
1726
feed_xdriver (g , 'B' , msg .button , is_button_press ? 1 : 0 );
0 commit comments