Skip to content

Commit f32245a

Browse files
committed
Give windows focus before sending events
Events from the GUI daemon are directed at specific windows. Ensuring that they are sent to the correct window is more importent than obeying the ICCCM input hint. Giving pointer focus to a window is accomplished by raising it.
1 parent a3313a4 commit f32245a

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

gui-agent/vmside.c

+23-23
Original file line numberDiff line numberDiff line change
@@ -1600,11 +1600,17 @@ static void mkghandles(Ghandles * g)
16001600
g->clipboard_data_len = 0;
16011601
}
16021602

1603-
static void handle_keypress(Ghandles * g, XID UNUSED(winid))
1603+
static void handle_keypress(Ghandles * g, XID winid)
16041604
{
16051605
struct msg_keypress key;
16061606
XkbStateRec state;
16071607
read_data(g->vchan, (char *) &key, sizeof(key));
1608+
1609+
// Ignore the focus 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+
16081614
// sync modifiers state
16091615
if (XkbGetState(g->display, XkbUseCoreKbd, &state) != Success) {
16101616
if (g->log_level > 0)
@@ -1673,8 +1679,9 @@ static void handle_button(Ghandles * g, XID winid)
16731679
if (l && l->data && ((struct window_data*)l->data)->is_docked) {
16741680
/* get position of embeder, not icon itself*/
16751681
winid = ((struct window_data*)l->data)->embeder;
1676-
XRaiseWindow(g->display, winid);
16771682
}
1683+
/* If the window was not raised before, it sure is now! */
1684+
XRaiseWindow(g->display, winid);
16781685

16791686
if (g->log_level > 1)
16801687
fprintf(stderr,
@@ -1790,26 +1797,25 @@ static void take_focus(Ghandles * g, XID winid)
17901797
static void handle_focus(Ghandles * g, XID winid)
17911798
{
17921799
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+
}
17971812
read_data(g->vchan, (char *) &key, sizeof(key));
17981813
if (key.type == FocusIn
17991814
&& (key.mode == NotifyNormal || key.mode == NotifyUngrab)) {
18001815

18011816
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);
18131819

18141820
// Give input focus only to window that set the input hint
18151821
if (input_hint)
@@ -1824,12 +1830,6 @@ static void handle_focus(Ghandles * g, XID winid)
18241830
} else if (key.type == FocusOut
18251831
&& (key.mode == NotifyNormal
18261832
|| 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-
}
18331833
if (input_hint)
18341834
XSetInputFocus(g->display, None, RevertToParent, g->time);
18351835

0 commit comments

Comments
 (0)