From 43fc297fbd1bebc821ed3ee2b932e5cc8b806542 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 27 Aug 2019 19:43:50 +0200 Subject: main: free search buffer --- main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 2a3b3daa..0710f933 100644 --- a/main.c +++ b/main.c @@ -1086,6 +1086,8 @@ out: for (size_t i = 0; i < sizeof(term.fonts) / sizeof(term.fonts[0]); i++) font_destroy(&term.fonts[i]); + free(term.search.buf); + if (term.flash.fd != -1) close(term.flash.fd); if (term.blink.fd != -1) -- cgit v1.3 From c2b4f4daa6f6e407f9856a3081b2d97d4efb567f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 28 Aug 2019 21:01:36 +0200 Subject: main: log cell width/height at info level, not debug This complements the INFO logs from the renderer when the terminal is resized. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 0710f933..60d041f1 100644 --- a/main.c +++ b/main.c @@ -630,7 +630,7 @@ main(int argc, char *const *argv) term.cell_width = (int)ceil(term.fextents.max_x_advance); term.cell_height = (int)ceil(term.fextents.height); - LOG_DBG("cell width=%d, height=%d", term.cell_width, term.cell_height); + LOG_INFO("cell width=%d, height=%d", term.cell_width, term.cell_height); term.wl.display = wl_display_connect(NULL); if (term.wl.display == NULL) { -- cgit v1.3 From 66912cbfb5e44d44670582fad932932f9de6794b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 19:34:41 +0200 Subject: search: use a sub-surface to render the search buffer --- main.c | 5 +++ search.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ terminal.h | 1 + 3 files changed, 141 insertions(+), 14 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 60d041f1..b78305f7 100644 --- a/main.c +++ b/main.c @@ -197,6 +197,11 @@ handle_global(void *data, struct wl_registry *registry, term->wl.registry, name, &wl_compositor_interface, 4); } + else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { + term->wl.sub_compositor = wl_registry_bind( + term->wl.registry, name, &wl_subcompositor_interface, 1); + } + else if (strcmp(interface, wl_shm_interface.name) == 0) { term->wl.shm = wl_registry_bind( term->wl.registry, name, &wl_shm_interface, 1); diff --git a/search.c b/search.c index 6aa6be5c..558f98c7 100644 --- a/search.c +++ b/search.c @@ -1,6 +1,8 @@ #include "search.h" #include + +#include #include #define LOG_MODULE "search" @@ -9,11 +11,98 @@ #include "grid.h" #include "render.h" #include "selection.h" +#include "shm.h" -void -search_begin(struct terminal *term) +#define max(x, y) ((x) > (y) ? (x) : (y)) + +static struct wl_surface *wl_surf; +static struct wl_subsurface *sub_surf; + + +static inline pixman_color_t +color_hex_to_pixman_with_alpha(uint32_t color, uint16_t alpha) { - LOG_DBG("search: begin"); + int alpha_div = 0xffff / alpha; + return (pixman_color_t){ + .red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) / alpha_div, + .green = ((color >> 8 & 0xff) | (color >> 0 & 0xff00)) / alpha_div, + .blue = ((color >> 0 & 0xff) | (color << 8 & 0xff00)) / alpha_div, + .alpha = alpha, + }; +} + +static inline pixman_color_t +color_hex_to_pixman(uint32_t color) +{ + /* Count on the compiler optimizing this */ + return color_hex_to_pixman_with_alpha(color, 0xffff); +} + +/* TODO: move to render.c? */ +static void +render(struct terminal *term) +{ + assert(sub_surf != NULL); + + /* TODO: at least sway allows the subsurface to extend outside the + * main window. Do we want that? */ + const int scale = term->scale >= 1 ? term->scale : 1; + const int margin = scale * 3; + const int width = 2 * margin + max(20, term->search.len) * term->cell_width; + const int height = 2 * margin + 1 * term->cell_height; + + struct buffer *buf = shm_get_buffer(term->wl.shm, width, height, 1); + + /* Background - yellow on empty/match, red on mismatch */ + pixman_color_t color = color_hex_to_pixman( + term->search.match_len == term->search.len ? 0xffff00 : 0xff0000); + + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, + 1, &(pixman_rectangle16_t){0, 0, width, height}); + + int x = margin; + int y = margin; + pixman_color_t fg = color_hex_to_pixman(0x000000); + + /* Text (what the user entered - *not* match(es)) */ + for (size_t i = 0; i < term->search.len; i++) { + const struct glyph *glyph = font_glyph_for_wc(&term->fonts[0], term->search.buf[i]); + if (glyph == NULL) + continue; + + pixman_image_t *src = pixman_image_create_solid_fill(&fg); + pixman_image_composite32( + PIXMAN_OP_OVER, src, glyph->pix, buf->pix, 0, 0, 0, 0, + x + glyph->x, y + term->fextents.ascent - glyph->y, + glyph->width, glyph->height); + pixman_image_unref(src); + + x += glyph->width; + } + + LOG_INFO("match length: %zu", term->search.match_len); + + wl_subsurface_set_position( + sub_surf, term->width - width - margin, term->height - height - margin); + + wl_surface_damage_buffer(wl_surf, 0, 0, width, height); + wl_surface_attach(wl_surf, buf->wl_buf, 0, 0); + wl_surface_set_buffer_scale(wl_surf, scale); + wl_surface_commit(wl_surf); +} + +static void +search_cancel_keep_selection(struct terminal *term) +{ + if (sub_surf != NULL) { + wl_subsurface_destroy(sub_surf); + sub_surf = NULL; + } + if (wl_surf != NULL) { + wl_surface_destroy(wl_surf); + wl_surf = NULL; + } free(term->search.buf); term->search.buf = NULL; @@ -21,35 +110,65 @@ search_begin(struct terminal *term) term->search.sz = 0; term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; + term->is_searching = false; + + render_refresh(term); +} + +void +search_begin(struct terminal *term) +{ + LOG_DBG("search: begin"); + + search_cancel_keep_selection(term); + selection_cancel(term); + term->search.original_view = term->grid->view; term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; - selection_cancel(term); + wl_surf = wl_compositor_create_surface(term->wl.compositor); + if (wl_surf != NULL) { + sub_surf = wl_subcompositor_get_subsurface( + term->wl.sub_compositor, wl_surf, term->wl.surface); + + if (sub_surf != NULL) { + /* Sub-surface updates may occur without updating the main + * window */ + wl_subsurface_set_desync(sub_surf); + } + } + + if (wl_surf == NULL || sub_surf == NULL) { + LOG_ERR("failed to create sub-surface for search box"); + if (wl_surf != NULL) + wl_surface_destroy(wl_surf); + assert(sub_surf == NULL); + } + + render(term); render_refresh(term); } void search_cancel(struct terminal *term) { - LOG_DBG("search: cancel"); - - free(term->search.buf); - term->search.buf = NULL; - term->search.len = 0; - term->search.sz = 0; - term->is_searching = false; + if (!term->is_searching) + return; - render_refresh(term); + search_cancel_keep_selection(term); + selection_cancel(term); } static void search_update(struct terminal *term) { if (term->search.len == 0) { + LOG_INFO("len == 0"); term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; selection_cancel(term); + render(term); return; } @@ -187,6 +306,7 @@ search_update(struct terminal *term) term->search.match.col = start_col; term->search.match_len = match_len; + render(term); return; } @@ -198,7 +318,7 @@ search_update(struct terminal *term) term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; selection_cancel(term); - + render(term); #undef ROW_DEC } @@ -225,12 +345,13 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask term->grid->view = term->search.original_view; term_damage_view(term); search_cancel(term); + return; } /* "Commit" search - copy selection to primary and cancel search */ else if (mods == 0 && sym == XKB_KEY_Return) { selection_finalize(term, term->input_serial); - search_cancel(term); + search_cancel_keep_selection(term); return; } diff --git a/terminal.h b/terminal.h index 18130392..755c7b4a 100644 --- a/terminal.h +++ b/terminal.h @@ -41,6 +41,7 @@ struct wayland { struct wl_display *display; struct wl_registry *registry; struct wl_compositor *compositor; + struct wl_subcompositor *sub_compositor; struct wl_surface *surface; struct wl_shm *shm; struct wl_seat *seat; -- cgit v1.3 From 44a353a7f74b562cb057c23760013a12becbecf3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 20:15:33 +0200 Subject: search: move wayland surface variables into the term struct --- main.c | 20 ++++++++++++-------- search.c | 47 +++++++++++++++++++++++------------------------ terminal.h | 16 ++++++++++++++-- 3 files changed, 49 insertions(+), 34 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b78305f7..e92996ef 100644 --- a/main.c +++ b/main.c @@ -1019,12 +1019,6 @@ out: if (term.wl.xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(term.wl.xdg_output_manager); - if (term.render.frame_callback != NULL) - wl_callback_destroy(term.render.frame_callback); - if (term.wl.xdg_toplevel != NULL) - xdg_toplevel_destroy(term.wl.xdg_toplevel); - if (term.wl.xdg_surface != NULL) - xdg_surface_destroy(term.wl.xdg_surface); free(term.wl.pointer.theme_name); if (term.wl.pointer.theme != NULL) wl_cursor_theme_destroy(term.wl.pointer.theme); @@ -1054,10 +1048,20 @@ out: zwp_primary_selection_device_manager_v1_destroy(term.wl.primary_selection_device_manager); if (term.wl.seat != NULL) wl_seat_destroy(term.wl.seat); - if (term.wl.surface != NULL) - wl_surface_destroy(term.wl.surface); + if (term.wl.search_sub_surface != NULL) + wl_subsurface_destroy(term.wl.search_sub_surface); + if (term.wl.search_surface != NULL) + wl_surface_destroy(term.wl.search_surface); + if (term.render.frame_callback != NULL) + wl_callback_destroy(term.render.frame_callback); + if (term.wl.xdg_toplevel != NULL) + xdg_toplevel_destroy(term.wl.xdg_toplevel); + if (term.wl.xdg_surface != NULL) + xdg_surface_destroy(term.wl.xdg_surface); if (term.wl.shell != NULL) xdg_wm_base_destroy(term.wl.shell); + if (term.wl.surface != NULL) + wl_surface_destroy(term.wl.surface); if (term.wl.shm != NULL) wl_shm_destroy(term.wl.shm); if (term.wl.compositor != NULL) diff --git a/search.c b/search.c index 558f98c7..150bd050 100644 --- a/search.c +++ b/search.c @@ -15,8 +15,6 @@ #define max(x, y) ((x) > (y) ? (x) : (y)) -static struct wl_surface *wl_surf; -static struct wl_subsurface *sub_surf; static inline pixman_color_t @@ -42,7 +40,7 @@ color_hex_to_pixman(uint32_t color) static void render(struct terminal *term) { - assert(sub_surf != NULL); + assert(term->wl.search_sub_surface != NULL); /* TODO: at least sway allows the subsurface to extend outside the * main window. Do we want that? */ @@ -84,24 +82,25 @@ render(struct terminal *term) LOG_INFO("match length: %zu", term->search.match_len); wl_subsurface_set_position( - sub_surf, term->width - width - margin, term->height - height - margin); + term->wl.search_sub_surface, + term->width - width - margin, term->height - height - margin); - wl_surface_damage_buffer(wl_surf, 0, 0, width, height); - wl_surface_attach(wl_surf, buf->wl_buf, 0, 0); - wl_surface_set_buffer_scale(wl_surf, scale); - wl_surface_commit(wl_surf); + wl_surface_damage_buffer(term->wl.search_surface, 0, 0, width, height); + wl_surface_attach(term->wl.search_surface, buf->wl_buf, 0, 0); + wl_surface_set_buffer_scale(term->wl.search_surface, scale); + wl_surface_commit(term->wl.search_surface); } static void search_cancel_keep_selection(struct terminal *term) { - if (sub_surf != NULL) { - wl_subsurface_destroy(sub_surf); - sub_surf = NULL; + if (term->wl.search_sub_surface != NULL) { + wl_subsurface_destroy(term->wl.search_sub_surface); + term->wl.search_sub_surface = NULL; } - if (wl_surf != NULL) { - wl_surface_destroy(wl_surf); - wl_surf = NULL; + if (term->wl.search_surface != NULL) { + wl_surface_destroy(term->wl.search_surface); + term->wl.search_surface = NULL; } free(term->search.buf); @@ -127,23 +126,23 @@ search_begin(struct terminal *term) term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; - wl_surf = wl_compositor_create_surface(term->wl.compositor); - if (wl_surf != NULL) { - sub_surf = wl_subcompositor_get_subsurface( - term->wl.sub_compositor, wl_surf, term->wl.surface); + term->wl.search_surface = wl_compositor_create_surface(term->wl.compositor); + if (term->wl.search_surface != NULL) { + term->wl.search_sub_surface = wl_subcompositor_get_subsurface( + term->wl.sub_compositor, term->wl.search_surface, term->wl.surface); - if (sub_surf != NULL) { + if (term->wl.search_sub_surface != NULL) { /* Sub-surface updates may occur without updating the main * window */ - wl_subsurface_set_desync(sub_surf); + wl_subsurface_set_desync(term->wl.search_sub_surface); } } - if (wl_surf == NULL || sub_surf == NULL) { + if (term->wl.search_surface == NULL || term->wl.search_sub_surface == NULL) { LOG_ERR("failed to create sub-surface for search box"); - if (wl_surf != NULL) - wl_surface_destroy(wl_surf); - assert(sub_surf == NULL); + if (term->wl.search_surface != NULL) + wl_surface_destroy(term->wl.search_surface); + assert(term->wl.search_sub_surface == NULL); } render(term); diff --git a/terminal.h b/terminal.h index 755c7b4a..948a8f11 100644 --- a/terminal.h +++ b/terminal.h @@ -42,15 +42,19 @@ struct wayland { struct wl_registry *registry; struct wl_compositor *compositor; struct wl_subcompositor *sub_compositor; - struct wl_surface *surface; struct wl_shm *shm; + struct wl_seat *seat; + struct wl_keyboard *keyboard; struct zxdg_output_manager_v1 *xdg_output_manager; + + /* Clipboard */ struct wl_data_device_manager *data_device_manager; struct wl_data_device *data_device; struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; struct zwp_primary_selection_device_v1 *primary_selection_device; - struct wl_keyboard *keyboard; + + /* Cursor */ struct { struct wl_pointer *pointer; uint32_t serial; @@ -61,9 +65,17 @@ struct wayland { int size; char *theme_name; } pointer; + + /* Main window */ + struct wl_surface *surface; struct xdg_wm_base *shell; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; + + /* Scrollback search */ + struct wl_surface *search_surface; + struct wl_subsurface *search_sub_surface; + bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */ -- cgit v1.3 From af8682210ec7b4f89f4d6a52fb568da9a4523d71 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 20:17:53 +0200 Subject: main: destroy sub-compositor at exit --- main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index e92996ef..18e2a19a 100644 --- a/main.c +++ b/main.c @@ -1064,6 +1064,8 @@ out: wl_surface_destroy(term.wl.surface); if (term.wl.shm != NULL) wl_shm_destroy(term.wl.shm); + if (term.wl.sub_compositor != NULL) + wl_subcompositor_destroy(term.wl.sub_compositor); if (term.wl.compositor != NULL) wl_compositor_destroy(term.wl.compositor); if (term.wl.registry != NULL) -- cgit v1.3 From 1e4b11b0fa73d4fa9e4f124fa04173f92f645d1f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 20:22:07 +0200 Subject: search: don't destroy/recreate search (sub)surface Create the sub-surface once, at startup. Then, instead of destroying it when committing/cancelling a search, unmap it (by attaching a NULL buffer to it). --- main.c | 7 +++++++ search.c | 29 ++--------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 18e2a19a..a076fb24 100644 --- a/main.c +++ b/main.c @@ -723,6 +723,7 @@ main(int argc, char *const *argv) goto out; } + /* Main window */ term.wl.surface = wl_compositor_create_surface(term.wl.compositor); if (term.wl.surface == NULL) { LOG_ERR("failed to create wayland surface"); @@ -740,6 +741,12 @@ main(int argc, char *const *argv) xdg_toplevel_set_app_id(term.wl.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); + /* Scrollback search box */ + term.wl.search_surface = wl_compositor_create_surface(term.wl.compositor); + term.wl.search_sub_surface = wl_subcompositor_get_subsurface( + term.wl.sub_compositor, term.wl.search_surface, term.wl.surface); + wl_subsurface_set_desync(term.wl.search_sub_surface); + wl_surface_commit(term.wl.surface); wl_display_roundtrip(term.wl.display); diff --git a/search.c b/search.c index 81bdf8f3..051a32db 100644 --- a/search.c +++ b/search.c @@ -18,14 +18,8 @@ static void search_cancel_keep_selection(struct terminal *term) { - if (term->wl.search_sub_surface != NULL) { - wl_subsurface_destroy(term->wl.search_sub_surface); - term->wl.search_sub_surface = NULL; - } - if (term->wl.search_surface != NULL) { - wl_surface_destroy(term->wl.search_surface); - term->wl.search_surface = NULL; - } + wl_surface_attach(term->wl.search_surface, NULL, 0, 0); + wl_surface_commit(term->wl.search_surface); free(term->search.buf); term->search.buf = NULL; @@ -50,25 +44,6 @@ search_begin(struct terminal *term) term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; - term->wl.search_surface = wl_compositor_create_surface(term->wl.compositor); - if (term->wl.search_surface != NULL) { - term->wl.search_sub_surface = wl_subcompositor_get_subsurface( - term->wl.sub_compositor, term->wl.search_surface, term->wl.surface); - - if (term->wl.search_sub_surface != NULL) { - /* Sub-surface updates may occur without updating the main - * window */ - wl_subsurface_set_desync(term->wl.search_sub_surface); - } - } - - if (term->wl.search_surface == NULL || term->wl.search_sub_surface == NULL) { - LOG_ERR("failed to create sub-surface for search box"); - if (term->wl.search_surface != NULL) - wl_surface_destroy(term->wl.search_surface); - assert(term->wl.search_sub_surface == NULL); - } - render_search_box(term); render_refresh(term); } -- cgit v1.3 From 47da5b4086d2081737ec2264f7b5b754c0166a3a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 30 Aug 2019 17:55:45 +0200 Subject: main: request server-side decorations --- main.c | 41 +++++++++++++++++++++++++++++++++++++++++ meson.build | 1 + terminal.h | 3 +++ 3 files changed, 45 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index a076fb24..c9a7b64c 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include #include +#include #define LOG_MODULE "main" #define LOG_ENABLE_DBG 0 @@ -215,6 +216,10 @@ handle_global(void *data, struct wl_registry *registry, xdg_wm_base_add_listener(term->wl.shell, &xdg_wm_base_listener, term); } + else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) + term->wl.xdg_decoration_manager = wl_registry_bind( + term->wl.registry, name, &zxdg_decoration_manager_v1_interface, 1); + else if (strcmp(interface, wl_seat_interface.name) == 0) { term->wl.seat = wl_registry_bind( term->wl.registry, name, &wl_seat_interface, 5); @@ -340,6 +345,30 @@ static const struct xdg_surface_listener xdg_surface_listener = { .configure = &xdg_surface_configure, }; +static void +xdg_toplevel_decoration_configure(void *data, + struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, + uint32_t mode) +{ + switch (mode) { + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: + LOG_ERR("unimplemented: client-side decorations"); + break; + + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: + LOG_DBG("using server-side decorations"); + break; + + default: + LOG_ERR("unimplemented: unknown XDG toplevel decoration mode: %u", mode); + break; + } +} + +static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = { + .configure = &xdg_toplevel_decoration_configure, +}; + static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { @@ -741,6 +770,14 @@ main(int argc, char *const *argv) xdg_toplevel_set_app_id(term.wl.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); + /* Request server-side decorations */ + term.wl.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( + term.wl.xdg_decoration_manager, term.wl.xdg_toplevel); + zxdg_toplevel_decoration_v1_set_mode( + term.wl.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + zxdg_toplevel_decoration_v1_add_listener( + term.wl.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term); + /* Scrollback search box */ term.wl.search_surface = wl_compositor_create_surface(term.wl.compositor); term.wl.search_sub_surface = wl_subcompositor_get_subsurface( @@ -1061,6 +1098,10 @@ out: wl_surface_destroy(term.wl.search_surface); if (term.render.frame_callback != NULL) wl_callback_destroy(term.render.frame_callback); + if (term.wl.xdg_toplevel_decoration != NULL) + zxdg_toplevel_decoration_v1_destroy(term.wl.xdg_toplevel_decoration); + if (term.wl.xdg_decoration_manager != NULL) + zxdg_decoration_manager_v1_destroy(term.wl.xdg_decoration_manager); if (term.wl.xdg_toplevel != NULL) xdg_toplevel_destroy(term.wl.xdg_toplevel); if (term.wl.xdg_surface != NULL) diff --git a/meson.build b/meson.build index 01a85cc8..632da62d 100644 --- a/meson.build +++ b/meson.build @@ -60,6 +60,7 @@ wl_proto_headers = [] wl_proto_src = [] foreach prot : [ wayland_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml', + wayland_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml', wayland_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml', wayland_protocols_datadir + '/unstable/primary-selection/primary-selection-unstable-v1.xml', ] diff --git a/terminal.h b/terminal.h index d81ff76d..f5eabad1 100644 --- a/terminal.h +++ b/terminal.h @@ -72,6 +72,9 @@ struct wayland { struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; + struct zxdg_decoration_manager_v1 *xdg_decoration_manager; + struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; + /* Scrollback search */ struct wl_surface *search_surface; struct wl_subsurface *search_sub_surface; -- cgit v1.3 From fb018eb64e78fd62cadbb42c26d5244ae0f8bb5f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 30 Aug 2019 17:56:23 +0200 Subject: main: render_resize() scales the width and height Thus, when we call render_resize() with *old* with/height values, we must scale them back to their original values. This fixes an issue where, for example, moving a window between outputs with different scales caused the window to keep growing. --- main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c9a7b64c..b6c90fe6 100644 --- a/main.c +++ b/main.c @@ -130,8 +130,10 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct monitor *mon = data; mon->scale = factor; + + int old_scale = mon->term->scale >= 1 ? mon->term->scale : 1; render_reload_cursor_theme(mon->term); - render_resize(mon->term, mon->term->width, mon->term->height); + render_resize(mon->term, mon->term->width / old_scale, mon->term->height / old_scale); } static const struct wl_output_listener output_listener = { @@ -271,8 +273,9 @@ surface_enter(void *data, struct wl_surface *wl_surface, tll_push_back(term->wl.on_outputs, &it->item); /* Resize, since scale-to-use may have changed */ + int scale = term->scale >= 1 ? term->scale : 1; render_reload_cursor_theme(term); - render_resize(term, term->width, term->height); + render_resize(term, term->width / scale, term->height / scale); return; } } @@ -293,8 +296,9 @@ surface_leave(void *data, struct wl_surface *wl_surface, tll_remove(term->wl.on_outputs, it); /* Resize, since scale-to-use may have changed */ + int scale = term->scale >= 1 ? term->scale : 1; render_reload_cursor_theme(term); - render_resize(term, term->width, term->height); + render_resize(term, term->width / scale, term->height / scale); return; } -- cgit v1.3 From 9f7ea6292e0fc114c5a3f8b5d0a77cb23f61ce89 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 30 Aug 2019 17:57:46 +0200 Subject: main: use a timer FD to delay render refresh after client data This ensures we never wait *longer* than 1ms (previously, we could end up doing multiple polls, each with a timeout value of 1ms - thereby potentially delaying the refresh indefinitely). --- main.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b6c90fe6..afa213cb 100644 --- a/main.c +++ b/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -888,8 +889,9 @@ main(int argc, char *const *argv) } } + bool timeout_is_armed = false; + int timeout_fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC); - int timeout_ms = -1; while (true) { struct pollfd fds[] = { {.fd = wl_display_get_fd(term.wl.display), .events = POLLIN}, @@ -897,10 +899,11 @@ main(int argc, char *const *argv) {.fd = term.kbd.repeat.fd, .events = POLLIN}, {.fd = term.flash.fd, .events = POLLIN}, {.fd = term.blink.fd, .events = POLLIN}, + {.fd = timeout_fd, .events = POLLIN}, }; wl_display_flush(term.wl.display); - int pret = poll(fds, sizeof(fds) / sizeof(fds[0]), timeout_ms); + int pret = poll(fds, sizeof(fds) / sizeof(fds[0]), -1); if (pret == -1) { if (errno == EINTR) @@ -910,13 +913,19 @@ main(int argc, char *const *argv) break; } - if (pret == 0 || (timeout_ms != -1 && !(fds[1].revents & POLLIN))) { - /* Delayed rendering */ - render_refresh(&term); - } + if (fds[5].revents & POLLIN) { + assert(timeout_is_armed); + + uint64_t unused; + ssize_t ret = read(timeout_fd, &unused, sizeof(unused)); - /* Reset poll timeout to infinity */ - timeout_ms = -1; + if (ret < 0 && errno != EAGAIN) + LOG_ERRNO("failed to read timeout timer"); + else if (ret > 0) { + timeout_is_armed = false; + render_refresh(&term); + } + } if (fds[0].revents & POLLIN) { wl_display_dispatch(term.wl.display); @@ -968,7 +977,10 @@ main(int argc, char *const *argv) * ourselves we just received keyboard input, and in * this case *not* delay rendering? */ - timeout_ms = 1; + if (!timeout_is_armed) { + timerfd_settime(timeout_fd, 0, &(struct itimerspec){.it_value = {.tv_nsec = 1000000}}, NULL); + timeout_is_armed = true; + } } } @@ -1039,9 +1051,10 @@ main(int argc, char *const *argv) render_refresh(&term); } } - } + close(timeout_fd); + out: mtx_lock(&term.render.workers.lock); assert(tll_length(term.render.workers.queue) == 0); -- cgit v1.3