From ea97a0dc87f7d8f070de747f0e3adc35780c6cca Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 12:22:16 +0100 Subject: wayland: instantiate sub-surfaces on-demand While most compositors handle instantiated but not-yet-mapped sub-surfaces correctly, e.g. kwin does not. For example, it will incorrectly offset the main surface both horizontally and vertically with a couple of pixels, leaving two transparent areas at the top and left, between the SSDs and the main surface. Note that a workaround is to position the sub-surfaces inside the main surface while they're unmapped. However, since the surfaces may be larger than the main surface (the CSDs, for examples, always are), this doesn't quite work since kwin, at least, resizes the window to include the sub-surfaces, even when unmapped. So, instead we instantiate all sub-surfaces on demand, when we know where to position them, and when they should be mapped. --- search.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'search.c') diff --git a/search.c b/search.c index a39c75a8..590c7577 100644 --- a/search.c +++ b/search.c @@ -40,8 +40,14 @@ search_ensure_size(struct terminal *term, size_t wanted_size) static void search_cancel_keep_selection(struct terminal *term) { - wl_surface_attach(term->window->search_surface, NULL, 0, 0); - wl_surface_commit(term->window->search_surface); + struct wl_window *win = term->window; + if (win->search_sub_surface != NULL) + wl_subsurface_destroy(win->search_sub_surface); + if (win->search_surface != NULL) + wl_surface_destroy(win->search_surface); + + win->search_surface = NULL; + win->search_sub_surface = NULL; free(term->search.buf); term->search.buf = NULL; @@ -65,6 +71,19 @@ search_begin(struct terminal *term) search_cancel_keep_selection(term); selection_cancel(term); + /* On-demand instantiate wayland surface */ + struct wl_window *win = term->window; + struct wayland *wayl = term->wl; + win->search_surface = wl_compositor_create_surface(wayl->compositor); + win->search_sub_surface = wl_subcompositor_get_subsurface( + wayl->sub_compositor, win->search_surface, win->surface); + wl_subsurface_set_desync(win->search_sub_surface); + + struct wl_region *region = wl_compositor_create_region(term->wl->compositor); + wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); + wl_surface_set_opaque_region(win->search_surface, region); + wl_region_destroy(region); + term->search.original_view = term->grid->view; term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; -- cgit v1.3 From 43c05518064d6b6dc9a24cf2bded216ab84508f7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 12:09:28 +0100 Subject: wayland: store pointer to window instance in all surfaces --- input.c | 8 +++++++- search.c | 2 ++ wayland.c | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'search.c') diff --git a/input.c b/input.c index 6a2bd0bf..d77061eb 100644 --- a/input.c +++ b/input.c @@ -676,7 +676,8 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, assert(surface != NULL); struct wayland *wayl = data; - struct terminal *term = wayl_terminal_from_surface(wayl, surface); + struct wl_window *win = wl_surface_get_user_data(surface); + struct terminal *term = win->term; LOG_DBG("pointer-enter: surface = %p, new-moused = %p", surface, term); @@ -743,6 +744,11 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, "compositor sent pointer_leave event without a pointer_enter " "event: surface=%p", surface); } else { + if (surface != NULL) { + /* Sway 1.4 sends this event with a NULL surface when we destroy the window */ + const struct wl_window *win = wl_surface_get_user_data(surface); + assert(old_moused == win->term); + } old_moused->active_surface = TERM_SURF_NONE; term_xcursor_update(old_moused); } diff --git a/search.c b/search.c index 590c7577..c0c33f3b 100644 --- a/search.c +++ b/search.c @@ -75,6 +75,8 @@ search_begin(struct terminal *term) struct wl_window *win = term->window; struct wayland *wayl = term->wl; win->search_surface = wl_compositor_create_surface(wayl->compositor); + wl_surface_set_user_data(win->search_surface, term->window); + win->search_sub_surface = wl_subcompositor_get_subsurface( wayl->sub_compositor, win->search_surface, win->surface); wl_subsurface_set_desync(win->search_sub_surface); diff --git a/wayland.c b/wayland.c index 9b8cb258..e5249a1d 100644 --- a/wayland.c +++ b/wayland.c @@ -51,6 +51,7 @@ csd_instantiate(struct wl_window *win) wayl->sub_compositor, win->csd.surface[i], win->surface); wl_subsurface_set_sync(win->csd.sub_surface[i]); + wl_surface_set_user_data(win->csd.surface[i], win); wl_surface_commit(win->csd.surface[i]); } } -- cgit v1.3 From 3ec50369cef48f0eeb9b4044201c076bcbbb91bd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 12:24:37 +0100 Subject: search: update search box before we update the main grid --- search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'search.c') diff --git a/search.c b/search.c index c0c33f3b..1c5d8e71 100644 --- a/search.c +++ b/search.c @@ -621,6 +621,6 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask LOG_DBG("search: buffer: %S", term->search.buf); search_find_next(term); - render_refresh(term); render_search_box(term); + render_refresh(term); } -- cgit v1.3 From b6f8a2e422fe05c1c1e63d39f72857d4c480bc7c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 13:06:00 +0100 Subject: search: enable/disable weston sub-surface desync quirk when rendering search box --- meson.build | 1 + quirks.c | 22 ++++++++++++++++++---- quirks.h | 3 ++- render.c | 4 ++++ search.c | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) (limited to 'search.c') diff --git a/meson.build b/meson.build index 21c23718..fcb85f90 100644 --- a/meson.build +++ b/meson.build @@ -112,6 +112,7 @@ executable( 'main.c', 'misc.c', 'misc.h', 'osc.c', 'osc.h', + 'quirks.c', 'quirks.h', 'render.c', 'render.h', 'search.c', 'search.h', 'selection.c', 'selection.h', diff --git a/quirks.c b/quirks.c index a1b1bafe..e96ad98e 100644 --- a/quirks.c +++ b/quirks.c @@ -3,8 +3,8 @@ #include #include -void -quirk_weston_subsurface_desync(struct wl_subsurface *sub) +static bool +is_weston(void) { /* * On weston (8.0), synchronized subsurfaces aren't updated @@ -19,7 +19,6 @@ quirk_weston_subsurface_desync(struct wl_subsurface *sub) * since it would defeat the purpose of having the subsurface * synchronized in the first place). */ - static bool is_weston = false; static bool initialized = false; @@ -28,8 +27,23 @@ quirk_weston_subsurface_desync(struct wl_subsurface *sub) is_weston = getenv("WESTON_CONFIG_FILE") != NULL; } - if (!is_weston) + return is_weston; +} + +void +quirk_weston_subsurface_desync_on(struct wl_subsurface *sub) +{ + if (!is_weston()) return; wl_subsurface_set_desync(sub); } + +void +quirk_weston_subsurface_desync_off(struct wl_subsurface *sub) +{ + if (!is_weston()) + return; + + wl_subsurface_set_sync(sub); +} diff --git a/quirks.h b/quirks.h index 1e087692..ce4b8b01 100644 --- a/quirks.h +++ b/quirks.h @@ -2,4 +2,5 @@ #include -void quirk_weston_subsurface_desync(struct wl_subsurface *sub); +void quirk_weston_subsurface_desync_on(struct wl_subsurface *sub); +void quirk_weston_subsurface_desync_off(struct wl_subsurface *sub); diff --git a/render.c b/render.c index 6e68f76b..df8a98de 100644 --- a/render.c +++ b/render.c @@ -18,6 +18,7 @@ #include "log.h" #include "config.h" #include "grid.h" +#include "quirks.h" #include "selection.h" #include "shm.h" @@ -1211,6 +1212,8 @@ render_search_box(struct terminal *term) if (term->search.cursor >= term->search.len) draw_bar(term, buf->pix, font, &fg, x, y); + quirk_weston_subsurface_desync_on(term->window->search_sub_surface); + /* TODO: this is only necessary on a window resize */ wl_subsurface_set_position( term->window->search_sub_surface, @@ -1229,6 +1232,7 @@ render_search_box(struct terminal *term) } wl_surface_commit(term->window->search_surface); + quirk_weston_subsurface_desync_off(term->window->search_sub_surface); } /* Move to terminal.c? */ diff --git a/search.c b/search.c index 1c5d8e71..f81ce6c6 100644 --- a/search.c +++ b/search.c @@ -79,12 +79,12 @@ search_begin(struct terminal *term) win->search_sub_surface = wl_subcompositor_get_subsurface( wayl->sub_compositor, win->search_surface, win->surface); - wl_subsurface_set_desync(win->search_sub_surface); struct wl_region *region = wl_compositor_create_region(term->wl->compositor); wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); wl_surface_set_opaque_region(win->search_surface, region); wl_region_destroy(region); + wl_subsurface_set_sync(win->search_sub_surface); term->search.original_view = term->grid->view; term->search.view_followed_offset = term->grid->view == term->grid->offset; -- cgit v1.3 From 7b3fffc6eceac1aeaa452e4c0a26c3c94ba7e8ba Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 13:06:30 +0100 Subject: search: don't mark the entire sub-surface as opaque --- search.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'search.c') diff --git a/search.c b/search.c index f81ce6c6..3d5159ae 100644 --- a/search.c +++ b/search.c @@ -79,11 +79,6 @@ search_begin(struct terminal *term) win->search_sub_surface = wl_subcompositor_get_subsurface( wayl->sub_compositor, win->search_surface, win->surface); - - struct wl_region *region = wl_compositor_create_region(term->wl->compositor); - wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); - wl_surface_set_opaque_region(win->search_surface, region); - wl_region_destroy(region); wl_subsurface_set_sync(win->search_sub_surface); term->search.original_view = term->grid->view; -- cgit v1.3 From c5a1af4e534f0f290ea885b221d7d37d020ac994 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 6 Mar 2020 19:16:54 +0100 Subject: render: never render CSD and/or search box "immediately" Handle the CSDs and the search box the same way we handle the main grid; when we need to redraw them, call render_refresh_{csd,search}(). This sets a flag that is checked after each FDM iteration. All actual rendering is done here. This also ties the commits of the Wayland sub-surfaces to the commit of the main surface. --- input.c | 11 +---- render.c | 145 +++++++++++++++++++++++++++++++++++++++---------------------- render.h | 7 +-- search.c | 6 +-- terminal.c | 14 ++---- terminal.h | 16 ++++++- 6 files changed, 118 insertions(+), 81 deletions(-) (limited to 'search.c') diff --git a/input.c b/input.c index a9e7ac83..efa58c9d 100644 --- a/input.c +++ b/input.c @@ -711,13 +711,9 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BUTTON_MINIMIZE: case TERM_SURF_BUTTON_MAXIMIZE: case TERM_SURF_BUTTON_CLOSE: - quirk_weston_csd_on(term); - render_csd(term); - quirk_weston_csd_off(term); - render_refresh(term); - term->xcursor = "left_ptr"; render_xcursor_set(term); + render_refresh_csd(term); break; case TERM_SURF_NONE: @@ -771,10 +767,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, if (old_moused->is_shutting_down) break; - quirk_weston_csd_on(old_moused); - render_csd(old_moused); - quirk_weston_csd_off(old_moused); - render_refresh(old_moused); + render_refresh_csd(old_moused); break; case TERM_SURF_NONE: diff --git a/render.c b/render.c index c90a2be5..fdb156ea 100644 --- a/render.c +++ b/render.c @@ -730,14 +730,10 @@ render_csd_part(struct terminal *term, pixman_image_unref(src); } -void +static void render_csd_title(struct terminal *term) { - if (term->window->use_csd != CSD_YES) - return; - - if (term->is_shutting_down) - return; + assert(term->window->use_csd == CSD_YES); struct csd_data info = get_csd_data(term, CSD_SURF_TITLE); struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE]; @@ -766,11 +762,9 @@ render_csd_title(struct terminal *term) static void render_csd_border(struct terminal *term, enum csd_surface surf_idx) { + assert(term->window->use_csd == CSD_YES); assert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM); - if (term->window->use_csd != CSD_YES) - return; - struct csd_data info = get_csd_data(term, surf_idx); struct wl_surface *surf = term->window->csd.surface[surf_idx]; @@ -934,16 +928,11 @@ render_csd_button_close(struct terminal *term, struct buffer *buf) pixman_image_unref(src); } -void +static void render_csd_button(struct terminal *term, enum csd_surface surf_idx) { - assert(surf_idx >= CSD_SURF_MINIMIZE); - - if (term->window->use_csd != CSD_YES) - return; - - if (term->is_shutting_down) - return; + assert(term->window->use_csd == CSD_YES); + assert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE); struct csd_data info = get_csd_data(term, surf_idx); struct wl_surface *surf = term->window->csd.surface[surf_idx]; @@ -1017,14 +1006,10 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) csd_commit(term, surf, buf); } -void +static void render_csd(struct terminal *term) { - if (term->window->use_csd != CSD_YES) - return; - - if (term->is_shutting_down) - return; + assert(term->window->use_csd == CSD_YES); if (term->window->is_fullscreen) return; @@ -1365,21 +1350,6 @@ grid_render(struct terminal *term) } static void -frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data) -{ - struct terminal *term = data; - - assert(term->window->frame_callback == wl_callback); - wl_callback_destroy(wl_callback); - term->window->frame_callback = NULL; - - if (term->render.pending) { - term->render.pending = false; - grid_render(term); - } -} - -void render_search_box(struct terminal *term) { assert(term->window->search_sub_surface != NULL); @@ -1479,6 +1449,38 @@ render_search_box(struct terminal *term) quirk_weston_subsurface_desync_off(term->window->search_sub_surface); } +static void +frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data) +{ + struct terminal *term = data; + + assert(term->window->frame_callback == wl_callback); + wl_callback_destroy(wl_callback); + term->window->frame_callback = NULL; + + if (term->render.pending.csd) { + term->render.pending.csd = false; + + if (term->window->use_csd == CSD_YES) { + quirk_weston_csd_on(term); + render_csd(term); + quirk_weston_csd_off(term); + } + } + + if (term->render.pending.search) { + term->render.pending.search = false; + + if (term->is_searching) + render_search_box(term); + } + + if (term->render.pending.grid) { + term->render.pending.grid = false; + grid_render(term); + } +} + /* Move to terminal.c? */ static bool maybe_resize(struct terminal *term, int width, int height, bool force) @@ -1651,8 +1653,6 @@ damage_view: term->unmaximized_height = term->height; } - render_csd(term); - #if 0 /* TODO: doesn't include CSD title bar */ xdg_toplevel_set_min_size( @@ -1672,14 +1672,13 @@ damage_view: term->height / term->scale + title_height); } - if (term->is_searching) - render_search_box(term); - tll_free(term->normal.scroll_damage); tll_free(term->alt.scroll_damage); term->render.last_buf = NULL; term_damage_view(term); + render_refresh_csd(term); + render_refresh_search(term); render_refresh(term); return true; @@ -1767,20 +1766,50 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) tll_foreach(renderer->wayl->terms, it) { struct terminal *term = it->item; - if (!term->render.refresh_needed) + if (!term->render.refresh.grid && + !term->render.refresh.csd && + !term->render.refresh.search) + { continue; + } - if (term->render.app_sync_updates.enabled) + if (term->render.app_sync_updates.enabled && + !term->render.refresh.csd && + !term->render.refresh.search) + { continue; + } + + if (term->render.refresh.csd || term->render.refresh.search) { + /* Force update of parent surface */ + term->render.refresh.grid = true; + } assert(term->window->is_configured); - term->render.refresh_needed = false; - if (term->window->frame_callback == NULL) - grid_render(term); - else { + bool grid = term->render.refresh.grid; + bool csd = term->render.refresh.csd; + bool search = term->render.refresh.search; + + term->render.refresh.grid = false; + term->render.refresh.csd = false; + term->render.refresh.search = false; + + if (term->window->frame_callback == NULL) { + if (csd && term->window->use_csd == CSD_YES) { + quirk_weston_csd_on(term); + render_csd(term); + quirk_weston_csd_off(term); + } + if (search) + render_search_box(term); + if (grid) + grid_render(term); + } else { /* Tells the frame callback to render again */ - term->render.pending = true; + term->render.pending.grid = grid; + term->render.pending.csd = csd; + term->render.pending.search = search; } } @@ -1815,7 +1844,21 @@ render_set_title(struct terminal *term, const char *_title) void render_refresh(struct terminal *term) { - term->render.refresh_needed = true; + term->render.refresh.grid = true; +} + +void +render_refresh_csd(struct terminal *term) +{ + if (term->window->use_csd == CSD_YES) + term->render.refresh.csd = true; +} + +void +render_refresh_search(struct terminal *term) +{ + if (term->is_searching) + term->render.refresh.search = true; } bool diff --git a/render.h b/render.h index cccf2001..99246f17 100644 --- a/render.h +++ b/render.h @@ -14,13 +14,10 @@ bool render_resize_force(struct terminal *term, int width, int height); void render_set_title(struct terminal *term, const char *title); void render_refresh(struct terminal *term); +void render_refresh_csd(struct terminal *term); +void render_refresh_search(struct terminal *term); bool render_xcursor_set(struct terminal *term); -void render_search_box(struct terminal *term); -void render_csd(struct terminal *term); -void render_csd_title(struct terminal *term); -void render_csd_button(struct terminal *term, enum csd_surface surf_idx); - struct render_worker_context { int my_id; struct terminal *term; diff --git a/search.c b/search.c index 3d5159ae..2c58f3f2 100644 --- a/search.c +++ b/search.c @@ -86,8 +86,7 @@ search_begin(struct terminal *term) term->is_searching = true; term_xcursor_update(term); - render_search_box(term); - render_refresh(term); + render_refresh_search(term); } void @@ -616,6 +615,5 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask LOG_DBG("search: buffer: %S", term->search.buf); search_find_next(term); - render_search_box(term); - render_refresh(term); + render_refresh_search(term); } diff --git a/terminal.c b/terminal.c index ebc27b3c..7fc177f0 100644 --- a/terminal.c +++ b/terminal.c @@ -199,7 +199,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) */ if (term->window->frame_callback == NULL) { if (term->render.app_sync_updates.enabled) - term->render.refresh_needed = true; + term->render.refresh.grid = true; else { /* First timeout - reset each time we receive input. */ @@ -235,7 +235,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) } } } else - term->render.pending = true; + term->render.pending.grid = true; if (hup) { if (term->hold_at_exit) { @@ -1637,10 +1637,7 @@ term_visual_focus_in(struct terminal *term) if (term->cursor_blink.active) cursor_blink_start_timer(term); - quirk_weston_csd_on(term); - render_csd(term); - quirk_weston_csd_off(term); - + render_refresh_csd(term); cursor_refresh(term); } @@ -1654,10 +1651,7 @@ term_visual_focus_out(struct terminal *term) if (term->cursor_blink.active) cursor_blink_stop_timer(term); - quirk_weston_csd_on(term); - render_csd(term); - quirk_weston_csd_off(term); - + render_refresh_csd(term); cursor_refresh(term); } diff --git a/terminal.h b/terminal.h index 3731ee0d..92082d8c 100644 --- a/terminal.h +++ b/terminal.h @@ -331,7 +331,20 @@ struct terminal { enum term_surface active_surface; struct { - bool refresh_needed; /* Terminal needs to be re-rendered, as soon-as-possible */ + /* Scheduled for rendering, as soon-as-possible */ + struct { + bool grid; + bool csd; + bool search; + } refresh; + + /* Scheduled for rendering, in the next frame callback */ + struct { + bool grid; + bool csd; + bool search; + } pending; + int scrollback_lines; /* Number of scrollback lines, from conf (TODO: move out from render struct?) */ struct { @@ -358,7 +371,6 @@ struct terminal { struct cell *cell; /* For easy access to content */ } last_cursor; - bool pending; /* Need to re-render again, after next frame-callback */ struct buffer *last_buf; /* Buffer we rendered to last time */ bool was_flashing; /* Flash was active last time we rendered */ bool was_searching; -- cgit v1.3