From 4ecb0ecf4d1f45df918a8dd2dbabd6e9d7090dcc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 15:58:52 +0100 Subject: wayland: rename focused/moused to kbd_focus/mouse_focus --- wayland.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index cbd49179..380cc526 100644 --- a/wayland.c +++ b/wayland.c @@ -849,12 +849,12 @@ wayl_cursor_set(struct wayland *wayl, const struct terminal *term) if (wayl->pointer.theme == NULL) return false; - if (wayl->moused == NULL) { + if (wayl->mouse_focus == NULL) { wayl->pointer.xcursor = NULL; return true; } - if (wayl->moused != term) { + if (wayl->mouse_focus != term) { /* This terminal doesn't have mouse focus */ return true; } -- cgit v1.3 From eb1ea2d80dd71c2799a961ca636722b74eb32286 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 16:06:35 +0100 Subject: term: add visually focused attribute to terminal struct --- terminal.h | 1 + wayland.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'wayland.c') diff --git a/terminal.h b/terminal.h index a1c01942..e4eafe77 100644 --- a/terminal.h +++ b/terminal.h @@ -276,6 +276,7 @@ struct terminal { struct wayland *wl; struct wl_window *window; + bool visual_focus; struct { int scrollback_lines; diff --git a/wayland.c b/wayland.c index 380cc526..80300aba 100644 --- a/wayland.c +++ b/wayland.c @@ -411,12 +411,21 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, { LOG_DBG("xdg-toplevel: configure: %dx%d", width, height); - if (width <= 0 || height <= 0) - return; - struct wayland *wayl = data; struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); - render_resize(term, width, height); + + bool is_focused = false; + enum xdg_toplevel_state *state; + wl_array_for_each(state, states) { + if (*state == XDG_TOPLEVEL_STATE_ACTIVATED) { + is_focused = true; + } + } + + term->visual_focus = is_focused; + + if (width >= 0 && height >= 0) + render_resize(term, width, height); } static void -- cgit v1.3 From 4a9f359a6a13c058e9c76b44941d4435065faa51 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 17:25:41 +0100 Subject: wayland: ignore early configure calls At this point, not everything has been setup and we crash when trying to convert the surface pointer to a terminal pointer. --- wayland.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 80300aba..e13e6b0b 100644 --- a/wayland.c +++ b/wayland.c @@ -411,6 +411,9 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, { LOG_DBG("xdg-toplevel: configure: %dx%d", width, height); + if (width == 0 && height == 0) + return; + struct wayland *wayl = data; struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); @@ -423,9 +426,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, } term->visual_focus = is_focused; - - if (width >= 0 && height >= 0) - render_resize(term, width, height); + render_resize(term, width, height); } static void -- cgit v1.3 From 2192d95fa9126012f7eeae9ac8382dd957b9ae18 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 17:38:50 +0100 Subject: wayland: xdg-toplevel-configure: check for stateless configure calls Ignore configure calls without state, instead of checking for width/height == 0. --- wayland.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index e13e6b0b..99e98fe2 100644 --- a/wayland.c +++ b/wayland.c @@ -411,20 +411,23 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, { LOG_DBG("xdg-toplevel: configure: %dx%d", width, height); - if (width == 0 && height == 0) - return; - - struct wayland *wayl = data; - struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); - + bool stateless = true; bool is_focused = false; + enum xdg_toplevel_state *state; wl_array_for_each(state, states) { - if (*state == XDG_TOPLEVEL_STATE_ACTIVATED) { + stateless = false; + + if (*state == XDG_TOPLEVEL_STATE_ACTIVATED) is_focused = true; - } } + if (stateless) + return; + + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); + term->visual_focus = is_focused; render_resize(term, width, height); } -- cgit v1.3 From 0e40e1c711134a600f7a410585a442edcf058db8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 19:37:01 +0100 Subject: wayland: xdg-top-level-configure: call term_visual_focus_{in,out} --- wayland.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 99e98fe2..7ab1ef2f 100644 --- a/wayland.c +++ b/wayland.c @@ -428,7 +428,11 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, struct wayland *wayl = data; struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); - term->visual_focus = is_focused; + if (is_focused && !term->visual_focus) + term_visual_focus_in(term); + else if (!is_focused && term->visual_focus) + term_visual_focus_out(term); + render_resize(term, width, height); } -- cgit v1.3 From 913c684844ad41c8a4b803abd649a9460e3a57dd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 11:16:06 +0100 Subject: term: term_init() calls wl_display_roundtrip() Instead of having `wayl_win_init()` call `wl_display_roundtrip()` (which it itself doesn't need), call it from `term_init()`. This allows us to add ourselves (the new terminal instance) to the terminal list in the wayland backend, before triggering the wayland events caused by `wayl_win_init()`. This is turn allows the wayland backend to find/lookup the new terminal when those events occur.. --- terminal.c | 7 ++++++- wayland.c | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'wayland.c') diff --git a/terminal.c b/terminal.c index 8a602925..c3697720 100644 --- a/terminal.c +++ b/terminal.c @@ -657,6 +657,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, if ((term->window = wayl_win_init(wayl)) == NULL) goto err; + /* Let the Wayland backend know we exist */ + tll_push_back(wayl->terms, term); + + /* Roundtrip to ensure the wayland window have been configured */ + wl_display_roundtrip(term->wl->display); + term_set_window_title(term, "foot"); /* Try to use user-configured window dimentions */ @@ -675,7 +681,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, height = max(height, term->cell_height); render_resize(term, width, height); - tll_push_back(wayl->terms, term); return term; err: diff --git a/wayland.c b/wayland.c index 7ab1ef2f..816ef1b6 100644 --- a/wayland.c +++ b/wayland.c @@ -804,8 +804,6 @@ wayl_win_init(struct wayland *wayl) wl_subsurface_set_desync(win->search_sub_surface); wl_surface_commit(win->surface); - wl_display_roundtrip(wayl->display); - return win; out: -- cgit v1.3 From 304355d8edaf8259ff73d34955b006c8f1abd4d4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 11:18:43 +0100 Subject: wayland: xdg-toplevel-configure: no need to detect early configure events We can now lookup terminal instances at all times, making it unnecessary to detect "early" configure events. Note that we still need to prevent a resize from happening when width/height is 0. --- wayland.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 816ef1b6..0f54abb3 100644 --- a/wayland.c +++ b/wayland.c @@ -411,20 +411,14 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, { LOG_DBG("xdg-toplevel: configure: %dx%d", width, height); - bool stateless = true; bool is_focused = false; enum xdg_toplevel_state *state; wl_array_for_each(state, states) { - stateless = false; - if (*state == XDG_TOPLEVEL_STATE_ACTIVATED) is_focused = true; } - if (stateless) - return; - struct wayland *wayl = data; struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); @@ -433,7 +427,8 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, else if (!is_focused && term->visual_focus) term_visual_focus_out(term); - render_resize(term, width, height); + if (width > 0 && height > 0) + render_resize(term, width, height); } static void -- cgit v1.3 From aa9e87ffb004e7e453a385d7a166e719c0ebec48 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 11:20:13 +0100 Subject: wayland: term_visual_focus_{in,out} handles already being focused/defocused --- wayland.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 0f54abb3..b42711f3 100644 --- a/wayland.c +++ b/wayland.c @@ -422,9 +422,9 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, struct wayland *wayl = data; struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); - if (is_focused && !term->visual_focus) + if (is_focused) term_visual_focus_in(term); - else if (!is_focused && term->visual_focus) + else term_visual_focus_out(term); if (width > 0 && height > 0) -- cgit v1.3 From 26c16a9a47a0fec437e31220733c1f559dfd33c4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 12:45:16 +0100 Subject: wayland: render_resize() now takes a 'refresh' argument --- wayland.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index b42711f3..ea4b2d40 100644 --- a/wayland.c +++ b/wayland.c @@ -142,7 +142,9 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor) tll_foreach(mon->wayl->terms, it) { struct terminal *term = it->item; - render_resize(term, term->width / term->scale, term->height / term->scale); + int scale = term->scale; + + render_resize(term, term->width / scale, term->height / scale, true); wayl_reload_cursor_theme(mon->wayl, term); } } @@ -368,7 +370,8 @@ surface_enter(void *data, struct wl_surface *wl_surface, tll_push_back(term->window->on_outputs, &it->item); /* Resize, since scale-to-use may have changed */ - render_resize(term, term->width / term->scale, term->height / term->scale); + int scale = term->scale; + render_resize(term, term->width / scale, term->height / scale, true); wayl_reload_cursor_theme(wayl, term); return; } @@ -392,7 +395,8 @@ surface_leave(void *data, struct wl_surface *wl_surface, tll_remove(term->window->on_outputs, it); /* Resize, since scale-to-use may have changed */ - render_resize(term, term->width / term->scale, term->height / term->scale); + int scale = term->scale; + render_resize(term, term->width / scale, term->height / scale, true); wayl_reload_cursor_theme(wayl, term); return; } @@ -428,7 +432,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, term_visual_focus_out(term); if (width > 0 && height > 0) - render_resize(term, width, height); + render_resize(term, width, height, false); } static void -- cgit v1.3 From c94da979fbe3d0267373717fc87654caa0bcfa72 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 12:45:58 +0100 Subject: wayland: xdg-surface-configure: refresh terminal Any changes done in any of the configure events are ignored before we've ack:ed the configure event. In particular, this means the resize done in xdg-toplevel-configure isn't displayed until the next time we call render_refresh(). Unless we do something ourselves, this can take quite some time, since we're basically need the slave to write something. So, in xdg-surface-configure, *after* having ack:ed the configure event, call render_refresh() to make the changes done in xdg-toplevel-configure visible as soon as possible. --- wayland.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index ea4b2d40..76c2f5d3 100644 --- a/wayland.c +++ b/wayland.c @@ -453,8 +453,23 @@ static void xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) { - //LOG_DBG("xdg-surface: configure"); + LOG_DBG("xdg-surface: configure"); xdg_surface_ack_configure(xdg_surface, serial); + + /* + * Changes done in e.g. xdg-toplevel-configure will be ignored + * since the 'configure' event hasn't been ack:ed yet. + * + * Unfortunately, *this* function is called *last*, meaning we + * have no way of acking the configure before we resize the + * terminal in xdg-toplevel-configure. + * + * So, refresh here, to ensure changes take effect as soon as possible. + */ + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_xdg_surface(wayl, xdg_surface); + if (term->width > 0 && term->height > 0) + render_refresh(term); } static const struct xdg_surface_listener xdg_surface_listener = { @@ -946,6 +961,19 @@ wayl_terminal_from_surface(struct wayland *wayl, struct wl_surface *surface) return NULL; } +struct terminal * +wayl_terminal_from_xdg_surface(struct wayland *wayl, + struct xdg_surface *surface) +{ + tll_foreach(wayl->terms, it) { + if (it->item->window->xdg_surface == surface) + return it->item; + } + + assert(false); + return NULL; +} + struct terminal * wayl_terminal_from_xdg_toplevel(struct wayland *wayl, struct xdg_toplevel *toplevel) -- cgit v1.3 From 8494cc808f01d699174e68648c742326cc4e1d28 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 12:49:04 +0100 Subject: wayland: debug log state changes in xdg-toplevel-configure --- wayland.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 76c2f5d3..87c0428a 100644 --- a/wayland.c +++ b/wayland.c @@ -413,16 +413,58 @@ static void xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states) { - LOG_DBG("xdg-toplevel: configure: %dx%d", width, height); - bool is_focused = false; +#if defined(_DEBUG) + char state_str[2048]; + int state_chars = 0; + + static const char *const strings[] = { + [XDG_TOPLEVEL_STATE_MAXIMIZED] = "maximized", + [XDG_TOPLEVEL_STATE_FULLSCREEN] = "fullscreen", + [XDG_TOPLEVEL_STATE_RESIZING] = "resizing", + [XDG_TOPLEVEL_STATE_ACTIVATED] = "activated", + [XDG_TOPLEVEL_STATE_TILED_LEFT] = "tiled:left", + [XDG_TOPLEVEL_STATE_TILED_RIGHT] = "tiled:right", + [XDG_TOPLEVEL_STATE_TILED_TOP] = "tiled:top", + [XDG_TOPLEVEL_STATE_TILED_BOTTOM] = "tiled:bottom", + }; +#endif enum xdg_toplevel_state *state; wl_array_for_each(state, states) { - if (*state == XDG_TOPLEVEL_STATE_ACTIVATED) + switch (*state) { + case XDG_TOPLEVEL_STATE_ACTIVATED: is_focused = true; + break; + + case XDG_TOPLEVEL_STATE_MAXIMIZED: + case XDG_TOPLEVEL_STATE_FULLSCREEN: + case XDG_TOPLEVEL_STATE_RESIZING: + case XDG_TOPLEVEL_STATE_TILED_LEFT: + case XDG_TOPLEVEL_STATE_TILED_RIGHT: + case XDG_TOPLEVEL_STATE_TILED_TOP: + case XDG_TOPLEVEL_STATE_TILED_BOTTOM: + /* Ignored */ + break; + } + +#if defined(_DEBUG) + if (*state >= XDG_TOPLEVEL_STATE_MAXIMIZED && + *state <= XDG_TOPLEVEL_STATE_TILED_BOTTOM) + { + state_chars += snprintf( + &state_str[state_chars], sizeof(state_str) - state_chars, + "%s, ", strings[*state]); + } +#endif } + if (state_chars > 2) + state_str[state_chars - 2] = '\0'; + + LOG_DBG("xdg-toplevel: configure: size=%dx%d, states=%s", + width, height, state_str); + struct wayland *wayl = data; struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); -- cgit v1.3