From 7f270a9f01f8c2674a29a1fcd1b91c8ea67cf6ea Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 22:38:35 +0100 Subject: term: add term_surface_kind(), and track currently active surface This is needed to handle pointer motion and button events correctly, since mouse actions in e.g. CSD surfaces are very different from mouse actions in the main window. --- terminal.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 3977caae..d97354cd 100644 --- a/terminal.c +++ b/terminal.c @@ -2133,3 +2133,24 @@ term_print(struct terminal *term, wchar_t wc, int width) else term->cursor.lcf = true; } + +enum term_surface +term_surface_kind(const struct terminal *term, const struct wl_surface *surface) +{ + if (surface == term->window->surface) + return TERM_SURF_GRID; + else if (surface == term->window->search_surface) + return TERM_SURF_SEARCH; + else if (surface == term->window->csd.surface[0]) + return TERM_SURF_TITLE; + else if (surface == term->window->csd.surface[1]) + return TERM_SURF_BORDER_LEFT; + else if (surface == term->window->csd.surface[2]) + return TERM_SURF_BORDER_RIGHT; + else if (surface == term->window->csd.surface[3]) + return TERM_SURF_BORDER_TOP; + else if (surface == term->window->csd.surface[4]) + return TERM_SURF_BORDER_BOTTOM; + else + return TERM_SURF_NONE; +} -- cgit v1.3 From ac32bcda07015dbf00f3b804f5e4595cd7994245 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 19:05:48 +0100 Subject: main: geometry defaults to 800x600 pixels --- completions/zsh/_foot | 2 +- config.c | 4 ++-- doc/foot.1.scd | 2 +- footrc | 2 +- terminal.c | 7 ------- 5 files changed, 5 insertions(+), 12 deletions(-) (limited to 'terminal.c') diff --git a/completions/zsh/_foot b/completions/zsh/_foot index ad04a467..0132604a 100644 --- a/completions/zsh/_foot +++ b/completions/zsh/_foot @@ -6,7 +6,7 @@ _arguments \ '(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \ '(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \ '--login-shell[start shell as a login shell]' \ - '(-g --geometry)'{-g,--geometry}'[window WIDTHxHEIGHT, in pixels (80x24 cells)]:geometry:()' \ + '(-g --geometry)'{-g,--geometry}'[window WIDTHxHEIGHT, in pixels (800x600)]:geometry:()' \ '(-s --server)'{-s,--server}'[run as server; open terminals by running footclient]:server:_files' \ '--hold[remain open after child process exits]' \ '(-p --print-pid)'{-p,--print-pid}'[print PID to this file or FD when up and running (server mode only)]:pidfile:_files' \ diff --git a/config.c b/config.c index 39a72648..7f23d7fe 100644 --- a/config.c +++ b/config.c @@ -491,8 +491,8 @@ config_load(struct config *conf, const char *conf_path) *conf = (struct config) { .term = strdup("foot"), .shell = get_shell(), - .width = -1, - .height = -1, + .width = 800, + .height = 600, .pad_x = 2, .pad_y = 2, .fonts = tll_init(), diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 8b5268b7..97815066 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -31,7 +31,7 @@ execute (instead of the shell). Default: _monospace_. *-g*,*--geometry*=_WIDTHxHEIGHT_ - Set initial window width and height. + Set initial window width and height. Default: *800x600*. *-t*,*--term*=_TERM_ Value to set the environment variable *TERM* to. Default: *foot*. diff --git a/footrc b/footrc index 337be31b..e6010eb2 100644 --- a/footrc +++ b/footrc @@ -2,7 +2,7 @@ # font=monospace # scrollback=1000 -# geometry=500x300 +# geometry=800x600 # pad=2x2 # shell= (you may need to override if you need a login shell) # term=foot diff --git a/terminal.c b/terminal.c index d97354cd..000d95b3 100644 --- a/terminal.c +++ b/terminal.c @@ -791,13 +791,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, unsigned width = conf->width; unsigned height = conf->height; - if (width == -1) { - /* No user-configuration - use 80x24 cells */ - assert(height == -1); - width = 80 * term->cell_width; - height = 24 * term->cell_height; - } - /* Don't go below a single cell */ width = max(width, term->cell_width); height = max(height, term->cell_height); -- 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 'terminal.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 e9d3e7d87f820d9f7d1f63eef7e8a9a5fa5e5718 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 20:31:37 +0100 Subject: term: visual_focus_in/out: redraw CSDs We draw the CSDs in a darker color when we're inactive. Weston seems to be buggy with synchronized subsurfaces, so temporarily reconfigure them to desynchronized surfaces. --- terminal.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 9c90e37d..b568731c 100644 --- a/terminal.c +++ b/terminal.c @@ -1633,6 +1633,15 @@ 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]); +#endif + render_csd(term); +#if 1 + for (int i = 0; i < 5; i++) + wl_subsurface_set_sync(term->window->csd.sub_surface[i]); +#endif cursor_refresh(term); } @@ -1646,6 +1655,15 @@ term_visual_focus_out(struct terminal *term) if (term->cursor_blink.active) cursor_blink_stop_timer(term); +#if 1 + 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]); +#endif cursor_refresh(term); } -- 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 'terminal.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 40f3d4c24ccfd116a53120e36df796a959ca6499 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 28 Feb 2020 18:35:05 +0100 Subject: terminal: error out when we fail to load the primary font --- terminal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index fe8860ad..9388d0d7 100644 --- a/terminal.c +++ b/terminal.c @@ -773,7 +773,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, term_set_window_title(term, "foot"); /* Load fonts */ - term_font_dpi_changed(term); + if (!term_font_dpi_changed(term)) + goto err; /* Start the slave/client */ if ((term->slave = slave_spawn(term->ptmx, argc, term->cwd, argv, term_env, conf->shell, login_shell)) == -1) -- cgit v1.3 From 8c98dfc51a4b313c3f4c019533069a6cc7c08a09 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 09:26:49 +0100 Subject: term: loop through all sub-surfaces when switching sync/desync mode --- terminal.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 9388d0d7..0b3091f8 100644 --- a/terminal.c +++ b/terminal.c @@ -27,6 +27,7 @@ #include "slave.h" #include "vt.h" +#define ALEN(v) (sizeof(v) / sizeof(v[0])) #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) @@ -1636,14 +1637,14 @@ term_visual_focus_in(struct terminal *term) #if 1 /* Weston seems to be buggy with synchronized CSDs */ if (term->window->use_csd == CSD_YES) { - for (int i = 0; i < 5; i++) + for (int i = 0; i < ALEN(term->window->csd.surface); i++) wl_subsurface_set_desync(term->window->csd.sub_surface[i]); } #endif render_csd(term); #if 1 if (term->window->use_csd == CSD_YES) { - for (int i = 0; i < 5; i++) + for (int i = 0; i < ALEN(term->window->csd.surface); i++) wl_subsurface_set_sync(term->window->csd.sub_surface[i]); } #endif @@ -1662,14 +1663,14 @@ term_visual_focus_out(struct terminal *term) #if 1 if (term->window->use_csd == CSD_YES) { - for (int i = 0; i < 5; i++) + for (int i = 0; i < ALEN(term->window->csd.surface); i++) wl_subsurface_set_desync(term->window->csd.sub_surface[i]); } #endif render_csd(term); #if 1 if (term->window->use_csd == CSD_YES) { - for (int i = 0; i < 5; i++) + for (int i = 0; i < ALEN(term->window->csd.surface); i++) wl_subsurface_set_sync(term->window->csd.sub_surface[i]); } #endif -- 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 'terminal.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 70cdb7af08fd4237f063ec241383b7c27e9685b3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 13:09:25 +0100 Subject: term: visual_focus_{in,out}: use quirk_weston_subsurface_desync_{on,off} --- terminal.c | 57 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 1d17ba5d..b0f0679c 100644 --- a/terminal.c +++ b/terminal.c @@ -21,6 +21,7 @@ #include "async.h" #include "config.h" #include "grid.h" +#include "quirks.h" #include "render.h" #include "selection.h" #include "sixel.h" @@ -1625,6 +1626,26 @@ term_restore_cursor(struct terminal *term) term->cursor.lcf = term->saved_cursor.lcf; } +static void +quirk_weston_csd_on(struct terminal *term) +{ + if (term->window->use_csd != CSD_YES) + return; + + for (int i = 0; i < ALEN(term->window->csd.surface); i++) + quirk_weston_subsurface_desync_on(term->window->csd.sub_surface[i]); +} + +static void +quirk_weston_csd_off(struct terminal *term) +{ + if (term->window->use_csd != CSD_YES) + return; + + for (int i = 0; i < ALEN(term->window->csd.surface); i++) + quirk_weston_subsurface_desync_off(term->window->csd.sub_surface[i]); +} + void term_visual_focus_in(struct terminal *term) { @@ -1635,20 +1656,10 @@ term_visual_focus_in(struct terminal *term) if (term->cursor_blink.active) cursor_blink_start_timer(term); -#if 1 /* Weston seems to be buggy with synchronized CSDs */ - if (term->window->use_csd == CSD_YES) { - for (int i = 0; i < ALEN(term->window->csd.surface); i++) - wl_subsurface_set_desync(term->window->csd.sub_surface[i]); - } -#endif - //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++) - wl_subsurface_set_sync(term->window->csd.sub_surface[i]); - } -#endif + quirk_weston_csd_on(term); + render_csd(term); + quirk_weston_csd_off(term); + cursor_refresh(term); } @@ -1662,20 +1673,10 @@ term_visual_focus_out(struct terminal *term) if (term->cursor_blink.active) cursor_blink_stop_timer(term); -#if 1 - if (term->window->use_csd == CSD_YES) { - for (int i = 0; i < ALEN(term->window->csd.surface); i++) - wl_subsurface_set_desync(term->window->csd.sub_surface[i]); - } -#endif - //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++) - wl_subsurface_set_sync(term->window->csd.sub_surface[i]); - } -#endif + quirk_weston_csd_on(term); + render_csd(term); + quirk_weston_csd_off(term); + cursor_refresh(term); } -- cgit v1.3 From f235bfdfdf2a33f9cf0a7074fb3c1722722ffb7b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 18:43:23 +0100 Subject: terminal: workaround founds with negative line gaps Some fonts, even monospaced ones, have a negative line gap (line height < ascent + descent). Using the font's line height as cell height will result in some glyphs overflowing into the cell above or below. Workaround by using which ever value is the largest: the line height or ascent + descent. --- terminal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index b0f0679c..290a1425 100644 --- a/terminal.c +++ b/terminal.c @@ -521,7 +521,8 @@ term_set_fonts(struct terminal *term, struct font *fonts[static 4]) term->cell_width = term->fonts[0]->space_x_advance > 0 ? term->fonts[0]->space_x_advance : term->fonts[0]->max_x_advance; - term->cell_height = term->fonts[0]->height; + term->cell_height = max(term->fonts[0]->height, + term->fonts[0]->ascent + term->fonts[0]->descent); LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); render_resize_force(term, term->width, term->height); -- 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 'terminal.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 e077290c56022255a986c0560f4d496a29bab55e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:19:47 +0100 Subject: quirks: add shortcut for flipping all CSD surfaces sync/desync state --- quirks.c | 22 ++++++++++++++++++++++ quirks.h | 6 ++++++ terminal.c | 20 -------------------- 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'terminal.c') diff --git a/quirks.c b/quirks.c index 0db29a5e..6db96e46 100644 --- a/quirks.c +++ b/quirks.c @@ -7,6 +7,8 @@ #define LOG_ENABLE_DBG 0 #include "log.h" +#define ALEN(v) (sizeof(v) / sizeof(v[0])) + static bool is_weston(void) { @@ -53,3 +55,23 @@ quirk_weston_subsurface_desync_off(struct wl_subsurface *sub) wl_subsurface_set_sync(sub); } + +void +quirk_weston_csd_on(struct terminal *term) +{ + if (term->window->use_csd != CSD_YES) + return; + + for (int i = 0; i < ALEN(term->window->csd.surface); i++) + quirk_weston_subsurface_desync_on(term->window->csd.sub_surface[i]); +} + +void +quirk_weston_csd_off(struct terminal *term) +{ + if (term->window->use_csd != CSD_YES) + return; + + for (int i = 0; i < ALEN(term->window->csd.surface); i++) + quirk_weston_subsurface_desync_off(term->window->csd.sub_surface[i]); +} diff --git a/quirks.h b/quirks.h index ce4b8b01..7b6ab4f8 100644 --- a/quirks.h +++ b/quirks.h @@ -2,5 +2,11 @@ #include +#include "terminal.h" + void quirk_weston_subsurface_desync_on(struct wl_subsurface *sub); void quirk_weston_subsurface_desync_off(struct wl_subsurface *sub); + +/* Shortcuts to call desync_{on,off} on all CSD subsurfaces */ +void quirk_weston_csd_on(struct terminal *term); +void quirk_weston_csd_off(struct terminal *term); diff --git a/terminal.c b/terminal.c index c57b3c1c..ebc27b3c 100644 --- a/terminal.c +++ b/terminal.c @@ -1627,26 +1627,6 @@ term_restore_cursor(struct terminal *term) term->cursor.lcf = term->saved_cursor.lcf; } -static void -quirk_weston_csd_on(struct terminal *term) -{ - if (term->window->use_csd != CSD_YES) - return; - - for (int i = 0; i < ALEN(term->window->csd.surface); i++) - quirk_weston_subsurface_desync_on(term->window->csd.sub_surface[i]); -} - -static void -quirk_weston_csd_off(struct terminal *term) -{ - if (term->window->use_csd != CSD_YES) - return; - - for (int i = 0; i < ALEN(term->window->csd.surface); i++) - quirk_weston_subsurface_desync_off(term->window->csd.sub_surface[i]); -} - void term_visual_focus_in(struct terminal *term) { -- 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 'terminal.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