From d303084a81f7682c23768267a22f8c49e51b5219 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 22:40:24 +0100 Subject: input: pointer-enter: differentiate between the surfaces --- input.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index d04b228d..a84a80f8 100644 --- a/input.c +++ b/input.c @@ -626,10 +626,40 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; - wayl->mouse.col = x / term->cell_width; - wayl->mouse.row = y / term->cell_height; + switch ((term->active_surface = term_surface_kind(term, surface))) { + case TERM_SURF_NONE: + assert(false); + break; + + case TERM_SURF_GRID: + wayl->mouse.col = x / term->cell_width; + wayl->mouse.row = y / term->cell_height; + term_xcursor_update(term); + break; + + case TERM_SURF_SEARCH: + term_xcursor_update(term); + break; + + case TERM_SURF_TITLE: + term->xcursor = "left_ptr"; + render_xcursor_set(term); + break; + + case TERM_SURF_BORDER_LEFT: + case TERM_SURF_BORDER_RIGHT: + term->xcursor = "size_hor"; + render_xcursor_set(term); + break; + + case TERM_SURF_BORDER_TOP: + case TERM_SURF_BORDER_BOTTOM: + term->xcursor = "size_ver"; + render_xcursor_set(term); + break; + } + - term_xcursor_update(term); } static void -- cgit v1.3 From 7b18f8394e45aaf5a930e6ea08b6a4a58f5c7dc7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 22:41:46 +0100 Subject: input: pointer-leave: reset 'active-surface' in terminal --- input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index a84a80f8..7d1c6c04 100644 --- a/input.c +++ b/input.c @@ -684,8 +684,10 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, LOG_WARN( "compositor sent pointer_leave event without a pointer_enter " "event: surface=%p", surface); - } else + } else { + old_moused->active_surface = TERM_SURF_NONE; term_xcursor_update(old_moused); + } } static void -- cgit v1.3 From 551170d94067614ce42d853f09bee908ed8ff9c2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 22:42:04 +0100 Subject: input: pointer-motion/button: ignore actions in non-main surfaces --- input.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 7d1c6c04..f0cac085 100644 --- a/input.c +++ b/input.c @@ -716,6 +716,9 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, assert(term != NULL); + if (term->active_surface != TERM_SURF_GRID) + return; + int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; @@ -771,6 +774,10 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } assert(term != NULL); + + if (term->active_surface != TERM_SURF_GRID) + return; + search_cancel(term); switch (state) { -- cgit v1.3 From c0e3db17120db7efb67e095ff251324518ff5d87 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 Feb 2020 20:31:13 +0100 Subject: input: wip: trigger move/resize when left-clicking CSD --- input.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 5 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index f0cac085..38e20c56 100644 --- a/input.c +++ b/input.c @@ -15,6 +15,8 @@ #include #include +#include + #define LOG_MODULE "input" #define LOG_ENABLE_DBG 0 #include "log.h" @@ -647,14 +649,28 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_BORDER_LEFT: + if (y < 10) + term->xcursor = "top_left_corner"; + else + term->xcursor = "left_side"; + render_xcursor_set(term); + break; + case TERM_SURF_BORDER_RIGHT: - term->xcursor = "size_hor"; + term->xcursor = "right_side"; render_xcursor_set(term); break; case TERM_SURF_BORDER_TOP: + if (x < 10) + term->xcursor = "top_left_corner"; + else + term->xcursor = "top_side"; + render_xcursor_set(term); + break; + case TERM_SURF_BORDER_BOTTOM: - term->xcursor = "size_ver"; + term->xcursor = "bottom_side"; render_xcursor_set(term); break; } @@ -716,12 +732,33 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, assert(term != NULL); - if (term->active_surface != TERM_SURF_GRID) - return; - int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; + switch (term->active_surface) { + case TERM_SURF_NONE: + case TERM_SURF_GRID: + case TERM_SURF_SEARCH: + case TERM_SURF_TITLE: + break; + + case TERM_SURF_BORDER_LEFT: + if (y < 10) + term->xcursor = "top_left_corner"; + else + term->xcursor = "left_side"; + render_xcursor_set(term); + break; + + case TERM_SURF_BORDER_RIGHT: + case TERM_SURF_BORDER_TOP: + case TERM_SURF_BORDER_BOTTOM: + break; + } + + if (term->active_surface != TERM_SURF_GRID) + return; + int col = (x - term->margins.left) / term->cell_width; int row = (y - term->margins.top) / term->cell_height; @@ -775,6 +812,37 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, assert(term != NULL); + switch (term->active_surface) { + case TERM_SURF_NONE: + assert(false); + break; + + case TERM_SURF_TITLE: + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + xdg_toplevel_move(term->window->xdg_toplevel, term->wl->seat, serial); + return; + + case TERM_SURF_BORDER_LEFT: + case TERM_SURF_BORDER_RIGHT: + case TERM_SURF_BORDER_TOP: + case TERM_SURF_BORDER_BOTTOM: { + static const int map[] = { + [TERM_SURF_BORDER_LEFT] = XDG_TOPLEVEL_RESIZE_EDGE_LEFT, + [TERM_SURF_BORDER_RIGHT] = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT, + [TERM_SURF_BORDER_TOP] = XDG_TOPLEVEL_RESIZE_EDGE_TOP, + [TERM_SURF_BORDER_BOTTOM] = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM, + }; + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + xdg_toplevel_resize(term->window->xdg_toplevel, term->wl->seat, serial, map[term->active_surface]); + return; + } + + case TERM_SURF_GRID: + case TERM_SURF_SEARCH: + break; + } + + if (term->active_surface != TERM_SURF_GRID) return; -- cgit v1.3 From d863ea8a4630069e85e590c2022ff94f3ca43edf Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 26 Feb 2020 13:23:11 +0100 Subject: input: temporary code to trigger maximize/minimize --- input.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 38e20c56..566f6d8d 100644 --- a/input.c +++ b/input.c @@ -820,6 +820,18 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_TITLE: if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) xdg_toplevel_move(term->window->xdg_toplevel, term->wl->seat, serial); + else if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED) { + if (term->window->is_maximized) { + LOG_INFO("UNsetting maximized"); + xdg_toplevel_unset_maximized(term->window->xdg_toplevel); + } else { + LOG_INFO("setting maximized"); + xdg_toplevel_set_maximized(term->window->xdg_toplevel); + } + } else if (button == BTN_MIDDLE && state == WL_POINTER_BUTTON_STATE_PRESSED) { + LOG_INFO("setting minimized"); + xdg_toplevel_set_minimized(term->window->xdg_toplevel); + } return; case TERM_SURF_BORDER_LEFT: -- cgit v1.3 From d48a7894120a0040ff240c8dc6df3fc6108363c5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 09:32:22 +0100 Subject: input: handle CSD border corners correctly That is, change to correct cursor, and do resize correctly. --- input.c | 118 +++++++++++++++++++++++++++++++++++++++++++++----------------- wayland.h | 1 + 2 files changed, 88 insertions(+), 31 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 566f6d8d..e3095009 100644 --- a/input.c +++ b/input.c @@ -611,6 +611,63 @@ input_repeat(struct wayland *wayl, uint32_t key) keyboard_key(wayl, NULL, wayl->input_serial, 0, key, XKB_KEY_DOWN); } +static bool +is_top_left(const struct terminal *term, int x, int y) +{ + return ( + (term->active_surface == TERM_SURF_BORDER_LEFT && y < 10 * term->scale) || + (term->active_surface == TERM_SURF_BORDER_TOP && x < (10 + csd_border_size) * term->scale)); +} + +static bool +is_top_right(const struct terminal *term, int x, int y) +{ + return ( + (term->active_surface == TERM_SURF_BORDER_RIGHT && y < 10 * term->scale) || + (term->active_surface == TERM_SURF_BORDER_TOP && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale)); +} + +static bool +is_bottom_left(const struct terminal *term, int x, int y) +{ + return ( + (term->active_surface == TERM_SURF_BORDER_LEFT && y > csd_title_size * term->scale + term->height) || + (term->active_surface == TERM_SURF_BORDER_BOTTOM && x < (10 + csd_border_size) * term->scale)); +} + +static bool +is_bottom_right(const struct terminal *term, int x, int y) +{ + return ( + (term->active_surface == TERM_SURF_BORDER_RIGHT && y > csd_title_size * term->scale + term->height) || + (term->active_surface == TERM_SURF_BORDER_BOTTOM && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale)); +} + +static const char * +xcursor_for_csd_border(struct terminal *term, int x, int y) +{ + if (is_top_left(term, x, y)) + return "top_left_corner"; + else if (is_top_right(term, x, y)) + return "top_right_corner"; + else if (is_bottom_left(term, x, y)) + return "bottom_left_corner"; + else if (is_bottom_right(term, x, y)) + return "bottom_right_corner"; + else if (term->active_surface == TERM_SURF_BORDER_LEFT) + return "left_side"; + else if (term->active_surface == TERM_SURF_BORDER_RIGHT) + return "right_side"; + else if (term->active_surface == TERM_SURF_BORDER_TOP) + return "top_side"; + else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) + return"bottom_side"; + else { + assert(false); + return NULL; + } +} + static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, @@ -643,34 +700,16 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, term_xcursor_update(term); break; - case TERM_SURF_TITLE: - term->xcursor = "left_ptr"; - render_xcursor_set(term); - break; - case TERM_SURF_BORDER_LEFT: - if (y < 10) - term->xcursor = "top_left_corner"; - else - term->xcursor = "left_side"; - render_xcursor_set(term); - break; - case TERM_SURF_BORDER_RIGHT: - term->xcursor = "right_side"; - render_xcursor_set(term); - break; - case TERM_SURF_BORDER_TOP: - if (x < 10) - term->xcursor = "top_left_corner"; - else - term->xcursor = "top_side"; + case TERM_SURF_BORDER_BOTTOM: + term->xcursor = xcursor_for_csd_border(term, x, y); render_xcursor_set(term); break; - case TERM_SURF_BORDER_BOTTOM: - term->xcursor = "bottom_side"; + case TERM_SURF_TITLE: + term->xcursor = "left_ptr"; render_xcursor_set(term); break; } @@ -735,6 +774,9 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; + term->window->csd.x = x; + term->window->csd.y = y; + switch (term->active_surface) { case TERM_SURF_NONE: case TERM_SURF_GRID: @@ -743,16 +785,11 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_BORDER_LEFT: - if (y < 10) - term->xcursor = "top_left_corner"; - else - term->xcursor = "left_side"; - render_xcursor_set(term); - break; - case TERM_SURF_BORDER_RIGHT: case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: + term->xcursor = xcursor_for_csd_border(term, x, y); + render_xcursor_set(term); break; } @@ -844,8 +881,27 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, [TERM_SURF_BORDER_TOP] = XDG_TOPLEVEL_RESIZE_EDGE_TOP, [TERM_SURF_BORDER_BOTTOM] = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM, }; - if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) - xdg_toplevel_resize(term->window->xdg_toplevel, term->wl->seat, serial, map[term->active_surface]); + + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) { + int resize_type; + + int x = term->window->csd.x; + int y = term->window->csd.y; + + if (is_top_left(term, x, y)) + resize_type = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT; + else if (is_top_right(term, x, y)) + resize_type = XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT; + else if (is_bottom_left(term, x, y)) + resize_type = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT; + else if (is_bottom_right(term, x, y)) + resize_type = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT; + else + resize_type = map[term->active_surface]; + + xdg_toplevel_resize( + term->window->xdg_toplevel, term->wl->seat, serial, resize_type); + } return; } diff --git a/wayland.h b/wayland.h index 95e0e1e9..5ffbab2d 100644 --- a/wayland.h +++ b/wayland.h @@ -105,6 +105,7 @@ struct wl_window { struct { struct wl_surface *surface[5]; struct wl_subsurface *sub_surface[5]; + int x, y; } csd; /* Scrollback search */ -- cgit v1.3 From 7b51d6919defbc87d0d11430f6ac9e5bfd137592 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 11:55:43 +0100 Subject: input: handle double/triple click state regardless of surface --- input.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index e3095009..462cbf32 100644 --- a/input.c +++ b/input.c @@ -849,6 +849,28 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, assert(term != NULL); + /* Update double/triple click state */ + if (state == WL_POINTER_BUTTON_STATE_PRESSED) { + /* Time since last click */ + struct timeval now, since_last; + gettimeofday(&now, NULL); + timersub(&now, &wayl->mouse.last_time, &since_last); + + /* Double- or triple click? */ + if (button == wayl->mouse.last_button && + since_last.tv_sec == 0 && + since_last.tv_usec <= 300 * 1000) + { + wayl->mouse.count++; + } else + wayl->mouse.count = 1; + + wayl->mouse.button = button; /* For motion events */ + wayl->mouse.last_button = button; + wayl->mouse.last_time = now; + } else + wayl->mouse.button = 0; /* For motion events */ + switch (term->active_surface) { case TERM_SURF_NONE: assert(false); @@ -910,28 +932,12 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, break; } - - if (term->active_surface != TERM_SURF_GRID) - return; + assert(term->active_surface == TERM_SURF_GRID); search_cancel(term); switch (state) { case WL_POINTER_BUTTON_STATE_PRESSED: { - /* Time since last click */ - struct timeval now, since_last; - gettimeofday(&now, NULL); - timersub(&now, &wayl->mouse.last_time, &since_last); - - /* Double- or triple click? */ - if (button == wayl->mouse.last_button && - since_last.tv_sec == 0 && - since_last.tv_usec <= 300 * 1000) - { - wayl->mouse.count++; - } else - wayl->mouse.count = 1; - if (button == BTN_LEFT) { switch (wayl->mouse.count) { case 1: @@ -955,9 +961,6 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, selection_cancel(term); } - wayl->mouse.button = button; /* For motion events */ - wayl->mouse.last_button = button; - wayl->mouse.last_time = now; term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col); break; } @@ -968,7 +971,6 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, else selection_finalize(term, serial); - wayl->mouse.button = 0; /* For motion events */ term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col); break; } -- cgit v1.3 From 4ee5a81d1a969ba9529c95d93b92f7c83de41fc8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 11:56:16 +0100 Subject: input: toggle maximized state when double-clicking the title bar --- input.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 462cbf32..9f57307b 100644 --- a/input.c +++ b/input.c @@ -877,19 +877,18 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_TITLE: - if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) - xdg_toplevel_move(term->window->xdg_toplevel, term->wl->seat, serial); - else if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED) { - if (term->window->is_maximized) { - LOG_INFO("UNsetting maximized"); - xdg_toplevel_unset_maximized(term->window->xdg_toplevel); - } else { - LOG_INFO("setting maximized"); - xdg_toplevel_set_maximized(term->window->xdg_toplevel); + if (state == WL_POINTER_BUTTON_STATE_PRESSED) { + + /* Toggle maximized state on double-click */ + if (button == BTN_LEFT && wayl->mouse.count == 2) { + if (term->window->is_maximized) + xdg_toplevel_unset_maximized(term->window->xdg_toplevel); + else + xdg_toplevel_set_maximized(term->window->xdg_toplevel); } - } else if (button == BTN_MIDDLE && state == WL_POINTER_BUTTON_STATE_PRESSED) { - LOG_INFO("setting minimized"); - xdg_toplevel_set_minimized(term->window->xdg_toplevel); + + else if (button == BTN_LEFT) + xdg_toplevel_move(term->window->xdg_toplevel, term->wl->seat, serial); } return; -- cgit v1.3 From 1091d1c0785cd07f2cb96fe88b9ccd0d331ede01 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 12:08:59 +0100 Subject: input: reset mouse state on pointer leave --- input.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 9f57307b..6a2bd0bf 100644 --- a/input.c +++ b/input.c @@ -734,6 +734,9 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, wayl->pointer.xcursor = NULL; } + /* Reset mouse state */ + memset(&wayl->mouse, 0, sizeof(wayl->mouse)); + wayl->mouse_focus = NULL; if (old_moused == NULL) { LOG_WARN( -- cgit v1.3 From 43c05518064d6b6dc9a24cf2bded216ab84508f7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 12:09:28 +0100 Subject: wayland: store pointer to window instance in all surfaces --- input.c | 8 +++++++- search.c | 2 ++ wayland.c | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index 6a2bd0bf..d77061eb 100644 --- a/input.c +++ b/input.c @@ -676,7 +676,8 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, assert(surface != NULL); struct wayland *wayl = data; - struct terminal *term = wayl_terminal_from_surface(wayl, surface); + struct wl_window *win = wl_surface_get_user_data(surface); + struct terminal *term = win->term; LOG_DBG("pointer-enter: surface = %p, new-moused = %p", surface, term); @@ -743,6 +744,11 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, "compositor sent pointer_leave event without a pointer_enter " "event: surface=%p", surface); } else { + if (surface != NULL) { + /* Sway 1.4 sends this event with a NULL surface when we destroy the window */ + const struct wl_window *win = wl_surface_get_user_data(surface); + assert(old_moused == win->term); + } old_moused->active_surface = TERM_SURF_NONE; term_xcursor_update(old_moused); } diff --git a/search.c b/search.c index 590c7577..c0c33f3b 100644 --- a/search.c +++ b/search.c @@ -75,6 +75,8 @@ search_begin(struct terminal *term) struct wl_window *win = term->window; struct wayland *wayl = term->wl; win->search_surface = wl_compositor_create_surface(wayl->compositor); + wl_surface_set_user_data(win->search_surface, term->window); + win->search_sub_surface = wl_subcompositor_get_subsurface( wayl->sub_compositor, win->search_surface, win->surface); wl_subsurface_set_desync(win->search_sub_surface); diff --git a/wayland.c b/wayland.c index 9b8cb258..e5249a1d 100644 --- a/wayland.c +++ b/wayland.c @@ -51,6 +51,7 @@ csd_instantiate(struct wl_window *win) wayl->sub_compositor, win->csd.surface[i], win->surface); wl_subsurface_set_sync(win->csd.sub_surface[i]); + wl_surface_set_user_data(win->csd.surface[i], win); wl_surface_commit(win->csd.surface[i]); } } -- cgit v1.3 From c917a74f487941fa16548261680484cb78e63189 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 12:13:58 +0100 Subject: wayland: remove all usages of wayl_terminal_from_surface() Use the 'user data' pointer from the wayland surface instead. --- input.c | 9 ++++++--- wayland.c | 13 ------------- wayland.h | 3 --- 3 files changed, 6 insertions(+), 19 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index d77061eb..a7a78a5d 100644 --- a/input.c +++ b/input.c @@ -88,9 +88,11 @@ keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, assert(surface != NULL); struct wayland *wayl = data; + struct wl_window *win = wl_surface_get_user_data(surface); + struct terminal *term = win->term; + + wayl->kbd_focus = term; wayl->input_serial = serial; - wayl->kbd_focus = wayl_terminal_from_surface(wayl, surface); - assert(wayl->kbd_focus != NULL); term_kbd_focus_in(wayl->kbd_focus); term_xcursor_update(wayl->kbd_focus); @@ -147,7 +149,8 @@ keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, assert( wayl->kbd_focus == NULL || surface == NULL || /* Seen on Sway 1.2 */ - wayl_terminal_from_surface(wayl, surface) == wayl->kbd_focus); + ((const struct wl_window *)wl_surface_get_user_data(surface))->term == wayl->kbd_focus + ); struct terminal *old_focused = wayl->kbd_focus; wayl->kbd_focus = NULL; diff --git a/wayland.c b/wayland.c index e5249a1d..5d3a30df 100644 --- a/wayland.c +++ b/wayland.c @@ -1150,19 +1150,6 @@ wayl_reload_cursor_theme(struct wayland *wayl, struct terminal *term) return render_xcursor_set(term); } -struct terminal * -wayl_terminal_from_surface(struct wayland *wayl, struct wl_surface *surface) -{ - tll_foreach(wayl->terms, it) { - if (term_surface_kind(it->item, surface) != TERM_SURF_NONE) - return it->item; - } - - assert(false); - LOG_WARN("surface %p doesn't map to a terminal", surface); - return NULL; -} - void wayl_flush(struct wayland *wayl) { diff --git a/wayland.h b/wayland.h index 5ffbab2d..a18b40a3 100644 --- a/wayland.h +++ b/wayland.h @@ -205,8 +205,5 @@ void wayl_destroy(struct wayland *wayl); void wayl_flush(struct wayland *wayl); void wayl_roundtrip(struct wayland *wayl); -struct terminal *wayl_terminal_from_surface( - struct wayland *wayl, struct wl_surface *surface); - struct wl_window *wayl_win_init(struct terminal *term); void wayl_win_destroy(struct wl_window *win); -- cgit v1.3 From 43b07b122a1fa460bdda3edc529726e3b6a6463d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 12:52:55 +0100 Subject: input: csd: add a small delay before initiating a move This ensures the user has time to double-click to toggle the maximized state. --- input.c | 41 ++++++++++++++++++++++++++++++++++++----- wayland.c | 4 ++++ wayland.h | 3 +++ 3 files changed, 43 insertions(+), 5 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index a7a78a5d..1db3541f 100644 --- a/input.c +++ b/input.c @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -833,6 +834,19 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col); } +static bool +fdm_csd_move(struct fdm *fdm, int fd, int events, void *data) +{ + struct wl_window *win = data; + struct wayland *wayl = win->term->wl; + + fdm_del(fdm, fd); + win->csd.move_timeout_fd = -1; + + xdg_toplevel_move(win->xdg_toplevel, wayl->seat, win->csd.serial); + return true; +} + static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) @@ -891,16 +905,33 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_TITLE: if (state == WL_POINTER_BUTTON_STATE_PRESSED) { + struct wl_window *win = term->window; + /* Toggle maximized state on double-click */ if (button == BTN_LEFT && wayl->mouse.count == 2) { - if (term->window->is_maximized) - xdg_toplevel_unset_maximized(term->window->xdg_toplevel); + if (win->is_maximized) + xdg_toplevel_unset_maximized(win->xdg_toplevel); else - xdg_toplevel_set_maximized(term->window->xdg_toplevel); + xdg_toplevel_set_maximized(win->xdg_toplevel); } - else if (button == BTN_LEFT) - xdg_toplevel_move(term->window->xdg_toplevel, term->wl->seat, serial); + else if (button == BTN_LEFT && win->csd.move_timeout_fd == -1) { + const struct itimerspec timeout = { + .it_value = {.tv_nsec = 100000000}, + }; + + int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); + if (fd >= 0 && + timerfd_settime(fd, 0, &timeout, NULL) == 0 && + fdm_add(wayl->fdm, fd, EPOLLIN, &fdm_csd_move, win)) + { + win->csd.move_timeout_fd = fd; + win->csd.serial = serial; + } else { + LOG_ERRNO("failed to configure XDG toplevel move timer FD"); + close(fd); + } + } } return; diff --git a/wayland.c b/wayland.c index 5d3a30df..7322a32f 100644 --- a/wayland.c +++ b/wayland.c @@ -1014,6 +1014,7 @@ wayl_win_init(struct terminal *term) struct wl_window *win = calloc(1, sizeof(*win)); win->term = term; win->use_csd = CSD_UNKNOWN; + win->csd.move_timeout_fd = -1; win->surface = wl_compositor_create_surface(wayl->compositor); if (win->surface == NULL) { @@ -1072,6 +1073,9 @@ wayl_win_destroy(struct wl_window *win) if (win == NULL) return; + if (win->csd.move_timeout_fd != -1) + close(win->csd.move_timeout_fd); + /* * First, unmap all surfaces to trigger things like * keyboard_leave() and wl_pointer_leave(). diff --git a/wayland.h b/wayland.h index a18b40a3..4d73be42 100644 --- a/wayland.h +++ b/wayland.h @@ -106,6 +106,9 @@ struct wl_window { struct wl_surface *surface[5]; struct wl_subsurface *sub_surface[5]; int x, y; + + int move_timeout_fd; + uint32_t serial; } csd; /* Scrollback search */ -- cgit v1.3 From e496d81f4d5a0432e0f12fd3494a48724f4d7d59 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 13:04:18 +0100 Subject: input: don't update xcursor on keyboard enter/leave I'm not sure why I added this in the first place... our cursor doesn't depend on keyboard focus. Furthermore, with CSDs, we may get keyboard enter events for the CSD surfaces, and these should definitely *not* update the xcursor as if it was inside the main surface. --- input.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 1db3541f..91b49460 100644 --- a/input.c +++ b/input.c @@ -96,7 +96,6 @@ keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, wayl->input_serial = serial; term_kbd_focus_in(wayl->kbd_focus); - term_xcursor_update(wayl->kbd_focus); } static bool @@ -163,10 +162,9 @@ keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, wayl->kbd.meta = false;; xkb_compose_state_reset(wayl->kbd.xkb_compose_state); - if (old_focused != NULL) { + if (old_focused != NULL) term_kbd_focus_out(old_focused); - term_xcursor_update(old_focused); - } else { + else { /* * Sway bug - under certain conditions we get a * keyboard_leave() (and keyboard_key()) without first having -- cgit v1.3 From 73133c10eed3ad8415646d42a3f6386d7d702348 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 15:29:00 +0100 Subject: input: cleanup --- input.c | 144 +++++++++++++++++++++++++++++++------------------------------- wayland.h | 4 +- 2 files changed, 73 insertions(+), 75 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 91b49460..705fc7af 100644 --- a/input.c +++ b/input.c @@ -689,10 +689,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, int y = wl_fixed_to_int(surface_y) * term->scale; switch ((term->active_surface = term_surface_kind(term, surface))) { - case TERM_SURF_NONE: - assert(false); - break; - case TERM_SURF_GRID: wayl->mouse.col = x / term->cell_width; wayl->mouse.row = y / term->cell_height; @@ -700,7 +696,9 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_SEARCH: - term_xcursor_update(term); + case TERM_SURF_TITLE: + term->xcursor = "left_ptr"; + render_xcursor_set(term); break; case TERM_SURF_BORDER_LEFT: @@ -711,13 +709,10 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, render_xcursor_set(term); break; - case TERM_SURF_TITLE: - term->xcursor = "left_ptr"; - render_xcursor_set(term); + case TERM_SURF_NONE: + assert(false); break; } - - } static void @@ -785,12 +780,11 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; - term->window->csd.x = x; - term->window->csd.y = y; + wayl->mouse.x = x; + wayl->mouse.y = y; switch (term->active_surface) { case TERM_SURF_NONE: - case TERM_SURF_GRID: case TERM_SURF_SEARCH: case TERM_SURF_TITLE: break; @@ -802,34 +796,34 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, term->xcursor = xcursor_for_csd_border(term, x, y); render_xcursor_set(term); break; - } - - if (term->active_surface != TERM_SURF_GRID) - return; - int col = (x - term->margins.left) / term->cell_width; - int row = (y - term->margins.top) / term->cell_height; + case TERM_SURF_GRID: { + int col = (x - term->margins.left) / term->cell_width; + int row = (y - term->margins.top) / term->cell_height; - if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) - return; + if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) + return; - bool update_selection = wayl->mouse.button == BTN_LEFT; - bool update_selection_early = term->selection.end.row == -1; + bool update_selection = wayl->mouse.button == BTN_LEFT; + bool update_selection_early = term->selection.end.row == -1; - if (update_selection && update_selection_early) - selection_update(term, col, row); + if (update_selection && update_selection_early) + selection_update(term, col, row); - if (col == wayl->mouse.col && row == wayl->mouse.row) - return; + if (col == wayl->mouse.col && row == wayl->mouse.row) + break; - wayl->mouse.col = col; - wayl->mouse.row = row; + wayl->mouse.col = col; + wayl->mouse.row = row; - if (update_selection && !update_selection_early) - selection_update(term, col, row); + if (update_selection && !update_selection_early) + selection_update(term, col, row); - term_mouse_motion( + term_mouse_motion( term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col); + break; + } + } } static bool @@ -896,10 +890,6 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, wayl->mouse.button = 0; /* For motion events */ switch (term->active_surface) { - case TERM_SURF_NONE: - assert(false); - break; - case TERM_SURF_TITLE: if (state == WL_POINTER_BUTTON_STATE_PRESSED) { @@ -947,8 +937,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) { int resize_type; - int x = term->window->csd.x; - int y = term->window->csd.y; + int x = wayl->mouse.x; + int y = wayl->mouse.y; if (is_top_left(term, x, y)) resize_type = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT; @@ -967,52 +957,60 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, return; } - case TERM_SURF_GRID: case TERM_SURF_SEARCH: break; - } - - assert(term->active_surface == TERM_SURF_GRID); - search_cancel(term); + case TERM_SURF_GRID: { + search_cancel(term); + + switch (state) { + case WL_POINTER_BUTTON_STATE_PRESSED: { + if (button == BTN_LEFT) { + switch (wayl->mouse.count) { + case 1: + selection_start( + term, wayl->mouse.col, wayl->mouse.row, + wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); + break; + + case 2: + selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, + wayl->kbd.ctrl, serial); + break; + + case 3: + selection_mark_row(term, wayl->mouse.row, serial); + break; + } + } else { + if (wayl->mouse.count == 1 && button == BTN_MIDDLE && + selection_enabled(term)) + { + selection_from_primary(term); + } + selection_cancel(term); + } - switch (state) { - case WL_POINTER_BUTTON_STATE_PRESSED: { - if (button == BTN_LEFT) { - switch (wayl->mouse.count) { - case 1: - selection_start( - term, wayl->mouse.col, wayl->mouse.row, - wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); - break; + term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col); + break; + } - case 2: - selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, - wayl->kbd.ctrl, serial); - break; + case WL_POINTER_BUTTON_STATE_RELEASED: + if (button != BTN_LEFT || term->selection.end.col == -1) + selection_cancel(term); + else + selection_finalize(term, serial); - case 3: - selection_mark_row(term, wayl->mouse.row, serial); - break; - } - } else { - if (wayl->mouse.count == 1 && button == BTN_MIDDLE && selection_enabled(term)) - selection_from_primary(term); - selection_cancel(term); + term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col); + break; } - - term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col); break; } - case WL_POINTER_BUTTON_STATE_RELEASED: - if (button != BTN_LEFT || term->selection.end.col == -1) - selection_cancel(term); - else - selection_finalize(term, serial); - - term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col); + case TERM_SURF_NONE: + assert(false); break; + } } diff --git a/wayland.h b/wayland.h index 4d73be42..768fee5f 100644 --- a/wayland.h +++ b/wayland.h @@ -105,8 +105,6 @@ struct wl_window { struct { struct wl_surface *surface[5]; struct wl_subsurface *sub_surface[5]; - int x, y; - int move_timeout_fd; uint32_t serial; } csd; @@ -182,6 +180,8 @@ struct wayland { } pointer; struct { + int x; + int y; int col; int row; int button; -- cgit v1.3 From 33744ebe63545540b583448f3d6b8aebc791911f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 15:29:58 +0100 Subject: input: fix 'unused variable' warning (release builds) --- input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index 705fc7af..3bb9eaba 100644 --- a/input.c +++ b/input.c @@ -743,7 +743,8 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, } else { if (surface != NULL) { /* Sway 1.4 sends this event with a NULL surface when we destroy the window */ - const struct wl_window *win = wl_surface_get_user_data(surface); + const struct wl_window *win __attribute__((unused)) + = wl_surface_get_user_data(surface); assert(old_moused == win->term); } old_moused->active_surface = TERM_SURF_NONE; -- cgit v1.3 From ea2d7f8b8c5782d422d02058861fa9a754055b17 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 29 Feb 2020 15:38:04 +0100 Subject: input: start window move right away if user starts dragging the window When the user left-clicks the title-bar, we start a timer. When the timer has elapsed, we initiate a 'move' operation. However, if the user clicked, and then started dragging right away, there was a very visible lag since we waited for the timeout before starting the move. Now, on a pointer motion event we detect a running 'move' timer, and abort it and instead start the 'move' operation right away. --- input.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 3bb9eaba..b5973364 100644 --- a/input.c +++ b/input.c @@ -758,6 +758,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, { struct wayland *wayl = data; struct terminal *term = wayl->mouse_focus; + struct wl_window *win = term->window; /* Workaround buggy Sway 1.2 */ if (term == NULL) { @@ -787,7 +788,17 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, switch (term->active_surface) { case TERM_SURF_NONE: case TERM_SURF_SEARCH: + break; + case TERM_SURF_TITLE: + /* We've started a 'move' timer, but user started dragging + * right away - abort the timer and initiate the actual move + * right away */ + if (wayl->mouse.button == BTN_LEFT && win->csd.move_timeout_fd != -1) { + fdm_del(wayl->fdm, win->csd.move_timeout_fd); + win->csd.move_timeout_fd = -1; + xdg_toplevel_move(win->xdg_toplevel, wayl->seat, win->csd.serial); + } break; case TERM_SURF_BORDER_LEFT: @@ -922,6 +933,14 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } } } + + else if (state == WL_POINTER_BUTTON_STATE_RELEASED) { + struct wl_window *win = term->window; + if (win->csd.move_timeout_fd != -1) { + fdm_del(wayl->fdm, win->csd.move_timeout_fd); + win->csd.move_timeout_fd = -1; + } + } return; case TERM_SURF_BORDER_LEFT: -- cgit v1.3 From fff480e5849ec5cd2916e4cfe006374806ebb756 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 11:43:58 +0100 Subject: input: use xdg_toplevel_resize_edge enum type --- input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index b5973364..bf3a0a91 100644 --- a/input.c +++ b/input.c @@ -947,7 +947,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BORDER_RIGHT: case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: { - static const int map[] = { + static const enum xdg_toplevel_resize_edge map[] = { [TERM_SURF_BORDER_LEFT] = XDG_TOPLEVEL_RESIZE_EDGE_LEFT, [TERM_SURF_BORDER_RIGHT] = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT, [TERM_SURF_BORDER_TOP] = XDG_TOPLEVEL_RESIZE_EDGE_TOP, @@ -955,7 +955,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, }; if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) { - int resize_type; + enum xdg_toplevel_resize_edge resize_type; int x = wayl->mouse.x; int y = wayl->mouse.y; -- cgit v1.3 From ae22366f3bc8e9a364c1a25436e182269e050032 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 1 Mar 2020 13:20:07 +0100 Subject: input: raise window 'move' timeout to 200ms 100ms was a bit low and prevented double-tap on touchpads from working. --- input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index bf3a0a91..2fde9ca4 100644 --- a/input.c +++ b/input.c @@ -917,7 +917,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, else if (button == BTN_LEFT && win->csd.move_timeout_fd == -1) { const struct itimerspec timeout = { - .it_value = {.tv_nsec = 100000000}, + .it_value = {.tv_nsec = 200000000}, }; int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); -- cgit v1.3 From 22ce09eb44db887d32a5b3a88740939b7285c763 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 18:42:49 +0100 Subject: config: make CSD user configurable The user can now configure the following: * Whether to prefer CSDs or SSDs. But note that this is only a hint to the compositor - it may deny our request. Furthermore, not all compositors implement the decoration manager protocol, meaning CSDs will be used regardless of the user configuration (GNOME/mutter being the most prominent one). * Title bar size and color, including transparency * Border size and color, including transparency Also drop support for rendering the CSDs inside the main surface. --- config.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++--- config.h | 14 ++++++++ doc/foot.5.scd | 31 ++++++++++++++++++ footrc | 7 ++++ input.c | 31 +++++++++--------- render.c | 100 ++++++++++++++++++++++----------------------------------- wayland.c | 35 +++++++++++--------- wayland.h | 9 ------ 8 files changed, 210 insertions(+), 107 deletions(-) (limited to 'input.c') diff --git a/config.c b/config.c index 37795bb9..246e0d18 100644 --- a/config.c +++ b/config.c @@ -133,7 +133,7 @@ str_to_double(const char *s, double *res) } static bool -str_to_color(const char *s, uint32_t *color, const char *path, int lineno) +str_to_color(const char *s, uint32_t *color, bool allow_alpha, const char *path, int lineno) { unsigned long value; if (!str_to_ulong(s, 16, &value)) { @@ -141,7 +141,12 @@ str_to_color(const char *s, uint32_t *color, const char *path, int lineno) return false; } - *color = value & 0xffffff; + if (!allow_alpha && (value & 0xff000000) != 0) { + LOG_ERR("%s:%d: color value must not have an alpha component", path, lineno); + return false; + } + + *color = value; return true; } @@ -273,7 +278,7 @@ parse_section_colors(const char *key, const char *value, struct config *conf, } uint32_t color_value; - if (!str_to_color(value, &color_value, path, lineno)) + if (!str_to_color(value, &color_value, false, path, lineno)) return false; *color = color_value; @@ -305,8 +310,8 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, uint32_t text_color, cursor_color; if (text == NULL || cursor == NULL || - !str_to_color(text, &text_color, path, lineno) || - !str_to_color(cursor, &cursor_color, path, lineno)) + !str_to_color(text, &text_color, false, path, lineno) || + !str_to_color(cursor, &cursor_color, false, path, lineno)) { LOG_ERR("%s:%d: invalid cursor colors: %s", path, lineno, value); free(value_copy); @@ -326,6 +331,66 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, return true; } +static bool +parse_section_csd(const char *key, const char *value, struct config *conf, + const char *path, unsigned lineno) +{ + if (strcmp(key, "preferred") == 0) { + if (strcmp(value, "server") == 0) + conf->csd.preferred = CONF_CSD_PREFER_SERVER; + else if (strcmp(value, "client") == 0) + conf->csd.preferred = CONF_CSD_PREFER_CLIENT; + else { + LOG_ERR("%s:%d: expected either 'server' or 'client'", path, lineno); + return false; + } + } + + else if (strcmp(key, "titlebar-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid titlebar-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.title_set = true; + conf->csd.color.title = color; + } + + else if (strcmp(key, "border-color") == 0) { + uint32_t color; + if (!str_to_color(value, &color, true, path, lineno)) { + LOG_ERR("%s:%d: invalid border-color: %s", path, lineno, value); + return false; + } + + conf->csd.color.border_set = true; + conf->csd.color.border = color; + } + + else if (strcmp(key, "titlebar") == 0) { + unsigned long pixels; + if (!str_to_ulong(value, 10, &pixels)) { + LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); + return false; + } + + conf->csd.title_height = pixels; + } + + else if (strcmp(key, "border") == 0) { + unsigned long pixels; + if (!str_to_ulong(value, 10, &pixels)) { + LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); + return false; + } + + conf->csd.border_width = pixels; + } + + return true; +} + static bool parse_config_file(FILE *f, struct config *conf, const char *path) { @@ -333,6 +398,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) SECTION_MAIN, SECTION_COLORS, SECTION_CURSOR, + SECTION_CSD, } section = SECTION_MAIN; /* Function pointer, called for each key/value line */ @@ -345,6 +411,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) [SECTION_MAIN] = &parse_section_main, [SECTION_COLORS] = &parse_section_colors, [SECTION_CURSOR] = &parse_section_cursor, + [SECTION_CSD] = &parse_section_csd, }; #if defined(_DEBUG) && defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG @@ -352,6 +419,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) [SECTION_MAIN] = "main", [SECTION_COLORS] = "colors", [SECTION_CURSOR] = "cursor", + [SECTION_CSD] = "csd", }; #endif @@ -408,6 +476,8 @@ parse_config_file(FILE *f, struct config *conf, const char *path) section = SECTION_COLORS; else if (strcmp(&line[1], "cursor") == 0) section = SECTION_CURSOR; + else if (strcmp(&line[1], "csd") == 0) + section = SECTION_CSD; else { LOG_ERR("%s:%d: invalid section name: %s", path, lineno, &line[1]); goto err; @@ -532,6 +602,16 @@ config_load(struct config *conf, const char *conf_path) }, }, + .csd = { + .preferred = CONF_CSD_PREFER_SERVER, + .title_height = 26, + .border_width = 5, + .color = { + .title_set = false, + .border_set = false, + }, + }, + .render_worker_count = sysconf(_SC_NPROCESSORS_ONLN), .server_socket_path = get_server_socket_path(), .presentation_timings = false, diff --git a/config.h b/config.h index 3677129f..fa765476 100644 --- a/config.h +++ b/config.h @@ -36,6 +36,20 @@ struct config { } color; } cursor; + struct { + enum { CONF_CSD_PREFER_SERVER, CONF_CSD_PREFER_CLIENT } preferred; + + int title_height; + int border_width; + + struct { + bool title_set; + bool border_set; + uint32_t title; + uint32_t border; + } color; + } csd; + size_t render_worker_count; char *server_socket_path; bool presentation_timings; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 41785366..30fd735c 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -98,6 +98,37 @@ in this order: Background translucency. A value in the range 0.0-1.0, where 0.0 means completely transparent, and 1.0 is opaque. Default: _1.0_. +# SECTION: csd + +This section controls the look of the _CSDs_ (Client Side +Decorations). Note that the default is to *not* use CSDs, but instead +to use _SSDs_ (Server Side Decorations) when the compositor supports +it. + +*preferred* + Which type of window decorations to prefer: *client* (CSD) or + *server* (SSD). Note that this is only a hint to the + compositor. Depending on the compositor's configuration and + capabilities, it may not have any effect. Default: _server_. + +*titlebar* + Height, in pixels (but subject to output scaling), of the + titlebar, not including the window border. Default: _26_. + +*border* + Width, in pixels (but subject to output scaling), of the + borders. Default: _5_. + +*titlebar-color* + Titlebar AARRGGBB color. Note that unlike the other color values, + the *titlebar-color* value also has an _alpha_ component. Default: + use the default _foreground_ color. + +*border-color* + Border AARRGGBB color. Note that unlike the other color values, + the *border-color* value also has an _alpha_ component. Default: + _transparent_. + # FONT FORMAT The font is specified in FontConfig syntax. That is, a colon-separated diff --git a/footrc b/footrc index e6010eb2..7eea3ada 100644 --- a/footrc +++ b/footrc @@ -33,3 +33,10 @@ # bright6=b3ffff # bright7=ffffff # alpha=1.0 + +[csd] +# preferred=server +# titlebar=26 +# border=5 +# titlebar-color= +# border-color=00000000 diff --git a/input.c b/input.c index 2fde9ca4..dbb8ec33 100644 --- a/input.c +++ b/input.c @@ -21,6 +21,7 @@ #define LOG_MODULE "input" #define LOG_ENABLE_DBG 0 #include "log.h" +#include "config.h" #include "commands.h" #include "keymap.h" #include "render.h" @@ -616,6 +617,7 @@ input_repeat(struct wayland *wayl, uint32_t key) static bool is_top_left(const struct terminal *term, int x, int y) { + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_LEFT && y < 10 * term->scale) || (term->active_surface == TERM_SURF_BORDER_TOP && x < (10 + csd_border_size) * term->scale)); @@ -624,6 +626,7 @@ is_top_left(const struct terminal *term, int x, int y) static bool is_top_right(const struct terminal *term, int x, int y) { + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_RIGHT && y < 10 * term->scale) || (term->active_surface == TERM_SURF_BORDER_TOP && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale)); @@ -632,6 +635,8 @@ is_top_right(const struct terminal *term, int x, int y) static bool is_bottom_left(const struct terminal *term, int x, int y) { + int csd_title_size = term->conf->csd.title_height; + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_LEFT && y > csd_title_size * term->scale + term->height) || (term->active_surface == TERM_SURF_BORDER_BOTTOM && x < (10 + csd_border_size) * term->scale)); @@ -640,6 +645,8 @@ is_bottom_left(const struct terminal *term, int x, int y) static bool is_bottom_right(const struct terminal *term, int x, int y) { + int csd_title_size = term->conf->csd.title_height; + int csd_border_size = term->conf->csd.border_width; return ( (term->active_surface == TERM_SURF_BORDER_RIGHT && y > csd_title_size * term->scale + term->height) || (term->active_surface == TERM_SURF_BORDER_BOTTOM && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale)); @@ -648,22 +655,14 @@ is_bottom_right(const struct terminal *term, int x, int y) static const char * xcursor_for_csd_border(struct terminal *term, int x, int y) { - if (is_top_left(term, x, y)) - return "top_left_corner"; - else if (is_top_right(term, x, y)) - return "top_right_corner"; - else if (is_bottom_left(term, x, y)) - return "bottom_left_corner"; - else if (is_bottom_right(term, x, y)) - return "bottom_right_corner"; - else if (term->active_surface == TERM_SURF_BORDER_LEFT) - return "left_side"; - else if (term->active_surface == TERM_SURF_BORDER_RIGHT) - return "right_side"; - else if (term->active_surface == TERM_SURF_BORDER_TOP) - return "top_side"; - else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) - return"bottom_side"; + if (is_top_left(term, x, y)) return "top_left_corner"; + else if (is_top_right(term, x, y)) return "top_right_corner"; + else if (is_bottom_left(term, x, y)) return "bottom_left_corner"; + else if (is_bottom_right(term, x, y)) return "bottom_right_corner"; + else if (term->active_surface == TERM_SURF_BORDER_LEFT) return "left_side"; + else if (term->active_surface == TERM_SURF_BORDER_RIGHT) return "right_side"; + else if (term->active_surface == TERM_SURF_BORDER_TOP) return "top_side"; + else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return"bottom_side"; else { assert(false); return NULL; diff --git a/render.c b/render.c index 740d3e55..f08c4cf4 100644 --- a/render.c +++ b/render.c @@ -25,9 +25,6 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) -const int csd_border_size = 5; -const int csd_title_size = 26; - struct renderer { struct fdm *fdm; struct wayland *wayl; @@ -680,12 +677,11 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) /* Only title bar is rendered in maximized mode */ const int border_width = !term->window->is_maximized - ? csd_border_size * term->scale : 0; + ? term->conf->csd.border_width * term->scale : 0; const int title_height = !term->window->is_fullscreen - ? csd_title_size * term->scale : 0; + ? term->conf->csd.title_height * term->scale : 0; -#if FOOT_CSD_OUTSIDE switch (surf_idx) { case CSD_SURF_TITLE: return (struct csd_data){ 0, -title_height, term->width, title_height}; case CSD_SURF_LEFT: return (struct csd_data){-border_width, -title_height, border_width, title_height + term->height}; @@ -697,18 +693,6 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) assert(false); return (struct csd_data){0}; } -#else - switch (surf_idx) { - case CSD_SURF_TITLE: return (struct csd_data){ border_width, border_width, term->width - 2 * border_width, title_height}; - case CSD_SURF_LEFT: return (struct csd_data){ 0, border_width, border_width, term->height - 2 * border_width}; - case CSD_SURF_RIGHT: return (struct csd_data){term->width - border_width, border_width, border_width, term->height - 2 * border_width}; - case CSD_SURF_TOP: return (struct csd_data){ 0, 0, term->width, border_width}; - - case CSD_SURF_COUNT: - assert(false); - return (struct csd_data){0}; - } -#endif assert(false); return (struct csd_data){0}; @@ -749,18 +733,18 @@ render_csd_title(struct terminal *term) struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); - pixman_color_t color = color_hex_to_pixman(term->colors.fg); + uint32_t _color = term->colors.fg; + uint16_t alpha = 0xffff; + + if (term->conf->csd.color.title_set) { + _color = term->conf->csd.color.title; + alpha = _color >> 24 | (_color >> 24 << 8); + } + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) pixman_color_dim(&color); - struct wl_region *region = wl_compositor_create_region(term->wl->compositor); - if (region != NULL) { - wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); - wl_surface_set_opaque_region(surf, region); - wl_region_destroy(region); - } - render_csd_part(term, surf, buf, info.width, info.height, &color); } @@ -782,8 +766,15 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx) struct buffer *buf = shm_get_buffer( term->wl->shm, info.width, info.height, cookie); - pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0); + uint32_t _color = 0; + uint16_t alpha = 0; + + if (term->conf->csd.color.border_set) { + _color = term->conf->csd.color.border; + alpha = _color >> 24 | (_color >> 24 << 8); + } + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) pixman_color_dim(&color); render_csd_part(term, surf, buf, info.width, info.height, &color); @@ -1145,12 +1136,7 @@ render_search_box(struct terminal *term) assert(term->scale >= 1); const int scale = term->scale; -#if FOOT_CSD_OUTSIDE - const int csd = 0; -#else - const int csd = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; -#endif - const size_t margin = csd + 3 * scale; + const size_t margin = 3 * scale; const size_t width = term->width - 2 * margin; const size_t visible_width = min( @@ -1264,15 +1250,6 @@ maybe_resize(struct terminal *term, int width, int height, bool force) width *= scale; height *= scale; - /* Scaled CSD border + title bar sizes */ -#if FOOT_CSD_OUTSIDE - const int csd_border = 0; - const int csd_title = 0; -#else - const int csd_border = term->window->use_csd == CSD_YES ? csd_border_size * scale : 0; - const int csd_title = term->window->use_csd == CSD_YES ? csd_title_size * scale : 0; -#endif - if (width == 0 && height == 0) { /* * The compositor is letting us choose the size @@ -1293,10 +1270,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force) /* Account for CSDs, to make actual window size match * the configured size */ if (!term->window->is_maximized) { - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; + width -= 2 * term->conf->csd.border_width; + height -= 2 * term->conf->csd.border_width + term->conf->csd.title_height; } else { - height -= csd_title_size; + height -= term->conf->csd.title_height; } } @@ -1305,24 +1282,23 @@ maybe_resize(struct terminal *term, int width, int height, bool force) } } - const int csd_x = 2 * csd_border; - const int csd_y = 2 * csd_border + csd_title; - - /* Padding */ - const int pad_x = scale * term->conf->pad_x; - const int pad_y = scale * term->conf->pad_y; - /* Don't shrink grid too much */ const int min_cols = 20; const int min_rows = 4; /* Minimum window size */ - const int min_width = csd_x + 2 * pad_x + min_cols * term->cell_width; - const int min_height = csd_y + 2 * pad_y + min_rows * term->cell_height; + const int min_width = min_cols * term->cell_width; + const int min_height = min_rows * term->cell_height; width = max(width, min_width); height = max(height, min_height); + /* Padding */ + const int max_pad_x = (width - min_width) / 2; + const int max_pad_y = (height - min_height) / 2; + const int pad_x = min(max_pad_x, scale * term->conf->pad_x); + const int pad_y = min(max_pad_y, scale * term->conf->pad_y); + if (!force && width == term->width && height == term->height && scale == term->scale) return false; @@ -1342,8 +1318,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int old_rows = term->rows; /* Screen rows/cols after resize */ - const int new_cols = (term->width - 2 * pad_x - csd_x) / term->cell_width; - const int new_rows = (term->height - 2 * pad_y - csd_y) / term->cell_height; + const int new_cols = (term->width - 2 * pad_x) / term->cell_width; + const int new_rows = (term->height - 2 * pad_y) / term->cell_height; /* Grid rows/cols after resize */ const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1)); @@ -1353,15 +1329,15 @@ maybe_resize(struct terminal *term, int width, int height, bool force) assert(new_rows >= 1); /* Margins */ - term->margins.left = csd_border + pad_x; - term->margins.top = csd_border + csd_title + pad_y; + term->margins.left = pad_x; + term->margins.top = pad_y; term->margins.right = term->width - new_cols * term->cell_width - term->margins.left; term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top; - assert(term->margins.left >= csd_border + pad_x); - assert(term->margins.right >= csd_border + pad_x); - assert(term->margins.top >= csd_border + csd_title + pad_y); - assert(term->margins.bottom >= csd_border + pad_y); + assert(term->margins.left >= pad_x); + assert(term->margins.right >= pad_x); + assert(term->margins.top >= pad_y); + assert(term->margins.bottom >= pad_y); if (new_cols == old_cols && new_rows == old_rows) { LOG_DBG("grid layout unaffected; skipping reflow"); diff --git a/wayland.c b/wayland.c index 957f736e..c5272994 100644 --- a/wayland.c +++ b/wayland.c @@ -536,18 +536,14 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, * sub-surfaces. Thus, since our resize code assumes the size * to resize to is the main window only, adjust the size here, * to account for the CSDs. - * - * Of course this does *not* apply when we position the CSDs - * *inside* the main surface. */ -#if FOOT_CSD_OUTSIDE + const struct config *conf = win->term->conf; if (!is_maximized) { - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; + width -= 2 * conf->csd.border_width; + height -= 2 * conf->csd.border_width + conf->csd.title_height; } else { - height -= csd_title_size; + height -= conf->csd.title_height; } -#endif } win->configure.is_activated = is_activated; @@ -670,18 +666,18 @@ xdg_toplevel_decoration_configure(void *data, if (win->is_configured && win->use_csd == CSD_YES) { struct terminal *term = win->term; - int scale = term->scale; + const struct config *conf = term->conf; + int scale = term->scale; int width = term->width / scale; int height = term->height / scale; -#if FOOT_CSD_OUTSIDE if (!term->window->is_maximized) { - width -= 2 * csd_border_size; - height -= 2 * csd_border_size + csd_title_size; + width -= 2 * conf->csd.border_width; + height -= 2 * conf->csd.border_width + conf->csd.title_height; } else - height -= csd_title_size; -#endif + height -= conf->csd.title_height; + render_resize_force(term, width, height); } } @@ -1013,6 +1009,7 @@ struct wl_window * wayl_win_init(struct terminal *term) { struct wayland *wayl = term->wl; + const struct config *conf = wayl->conf; struct wl_window *win = calloc(1, sizeof(*win)); win->term = term; @@ -1050,8 +1047,16 @@ wayl_win_init(struct terminal *term) if (wayl->xdg_decoration_manager != NULL) { win->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( wayl->xdg_decoration_manager, win->xdg_toplevel); + + LOG_INFO("preferring %s decorations", + conf->csd.preferred == CONF_CSD_PREFER_SERVER ? "SSD" : "CSD"); + zxdg_toplevel_decoration_v1_set_mode( - win->xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + win->xdg_toplevel_decoration, + (conf->csd.preferred == CONF_CSD_PREFER_SERVER + ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE + : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE)); + zxdg_toplevel_decoration_v1_add_listener( win->xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, win); } else { diff --git a/wayland.h b/wayland.h index b879c319..f94ad0e5 100644 --- a/wayland.h +++ b/wayland.h @@ -82,15 +82,6 @@ struct wl_primary { uint32_t serial; }; -/* I'd prefer to position the CSD sub-surfaces outside the main - * surface. Unfortunately, a lot of compositors doesn't handle this - * correctly. When this define is 0, we instead position the CSD - * sub-surfaces inside the main surface, and offset the grid content - * accordingly. */ -#define FOOT_CSD_OUTSIDE 1 -extern const int csd_border_size; -extern const int csd_title_size; - enum csd_surface { CSD_SURF_TITLE, CSD_SURF_LEFT, -- cgit v1.3 From 6eae5ebd94d2fbc8b0fec3275b8fd3a094a40ac5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 2 Mar 2020 18:47:17 +0100 Subject: input: don't change xcursor if active surface isn't the main grid --- input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index dbb8ec33..2526807a 100644 --- a/input.c +++ b/input.c @@ -585,7 +585,7 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, wayl->kbd.meta = xkb_state_mod_index_is_active( wayl->kbd.xkb_state, wayl->kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); - if (wayl->kbd_focus) + if (wayl->kbd_focus && wayl->kbd_focus->active_surface == TERM_SURF_GRID) term_xcursor_update(wayl->kbd_focus); } -- 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 'input.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 264acd6463794a659d52f833702a8e864034cecd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 3 Mar 2020 18:22:32 +0100 Subject: input: do a full CSD repaint on pointer motion over CSD buttons This fixes repainting issues on mutter. --- input.c | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 5ca13785..a9e7ac83 100644 --- a/input.c +++ b/input.c @@ -39,7 +39,6 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); - /* TODO: free old context + keymap */ if (wayl->kbd.xkb_compose_state != NULL) { xkb_compose_state_unref(wayl->kbd.xkb_compose_state); wayl->kbd.xkb_compose_state = NULL; @@ -711,25 +710,15 @@ 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: { - 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); + 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); break; - } case TERM_SURF_NONE: assert(false); @@ -778,22 +767,15 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, 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); + case TERM_SURF_BUTTON_CLOSE: + 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); break; - } case TERM_SURF_NONE: case TERM_SURF_GRID: @@ -1054,7 +1036,6 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, 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: -- 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 'input.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