From 24ee3dcc10c5e1cf57456cc39fa0b5e8700a06ed Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 17 Apr 2022 16:29:30 +0200 Subject: wayland: refactor: remove ‘struct config’ pointer from wayland struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The global config doesn’t necessarily reflect the correct configuration to use - we should *always* use the current terminal instance’s conf pointer. * Move selection override modifier mask to the key_binding_set struct * Always warn if XDG activation is unavailable, not just if bell.urgent is set (we no longer have access to this information) * Pass ‘bool presentation_timings’ as a parameter to wayl_init() * Remove ‘presentation_timings’ member from the ‘terminal’ struct Closes #932 --- input.c | 19 ++++++++----------- key-binding.c | 4 ++++ key-binding.h | 1 + main.c | 5 ++++- render.c | 2 +- terminal.c | 1 - terminal.h | 1 - wayland.c | 14 +++++++------- wayland.h | 10 +++++----- 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/input.c b/input.c index 04d03bbe..9981ecee 100644 --- a/input.c +++ b/input.c @@ -489,11 +489,6 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN"); } - /* Set selection-override modmask from configured mods and seat's mod indices */ - const struct config_key_modifiers* override_mods = - &wayl->conf->mouse.selection_override_modifiers; - seat->kbd.selection_override_modmask = conf_modifiers_to_mask(seat, override_mods); - munmap(map_str, size); close(fd); @@ -2237,17 +2232,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (seat->wl_keyboard != NULL && seat->kbd.xkb_state != NULL) { /* Seat has keyboard - use mouse bindings *with* modifiers */ + const struct key_binding_set *bindings = key_binding_for( + wayl->key_binding_manager, term, seat); + xassert(bindings != NULL); + xkb_mod_mask_t mods; get_current_modifiers(seat, &mods, NULL, 0); mods &= seat->kbd.bind_significant; - /* Ignore selection override modifiers when matching modifiers */ - mods &= ~seat->kbd.selection_override_modmask; + /* Ignore selection override modifiers when + * matching modifiers */ + mods &= ~bindings->selection_overrides; const struct key_binding *match = NULL; - const struct key_binding_set *bindings = key_binding_for( - wayl->key_binding_manager, term, seat); - xassert(bindings != NULL); tll_foreach(bindings->mouse, it) { const struct key_binding *binding = &it->item; @@ -2278,7 +2275,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, else { /* Seat does NOT have a keyboard - use mouse bindings *without* modifiers */ const struct config_key_binding *match = NULL; - const struct config *conf = seat->wayl->conf; + const struct config *conf = term->conf; for (size_t i = 0; i < conf->bindings.mouse.count; i++) { const struct config_key_binding *binding = diff --git a/key-binding.c b/key-binding.c index a9e23d44..9133f60c 100644 --- a/key-binding.c +++ b/key-binding.c @@ -460,6 +460,9 @@ load_keymap(struct key_set *set) convert_search_bindings(set); convert_url_bindings(set); convert_mouse_bindings(set); + + set->public.selection_overrides = conf_modifiers_to_mask( + set->seat, &set->conf->mouse.selection_override_modifiers); } void @@ -495,6 +498,7 @@ unload_keymap(struct key_set *set) key_bindings_destroy(&set->public.search); key_bindings_destroy(&set->public.url); key_bindings_destroy(&set->public.mouse); + set->public.selection_overrides = 0; } void diff --git a/key-binding.h b/key-binding.h index a8301fd4..f30184c5 100644 --- a/key-binding.h +++ b/key-binding.h @@ -112,6 +112,7 @@ struct key_binding_set { key_binding_list_t search; key_binding_list_t url; key_binding_list_t mouse; + xkb_mod_mask_t selection_overrides; }; struct key_binding_manager; diff --git a/main.c b/main.c index 0acb7ea6..56fc1a01 100644 --- a/main.c +++ b/main.c @@ -605,8 +605,11 @@ main(int argc, char *const *argv) if ((key_binding_manager = key_binding_manager_new()) == NULL) goto out; - if ((wayl = wayl_init(&conf, fdm, key_binding_manager)) == NULL) + if ((wayl = wayl_init( + fdm, key_binding_manager, conf.presentation_timings)) == NULL) + { goto out; + } if ((renderer = render_init(fdm, wayl)) == NULL) goto out; diff --git a/render.c b/render.c index 5fa82e61..3248b7ae 100644 --- a/render.c +++ b/render.c @@ -2920,7 +2920,7 @@ grid_render(struct terminal *term) wl_surface_set_buffer_scale(term->window->surface, term->scale); - if (term->wl->presentation != NULL && term->render.presentation_timings) { + if (term->wl->presentation != NULL && term->conf->presentation_timings) { struct timespec commit_time; clock_gettime(term->wl->presentation_clock_id, &commit_time); diff --git a/terminal.c b/terminal.c index 2bb35ef5..389024f8 100644 --- a/terminal.c +++ b/terminal.c @@ -1202,7 +1202,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .count = conf->render_worker_count, .queue = tll_init(), }, - .presentation_timings = conf->presentation_timings, }, .delayed_render_timer = { .is_armed = false, diff --git a/terminal.h b/terminal.h index 6c566e6e..ea86db24 100644 --- a/terminal.h +++ b/terminal.h @@ -591,7 +591,6 @@ struct terminal { size_t search_glyph_offset; - bool presentation_timings; struct timespec input_time; } render; diff --git a/wayland.c b/wayland.c index 2eeb1d72..d65a571b 100644 --- a/wayland.c +++ b/wayland.c @@ -1013,7 +1013,7 @@ handle_global(void *data, struct wl_registry *registry, } else if (strcmp(interface, wp_presentation_interface.name) == 0) { - if (wayl->conf->presentation_timings) { + if (wayl->presentation_timings) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1190,8 +1190,8 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data) } struct wayland * -wayl_init(const struct config *conf, struct fdm *fdm, - struct key_binding_manager *key_binding_manager) +wayl_init(struct fdm *fdm, struct key_binding_manager *key_binding_manager, + bool presentation_timings) { struct wayland *wayl = calloc(1, sizeof(*wayl)); if (unlikely(wayl == NULL)) { @@ -1199,10 +1199,10 @@ wayl_init(const struct config *conf, struct fdm *fdm, return NULL; } - wayl->conf = conf; wayl->fdm = fdm; wayl->key_binding_manager = key_binding_manager; wayl->fd = -1; + wayl->presentation_timings = presentation_timings; if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) { LOG_ERR("failed to add FDM hook"); @@ -1253,16 +1253,16 @@ wayl_init(const struct config *conf, struct fdm *fdm, LOG_WARN("no primary selection available"); #if defined(HAVE_XDG_ACTIVATION) - if (wayl->xdg_activation == NULL && conf->bell.urgent) { + if (wayl->xdg_activation == NULL) { #else - if (conf->bell.urgent) { + if (true) { #endif LOG_WARN( "no XDG activation support; " "bell.urgent will fall back to coloring the window margins red"); } - if (conf->presentation_timings && wayl->presentation == NULL) { + if (presentation_timings && wayl->presentation == NULL) { LOG_ERR("presentation time interface not implemented by compositor"); goto out; } diff --git a/wayland.h b/wayland.h index 90087706..f0c9baa3 100644 --- a/wayland.h +++ b/wayland.h @@ -6,6 +6,7 @@ #include #include +#include /* Wayland protocols */ #include @@ -22,7 +23,6 @@ #include #include -#include "config.h" #include "fdm.h" /* Forward declarations */ @@ -354,10 +354,8 @@ struct wl_window { int resize_timeout_fd; }; -struct config; struct terminal; struct wayland { - const struct config *conf; struct fdm *fdm; struct key_binding_manager *key_binding_manager; @@ -381,6 +379,7 @@ struct wayland { struct xdg_activation_v1 *xdg_activation; #endif + bool presentation_timings; struct wp_presentation *presentation; uint32_t presentation_clock_id; @@ -395,8 +394,9 @@ struct wayland { tll(struct terminal *) terms; }; -struct wayland *wayl_init(const struct config *conf, struct fdm *fdm, - struct key_binding_manager *key_binding_manager); +struct wayland *wayl_init( + struct fdm *fdm, struct key_binding_manager *key_binding_manager, + bool presentation_timings); void wayl_destroy(struct wayland *wayl); bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale); -- cgit v1.3