wayland: optionally disable pointer input on subsurfaces

We have a number of sub-surfaces for which we are *not* interrested in
pointer (or touch) input.

Up until now, we’ve manually dealt with these, by recognizing these
surfaces in all pointer events, and ignoring them.

But, lo and behold, there are better ways of doing this. By clearing
the subsurface’s input region, the compositor will do this for us -
when a pointer is outside a surface’s input region, the event is
passed to the next surface underneath it.

This is exactly what we want! Do this for all subsurfaces, *except*
the CSDs.
This commit is contained in:
Daniel Eklöf 2022-04-16 17:41:14 +02:00
parent fc2ebf772c
commit 129deaffa8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
8 changed files with 27 additions and 49 deletions

18
input.c
View file

@ -1904,10 +1904,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
break;
}
case TERM_SURF_SEARCH:
case TERM_SURF_SCROLLBACK_INDICATOR:
case TERM_SURF_RENDER_TIMER:
case TERM_SURF_JUMP_LABEL:
case TERM_SURF_TITLE:
case TERM_SURF_BORDER_LEFT:
case TERM_SURF_BORDER_RIGHT:
@ -1993,10 +1989,6 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
break;
case TERM_SURF_NONE:
case TERM_SURF_SEARCH:
case TERM_SURF_SCROLLBACK_INDICATOR:
case TERM_SURF_RENDER_TIMER:
case TERM_SURF_JUMP_LABEL:
case TERM_SURF_TITLE:
case TERM_SURF_BORDER_LEFT:
case TERM_SURF_BORDER_RIGHT:
@ -2044,10 +2036,6 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
switch (surf_kind) {
case TERM_SURF_NONE:
case TERM_SURF_SEARCH:
case TERM_SURF_SCROLLBACK_INDICATOR:
case TERM_SURF_RENDER_TIMER:
case TERM_SURF_JUMP_LABEL:
case TERM_SURF_BUTTON_MINIMIZE:
case TERM_SURF_BUTTON_MAXIMIZE:
case TERM_SURF_BUTTON_CLOSE:
@ -2463,12 +2451,6 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
term_shutdown(term);
break;
case TERM_SURF_SEARCH:
case TERM_SURF_SCROLLBACK_INDICATOR:
case TERM_SURF_RENDER_TIMER:
case TERM_SURF_JUMP_LABEL:
break;
case TERM_SURF_GRID: {
search_cancel(term);
urls_reset(term);

View file

@ -2159,7 +2159,9 @@ render_scrollback_position(struct terminal *term)
}
if (win->scrollback_indicator.surf == NULL) {
if (!wayl_win_subsurface_new(win, &win->scrollback_indicator)) {
if (!wayl_win_subsurface_new(
win, &win->scrollback_indicator, false))
{
LOG_ERR("failed to create scrollback indicator surface");
return;
}

View file

@ -136,7 +136,8 @@ search_begin(struct terminal *term)
}
/* On-demand instantiate wayland surface */
bool ret = wayl_win_subsurface_new(term->window, &term->window->search);
bool ret = wayl_win_subsurface_new(
term->window, &term->window->search, false);
xassert(ret);
const struct grid *grid = term->grid;

View file

@ -3008,10 +3008,6 @@ term_xcursor_update_for_seat(struct terminal *term, struct seat *seat)
: XCURSOR_LEFT_PTR;
break;
}
case TERM_SURF_SEARCH:
case TERM_SURF_SCROLLBACK_INDICATOR:
case TERM_SURF_RENDER_TIMER:
case TERM_SURF_JUMP_LABEL:
case TERM_SURF_TITLE:
case TERM_SURF_BUTTON_MINIMIZE:
case TERM_SURF_BUTTON_MAXIMIZE:
@ -3389,12 +3385,6 @@ term_surface_kind(const struct terminal *term, const struct wl_surface *surface)
{
if (likely(surface == term->window->surface))
return TERM_SURF_GRID;
else if (surface == term->window->search.surf)
return TERM_SURF_SEARCH;
else if (surface == term->window->scrollback_indicator.surf)
return TERM_SURF_SCROLLBACK_INDICATOR;
else if (surface == term->window->render_timer.surf)
return TERM_SURF_RENDER_TIMER;
else if (surface == term->window->csd.surface[CSD_SURF_TITLE].surf)
return TERM_SURF_TITLE;
else if (surface == term->window->csd.surface[CSD_SURF_LEFT].surf)
@ -3411,13 +3401,8 @@ term_surface_kind(const struct terminal *term, const struct wl_surface *surface)
return TERM_SURF_BUTTON_MAXIMIZE;
else if (surface == term->window->csd.surface[CSD_SURF_CLOSE].surf)
return TERM_SURF_BUTTON_CLOSE;
else {
tll_foreach(term->window->urls, it) {
if (surface == it->item.surf.surf)
return TERM_SURF_JUMP_LABEL;
}
else
return TERM_SURF_NONE;
}
}
static bool

View file

@ -272,10 +272,6 @@ struct ptmx_buffer {
enum term_surface {
TERM_SURF_NONE,
TERM_SURF_GRID,
TERM_SURF_SEARCH,
TERM_SURF_SCROLLBACK_INDICATOR,
TERM_SURF_RENDER_TIMER,
TERM_SURF_JUMP_LABEL,
TERM_SURF_TITLE,
TERM_SURF_BORDER_LEFT,
TERM_SURF_BORDER_RIGHT,

View file

@ -718,7 +718,7 @@ urls_render(struct terminal *term)
xassert(tll_length(win->urls) == 0);
tll_foreach(win->term->urls, it) {
struct wl_url url = {.url = &it->item};
wayl_win_subsurface_new(win, &url.surf);
wayl_win_subsurface_new(win, &url.surf, false);
tll_push_back(win->urls, url);
tag_cells_for_url(term, &it->item, true);

View file

@ -67,13 +67,14 @@ csd_instantiate(struct wl_window *win)
xassert(wayl != NULL);
for (size_t i = 0; i < CSD_SURF_MINIMIZE; i++) {
bool ret = wayl_win_subsurface_new(win, &win->csd.surface[i]);
bool ret = wayl_win_subsurface_new(win, &win->csd.surface[i], true);
xassert(ret);
}
for (size_t i = CSD_SURF_MINIMIZE; i < CSD_SURF_COUNT; i++) {
bool ret = wayl_win_subsurface_new_with_custom_parent(
win, win->csd.surface[CSD_SURF_TITLE].surf, &win->csd.surface[i]);
win, win->csd.surface[CSD_SURF_TITLE].surf, &win->csd.surface[i],
true);
xassert(ret);
}
@ -1478,7 +1479,7 @@ wayl_win_init(struct terminal *term, const char *token)
switch (conf->tweak.render_timer) {
case RENDER_TIMER_OSD:
case RENDER_TIMER_BOTH:
if (!wayl_win_subsurface_new(win, &win->render_timer)) {
if (!wayl_win_subsurface_new(win, &win->render_timer, false)) {
LOG_ERR("failed to create render timer surface");
goto out;
}
@ -1783,7 +1784,7 @@ wayl_win_csd_borders_visible(const struct wl_window *win)
bool
wayl_win_subsurface_new_with_custom_parent(
struct wl_window *win, struct wl_surface *parent,
struct wl_surf_subsurf *surf)
struct wl_surf_subsurf *surf, bool allow_pointer_input)
{
struct wayland *wayl = win->term->wl;
@ -1807,15 +1808,25 @@ wayl_win_subsurface_new_with_custom_parent(
wl_surface_set_user_data(main_surface, win);
wl_subsurface_set_sync(sub);
/* Disable pointer and touch events */
if (!allow_pointer_input) {
struct wl_region *empty =
wl_compositor_create_region(wayl->compositor);
wl_surface_set_input_region(main_surface, empty);
wl_region_destroy(empty);
}
surf->surf = main_surface;
surf->sub = sub;
return true;
}
bool
wayl_win_subsurface_new(struct wl_window *win, struct wl_surf_subsurf *surf)
wayl_win_subsurface_new(struct wl_window *win, struct wl_surf_subsurf *surf,
bool allow_pointer_input)
{
return wayl_win_subsurface_new_with_custom_parent(win, win->surface, surf);
return wayl_win_subsurface_new_with_custom_parent(
win, win->surface, surf, allow_pointer_input);
}
void

View file

@ -515,10 +515,11 @@ bool wayl_win_csd_titlebar_visible(const struct wl_window *win);
bool wayl_win_csd_borders_visible(const struct wl_window *win);
bool wayl_win_subsurface_new(
struct wl_window *win, struct wl_surf_subsurf *surf);
struct wl_window *win, struct wl_surf_subsurf *surf,
bool allow_pointer_input);
bool wayl_win_subsurface_new_with_custom_parent(
struct wl_window *win, struct wl_surface *parent,
struct wl_surf_subsurf *surf);
struct wl_surf_subsurf *surf, bool allow_pointer_input);
void wayl_win_subsurface_destroy(struct wl_surf_subsurf *surf);
void wayl_bindings_reset(struct seat *seat);