mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
xwayland: do not allow apps to change focus after wlroots request
This commit is contained in:
parent
1dbcfdaf81
commit
74f7be7287
2 changed files with 19 additions and 4 deletions
|
@ -128,6 +128,7 @@ struct wlr_xwm {
|
||||||
#if WLR_HAS_XCB_ERRORS
|
#if WLR_HAS_XCB_ERRORS
|
||||||
xcb_errors_context_t *errors_context;
|
xcb_errors_context_t *errors_context;
|
||||||
#endif
|
#endif
|
||||||
|
unsigned int last_focus_seq;
|
||||||
|
|
||||||
struct wl_listener compositor_new_surface;
|
struct wl_listener compositor_new_surface;
|
||||||
struct wl_listener compositor_destroy;
|
struct wl_listener compositor_destroy;
|
||||||
|
|
|
@ -275,8 +275,9 @@ static void xwm_set_focus_window(struct wlr_xwm *xwm,
|
||||||
} else {
|
} else {
|
||||||
xwm_send_wm_message(xsurface, &message_data, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT);
|
xwm_send_wm_message(xsurface, &message_data, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT);
|
||||||
|
|
||||||
xcb_set_input_focus(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT,
|
xcb_void_cookie_t cookie = xcb_set_input_focus(xwm->xcb_conn,
|
||||||
xsurface->window_id, XCB_CURRENT_TIME);
|
XCB_INPUT_FOCUS_POINTER_ROOT, xsurface->window_id, XCB_CURRENT_TIME);
|
||||||
|
xwm->last_focus_seq = cookie.sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t values[1];
|
uint32_t values[1];
|
||||||
|
@ -1293,6 +1294,16 @@ static void xwm_handle_client_message(struct wlr_xwm *xwm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool validate_focus_serial(uint16_t last_focus_seq, uint16_t event_seq) {
|
||||||
|
uint16_t rev_dist = event_seq - last_focus_seq;
|
||||||
|
if (rev_dist >= UINT16_MAX / 2) {
|
||||||
|
// Probably overflow or too old
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void xwm_handle_focus_in(struct wlr_xwm *xwm,
|
static void xwm_handle_focus_in(struct wlr_xwm *xwm,
|
||||||
xcb_focus_in_event_t *ev) {
|
xcb_focus_in_event_t *ev) {
|
||||||
// Do not interfere with grabs
|
// Do not interfere with grabs
|
||||||
|
@ -1311,10 +1322,13 @@ static void xwm_handle_focus_in(struct wlr_xwm *xwm,
|
||||||
// Note: Some applications rely on being able to change focus, for ex. Steam:
|
// Note: Some applications rely on being able to change focus, for ex. Steam:
|
||||||
// https://github.com/swaywm/sway/issues/1865
|
// https://github.com/swaywm/sway/issues/1865
|
||||||
// Because of that, we allow changing focus between surfaces belonging to the
|
// Because of that, we allow changing focus between surfaces belonging to the
|
||||||
// same application.
|
// same application. We must be careful to ignore requests that are too old
|
||||||
|
// though, because otherwise it may lead to race conditions:
|
||||||
|
// https://github.com/swaywm/wlroots/issues/2324
|
||||||
struct wlr_xwayland_surface *requested_focus = lookup_surface(xwm, ev->event);
|
struct wlr_xwayland_surface *requested_focus = lookup_surface(xwm, ev->event);
|
||||||
if (xwm->focus_surface && requested_focus &&
|
if (xwm->focus_surface && requested_focus &&
|
||||||
requested_focus->pid == xwm->focus_surface->pid) {
|
requested_focus->pid == xwm->focus_surface->pid &&
|
||||||
|
validate_focus_serial(xwm->last_focus_seq, ev->sequence)) {
|
||||||
xwm_set_focus_window(xwm, requested_focus);
|
xwm_set_focus_window(xwm, requested_focus);
|
||||||
} else {
|
} else {
|
||||||
xwm_set_focus_window(xwm, xwm->focus_surface);
|
xwm_set_focus_window(xwm, xwm->focus_surface);
|
||||||
|
|
Loading…
Reference in a new issue