wayland: refactor: remove ‘struct config’ pointer from wayland struct

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
This commit is contained in:
Daniel Eklöf 2022-04-17 16:29:30 +02:00
parent 7a5e5a80b9
commit 24ee3dcc10
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
9 changed files with 30 additions and 27 deletions

19
input.c
View file

@ -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"); 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); munmap(map_str, size);
close(fd); 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) { if (seat->wl_keyboard != NULL && seat->kbd.xkb_state != NULL) {
/* Seat has keyboard - use mouse bindings *with* modifiers */ /* 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; xkb_mod_mask_t mods;
get_current_modifiers(seat, &mods, NULL, 0); get_current_modifiers(seat, &mods, NULL, 0);
mods &= seat->kbd.bind_significant; mods &= seat->kbd.bind_significant;
/* Ignore selection override modifiers when matching modifiers */ /* Ignore selection override modifiers when
mods &= ~seat->kbd.selection_override_modmask; * matching modifiers */
mods &= ~bindings->selection_overrides;
const struct key_binding *match = NULL; 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) { tll_foreach(bindings->mouse, it) {
const struct key_binding *binding = &it->item; const struct key_binding *binding = &it->item;
@ -2278,7 +2275,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
else { else {
/* Seat does NOT have a keyboard - use mouse bindings *without* modifiers */ /* Seat does NOT have a keyboard - use mouse bindings *without* modifiers */
const struct config_key_binding *match = NULL; 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++) { for (size_t i = 0; i < conf->bindings.mouse.count; i++) {
const struct config_key_binding *binding = const struct config_key_binding *binding =

View file

@ -460,6 +460,9 @@ load_keymap(struct key_set *set)
convert_search_bindings(set); convert_search_bindings(set);
convert_url_bindings(set); convert_url_bindings(set);
convert_mouse_bindings(set); convert_mouse_bindings(set);
set->public.selection_overrides = conf_modifiers_to_mask(
set->seat, &set->conf->mouse.selection_override_modifiers);
} }
void void
@ -495,6 +498,7 @@ unload_keymap(struct key_set *set)
key_bindings_destroy(&set->public.search); key_bindings_destroy(&set->public.search);
key_bindings_destroy(&set->public.url); key_bindings_destroy(&set->public.url);
key_bindings_destroy(&set->public.mouse); key_bindings_destroy(&set->public.mouse);
set->public.selection_overrides = 0;
} }
void void

View file

@ -112,6 +112,7 @@ struct key_binding_set {
key_binding_list_t search; key_binding_list_t search;
key_binding_list_t url; key_binding_list_t url;
key_binding_list_t mouse; key_binding_list_t mouse;
xkb_mod_mask_t selection_overrides;
}; };
struct key_binding_manager; struct key_binding_manager;

5
main.c
View file

@ -605,8 +605,11 @@ main(int argc, char *const *argv)
if ((key_binding_manager = key_binding_manager_new()) == NULL) if ((key_binding_manager = key_binding_manager_new()) == NULL)
goto out; 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; goto out;
}
if ((renderer = render_init(fdm, wayl)) == NULL) if ((renderer = render_init(fdm, wayl)) == NULL)
goto out; goto out;

View file

@ -2920,7 +2920,7 @@ grid_render(struct terminal *term)
wl_surface_set_buffer_scale(term->window->surface, term->scale); 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; struct timespec commit_time;
clock_gettime(term->wl->presentation_clock_id, &commit_time); clock_gettime(term->wl->presentation_clock_id, &commit_time);

View file

@ -1202,7 +1202,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.count = conf->render_worker_count, .count = conf->render_worker_count,
.queue = tll_init(), .queue = tll_init(),
}, },
.presentation_timings = conf->presentation_timings,
}, },
.delayed_render_timer = { .delayed_render_timer = {
.is_armed = false, .is_armed = false,

View file

@ -591,7 +591,6 @@ struct terminal {
size_t search_glyph_offset; size_t search_glyph_offset;
bool presentation_timings;
struct timespec input_time; struct timespec input_time;
} render; } render;

View file

@ -1013,7 +1013,7 @@ handle_global(void *data, struct wl_registry *registry,
} }
else if (strcmp(interface, wp_presentation_interface.name) == 0) { else if (strcmp(interface, wp_presentation_interface.name) == 0) {
if (wayl->conf->presentation_timings) { if (wayl->presentation_timings) {
const uint32_t required = 1; const uint32_t required = 1;
if (!verify_iface_version(interface, version, required)) if (!verify_iface_version(interface, version, required))
return; return;
@ -1190,8 +1190,8 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data)
} }
struct wayland * struct wayland *
wayl_init(const struct config *conf, struct fdm *fdm, wayl_init(struct fdm *fdm, struct key_binding_manager *key_binding_manager,
struct key_binding_manager *key_binding_manager) bool presentation_timings)
{ {
struct wayland *wayl = calloc(1, sizeof(*wayl)); struct wayland *wayl = calloc(1, sizeof(*wayl));
if (unlikely(wayl == NULL)) { if (unlikely(wayl == NULL)) {
@ -1199,10 +1199,10 @@ wayl_init(const struct config *conf, struct fdm *fdm,
return NULL; return NULL;
} }
wayl->conf = conf;
wayl->fdm = fdm; wayl->fdm = fdm;
wayl->key_binding_manager = key_binding_manager; wayl->key_binding_manager = key_binding_manager;
wayl->fd = -1; wayl->fd = -1;
wayl->presentation_timings = presentation_timings;
if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) { if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) {
LOG_ERR("failed to add FDM hook"); 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"); LOG_WARN("no primary selection available");
#if defined(HAVE_XDG_ACTIVATION) #if defined(HAVE_XDG_ACTIVATION)
if (wayl->xdg_activation == NULL && conf->bell.urgent) { if (wayl->xdg_activation == NULL) {
#else #else
if (conf->bell.urgent) { if (true) {
#endif #endif
LOG_WARN( LOG_WARN(
"no XDG activation support; " "no XDG activation support; "
"bell.urgent will fall back to coloring the window margins red"); "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"); LOG_ERR("presentation time interface not implemented by compositor");
goto out; goto out;
} }

View file

@ -6,6 +6,7 @@
#include <uchar.h> #include <uchar.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
/* Wayland protocols */ /* Wayland protocols */
#include <presentation-time.h> #include <presentation-time.h>
@ -22,7 +23,6 @@
#include <fcft/fcft.h> #include <fcft/fcft.h>
#include <tllist.h> #include <tllist.h>
#include "config.h"
#include "fdm.h" #include "fdm.h"
/* Forward declarations */ /* Forward declarations */
@ -354,10 +354,8 @@ struct wl_window {
int resize_timeout_fd; int resize_timeout_fd;
}; };
struct config;
struct terminal; struct terminal;
struct wayland { struct wayland {
const struct config *conf;
struct fdm *fdm; struct fdm *fdm;
struct key_binding_manager *key_binding_manager; struct key_binding_manager *key_binding_manager;
@ -381,6 +379,7 @@ struct wayland {
struct xdg_activation_v1 *xdg_activation; struct xdg_activation_v1 *xdg_activation;
#endif #endif
bool presentation_timings;
struct wp_presentation *presentation; struct wp_presentation *presentation;
uint32_t presentation_clock_id; uint32_t presentation_clock_id;
@ -395,8 +394,9 @@ struct wayland {
tll(struct terminal *) terms; tll(struct terminal *) terms;
}; };
struct wayland *wayl_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl_init(
struct key_binding_manager *key_binding_manager); struct fdm *fdm, struct key_binding_manager *key_binding_manager,
bool presentation_timings);
void wayl_destroy(struct wayland *wayl); void wayl_destroy(struct wayland *wayl);
bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale); bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale);