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.h | 1 + 1 file changed, 1 insertion(+) (limited to 'render.h') 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 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.h') 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 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.h') 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 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.h') 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 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.h') 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