@@ -1600,11 +1600,17 @@ static void mkghandles(Ghandles * g)
1600
1600
g -> clipboard_data_len = 0 ;
1601
1601
}
1602
1602
1603
- static void handle_keypress (Ghandles * g , XID UNUSED ( winid ) )
1603
+ static void handle_keypress (Ghandles * g , XID winid )
1604
1604
{
1605
1605
struct msg_keypress key ;
1606
1606
XkbStateRec state ;
1607
1607
read_data (g -> vchan , (char * ) & key , sizeof (key ));
1608
+
1609
+ // Ignore the input hint. If the window already has focus, then this is a
1610
+ // no-op other than changing a timestamp. Otherwise, it is too late to wait
1611
+ // for the window to take focus for itself.
1612
+ XSetInputFocus (g -> display , winid , RevertToParent , g -> time );
1613
+
1608
1614
// sync modifiers state
1609
1615
if (XkbGetState (g -> display , XkbUseCoreKbd , & state ) != Success ) {
1610
1616
if (g -> log_level > 0 )
@@ -1673,8 +1679,9 @@ static void handle_button(Ghandles * g, XID winid)
1673
1679
if (l && l -> data && ((struct window_data * )l -> data )-> is_docked ) {
1674
1680
/* get position of embeder, not icon itself*/
1675
1681
winid = ((struct window_data * )l -> data )-> embeder ;
1676
- XRaiseWindow (g -> display , winid );
1677
1682
}
1683
+ /* If the window was not raised before, it sure is now! */
1684
+ XRaiseWindow (g -> display , winid );
1678
1685
1679
1686
if (g -> log_level > 1 )
1680
1687
fprintf (stderr ,
@@ -1790,26 +1797,25 @@ static void take_focus(Ghandles * g, XID winid)
1790
1797
static void handle_focus (Ghandles * g , XID winid )
1791
1798
{
1792
1799
struct msg_focus key ;
1793
- struct genlist * l ;
1794
- int input_hint ;
1795
- int use_take_focus ;
1796
-
1800
+ bool input_hint = true, use_take_focus = false, is_docked = false;
1801
+ Window embedder = None ;
1802
+ struct genlist * l = list_lookup (windows_list , winid );
1803
+ if (l && l -> data ) {
1804
+ const struct window_data * data = l -> data ;
1805
+ input_hint = data -> input_hint ;
1806
+ use_take_focus = data -> support_take_focus ;
1807
+ if ((is_docked = data -> is_docked ))
1808
+ embedder = data -> embeder ;
1809
+ } else {
1810
+ fprintf (stderr , "WARNING handle_focus: Window 0x%x data not initialized" , (int )winid );
1811
+ }
1797
1812
read_data (g -> vchan , (char * ) & key , sizeof (key ));
1798
1813
if (key .type == FocusIn
1799
1814
&& (key .mode == NotifyNormal || key .mode == NotifyUngrab )) {
1800
1815
1801
1816
XRaiseWindow (g -> display , winid );
1802
-
1803
- if ( (l = list_lookup (windows_list , winid )) && (l -> data ) ) {
1804
- input_hint = ((struct window_data * )l -> data )-> input_hint ;
1805
- use_take_focus = ((struct window_data * )l -> data )-> support_take_focus ;
1806
- if (((struct window_data * )l -> data )-> is_docked )
1807
- XRaiseWindow (g -> display , ((struct window_data * )l -> data )-> embeder );
1808
- } else {
1809
- fprintf (stderr , "WARNING handle_focus: Window 0x%x data not initialized" , (int )winid );
1810
- input_hint = True ;
1811
- use_take_focus = False ;
1812
- }
1817
+ if (is_docked )
1818
+ XRaiseWindow (g -> display , embedder );
1813
1819
1814
1820
// Give input focus only to window that set the input hint
1815
1821
if (input_hint )
@@ -1824,12 +1830,6 @@ static void handle_focus(Ghandles * g, XID winid)
1824
1830
} else if (key .type == FocusOut
1825
1831
&& (key .mode == NotifyNormal
1826
1832
|| key .mode == NotifyUngrab )) {
1827
- if ( (l = list_lookup (windows_list , winid )) && (l -> data ) )
1828
- input_hint = ((struct window_data * )l -> data )-> input_hint ;
1829
- else {
1830
- fprintf (stderr , "WARNING handle_focus: Window 0x%x data not initialized" , (int )winid );
1831
- input_hint = True ;
1832
- }
1833
1833
if (input_hint )
1834
1834
XSetInputFocus (g -> display , None , RevertToParent , g -> time );
1835
1835
0 commit comments