@@ -1671,6 +1671,8 @@ static void handle_keypress(Ghandles * g, XID UNUSED(winid))
1671
1671
if (!is_mod_key ) feed_xdriver (g , 'K' , key .keycode , is_press );
1672
1672
}
1673
1673
1674
+ static void handle_focus_helper (Ghandles * g , XID winid , struct msg_focus msg );
1675
+
1674
1676
static void handle_button (Ghandles * g , XID winid )
1675
1677
{
1676
1678
struct msg_button msg ;
@@ -1688,7 +1690,24 @@ static void handle_button(Ghandles * g, XID winid)
1688
1690
fprintf (stderr ,
1689
1691
"send buttonevent, win 0x%x type=%d button=%d\n" ,
1690
1692
(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 );
1692
1711
}
1693
1712
1694
1713
static void handle_motion (Ghandles * g , XID winid )
0 commit comments