From 8368e8184ff94a9107d16a62fc3726c584e454d9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 23 Feb 2020 14:17:48 +0100 Subject: csd: wip: something to get started... --- render.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 346b5351..c7d702b8 100644 --- a/render.c +++ b/render.c @@ -38,6 +38,10 @@ static struct { static void fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data); +#define shm_cookie_grid(term) ((unsigned long)((uintptr_t)term + 0)) +#define shm_cookie_search(term) ((unsigned long)((uintptr_t)term + 1)) +#define shm_cookie_csd(term, n) ((unsigned long)((uintptr_t)term + 2 + (n))) + struct renderer * render_init(struct fdm *fdm, struct wayland *wayl) { @@ -655,6 +659,45 @@ render_worker_thread(void *_ctx) return -1; } +static void +render_csd(struct terminal *term) +{ + LOG_INFO("rendering CSD"); + + const int border_width = 2 * term->scale; + const int title_height = 20 * term->scale; + + const int geom[5][4] = { + {-border_width, -title_height, term->width + 2 * border_width, title_height}, + }; + + for (size_t i = 0; i < 1; i++) { + const int x = geom[i][0]; + const int y = geom[i][1]; + const int width = geom[i][2]; + const int height = geom[i][3]; + + unsigned long cookie = shm_cookie_csd(term, 0); + struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); + + pixman_color_t color = color_hex_to_pixman(0xffffff); + pixman_image_t *src = pixman_image_create_solid_fill(&color); + + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, 1, + &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); + pixman_image_unref(src); + + wl_subsurface_set_position( + term->window->csd.sub_surface[i], x, y); + + wl_surface_attach(term->window->csd.surface[i], buf->wl_buf, 0, 0); + wl_surface_damage_buffer(term->window->csd.surface[i], 0, 0, buf->width, buf->height); + wl_surface_set_buffer_scale(term->window->csd.surface[i], term->scale); + wl_surface_commit(term->window->csd.surface[i]); + } +} + static void frame_callback( void *data, struct wl_callback *wl_callback, uint32_t callback_data); @@ -675,10 +718,13 @@ grid_render(struct terminal *term) gettimeofday(&start_time, NULL); #endif + if (term->window->use_csd) + render_csd(term); + assert(term->width > 0); assert(term->height > 0); - unsigned long cookie = (uintptr_t)term; + unsigned long cookie = shm_cookie_grid(term); struct buffer *buf = shm_get_buffer( term->wl->shm, term->width, term->height, cookie); @@ -990,7 +1036,7 @@ render_search_box(struct terminal *term) const size_t visible_chars = (width - 2 * margin) / term->cell_width; size_t glyph_offset = term->render.search_glyph_offset; - unsigned long cookie = (uintptr_t)term + 1; + unsigned long cookie = shm_cookie_search(term); struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); /* Background - yellow on empty/match, red on mismatch */ -- cgit v1.3 From 2798807853d14104e3a72e1d7d682c085fd84724 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 22:06:20 +0100 Subject: render: csd: render all borders and the title bar * Still no content in the title bar * Colors are temporary * No resize/drag yet --- render.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 0e019431..3e7f57b1 100644 --- a/render.c +++ b/render.c @@ -668,10 +668,14 @@ render_csd(struct terminal *term) const int title_height = 20 * term->scale; const int geom[5][4] = { - {-border_width, -title_height, term->width + 2 * border_width, title_height}, + {0, -title_height, term->width, title_height}, + {-border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, + {-border_width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, + {term->width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, + {-border_width, term->height, term->width + 2 * border_width, border_width}, }; - for (size_t i = 0; i < 1; i++) { + for (size_t i = 0; i < 5; i++) { const int x = geom[i][0]; const int y = geom[i][1]; const int width = geom[i][2]; @@ -680,7 +684,7 @@ render_csd(struct terminal *term) unsigned long cookie = shm_cookie_csd(term, 0); struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); - pixman_color_t color = color_hex_to_pixman(0xffffff); + pixman_color_t color = color_hex_to_pixman(i == 0 ? 0xffffff : 0xff0000); pixman_image_t *src = pixman_image_create_solid_fill(&color); pixman_image_fill_rectangles( -- cgit v1.3 From 0b265cc9a5f222769e0a4e80bc360380501694bc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 22:40:02 +0100 Subject: render: csd: sort geometry entries --- render.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 3e7f57b1..bc054046 100644 --- a/render.c +++ b/render.c @@ -664,15 +664,15 @@ render_csd(struct terminal *term) { LOG_INFO("rendering CSD"); - const int border_width = 2 * term->scale; + const int border_width = 1 * term->scale; const int title_height = 20 * term->scale; const int geom[5][4] = { {0, -title_height, term->width, title_height}, - {-border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, - {-border_width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, - {term->width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, - {-border_width, term->height, term->width + 2 * border_width, border_width}, + {-border_width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, /* left */ + {term->width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, /* right */ + {-border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, /* top */ + {-border_width, term->height, term->width + 2 * border_width, border_width}, /* bottom */ }; for (size_t i = 0; i < 5; i++) { -- cgit v1.3 From d15eb936ef2ee533cde2596b4c9b9f09cdb03973 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 19:08:14 +0100 Subject: render: make CSD border and title size globally accessible --- render.c | 3 +++ wayland.h | 3 +++ 2 files changed, 6 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index bc054046..845bc0f1 100644 --- a/render.c +++ b/render.c @@ -24,6 +24,9 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) +const int csd_border_size = 5; +const int csd_title_size = 20; + struct renderer { struct fdm *fdm; struct wayland *wayl; diff --git a/wayland.h b/wayland.h index 7de13850..243df207 100644 --- a/wayland.h +++ b/wayland.h @@ -82,6 +82,9 @@ struct wl_primary { uint32_t serial; }; +extern const int csd_border_size; +extern const int csd_title_size; + struct wayland; struct wl_window { struct terminal *term; -- cgit v1.3 From 70ce7245c6fc4b1e19b03acf7b53400a81523258 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 19:09:29 +0100 Subject: render: export render_csd() --- render.c | 51 +++++++++++++++++++++++++++++++++------------------ render.h | 1 + 2 files changed, 34 insertions(+), 18 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 845bc0f1..dc01f45b 100644 --- a/render.c +++ b/render.c @@ -662,32 +662,44 @@ render_worker_thread(void *_ctx) return -1; } -static void +void render_csd(struct terminal *term) { - LOG_INFO("rendering CSD"); + if (!term->window->use_csd) + return; - const int border_width = 1 * term->scale; - const int title_height = 20 * term->scale; + const int border_width = csd_border_size * term->scale; + const int title_height = csd_title_size * term->scale; const int geom[5][4] = { - {0, -title_height, term->width, title_height}, - {-border_width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, /* left */ - {term->width, -title_height - border_width, border_width, term->height + title_height + 2 * border_width}, /* right */ - {-border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, /* top */ - {-border_width, term->height, term->width + 2 * border_width, border_width}, /* bottom */ + /* X, Y, WIDTH, HEIGHT */ + { border_width, border_width, term->width - 2 * border_width, title_height}, /* title */ + { 0, border_width, border_width, term->height - 2 * border_width}, /* left */ + {term->width - border_width, border_width, border_width, term->height - 2 * border_width}, /* right */ + { 0, 0, term->width, border_width}, /* top */ + { 0, term->height - border_width, term->width, border_width}, /* bottom */ }; - for (size_t i = 0; i < 5; i++) { + struct wl_region *region = wl_compositor_create_region(term->wl->compositor); + if (region != NULL) + wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); + + for (size_t i = 0; i < sizeof(geom) / sizeof(geom[0]); i++) { + struct wl_surface *surf = term->window->csd.surface[i]; + struct wl_subsurface *sub = term->window->csd.sub_surface[i]; + const int x = geom[i][0]; const int y = geom[i][1]; const int width = geom[i][2]; const int height = geom[i][3]; - unsigned long cookie = shm_cookie_csd(term, 0); + unsigned long cookie = shm_cookie_csd(term, i); struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); - pixman_color_t color = color_hex_to_pixman(i == 0 ? 0xffffff : 0xff0000); + pixman_color_t color = color_hex_to_pixman(term->colors.fg); + if (!term->visual_focus) + pixman_color_dim(&color); + pixman_image_t *src = pixman_image_create_solid_fill(&color); pixman_image_fill_rectangles( @@ -695,14 +707,17 @@ render_csd(struct terminal *term) &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); pixman_image_unref(src); - wl_subsurface_set_position( - term->window->csd.sub_surface[i], x, y); + wl_subsurface_set_position(sub, x, y); - wl_surface_attach(term->window->csd.surface[i], buf->wl_buf, 0, 0); - wl_surface_damage_buffer(term->window->csd.surface[i], 0, 0, buf->width, buf->height); - wl_surface_set_buffer_scale(term->window->csd.surface[i], term->scale); - wl_surface_commit(term->window->csd.surface[i]); + wl_surface_attach(surf, buf->wl_buf, 0, 0); + wl_surface_set_opaque_region(surf, region); + wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); + wl_surface_set_buffer_scale(surf, term->scale); + wl_surface_commit(surf); } + + if (region != NULL) + wl_region_destroy(region); } static void frame_callback( diff --git a/render.h b/render.h index 3bd52fa5..9c96aa24 100644 --- a/render.h +++ b/render.h @@ -16,6 +16,7 @@ void render_refresh(struct terminal *term); bool render_xcursor_set(struct terminal *term); void render_search_box(struct terminal *term); +void render_csd(struct terminal *term); struct render_worker_context { int my_id; -- cgit v1.3 From d3c7d25dae3124fec14574cb8379411b17e28ae2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 19:09:49 +0100 Subject: render: call render_csd() from render_resize(), not render_grid() The CSDs doesn't need to be re-drawn each time we redraw the grid, only when the window is resized. --- render.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index dc01f45b..95391bb8 100644 --- a/render.c +++ b/render.c @@ -740,9 +740,6 @@ grid_render(struct terminal *term) gettimeofday(&start_time, NULL); #endif - if (term->window->use_csd) - render_csd(term); - assert(term->width > 0); assert(term->height > 0); @@ -1244,6 +1241,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) damage_view: tll_free(term->normal.scroll_damage); tll_free(term->alt.scroll_damage); + render_csd(term); term->render.last_buf = NULL; term_damage_view(term); render_refresh(term); -- cgit v1.3 From 7db9221aa925ba2995e315e7d3fa76247b56c51d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 19:10:48 +0100 Subject: render: render_resize(): don't allow too small window sizes --- render.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 95391bb8..29a47cfc 100644 --- a/render.c +++ b/render.c @@ -1139,6 +1139,27 @@ maybe_resize(struct terminal *term, int width, int height, bool force) return; } + /* Scaled CSD border + title bar sizes */ + const int csd_border = term->window->use_csd ? csd_border_size * scale : 0; + const int csd_title = term->window->use_csd ? csd_title_size * scale : 0; + const int csd_x = 2 * csd_border; + const int csd_y = 2 * csd_border + csd_title; + + /* Padding */ + const int pad_x = scale * term->conf->pad_x; + const int pad_y = scale * term->conf->pad_y; + + /* Don't shrink grid too much */ + const int min_cols = 20; + const int min_rows = 4; + + /* Minimum window size */ + const int min_width = csd_x + 2 * pad_x + min_cols * term->cell_width; + const int min_height = csd_y + 2 * pad_y + min_rows * term->cell_height; + + width = max(width, min_width); + height = max(height, min_height); + if (!force && width == term->width && height == term->height && scale == term->scale) return; @@ -1157,13 +1178,9 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int old_cols = term->cols; const int old_rows = term->rows; - /* Padding */ - const int pad_x = term->width > 2 * scale * term->conf->pad_x ? scale * term->conf->pad_x : 0; - const int pad_y = term->height > 2 * scale * term->conf->pad_y ? scale * term->conf->pad_y : 0; - /* Screen rows/cols after resize */ - const int new_cols = max((term->width - 2 * pad_x) / term->cell_width, 1); - const int new_rows = max((term->height - 2 * pad_y) / term->cell_height, 1); + const int new_cols = (term->width - 2 * pad_x - csd_x) / term->cell_width; + const int new_rows = (term->height - 2 * pad_y - csd_y) / term->cell_height; /* Grid rows/cols after resize */ const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1)); @@ -1173,11 +1190,16 @@ maybe_resize(struct terminal *term, int width, int height, bool force) assert(new_rows >= 1); /* Margins */ - term->margins.left = (term->width - new_cols * term->cell_width) / 2; - term->margins.top = (term->height - new_rows * term->cell_height) / 2; + term->margins.left = csd_border + (term->width - csd_x - new_cols * term->cell_width) / 2; + term->margins.top = csd_border + csd_title + (term->height - csd_y - new_rows * term->cell_height) / 2; term->margins.right = term->width - new_cols * term->cell_width - term->margins.left; term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top; + assert(term->margins.left >= csd_border + pad_x); + assert(term->margins.right >= csd_border + pad_x); + assert(term->margins.top >= csd_border + csd_title + pad_y); + assert(term->margins.bottom >= csd_border + pad_y); + if (new_cols == old_cols && new_rows == old_rows) { LOG_DBG("grid layout unaffected; skipping reflow"); goto damage_view; @@ -1239,6 +1261,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->render.last_cursor.cell = NULL; damage_view: + xdg_toplevel_set_min_size(term->window->xdg_toplevel, min_width / scale, min_height / scale); tll_free(term->normal.scroll_damage); tll_free(term->alt.scroll_damage); render_csd(term); -- cgit v1.3 From 595b32ddf99d40fa5c51f7b3e0696a27cc6adb28 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 19:51:03 +0100 Subject: render: render_resize_*() returns a boolean indicating whether size changed. --- render.c | 16 +++++++++------- render.h | 5 +++-- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 29a47cfc..460ffd74 100644 --- a/render.c +++ b/render.c @@ -1114,11 +1114,11 @@ render_search_box(struct terminal *term) } /* Move to terminal.c? */ -static void +static bool maybe_resize(struct terminal *term, int width, int height, bool force) { if (!force && (width == 0 || height == 0)) - return; + return false; int scale = -1; tll_foreach(term->window->on_outputs, it) { @@ -1136,7 +1136,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) if (!force && width == 0 && height == 0) { /* Assume we're not fully up and running yet */ - return; + return false; } /* Scaled CSD border + title bar sizes */ @@ -1161,7 +1161,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) height = max(height, min_height); if (!force && width == term->width && height == term->height && scale == term->scale) - return; + return false; selection_cancel(term); @@ -1261,22 +1261,24 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->render.last_cursor.cell = NULL; damage_view: - xdg_toplevel_set_min_size(term->window->xdg_toplevel, min_width / scale, min_height / scale); + xdg_toplevel_set_min_size( + term->window->xdg_toplevel, min_width / scale, min_height / scale); tll_free(term->normal.scroll_damage); tll_free(term->alt.scroll_damage); render_csd(term); term->render.last_buf = NULL; term_damage_view(term); render_refresh(term); + return true; } -void +bool render_resize(struct terminal *term, int width, int height) { return maybe_resize(term, width, height, false); } -void +bool render_resize_force(struct terminal *term, int width, int height) { return maybe_resize(term, width, height, true); diff --git a/render.h b/render.h index 9c96aa24..8602d367 100644 --- a/render.h +++ b/render.h @@ -1,4 +1,5 @@ #pragma once +#include #include "terminal.h" #include "fdm.h" @@ -8,8 +9,8 @@ struct renderer; struct renderer *render_init(struct fdm *fdm, struct wayland *wayl); void render_destroy(struct renderer *renderer); -void render_resize(struct terminal *term, int width, int height); -void render_resize_force(struct terminal *term, int width, int height); +bool render_resize(struct terminal *term, int width, int height); +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); -- cgit v1.3 From ef53729242596344f07b1e9329ffaad51252b0c3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 20:29:44 +0100 Subject: render: resize with with/height == 0 resizes to user configured dimensions --- render.c | 12 ++++++------ terminal.c | 17 ----------------- 2 files changed, 6 insertions(+), 23 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 460ffd74..54c9e993 100644 --- a/render.c +++ b/render.c @@ -1117,7 +1117,7 @@ render_search_box(struct terminal *term) static bool maybe_resize(struct terminal *term, int width, int height, bool force) { - if (!force && (width == 0 || height == 0)) + if (term->cell_width == 0 && term->cell_height == 0) return false; int scale = -1; @@ -1131,14 +1131,14 @@ maybe_resize(struct terminal *term, int width, int height, bool force) scale = 1; } + if (width == 0 && height == 0) { + width = term->conf->width; + height = term->conf->height; + } + width *= scale; height *= scale; - if (!force && width == 0 && height == 0) { - /* Assume we're not fully up and running yet */ - return false; - } - /* Scaled CSD border + title bar sizes */ const int csd_border = term->window->use_csd ? csd_border_size * scale : 0; const int csd_title = term->window->use_csd ? csd_title_size * scale : 0; diff --git a/terminal.c b/terminal.c index 000d95b3..9c90e37d 100644 --- a/terminal.c +++ b/terminal.c @@ -773,29 +773,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, term_set_window_title(term, "foot"); /* Load fonts */ -#if 0 - struct font *fonts[4]; - if (!load_fonts_from_conf(term, conf, fonts)) - goto err; - term_set_fonts(term, fonts); -#endif term_font_dpi_changed(term); /* Start the slave/client */ if ((term->slave = slave_spawn(term->ptmx, argc, term->cwd, argv, term_env, conf->shell, login_shell)) == -1) goto err; - if (term->width == 0 && term->height == 0) { - - /* Try to use user-configured window dimentions */ - unsigned width = conf->width; - unsigned height = conf->height; - - /* Don't go below a single cell */ - width = max(width, term->cell_width); - height = max(height, term->cell_height); - render_resize(term, width, height); - } return term; -- cgit v1.3 From cc3dad9599986a5b4b42cc8e6f99be8f018fc8d4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 20:30:45 +0100 Subject: render: search: take CSD into account --- render.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 54c9e993..91dac6a8 100644 --- a/render.c +++ b/render.c @@ -1040,8 +1040,11 @@ render_search_box(struct terminal *term) const size_t wanted_visible_chars = max(20, term->search.len); - const int scale = term->scale >= 1 ? term->scale : 1; - const size_t margin = scale * 3; + assert(term->scale >= 1); + const int scale = term->scale; + + const int csd = term->window->use_csd ? csd_border_size * scale : 0; + const size_t margin = csd + 3 * scale; const size_t width = min( term->width - 2 * margin, @@ -1102,14 +1105,15 @@ render_search_box(struct terminal *term) if (term->search.cursor >= term->search.len) draw_bar(term, buf->pix, font, &fg, x, y); + wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0); + wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height); + wl_surface_set_buffer_scale(term->window->search_surface, scale); + wl_subsurface_set_position( term->window->search_sub_surface, max(0, (int32_t)term->width - width - margin), max(0, (int32_t)term->height - height - margin)); - wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height); - wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0); - wl_surface_set_buffer_scale(term->window->search_surface, scale); wl_surface_commit(term->window->search_surface); } -- cgit v1.3 From 2f587f6f3d29c2dbfc6625e94144bf325263d090 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 12:17:58 +0100 Subject: csd: position CSD sub-surfaces *outside* the main window For now, this behavior is controlled with an ifdef. At least kwin seems very buggy when the decorations are positioned like this (but normally you'd use server-side decorations with kwin anyway). This commit also changes 'use_csd' to be a tri-state variable; when instantiating a window it is set to 'unknown'. If there's no decoration manager available (e.g. weston), we immediately set it to 'yes' (use CSDs). Otherwise, we wait for the decoration manager callback to indicate whether we should use CSDs or not. --- render.c | 113 +++++++++++++++++++++++++++++++++++++------------------------ terminal.c | 26 +++++++++----- wayland.c | 6 ++-- wayland.h | 3 +- 4 files changed, 91 insertions(+), 57 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 91dac6a8..598141ef 100644 --- a/render.c +++ b/render.c @@ -665,59 +665,74 @@ render_worker_thread(void *_ctx) void render_csd(struct terminal *term) { - if (!term->window->use_csd) - return; + switch (term->window->use_csd) { + case CSD_UNKNOWN: + case CSD_NO: + break; - const int border_width = csd_border_size * term->scale; - const int title_height = csd_title_size * term->scale; + case CSD_YES: { + const int border_width = csd_border_size * term->scale; + const int title_height = csd_title_size * term->scale; + + const int geom[5][4] = { + /* X, Y, WIDTH, HEIGHT */ +#if FOOT_CSD_OUTSIDE + { 0, -title_height, term->width, title_height}, /* title */ + { -border_width, -title_height, border_width, title_height + term->height}, /* left */ + { term->width, -title_height, border_width, title_height + term->height}, /* right */ + { -border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, /* top */ + { -border_width, term->height, term->width + 2 * border_width, border_width}, /* bottom */ +#else + { border_width, border_width, term->width - 2 * border_width, title_height}, /* title */ + { 0, border_width, border_width, term->height - 2 * border_width}, /* left */ + {term->width - border_width, border_width, border_width, term->height - 2 * border_width}, /* right */ + { 0, 0, term->width, border_width}, /* top */ + { 0, term->height - border_width, term->width, border_width}, /* bottom */ +#endif + }; - const int geom[5][4] = { - /* X, Y, WIDTH, HEIGHT */ - { border_width, border_width, term->width - 2 * border_width, title_height}, /* title */ - { 0, border_width, border_width, term->height - 2 * border_width}, /* left */ - {term->width - border_width, border_width, border_width, term->height - 2 * border_width}, /* right */ - { 0, 0, term->width, border_width}, /* top */ - { 0, term->height - border_width, term->width, border_width}, /* bottom */ - }; + struct wl_region *region = wl_compositor_create_region(term->wl->compositor); + if (region != NULL) + wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); - struct wl_region *region = wl_compositor_create_region(term->wl->compositor); - if (region != NULL) - wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); + for (size_t i = 0; i < sizeof(geom) / sizeof(geom[0]); i++) { + struct wl_surface *surf = term->window->csd.surface[i]; + struct wl_subsurface *sub = term->window->csd.sub_surface[i]; - for (size_t i = 0; i < sizeof(geom) / sizeof(geom[0]); i++) { - struct wl_surface *surf = term->window->csd.surface[i]; - struct wl_subsurface *sub = term->window->csd.sub_surface[i]; + const int x = geom[i][0]; + const int y = geom[i][1]; + const int width = geom[i][2]; + const int height = geom[i][3]; - const int x = geom[i][0]; - const int y = geom[i][1]; - const int width = geom[i][2]; - const int height = geom[i][3]; + unsigned long cookie = shm_cookie_csd(term, i); + struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); - unsigned long cookie = shm_cookie_csd(term, i); - struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); + pixman_color_t color = color_hex_to_pixman(term->colors.fg); + if (!term->visual_focus) + pixman_color_dim(&color); - pixman_color_t color = color_hex_to_pixman(term->colors.fg); - if (!term->visual_focus) - pixman_color_dim(&color); + pixman_image_t *src = pixman_image_create_solid_fill(&color); - pixman_image_t *src = pixman_image_create_solid_fill(&color); + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, 1, + &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); + pixman_image_unref(src); - pixman_image_fill_rectangles( - PIXMAN_OP_SRC, buf->pix, &color, 1, - &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); - pixman_image_unref(src); + wl_subsurface_set_position(sub, x, y); - wl_subsurface_set_position(sub, x, y); + wl_surface_attach(surf, buf->wl_buf, 0, 0); + wl_surface_set_opaque_region(surf, region); + wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); + wl_surface_set_buffer_scale(surf, term->scale); + wl_surface_commit(surf); + } - wl_surface_attach(surf, buf->wl_buf, 0, 0); - wl_surface_set_opaque_region(surf, region); - wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); - wl_surface_set_buffer_scale(surf, term->scale); - wl_surface_commit(surf); - } + if (region != NULL) + wl_region_destroy(region); - if (region != NULL) - wl_region_destroy(region); + break; + } + } } static void frame_callback( @@ -1043,7 +1058,11 @@ render_search_box(struct terminal *term) assert(term->scale >= 1); const int scale = term->scale; - const int csd = term->window->use_csd ? csd_border_size * scale : 0; +#if FOOT_CSD_OUTSIDE + const int csd = 0; +#else + const int csd = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; +#endif const size_t margin = csd + 3 * scale; const size_t width = min( @@ -1144,8 +1163,14 @@ maybe_resize(struct terminal *term, int width, int height, bool force) height *= scale; /* Scaled CSD border + title bar sizes */ - const int csd_border = term->window->use_csd ? csd_border_size * scale : 0; - const int csd_title = term->window->use_csd ? csd_title_size * scale : 0; +#if FOOT_CSD_OUTSIDE + const int csd_border = 0; + const int csd_title = 0; +#else + const int csd_border = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; + const int csd_title = term->window->use_csd == CSD_YES ? ? csd_title_size * scale : 0; +#endif + const int csd_x = 2 * csd_border; const int csd_y = 2 * csd_border + csd_title; diff --git a/terminal.c b/terminal.c index b568731c..fe8860ad 100644 --- a/terminal.c +++ b/terminal.c @@ -1633,14 +1633,18 @@ term_visual_focus_in(struct terminal *term) if (term->cursor_blink.active) cursor_blink_start_timer(term); -#if 1 - for (int i = 0; i < 5; i++) - wl_subsurface_set_desync(term->window->csd.sub_surface[i]); +#if 1 /* Weston seems to be buggy with synchronized CSDs */ + if (term->window->use_csd == CSD_YES) { + for (int i = 0; i < 5; i++) + wl_subsurface_set_desync(term->window->csd.sub_surface[i]); + } #endif render_csd(term); #if 1 - for (int i = 0; i < 5; i++) - wl_subsurface_set_sync(term->window->csd.sub_surface[i]); + if (term->window->use_csd == CSD_YES) { + for (int i = 0; i < 5; i++) + wl_subsurface_set_sync(term->window->csd.sub_surface[i]); + } #endif cursor_refresh(term); } @@ -1656,13 +1660,17 @@ term_visual_focus_out(struct terminal *term) cursor_blink_stop_timer(term); #if 1 - for (int i = 0; i < 5; i++) - wl_subsurface_set_desync(term->window->csd.sub_surface[i]); + if (term->window->use_csd == CSD_YES) { + for (int i = 0; i < 5; i++) + wl_subsurface_set_desync(term->window->csd.sub_surface[i]); + } #endif render_csd(term); #if 1 - for (int i = 0; i < 5; i++) - wl_subsurface_set_sync(term->window->csd.sub_surface[i]); + if (term->window->use_csd == CSD_YES) { + for (int i = 0; i < 5; i++) + wl_subsurface_set_sync(term->window->csd.sub_surface[i]); + } #endif cursor_refresh(term); } diff --git a/wayland.c b/wayland.c index 1987c72a..140c3de9 100644 --- a/wayland.c +++ b/wayland.c @@ -551,12 +551,12 @@ xdg_toplevel_decoration_configure(void *data, switch (mode) { case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: LOG_DBG("using client-side decorations"); - win->use_csd = true; + win->use_csd = CSD_YES; break; case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: LOG_DBG("using server-side decorations"); - win->use_csd = false; + win->use_csd = CSD_NO; break; default: @@ -902,7 +902,7 @@ wayl_win_init(struct terminal *term) struct wl_window *win = calloc(1, sizeof(*win)); win->term = term; - win->use_csd = true; + win->use_csd = CSD_UNKNOWN; win->surface = wl_compositor_create_surface(wayl->compositor); if (win->surface == NULL) { diff --git a/wayland.h b/wayland.h index 243df207..617e8185 100644 --- a/wayland.h +++ b/wayland.h @@ -82,6 +82,7 @@ struct wl_primary { uint32_t serial; }; +#define FOOT_CSD_OUTSIDE 1 extern const int csd_border_size; extern const int csd_title_size; @@ -94,7 +95,7 @@ struct wl_window { struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; - bool use_csd; + enum {CSD_UNKNOWN, CSD_NO, CSD_YES } use_csd; struct { struct wl_surface *surface[5]; -- cgit v1.3 From f960e7aff7193505b4dac8a993ebdae241097014 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 12:21:03 +0100 Subject: render: resize: ignore unconfigured windows --- render.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 598141ef..7d15a384 100644 --- a/render.c +++ b/render.c @@ -1140,6 +1140,9 @@ render_search_box(struct terminal *term) static bool maybe_resize(struct terminal *term, int width, int height, bool force) { + if (!term->window->is_configured) + return false; + if (term->cell_width == 0 && term->cell_height == 0) return false; -- cgit v1.3 From 1e1b2043777511aedcaccf784ebac12bdecd866e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 12:39:17 +0100 Subject: csd: don't draw CSDs in fullscreen mode --- render.c | 3 +++ wayland.c | 88 +++++++++++++++++++++++++++++++++------------------------------ wayland.h | 2 ++ 3 files changed, 51 insertions(+), 42 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 7d15a384..3920ec90 100644 --- a/render.c +++ b/render.c @@ -671,6 +671,9 @@ render_csd(struct terminal *term) break; case CSD_YES: { + if (term->window->is_fullscreen) + return; + const int border_width = csd_border_size * term->scale; const int title_height = csd_title_size * term->scale; diff --git a/wayland.c b/wayland.c index 9959081f..d875b3d7 100644 --- a/wayland.c +++ b/wayland.c @@ -36,6 +36,39 @@ static bool wayl_reload_cursor_theme( struct wayland *wayl, struct terminal *term); +static void +csd_instantiate(struct wl_window *win) +{ + struct wayland *wayl = win->term->wl; + assert(wayl != NULL); + + for (size_t i = 0; i < ALEN(win->csd.surface); i++) { + assert(win->csd.surface[i] == NULL); + assert(win->csd.sub_surface[i] == NULL); + + win->csd.surface[i] = wl_compositor_create_surface(wayl->compositor); + win->csd.sub_surface[i] = wl_subcompositor_get_subsurface( + wayl->sub_compositor, win->csd.surface[i], win->surface); + + wl_subsurface_set_sync(win->csd.sub_surface[i]); + wl_surface_commit(win->csd.surface[i]); + } +} + +static void +csd_destroy(struct wl_window *win) +{ + for (size_t i = 0; i < ALEN(win->csd.surface); i++) { + if (win->csd.sub_surface[i] != NULL) + wl_subsurface_destroy(win->csd.sub_surface[i]); + if (win->csd.surface[i] != NULL) + wl_surface_destroy(win->csd.surface[i]); + + win->csd.surface[i] = NULL; + win->csd.sub_surface[i] = NULL; + } +} + static void shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) { @@ -426,7 +459,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states) { bool is_activated = false; - bool is_resizing = false; + bool is_fullscreen = false; #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG char state_str[2048]; @@ -447,16 +480,11 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, enum xdg_toplevel_state *state; wl_array_for_each(state, states) { switch (*state) { - case XDG_TOPLEVEL_STATE_ACTIVATED: - is_activated = true; - break; + case XDG_TOPLEVEL_STATE_ACTIVATED: is_activated = true; break; + case XDG_TOPLEVEL_STATE_FULLSCREEN: is_fullscreen = true; break; case XDG_TOPLEVEL_STATE_RESIZING: - is_resizing = true; - break; - case XDG_TOPLEVEL_STATE_MAXIMIZED: - case XDG_TOPLEVEL_STATE_FULLSCREEN: case XDG_TOPLEVEL_STATE_TILED_LEFT: case XDG_TOPLEVEL_STATE_TILED_RIGHT: case XDG_TOPLEVEL_STATE_TILED_TOP: @@ -495,7 +523,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, */ struct wl_window *win = data; - if (win->use_csd == CSD_YES && width != 0 && height != 0) { + if (!is_fullscreen && win->use_csd == CSD_YES && width != 0 && height != 0) { /* * The size received here is the *total* window size. * @@ -509,6 +537,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, } win->configure.is_activated = is_activated; + win->configure.is_fullscreen = is_fullscreen; win->configure.width = width; win->configure.height = height; } @@ -538,6 +567,14 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, win->is_configured = true; + if (win->is_fullscreen != win->configure.is_fullscreen && win->use_csd == CSD_YES) { + if (win->configure.is_fullscreen) + csd_destroy(win); + else + csd_instantiate(win); + win->is_fullscreen = win->configure.is_fullscreen; + } + xdg_surface_ack_configure(xdg_surface, serial); bool resized = render_resize(term, win->configure.width, win->configure.height); @@ -560,39 +597,6 @@ static const struct xdg_surface_listener xdg_surface_listener = { .configure = &xdg_surface_configure, }; -static void -csd_instantiate(struct wl_window *win) -{ - struct wayland *wayl = win->term->wl; - assert(wayl != NULL); - - for (size_t i = 0; i < ALEN(win->csd.surface); i++) { - assert(win->csd.surface[i] == NULL); - assert(win->csd.sub_surface[i] == NULL); - - win->csd.surface[i] = wl_compositor_create_surface(wayl->compositor); - win->csd.sub_surface[i] = wl_subcompositor_get_subsurface( - wayl->sub_compositor, win->csd.surface[i], win->surface); - - wl_subsurface_set_sync(win->csd.sub_surface[i]); - wl_surface_commit(win->csd.surface[i]); - } -} - -static void -csd_destroy(struct wl_window *win) -{ - for (size_t i = 0; i < ALEN(win->csd.surface); i++) { - if (win->csd.sub_surface[i] != NULL) - wl_subsurface_destroy(win->csd.sub_surface[i]); - if (win->csd.surface[i] != NULL) - wl_surface_destroy(win->csd.surface[i]); - - win->csd.surface[i] = NULL; - win->csd.sub_surface[i] = NULL; - } -} - static void xdg_toplevel_decoration_configure(void *data, struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, diff --git a/wayland.h b/wayland.h index 617e8185..f7961552 100644 --- a/wayland.h +++ b/wayland.h @@ -111,8 +111,10 @@ struct wl_window { tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */ bool is_configured; + bool is_fullscreen; struct { bool is_activated; + bool is_fullscreen; int width; int height; } configure; -- cgit v1.3 From 90efe6ec025060ea44fc3b888b4745befe410dbb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 12:51:58 +0100 Subject: render: don't center grid on surface Up until now, we've centered the grid on the main surface. Meaning, we calculated the unusable area, added the user configured padding and then centered the grid. This may look nice at first, but doesn't anymore when you start resizing the window. Resizing the window will cause the top+left margins to change, which makes the text "jump" or "wobble". So, now we fix the grid in the upper left corner defined by the user configured padding (plus CSDs if they aren't positioned outside the main surface). --- render.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 3920ec90..5706457a 100644 --- a/render.c +++ b/render.c @@ -1225,8 +1225,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) assert(new_rows >= 1); /* Margins */ - term->margins.left = csd_border + (term->width - csd_x - new_cols * term->cell_width) / 2; - term->margins.top = csd_border + csd_title + (term->height - csd_y - new_rows * term->cell_height) / 2; + term->margins.left = csd_border + pad_x; + term->margins.top = csd_border + csd_title + pad_y; term->margins.right = term->width - new_cols * term->cell_width - term->margins.left; term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top; -- cgit v1.3 From 6eece79218241acbddfdd8c3473aec7d10e302df Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 13:22:20 +0100 Subject: render: csd: fix typo when CSDs are positioned *inside* main surface --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 5706457a..6f71ae30 100644 --- a/render.c +++ b/render.c @@ -1174,7 +1174,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int csd_title = 0; #else const int csd_border = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; - const int csd_title = term->window->use_csd == CSD_YES ? ? csd_title_size * scale : 0; + const int csd_title = term->window->use_csd == CSD_YES ? csd_title_size * scale : 0; #endif const int csd_x = 2 * csd_border; -- cgit v1.3 From 3228758951ea407886042fa07f586d10084e3a8f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 15:27:40 +0100 Subject: render: resize: adjust user configured size for CSDs --- render.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 6f71ae30..a752dd8e 100644 --- a/render.c +++ b/render.c @@ -1163,6 +1163,11 @@ maybe_resize(struct terminal *term, int width, int height, bool force) if (width == 0 && height == 0) { width = term->conf->width; height = term->conf->height; + +#if FOOT_CSD_OUTSIDE + width -= 2 * csd_border_size; + height -= 2 * csd_border_size + csd_title_size; +#endif } width *= scale; -- cgit v1.3 From ddbfb3676cce56d289271f8287a4389daea562f3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 20:59:11 +0100 Subject: render: remember, and use, last unmaximized size When the compositor wants us to decide the size (it sends a configure event with width/height == 0), then use the last unmaximized size, if there is one. If there isn't one, use the size from the user configuration. --- render.c | 36 ++++++++++++++++++++++++++---------- terminal.h | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index a752dd8e..98ea90f6 100644 --- a/render.c +++ b/render.c @@ -1160,16 +1160,6 @@ maybe_resize(struct terminal *term, int width, int height, bool force) scale = 1; } - if (width == 0 && height == 0) { - width = term->conf->width; - height = term->conf->height; - -#if FOOT_CSD_OUTSIDE - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; -#endif - } - width *= scale; height *= scale; @@ -1182,6 +1172,27 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int csd_title = term->window->use_csd == CSD_YES ? csd_title_size * scale : 0; #endif + if (width == 0 && height == 0) { + /* + * The compositor is letting us choose the size + * + * If we have a "last" used size - use that. Otherwise, use + * the size from the user configuration. + */ + if (term->unmaximized_width != 0 && term->unmaximized_height != 0) { + width = term->unmaximized_width; + height = term->unmaximized_height; + } else { + width = term->conf->width * scale; + height = term->conf->height * scale; + +#if FOOT_CSD_OUTSIDE + width -= 2 * csd_border; + height -= 2 * csd_border + csd_title; +#endif + } + } + const int csd_x = 2 * csd_border; const int csd_y = 2 * csd_border + csd_title; @@ -1301,6 +1312,11 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->render.last_cursor.cell = NULL; damage_view: + if (!term->window->is_maximized) { + term->unmaximized_width = term->width; + term->unmaximized_height = term->height; + } + xdg_toplevel_set_min_size( term->window->xdg_toplevel, min_width / scale, min_height / scale); tll_free(term->normal.scroll_damage); diff --git a/terminal.h b/terminal.h index c25c0245..df3fb06a 100644 --- a/terminal.h +++ b/terminal.h @@ -248,6 +248,8 @@ struct terminal { int scale; int width; /* pixels */ int height; /* pixels */ + int unmaximized_width; /* last unmaximized size, pixels */ + int unmaximized_height; /* last unmaximized size, pixels */ struct { int left; int right; -- cgit v1.3 From 925088a8f21c2b2b136d30ca2d4bc45fd816ce35 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 18:35:21 +0100 Subject: render: color_hex_to_pixman_with_alpha(): handle alpha == 0 (transparent) --- render.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 98ea90f6..634e07dc 100644 --- a/render.c +++ b/render.c @@ -218,6 +218,9 @@ color_hex_to_rgb(uint32_t color) static inline pixman_color_t color_hex_to_pixman_with_alpha(uint32_t color, uint16_t alpha) { + if (alpha == 0) + return (pixman_color_t){0, 0, 0, 0}; + int alpha_div = 0xffff / alpha; return (pixman_color_t){ .red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) / alpha_div, -- cgit v1.3 From b44bbb5b2b400b9d69f5e0d1c8d9c57425fb695e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 18:49:34 +0100 Subject: render: CSDs: don't render borders (only title bar) in maximized mode --- render.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 634e07dc..db824f17 100644 --- a/render.c +++ b/render.c @@ -677,7 +677,10 @@ render_csd(struct terminal *term) if (term->window->is_fullscreen) return; - const int border_width = csd_border_size * term->scale; + /* Only title bar is rendered in maximized mode */ + const int border_width = !term->window->is_maximized + ? csd_border_size * term->scale : 0; + const int title_height = csd_title_size * term->scale; const int geom[5][4] = { @@ -710,6 +713,15 @@ render_csd(struct terminal *term) const int width = geom[i][2]; const int height = geom[i][3]; + if (width == 0 || height == 0) { + /* CSD borders aren't rendered in maximized mode */ + assert(term->window->is_maximized); + wl_subsurface_set_position(sub, 0, 0); + wl_surface_attach(surf, NULL, 0, 0); + wl_surface_commit(surf); + continue; + } + unsigned long cookie = shm_cookie_csd(term, i); struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); -- cgit v1.3 From e7e553ae5b49624bf38adc70e8e3a209d1ef2e5e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 18:50:15 +0100 Subject: render: resize: exclude CSD borders when loading default geometry in maximized mode --- render.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index db824f17..53bedb75 100644 --- a/render.c +++ b/render.c @@ -1198,13 +1198,24 @@ maybe_resize(struct terminal *term, int width, int height, bool force) width = term->unmaximized_width; height = term->unmaximized_height; } else { - width = term->conf->width * scale; - height = term->conf->height * scale; + width = term->conf->width; + height = term->conf->height; + + if (term->window->use_csd == CSD_YES) { + assert(!term->window->is_fullscreen); + + /* Account for CSDs, to make actual window size match + * the configured size */ + if (!term->window->is_maximized) { + width -= 2 * csd_border_size; + height -= 2 * csd_border_size + csd_title_size; + } else { + height -= csd_title_size; + } + } -#if FOOT_CSD_OUTSIDE - width -= 2 * csd_border; - height -= 2 * csd_border + csd_title; -#endif + width *= scale; + height *= scale; } } -- cgit v1.3 From ec2ad7755fb65c809214d8e3615ad46f1a3ddba0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 18:51:09 +0100 Subject: render: CSDs: transparent borders This gives the illusion that window is border-less, but still gives us surfaces the user can grab to resize the window. --- render.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 53bedb75..f2b2dc4e 100644 --- a/render.c +++ b/render.c @@ -723,9 +723,12 @@ render_csd(struct terminal *term) } unsigned long cookie = shm_cookie_csd(term, i); - struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie); + struct buffer *buf = shm_get_buffer( + term->wl->shm, width, height, cookie); + + pixman_color_t color = color_hex_to_pixman_with_alpha( + i == 0 ? term->colors.fg : 0x0, i == 0 ? 0xffff : 0x0); - pixman_color_t color = color_hex_to_pixman(term->colors.fg); if (!term->visual_focus) pixman_color_dim(&color); @@ -739,7 +742,7 @@ render_csd(struct terminal *term) wl_subsurface_set_position(sub, x, y); wl_surface_attach(surf, buf->wl_buf, 0, 0); - wl_surface_set_opaque_region(surf, region); + //wl_surface_set_opaque_region(surf, region); wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); wl_surface_set_buffer_scale(surf, term->scale); wl_surface_commit(surf); -- cgit v1.3 From 45c1585bfbabaaf11778c55e4c431a975bfd6306 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 18:51:51 +0100 Subject: render: resize: change 'resize' log from info to debug --- render.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index f2b2dc4e..2ceaa4fa 100644 --- a/render.c +++ b/render.c @@ -1299,10 +1299,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->cols = new_cols; term->rows = new_rows; - LOG_INFO("resize: %dx%d, grid: cols=%d, rows=%d " - "(left-margin=%d, right-margin=%d, top-margin=%d, bottom-margin=%d)", - term->width, term->height, term->cols, term->rows, - term->margins.left, term->margins.right, term->margins.top, term->margins.bottom); + LOG_DBG("resize: %dx%d, grid: cols=%d, rows=%d " + "(left-margin=%d, right-margin=%d, top-margin=%d, bottom-margin=%d)", + term->width, term->height, term->cols, term->rows, + term->margins.left, term->margins.right, term->margins.top, term->margins.bottom); /* Signal TIOCSWINSZ */ if (ioctl(term->ptmx, TIOCSWINSZ, -- cgit v1.3 From de9fcbc339ecca7b79dbe4c4af0c5114280b5c47 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 19:00:48 +0100 Subject: render: csd: use a struct for positioning information --- render.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 2ceaa4fa..4dbf272a 100644 --- a/render.c +++ b/render.c @@ -683,7 +683,12 @@ render_csd(struct terminal *term) const int title_height = csd_title_size * term->scale; - const int geom[5][4] = { + const struct { + int x; + int y; + int width; + int height; + } geom[] = { /* X, Y, WIDTH, HEIGHT */ #if FOOT_CSD_OUTSIDE { 0, -title_height, term->width, title_height}, /* title */ @@ -708,10 +713,10 @@ render_csd(struct terminal *term) struct wl_surface *surf = term->window->csd.surface[i]; struct wl_subsurface *sub = term->window->csd.sub_surface[i]; - const int x = geom[i][0]; - const int y = geom[i][1]; - const int width = geom[i][2]; - const int height = geom[i][3]; + const int x = geom[i].x; + const int y = geom[i].y; + const int width = geom[i].width; + const int height = geom[i].height; if (width == 0 || height == 0) { /* CSD borders aren't rendered in maximized mode */ -- cgit v1.3 From e01030f99fcf4cbc92c0319b6bf083c515099e46 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 09:39:05 +0100 Subject: render: csd: bump title bar height from 20 -> 26 --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 4dbf272a..74c683dd 100644 --- a/render.c +++ b/render.c @@ -25,7 +25,7 @@ #define max(x, y) ((x) > (y) ? (x) : (y)) const int csd_border_size = 5; -const int csd_title_size = 20; +const int csd_title_size = 26; struct renderer { struct fdm *fdm; -- cgit v1.3 From 601dc02ea1758f6690fffa925bffb959ba300739 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 11:40:41 +0100 Subject: render: wl_subsurface_set_position() uses un-scaled coordinates This fixes an issue where the CSDs and the search box was incorrectly positioned when output's scale != 1. --- render.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 74c683dd..6d3e7180 100644 --- a/render.c +++ b/render.c @@ -744,7 +744,7 @@ render_csd(struct terminal *term) &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); pixman_image_unref(src); - wl_subsurface_set_position(sub, x, y); + wl_subsurface_set_position(sub, x / term->scale, y / term->scale); wl_surface_attach(surf, buf->wl_buf, 0, 0); //wl_surface_set_opaque_region(surf, region); @@ -1156,8 +1156,8 @@ render_search_box(struct terminal *term) wl_subsurface_set_position( term->window->search_sub_surface, - max(0, (int32_t)term->width - width - margin), - max(0, (int32_t)term->height - height - margin)); + max(0, (int32_t)term->width - width - margin) / scale, + max(0, (int32_t)term->height - height - margin) / scale); wl_surface_commit(term->window->search_surface); } -- cgit v1.3 From f67572208db6314338fdf57faeda9e999673303a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 11:41:40 +0100 Subject: render: search: fix off-by-one error in number of visible characters --- render.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 6d3e7180..a1162a39 100644 --- a/render.c +++ b/render.c @@ -1119,7 +1119,7 @@ render_search_box(struct terminal *term) pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]); if (term->search.cursor < glyph_offset || - term->search.cursor >= glyph_offset + visible_chars + 2) + term->search.cursor >= glyph_offset + visible_chars + 1) { /* Make sure cursor is always visible */ term->render.search_glyph_offset = glyph_offset = term->search.cursor; @@ -1127,7 +1127,7 @@ render_search_box(struct terminal *term) /* Text (what the user entered - *not* match(es)) */ for (size_t i = glyph_offset; - i < term->search.len && i - glyph_offset < visible_chars + 1; + i < term->search.len && i - glyph_offset < visible_chars; i++) { if (i == term->search.cursor) -- cgit v1.3 From cbf657e2d23bc58041faf7736b87af59f826bf54 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 11:42:00 +0100 Subject: render: resize: redraw search box, if visible --- render.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index a1162a39..a22ee8d1 100644 --- a/render.c +++ b/render.c @@ -1353,12 +1353,18 @@ damage_view: xdg_toplevel_set_min_size( term->window->xdg_toplevel, min_width / scale, min_height / scale); + + render_csd(term); + if (term->is_searching) + render_search_box(term); + tll_free(term->normal.scroll_damage); tll_free(term->alt.scroll_damage); - render_csd(term); + term->render.last_buf = NULL; term_damage_view(term); render_refresh(term); + return true; } -- cgit v1.3 From 9264e1e5bd00243859e6281d717b6cbe0355e3f5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 17:25:08 +0100 Subject: render: don't update last 'un-maximized' size when in fullscreen --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index a22ee8d1..a067ad68 100644 --- a/render.c +++ b/render.c @@ -1346,7 +1346,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->render.last_cursor.cell = NULL; damage_view: - if (!term->window->is_maximized) { + if (!term->window->is_maximized && !term->window->is_fullscreen) { term->unmaximized_width = term->width; term->unmaximized_height = term->height; } -- cgit v1.3 From 92d638eb1c34859a08605ffc79be8f0a4a3c63a3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 18:02:38 +0100 Subject: render: csd: split up positioning from rendering --- render.c | 203 ++++++++++++++++++++++++++++++++++++++----------------------- render.h | 1 + terminal.c | 6 +- wayland.h | 9 +++ 4 files changed, 140 insertions(+), 79 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index a067ad68..340747c0 100644 --- a/render.c +++ b/render.c @@ -43,7 +43,7 @@ static void fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data); #define shm_cookie_grid(term) ((unsigned long)((uintptr_t)term + 0)) #define shm_cookie_search(term) ((unsigned long)((uintptr_t)term + 1)) -#define shm_cookie_csd(term, n) ((unsigned long)((uintptr_t)term + 2 + (n))) +#define shm_cookie_csd(term, n) ((unsigned long)((uintptr_t)term + 2 + (n))) /* Should be placed last */ struct renderer * render_init(struct fdm *fdm, struct wayland *wayl) @@ -665,100 +665,149 @@ render_worker_thread(void *_ctx) return -1; } -void -render_csd(struct terminal *term) -{ - switch (term->window->use_csd) { - case CSD_UNKNOWN: - case CSD_NO: - break; +struct csd_data { + enum csd_surface idx; + int x; + int y; + int width; + int height; +}; - case CSD_YES: { - if (term->window->is_fullscreen) - return; +static const struct csd_data * +get_csd_data(const struct terminal *term, enum csd_surface surf_idx) +{ + assert(term->window->use_csd == CSD_YES); - /* Only title bar is rendered in maximized mode */ - const int border_width = !term->window->is_maximized - ? csd_border_size * term->scale : 0; + /* Only title bar is rendered in maximized mode */ + const int border_width = !term->window->is_maximized + ? csd_border_size * term->scale : 0; - const int title_height = csd_title_size * term->scale; + const int title_height = !term->window->is_fullscreen + ? csd_title_size * term->scale : 0; - const struct { - int x; - int y; - int width; - int height; - } geom[] = { - /* X, Y, WIDTH, HEIGHT */ + const struct csd_data csd_data[] = { + /* SURF IDX, X, Y, WIDTH, HEIGHT */ #if FOOT_CSD_OUTSIDE - { 0, -title_height, term->width, title_height}, /* title */ - { -border_width, -title_height, border_width, title_height + term->height}, /* left */ - { term->width, -title_height, border_width, title_height + term->height}, /* right */ - { -border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, /* top */ - { -border_width, term->height, term->width + 2 * border_width, border_width}, /* bottom */ + {CSD_SURF_TITLE, 0, -title_height, term->width, title_height}, + {CSD_SURF_LEFT, -border_width, -title_height, border_width, title_height + term->height}, + {CSD_SURF_RIGHT , term->width, -title_height, border_width, title_height + term->height}, + {CSD_SURF_TOP, -border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, + {CSD_SURF_BOTTOM, -border_width, term->height, term->width + 2 * border_width, border_width}, #else - { border_width, border_width, term->width - 2 * border_width, title_height}, /* title */ - { 0, border_width, border_width, term->height - 2 * border_width}, /* left */ - {term->width - border_width, border_width, border_width, term->height - 2 * border_width}, /* right */ - { 0, 0, term->width, border_width}, /* top */ - { 0, term->height - border_width, term->width, border_width}, /* bottom */ + {CSD_SURF_TITLE, border_width, border_width, term->width - 2 * border_width, title_height}, + {CSD_SURF_LEFT, 0, border_width, border_width, term->height - 2 * border_width}, + {CSD_SURF_RIGHT, term->width - border_width, border_width, border_width, term->height - 2 * border_width}, + {CSD_SURF_TOP, 0, 0, term->width, border_width}, + {CSD_SURF_BOTTOM, 0, term->height - border_width, term->width, border_width}, #endif - }; - - struct wl_region *region = wl_compositor_create_region(term->wl->compositor); - if (region != NULL) - wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); - - for (size_t i = 0; i < sizeof(geom) / sizeof(geom[0]); i++) { - struct wl_surface *surf = term->window->csd.surface[i]; - struct wl_subsurface *sub = term->window->csd.sub_surface[i]; - - const int x = geom[i].x; - const int y = geom[i].y; - const int width = geom[i].width; - const int height = geom[i].height; - - if (width == 0 || height == 0) { - /* CSD borders aren't rendered in maximized mode */ - assert(term->window->is_maximized); - wl_subsurface_set_position(sub, 0, 0); - wl_surface_attach(surf, NULL, 0, 0); - wl_surface_commit(surf); - continue; - } + }; - unsigned long cookie = shm_cookie_csd(term, i); - struct buffer *buf = shm_get_buffer( - term->wl->shm, width, height, cookie); + const struct csd_data *ret = &csd_data[surf_idx]; + assert(ret->idx == surf_idx); + return ret; +} + +static void +render_csd_part(struct terminal *term, + struct wl_surface *surf, struct buffer *buf, + int width, int height, pixman_color_t *color) +{ + assert(term->window->use_csd == CSD_YES); - pixman_color_t color = color_hex_to_pixman_with_alpha( - i == 0 ? term->colors.fg : 0x0, i == 0 ? 0xffff : 0x0); + pixman_image_t *src = pixman_image_create_solid_fill(color); - if (!term->visual_focus) - pixman_color_dim(&color); + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, color, 1, + &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); + pixman_image_unref(src); + + wl_surface_attach(surf, buf->wl_buf, 0, 0); + wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); + wl_surface_set_buffer_scale(surf, term->scale); + wl_surface_commit(surf); +} - pixman_image_t *src = pixman_image_create_solid_fill(&color); +void +render_csd_title(struct terminal *term) +{ + if (term->window->use_csd != CSD_YES) + return; - pixman_image_fill_rectangles( - PIXMAN_OP_SRC, buf->pix, &color, 1, - &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); - pixman_image_unref(src); + const struct csd_data *info = get_csd_data(term, CSD_SURF_TITLE); + struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE]; - wl_subsurface_set_position(sub, x / term->scale, y / term->scale); + unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE); + struct buffer *buf = shm_get_buffer( + term->wl->shm, info->width, info->height, cookie); - wl_surface_attach(surf, buf->wl_buf, 0, 0); - //wl_surface_set_opaque_region(surf, region); - wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); - wl_surface_set_buffer_scale(surf, term->scale); - wl_surface_commit(surf); - } + pixman_color_t color = color_hex_to_pixman(term->colors.fg); - if (region != NULL) - wl_region_destroy(region); + if (!term->visual_focus) + pixman_color_dim(&color); - break; + struct wl_region *region = wl_compositor_create_region(term->wl->compositor); + if (region != NULL) { + wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); + wl_surface_set_opaque_region(surf, region); + wl_region_destroy(region); } + + render_csd_part(term, surf, buf, info->width, info->height, &color); +} + +static void +render_csd_border(struct terminal *term, enum csd_surface surf_idx) +{ + assert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM); + + if (term->window->use_csd != CSD_YES) + return; + + const struct csd_data *info = get_csd_data(term, surf_idx); + struct wl_surface *surf = term->window->csd.surface[surf_idx]; + + unsigned long cookie = shm_cookie_csd(term, surf_idx); + struct buffer *buf = shm_get_buffer( + term->wl->shm, info->width, info->height, cookie); + + pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0); + + if (!term->visual_focus) + pixman_color_dim(&color); + render_csd_part(term, surf, buf, info->width, info->height, &color); +} + +void +render_csd(struct terminal *term) +{ + if (term->window->use_csd != CSD_YES) + return; + + for (size_t i = 0; i < CSD_SURF_COUNT; i++) { + const struct csd_data *info = get_csd_data(term, i); + const int x = info->x; + const int y = info->y; + const int width = info->width; + const int height = info->height; + + struct wl_surface *surf = term->window->csd.surface[i]; + struct wl_subsurface *sub = term->window->csd.sub_surface[i]; + + if (width == 0 || height == 0) { + /* CSD borders aren't rendered in maximized mode */ + assert(term->window->is_maximized); + wl_subsurface_set_position(sub, 0, 0); + wl_surface_attach(surf, NULL, 0, 0); + wl_surface_commit(surf); + continue; + } + + wl_subsurface_set_position(sub, x / term->scale, y / term->scale); } + + render_csd_title(term); + for (size_t i = CSD_SURF_LEFT; i <= CSD_SURF_BOTTOM; i++) + render_csd_border(term, i); } static void frame_callback( diff --git a/render.h b/render.h index 8602d367..2177e8bd 100644 --- a/render.h +++ b/render.h @@ -18,6 +18,7 @@ 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); struct render_worker_context { int my_id; diff --git a/terminal.c b/terminal.c index 0b3091f8..1d17ba5d 100644 --- a/terminal.c +++ b/terminal.c @@ -1641,7 +1641,8 @@ term_visual_focus_in(struct terminal *term) wl_subsurface_set_desync(term->window->csd.sub_surface[i]); } #endif - render_csd(term); + //render_csd(term); + render_csd_title(term); #if 1 if (term->window->use_csd == CSD_YES) { for (int i = 0; i < ALEN(term->window->csd.surface); i++) @@ -1667,7 +1668,8 @@ term_visual_focus_out(struct terminal *term) wl_subsurface_set_desync(term->window->csd.sub_surface[i]); } #endif - render_csd(term); + //render_csd(term); + render_csd_title(term); #if 1 if (term->window->use_csd == CSD_YES) { for (int i = 0; i < ALEN(term->window->csd.surface); i++) diff --git a/wayland.h b/wayland.h index 768fee5f..b879c319 100644 --- a/wayland.h +++ b/wayland.h @@ -91,6 +91,15 @@ struct wl_primary { extern const int csd_border_size; extern const int csd_title_size; +enum csd_surface { + CSD_SURF_TITLE, + CSD_SURF_LEFT, + CSD_SURF_RIGHT, + CSD_SURF_TOP, + CSD_SURF_BOTTOM, + CSD_SURF_COUNT, +}; + struct wayland; struct wl_window { struct terminal *term; -- cgit v1.3 From f038a27366b5b704c0ded0a1a094f2d5c4d0d542 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 12:28:01 +0100 Subject: render: csd: switch-based CSD positioning --- render.c | 64 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 340747c0..cd49255e 100644 --- a/render.c +++ b/render.c @@ -666,14 +666,13 @@ render_worker_thread(void *_ctx) } struct csd_data { - enum csd_surface idx; int x; int y; int width; int height; }; -static const struct csd_data * +static struct csd_data get_csd_data(const struct terminal *term, enum csd_surface surf_idx) { assert(term->window->use_csd == CSD_YES); @@ -685,26 +684,33 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) const int title_height = !term->window->is_fullscreen ? csd_title_size * term->scale : 0; - const struct csd_data csd_data[] = { - /* SURF IDX, X, Y, WIDTH, HEIGHT */ #if FOOT_CSD_OUTSIDE - {CSD_SURF_TITLE, 0, -title_height, term->width, title_height}, - {CSD_SURF_LEFT, -border_width, -title_height, border_width, title_height + term->height}, - {CSD_SURF_RIGHT , term->width, -title_height, border_width, title_height + term->height}, - {CSD_SURF_TOP, -border_width, -title_height - border_width, term->width + 2 * border_width, border_width}, - {CSD_SURF_BOTTOM, -border_width, term->height, term->width + 2 * border_width, border_width}, + switch (surf_idx) { + case CSD_SURF_TITLE: return (struct csd_data){ 0, -title_height, term->width, title_height}; + case CSD_SURF_LEFT: return (struct csd_data){-border_width, -title_height, border_width, title_height + term->height}; + case CSD_SURF_RIGHT: return (struct csd_data){ term->width, -title_height, border_width, title_height + term->height}; + case CSD_SURF_TOP: return (struct csd_data){-border_width, -title_height - border_width, term->width + 2 * border_width, border_width}; + case CSD_SURF_BOTTOM: return (struct csd_data){-border_width, term->height, term->width + 2 * border_width, border_width}; + + case CSD_SURF_COUNT: + assert(false); + return (struct csd_data){0}; + } #else - {CSD_SURF_TITLE, border_width, border_width, term->width - 2 * border_width, title_height}, - {CSD_SURF_LEFT, 0, border_width, border_width, term->height - 2 * border_width}, - {CSD_SURF_RIGHT, term->width - border_width, border_width, border_width, term->height - 2 * border_width}, - {CSD_SURF_TOP, 0, 0, term->width, border_width}, - {CSD_SURF_BOTTOM, 0, term->height - border_width, term->width, border_width}, + switch (surf_idx) { + case CSD_SURF_TITLE: return (struct csd_data){ border_width, border_width, term->width - 2 * border_width, title_height}; + case CSD_SURF_LEFT: return (struct csd_data){ 0, border_width, border_width, term->height - 2 * border_width}; + case CSD_SURF_RIGHT: return (struct csd_data){term->width - border_width, border_width, border_width, term->height - 2 * border_width}; + case CSD_SURF_TOP: return (struct csd_data){ 0, 0, term->width, border_width}; + + case CSD_SURF_COUNT: + assert(false); + return (struct csd_data){0}; + } #endif - }; - const struct csd_data *ret = &csd_data[surf_idx]; - assert(ret->idx == surf_idx); - return ret; + assert(false); + return (struct csd_data){0}; } static void @@ -733,12 +739,12 @@ render_csd_title(struct terminal *term) if (term->window->use_csd != CSD_YES) return; - const struct csd_data *info = get_csd_data(term, CSD_SURF_TITLE); + struct csd_data info = get_csd_data(term, CSD_SURF_TITLE); struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE]; unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE); struct buffer *buf = shm_get_buffer( - term->wl->shm, info->width, info->height, cookie); + term->wl->shm, info.width, info.height, cookie); pixman_color_t color = color_hex_to_pixman(term->colors.fg); @@ -752,7 +758,7 @@ render_csd_title(struct terminal *term) wl_region_destroy(region); } - render_csd_part(term, surf, buf, info->width, info->height, &color); + render_csd_part(term, surf, buf, info.width, info.height, &color); } static void @@ -763,18 +769,18 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) if (term->window->use_csd != CSD_YES) return; - const struct csd_data *info = get_csd_data(term, surf_idx); + struct csd_data info = get_csd_data(term, surf_idx); struct wl_surface *surf = term->window->csd.surface[surf_idx]; unsigned long cookie = shm_cookie_csd(term, surf_idx); struct buffer *buf = shm_get_buffer( - term->wl->shm, info->width, info->height, cookie); + term->wl->shm, info.width, info.height, cookie); pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0); if (!term->visual_focus) pixman_color_dim(&color); - render_csd_part(term, surf, buf, info->width, info->height, &color); + render_csd_part(term, surf, buf, info.width, info.height, &color); } void @@ -784,11 +790,11 @@ render_csd(struct terminal *term) return; for (size_t i = 0; i < CSD_SURF_COUNT; i++) { - const struct csd_data *info = get_csd_data(term, i); - const int x = info->x; - const int y = info->y; - const int width = info->width; - const int height = info->height; + struct csd_data info = get_csd_data(term, i); + const int x = info.x; + const int y = info.y; + const int width = info.width; + const int height = info.height; struct wl_surface *surf = term->window->csd.surface[i]; struct wl_subsurface *sub = term->window->csd.sub_surface[i]; -- cgit v1.3 From 7b1dafae0f84cde10ad8950642535ca7d9a4427c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 12:28:33 +0100 Subject: render: search: kwin has problems with a resizing/repositioned sub-surface So, make it equal to the window size, and make the non-used area fully transparent. --- render.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index cd49255e..70d93033 100644 --- a/render.c +++ b/render.c @@ -1146,14 +1146,15 @@ render_search_box(struct terminal *term) #endif const size_t margin = csd + 3 * scale; - const size_t width = min( + const size_t width = term->width - 2 * margin; + const size_t visible_width = min( term->width - 2 * margin, 2 * margin + wanted_visible_chars * term->cell_width); const size_t height = min( term->height - 2 * margin, 2 * margin + 1 * term->cell_height); - const size_t visible_chars = (width - 2 * margin) / term->cell_width; + const size_t visible_chars = (visible_width - 2 * margin) / term->cell_width; size_t glyph_offset = term->render.search_glyph_offset; unsigned long cookie = shm_cookie_search(term); @@ -1166,10 +1167,15 @@ render_search_box(struct terminal *term) pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix, &color, - 1, &(pixman_rectangle16_t){0, 0, width, height}); + 1, &(pixman_rectangle16_t){width - visible_width, 0, visible_width, height}); + + pixman_color_t transparent = color_hex_to_pixman_with_alpha(0, 0); + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &transparent, + 1, &(pixman_rectangle16_t){0, 0, width - visible_width, height}); struct font *font = term->fonts[0]; - int x = margin; + int x = width - visible_width + margin; int y = margin; pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]); @@ -1205,15 +1211,15 @@ render_search_box(struct terminal *term) if (term->search.cursor >= term->search.len) draw_bar(term, buf->pix, font, &fg, x, y); - wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0); - wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height); - wl_surface_set_buffer_scale(term->window->search_surface, scale); - wl_subsurface_set_position( term->window->search_sub_surface, - max(0, (int32_t)term->width - width - margin) / scale, + margin / scale, max(0, (int32_t)term->height - height - margin) / scale); + wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0); + wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height); + wl_surface_set_buffer_scale(term->window->search_surface, scale); + wl_surface_commit(term->window->search_surface); } -- cgit v1.3 From b8d79c719b77fb1e9f958353c62aea09d592067b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 12:54:27 +0100 Subject: render: search: mark visible portion of sub-surface opaque --- quirks.c | 35 +++++++++++++++++++++++++++++++++++ quirks.h | 5 +++++ render.c | 7 +++++++ 3 files changed, 47 insertions(+) create mode 100644 quirks.c create mode 100644 quirks.h (limited to 'render.c') diff --git a/quirks.c b/quirks.c new file mode 100644 index 00000000..a1b1bafe --- /dev/null +++ b/quirks.c @@ -0,0 +1,35 @@ +#include "quirks.h" + +#include +#include + +void +quirk_weston_subsurface_desync(struct wl_subsurface *sub) +{ + /* + * On weston (8.0), synchronized subsurfaces aren't updated + * correctly. + + * They appear to render once, but after that, updates are + * sporadic. Sometimes they update, most of the time they + * don't. + * + * Adding explicit parent surface commits right after the + * subsurface commit doesn't help (and would be useless anyway, + * since it would defeat the purpose of having the subsurface + * synchronized in the first place). + */ + + static bool is_weston = false; + static bool initialized = false; + + if (!initialized) { + initialized = true; + is_weston = getenv("WESTON_CONFIG_FILE") != NULL; + } + + if (!is_weston) + return; + + wl_subsurface_set_desync(sub); +} diff --git a/quirks.h b/quirks.h new file mode 100644 index 00000000..1e087692 --- /dev/null +++ b/quirks.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void quirk_weston_subsurface_desync(struct wl_subsurface *sub); diff --git a/render.c b/render.c index 70d93033..d15aa756 100644 --- a/render.c +++ b/render.c @@ -1220,6 +1220,13 @@ render_search_box(struct terminal *term) wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height); wl_surface_set_buffer_scale(term->window->search_surface, scale); + struct wl_region *region = wl_compositor_create_region(term->wl->compositor); + if (region != NULL) { + wl_region_add(region, width - visible_width, 0, visible_width, height); + wl_surface_set_opaque_region(term->window->search_surface, region); + wl_region_destroy(region); + } + wl_surface_commit(term->window->search_surface); } -- cgit v1.3 From a29427a185f170d2e33f4530f06a6a8e23f81d2c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 12:54:50 +0100 Subject: render: search: add todo to only position sub-surface on a window resize --- render.c | 1 + 1 file changed, 1 insertion(+) (limited to 'render.c') diff --git a/render.c b/render.c index d15aa756..6e68f76b 100644 --- a/render.c +++ b/render.c @@ -1211,6 +1211,7 @@ render_search_box(struct terminal *term) if (term->search.cursor >= term->search.len) draw_bar(term, buf->pix, font, &fg, x, y); + /* TODO: this is only necessary on a window resize */ wl_subsurface_set_position( term->window->search_sub_surface, margin / scale, -- 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 'render.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 875b067f136f05c04db56be9d9de69b3391832c8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 13:17:54 +0100 Subject: render: csd: don't try to render a zero-width/height border --- render.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index df8a98de..740d3e55 100644 --- a/render.c +++ b/render.c @@ -743,6 +743,8 @@ render_csd_title(struct terminal *term) struct csd_data info = get_csd_data(term, CSD_SURF_TITLE); struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE]; + assert(info.width > 0 && info.height > 0); + unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE); struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); @@ -773,6 +775,9 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) struct csd_data info = get_csd_data(term, surf_idx); struct wl_surface *surf = term->window->csd.surface[surf_idx]; + if (info.width == 0 || info.height == 0) + return; + unsigned long cookie = shm_cookie_csd(term, surf_idx); struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); -- cgit v1.3 From 22ce09eb44db887d32a5b3a88740939b7285c763 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 18:42:49 +0100 Subject: config: make CSD user configurable The user can now configure the following: * Whether to prefer CSDs or SSDs. But note that this is only a hint to the compositor - it may deny our request. Furthermore, not all compositors implement the decoration manager protocol, meaning CSDs will be used regardless of the user configuration (GNOME/mutter being the most prominent one). * Title bar size and color, including transparency * Border size and color, including transparency Also drop support for rendering the CSDs inside the main surface. --- config.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++--- config.h | 14 ++++++++ doc/foot.5.scd | 31 ++++++++++++++++++ footrc | 7 ++++ input.c | 31 +++++++++--------- render.c | 100 ++++++++++++++++++++++----------------------------------- wayland.c | 35 +++++++++++--------- wayland.h | 9 ------ 8 files changed, 210 insertions(+), 107 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index 37795bb9..246e0d18 100644 --- a/config.c +++ b/config.c @@ -133,7 +133,7 @@ str_to_double(const char *s, double *res) } static bool -str_to_color(const char *s, uint32_t *color, const char *path, int lineno) +str_to_color(const char *s, uint32_t *color, bool allow_alpha, const char *path, int lineno) { unsigned long value; if (!str_to_ulong(s, 16, &value)) { @@ -141,7 +141,12 @@ str_to_color(const char *s, uint32_t *color, const char *path, int lineno) return false; } - *color = value & 0xffffff; + if (!allow_alpha && (value & 0xff000000) != 0) { + LOG_ERR("%s:%d: color value must not have an alpha component", path, lineno); + return false; + } + + *color = value; return true; } @@ -273,7 +278,7 @@ parse_section_colors(const char *key, const char *value, struct config *conf, } uint32_t color_value; - if (!str_to_color(value, &color_value, path, lineno)) + if (!str_to_color(value, &color_value, false, path, lineno)) return false; *color = color_value; @@ -305,8 +310,8 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, uint32_t text_color, cursor_color; if (text == NULL || cursor == NULL || - !str_to_color(text, &text_color, path, lineno) || - !str_to_color(cursor, &cursor_color, path, lineno)) + !str_to_color(text, &text_color, false, path, lineno) || + !str_to_color(cursor, &cursor_color, false, path, lineno)) { LOG_ERR("%s:%d: invalid cursor colors: %s", path, lineno, value); free(value_copy); @@ -326,6 +331,66 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, return true; } +static bool +parse_section_csd(const char *key, const char *value, struct config *conf, + const char *path, unsigned lineno) +{ + if (strcmp(key, "preferred") == 0) { + if (strcmp(value, "server") == 0) + conf->csd.preferred = CONF_CSD_PREFER_SERVER; + else if (strcmp(value, "client") == 0) + conf->csd.preferred = CONF_CSD_PREFER_CLIENT; + else { + LOG_ERR("%s:%d: expected either 'server' or 'client'", path, lineno); + return false; + } + } + + else if (strcmp(key, "titlebar-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid titlebar-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.title_set = true; + conf->csd.color.title = color; + } + + else if (strcmp(key, "border-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid border-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.border_set = true; + conf->csd.color.border = color; + } + + else if (strcmp(key, "titlebar") == 0) { + unsigned long pixels; + if (!str_to_ulong(value, 10, &pixels)) { + LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); + return false; + } + + conf->csd.title_height = pixels; + } + + else if (strcmp(key, "border") == 0) { + unsigned long pixels; + if (!str_to_ulong(value, 10, &pixels)) { + LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); + return false; + } + + conf->csd.border_width = pixels; + } + + return true; +} + static bool parse_config_file(FILE *f, struct config *conf, const char *path) { @@ -333,6 +398,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) SECTION_MAIN, SECTION_COLORS, SECTION_CURSOR, + SECTION_CSD, } section = SECTION_MAIN; /* Function pointer, called for each key/value line */ @@ -345,6 +411,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) [SECTION_MAIN] = &parse_section_main, [SECTION_COLORS] = &parse_section_colors, [SECTION_CURSOR] = &parse_section_cursor, + [SECTION_CSD] = &parse_section_csd, }; #if defined(_DEBUG) && defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG @@ -352,6 +419,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) [SECTION_MAIN] = "main", [SECTION_COLORS] = "colors", [SECTION_CURSOR] = "cursor", + [SECTION_CSD] = "csd", }; #endif @@ -408,6 +476,8 @@ parse_config_file(FILE *f, struct config *conf, const char *path) section = SECTION_COLORS; else if (strcmp(&line[1], "cursor") == 0) section = SECTION_CURSOR; + else if (strcmp(&line[1], "csd") == 0) + section = SECTION_CSD; else { LOG_ERR("%s:%d: invalid section name: %s", path, lineno, &line[1]); goto err; @@ -532,6 +602,16 @@ config_load(struct config *conf, const char *conf_path) }, }, + .csd = { + .preferred = CONF_CSD_PREFER_SERVER, + .title_height = 26, + .border_width = 5, + .color = { + .title_set = false, + .border_set = false, + }, + }, + .render_worker_count = sysconf(_SC_NPROCESSORS_ONLN), .server_socket_path = get_server_socket_path(), .presentation_timings = false, diff --git a/config.h b/config.h index 3677129f..fa765476 100644 --- a/config.h +++ b/config.h @@ -36,6 +36,20 @@ struct config { } color; } cursor; + struct { + enum { CONF_CSD_PREFER_SERVER, CONF_CSD_PREFER_CLIENT } preferred; + + int title_height; + int border_width; + + struct { + bool title_set; + bool border_set; + uint32_t title; + uint32_t border; + } color; + } csd; + size_t render_worker_count; char *server_socket_path; bool presentation_timings; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 41785366..30fd735c 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -98,6 +98,37 @@ in this order: Background translucency. A value in the range 0.0-1.0, where 0.0 means completely transparent, and 1.0 is opaque. Default: _1.0_. +# SECTION: csd + +This section controls the look of the _CSDs_ (Client Side +Decorations). Note that the default is to *not* use CSDs, but instead +to use _SSDs_ (Server Side Decorations) when the compositor supports +it. + +*preferred* + Which type of window decorations to prefer: *client* (CSD) or + *server* (SSD). Note that this is only a hint to the + compositor. Depending on the compositor's configuration and + capabilities, it may not have any effect. Default: _server_. + +*titlebar* + Height, in pixels (but subject to output scaling), of the + titlebar, not including the window border. Default: _26_. + +*border* + Width, in pixels (but subject to output scaling), of the + borders. Default: _5_. + +*titlebar-color* + Titlebar AARRGGBB color. Note that unlike the other color values, + the *titlebar-color* value also has an _alpha_ component. Default: + use the default _foreground_ color. + +*border-color* + Border AARRGGBB color. Note that unlike the other color values, + the *border-color* value also has an _alpha_ component. Default: + _transparent_. + # FONT FORMAT The font is specified in FontConfig syntax. That is, a colon-separated diff --git a/footrc b/footrc index e6010eb2..7eea3ada 100644 --- a/footrc +++ b/footrc @@ -33,3 +33,10 @@ # bright6=b3ffff # bright7=ffffff # alpha=1.0 + +[csd] +# preferred=server +# titlebar=26 +# border=5 +# titlebar-color= +# border-color=00000000 diff --git a/input.c b/input.c index 2fde9ca4..dbb8ec33 100644 --- a/input.c +++ b/input.c @@ -21,6 +21,7 @@ #define LOG_MODULE "input" #define LOG_ENABLE_DBG 0 #include "log.h" +#include "config.h" #include "commands.h" #include "keymap.h" #include "render.h" @@ -616,6 +617,7 @@ input_repeat(struct wayland *wayl, uint32_t key) static bool is_top_left(const struct terminal *term, int x, int y) { + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_LEFT && y < 10 * term->scale) || (term->active_surface == TERM_SURF_BORDER_TOP && x < (10 + csd_border_size) * term->scale)); @@ -624,6 +626,7 @@ is_top_left(const struct terminal *term, int x, int y) static bool is_top_right(const struct terminal *term, int x, int y) { + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_RIGHT && y < 10 * term->scale) || (term->active_surface == TERM_SURF_BORDER_TOP && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale)); @@ -632,6 +635,8 @@ is_top_right(const struct terminal *term, int x, int y) static bool is_bottom_left(const struct terminal *term, int x, int y) { + int csd_title_size = term->conf->csd.title_height; + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_LEFT && y > csd_title_size * term->scale + term->height) || (term->active_surface == TERM_SURF_BORDER_BOTTOM && x < (10 + csd_border_size) * term->scale)); @@ -640,6 +645,8 @@ is_bottom_left(const struct terminal *term, int x, int y) static bool is_bottom_right(const struct terminal *term, int x, int y) { + int csd_title_size = term->conf->csd.title_height; + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_RIGHT && y > csd_title_size * term->scale + term->height) || (term->active_surface == TERM_SURF_BORDER_BOTTOM && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale)); @@ -648,22 +655,14 @@ is_bottom_right(const struct terminal *term, int x, int y) static const char * xcursor_for_csd_border(struct terminal *term, int x, int y) { - if (is_top_left(term, x, y)) - return "top_left_corner"; - else if (is_top_right(term, x, y)) - return "top_right_corner"; - else if (is_bottom_left(term, x, y)) - return "bottom_left_corner"; - else if (is_bottom_right(term, x, y)) - return "bottom_right_corner"; - else if (term->active_surface == TERM_SURF_BORDER_LEFT) - return "left_side"; - else if (term->active_surface == TERM_SURF_BORDER_RIGHT) - return "right_side"; - else if (term->active_surface == TERM_SURF_BORDER_TOP) - return "top_side"; - else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) - return"bottom_side"; + if (is_top_left(term, x, y)) return "top_left_corner"; + else if (is_top_right(term, x, y)) return "top_right_corner"; + else if (is_bottom_left(term, x, y)) return "bottom_left_corner"; + else if (is_bottom_right(term, x, y)) return "bottom_right_corner"; + else if (term->active_surface == TERM_SURF_BORDER_LEFT) return "left_side"; + else if (term->active_surface == TERM_SURF_BORDER_RIGHT) return "right_side"; + else if (term->active_surface == TERM_SURF_BORDER_TOP) return "top_side"; + else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return"bottom_side"; else { assert(false); return NULL; diff --git a/render.c b/render.c index 740d3e55..f08c4cf4 100644 --- a/render.c +++ b/render.c @@ -25,9 +25,6 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) -const int csd_border_size = 5; -const int csd_title_size = 26; - struct renderer { struct fdm *fdm; struct wayland *wayl; @@ -680,12 +677,11 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) /* Only title bar is rendered in maximized mode */ const int border_width = !term->window->is_maximized - ? csd_border_size * term->scale : 0; + ? term->conf->csd.border_width * term->scale : 0; const int title_height = !term->window->is_fullscreen - ? csd_title_size * term->scale : 0; + ? term->conf->csd.title_height * term->scale : 0; -#if FOOT_CSD_OUTSIDE switch (surf_idx) { case CSD_SURF_TITLE: return (struct csd_data){ 0, -title_height, term->width, title_height}; case CSD_SURF_LEFT: return (struct csd_data){-border_width, -title_height, border_width, title_height + term->height}; @@ -697,18 +693,6 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) assert(false); return (struct csd_data){0}; } -#else - switch (surf_idx) { - case CSD_SURF_TITLE: return (struct csd_data){ border_width, border_width, term->width - 2 * border_width, title_height}; - case CSD_SURF_LEFT: return (struct csd_data){ 0, border_width, border_width, term->height - 2 * border_width}; - case CSD_SURF_RIGHT: return (struct csd_data){term->width - border_width, border_width, border_width, term->height - 2 * border_width}; - case CSD_SURF_TOP: return (struct csd_data){ 0, 0, term->width, border_width}; - - case CSD_SURF_COUNT: - assert(false); - return (struct csd_data){0}; - } -#endif assert(false); return (struct csd_data){0}; @@ -749,18 +733,18 @@ render_csd_title(struct terminal *term) struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); - pixman_color_t color = color_hex_to_pixman(term->colors.fg); + uint32_t _color = term->colors.fg; + uint16_t alpha = 0xffff; + + if (term->conf->csd.color.title_set) { + _color = term->conf->csd.color.title; + alpha = _color >> 24 | (_color >> 24 << 8); + } + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) pixman_color_dim(&color); - struct wl_region *region = wl_compositor_create_region(term->wl->compositor); - if (region != NULL) { - wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); - wl_surface_set_opaque_region(surf, region); - wl_region_destroy(region); - } - render_csd_part(term, surf, buf, info.width, info.height, &color); } @@ -782,8 +766,15 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); - pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0); + uint32_t _color = 0; + uint16_t alpha = 0; + + if (term->conf->csd.color.border_set) { + _color = term->conf->csd.color.border; + alpha = _color >> 24 | (_color >> 24 << 8); + } + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) pixman_color_dim(&color); render_csd_part(term, surf, buf, info.width, info.height, &color); @@ -1145,12 +1136,7 @@ render_search_box(struct terminal *term) assert(term->scale >= 1); const int scale = term->scale; -#if FOOT_CSD_OUTSIDE - const int csd = 0; -#else - const int csd = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; -#endif - const size_t margin = csd + 3 * scale; + const size_t margin = 3 * scale; const size_t width = term->width - 2 * margin; const size_t visible_width = min( @@ -1264,15 +1250,6 @@ maybe_resize(struct terminal *term, int width, int height, bool force) width *= scale; height *= scale; - /* Scaled CSD border + title bar sizes */ -#if FOOT_CSD_OUTSIDE - const int csd_border = 0; - const int csd_title = 0; -#else - const int csd_border = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; - const int csd_title = term->window->use_csd == CSD_YES ? csd_title_size * scale : 0; -#endif - if (width == 0 && height == 0) { /* * The compositor is letting us choose the size @@ -1293,10 +1270,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force) /* Account for CSDs, to make actual window size match * the configured size */ if (!term->window->is_maximized) { - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; + width -= 2 * term->conf->csd.border_width; + height -= 2 * term->conf->csd.border_width + term->conf->csd.title_height; } else { - height -= csd_title_size; + height -= term->conf->csd.title_height; } } @@ -1305,24 +1282,23 @@ maybe_resize(struct terminal *term, int width, int height, bool force) } } - const int csd_x = 2 * csd_border; - const int csd_y = 2 * csd_border + csd_title; - - /* Padding */ - const int pad_x = scale * term->conf->pad_x; - const int pad_y = scale * term->conf->pad_y; - /* Don't shrink grid too much */ const int min_cols = 20; const int min_rows = 4; /* Minimum window size */ - const int min_width = csd_x + 2 * pad_x + min_cols * term->cell_width; - const int min_height = csd_y + 2 * pad_y + min_rows * term->cell_height; + const int min_width = min_cols * term->cell_width; + const int min_height = min_rows * term->cell_height; width = max(width, min_width); height = max(height, min_height); + /* Padding */ + const int max_pad_x = (width - min_width) / 2; + const int max_pad_y = (height - min_height) / 2; + const int pad_x = min(max_pad_x, scale * term->conf->pad_x); + const int pad_y = min(max_pad_y, scale * term->conf->pad_y); + if (!force && width == term->width && height == term->height && scale == term->scale) return false; @@ -1342,8 +1318,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int old_rows = term->rows; /* Screen rows/cols after resize */ - const int new_cols = (term->width - 2 * pad_x - csd_x) / term->cell_width; - const int new_rows = (term->height - 2 * pad_y - csd_y) / term->cell_height; + const int new_cols = (term->width - 2 * pad_x) / term->cell_width; + const int new_rows = (term->height - 2 * pad_y) / term->cell_height; /* Grid rows/cols after resize */ const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1)); @@ -1353,15 +1329,15 @@ maybe_resize(struct terminal *term, int width, int height, bool force) assert(new_rows >= 1); /* Margins */ - term->margins.left = csd_border + pad_x; - term->margins.top = csd_border + csd_title + pad_y; + term->margins.left = pad_x; + term->margins.top = pad_y; term->margins.right = term->width - new_cols * term->cell_width - term->margins.left; term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top; - assert(term->margins.left >= csd_border + pad_x); - assert(term->margins.right >= csd_border + pad_x); - assert(term->margins.top >= csd_border + csd_title + pad_y); - assert(term->margins.bottom >= csd_border + pad_y); + assert(term->margins.left >= pad_x); + assert(term->margins.right >= pad_x); + assert(term->margins.top >= pad_y); + assert(term->margins.bottom >= pad_y); if (new_cols == old_cols && new_rows == old_rows) { LOG_DBG("grid layout unaffected; skipping reflow"); diff --git a/wayland.c b/wayland.c index 957f736e..c5272994 100644 --- a/wayland.c +++ b/wayland.c @@ -536,18 +536,14 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, * sub-surfaces. Thus, since our resize code assumes the size * to resize to is the main window only, adjust the size here, * to account for the CSDs. - * - * Of course this does *not* apply when we position the CSDs - * *inside* the main surface. */ -#if FOOT_CSD_OUTSIDE + const struct config *conf = win->term->conf; if (!is_maximized) { - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; + width -= 2 * conf->csd.border_width; + height -= 2 * conf->csd.border_width + conf->csd.title_height; } else { - height -= csd_title_size; + height -= conf->csd.title_height; } -#endif } win->configure.is_activated = is_activated; @@ -670,18 +666,18 @@ xdg_toplevel_decoration_configure(void *data, if (win->is_configured && win->use_csd == CSD_YES) { struct terminal *term = win->term; - int scale = term->scale; + const struct config *conf = term->conf; + int scale = term->scale; int width = term->width / scale; int height = term->height / scale; -#if FOOT_CSD_OUTSIDE if (!term->window->is_maximized) { - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; + width -= 2 * conf->csd.border_width; + height -= 2 * conf->csd.border_width + conf->csd.title_height; } else - height -= csd_title_size; -#endif + height -= conf->csd.title_height; + render_resize_force(term, width, height); } } @@ -1013,6 +1009,7 @@ struct wl_window * wayl_win_init(struct terminal *term) { struct wayland *wayl = term->wl; + const struct config *conf = wayl->conf; struct wl_window *win = calloc(1, sizeof(*win)); win->term = term; @@ -1050,8 +1047,16 @@ wayl_win_init(struct terminal *term) if (wayl->xdg_decoration_manager != NULL) { win->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( wayl->xdg_decoration_manager, win->xdg_toplevel); + + LOG_INFO("preferring %s decorations", + conf->csd.preferred == CONF_CSD_PREFER_SERVER ? "SSD" : "CSD"); + zxdg_toplevel_decoration_v1_set_mode( - win->xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + win->xdg_toplevel_decoration, + (conf->csd.preferred == CONF_CSD_PREFER_SERVER + ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE + : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE)); + zxdg_toplevel_decoration_v1_add_listener( win->xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, win); } else { diff --git a/wayland.h b/wayland.h index b879c319..f94ad0e5 100644 --- a/wayland.h +++ b/wayland.h @@ -82,15 +82,6 @@ struct wl_primary { uint32_t serial; }; -/* I'd prefer to position the CSD sub-surfaces outside the main - * surface. Unfortunately, a lot of compositors doesn't handle this - * correctly. When this define is 0, we instead position the CSD - * sub-surfaces inside the main surface, and offset the grid content - * accordingly. */ -#define FOOT_CSD_OUTSIDE 1 -extern const int csd_border_size; -extern const int csd_title_size; - enum csd_surface { CSD_SURF_TITLE, CSD_SURF_LEFT, -- cgit v1.3 From 9699c9b8bfcbd7f9ebef5ee4ffe370cb03b1c8a2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 20:29:28 +0100 Subject: csd: initial implementation of minimize/maximize/close buttons --- config.c | 47 ++++++++++++++++++++++++++++++++-- config.h | 7 +++++ doc/foot.5.scd | 34 ++++++++++++++++++------ footrc | 8 ++++-- input.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ render.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- render.h | 1 + terminal.c | 16 ++++++++---- terminal.h | 3 +++ wayland.c | 6 ++++- wayland.h | 7 +++-- 11 files changed, 268 insertions(+), 21 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index 983cda99..ef7f9a25 100644 --- a/config.c +++ b/config.c @@ -372,7 +372,7 @@ parse_section_csd(const char *key, const char *value, struct config *conf, conf->csd.color.border = color; } - else if (strcmp(key, "titlebar") == 0) { + else if (strcmp(key, "titlebar-size") == 0) { unsigned long pixels; if (!str_to_ulong(value, 10, &pixels)) { LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); @@ -382,7 +382,7 @@ parse_section_csd(const char *key, const char *value, struct config *conf, conf->csd.title_height = pixels; } - else if (strcmp(key, "border") == 0) { + else if (strcmp(key, "border-width") == 0) { unsigned long pixels; if (!str_to_ulong(value, 10, &pixels)) { LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); @@ -392,6 +392,48 @@ parse_section_csd(const char *key, const char *value, struct config *conf, conf->csd.border_width = pixels; } + else if (strcmp(key, "button-width") == 0) { + unsigned long pixels; + if (!str_to_ulong(value, 10, &pixels)) { + LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); + return false; + } + + conf->csd.button_width = pixels; + } + + else if (strcmp(key, "button-minimize-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid button-minimize-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.minimize_set = true; + conf->csd.color.minimize = color; + } + + else if (strcmp(key, "button-maximize-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid button-maximize-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.maximize_set = true; + conf->csd.color.maximize = color; + } + + else if (strcmp(key, "button-close-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid button-close-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.close_set = true; + conf->csd.color.close = color; + } return true; } @@ -602,6 +644,7 @@ config_load(struct config *conf, const char *conf_path) .preferred = CONF_CSD_PREFER_SERVER, .title_height = 26, .border_width = 5, + .button_width = 22, .color = { .title_set = false, .border_set = false, diff --git a/config.h b/config.h index fa765476..dd34c589 100644 --- a/config.h +++ b/config.h @@ -41,12 +41,19 @@ struct config { int title_height; int border_width; + int button_width; struct { bool title_set; bool border_set; + bool minimize_set; + bool maximize_set; + bool close_set; uint32_t title; uint32_t border; + uint32_t minimize; + uint32_t maximize; + uint32_t close; } color; } csd; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 99240b21..778809a4 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -83,6 +83,10 @@ applications can change these runtime. This section controls the 16 ANSI colors and the default foreground and background colors. Note that applications can change these runtime. +The colors are in RRGGBB format. That is, they do *not* have an alpha +component. You can configure the background transparency with the +_alpha_ option. + *foreground* Default RRGGBB foreground color. This is the color used when no ANSI color is being used. Default: _dcdccc_. @@ -112,29 +116,43 @@ Decorations). Note that the default is to *not* use CSDs, but instead to use _SSDs_ (Server Side Decorations) when the compositor supports it. +Note that unlike the colors defined in the _colors_ section, the color +values here are in AARRGGBB format. I.e. they contain an alpha +component. + *preferred* Which type of window decorations to prefer: *client* (CSD) or *server* (SSD). Note that this is only a hint to the compositor. Depending on the compositor's configuration and capabilities, it may not have any effect. Default: _server_. -*titlebar* +*titlebar-size* Height, in pixels (but subject to output scaling), of the titlebar, not including the window border. Default: _26_. -*border* +*border-width* Width, in pixels (but subject to output scaling), of the borders. Default: _5_. *titlebar-color* - Titlebar AARRGGBB color. Note that unlike the other color values, - the *titlebar-color* value also has an _alpha_ component. Default: - use the default _foreground_ color. + Titlebar AARRGGBB color. Default: use the default _foreground_ + color. *border-color* - Border AARRGGBB color. Note that unlike the other color values, - the *border-color* value also has an _alpha_ component. Default: - _transparent_. + Border AARRGGBB color. Default: _transparent_. + +*button-width* + Width, in pixels (but subject to output scaling), of the + minimize/maximize/close buttons. Default: _22_. + +*button-minimize-color* + Minimize button's AARRGGBB color. Default: _ff0000ff_. + +*button-maximize-color* + Maximize button's AARRGGBB color. Default: _ff00ff00_. + +*button-close-color* + Close button's AARRGGBB color. Default: _ffff0000_. # FONT FORMAT diff --git a/footrc b/footrc index 7078ff43..a9bce529 100644 --- a/footrc +++ b/footrc @@ -36,7 +36,11 @@ [csd] # preferred=server -# titlebar=26 -# border=5 +# titlebar-size=26 +# border-width=5 # titlebar-color= # border-color=00000000 +# button-width=22 +# button-minimize-color=ff0000ff +# button-maximize-color=ff00ff00 +# button-close-color=ffff0000 diff --git a/input.c b/input.c index 2526807a..5ca13785 100644 --- a/input.c +++ b/input.c @@ -24,6 +24,7 @@ #include "config.h" #include "commands.h" #include "keymap.h" +#include "quirks.h" #include "render.h" #include "search.h" #include "selection.h" @@ -708,6 +709,28 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, render_xcursor_set(term); break; + case TERM_SURF_BUTTON_MINIMIZE: + case TERM_SURF_BUTTON_MAXIMIZE: + case TERM_SURF_BUTTON_CLOSE: { + enum csd_surface idx = + term->active_surface == TERM_SURF_BUTTON_MINIMIZE ? CSD_SURF_MINIMIZE : + term->active_surface == TERM_SURF_BUTTON_MAXIMIZE ? CSD_SURF_MAXIMIZE : + CSD_SURF_CLOSE; + + quirk_weston_subsurface_desync_on(term->window->csd.sub_surface[CSD_SURF_TITLE]); + quirk_weston_subsurface_desync_on(term->window->csd.sub_surface[idx]); + + render_csd_button(term, idx); + + quirk_weston_subsurface_desync_off(term->window->csd.sub_surface[idx]); + quirk_weston_subsurface_desync_off(term->window->csd.sub_surface[CSD_SURF_TITLE]); + wl_surface_commit(win->surface); + + term->xcursor = "left_ptr"; + render_xcursor_set(term); + break; + } + case TERM_SURF_NONE: assert(false); break; @@ -746,8 +769,43 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, = wl_surface_get_user_data(surface); assert(old_moused == win->term); } + + enum term_surface active_surface = old_moused->active_surface; + old_moused->active_surface = TERM_SURF_NONE; term_xcursor_update(old_moused); + + switch (active_surface) { + case TERM_SURF_BUTTON_MINIMIZE: + case TERM_SURF_BUTTON_MAXIMIZE: + case TERM_SURF_BUTTON_CLOSE: { + enum csd_surface idx = + active_surface == TERM_SURF_BUTTON_MINIMIZE ? CSD_SURF_MINIMIZE : + active_surface == TERM_SURF_BUTTON_MAXIMIZE ? CSD_SURF_MAXIMIZE : + CSD_SURF_CLOSE; + + quirk_weston_subsurface_desync_on(old_moused->window->csd.sub_surface[CSD_SURF_TITLE]); + quirk_weston_subsurface_desync_on(old_moused->window->csd.sub_surface[idx]); + + render_csd_button(old_moused, idx); + + quirk_weston_subsurface_desync_off(old_moused->window->csd.sub_surface[idx]); + quirk_weston_subsurface_desync_off(old_moused->window->csd.sub_surface[CSD_SURF_TITLE]); + wl_surface_commit(old_moused->window->surface); + break; + } + + case TERM_SURF_NONE: + case TERM_SURF_GRID: + case TERM_SURF_SEARCH: + case TERM_SURF_TITLE: + case TERM_SURF_BORDER_LEFT: + case TERM_SURF_BORDER_RIGHT: + case TERM_SURF_BORDER_TOP: + case TERM_SURF_BORDER_BOTTOM: + break; + } + } } @@ -787,6 +845,9 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, switch (term->active_surface) { case TERM_SURF_NONE: case TERM_SURF_SEARCH: + case TERM_SURF_BUTTON_MINIMIZE: + case TERM_SURF_BUTTON_MAXIMIZE: + case TERM_SURF_BUTTON_CLOSE: break; case TERM_SURF_TITLE: @@ -976,6 +1037,26 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, return; } + case TERM_SURF_BUTTON_MINIMIZE: + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + xdg_toplevel_set_minimized(term->window->xdg_toplevel); + break; + + case TERM_SURF_BUTTON_MAXIMIZE: + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) { + if (term->window->is_maximized) + xdg_toplevel_unset_maximized(term->window->xdg_toplevel); + else + xdg_toplevel_set_maximized(term->window->xdg_toplevel); + } + break; + + case TERM_SURF_BUTTON_CLOSE: + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + term_shutdown(term); + //LOG_ERR("unimplemented: terminate"); + break; + case TERM_SURF_SEARCH: break; diff --git a/render.c b/render.c index f08c4cf4..c24c41cc 100644 --- a/render.c +++ b/render.c @@ -682,6 +682,9 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) const int title_height = !term->window->is_fullscreen ? term->conf->csd.title_height * term->scale : 0; + const int button_width = !term->window->is_fullscreen + ? term->conf->csd.button_width * term->scale : 0; + switch (surf_idx) { case CSD_SURF_TITLE: return (struct csd_data){ 0, -title_height, term->width, title_height}; case CSD_SURF_LEFT: return (struct csd_data){-border_width, -title_height, border_width, title_height + term->height}; @@ -689,6 +692,11 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) case CSD_SURF_TOP: return (struct csd_data){-border_width, -title_height - border_width, term->width + 2 * border_width, border_width}; case CSD_SURF_BOTTOM: return (struct csd_data){-border_width, term->height, term->width + 2 * border_width, border_width}; + /* Positioned relative to CSD_SURF_TITLE */ + case CSD_SURF_MINIMIZE: return (struct csd_data){term->width - 3 * button_width, 0, button_width, title_height}; + case CSD_SURF_MAXIMIZE: return (struct csd_data){term->width - 2 * button_width, 0, button_width, title_height}; + case CSD_SURF_CLOSE: return (struct csd_data){term->width - 1 * button_width, 0, button_width, title_height}; + case CSD_SURF_COUNT: assert(false); return (struct csd_data){0}; @@ -780,6 +788,73 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) render_csd_part(term, surf, buf, info.width, info.height, &color); } +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; + + struct csd_data info = get_csd_data(term, surf_idx); + struct wl_surface *surf = term->window->csd.surface[surf_idx]; + + if (info.width == 0 || info.height == 0) + return; + + unsigned long cookie = shm_cookie_csd(term, surf_idx); + struct buffer *buf = shm_get_buffer( + term->wl->shm, info.width, info.height, cookie); + + uint32_t _color; + uint16_t alpha = 0xffff; + bool is_active = false; + const bool *is_set = NULL; + const uint32_t *conf_color = NULL; + + switch (surf_idx) { + case CSD_SURF_MINIMIZE: + _color = 0xff0000ff; + is_set = &term->conf->csd.color.minimize_set; + conf_color = &term->conf->csd.color.minimize; + is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE; + break; + + case CSD_SURF_MAXIMIZE: + _color = 0xff00ff00; + is_set = &term->conf->csd.color.maximize_set; + conf_color = &term->conf->csd.color.maximize; + is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE; + break; + + case CSD_SURF_CLOSE: + _color = 0xffff0000; + is_set = &term->conf->csd.color.close_set; + conf_color = &term->conf->csd.color.close; + is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE; + break; + + default: + assert(false); + break; + } + + if (is_active) { + if (*is_set) { + _color = *conf_color; + alpha = _color >> 24 | (_color >> 24 << 8); + } + } else { + _color = 0; + alpha = 0; + } + + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); + if (!term->visual_focus) + pixman_color_dim(&color); + render_csd_part(term, surf, buf, info.width, info.height, &color); +} + void render_csd(struct terminal *term) { @@ -798,7 +873,7 @@ render_csd(struct terminal *term) if (width == 0 || height == 0) { /* CSD borders aren't rendered in maximized mode */ - assert(term->window->is_maximized); + assert(term->window->is_maximized || term->window->is_fullscreen); wl_subsurface_set_position(sub, 0, 0); wl_surface_attach(surf, NULL, 0, 0); wl_surface_commit(surf); @@ -811,6 +886,8 @@ render_csd(struct terminal *term) render_csd_title(term); for (size_t i = CSD_SURF_LEFT; i <= CSD_SURF_BOTTOM; i++) render_csd_border(term, i); + for (size_t i = CSD_SURF_MINIMIZE; i < CSD_SURF_COUNT; i++) + render_csd_button(term, i); } static void frame_callback( diff --git a/render.h b/render.h index 2177e8bd..cccf2001 100644 --- a/render.h +++ b/render.h @@ -19,6 +19,7 @@ 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; diff --git a/terminal.c b/terminal.c index 290a1425..c57b3c1c 100644 --- a/terminal.c +++ b/terminal.c @@ -2149,16 +2149,22 @@ term_surface_kind(const struct terminal *term, const struct wl_surface *surface) return TERM_SURF_GRID; else if (surface == term->window->search_surface) return TERM_SURF_SEARCH; - else if (surface == term->window->csd.surface[0]) + else if (surface == term->window->csd.surface[CSD_SURF_TITLE]) return TERM_SURF_TITLE; - else if (surface == term->window->csd.surface[1]) + else if (surface == term->window->csd.surface[CSD_SURF_LEFT]) return TERM_SURF_BORDER_LEFT; - else if (surface == term->window->csd.surface[2]) + else if (surface == term->window->csd.surface[CSD_SURF_RIGHT]) return TERM_SURF_BORDER_RIGHT; - else if (surface == term->window->csd.surface[3]) + else if (surface == term->window->csd.surface[CSD_SURF_TOP]) return TERM_SURF_BORDER_TOP; - else if (surface == term->window->csd.surface[4]) + else if (surface == term->window->csd.surface[CSD_SURF_BOTTOM]) return TERM_SURF_BORDER_BOTTOM; + else if (surface == term->window->csd.surface[CSD_SURF_MINIMIZE]) + return TERM_SURF_BUTTON_MINIMIZE; + else if (surface == term->window->csd.surface[CSD_SURF_MAXIMIZE]) + return TERM_SURF_BUTTON_MAXIMIZE; + else if (surface == term->window->csd.surface[CSD_SURF_CLOSE]) + return TERM_SURF_BUTTON_CLOSE; else return TERM_SURF_NONE; } diff --git a/terminal.h b/terminal.h index df3fb06a..3731ee0d 100644 --- a/terminal.h +++ b/terminal.h @@ -194,6 +194,9 @@ enum term_surface { TERM_SURF_BORDER_RIGHT, TERM_SURF_BORDER_TOP, TERM_SURF_BORDER_BOTTOM, + TERM_SURF_BUTTON_MINIMIZE, + TERM_SURF_BUTTON_MAXIMIZE, + TERM_SURF_BUTTON_CLOSE, }; struct terminal { diff --git a/wayland.c b/wayland.c index 95d2880e..26982815 100644 --- a/wayland.c +++ b/wayland.c @@ -47,8 +47,12 @@ csd_instantiate(struct wl_window *win) assert(win->csd.sub_surface[i] == NULL); win->csd.surface[i] = wl_compositor_create_surface(wayl->compositor); + + struct wl_surface *parent = i < CSD_SURF_MINIMIZE + ? win->surface : win->csd.surface[CSD_SURF_TITLE]; + win->csd.sub_surface[i] = wl_subcompositor_get_subsurface( - wayl->sub_compositor, win->csd.surface[i], win->surface); + wayl->sub_compositor, win->csd.surface[i], parent); wl_subsurface_set_sync(win->csd.sub_surface[i]); wl_surface_set_user_data(win->csd.surface[i], win); diff --git a/wayland.h b/wayland.h index f94ad0e5..ed53591d 100644 --- a/wayland.h +++ b/wayland.h @@ -88,6 +88,9 @@ enum csd_surface { CSD_SURF_RIGHT, CSD_SURF_TOP, CSD_SURF_BOTTOM, + CSD_SURF_MINIMIZE, + CSD_SURF_MAXIMIZE, + CSD_SURF_CLOSE, CSD_SURF_COUNT, }; @@ -103,8 +106,8 @@ struct wl_window { enum {CSD_UNKNOWN, CSD_NO, CSD_YES } use_csd; struct { - struct wl_surface *surface[5]; - struct wl_subsurface *sub_surface[5]; + struct wl_surface *surface[CSD_SURF_COUNT]; + struct wl_subsurface *sub_surface[CSD_SURF_COUNT]; int move_timeout_fd; uint32_t serial; } csd; -- cgit v1.3 From 20eaa152719156d06cf141db710d54283034cc82 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 21:06:15 +0100 Subject: render: initial minimize/maximize/close glyphs These are really ugly, but is meant to get something up there, that can be polished afterwards. --- render.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 5 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index c24c41cc..c9aa8f78 100644 --- a/render.c +++ b/render.c @@ -706,6 +706,15 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) return (struct csd_data){0}; } +static void +csd_commit(struct terminal *term, struct wl_surface *surf, struct buffer *buf) +{ + wl_surface_attach(surf, buf->wl_buf, 0, 0); + wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); + wl_surface_set_buffer_scale(surf, term->scale); + wl_surface_commit(surf); +} + static void render_csd_part(struct terminal *term, struct wl_surface *surf, struct buffer *buf, @@ -719,11 +728,6 @@ render_csd_part(struct terminal *term, PIXMAN_OP_SRC, buf->pix, color, 1, &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); pixman_image_unref(src); - - wl_surface_attach(surf, buf->wl_buf, 0, 0); - wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); - wl_surface_set_buffer_scale(surf, term->scale); - wl_surface_commit(surf); } void @@ -754,6 +758,7 @@ render_csd_title(struct terminal *term) pixman_color_dim(&color); render_csd_part(term, surf, buf, info.width, info.height, &color); + csd_commit(term, surf, buf); } static void @@ -786,6 +791,58 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) if (!term->visual_focus) pixman_color_dim(&color); render_csd_part(term, surf, buf, info.width, info.height, &color); + csd_commit(term, surf, buf); +} + +static void +render_csd_button_minimize(struct terminal *term, struct buffer *buf) +{ + pixman_color_t color = color_hex_to_pixman(0); + pixman_image_t *src = pixman_image_create_solid_fill(&color); + + int x_margin = (term->conf->csd.button_width * 1 / 4) * term->scale; + int y_margin = (term->conf->csd.title_height * 4 / 6) * term->scale; + + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, 1, + &(pixman_rectangle16_t){x_margin, y_margin, buf->width - 2 * x_margin, 1 * term->scale}); + + pixman_image_unref(src); +} + +static void +render_csd_button_maximize(struct terminal *term, struct buffer *buf) +{ + pixman_color_t color = color_hex_to_pixman(0); + pixman_image_t *src = pixman_image_create_solid_fill(&color); + + int x_margin = (term->conf->csd.button_width * 1 / 4) * term->scale; + int y_margin = (term->conf->csd.title_height * 2 / 6) * term->scale; + + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, 1, + &(pixman_rectangle16_t){x_margin, y_margin, buf->width - 2 * x_margin, 2 * term->scale}); + + pixman_image_unref(src); +} + +static void +render_csd_button_close(struct terminal *term, struct buffer *buf) +{ + pixman_color_t color = color_hex_to_pixman(0); + pixman_image_t *src = pixman_image_create_solid_fill(&color); + + int min_length = min(buf->width, buf->height); + int length = min_length / 2; + + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, 2, + (pixman_rectangle16_t[]){ + {(buf->width - length) / 2, buf->height / 2, length, 1 * term->scale}, + {buf->width / 2, (buf->height - length) / 2, 1 * term->scale, length}, + }); + + pixman_image_unref(src); } void @@ -853,6 +910,19 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) if (!term->visual_focus) pixman_color_dim(&color); render_csd_part(term, surf, buf, info.width, info.height, &color); + + switch (surf_idx) { + case CSD_SURF_MINIMIZE: render_csd_button_minimize(term, buf); break; + case CSD_SURF_MAXIMIZE: render_csd_button_maximize(term, buf); break; + case CSD_SURF_CLOSE: render_csd_button_close(term, buf); break; + break; + + default: + assert(false); + break; + } + + csd_commit(term, surf, buf); } void -- cgit v1.3 From b14c217fb62bbdf4350c2877b889f42fe2ba69b8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 21:09:21 +0100 Subject: render: csd: minimize: change default color to a lighter blue --- doc/foot.5.scd | 2 +- render.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 778809a4..f4a263d8 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -146,7 +146,7 @@ component. minimize/maximize/close buttons. Default: _22_. *button-minimize-color* - Minimize button's AARRGGBB color. Default: _ff0000ff_. + Minimize button's AARRGGBB color. Default: _ff1e90ff_. *button-maximize-color* Maximize button's AARRGGBB color. Default: _ff00ff00_. diff --git a/render.c b/render.c index c9aa8f78..c3ea0744 100644 --- a/render.c +++ b/render.c @@ -871,7 +871,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) switch (surf_idx) { case CSD_SURF_MINIMIZE: - _color = 0xff0000ff; + _color = 0xff1e90ff; is_set = &term->conf->csd.color.minimize_set; conf_color = &term->conf->csd.color.minimize; is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE; -- cgit v1.3 From 63a3d6ce03f0de8bf5f1d7d8ccc789970c8c11c8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 21:10:25 +0100 Subject: render: csd: close: change default color to a lighter blue --- doc/foot.5.scd | 2 +- render.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/doc/foot.5.scd b/doc/foot.5.scd index f4a263d8..8d5f9bab 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -152,7 +152,7 @@ component. Maximize button's AARRGGBB color. Default: _ff00ff00_. *button-close-color* - Close button's AARRGGBB color. Default: _ffff0000_. + Close button's AARRGGBB color. Default: _ffff3030_. # FONT FORMAT diff --git a/render.c b/render.c index c3ea0744..468b2d31 100644 --- a/render.c +++ b/render.c @@ -885,7 +885,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) break; case CSD_SURF_CLOSE: - _color = 0xffff0000; + _color = 0xffff3030; is_set = &term->conf->csd.color.close_set; conf_color = &term->conf->csd.color.close; is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE; -- cgit v1.3 From cb6616ef8ac9f778a4e86b713033d0355dc27279 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 21:11:17 +0100 Subject: render: csd: maximize: change default color to a lighter green --- doc/foot.5.scd | 2 +- render.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 8d5f9bab..3d775cb5 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -149,7 +149,7 @@ component. Minimize button's AARRGGBB color. Default: _ff1e90ff_. *button-maximize-color* - Maximize button's AARRGGBB color. Default: _ff00ff00_. + Maximize button's AARRGGBB color. Default: _ff30ff30_. *button-close-color* Close button's AARRGGBB color. Default: _ffff3030_. diff --git a/render.c b/render.c index 468b2d31..52c80e08 100644 --- a/render.c +++ b/render.c @@ -878,7 +878,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) break; case CSD_SURF_MAXIMIZE: - _color = 0xff00ff00; + _color = 0xff30ff30; is_set = &term->conf->csd.color.maximize_set; conf_color = &term->conf->csd.color.maximize; is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE; -- cgit v1.3 From c90d70b2bfc93fa7bf58f9e8805a55b191828886 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:18:59 +0100 Subject: config: CSD borders are always invisible That is, remove all configuration options and always draw them fully transparent. --- config.c | 29 ++--------------------------- config.h | 2 -- doc/foot.5.scd | 17 +++++------------ footrc | 6 ++---- render.c | 12 +----------- 5 files changed, 10 insertions(+), 56 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index ef7f9a25..158eabec 100644 --- a/config.c +++ b/config.c @@ -350,7 +350,7 @@ parse_section_csd(const char *key, const char *value, struct config *conf, } } - else if (strcmp(key, "titlebar-color") == 0) { + else if (strcmp(key, "color") == 0) { uint32_t color; if (!str_to_color(value, &color, true, path, lineno)) { LOG_ERR("%s:%d: invalid titlebar-color: %s", path, lineno, value); @@ -361,18 +361,7 @@ parse_section_csd(const char *key, const char *value, struct config *conf, conf->csd.color.title = color; } - else if (strcmp(key, "border-color") == 0) { - uint32_t color; - if (!str_to_color(value, &color, true, path, lineno)) { - LOG_ERR("%s:%d: invalid border-color: %s", path, lineno, value); - return false; - } - - conf->csd.color.border_set = true; - conf->csd.color.border = color; - } - - else if (strcmp(key, "titlebar-size") == 0) { + else if (strcmp(key, "size") == 0) { unsigned long pixels; if (!str_to_ulong(value, 10, &pixels)) { LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); @@ -382,16 +371,6 @@ parse_section_csd(const char *key, const char *value, struct config *conf, conf->csd.title_height = pixels; } - else if (strcmp(key, "border-width") == 0) { - unsigned long pixels; - if (!str_to_ulong(value, 10, &pixels)) { - LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); - return false; - } - - conf->csd.border_width = pixels; - } - else if (strcmp(key, "button-width") == 0) { unsigned long pixels; if (!str_to_ulong(value, 10, &pixels)) { @@ -645,10 +624,6 @@ config_load(struct config *conf, const char *conf_path) .title_height = 26, .border_width = 5, .button_width = 22, - .color = { - .title_set = false, - .border_set = false, - }, }, .render_worker_count = sysconf(_SC_NPROCESSORS_ONLN), diff --git a/config.h b/config.h index dd34c589..a89637e1 100644 --- a/config.h +++ b/config.h @@ -45,12 +45,10 @@ struct config { struct { bool title_set; - bool border_set; bool minimize_set; bool maximize_set; bool close_set; uint32_t title; - uint32_t border; uint32_t minimize; uint32_t maximize; uint32_t close; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 3d775cb5..69c6f385 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -126,23 +126,16 @@ component. compositor. Depending on the compositor's configuration and capabilities, it may not have any effect. Default: _server_. -*titlebar-size* - Height, in pixels (but subject to output scaling), of the - titlebar, not including the window border. Default: _26_. +*size* + Height, in pixels (subject to output scaling), of the + titlebar. Default: _26_. -*border-width* - Width, in pixels (but subject to output scaling), of the - borders. Default: _5_. - -*titlebar-color* +*color* Titlebar AARRGGBB color. Default: use the default _foreground_ color. -*border-color* - Border AARRGGBB color. Default: _transparent_. - *button-width* - Width, in pixels (but subject to output scaling), of the + Width, in pixels (subject to output scaling), of the minimize/maximize/close buttons. Default: _22_. *button-minimize-color* diff --git a/footrc b/footrc index a9bce529..e2799fdd 100644 --- a/footrc +++ b/footrc @@ -36,10 +36,8 @@ [csd] # preferred=server -# titlebar-size=26 -# border-width=5 -# titlebar-color= -# border-color=00000000 +# size=26 +# color= # button-width=22 # button-minimize-color=ff0000ff # button-maximize-color=ff00ff00 diff --git a/render.c b/render.c index 52c80e08..b422ef93 100644 --- a/render.c +++ b/render.c @@ -779,17 +779,7 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); - uint32_t _color = 0; - uint16_t alpha = 0; - - if (term->conf->csd.color.border_set) { - _color = term->conf->csd.color.border; - alpha = _color >> 24 | (_color >> 24 << 8); - } - - pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); - if (!term->visual_focus) - pixman_color_dim(&color); + pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0); render_csd_part(term, surf, buf, info.width, info.height, &color); csd_commit(term, surf, buf); } -- cgit v1.3 From c10f1d5459568d4883e55d3d7531594d6c93066b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:23:37 +0100 Subject: render: don't try to render CSDs when the terminal is shutting down --- render.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index b422ef93..771cfe64 100644 --- a/render.c +++ b/render.c @@ -736,6 +736,9 @@ render_csd_title(struct terminal *term) if (term->window->use_csd != CSD_YES) return; + if (term->is_shutting_down) + return; + struct csd_data info = get_csd_data(term, CSD_SURF_TITLE); struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE]; @@ -756,7 +759,6 @@ render_csd_title(struct terminal *term) pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) pixman_color_dim(&color); - render_csd_part(term, surf, buf, info.width, info.height, &color); csd_commit(term, surf, buf); } @@ -843,6 +845,9 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) if (term->window->use_csd != CSD_YES) return; + if (term->is_shutting_down) + return; + struct csd_data info = get_csd_data(term, surf_idx); struct wl_surface *surf = term->window->csd.surface[surf_idx]; @@ -921,6 +926,9 @@ render_csd(struct terminal *term) if (term->window->use_csd != CSD_YES) return; + if (term->is_shutting_down) + return; + for (size_t i = 0; i < CSD_SURF_COUNT; i++) { struct csd_data info = get_csd_data(term, i); const int x = info.x; -- cgit v1.3 From c9659ecd14d7d94d1c0b26cf1864606f994bd22e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:23:52 +0100 Subject: render: csd: don't even try to render CSDs when we're in fullscreen mode --- render.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 771cfe64..7d7da79e 100644 --- a/render.c +++ b/render.c @@ -929,6 +929,9 @@ render_csd(struct terminal *term) if (term->is_shutting_down) return; + if (term->window->is_fullscreen) + return; + for (size_t i = 0; i < CSD_SURF_COUNT; i++) { struct csd_data info = get_csd_data(term, i); const int x = info.x; -- cgit v1.3 From 09bb9bef33b6e9a2bbac830bd14dca1d14986e69 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:24:09 +0100 Subject: render: csd: center 'close' button's cross --- render.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 7d7da79e..dc884d17 100644 --- a/render.c +++ b/render.c @@ -830,8 +830,8 @@ render_csd_button_close(struct terminal *term, struct buffer *buf) pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix, &color, 2, (pixman_rectangle16_t[]){ - {(buf->width - length) / 2, buf->height / 2, length, 1 * term->scale}, - {buf->width / 2, (buf->height - length) / 2, 1 * term->scale, length}, + {(buf->width - length - term->scale) / 2, (buf->height - term->scale) / 2, length, 1 * term->scale}, + {(buf->width - term->scale) / 2, (buf->height - length - term->scale) / 2, 1 * term->scale, length}, }); pixman_image_unref(src); -- cgit v1.3 From da91a9de4b6b3d4501a053e1528abe4e44b3a726 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:24:31 +0100 Subject: render: csd: assert surfaces exist before trying to use them --- render.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index dc884d17..919cf8bd 100644 --- a/render.c +++ b/render.c @@ -942,6 +942,9 @@ render_csd(struct terminal *term) struct wl_surface *surf = term->window->csd.surface[i]; struct wl_subsurface *sub = term->window->csd.sub_surface[i]; + assert(surf != NULL); + assert(sub != NULL); + if (width == 0 || height == 0) { /* CSD borders aren't rendered in maximized mode */ assert(term->window->is_maximized || term->window->is_fullscreen); -- cgit v1.3 From 044556ef3e1a04173e4b1c12baa2947b08222fab Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:24:51 +0100 Subject: render: csd: render surfaces in reverse order This ensures the inner most child surfaces are rendered and comitted before the parent surfaces. --- render.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 919cf8bd..a492fb28 100644 --- a/render.c +++ b/render.c @@ -957,11 +957,11 @@ render_csd(struct terminal *term) wl_subsurface_set_position(sub, x / term->scale, y / term->scale); } - render_csd_title(term); for (size_t i = CSD_SURF_LEFT; i <= CSD_SURF_BOTTOM; i++) render_csd_border(term, i); - for (size_t i = CSD_SURF_MINIMIZE; i < CSD_SURF_COUNT; i++) + for (size_t i = CSD_SURF_MINIMIZE; i <= CSD_SURF_CLOSE; i++) render_csd_button(term, i); + render_csd_title(term); } static void frame_callback( -- cgit v1.3 From d76484ae50efb8ede95e6b0921bdb1fad26dccd9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:26:15 +0100 Subject: wayland: set window geometry to exclude the invisible CSD borders But it *does* include the title bar. This simplifies the 'adjustment' needed to be done to the configured window size. It also fixes a number of issues: * the compositor will now properly snap the window to screen edges (before, there was an empty space between the edge and the window - the CSD border). * This also removes the need for the mutter 'commit' workaround. We must be doing something right now. --- render.c | 30 ++++++++++++++++++++---------- wayland.c | 61 ++++++++----------------------------------------------------- 2 files changed, 28 insertions(+), 63 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index a492fb28..82abac4d 100644 --- a/render.c +++ b/render.c @@ -1416,16 +1416,9 @@ maybe_resize(struct terminal *term, int width, int height, bool force) height = term->conf->height; if (term->window->use_csd == CSD_YES) { + /* Take CSD title bar into account */ assert(!term->window->is_fullscreen); - - /* Account for CSDs, to make actual window size match - * the configured size */ - if (!term->window->is_maximized) { - width -= 2 * term->conf->csd.border_width; - height -= 2 * term->conf->csd.border_width + term->conf->csd.title_height; - } else { - height -= term->conf->csd.title_height; - } + height -= term->conf->csd.title_height; } width *= scale; @@ -1556,10 +1549,27 @@ damage_view: term->unmaximized_height = term->height; } + render_csd(term); + +#if 0 + /* TODO: doesn't include CSD title bar */ xdg_toplevel_set_min_size( term->window->xdg_toplevel, min_width / scale, min_height / scale); +#endif + + { + bool title_shown = !term->window->is_fullscreen && + term->window->use_csd == CSD_YES; + + int title_height = title_shown ? term->conf->csd.title_height : 0; + xdg_surface_set_window_geometry( + term->window->xdg_surface, + 0, + -title_height, + term->width / term->scale, + term->height / term->scale + title_height); + - render_csd(term); if (term->is_searching) render_search_box(term); diff --git a/wayland.c b/wayland.c index 38fafc49..f965767a 100644 --- a/wayland.c +++ b/wayland.c @@ -540,24 +540,14 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, */ struct wl_window *win = data; - if (!is_fullscreen && win->use_csd == CSD_YES && width != 0 && height != 0) { + if (!is_fullscreen && win->use_csd == CSD_YES && width > 0 && height > 0) { /* - * The size received here is the *total* window size. - * - * This *includes* the (negatively positioned) CSD - * sub-surfaces. Thus, since our resize code assumes the size - * to resize to is the main window only, adjust the size here, - * to account for the CSDs. + * We include the CSD title bar in our window geometry. Thus, + * the height we call render_resize() with must be adjusted, + * since it expects the size to refer to the main grid only. */ - const struct config *conf = win->term->conf; - if (!is_maximized) { - width -= 2 * conf->csd.border_width; - height -= 2 * conf->csd.border_width + conf->csd.title_height; - } else { - height -= conf->csd.title_height; - } + height -= win->term->conf->csd.title_height; } - win->configure.is_activated = is_activated; win->configure.is_fullscreen = is_fullscreen; win->configure.is_maximized = is_maximized; @@ -607,37 +597,7 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, else term_visual_focus_out(term); - static bool desktop_is_gnome = false; - static bool desktop_is_initialized = false; - - if (!desktop_is_initialized) { - const char *current_desktop = getenv("XDG_CURRENT_DESKTOP"); - - desktop_is_gnome = current_desktop != NULL && - strcasestr(current_desktop, "gnome") != NULL; - - if (desktop_is_gnome) - LOG_WARN("applying wl_surface_commit() workaround for mutter"); - - desktop_is_initialized = true; - } - - if (desktop_is_gnome) { - /* - * Resizing the window under mutter causes the "other" side to - * jump back and forth, *even* if we re-render and commit a - * properly resized frame immediately. - * - * For that reason, the code path below also does not work, - * since in case we *did* resize, it appears the commit - * happens "too late" after the ack. - * - * Finally, doing this on any other compositor breaks the CSD - * synchronization with the main surface. Hence we only do - * this when running under mutter. - */ - wl_surface_commit(win->surface); - } else if (!resized) { + if (!resized) { /* * If we didn't resize, we won't be commit a new surface * anytime soon. Some compositors require a commit in @@ -678,18 +638,13 @@ xdg_toplevel_decoration_configure(void *data, if (win->is_configured && win->use_csd == CSD_YES) { struct terminal *term = win->term; - const struct config *conf = term->conf; int scale = term->scale; int width = term->width / scale; int height = term->height / scale; - if (!term->window->is_maximized) { - width -= 2 * conf->csd.border_width; - height -= 2 * conf->csd.border_width + conf->csd.title_height; - } else - height -= conf->csd.title_height; - + /* Take CSD title bar into account */ + height -= term->conf->csd.title_height; render_resize_force(term, width, height); } } -- cgit v1.3 From b81b1b6ff7e0a1c4bbe8eeb1216927f1dc3506b0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:27:59 +0100 Subject: render: configure a clip region to exclude the grid margins This ensures content in the last column doesn't flow over into the margins (where they are typically never erased, unless the window is resized). --- render.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 82abac4d..6f8aa6b5 100644 --- a/render.c +++ b/render.c @@ -994,6 +994,9 @@ grid_render(struct terminal *term) wl_surface_attach(term->window->surface, buf->wl_buf, 0, 0); pixman_image_t *pix = buf->pix; + pixman_region16_t clip; + pixman_region_init_rect(&clip, term->margins.left, term->margins.top, term->cols * term->cell_width, term->rows * term->cell_height); + pixman_image_set_clip_region(pix, &clip); /* If we resized the window, or is flashing, or just stopped flashing */ if (term->render.last_buf != buf || @@ -1027,6 +1030,7 @@ grid_render(struct terminal *term) if (term->is_searching) pixman_color_dim(&bg); + pixman_image_set_clip_region(pix, NULL); pixman_image_fill_rectangles( PIXMAN_OP_SRC, pix, &bg, 4, (pixman_rectangle16_t[]){ @@ -1034,6 +1038,7 @@ grid_render(struct terminal *term) {0, 0, term->margins.left, term->height}, /* Left */ {rmargin, 0, term->margins.right, term->height}, /* Right */ {0, bmargin, term->width, term->margins.bottom}}); /* Bottom */ + pixman_image_set_clip_region(pix, &clip); wl_surface_damage_buffer( term->window->surface, 0, 0, term->width, term->margins.top); -- cgit v1.3 From a78cca74a030782e33646d0719f44e20c585e8ca Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:29:46 +0100 Subject: render: oops, add missing '}' --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 6f8aa6b5..bccd870a 100644 --- a/render.c +++ b/render.c @@ -1573,7 +1573,7 @@ damage_view: -title_height, term->width / term->scale, term->height / term->scale + title_height); - + } if (term->is_searching) render_search_box(term); -- cgit v1.3 From f434933824da23ced65e4134d6cb76c99b49897e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 6 Mar 2020 19:13:10 +0100 Subject: render: CSD: use *default* foreground, not current foreground Applications may temporarily change the foreground color. Don't use this when rendering the CSD title bar - use the default foreground (i.e the default default one, or the one configured by the user in footrc). --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index bccd870a..fa929b37 100644 --- a/render.c +++ b/render.c @@ -748,7 +748,7 @@ render_csd_title(struct terminal *term) struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); - uint32_t _color = term->colors.fg; + uint32_t _color = term->colors.default_fg; uint16_t alpha = 0xffff; if (term->conf->csd.color.title_set) { -- cgit v1.3 From e5540a0d2ecfe8156946e444d265e4e41818793c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 6 Mar 2020 19:15:09 +0100 Subject: render: csd: improved look of minimize/maximize/close buttons * minimize: a downward triangle * maximize (window): an upward triangle * maximize (already maximized): a hollow square * close: a filled square The glyphs are now rendered using the default background color instead of hardcoded to black. --- render.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 20 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index fa929b37..c90a2be5 100644 --- a/render.c +++ b/render.c @@ -789,50 +789,147 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) static void render_csd_button_minimize(struct terminal *term, struct buffer *buf) { - pixman_color_t color = color_hex_to_pixman(0); + pixman_color_t color = color_hex_to_pixman(term->colors.default_bg); pixman_image_t *src = pixman_image_create_solid_fill(&color); - int x_margin = (term->conf->csd.button_width * 1 / 4) * term->scale; - int y_margin = (term->conf->csd.title_height * 4 / 6) * term->scale; + const int max_height = buf->height / 2; + const int max_width = buf->width / 2; - pixman_image_fill_rectangles( - PIXMAN_OP_SRC, buf->pix, &color, 1, - &(pixman_rectangle16_t){x_margin, y_margin, buf->width - 2 * x_margin, 1 * term->scale}); + int width = max_width; + int height = max_width / 2; + + if (height > max_height) { + height = max_height; + width = height * 2; + } + + assert(width <= max_width); + assert(height <= max_height); + + int x_margin = (buf->width - width) / 2.; + int y_margin = (buf->height - height) / 2.; + + pixman_triangle_t tri = { + .p1 = { + .x = pixman_int_to_fixed(x_margin), + .y = pixman_int_to_fixed(y_margin), + }, + .p2 = { + .x = pixman_int_to_fixed(x_margin + width), + .y = pixman_int_to_fixed(y_margin), + }, + .p3 = { + .x = pixman_int_to_fixed(buf->width / 2), + .y = pixman_int_to_fixed(y_margin + height), + }, + }; + pixman_composite_triangles( + PIXMAN_OP_OVER, src, buf->pix, PIXMAN_a1, + 0, 0, 0, 0, 1, &tri); pixman_image_unref(src); } static void -render_csd_button_maximize(struct terminal *term, struct buffer *buf) +render_csd_button_maximize_maximized( + struct terminal *term, struct buffer *buf) { - pixman_color_t color = color_hex_to_pixman(0); + pixman_color_t color = color_hex_to_pixman(term->colors.default_bg); pixman_image_t *src = pixman_image_create_solid_fill(&color); - int x_margin = (term->conf->csd.button_width * 1 / 4) * term->scale; - int y_margin = (term->conf->csd.title_height * 2 / 6) * term->scale; + const int max_height = buf->height / 3; + const int max_width = buf->width / 3; + + int width = min(max_height, max_width); + int thick = 1 * term->scale; + + const int x_margin = (buf->width - width) / 2; + const int y_margin = (buf->height - width) / 2; pixman_image_fill_rectangles( - PIXMAN_OP_SRC, buf->pix, &color, 1, - &(pixman_rectangle16_t){x_margin, y_margin, buf->width - 2 * x_margin, 2 * term->scale}); + PIXMAN_OP_SRC, buf->pix, &color, 4, + (pixman_rectangle16_t[]){ + {x_margin, y_margin, width, thick}, + {x_margin, y_margin + thick, thick, width - 2 * thick}, + {x_margin + width - thick, y_margin + thick, thick, width - 2 * thick}, + {x_margin, y_margin + width - thick, width, thick}}); pixman_image_unref(src); + +} + +static void +render_csd_button_maximize_window( + struct terminal *term, struct buffer *buf) +{ + pixman_color_t color = color_hex_to_pixman(term->colors.default_bg); + pixman_image_t *src = pixman_image_create_solid_fill(&color); + + const int max_height = buf->height / 2; + const int max_width = buf->width / 2; + + int width = max_width; + int height = max_width / 2; + + if (height > max_height) { + height = max_height; + width = height * 2; + } + + assert(width <= max_width); + assert(height <= max_height); + + int x_margin = (buf->width - width) / 2.; + int y_margin = (buf->height - height) / 2.; + + pixman_triangle_t tri = { + .p1 = { + .x = pixman_int_to_fixed(buf->width / 2), + .y = pixman_int_to_fixed(y_margin), + }, + .p2 = { + .x = pixman_int_to_fixed(x_margin), + .y = pixman_int_to_fixed(y_margin + height), + }, + .p3 = { + .x = pixman_int_to_fixed(x_margin + width), + .y = pixman_int_to_fixed(y_margin + height), + }, + }; + + pixman_composite_triangles( + PIXMAN_OP_OVER, src, buf->pix, PIXMAN_a1, + 0, 0, 0, 0, 1, &tri); + + pixman_image_unref(src); +} + +static void +render_csd_button_maximize(struct terminal *term, struct buffer *buf) +{ + if (term->window->is_maximized) + render_csd_button_maximize_maximized(term, buf); + else + render_csd_button_maximize_window(term, buf); } static void render_csd_button_close(struct terminal *term, struct buffer *buf) { - pixman_color_t color = color_hex_to_pixman(0); + pixman_color_t color = color_hex_to_pixman(term->colors.default_bg); pixman_image_t *src = pixman_image_create_solid_fill(&color); - int min_length = min(buf->width, buf->height); - int length = min_length / 2; + const int max_height = buf->height / 3; + const int max_width = buf->width / 3; + + int width = min(max_height, max_width); + + const int x_margin = (buf->width - width) / 2; + const int y_margin = (buf->height - width) / 2; pixman_image_fill_rectangles( - PIXMAN_OP_SRC, buf->pix, &color, 2, - (pixman_rectangle16_t[]){ - {(buf->width - length - term->scale) / 2, (buf->height - term->scale) / 2, length, 1 * term->scale}, - {(buf->width - term->scale) / 2, (buf->height - length - term->scale) / 2, 1 * term->scale, length}, - }); + PIXMAN_OP_SRC, buf->pix, &color, 1, + &(pixman_rectangle16_t){x_margin, y_margin, width, width}); pixman_image_unref(src); } -- 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 'render.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