From f63458ef3387eac67a402e6ce7bedd91eb49d9bc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 12:57:37 +0100 Subject: term: move per-window wayland objects from wayland struct to terminal struct Short term, we want to break out the wayland backend from the terminal struct. Long term, we might want to support multiple windows. One step towards both the above is separating global wayland objects from per-window objects. --- search.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'search.c') diff --git a/search.c b/search.c index 45ca675e..59ac0152 100644 --- a/search.c +++ b/search.c @@ -19,8 +19,8 @@ static void search_cancel_keep_selection(struct terminal *term) { - wl_surface_attach(term->wl.search_surface, NULL, 0, 0); - wl_surface_commit(term->wl.search_surface); + wl_surface_attach(term->window.search_surface, NULL, 0, 0); + wl_surface_commit(term->window.search_surface); free(term->search.buf); term->search.buf = NULL; -- cgit v1.3 From c9455d5f211616ce3750e58a472e1b5a4251b8be Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 17:07:44 +0100 Subject: kbd: move into wayland --- input.c | 136 ++++++++++++++++++++++++++++++------------------------------ kbd.c | 18 -------- kbd.h | 35 ---------------- main.c | 31 +++++++------- meson.build | 1 - search.c | 16 +++---- selection.c | 2 +- terminal.c | 6 +-- terminal.h | 2 - wayland.c | 11 +++++ wayland.h | 38 +++++++++++++++-- 11 files changed, 141 insertions(+), 155 deletions(-) delete mode 100644 kbd.c delete mode 100644 kbd.h (limited to 'search.c') diff --git a/input.c b/input.c index 00397974..975923a3 100644 --- a/input.c +++ b/input.c @@ -35,45 +35,45 @@ 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 (term->kbd.xkb_compose_state != NULL) { - xkb_compose_state_unref(term->kbd.xkb_compose_state); - term->kbd.xkb_compose_state = NULL; + if (term->wl.kbd.xkb_compose_state != NULL) { + xkb_compose_state_unref(term->wl.kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state = NULL; } - if (term->kbd.xkb_compose_table != NULL) { - xkb_compose_table_unref(term->kbd.xkb_compose_table); - term->kbd.xkb_compose_table = NULL; + if (term->wl.kbd.xkb_compose_table != NULL) { + xkb_compose_table_unref(term->wl.kbd.xkb_compose_table); + term->wl.kbd.xkb_compose_table = NULL; } - if (term->kbd.xkb_keymap != NULL) { - xkb_keymap_unref(term->kbd.xkb_keymap); - term->kbd.xkb_keymap = NULL; + if (term->wl.kbd.xkb_keymap != NULL) { + xkb_keymap_unref(term->wl.kbd.xkb_keymap); + term->wl.kbd.xkb_keymap = NULL; } - if (term->kbd.xkb_state != NULL) { - xkb_state_unref(term->kbd.xkb_state); - term->kbd.xkb_state = NULL; + if (term->wl.kbd.xkb_state != NULL) { + xkb_state_unref(term->wl.kbd.xkb_state); + term->wl.kbd.xkb_state = NULL; } - if (term->kbd.xkb != NULL) { - xkb_context_unref(term->kbd.xkb); - term->kbd.xkb = NULL; + if (term->wl.kbd.xkb != NULL) { + xkb_context_unref(term->wl.kbd.xkb); + term->wl.kbd.xkb = NULL; } - term->kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - term->kbd.xkb_keymap = xkb_keymap_new_from_string( - term->kbd.xkb, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, + term->wl.kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + term->wl.kbd.xkb_keymap = xkb_keymap_new_from_string( + term->wl.kbd.xkb, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); /* TODO: initialize in enter? */ - term->kbd.xkb_state = xkb_state_new(term->kbd.xkb_keymap); + term->wl.kbd.xkb_state = xkb_state_new(term->wl.kbd.xkb_keymap); - term->kbd.mod_shift = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Shift"); - term->kbd.mod_alt = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Mod1") ; - term->kbd.mod_ctrl = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Control"); - term->kbd.mod_meta = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Mod4"); + term->wl.kbd.mod_shift = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Shift"); + term->wl.kbd.mod_alt = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Mod1") ; + term->wl.kbd.mod_ctrl = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Control"); + term->wl.kbd.mod_meta = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Mod4"); /* Compose (dead keys) */ - term->kbd.xkb_compose_table = xkb_compose_table_new_from_locale( - term->kbd.xkb, setlocale(LC_CTYPE, NULL), XKB_COMPOSE_COMPILE_NO_FLAGS); - term->kbd.xkb_compose_state = xkb_compose_state_new( - term->kbd.xkb_compose_table, XKB_COMPOSE_STATE_NO_FLAGS); + term->wl.kbd.xkb_compose_table = xkb_compose_table_new_from_locale( + term->wl.kbd.xkb, setlocale(LC_CTYPE, NULL), XKB_COMPOSE_COMPILE_NO_FLAGS); + term->wl.kbd.xkb_compose_state = xkb_compose_state_new( + term->wl.kbd.xkb_compose_table, XKB_COMPOSE_STATE_NO_FLAGS); munmap(map_str, size); close(fd); @@ -91,12 +91,12 @@ keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, static bool start_repeater(struct terminal *term, uint32_t key) { - if (term->kbd.repeat.dont_re_repeat) + if (term->wl.kbd.repeat.dont_re_repeat) return true; struct itimerspec t = { - .it_value = {.tv_sec = 0, .tv_nsec = term->kbd.repeat.delay * 1000000}, - .it_interval = {.tv_sec = 0, .tv_nsec = 1000000000 / term->kbd.repeat.rate}, + .it_value = {.tv_sec = 0, .tv_nsec = term->wl.kbd.repeat.delay * 1000000}, + .it_interval = {.tv_sec = 0, .tv_nsec = 1000000000 / term->wl.kbd.repeat.rate}, }; if (t.it_value.tv_nsec >= 1000000000) { @@ -107,22 +107,22 @@ start_repeater(struct terminal *term, uint32_t key) t.it_interval.tv_sec += t.it_interval.tv_nsec / 1000000000; t.it_interval.tv_nsec %= 1000000000; } - if (timerfd_settime(term->kbd.repeat.fd, 0, &t, NULL) < 0) { + if (timerfd_settime(term->wl.kbd.repeat.fd, 0, &t, NULL) < 0) { LOG_ERRNO("failed to arm keyboard repeat timer"); return false; } - term->kbd.repeat.key = key; + term->wl.kbd.repeat.key = key; return true; } static bool stop_repeater(struct terminal *term, uint32_t key) { - if (key != -1 && key != term->kbd.repeat.key) + if (key != -1 && key != term->wl.kbd.repeat.key) return true; - if (timerfd_settime(term->kbd.repeat.fd, 0, &(struct itimerspec){{0}}, NULL) < 0) { + if (timerfd_settime(term->wl.kbd.repeat.fd, 0, &(struct itimerspec){{0}}, NULL) < 0) { LOG_ERRNO("failed to disarm keyboard repeat timer"); return false; } @@ -146,10 +146,10 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, { struct terminal *term = data; - const xkb_mod_mask_t ctrl = 1 << term->kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << term->kbd.mod_alt; - const xkb_mod_mask_t shift = 1 << term->kbd.mod_shift; - const xkb_mod_mask_t meta = 1 << term->kbd.mod_meta; + const xkb_mod_mask_t ctrl = 1 << term->wl.kbd.mod_ctrl; + const xkb_mod_mask_t alt = 1 << term->wl.kbd.mod_alt; + const xkb_mod_mask_t shift = 1 << term->wl.kbd.mod_shift; + const xkb_mod_mask_t meta = 1 << term->wl.kbd.mod_meta; if (state == XKB_KEY_UP) { stop_repeater(term, key); @@ -157,7 +157,7 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, } key += 8; - xkb_keysym_t sym = xkb_state_key_get_one_sym(term->kbd.xkb_state, key); + xkb_keysym_t sym = xkb_state_key_get_one_sym(term->wl.kbd.xkb_state, key); #if 0 char foo[100]; @@ -165,16 +165,16 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, LOG_INFO("%s", foo); #endif - xkb_compose_state_feed(term->kbd.xkb_compose_state, sym); + xkb_compose_state_feed(term->wl.kbd.xkb_compose_state, sym); enum xkb_compose_status compose_status = xkb_compose_state_get_status( - term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state); if (compose_status == XKB_COMPOSE_COMPOSING) return; xkb_mod_mask_t mods = xkb_state_serialize_mods( - term->kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); - //xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods(term->kbd.xkb_state, key); + term->wl.kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); + //xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods(term->wl.kbd.xkb_state, key); xkb_mod_mask_t consumed = 0x0; xkb_mod_mask_t significant = ctrl | alt | shift | meta; xkb_mod_mask_t effective_mods = mods & ~consumed & significant; @@ -188,7 +188,7 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, #if 0 for (size_t i = 0; i < 32; i++) { if (mods & (1 << i)) { - LOG_INFO("%s", xkb_keymap_mod_get_name(term->kbd.xkb_keymap, i)); + LOG_INFO("%s", xkb_keymap_mod_get_name(term->wl.kbd.xkb_keymap, i)); } } #endif @@ -200,10 +200,10 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, bool found_map = false; enum modifier keymap_mods = MOD_NONE; - keymap_mods |= term->kbd.shift ? MOD_SHIFT : MOD_NONE; - keymap_mods |= term->kbd.alt ? MOD_ALT : MOD_NONE; - keymap_mods |= term->kbd.ctrl ? MOD_CTRL : MOD_NONE; - keymap_mods |= term->kbd.meta ? MOD_META : MOD_NONE; + keymap_mods |= term->wl.kbd.shift ? MOD_SHIFT : MOD_NONE; + keymap_mods |= term->wl.kbd.alt ? MOD_ALT : MOD_NONE; + keymap_mods |= term->wl.kbd.ctrl ? MOD_CTRL : MOD_NONE; + keymap_mods |= term->wl.kbd.meta ? MOD_META : MOD_NONE; if (effective_mods == shift) { if (sym == XKB_KEY_Page_Up) { @@ -268,11 +268,11 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, if (compose_status == XKB_COMPOSE_COMPOSED) { count = xkb_compose_state_get_utf8( - term->kbd.xkb_compose_state, (char *)buf, sizeof(buf)); - xkb_compose_state_reset(term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state, (char *)buf, sizeof(buf)); + xkb_compose_state_reset(term->wl.kbd.xkb_compose_state); } else { count = xkb_state_key_get_utf8( - term->kbd.xkb_state, key, (char *)buf, sizeof(buf)); + term->wl.kbd.xkb_state, key, (char *)buf, sizeof(buf)); } if (count > 0) { @@ -338,17 +338,17 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, mods_depressed, mods_latched, mods_locked, group); xkb_state_update_mask( - term->kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); + term->wl.kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); /* Update state of modifiers we're interrested in for e.g mouse events */ - term->kbd.shift = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_shift, XKB_STATE_MODS_DEPRESSED); - term->kbd.alt = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_alt, XKB_STATE_MODS_DEPRESSED); - term->kbd.ctrl = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); - term->kbd.meta = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.shift = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_shift, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.alt = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_alt, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.ctrl = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.meta = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); } static void @@ -357,8 +357,8 @@ keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, { struct terminal *term = data; LOG_DBG("keyboard repeat: rate=%d, delay=%d", rate, delay); - term->kbd.repeat.rate = rate; - term->kbd.repeat.delay = delay; + term->wl.kbd.repeat.rate = rate; + term->wl.kbd.repeat.delay = delay; } const struct wl_keyboard_listener keyboard_listener = { @@ -430,7 +430,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, term_mouse_motion( term, term->mouse.button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); } static void @@ -467,7 +467,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case 2: selection_mark_word(term, term->mouse.col, term->mouse.row, - term->kbd.ctrl, serial); + term->wl.kbd.ctrl, serial); break; case 3: @@ -484,7 +484,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, term->mouse.last_button = button; term->mouse.last_time = now; term_mouse_down(term, button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); break; } @@ -496,7 +496,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, term->mouse.button = 0; /* For motion events */ term_mouse_up(term, button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); break; } } @@ -520,7 +520,7 @@ mouse_scroll(struct terminal *term, int amount) */ xkb_keycode_t key = xkb_keymap_key_by_name( - term->kbd.xkb_keymap, button == BTN_BACK ? "UP" : "DOWN"); + term->wl.kbd.xkb_keymap, button == BTN_BACK ? "UP" : "DOWN"); for (int i = 0; i < amount; i++) keyboard_key(term, NULL, term->input_serial, 0, key - 8, XKB_KEY_DOWN); @@ -528,7 +528,7 @@ mouse_scroll(struct terminal *term, int amount) } else { for (int i = 0; i < amount; i++) term_mouse_down(term, button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); scrollback(term, amount); } diff --git a/kbd.c b/kbd.c deleted file mode 100644 index c38e77ba..00000000 --- a/kbd.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "kbd.h" - -#include - -void -kbd_destroy(struct kbd *kbd) -{ - if (kbd->xkb_compose_state != NULL) - xkb_compose_state_unref(kbd->xkb_compose_state); - if (kbd->xkb_compose_table != NULL) - xkb_compose_table_unref(kbd->xkb_compose_table); - if (kbd->xkb_keymap != NULL) - xkb_keymap_unref(kbd->xkb_keymap); - if (kbd->xkb_state != NULL) - xkb_state_unref(kbd->xkb_state); - if (kbd->xkb != NULL) - xkb_context_unref(kbd->xkb); -} diff --git a/kbd.h b/kbd.h deleted file mode 100644 index 06de5b50..00000000 --- a/kbd.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include - -#include - -struct kbd { - struct xkb_context *xkb; - struct xkb_keymap *xkb_keymap; - struct xkb_state *xkb_state; - struct xkb_compose_table *xkb_compose_table; - struct xkb_compose_state *xkb_compose_state; - struct { - int fd; - - bool dont_re_repeat; - int32_t delay; - int32_t rate; - uint32_t key; - } repeat; - - xkb_mod_index_t mod_shift; - xkb_mod_index_t mod_alt; - xkb_mod_index_t mod_ctrl; - xkb_mod_index_t mod_meta; - - /* Enabled modifiers */ - bool shift; - bool alt; - bool ctrl; - bool meta; -}; - -void kbd_destroy(struct kbd *kbd); diff --git a/main.c b/main.c index 7c8de292..90f9ef2a 100644 --- a/main.c +++ b/main.c @@ -492,7 +492,7 @@ fdm_repeat(struct fdm *fdm, int fd, int events, void *data) struct terminal *term = data; uint64_t expiration_count; ssize_t ret = read( - term->kbd.repeat.fd, &expiration_count, sizeof(expiration_count)); + term->wl.kbd.repeat.fd, &expiration_count, sizeof(expiration_count)); if (ret < 0) { if (errno == EAGAIN) @@ -502,10 +502,10 @@ fdm_repeat(struct fdm *fdm, int fd, int events, void *data) return false; } - term->kbd.repeat.dont_re_repeat = true; + term->wl.kbd.repeat.dont_re_repeat = true; for (size_t i = 0; i < expiration_count; i++) - input_repeat(term, term->kbd.repeat.key); - term->kbd.repeat.dont_re_repeat = false; + input_repeat(term, term->wl.kbd.repeat.key); + term->wl.kbd.repeat.dont_re_repeat = false; return true; } @@ -742,11 +742,6 @@ main(int argc, char *const *argv) //.background = conf.colors.bg }, }, - .kbd = { - .repeat = { - .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), - }, - }, .colors = { .default_fg = conf.colors.fg, .default_bg = conf.colors.bg, @@ -788,6 +783,13 @@ main(int argc, char *const *argv) .normal = {.damage = tll_init(), .scroll_damage = tll_init()}, .alt = {.damage = tll_init(), .scroll_damage = tll_init()}, .grid = &term.normal, + .wl = { + .kbd = { + .repeat = { + .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), + }, + }, + }, .render = { .scrollback_lines = conf.scrollback_lines, .workers = { @@ -833,7 +835,7 @@ main(int argc, char *const *argv) goto out; } - if (term.flash.fd == -1 || term.blink.fd == -1 || term.kbd.repeat.fd == -1) { + if (term.flash.fd == -1 || term.blink.fd == -1 || term.wl.kbd.repeat.fd == -1) { LOG_ERR("failed to create timers"); goto out; } @@ -1108,7 +1110,7 @@ main(int argc, char *const *argv) fdm_add(fdm, wl_display_get_fd(term.wl.display), EPOLLIN, &fdm_wayl, &term); fdm_add(fdm, term.ptmx, EPOLLIN, &fdm_ptmx, &term); - fdm_add(fdm, term.kbd.repeat.fd, EPOLLIN, &fdm_repeat, &term); + fdm_add(fdm, term.wl.kbd.repeat.fd, EPOLLIN, &fdm_repeat, &term); fdm_add(fdm, term.flash.fd, EPOLLIN, &fdm_flash, &term); fdm_add(fdm, term.blink.fd, EPOLLIN, &fdm_blink, &term); fdm_add(fdm, term.delayed_render_timer.lower_fd, EPOLLIN, &fdm_delayed_render, &term); @@ -1127,7 +1129,7 @@ out: if (fdm != NULL) { fdm_del(fdm, wl_display_get_fd(term.wl.display)); fdm_del(fdm, term.ptmx); - fdm_del(fdm, term.kbd.repeat.fd); + fdm_del(fdm, term.wl.kbd.repeat.fd); fdm_del(fdm, term.flash.fd); fdm_del(fdm, term.blink.fd); fdm_del(fdm, term.delayed_render_timer.lower_fd); @@ -1150,7 +1152,6 @@ out: shm_fini(); - kbd_destroy(&term.kbd); wayl_win_destroy(&term.window); wayl_destroy(&term.wl); @@ -1174,8 +1175,8 @@ out: close(term.flash.fd); if (term.blink.fd != -1) close(term.blink.fd); - if (term.kbd.repeat.fd != -1) - close(term.kbd.repeat.fd); + if (term.wl.kbd.repeat.fd != -1) + close(term.wl.kbd.repeat.fd); if (term.ptmx != -1) close(term.ptmx); diff --git a/meson.build b/meson.build index cc6bc7f4..da91ff91 100644 --- a/meson.build +++ b/meson.build @@ -72,7 +72,6 @@ executable( 'font.c', 'font.h', 'grid.c', 'grid.h', 'input.c', 'input.h', - 'kbd.c', 'kbd.h', 'log.c', 'log.h', 'main.c', 'osc.c', 'osc.h', diff --git a/search.c b/search.c index 59ac0152..e9da3770 100644 --- a/search.c +++ b/search.c @@ -294,13 +294,13 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask { LOG_DBG("search: input: sym=%d/0x%x, mods=0x%08x", sym, sym, mods); - const xkb_mod_mask_t ctrl = 1 << term->kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << term->kbd.mod_alt; - //const xkb_mod_mask_t shift = 1 << term->kbd.mod_shift; - //const xkb_mod_mask_t meta = 1 << term->kbd.mod_meta; + const xkb_mod_mask_t ctrl = 1 << term->wl.kbd.mod_ctrl; + const xkb_mod_mask_t alt = 1 << term->wl.kbd.mod_alt; + //const xkb_mod_mask_t shift = 1 << term->wl.kbd.mod_shift; + //const xkb_mod_mask_t meta = 1 << term->wl.kbd.mod_meta; enum xkb_compose_status compose_status = xkb_compose_state_get_status( - term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state); /* Cancel search */ if ((mods == 0 && sym == XKB_KEY_Escape) || @@ -449,11 +449,11 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask if (compose_status == XKB_COMPOSE_COMPOSED) { count = xkb_compose_state_get_utf8( - term->kbd.xkb_compose_state, (char *)buf, sizeof(buf)); - xkb_compose_state_reset(term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state, (char *)buf, sizeof(buf)); + xkb_compose_state_reset(term->wl.kbd.xkb_compose_state); } else { count = xkb_state_key_get_utf8( - term->kbd.xkb_state, key, (char *)buf, sizeof(buf)); + term->wl.kbd.xkb_state, key, (char *)buf, sizeof(buf)); } const char *src = (const char *)buf; diff --git a/selection.c b/selection.c index e53ace8b..33875e94 100644 --- a/selection.c +++ b/selection.c @@ -22,7 +22,7 @@ selection_enabled(const struct terminal *term) { return term->mouse_tracking == MOUSE_NONE || - term->kbd.shift || + term->wl.kbd.shift || term->is_searching; } diff --git a/terminal.c b/terminal.c index 95a60682..ada701cc 100644 --- a/terminal.c +++ b/terminal.c @@ -480,7 +480,7 @@ void term_mouse_down(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->kbd.shift) { + if (term->wl.kbd.shift) { /* "raw" mouse mode */ return; } @@ -513,7 +513,7 @@ void term_mouse_up(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->kbd.shift) { + if (term->wl.kbd.shift) { /* "raw" mouse mode */ return; } @@ -551,7 +551,7 @@ void term_mouse_motion(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->kbd.shift) { + if (term->wl.kbd.shift) { /* "raw" mouse mode */ return; } diff --git a/terminal.h b/terminal.h index 7ee45ca7..cd8d7768 100644 --- a/terminal.h +++ b/terminal.h @@ -11,7 +11,6 @@ #include "font.h" #include "tllist.h" #include "wayland.h" -#include "kbd.h" #define likely(c) __builtin_expect(!!(c), 1) #define unlikely(c) __builtin_expect(!!(c), 0) @@ -176,7 +175,6 @@ struct terminal { } blink; struct vt vt; - struct kbd kbd; int scale; int width; /* pixels */ diff --git a/wayland.c b/wayland.c index 96ba3641..e6701de6 100644 --- a/wayland.c +++ b/wayland.c @@ -34,6 +34,17 @@ wayl_destroy(struct wayland *wayl) if (wayl->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); + if (wayl->kbd.xkb_compose_state != NULL) + xkb_compose_state_unref(wayl->kbd.xkb_compose_state); + if (wayl->kbd.xkb_compose_table != NULL) + xkb_compose_table_unref(wayl->kbd.xkb_compose_table); + if (wayl->kbd.xkb_keymap != NULL) + xkb_keymap_unref(wayl->kbd.xkb_keymap); + if (wayl->kbd.xkb_state != NULL) + xkb_state_unref(wayl->kbd.xkb_state); + if (wayl->kbd.xkb != NULL) + xkb_context_unref(wayl->kbd.xkb); + if (wayl->clipboard.data_source != NULL) wl_data_source_destroy(wayl->clipboard.data_source); if (wayl->clipboard.data_offer != NULL) diff --git a/wayland.h b/wayland.h index 1b680b2c..643d5ac5 100644 --- a/wayland.h +++ b/wayland.h @@ -5,6 +5,7 @@ #include #include +#include #include "tllist.h" @@ -27,6 +28,33 @@ struct monitor { float refresh; }; +struct kbd { + struct xkb_context *xkb; + struct xkb_keymap *xkb_keymap; + struct xkb_state *xkb_state; + struct xkb_compose_table *xkb_compose_table; + struct xkb_compose_state *xkb_compose_state; + struct { + int fd; + + bool dont_re_repeat; + int32_t delay; + int32_t rate; + uint32_t key; + } repeat; + + xkb_mod_index_t mod_shift; + xkb_mod_index_t mod_alt; + xkb_mod_index_t mod_ctrl; + xkb_mod_index_t mod_meta; + + /* Enabled modifiers */ + bool shift; + bool alt; + bool ctrl; + bool meta; +}; + struct wl_clipboard { struct wl_data_source *data_source; struct wl_data_offer *data_offer; @@ -70,12 +98,18 @@ struct wayland { struct wl_keyboard *keyboard; struct zxdg_output_manager_v1 *xdg_output_manager; + /* Keyboard */ + struct kbd kbd; + /* Clipboard */ struct wl_data_device_manager *data_device_manager; struct wl_data_device *data_device; struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; struct zwp_primary_selection_device_v1 *primary_selection_device; + struct wl_clipboard clipboard; + struct wl_primary primary; + /* Cursor */ struct { struct wl_pointer *pointer; @@ -88,10 +122,6 @@ struct wayland { char *theme_name; } pointer; - /* Clipboard */ - struct wl_clipboard clipboard; - struct wl_primary primary; - bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ }; -- cgit v1.3 From 9f0b1f94c284e76ff1579e7f34f4a7418ef98b02 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 18:43:07 +0100 Subject: wayland: change all wayland callbacks to take a wayland pointer Instead of passing the terminal to the wayland callbacks, pass a 'struct wayland' pointer. --- input.c | 260 ++++++++++++++++++++++++++++++++---------------------------- main.c | 138 +++++++++++++++++--------------- osc.c | 6 +- search.c | 2 +- selection.c | 8 +- terminal.h | 14 ---- wayland.c | 25 +++++- wayland.h | 31 +++++++- 8 files changed, 269 insertions(+), 215 deletions(-) (limited to 'search.c') diff --git a/input.c b/input.c index 975923a3..56da84d9 100644 --- a/input.c +++ b/input.c @@ -30,50 +30,50 @@ static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size) { - struct terminal *term = data; + struct wayland *wayl = data; char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); /* TODO: free old context + keymap */ - if (term->wl.kbd.xkb_compose_state != NULL) { - xkb_compose_state_unref(term->wl.kbd.xkb_compose_state); - term->wl.kbd.xkb_compose_state = NULL; + if (wayl->kbd.xkb_compose_state != NULL) { + xkb_compose_state_unref(wayl->kbd.xkb_compose_state); + wayl->kbd.xkb_compose_state = NULL; } - if (term->wl.kbd.xkb_compose_table != NULL) { - xkb_compose_table_unref(term->wl.kbd.xkb_compose_table); - term->wl.kbd.xkb_compose_table = NULL; + if (wayl->kbd.xkb_compose_table != NULL) { + xkb_compose_table_unref(wayl->kbd.xkb_compose_table); + wayl->kbd.xkb_compose_table = NULL; } - if (term->wl.kbd.xkb_keymap != NULL) { - xkb_keymap_unref(term->wl.kbd.xkb_keymap); - term->wl.kbd.xkb_keymap = NULL; + if (wayl->kbd.xkb_keymap != NULL) { + xkb_keymap_unref(wayl->kbd.xkb_keymap); + wayl->kbd.xkb_keymap = NULL; } - if (term->wl.kbd.xkb_state != NULL) { - xkb_state_unref(term->wl.kbd.xkb_state); - term->wl.kbd.xkb_state = NULL; + if (wayl->kbd.xkb_state != NULL) { + xkb_state_unref(wayl->kbd.xkb_state); + wayl->kbd.xkb_state = NULL; } - if (term->wl.kbd.xkb != NULL) { - xkb_context_unref(term->wl.kbd.xkb); - term->wl.kbd.xkb = NULL; + if (wayl->kbd.xkb != NULL) { + xkb_context_unref(wayl->kbd.xkb); + wayl->kbd.xkb = NULL; } - term->wl.kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - term->wl.kbd.xkb_keymap = xkb_keymap_new_from_string( - term->wl.kbd.xkb, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, + wayl->kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + wayl->kbd.xkb_keymap = xkb_keymap_new_from_string( + wayl->kbd.xkb, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); /* TODO: initialize in enter? */ - term->wl.kbd.xkb_state = xkb_state_new(term->wl.kbd.xkb_keymap); + wayl->kbd.xkb_state = xkb_state_new(wayl->kbd.xkb_keymap); - term->wl.kbd.mod_shift = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Shift"); - term->wl.kbd.mod_alt = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Mod1") ; - term->wl.kbd.mod_ctrl = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Control"); - term->wl.kbd.mod_meta = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Mod4"); + wayl->kbd.mod_shift = xkb_keymap_mod_get_index(wayl->kbd.xkb_keymap, "Shift"); + wayl->kbd.mod_alt = xkb_keymap_mod_get_index(wayl->kbd.xkb_keymap, "Mod1") ; + wayl->kbd.mod_ctrl = xkb_keymap_mod_get_index(wayl->kbd.xkb_keymap, "Control"); + wayl->kbd.mod_meta = xkb_keymap_mod_get_index(wayl->kbd.xkb_keymap, "Mod4"); /* Compose (dead keys) */ - term->wl.kbd.xkb_compose_table = xkb_compose_table_new_from_locale( - term->wl.kbd.xkb, setlocale(LC_CTYPE, NULL), XKB_COMPOSE_COMPILE_NO_FLAGS); - term->wl.kbd.xkb_compose_state = xkb_compose_state_new( - term->wl.kbd.xkb_compose_table, XKB_COMPOSE_STATE_NO_FLAGS); + wayl->kbd.xkb_compose_table = xkb_compose_table_new_from_locale( + wayl->kbd.xkb, setlocale(LC_CTYPE, NULL), XKB_COMPOSE_COMPILE_NO_FLAGS); + wayl->kbd.xkb_compose_state = xkb_compose_state_new( + wayl->kbd.xkb_compose_table, XKB_COMPOSE_STATE_NO_FLAGS); munmap(map_str, size); close(fd); @@ -83,20 +83,22 @@ static void keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { - struct terminal *term = data; - term->input_serial = serial; - term_focus_in(term); + struct wayland *wayl = data; + wayl->input_serial = serial; + wayl->focused = wayl_terminal_from_surface(wayl, surface); + assert(wayl->focused != NULL); + term_focus_in(wayl->focused); } static bool -start_repeater(struct terminal *term, uint32_t key) +start_repeater(struct wayland *wayl, uint32_t key) { - if (term->wl.kbd.repeat.dont_re_repeat) + if (wayl->kbd.repeat.dont_re_repeat) return true; struct itimerspec t = { - .it_value = {.tv_sec = 0, .tv_nsec = term->wl.kbd.repeat.delay * 1000000}, - .it_interval = {.tv_sec = 0, .tv_nsec = 1000000000 / term->wl.kbd.repeat.rate}, + .it_value = {.tv_sec = 0, .tv_nsec = wayl->kbd.repeat.delay * 1000000}, + .it_interval = {.tv_sec = 0, .tv_nsec = 1000000000 / wayl->kbd.repeat.rate}, }; if (t.it_value.tv_nsec >= 1000000000) { @@ -107,22 +109,22 @@ start_repeater(struct terminal *term, uint32_t key) t.it_interval.tv_sec += t.it_interval.tv_nsec / 1000000000; t.it_interval.tv_nsec %= 1000000000; } - if (timerfd_settime(term->wl.kbd.repeat.fd, 0, &t, NULL) < 0) { + if (timerfd_settime(wayl->kbd.repeat.fd, 0, &t, NULL) < 0) { LOG_ERRNO("failed to arm keyboard repeat timer"); return false; } - term->wl.kbd.repeat.key = key; + wayl->kbd.repeat.key = key; return true; } static bool -stop_repeater(struct terminal *term, uint32_t key) +stop_repeater(struct wayland *wayl, uint32_t key) { - if (key != -1 && key != term->wl.kbd.repeat.key) + if (key != -1 && key != wayl->kbd.repeat.key) return true; - if (timerfd_settime(term->wl.kbd.repeat.fd, 0, &(struct itimerspec){{0}}, NULL) < 0) { + if (timerfd_settime(wayl->kbd.repeat.fd, 0, &(struct itimerspec){{0}}, NULL) < 0) { LOG_ERRNO("failed to disarm keyboard repeat timer"); return false; } @@ -134,30 +136,33 @@ static void keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface) { - struct terminal *term = data; + struct wayland *wayl = data; - stop_repeater(term, -1); - term_focus_out(term); + stop_repeater(wayl, -1); + term_focus_out(wayl->focused); + wayl->focused = NULL; } static void keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl->focused; + assert(term != NULL); - const xkb_mod_mask_t ctrl = 1 << term->wl.kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << term->wl.kbd.mod_alt; - const xkb_mod_mask_t shift = 1 << term->wl.kbd.mod_shift; - const xkb_mod_mask_t meta = 1 << term->wl.kbd.mod_meta; + const xkb_mod_mask_t ctrl = 1 << wayl->kbd.mod_ctrl; + const xkb_mod_mask_t alt = 1 << wayl->kbd.mod_alt; + const xkb_mod_mask_t shift = 1 << wayl->kbd.mod_shift; + const xkb_mod_mask_t meta = 1 << wayl->kbd.mod_meta; if (state == XKB_KEY_UP) { - stop_repeater(term, key); + stop_repeater(wayl, key); return; } key += 8; - xkb_keysym_t sym = xkb_state_key_get_one_sym(term->wl.kbd.xkb_state, key); + xkb_keysym_t sym = xkb_state_key_get_one_sym(wayl->kbd.xkb_state, key); #if 0 char foo[100]; @@ -165,22 +170,22 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, LOG_INFO("%s", foo); #endif - xkb_compose_state_feed(term->wl.kbd.xkb_compose_state, sym); + xkb_compose_state_feed(wayl->kbd.xkb_compose_state, sym); enum xkb_compose_status compose_status = xkb_compose_state_get_status( - term->wl.kbd.xkb_compose_state); + wayl->kbd.xkb_compose_state); if (compose_status == XKB_COMPOSE_COMPOSING) return; xkb_mod_mask_t mods = xkb_state_serialize_mods( - term->wl.kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); - //xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods(term->wl.kbd.xkb_state, key); + wayl->kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); + //xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods(wayl->kbd.xkb_state, key); xkb_mod_mask_t consumed = 0x0; xkb_mod_mask_t significant = ctrl | alt | shift | meta; xkb_mod_mask_t effective_mods = mods & ~consumed & significant; if (term->is_searching) { - start_repeater(term, key - 8); + start_repeater(wayl, key - 8); search_input(term, key, sym, effective_mods); return; } @@ -188,7 +193,7 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, #if 0 for (size_t i = 0; i < 32; i++) { if (mods & (1 << i)) { - LOG_INFO("%s", xkb_keymap_mod_get_name(term->wl.kbd.xkb_keymap, i)); + LOG_INFO("%s", xkb_keymap_mod_get_name(wayl->kbd.xkb_keymap, i)); } } #endif @@ -200,10 +205,10 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, bool found_map = false; enum modifier keymap_mods = MOD_NONE; - keymap_mods |= term->wl.kbd.shift ? MOD_SHIFT : MOD_NONE; - keymap_mods |= term->wl.kbd.alt ? MOD_ALT : MOD_NONE; - keymap_mods |= term->wl.kbd.ctrl ? MOD_CTRL : MOD_NONE; - keymap_mods |= term->wl.kbd.meta ? MOD_META : MOD_NONE; + keymap_mods |= wayl->kbd.shift ? MOD_SHIFT : MOD_NONE; + keymap_mods |= wayl->kbd.alt ? MOD_ALT : MOD_NONE; + keymap_mods |= wayl->kbd.ctrl ? MOD_CTRL : MOD_NONE; + keymap_mods |= wayl->kbd.meta ? MOD_META : MOD_NONE; if (effective_mods == shift) { if (sym == XKB_KEY_Page_Up) { @@ -268,11 +273,11 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, if (compose_status == XKB_COMPOSE_COMPOSED) { count = xkb_compose_state_get_utf8( - term->wl.kbd.xkb_compose_state, (char *)buf, sizeof(buf)); - xkb_compose_state_reset(term->wl.kbd.xkb_compose_state); + wayl->kbd.xkb_compose_state, (char *)buf, sizeof(buf)); + xkb_compose_state_reset(wayl->kbd.xkb_compose_state); } else { count = xkb_state_key_get_utf8( - term->wl.kbd.xkb_state, key, (char *)buf, sizeof(buf)); + wayl->kbd.xkb_state, key, (char *)buf, sizeof(buf)); } if (count > 0) { @@ -324,7 +329,7 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, } } - start_repeater(term, key - 8); + start_repeater(wayl, key - 8); } static void @@ -332,33 +337,33 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) { - struct terminal *term = data; + struct wayland *wayl = data; LOG_DBG("modifiers: depressed=0x%x, latched=0x%x, locked=0x%x, group=%u", mods_depressed, mods_latched, mods_locked, group); xkb_state_update_mask( - term->wl.kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); + wayl->kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); /* Update state of modifiers we're interrested in for e.g mouse events */ - term->wl.kbd.shift = xkb_state_mod_index_is_active( - term->wl.kbd.xkb_state, term->wl.kbd.mod_shift, XKB_STATE_MODS_DEPRESSED); - term->wl.kbd.alt = xkb_state_mod_index_is_active( - term->wl.kbd.xkb_state, term->wl.kbd.mod_alt, XKB_STATE_MODS_DEPRESSED); - term->wl.kbd.ctrl = xkb_state_mod_index_is_active( - term->wl.kbd.xkb_state, term->wl.kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); - term->wl.kbd.meta = xkb_state_mod_index_is_active( - term->wl.kbd.xkb_state, term->wl.kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); + wayl->kbd.shift = xkb_state_mod_index_is_active( + wayl->kbd.xkb_state, wayl->kbd.mod_shift, XKB_STATE_MODS_DEPRESSED); + wayl->kbd.alt = xkb_state_mod_index_is_active( + wayl->kbd.xkb_state, wayl->kbd.mod_alt, XKB_STATE_MODS_DEPRESSED); + wayl->kbd.ctrl = xkb_state_mod_index_is_active( + wayl->kbd.xkb_state, wayl->kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); + wayl->kbd.meta = xkb_state_mod_index_is_active( + wayl->kbd.xkb_state, wayl->kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); } static void keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay) { - struct terminal *term = data; + struct wayland *wayl = data; LOG_DBG("keyboard repeat: rate=%d, delay=%d", rate, delay); - term->wl.kbd.repeat.rate = rate; - term->wl.kbd.repeat.delay = delay; + wayl->kbd.repeat.rate = rate; + wayl->kbd.repeat.delay = delay; } const struct wl_keyboard_listener keyboard_listener = { @@ -373,7 +378,7 @@ const struct wl_keyboard_listener keyboard_listener = { void input_repeat(struct terminal *term, uint32_t key) { - keyboard_key(term, NULL, 0, 0, key, XKB_KEY_DOWN); + keyboard_key(&term->wl, NULL, 0, 0, key, XKB_KEY_DOWN); } static void @@ -381,13 +386,16 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_surface(wayl, surface); + + wayl->moused = term; int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; - term->mouse.col = x / term->cell_width; - term->mouse.row = y / term->cell_height; + wayl->mouse.col = x / term->cell_width; + wayl->mouse.row = y / term->cell_height; render_update_cursor_surface(term); } @@ -396,13 +404,17 @@ static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) { + struct wayland *wayl = data; + wayl->moused = NULL; } static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl->moused; + assert(term != NULL); int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; @@ -413,24 +425,24 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) return; - bool update_selection = term->mouse.button == BTN_LEFT; + 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 (col == term->mouse.col && row == term->mouse.row) + if (col == wayl->mouse.col && row == wayl->mouse.row) return; - term->mouse.col = col; - term->mouse.row = row; + wayl->mouse.col = col; + wayl->mouse.row = row; if (update_selection && !update_selection_early) selection_update(term, col, row); term_mouse_motion( - term, term->mouse.button, term->mouse.row, term->mouse.col, - term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); + term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col, + wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); } static void @@ -439,7 +451,9 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, { LOG_DBG("BUTTON: button=%x, state=%u", button, state); - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl->moused; + assert(term != NULL); search_cancel(term); @@ -448,43 +462,43 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, /* Time since last click */ struct timeval now, since_last; gettimeofday(&now, NULL); - timersub(&now, &term->mouse.last_time, &since_last); + timersub(&now, &wayl->mouse.last_time, &since_last); /* Double- or triple click? */ - if (button == term->mouse.last_button && + if (button == wayl->mouse.last_button && since_last.tv_sec == 0 && since_last.tv_usec <= 300 * 1000) { - term->mouse.count++; + wayl->mouse.count++; } else - term->mouse.count = 1; + wayl->mouse.count = 1; if (button == BTN_LEFT) { - switch (term->mouse.count) { + switch (wayl->mouse.count) { case 1: - selection_start(term, term->mouse.col, term->mouse.row); + selection_start(term, wayl->mouse.col, wayl->mouse.row); break; case 2: - selection_mark_word(term, term->mouse.col, term->mouse.row, - term->wl.kbd.ctrl, serial); + selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, + wayl->kbd.ctrl, serial); break; case 3: - selection_mark_row(term, term->mouse.row, serial); + selection_mark_row(term, wayl->mouse.row, serial); break; } } else { - if (term->mouse.count == 1 && button == BTN_MIDDLE && selection_enabled(term)) + if (wayl->mouse.count == 1 && button == BTN_MIDDLE && selection_enabled(term)) selection_from_primary(term); selection_cancel(term); } - term->mouse.button = button; /* For motion events */ - term->mouse.last_button = button; - term->mouse.last_time = now; - term_mouse_down(term, button, term->mouse.row, term->mouse.col, - term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); + 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, + wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); break; } @@ -494,16 +508,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, else selection_finalize(term, serial); - term->mouse.button = 0; /* For motion events */ - term_mouse_up(term, button, term->mouse.row, term->mouse.col, - term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); + wayl->mouse.button = 0; /* For motion events */ + term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col, + wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); break; } } static void -mouse_scroll(struct terminal *term, int amount) +mouse_scroll(struct wayland *wayl, int amount) { + struct terminal *term = wayl->moused; + assert(term != NULL); + int button = amount < 0 ? BTN_BACK : BTN_FORWARD; void (*scrollback)(struct terminal *term, int rows) @@ -520,15 +537,15 @@ mouse_scroll(struct terminal *term, int amount) */ xkb_keycode_t key = xkb_keymap_key_by_name( - term->wl.kbd.xkb_keymap, button == BTN_BACK ? "UP" : "DOWN"); + wayl->kbd.xkb_keymap, button == BTN_BACK ? "UP" : "DOWN"); for (int i = 0; i < amount; i++) - keyboard_key(term, NULL, term->input_serial, 0, key - 8, XKB_KEY_DOWN); - keyboard_key(term, NULL, term->input_serial, 0, key - 8, XKB_KEY_UP); + keyboard_key(term, NULL, wayl->input_serial, 0, key - 8, XKB_KEY_DOWN); + keyboard_key(term, NULL, wayl->input_serial, 0, key - 8, XKB_KEY_UP); } else { for (int i = 0; i < amount; i++) - term_mouse_down(term, button, term->mouse.row, term->mouse.col, - term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); + term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col, + wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); scrollback(term, amount); } @@ -541,11 +558,12 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL) return; - struct terminal *term = data; - if (term->mouse.have_discrete) + struct wayland *wayl = data; + + if (wayl->mouse.have_discrete) return; - mouse_scroll(term, wl_fixed_to_int(value)); + mouse_scroll(wayl, wl_fixed_to_int(value)); } static void @@ -555,16 +573,16 @@ wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL) return; - struct terminal *term = data; - term->mouse.have_discrete = true; - mouse_scroll(term, discrete); + struct wayland *wayl = data; + wayl->mouse.have_discrete = true; + mouse_scroll(wayl, discrete); } static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { - struct terminal *term = data; - term->mouse.have_discrete = false; + struct wayland *wayl = data; + wayl->mouse.have_discrete = false; } static void diff --git a/main.c b/main.c index c1043171..b70b8420 100644 --- a/main.c +++ b/main.c @@ -49,9 +49,9 @@ static void shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) { - struct terminal *term = data; + struct wayland *wayl = data; if (format == WL_SHM_FORMAT_ARGB8888) - term->wl.have_argb8888 = true; + wayl->have_argb8888 = true; } static const struct wl_shm_listener shm_listener = { @@ -73,26 +73,26 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum wl_seat_capability caps) { - struct terminal *term = data; + struct wayland *wayl = data; - if (term->wl.keyboard != NULL) { - wl_keyboard_release(term->wl.keyboard); - term->wl.keyboard = NULL; + if (wayl->keyboard != NULL) { + wl_keyboard_release(wayl->keyboard); + wayl->keyboard = NULL; } - if (term->wl.pointer.pointer != NULL) { - wl_pointer_release(term->wl.pointer.pointer); - term->wl.pointer.pointer = NULL; + if (wayl->pointer.pointer != NULL) { + wl_pointer_release(wayl->pointer.pointer); + wayl->pointer.pointer = NULL; } if (caps & WL_SEAT_CAPABILITY_KEYBOARD) { - term->wl.keyboard = wl_seat_get_keyboard(wl_seat); - wl_keyboard_add_listener(term->wl.keyboard, &keyboard_listener, term); + wayl->keyboard = wl_seat_get_keyboard(wl_seat); + wl_keyboard_add_listener(wayl->keyboard, &keyboard_listener, wayl); } if (caps & WL_SEAT_CAPABILITY_POINTER) { - term->wl.pointer.pointer = wl_seat_get_pointer(wl_seat); - wl_pointer_add_listener(term->wl.pointer.pointer, &pointer_listener, term); + wayl->pointer.pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(wayl->pointer.pointer, &pointer_listener, wayl); } } @@ -137,10 +137,12 @@ static void output_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct monitor *mon = data; + struct terminal *term = mon->wayl->term; + mon->scale = factor; - render_resize(mon->term, mon->term->width / mon->term->scale, mon->term->height / mon->term->scale); - render_reload_cursor_theme(mon->term); + render_resize(term, term->width / term->scale, term->height / term->scale); + render_reload_cursor_theme(term); } static const struct wl_output_listener output_listener = { @@ -200,72 +202,71 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { LOG_DBG("global: %s, version=%u", interface, version); - struct terminal *term = data; + struct wayland *wayl = data; if (strcmp(interface, wl_compositor_interface.name) == 0) { - term->wl.compositor = wl_registry_bind( - term->wl.registry, name, &wl_compositor_interface, 4); + wayl->compositor = wl_registry_bind( + wayl->registry, name, &wl_compositor_interface, 4); } else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { - term->wl.sub_compositor = wl_registry_bind( - term->wl.registry, name, &wl_subcompositor_interface, 1); + wayl->sub_compositor = wl_registry_bind( + wayl->registry, name, &wl_subcompositor_interface, 1); } else if (strcmp(interface, wl_shm_interface.name) == 0) { - term->wl.shm = wl_registry_bind( - term->wl.registry, name, &wl_shm_interface, 1); - wl_shm_add_listener(term->wl.shm, &shm_listener, term); - wl_display_roundtrip(term->wl.display); + wayl->shm = wl_registry_bind( + wayl->registry, name, &wl_shm_interface, 1); + wl_shm_add_listener(wayl->shm, &shm_listener, wayl); + wl_display_roundtrip(wayl->display); } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { - term->window.shell = wl_registry_bind( - term->wl.registry, name, &xdg_wm_base_interface, 1); - xdg_wm_base_add_listener(term->window.shell, &xdg_wm_base_listener, term); + wayl->shell = wl_registry_bind( + wayl->registry, name, &xdg_wm_base_interface, 1); + xdg_wm_base_add_listener(wayl->shell, &xdg_wm_base_listener, wayl); } else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) - term->window.xdg_decoration_manager = wl_registry_bind( - term->wl.registry, name, &zxdg_decoration_manager_v1_interface, 1); + wayl->xdg_decoration_manager = wl_registry_bind( + wayl->registry, name, &zxdg_decoration_manager_v1_interface, 1); else if (strcmp(interface, wl_seat_interface.name) == 0) { - term->wl.seat = wl_registry_bind( - term->wl.registry, name, &wl_seat_interface, 5); - wl_seat_add_listener(term->wl.seat, &seat_listener, term); - wl_display_roundtrip(term->wl.display); + wayl->seat = wl_registry_bind( + wayl->registry, name, &wl_seat_interface, 5); + wl_seat_add_listener(wayl->seat, &seat_listener, wayl); + wl_display_roundtrip(wayl->display); } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { - term->wl.xdg_output_manager = wl_registry_bind( - term->wl.registry, name, &zxdg_output_manager_v1_interface, min(version, 2)); + wayl->xdg_output_manager = wl_registry_bind( + wayl->registry, name, &zxdg_output_manager_v1_interface, min(version, 2)); } else if (strcmp(interface, wl_output_interface.name) == 0) { struct wl_output *output = wl_registry_bind( - term->wl.registry, name, &wl_output_interface, 3); + wayl->registry, name, &wl_output_interface, 3); tll_push_back( - term->wl.monitors, ((struct monitor){ - .term = term, .output = output})); + wayl->monitors, ((struct monitor){.wayl = wayl, .output = output})); - struct monitor *mon = &tll_back(term->wl.monitors); + struct monitor *mon = &tll_back(wayl->monitors); wl_output_add_listener(output, &output_listener, mon); mon->xdg = zxdg_output_manager_v1_get_xdg_output( - term->wl.xdg_output_manager, mon->output); + wayl->xdg_output_manager, mon->output); zxdg_output_v1_add_listener(mon->xdg, &xdg_output_listener, mon); - wl_display_roundtrip(term->wl.display); + wl_display_roundtrip(wayl->display); } else if (strcmp(interface, wl_data_device_manager_interface.name) == 0) { - term->wl.data_device_manager = wl_registry_bind( - term->wl.registry, name, &wl_data_device_manager_interface, 1); + wayl->data_device_manager = wl_registry_bind( + wayl->registry, name, &wl_data_device_manager_interface, 1); } else if (strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) { - term->wl.primary_selection_device_manager = wl_registry_bind( - term->wl.registry, name, &zwp_primary_selection_device_manager_v1_interface, 1); + wayl->primary_selection_device_manager = wl_registry_bind( + wayl->registry, name, &zwp_primary_selection_device_manager_v1_interface, 1); } } @@ -273,8 +274,10 @@ static void surface_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) { - struct terminal *term = data; - tll_foreach(term->wl.monitors, it) { + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_surface(wayl, wl_surface); + + tll_foreach(wayl->monitors, it) { if (it->item.output == wl_output) { LOG_DBG("mapped on %s", it->item.name); tll_push_back(term->window.on_outputs, &it->item); @@ -293,7 +296,9 @@ static void surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) { - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_surface(wayl, wl_surface); + tll_foreach(term->window.on_outputs, it) { if (it->item->output != wl_output) continue; @@ -324,17 +329,20 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, if (width <= 0 || height <= 0) return; - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); render_resize(term, width, height); } static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) { - struct terminal *term = data; + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); LOG_DBG("xdg-toplevel: close"); + term->quit = true; - wl_display_roundtrip(term->wl.display); + wl_display_roundtrip(wayl->display); } static const struct xdg_toplevel_listener xdg_toplevel_listener = { @@ -393,15 +401,15 @@ static const struct wl_registry_listener registry_listener = { static bool fdm_wayl(struct fdm *fdm, int fd, int events, void *data) { - struct terminal *term = data; - int event_count = wl_display_dispatch(term->wl.display); + struct wayland *wayl = data; + int event_count = wl_display_dispatch(wayl->display); if (events & EPOLLHUP) { LOG_ERR("disconnected from Wayland"); return false; } - return event_count != -1 && !term->quit; + return event_count != -1 && !wayl->term->quit; } static bool @@ -900,7 +908,7 @@ main(int argc, char *const *argv) goto out; } - wl_registry_add_listener(term.wl.registry, ®istry_listener, &term); + wl_registry_add_listener(term.wl.registry, ®istry_listener, &term.wl); wl_display_roundtrip(term.wl.display); if (term.wl.compositor == NULL) { @@ -911,7 +919,7 @@ main(int argc, char *const *argv) LOG_ERR("no shared memory buffers interface"); goto out; } - if (term.window.shell == NULL) { + if (term.wl.shell == NULL) { LOG_ERR("no XDG shell interface"); goto out; } @@ -940,14 +948,14 @@ main(int argc, char *const *argv) /* Clipboard */ term.wl.data_device = wl_data_device_manager_get_data_device( term.wl.data_device_manager, term.wl.seat); - wl_data_device_add_listener(term.wl.data_device, &data_device_listener, &term); + wl_data_device_add_listener(term.wl.data_device, &data_device_listener, &term.wl); /* Primary selection */ if (term.wl.primary_selection_device_manager != NULL) { term.wl.primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( term.wl.primary_selection_device_manager, term.wl.seat); zwp_primary_selection_device_v1_add_listener( - term.wl.primary_selection_device, &primary_selection_device_listener, &term); + term.wl.primary_selection_device, &primary_selection_device_listener, &term.wl); } /* Cursor */ @@ -981,24 +989,24 @@ main(int argc, char *const *argv) goto out; } - wl_surface_add_listener(term.window.surface, &surface_listener, &term); + wl_surface_add_listener(term.window.surface, &surface_listener, &term.wl); - term.window.xdg_surface = xdg_wm_base_get_xdg_surface(term.window.shell, term.window.surface); - xdg_surface_add_listener(term.window.xdg_surface, &xdg_surface_listener, &term); + term.window.xdg_surface = xdg_wm_base_get_xdg_surface(term.wl.shell, term.window.surface); + xdg_surface_add_listener(term.window.xdg_surface, &xdg_surface_listener, &term.wl); term.window.xdg_toplevel = xdg_surface_get_toplevel(term.window.xdg_surface); - xdg_toplevel_add_listener(term.window.xdg_toplevel, &xdg_toplevel_listener, &term); + xdg_toplevel_add_listener(term.window.xdg_toplevel, &xdg_toplevel_listener, &term.wl); xdg_toplevel_set_app_id(term.window.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); /* Request server-side decorations */ term.window.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( - term.window.xdg_decoration_manager, term.window.xdg_toplevel); + term.wl.xdg_decoration_manager, term.window.xdg_toplevel); zxdg_toplevel_decoration_v1_set_mode( term.window.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); zxdg_toplevel_decoration_v1_add_listener( - term.window.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term); + term.window.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term.wl); /* Scrollback search box */ term.window.search_surface = wl_compositor_create_surface(term.wl.compositor); @@ -1109,7 +1117,7 @@ main(int argc, char *const *argv) if ((fdm = fdm_init()) == NULL) goto out; - fdm_add(fdm, wl_display_get_fd(term.wl.display), EPOLLIN, &fdm_wayl, &term); + fdm_add(fdm, wl_display_get_fd(term.wl.display), EPOLLIN, &fdm_wayl, &term.wl); fdm_add(fdm, term.ptmx, EPOLLIN, &fdm_ptmx, &term); fdm_add(fdm, term.wl.kbd.repeat.fd, EPOLLIN, &fdm_repeat, &term); fdm_add(fdm, term.flash.fd, EPOLLIN, &fdm_flash, &term); diff --git a/osc.c b/osc.c index 694547c8..b506f0bb 100644 --- a/osc.c +++ b/osc.c @@ -30,14 +30,14 @@ osc_to_clipboard(struct terminal *term, const char *target, switch (*t) { case 'c': { char *copy = strdup(decoded); - if (!text_to_clipboard(term, copy, term->input_serial)) + if (!text_to_clipboard(term, copy, term->wl.input_serial)) free(copy); break; } case 'p': { char *copy = strdup(decoded); - if (!text_to_primary(term, copy, term->input_serial)) + if (!text_to_primary(term, copy, term->wl.input_serial)) free(copy); break; } @@ -130,7 +130,7 @@ osc_from_clipboard(struct terminal *term, const char *source) switch (src) { case 'c': - text_from_clipboard(term, term->input_serial, &from_clipboard_cb, &ctx); + text_from_clipboard(term, term->wl.input_serial, &from_clipboard_cb, &ctx); break; case 'p': diff --git a/search.c b/search.c index e9da3770..5c0ce1b7 100644 --- a/search.c +++ b/search.c @@ -317,7 +317,7 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask /* "Commit" search - copy selection to primary and cancel search */ else if (mods == 0 && sym == XKB_KEY_Return) { - selection_finalize(term, term->input_serial); + selection_finalize(term, term->wl.input_serial); search_cancel_keep_selection(term); return; } diff --git a/selection.c b/selection.c index 33875e94..a3c88307 100644 --- a/selection.c +++ b/selection.c @@ -742,8 +742,8 @@ selection(void *data, struct wl_data_device *wl_data_device, { /* Selection offer from other client */ - struct terminal *term = data; - struct wl_clipboard *clipboard = &term->wl.clipboard; + struct wayland *wayl = data; + struct wl_clipboard *clipboard = &wayl->clipboard; if (clipboard->data_offer != NULL) wl_data_offer_destroy(clipboard->data_offer); @@ -791,8 +791,8 @@ primary_selection(void *data, { /* Selection offer from other client, for primary */ - struct terminal *term = data; - struct wl_primary *primary = &term->wl.primary; + struct wayland *wayl = data; + struct wl_primary *primary = &wayl->primary; if (primary->data_offer != NULL) zwp_primary_selection_offer_v1_destroy(primary->data_offer); diff --git a/terminal.h b/terminal.h index cd8d7768..7d7d1fcd 100644 --- a/terminal.h +++ b/terminal.h @@ -200,19 +200,6 @@ struct terminal { uint32_t default_table[256]; } colors; - struct { - int col; - int row; - int button; - - int count; - int last_button; - struct timeval last_time; - - /* We used a discrete axis event in the current pointer frame */ - bool have_discrete; - } mouse; - struct coord cursor; struct coord saved_cursor; struct coord alt_saved_cursor; @@ -228,7 +215,6 @@ struct terminal { uint32_t cursor; } cursor_color; - uint32_t input_serial; struct { struct coord start; struct coord end; diff --git a/wayland.c b/wayland.c index e6701de6..c3d7657f 100644 --- a/wayland.c +++ b/wayland.c @@ -13,6 +13,7 @@ #include "log.h" #include "tllist.h" +#include "terminal.h" void wayl_init(struct wayland *wayl) @@ -33,6 +34,11 @@ wayl_destroy(struct wayland *wayl) if (wayl->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); + if (wayl->shell != NULL) + xdg_wm_base_destroy(wayl->shell); + + if (wayl->xdg_decoration_manager != NULL) + zxdg_decoration_manager_v1_destroy(wayl->xdg_decoration_manager); if (wayl->kbd.xkb_compose_state != NULL) xkb_compose_state_unref(wayl->kbd.xkb_compose_state); @@ -99,14 +105,25 @@ wayl_win_destroy(struct wl_window *win) wl_callback_destroy(win->frame_callback); if (win->xdg_toplevel_decoration != NULL) zxdg_toplevel_decoration_v1_destroy(win->xdg_toplevel_decoration); - if (win->xdg_decoration_manager != NULL) - zxdg_decoration_manager_v1_destroy(win->xdg_decoration_manager); if (win->xdg_toplevel != NULL) xdg_toplevel_destroy(win->xdg_toplevel); if (win->xdg_surface != NULL) xdg_surface_destroy(win->xdg_surface); - if (win->shell != NULL) - xdg_wm_base_destroy(win->shell); if (win->surface != NULL) wl_surface_destroy(win->surface); } + +struct terminal * +wayl_terminal_from_surface(struct wayland *wayl, struct wl_surface *surface) +{ + assert(surface == wayl->term->window.surface); + return wayl->term; +} + +struct terminal * +wayl_terminal_from_xdg_toplevel(struct wayland *wayl, + struct xdg_toplevel *toplevel) +{ + assert(toplevel == wayl->term->window.xdg_toplevel); + return wayl->term; +} diff --git a/wayland.h b/wayland.h index 43c4179f..9b02b84e 100644 --- a/wayland.h +++ b/wayland.h @@ -10,7 +10,8 @@ #include "tllist.h" struct monitor { - struct terminal *term; + //struct terminal *term; + struct wayland *wayl; struct wl_output *output; struct zxdg_output_v1 *xdg; char *name; @@ -71,11 +72,9 @@ struct wl_primary { struct wl_window { struct wl_surface *surface; - struct xdg_wm_base *shell; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; - struct zxdg_decoration_manager_v1 *xdg_decoration_manager; struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; /* Scrollback search */ @@ -99,10 +98,14 @@ struct wayland { struct wl_keyboard *keyboard; struct zxdg_output_manager_v1 *xdg_output_manager; + struct xdg_wm_base *shell; + struct zxdg_decoration_manager_v1 *xdg_decoration_manager; + /* Keyboard */ struct kbd kbd; /* Clipboard */ + uint32_t input_serial; struct wl_data_device_manager *data_device_manager; struct wl_data_device *data_device; struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; @@ -123,15 +126,37 @@ struct wayland { char *theme_name; } pointer; + struct { + int col; + int row; + int button; + + int count; + int last_button; + struct timeval last_time; + + /* We used a discrete axis event in the current pointer frame */ + bool have_discrete; + } mouse; + bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ /* TODO: turn into a list to support multiple windows */ struct terminal *term; + struct terminal *focused; + struct terminal *moused; }; /* TODO: return allocated pointer */ void wayl_init(struct wayland *wayl); void wayl_destroy(struct wayland *wayl); +struct terminal *wayl_terminal_from_surface( + struct wayland *wayl, struct wl_surface *surface); +struct terminal *wayl_terminal_from_xdg_surface( + struct wayland *wayl, struct xdg_surface *surface); +struct terminal *wayl_terminal_from_xdg_toplevel( + struct wayland *wayl, struct xdg_toplevel *toplevel); + void wayl_win_destroy(struct wl_window *win); -- cgit v1.3 From 1adab32906b5455781921b779019a6d3f0e4fe56 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 18:51:14 +0100 Subject: term: wayland struct is now not a part of the terminal struct We do however need access to it, so provide a pointer. The difference is that now we can have a *single* wayland instance, but multiple terminal instances. --- main.c | 110 +++++++++++++++++++++++++++++++----------------------------- osc.c | 6 ++-- render.c | 44 ++++++++++++------------ search.c | 18 +++++----- selection.c | 42 +++++++++++------------ terminal.c | 6 ++-- terminal.h | 2 +- wayland.h | 1 - 8 files changed, 115 insertions(+), 114 deletions(-) (limited to 'search.c') diff --git a/main.c b/main.c index f2fff1e3..5dd37dfb 100644 --- a/main.c +++ b/main.c @@ -729,6 +729,14 @@ main(int argc, char *const *argv) struct fdm *fdm = NULL; + struct wayland wayl = { + .kbd = { + .repeat = { + .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), + }, + }, + }; + struct terminal term = { .quit = false, .ptmx = posix_openpt(O_RDWR | O_NOCTTY), @@ -791,13 +799,7 @@ main(int argc, char *const *argv) .normal = {.damage = tll_init(), .scroll_damage = tll_init()}, .alt = {.damage = tll_init(), .scroll_damage = tll_init()}, .grid = &term.normal, - .wl = { - .kbd = { - .repeat = { - .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), - }, - }, - }, + .wl = &wayl, .render = { .scrollback_lines = conf.scrollback_lines, .workers = { @@ -843,7 +845,7 @@ main(int argc, char *const *argv) goto out; } - if (term.flash.fd == -1 || term.blink.fd == -1 || term.wl.kbd.repeat.fd == -1) { + if (term.flash.fd == -1 || term.blink.fd == -1 || term.wl->kbd.repeat.fd == -1) { LOG_ERR("failed to create timers"); goto out; } @@ -895,67 +897,67 @@ main(int argc, char *const *argv) term.cell_height = (int)ceil(term.fextents.height); LOG_INFO("cell width=%d, height=%d", term.cell_width, term.cell_height); - term.wl.term = &term; - term.wl.display = wl_display_connect(NULL); - if (term.wl.display == NULL) { + term.wl->term = &term; + term.wl->display = wl_display_connect(NULL); + if (term.wl->display == NULL) { LOG_ERR("failed to connect to wayland; no compositor running?"); goto out; } - term.wl.registry = wl_display_get_registry(term.wl.display); - if (term.wl.registry == NULL) { + term.wl->registry = wl_display_get_registry(term.wl->display); + if (term.wl->registry == NULL) { LOG_ERR("failed to get wayland registry"); goto out; } - wl_registry_add_listener(term.wl.registry, ®istry_listener, &term.wl); - wl_display_roundtrip(term.wl.display); + wl_registry_add_listener(term.wl->registry, ®istry_listener, term.wl); + wl_display_roundtrip(term.wl->display); - if (term.wl.compositor == NULL) { + if (term.wl->compositor == NULL) { LOG_ERR("no compositor"); goto out; } - if (term.wl.shm == NULL) { + if (term.wl->shm == NULL) { LOG_ERR("no shared memory buffers interface"); goto out; } - if (term.wl.shell == NULL) { + if (term.wl->shell == NULL) { LOG_ERR("no XDG shell interface"); goto out; } - if (!term.wl.have_argb8888) { + if (!term.wl->have_argb8888) { LOG_ERR("compositor does not support ARGB surfaces"); goto out; } - if (term.wl.seat == NULL) { + if (term.wl->seat == NULL) { LOG_ERR("no seat available"); goto out; } - if (term.wl.data_device_manager == NULL) { + if (term.wl->data_device_manager == NULL) { LOG_ERR("no clipboard available " "(wl_data_device_manager not implemented by server)"); goto out; } - if (term.wl.primary_selection_device_manager == NULL) + if (term.wl->primary_selection_device_manager == NULL) LOG_WARN("no primary selection available"); - tll_foreach(term.wl.monitors, it) { + tll_foreach(term.wl->monitors, it) { LOG_INFO("%s: %dx%d+%dx%d (scale=%d, refresh=%.2fHz)", it->item.name, it->item.width_px, it->item.height_px, it->item.x, it->item.y, it->item.scale, it->item.refresh); } /* Clipboard */ - term.wl.data_device = wl_data_device_manager_get_data_device( - term.wl.data_device_manager, term.wl.seat); - wl_data_device_add_listener(term.wl.data_device, &data_device_listener, &term.wl); + term.wl->data_device = wl_data_device_manager_get_data_device( + term.wl->data_device_manager, term.wl->seat); + wl_data_device_add_listener(term.wl->data_device, &data_device_listener, term.wl); /* Primary selection */ - if (term.wl.primary_selection_device_manager != NULL) { - term.wl.primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( - term.wl.primary_selection_device_manager, term.wl.seat); + if (term.wl->primary_selection_device_manager != NULL) { + term.wl->primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( + term.wl->primary_selection_device_manager, term.wl->seat); zwp_primary_selection_device_v1_add_listener( - term.wl.primary_selection_device, &primary_selection_device_listener, &term.wl); + term.wl->primary_selection_device, &primary_selection_device_listener, term.wl); } /* Cursor */ @@ -973,49 +975,49 @@ main(int argc, char *const *argv) /* Note: theme is (re)loaded on scale and output changes */ LOG_INFO("cursor theme: %s, size: %u", cursor_theme, cursor_size); - term.wl.pointer.size = cursor_size; - term.wl.pointer.theme_name = cursor_theme != NULL ? strdup(cursor_theme) : NULL; + term.wl->pointer.size = cursor_size; + term.wl->pointer.theme_name = cursor_theme != NULL ? strdup(cursor_theme) : NULL; - term.wl.pointer.surface = wl_compositor_create_surface(term.wl.compositor); - if (term.wl.pointer.surface == NULL) { + term.wl->pointer.surface = wl_compositor_create_surface(term.wl->compositor); + if (term.wl->pointer.surface == NULL) { LOG_ERR("failed to create cursor surface"); goto out; } /* Main window */ - term.window.surface = wl_compositor_create_surface(term.wl.compositor); + term.window.surface = wl_compositor_create_surface(term.wl->compositor); if (term.window.surface == NULL) { LOG_ERR("failed to create wayland surface"); goto out; } - wl_surface_add_listener(term.window.surface, &surface_listener, &term.wl); + wl_surface_add_listener(term.window.surface, &surface_listener, term.wl); - term.window.xdg_surface = xdg_wm_base_get_xdg_surface(term.wl.shell, term.window.surface); - xdg_surface_add_listener(term.window.xdg_surface, &xdg_surface_listener, &term.wl); + term.window.xdg_surface = xdg_wm_base_get_xdg_surface(term.wl->shell, term.window.surface); + xdg_surface_add_listener(term.window.xdg_surface, &xdg_surface_listener, term.wl); term.window.xdg_toplevel = xdg_surface_get_toplevel(term.window.xdg_surface); - xdg_toplevel_add_listener(term.window.xdg_toplevel, &xdg_toplevel_listener, &term.wl); + xdg_toplevel_add_listener(term.window.xdg_toplevel, &xdg_toplevel_listener, term.wl); xdg_toplevel_set_app_id(term.window.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); /* Request server-side decorations */ term.window.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( - term.wl.xdg_decoration_manager, term.window.xdg_toplevel); + term.wl->xdg_decoration_manager, term.window.xdg_toplevel); zxdg_toplevel_decoration_v1_set_mode( term.window.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); zxdg_toplevel_decoration_v1_add_listener( - term.window.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term.wl); + term.window.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, term.wl); /* Scrollback search box */ - term.window.search_surface = wl_compositor_create_surface(term.wl.compositor); + term.window.search_surface = wl_compositor_create_surface(term.wl->compositor); term.window.search_sub_surface = wl_subcompositor_get_subsurface( - term.wl.sub_compositor, term.window.search_surface, term.window.surface); + term.wl->sub_compositor, term.window.search_surface, term.window.surface); wl_subsurface_set_desync(term.window.search_sub_surface); wl_surface_commit(term.window.surface); - wl_display_roundtrip(term.wl.display); + wl_display_roundtrip(term.wl->display); if (conf.width == -1) { assert(conf.height == -1); @@ -1026,7 +1028,7 @@ main(int argc, char *const *argv) conf.height = max(conf.height, term.cell_height); render_resize(&term, conf.width, conf.height); - wl_display_dispatch_pending(term.wl.display); + wl_display_dispatch_pending(term.wl->display); { int fork_pipe[2]; @@ -1102,7 +1104,7 @@ main(int argc, char *const *argv) { - int fd = wl_display_get_fd(term.wl.display); + int fd = wl_display_get_fd(term.wl->display); int fd_flags = fcntl(fd, F_GETFL); if (fd_flags == -1) { LOG_ERRNO("failed to set non blocking mode on Wayland display connection"); @@ -1117,16 +1119,16 @@ main(int argc, char *const *argv) if ((fdm = fdm_init()) == NULL) goto out; - fdm_add(fdm, wl_display_get_fd(term.wl.display), EPOLLIN, &fdm_wayl, &term.wl); + fdm_add(fdm, wl_display_get_fd(term.wl->display), EPOLLIN, &fdm_wayl, term.wl); fdm_add(fdm, term.ptmx, EPOLLIN, &fdm_ptmx, &term); - fdm_add(fdm, term.wl.kbd.repeat.fd, EPOLLIN, &fdm_repeat, &term.wl); + fdm_add(fdm, term.wl->kbd.repeat.fd, EPOLLIN, &fdm_repeat, term.wl); fdm_add(fdm, term.flash.fd, EPOLLIN, &fdm_flash, &term); fdm_add(fdm, term.blink.fd, EPOLLIN, &fdm_blink, &term); fdm_add(fdm, term.delayed_render_timer.lower_fd, EPOLLIN, &fdm_delayed_render, &term); fdm_add(fdm, term.delayed_render_timer.upper_fd, EPOLLIN, &fdm_delayed_render, &term); while (true) { - wl_display_flush(term.wl.display); + wl_display_flush(term.wl->display); if (!fdm_poll(fdm)) break; } @@ -1136,9 +1138,9 @@ main(int argc, char *const *argv) out: if (fdm != NULL) { - fdm_del(fdm, wl_display_get_fd(term.wl.display)); + fdm_del(fdm, wl_display_get_fd(term.wl->display)); fdm_del(fdm, term.ptmx); - fdm_del(fdm, term.wl.kbd.repeat.fd); + fdm_del(fdm, term.wl->kbd.repeat.fd); fdm_del(fdm, term.flash.fd); fdm_del(fdm, term.blink.fd); fdm_del(fdm, term.delayed_render_timer.lower_fd); @@ -1162,7 +1164,7 @@ out: shm_fini(); wayl_win_destroy(&term.window); - wayl_destroy(&term.wl); + wayl_destroy(&wayl); free(term.vt.osc.data); for (int row = 0; row < term.normal.num_rows; row++) @@ -1184,8 +1186,8 @@ out: close(term.flash.fd); if (term.blink.fd != -1) close(term.blink.fd); - if (term.wl.kbd.repeat.fd != -1) - close(term.wl.kbd.repeat.fd); + if (term.wl->kbd.repeat.fd != -1) + close(term.wl->kbd.repeat.fd); if (term.ptmx != -1) close(term.ptmx); diff --git a/osc.c b/osc.c index b506f0bb..e860edcd 100644 --- a/osc.c +++ b/osc.c @@ -30,14 +30,14 @@ osc_to_clipboard(struct terminal *term, const char *target, switch (*t) { case 'c': { char *copy = strdup(decoded); - if (!text_to_clipboard(term, copy, term->wl.input_serial)) + if (!text_to_clipboard(term, copy, term->wl->input_serial)) free(copy); break; } case 'p': { char *copy = strdup(decoded); - if (!text_to_primary(term, copy, term->wl.input_serial)) + if (!text_to_primary(term, copy, term->wl->input_serial)) free(copy); break; } @@ -130,7 +130,7 @@ osc_from_clipboard(struct terminal *term, const char *source) switch (src) { case 'c': - text_from_clipboard(term, term->wl.input_serial, &from_clipboard_cb, &ctx); + text_from_clipboard(term, term->wl->input_serial, &from_clipboard_cb, &ctx); break; case 'p': diff --git a/render.c b/render.c index c2840eb8..75f319bf 100644 --- a/render.c +++ b/render.c @@ -440,7 +440,7 @@ grid_render(struct terminal *term) assert(term->width > 0); assert(term->height > 0); - struct buffer *buf = shm_get_buffer(term->wl.shm, term->width, term->height, 1 + term->render.workers.count); + struct buffer *buf = shm_get_buffer(term->wl->shm, term->width, term->height, 1 + term->render.workers.count); wl_surface_attach(term->window.surface, buf->wl_buf, 0, 0); pixman_image_t *pix = buf->pix; @@ -741,7 +741,7 @@ render_search_box(struct terminal *term) const int width = 2 * margin + max(20, term->search.len) * term->cell_width; const int height = 2 * margin + 1 * term->cell_height; - struct buffer *buf = shm_get_buffer(term->wl.shm, width, height, 1); + struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, 1); /* Background - yellow on empty/match, red on mismatch */ pixman_color_t color = color_hex_to_pixman( @@ -945,28 +945,28 @@ render_set_title(struct terminal *term, const char *title) bool render_reload_cursor_theme(struct terminal *term) { - if (term->wl.pointer.size == 0) + if (term->wl->pointer.size == 0) return true; - if (term->wl.pointer.theme != NULL) { - wl_cursor_theme_destroy(term->wl.pointer.theme); - term->wl.pointer.theme = NULL; - term->wl.pointer.cursor = NULL; + if (term->wl->pointer.theme != NULL) { + wl_cursor_theme_destroy(term->wl->pointer.theme); + term->wl->pointer.theme = NULL; + term->wl->pointer.cursor = NULL; } LOG_DBG("reloading cursor theme: %s@%d", - term->wl.pointer.theme_name, term->wl.pointer.size); + term->wl->pointer.theme_name, term->wl->pointer.size); - term->wl.pointer.theme = wl_cursor_theme_load( - term->wl.pointer.theme_name, term->wl.pointer.size * term->scale, term->wl.shm); - if (term->wl.pointer.theme == NULL) { + term->wl->pointer.theme = wl_cursor_theme_load( + term->wl->pointer.theme_name, term->wl->pointer.size * term->scale, term->wl->shm); + if (term->wl->pointer.theme == NULL) { LOG_ERR("failed to load cursor theme"); return false; } - term->wl.pointer.cursor = wl_cursor_theme_get_cursor( - term->wl.pointer.theme, "left_ptr"); - assert(term->wl.pointer.cursor != NULL); + term->wl->pointer.cursor = wl_cursor_theme_get_cursor( + term->wl->pointer.theme, "left_ptr"); + assert(term->wl->pointer.cursor != NULL); render_update_cursor_surface(term); return true; @@ -975,26 +975,26 @@ render_reload_cursor_theme(struct terminal *term) void render_update_cursor_surface(struct terminal *term) { - if (term->wl.pointer.cursor == NULL) + if (term->wl->pointer.cursor == NULL) return; const int scale = term->scale; - wl_surface_set_buffer_scale(term->wl.pointer.surface, scale); + wl_surface_set_buffer_scale(term->wl->pointer.surface, scale); - struct wl_cursor_image *image = term->wl.pointer.cursor->images[0]; + struct wl_cursor_image *image = term->wl->pointer.cursor->images[0]; wl_surface_attach( - term->wl.pointer.surface, wl_cursor_image_get_buffer(image), 0, 0); + term->wl->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0); wl_pointer_set_cursor( - term->wl.pointer.pointer, term->wl.pointer.serial, - term->wl.pointer.surface, + term->wl->pointer.pointer, term->wl->pointer.serial, + term->wl->pointer.surface, image->hotspot_x / scale, image->hotspot_y / scale); wl_surface_damage_buffer( - term->wl.pointer.surface, 0, 0, INT32_MAX, INT32_MAX); + term->wl->pointer.surface, 0, 0, INT32_MAX, INT32_MAX); - wl_surface_commit(term->wl.pointer.surface); + wl_surface_commit(term->wl->pointer.surface); } void diff --git a/search.c b/search.c index 5c0ce1b7..e055b478 100644 --- a/search.c +++ b/search.c @@ -294,13 +294,13 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask { LOG_DBG("search: input: sym=%d/0x%x, mods=0x%08x", sym, sym, mods); - const xkb_mod_mask_t ctrl = 1 << term->wl.kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << term->wl.kbd.mod_alt; - //const xkb_mod_mask_t shift = 1 << term->wl.kbd.mod_shift; - //const xkb_mod_mask_t meta = 1 << term->wl.kbd.mod_meta; + const xkb_mod_mask_t ctrl = 1 << term->wl->kbd.mod_ctrl; + const xkb_mod_mask_t alt = 1 << term->wl->kbd.mod_alt; + //const xkb_mod_mask_t shift = 1 << term->wl->kbd.mod_shift; + //const xkb_mod_mask_t meta = 1 << term->wl->kbd.mod_meta; enum xkb_compose_status compose_status = xkb_compose_state_get_status( - term->wl.kbd.xkb_compose_state); + term->wl->kbd.xkb_compose_state); /* Cancel search */ if ((mods == 0 && sym == XKB_KEY_Escape) || @@ -317,7 +317,7 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask /* "Commit" search - copy selection to primary and cancel search */ else if (mods == 0 && sym == XKB_KEY_Return) { - selection_finalize(term, term->wl.input_serial); + selection_finalize(term, term->wl->input_serial); search_cancel_keep_selection(term); return; } @@ -449,11 +449,11 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask if (compose_status == XKB_COMPOSE_COMPOSED) { count = xkb_compose_state_get_utf8( - term->wl.kbd.xkb_compose_state, (char *)buf, sizeof(buf)); - xkb_compose_state_reset(term->wl.kbd.xkb_compose_state); + term->wl->kbd.xkb_compose_state, (char *)buf, sizeof(buf)); + xkb_compose_state_reset(term->wl->kbd.xkb_compose_state); } else { count = xkb_state_key_get_utf8( - term->wl.kbd.xkb_state, key, (char *)buf, sizeof(buf)); + term->wl->kbd.xkb_state, key, (char *)buf, sizeof(buf)); } const char *src = (const char *)buf; diff --git a/selection.c b/selection.c index a3c88307..d2ed7354 100644 --- a/selection.c +++ b/selection.c @@ -22,7 +22,7 @@ selection_enabled(const struct terminal *term) { return term->mouse_tracking == MOUSE_NONE || - term->wl.kbd.shift || + term->wl->kbd.shift || term->is_searching; } @@ -434,12 +434,12 @@ static const struct zwp_primary_selection_source_v1_listener primary_selection_s bool text_to_clipboard(struct terminal *term, char *text, uint32_t serial) { - struct wl_clipboard *clipboard = &term->wl.clipboard; + struct wl_clipboard *clipboard = &term->wl->clipboard; - if (term->wl.clipboard.data_source != NULL) { + if (term->wl->clipboard.data_source != NULL) { /* Kill previous data source */ assert(clipboard->serial != 0); - wl_data_device_set_selection(term->wl.data_device, NULL, clipboard->serial); + wl_data_device_set_selection(term->wl->data_device, NULL, clipboard->serial); wl_data_source_destroy(clipboard->data_source); free(clipboard->text); @@ -448,7 +448,7 @@ text_to_clipboard(struct terminal *term, char *text, uint32_t serial) } clipboard->data_source - = wl_data_device_manager_create_data_source(term->wl.data_device_manager); + = wl_data_device_manager_create_data_source(term->wl->data_device_manager); if (clipboard->data_source == NULL) { LOG_ERR("failed to create clipboard data source"); @@ -460,7 +460,7 @@ text_to_clipboard(struct terminal *term, char *text, uint32_t serial) /* Configure source */ wl_data_source_offer(clipboard->data_source, "text/plain;charset=utf-8"); wl_data_source_add_listener(clipboard->data_source, &data_source_listener, term); - wl_data_device_set_selection(term->wl.data_device, clipboard->data_source, serial); + wl_data_device_set_selection(term->wl->data_device, clipboard->data_source, serial); wl_data_source_set_user_data(clipboard->data_source, clipboard); /* Needed when sending the selection to other client */ @@ -482,7 +482,7 @@ text_from_clipboard(struct terminal *term, uint32_t serial, void (*cb)(const char *data, size_t size, void *user), void *user) { - struct wl_clipboard *clipboard = &term->wl.clipboard; + struct wl_clipboard *clipboard = &term->wl->clipboard; if (clipboard->data_offer == NULL) return; @@ -499,7 +499,7 @@ text_from_clipboard(struct terminal *term, uint32_t serial, /* Give write-end of pipe to other client */ wl_data_offer_receive( clipboard->data_offer, "text/plain;charset=utf-8", write_fd); - wl_display_roundtrip(term->wl.display); + wl_display_roundtrip(term->wl->display); /* Don't keep our copy of the write-end open (or we'll never get EOF) */ close(write_fd); @@ -539,7 +539,7 @@ from_clipboard_cb(const char *data, size_t size, void *user) void selection_from_clipboard(struct terminal *term, uint32_t serial) { - struct wl_clipboard *clipboard = &term->wl.clipboard; + struct wl_clipboard *clipboard = &term->wl->clipboard; if (clipboard->data_offer == NULL) return; @@ -555,18 +555,18 @@ selection_from_clipboard(struct terminal *term, uint32_t serial) bool text_to_primary(struct terminal *term, char *text, uint32_t serial) { - if (term->wl.primary_selection_device_manager == NULL) + if (term->wl->primary_selection_device_manager == NULL) return false; - struct wl_primary *primary = &term->wl.primary; + struct wl_primary *primary = &term->wl->primary; /* TODO: somehow share code with the clipboard equivalent */ - if (term->wl.primary.data_source != NULL) { + if (term->wl->primary.data_source != NULL) { /* Kill previous data source */ assert(primary->serial != 0); zwp_primary_selection_device_v1_set_selection( - term->wl.primary_selection_device, NULL, primary->serial); + term->wl->primary_selection_device, NULL, primary->serial); zwp_primary_selection_source_v1_destroy(primary->data_source); free(primary->text); @@ -576,7 +576,7 @@ text_to_primary(struct terminal *term, char *text, uint32_t serial) primary->data_source = zwp_primary_selection_device_manager_v1_create_source( - term->wl.primary_selection_device_manager); + term->wl->primary_selection_device_manager); if (primary->data_source == NULL) { LOG_ERR("failed to create clipboard data source"); @@ -589,7 +589,7 @@ text_to_primary(struct terminal *term, char *text, uint32_t serial) /* Configure source */ zwp_primary_selection_source_v1_offer(primary->data_source, "text/plain;charset=utf-8"); zwp_primary_selection_source_v1_add_listener(primary->data_source, &primary_selection_source_listener, term); - zwp_primary_selection_device_v1_set_selection(term->wl.primary_selection_device, primary->data_source, serial); + zwp_primary_selection_device_v1_set_selection(term->wl->primary_selection_device, primary->data_source, serial); zwp_primary_selection_source_v1_set_user_data(primary->data_source, primary); /* Needed when sending the selection to other client */ @@ -600,7 +600,7 @@ text_to_primary(struct terminal *term, char *text, uint32_t serial) void selection_to_primary(struct terminal *term, uint32_t serial) { - if (term->wl.primary_selection_device_manager == NULL) + if (term->wl->primary_selection_device_manager == NULL) return; /* Get selection as a string */ @@ -614,10 +614,10 @@ text_from_primary( struct terminal *term, void (*cb)(const char *data, size_t size, void *user), void *user) { - if (term->wl.primary_selection_device_manager == NULL) + if (term->wl->primary_selection_device_manager == NULL) return; - struct wl_primary *primary = &term->wl.primary; + struct wl_primary *primary = &term->wl->primary; if (primary->data_offer == NULL) return; @@ -634,7 +634,7 @@ text_from_primary( /* Give write-end of pipe to other client */ zwp_primary_selection_offer_v1_receive( primary->data_offer, "text/plain;charset=utf-8", write_fd); - wl_display_roundtrip(term->wl.display); + wl_display_roundtrip(term->wl->display); /* Don't keep our copy of the write-end open (or we'll never get EOF) */ close(write_fd); @@ -667,10 +667,10 @@ text_from_primary( void selection_from_primary(struct terminal *term) { - if (term->wl.primary_selection_device_manager == NULL) + if (term->wl->primary_selection_device_manager == NULL) return; - struct wl_clipboard *clipboard = &term->wl.clipboard; + struct wl_clipboard *clipboard = &term->wl->clipboard; if (clipboard->data_offer == NULL) return; diff --git a/terminal.c b/terminal.c index ada701cc..684f4c30 100644 --- a/terminal.c +++ b/terminal.c @@ -480,7 +480,7 @@ void term_mouse_down(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->wl.kbd.shift) { + if (term->wl->kbd.shift) { /* "raw" mouse mode */ return; } @@ -513,7 +513,7 @@ void term_mouse_up(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->wl.kbd.shift) { + if (term->wl->kbd.shift) { /* "raw" mouse mode */ return; } @@ -551,7 +551,7 @@ void term_mouse_motion(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->wl.kbd.shift) { + if (term->wl->kbd.shift) { /* "raw" mouse mode */ return; } diff --git a/terminal.h b/terminal.h index 7d7d1fcd..724bc6f1 100644 --- a/terminal.h +++ b/terminal.h @@ -246,7 +246,7 @@ struct terminal { int max_x_advance; } fextents; - struct wayland wl; + struct wayland *wl; struct wl_window window; struct { diff --git a/wayland.h b/wayland.h index f82d2630..e0f7cd2f 100644 --- a/wayland.h +++ b/wayland.h @@ -12,7 +12,6 @@ #include "tllist.h" struct monitor { - //struct terminal *term; struct wayland *wayl; struct wl_output *output; struct zxdg_output_v1 *xdg; -- cgit v1.3 From 61cc8c3c55767556b81474eebe6712f7e9b42706 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 19:08:48 +0100 Subject: wayland: implement wayl_init() Wayland instantiation is now done by the wayland backend, not in main. --- main.c | 509 +++-------------------------------------------------------- render.c | 56 +++---- search.c | 4 +- terminal.h | 2 +- wayland.c | 518 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- wayland.h | 6 +- 6 files changed, 569 insertions(+), 526 deletions(-) (limited to 'search.c') diff --git a/main.c b/main.c index 5dd37dfb..eb91ce5b 100644 --- a/main.c +++ b/main.c @@ -33,371 +33,17 @@ #include "fdm.h" #include "font.h" #include "grid.h" -#include "input.h" -#include "render.h" -#include "selection.h" #include "shm.h" #include "slave.h" #include "terminal.h" #include "tokenize.h" #include "version.h" +#include "render.h" #include "vt.h" #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) -static void -shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) -{ - struct wayland *wayl = data; - if (format == WL_SHM_FORMAT_ARGB8888) - wayl->have_argb8888 = true; -} - -static const struct wl_shm_listener shm_listener = { - .format = &shm_format, -}; - -static void -xdg_wm_base_ping(void *data, struct xdg_wm_base *shell, uint32_t serial) -{ - LOG_DBG("wm base ping"); - xdg_wm_base_pong(shell, serial); -} - -static const struct xdg_wm_base_listener xdg_wm_base_listener = { - .ping = &xdg_wm_base_ping, -}; - -static void -seat_handle_capabilities(void *data, struct wl_seat *wl_seat, - enum wl_seat_capability caps) -{ - struct wayland *wayl = data; - - if (wayl->keyboard != NULL) { - wl_keyboard_release(wayl->keyboard); - wayl->keyboard = NULL; - } - - if (wayl->pointer.pointer != NULL) { - wl_pointer_release(wayl->pointer.pointer); - wayl->pointer.pointer = NULL; - } - - if (caps & WL_SEAT_CAPABILITY_KEYBOARD) { - wayl->keyboard = wl_seat_get_keyboard(wl_seat); - wl_keyboard_add_listener(wayl->keyboard, &keyboard_listener, wayl); - } - - if (caps & WL_SEAT_CAPABILITY_POINTER) { - wayl->pointer.pointer = wl_seat_get_pointer(wl_seat); - wl_pointer_add_listener(wayl->pointer.pointer, &pointer_listener, wayl); - } -} - -static void -seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) -{ -} - -static const struct wl_seat_listener seat_listener = { - .capabilities = seat_handle_capabilities, - .name = seat_handle_name, -}; - -static void -output_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, - int32_t physical_width, int32_t physical_height, - int32_t subpixel, const char *make, const char *model, - int32_t transform) -{ - struct monitor *mon = data; - mon->width_mm = physical_width; - mon->height_mm = physical_height; -} - -static void -output_mode(void *data, struct wl_output *wl_output, uint32_t flags, - int32_t width, int32_t height, int32_t refresh) -{ - if ((flags & WL_OUTPUT_MODE_CURRENT) == 0) - return; - - struct monitor *mon = data; - mon->refresh = (float)refresh / 1000; -} - -static void -output_done(void *data, struct wl_output *wl_output) -{ -} - -static void -output_scale(void *data, struct wl_output *wl_output, int32_t factor) -{ - struct monitor *mon = data; - struct terminal *term = mon->wayl->term; - - mon->scale = factor; - - render_resize(term, term->width / term->scale, term->height / term->scale); - render_reload_cursor_theme(term); -} - -static const struct wl_output_listener output_listener = { - .geometry = &output_geometry, - .mode = &output_mode, - .done = &output_done, - .scale = &output_scale, -}; - -static void -xdg_output_handle_logical_position( - void *data, struct zxdg_output_v1 *xdg_output, int32_t x, int32_t y) -{ - struct monitor *mon = data; - mon->x = x; - mon->y = y; -} - -static void -xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output, - int32_t width, int32_t height) -{ - struct monitor *mon = data; - mon->width_px = width; - mon->height_px = height; -} - -static void -xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output) -{ -} - -static void -xdg_output_handle_name(void *data, struct zxdg_output_v1 *xdg_output, - const char *name) -{ - struct monitor *mon = data; - mon->name = strdup(name); -} - -static void -xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output, - const char *description) -{ -} - -static struct zxdg_output_v1_listener xdg_output_listener = { - .logical_position = xdg_output_handle_logical_position, - .logical_size = xdg_output_handle_logical_size, - .done = xdg_output_handle_done, - .name = xdg_output_handle_name, - .description = xdg_output_handle_description, -}; - -static void -handle_global(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) -{ - LOG_DBG("global: %s, version=%u", interface, version); - struct wayland *wayl = data; - - if (strcmp(interface, wl_compositor_interface.name) == 0) { - wayl->compositor = wl_registry_bind( - wayl->registry, name, &wl_compositor_interface, 4); - } - - else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { - wayl->sub_compositor = wl_registry_bind( - wayl->registry, name, &wl_subcompositor_interface, 1); - } - - else if (strcmp(interface, wl_shm_interface.name) == 0) { - wayl->shm = wl_registry_bind( - wayl->registry, name, &wl_shm_interface, 1); - wl_shm_add_listener(wayl->shm, &shm_listener, wayl); - wl_display_roundtrip(wayl->display); - } - - else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { - wayl->shell = wl_registry_bind( - wayl->registry, name, &xdg_wm_base_interface, 1); - xdg_wm_base_add_listener(wayl->shell, &xdg_wm_base_listener, wayl); - } - - else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) - wayl->xdg_decoration_manager = wl_registry_bind( - wayl->registry, name, &zxdg_decoration_manager_v1_interface, 1); - - else if (strcmp(interface, wl_seat_interface.name) == 0) { - wayl->seat = wl_registry_bind( - wayl->registry, name, &wl_seat_interface, 5); - wl_seat_add_listener(wayl->seat, &seat_listener, wayl); - wl_display_roundtrip(wayl->display); - } - - else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { - wayl->xdg_output_manager = wl_registry_bind( - wayl->registry, name, &zxdg_output_manager_v1_interface, min(version, 2)); - } - - else if (strcmp(interface, wl_output_interface.name) == 0) { - struct wl_output *output = wl_registry_bind( - wayl->registry, name, &wl_output_interface, 3); - - tll_push_back( - wayl->monitors, ((struct monitor){.wayl = wayl, .output = output})); - - struct monitor *mon = &tll_back(wayl->monitors); - wl_output_add_listener(output, &output_listener, mon); - - mon->xdg = zxdg_output_manager_v1_get_xdg_output( - wayl->xdg_output_manager, mon->output); - zxdg_output_v1_add_listener(mon->xdg, &xdg_output_listener, mon); - wl_display_roundtrip(wayl->display); - } - - else if (strcmp(interface, wl_data_device_manager_interface.name) == 0) { - wayl->data_device_manager = wl_registry_bind( - wayl->registry, name, &wl_data_device_manager_interface, 1); - } - - else if (strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) { - wayl->primary_selection_device_manager = wl_registry_bind( - wayl->registry, name, &zwp_primary_selection_device_manager_v1_interface, 1); - } -} - -static void -surface_enter(void *data, struct wl_surface *wl_surface, - struct wl_output *wl_output) -{ - struct wayland *wayl = data; - struct terminal *term = wayl_terminal_from_surface(wayl, wl_surface); - - tll_foreach(wayl->monitors, it) { - if (it->item.output == wl_output) { - LOG_DBG("mapped on %s", it->item.name); - 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); - render_reload_cursor_theme(term); - return; - } - } - - LOG_ERR("mapped on unknown output"); -} - -static void -surface_leave(void *data, struct wl_surface *wl_surface, - struct wl_output *wl_output) -{ - struct wayland *wayl = data; - struct terminal *term = wayl_terminal_from_surface(wayl, wl_surface); - - tll_foreach(term->window.on_outputs, it) { - if (it->item->output != wl_output) - continue; - - LOG_DBG("unmapped from %s", it->item->name); - 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); - render_reload_cursor_theme(term); - return; - } - - LOG_ERR("unmapped from unknown output"); -} - -static const struct wl_surface_listener surface_listener = { - .enter = &surface_enter, - .leave = &surface_leave, -}; - -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); - - 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); -} - -static void -xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) -{ - struct wayland *wayl = data; - struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); - LOG_DBG("xdg-toplevel: close"); - - term->quit = true; - wl_display_roundtrip(wayl->display); -} - -static const struct xdg_toplevel_listener xdg_toplevel_listener = { - .configure = &xdg_toplevel_configure, - .close = &xdg_toplevel_close, -}; - -static void -xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, - uint32_t serial) -{ - //LOG_DBG("xdg-surface: configure"); - xdg_surface_ack_configure(xdg_surface, serial); -} - -static const struct xdg_surface_listener xdg_surface_listener = { - .configure = &xdg_surface_configure, -}; - -static void -xdg_toplevel_decoration_configure(void *data, - struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, - uint32_t mode) -{ - switch (mode) { - case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: - LOG_ERR("unimplemented: client-side decorations"); - break; - - case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: - LOG_DBG("using server-side decorations"); - break; - - default: - LOG_ERR("unimplemented: unknown XDG toplevel decoration mode: %u", mode); - break; - } -} - -static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = { - .configure = &xdg_toplevel_decoration_configure, -}; - -static void -handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) -{ - LOG_WARN("global removed: %u", name); - assert(false); -} - -static const struct wl_registry_listener registry_listener = { - .global = &handle_global, - .global_remove = &handle_global_remove, -}; - static bool fdm_wayl(struct fdm *fdm, int fd, int events, void *data) { @@ -470,7 +116,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) * ourselves we just received keyboard input, and in * this case *not* delay rendering? */ - if (term->window.frame_callback == NULL) { + if (term->window->frame_callback == NULL) { /* First timeout - reset each time we receive input. */ timerfd_settime( term->delayed_render_timer.lower_fd, 0, @@ -491,6 +137,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) return !(events & EPOLLHUP); } +#include "input.h" static bool fdm_repeat(struct fdm *fdm, int fd, int events, void *data) { @@ -727,16 +374,6 @@ main(int argc, char *const *argv) setlocale(LC_ALL, ""); setenv("TERM", conf.term, 1); - struct fdm *fdm = NULL; - - struct wayland wayl = { - .kbd = { - .repeat = { - .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), - }, - }, - }; - struct terminal term = { .quit = false, .ptmx = posix_openpt(O_RDWR | O_NOCTTY), @@ -799,7 +436,6 @@ main(int argc, char *const *argv) .normal = {.damage = tll_init(), .scroll_damage = tll_init()}, .alt = {.damage = tll_init(), .scroll_damage = tll_init()}, .grid = &term.normal, - .wl = &wayl, .render = { .scrollback_lines = conf.scrollback_lines, .workers = { @@ -840,6 +476,18 @@ main(int argc, char *const *argv) memcpy(term.colors.table, term.colors.default_table, sizeof(term.colors.table)); } + struct fdm *fdm = NULL; + struct wayland *wayl = NULL; + + if ((fdm = fdm_init()) == NULL) + goto out; + + if ((wayl = wayl_init(fdm)) == NULL) + goto out; + + term.wl = wayl; + wayl->term = &term; + if (term.ptmx == -1) { LOG_ERR("failed to open pseudo terminal"); goto out; @@ -897,133 +545,19 @@ main(int argc, char *const *argv) term.cell_height = (int)ceil(term.fextents.height); LOG_INFO("cell width=%d, height=%d", term.cell_width, term.cell_height); - term.wl->term = &term; - term.wl->display = wl_display_connect(NULL); - if (term.wl->display == NULL) { - LOG_ERR("failed to connect to wayland; no compositor running?"); - goto out; - } - - term.wl->registry = wl_display_get_registry(term.wl->display); - if (term.wl->registry == NULL) { - LOG_ERR("failed to get wayland registry"); - goto out; - } - - wl_registry_add_listener(term.wl->registry, ®istry_listener, term.wl); - wl_display_roundtrip(term.wl->display); - - if (term.wl->compositor == NULL) { - LOG_ERR("no compositor"); - goto out; - } - if (term.wl->shm == NULL) { - LOG_ERR("no shared memory buffers interface"); - goto out; - } - if (term.wl->shell == NULL) { - LOG_ERR("no XDG shell interface"); - goto out; - } - if (!term.wl->have_argb8888) { - LOG_ERR("compositor does not support ARGB surfaces"); - goto out; - } - if (term.wl->seat == NULL) { - LOG_ERR("no seat available"); - goto out; - } - if (term.wl->data_device_manager == NULL) { - LOG_ERR("no clipboard available " - "(wl_data_device_manager not implemented by server)"); - goto out; - } - if (term.wl->primary_selection_device_manager == NULL) - LOG_WARN("no primary selection available"); - - tll_foreach(term.wl->monitors, it) { - LOG_INFO("%s: %dx%d+%dx%d (scale=%d, refresh=%.2fHz)", - it->item.name, it->item.width_px, it->item.height_px, - it->item.x, it->item.y, it->item.scale, it->item.refresh); - } - - /* Clipboard */ - term.wl->data_device = wl_data_device_manager_get_data_device( - term.wl->data_device_manager, term.wl->seat); - wl_data_device_add_listener(term.wl->data_device, &data_device_listener, term.wl); - - /* Primary selection */ - if (term.wl->primary_selection_device_manager != NULL) { - term.wl->primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( - term.wl->primary_selection_device_manager, term.wl->seat); - zwp_primary_selection_device_v1_add_listener( - term.wl->primary_selection_device, &primary_selection_device_listener, term.wl); - } - - /* Cursor */ - unsigned cursor_size = 24; - const char *cursor_theme = getenv("XCURSOR_THEME"); - - { - const char *env_cursor_size = getenv("XCURSOR_SIZE"); - if (env_cursor_size != NULL) { - unsigned size; - if (sscanf(env_cursor_size, "%u", &size) == 1) - cursor_size = size; - } - } - - /* Note: theme is (re)loaded on scale and output changes */ - LOG_INFO("cursor theme: %s, size: %u", cursor_theme, cursor_size); - term.wl->pointer.size = cursor_size; - term.wl->pointer.theme_name = cursor_theme != NULL ? strdup(cursor_theme) : NULL; - - term.wl->pointer.surface = wl_compositor_create_surface(term.wl->compositor); - if (term.wl->pointer.surface == NULL) { - LOG_ERR("failed to create cursor surface"); - goto out; - } - /* Main window */ - term.window.surface = wl_compositor_create_surface(term.wl->compositor); - if (term.window.surface == NULL) { - LOG_ERR("failed to create wayland surface"); + term.window = wayl_win_init(wayl); + if (term.window == NULL) goto out; - } - - wl_surface_add_listener(term.window.surface, &surface_listener, term.wl); - term.window.xdg_surface = xdg_wm_base_get_xdg_surface(term.wl->shell, term.window.surface); - xdg_surface_add_listener(term.window.xdg_surface, &xdg_surface_listener, term.wl); - - term.window.xdg_toplevel = xdg_surface_get_toplevel(term.window.xdg_surface); - xdg_toplevel_add_listener(term.window.xdg_toplevel, &xdg_toplevel_listener, term.wl); - - xdg_toplevel_set_app_id(term.window.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); - /* Request server-side decorations */ - term.window.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( - term.wl->xdg_decoration_manager, term.window.xdg_toplevel); - zxdg_toplevel_decoration_v1_set_mode( - term.window.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); - zxdg_toplevel_decoration_v1_add_listener( - term.window.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, term.wl); - - /* Scrollback search box */ - term.window.search_surface = wl_compositor_create_surface(term.wl->compositor); - term.window.search_sub_surface = wl_subcompositor_get_subsurface( - term.wl->sub_compositor, term.window.search_surface, term.window.surface); - wl_subsurface_set_desync(term.window.search_sub_surface); - - wl_surface_commit(term.window.surface); - wl_display_roundtrip(term.wl->display); - if (conf.width == -1) { assert(conf.height == -1); conf.width = 80 * term.cell_width; conf.height = 24 * term.cell_height; } + conf.width = max(conf.width, term.cell_width); conf.height = max(conf.height, term.cell_height); render_resize(&term, conf.width, conf.height); @@ -1116,9 +650,6 @@ main(int argc, char *const *argv) } } - if ((fdm = fdm_init()) == NULL) - goto out; - fdm_add(fdm, wl_display_get_fd(term.wl->display), EPOLLIN, &fdm_wayl, term.wl); fdm_add(fdm, term.ptmx, EPOLLIN, &fdm_ptmx, &term); fdm_add(fdm, term.wl->kbd.repeat.fd, EPOLLIN, &fdm_repeat, term.wl); @@ -1163,8 +694,8 @@ out: shm_fini(); - wayl_win_destroy(&term.window); - wayl_destroy(&wayl); + wayl_win_destroy(term.window); + wayl_destroy(wayl); free(term.vt.osc.data); for (int row = 0; row < term.normal.num_rows; row++) diff --git a/render.c b/render.c index 75f319bf..09e4d7d0 100644 --- a/render.c +++ b/render.c @@ -331,7 +331,7 @@ grid_render_scroll(struct terminal *term, struct buffer *buf, height * buf->stride); wl_surface_damage_buffer( - term->window.surface, term->x_margin, dst_y, term->width - term->x_margin, height); + term->window->surface, term->x_margin, dst_y, term->width - term->x_margin, height); } } @@ -357,7 +357,7 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf, height * buf->stride); wl_surface_damage_buffer( - term->window.surface, term->x_margin, dst_y, term->width - term->x_margin, height); + term->window->surface, term->x_margin, dst_y, term->width - term->x_margin, height); } } @@ -441,7 +441,7 @@ grid_render(struct terminal *term) assert(term->height > 0); struct buffer *buf = shm_get_buffer(term->wl->shm, term->width, term->height, 1 + term->render.workers.count); - wl_surface_attach(term->window.surface, buf->wl_buf, 0, 0); + wl_surface_attach(term->window->surface, buf->wl_buf, 0, 0); pixman_image_t *pix = buf->pix; bool all_clean = tll_length(term->grid->scroll_damage) == 0; @@ -489,13 +489,13 @@ grid_render(struct terminal *term) {0, bmargin, term->width, bmargin_height}}); /* Bottom */ wl_surface_damage_buffer( - term->window.surface, 0, 0, term->width, term->y_margin); + term->window->surface, 0, 0, term->width, term->y_margin); wl_surface_damage_buffer( - term->window.surface, 0, 0, term->x_margin, term->height); + term->window->surface, 0, 0, term->x_margin, term->height); wl_surface_damage_buffer( - term->window.surface, rmargin, 0, rmargin_width, term->height); + term->window->surface, rmargin, 0, rmargin_width, term->height); wl_surface_damage_buffer( - term->window.surface, 0, bmargin, term->width, bmargin_height); + term->window->surface, 0, bmargin, term->width, bmargin_height); /* Force a full grid refresh */ term_damage_view(term); @@ -516,7 +516,7 @@ grid_render(struct terminal *term) render_cell(term, pix, cell, at.col, at.row, false); wl_surface_damage_buffer( - term->window.surface, + term->window->surface, term->x_margin + at.col * term->cell_width, term->y_margin + at.row * term->cell_height, term->cell_width, term->cell_height); @@ -569,7 +569,7 @@ grid_render(struct terminal *term) all_clean = false; wl_surface_damage_buffer( - term->window.surface, + term->window->surface, term->x_margin, term->y_margin + r * term->cell_height, term->width - term->x_margin, term->cell_height); } @@ -592,7 +592,7 @@ grid_render(struct terminal *term) all_clean = false; wl_surface_damage_buffer( - term->window.surface, + term->window->surface, term->x_margin, term->y_margin + r * term->cell_height, term->width - term->x_margin, term->cell_height); } @@ -674,7 +674,7 @@ grid_render(struct terminal *term) term, pix, cell, term->cursor.col, view_aligned_row, true); wl_surface_damage_buffer( - term->window.surface, + term->window->surface, term->x_margin + term->cursor.col * term->cell_width, term->y_margin + view_aligned_row * term->cell_height, cols_updated * term->cell_width, term->cell_height); @@ -694,18 +694,18 @@ grid_render(struct terminal *term) 1, &(pixman_rectangle16_t){0, 0, term->width, term->height}); wl_surface_damage_buffer( - term->window.surface, 0, 0, term->width, term->height); + term->window->surface, 0, 0, term->width, term->height); } assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows); assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); - assert(term->window.frame_callback == NULL); - term->window.frame_callback = wl_surface_frame(term->window.surface); - wl_callback_add_listener(term->window.frame_callback, &frame_listener, term); + assert(term->window->frame_callback == NULL); + term->window->frame_callback = wl_surface_frame(term->window->surface); + wl_callback_add_listener(term->window->frame_callback, &frame_listener, term); - wl_surface_set_buffer_scale(term->window.surface, term->scale); - wl_surface_commit(term->window.surface); + wl_surface_set_buffer_scale(term->window->surface, term->scale); + wl_surface_commit(term->window->surface); #if TIME_FRAME_RENDERING struct timeval end_time; @@ -723,16 +723,16 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da { struct terminal *term = data; - assert(term->window.frame_callback == wl_callback); + assert(term->window->frame_callback == wl_callback); wl_callback_destroy(wl_callback); - term->window.frame_callback = NULL; + term->window->frame_callback = NULL; grid_render(term); } void render_search_box(struct terminal *term) { - assert(term->window.search_sub_surface != NULL); + assert(term->window->search_sub_surface != NULL); /* TODO: at least sway allows the subsurface to extend outside the * main window. Do we want that? */ @@ -780,13 +780,13 @@ render_search_box(struct terminal *term) draw_bar(term, buf->pix, font, &fg, x, y); wl_subsurface_set_position( - term->window.search_sub_surface, + term->window->search_sub_surface, term->width - width - margin, term->height - height - margin); - wl_surface_damage_buffer(term->window.search_surface, 0, 0, width, height); - wl_surface_attach(term->window.search_surface, buf->wl_buf, 0, 0); - wl_surface_set_buffer_scale(term->window.search_surface, scale); - wl_surface_commit(term->window.search_surface); + wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height); + wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0); + wl_surface_set_buffer_scale(term->window->search_surface, scale); + wl_surface_commit(term->window->search_surface); } static void @@ -818,7 +818,7 @@ void render_resize(struct terminal *term, int width, int height) { int scale = -1; - tll_foreach(term->window.on_outputs, it) { + tll_foreach(term->window->on_outputs, it) { if (it->item->scale > scale) scale = it->item->scale; } @@ -939,7 +939,7 @@ render_resize(struct terminal *term, int width, int height) void render_set_title(struct terminal *term, const char *title) { - xdg_toplevel_set_title(term->window.xdg_toplevel, title); + xdg_toplevel_set_title(term->window->xdg_toplevel, title); } bool @@ -1000,6 +1000,6 @@ render_update_cursor_surface(struct terminal *term) void render_refresh(struct terminal *term) { - if (term->window.frame_callback == NULL) + if (term->window->frame_callback == NULL) grid_render(term); } diff --git a/search.c b/search.c index e055b478..134c3527 100644 --- a/search.c +++ b/search.c @@ -19,8 +19,8 @@ static void search_cancel_keep_selection(struct terminal *term) { - wl_surface_attach(term->window.search_surface, NULL, 0, 0); - wl_surface_commit(term->window.search_surface); + wl_surface_attach(term->window->search_surface, NULL, 0, 0); + wl_surface_commit(term->window->search_surface); free(term->search.buf); term->search.buf = NULL; diff --git a/terminal.h b/terminal.h index 724bc6f1..2f3fcdc5 100644 --- a/terminal.h +++ b/terminal.h @@ -247,7 +247,7 @@ struct terminal { } fextents; struct wayland *wl; - struct wl_window window; + struct wl_window *window; struct { int scrollback_lines; diff --git a/wayland.c b/wayland.c index c3d7657f..227f9fc4 100644 --- a/wayland.c +++ b/wayland.c @@ -1,5 +1,8 @@ #include "wayland.h" +#include +#include + #include #include #include @@ -14,10 +17,471 @@ #include "tllist.h" #include "terminal.h" +#include "input.h" +#include "render.h" +#include "selection.h" -void -wayl_init(struct wayland *wayl) +#define min(x, y) ((x) < (y) ? (x) : (y)) +#define max(x, y) ((x) > (y) ? (x) : (y)) + +static void +shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) +{ + struct wayland *wayl = data; + if (format == WL_SHM_FORMAT_ARGB8888) + wayl->have_argb8888 = true; +} + +static const struct wl_shm_listener shm_listener = { + .format = &shm_format, +}; + +static void +xdg_wm_base_ping(void *data, struct xdg_wm_base *shell, uint32_t serial) +{ + LOG_DBG("wm base ping"); + xdg_wm_base_pong(shell, serial); +} + +static const struct xdg_wm_base_listener xdg_wm_base_listener = { + .ping = &xdg_wm_base_ping, +}; + +static void +seat_handle_capabilities(void *data, struct wl_seat *wl_seat, + enum wl_seat_capability caps) +{ + struct wayland *wayl = data; + + if (wayl->keyboard != NULL) { + wl_keyboard_release(wayl->keyboard); + wayl->keyboard = NULL; + } + + if (wayl->pointer.pointer != NULL) { + wl_pointer_release(wayl->pointer.pointer); + wayl->pointer.pointer = NULL; + } + + if (caps & WL_SEAT_CAPABILITY_KEYBOARD) { + wayl->keyboard = wl_seat_get_keyboard(wl_seat); + wl_keyboard_add_listener(wayl->keyboard, &keyboard_listener, wayl); + } + + if (caps & WL_SEAT_CAPABILITY_POINTER) { + wayl->pointer.pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(wayl->pointer.pointer, &pointer_listener, wayl); + } +} + +static void +seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) +{ +} + +static const struct wl_seat_listener seat_listener = { + .capabilities = seat_handle_capabilities, + .name = seat_handle_name, +}; + +static void +output_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, + int32_t physical_width, int32_t physical_height, + int32_t subpixel, const char *make, const char *model, + int32_t transform) +{ + struct monitor *mon = data; + mon->width_mm = physical_width; + mon->height_mm = physical_height; +} + +static void +output_mode(void *data, struct wl_output *wl_output, uint32_t flags, + int32_t width, int32_t height, int32_t refresh) +{ + if ((flags & WL_OUTPUT_MODE_CURRENT) == 0) + return; + + struct monitor *mon = data; + mon->refresh = (float)refresh / 1000; +} + +static void +output_done(void *data, struct wl_output *wl_output) +{ +} + +static void +output_scale(void *data, struct wl_output *wl_output, int32_t factor) +{ + struct monitor *mon = data; + + mon->scale = factor; + + struct terminal *term = mon->wayl->term; + if (term != NULL) { + render_resize(term, term->width / term->scale, term->height / term->scale); + render_reload_cursor_theme(term); + } +} + +static const struct wl_output_listener output_listener = { + .geometry = &output_geometry, + .mode = &output_mode, + .done = &output_done, + .scale = &output_scale, +}; + +static void +xdg_output_handle_logical_position( + void *data, struct zxdg_output_v1 *xdg_output, int32_t x, int32_t y) +{ + struct monitor *mon = data; + mon->x = x; + mon->y = y; +} + +static void +xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output, + int32_t width, int32_t height) +{ + struct monitor *mon = data; + mon->width_px = width; + mon->height_px = height; +} + +static void +xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output) +{ +} + +static void +xdg_output_handle_name(void *data, struct zxdg_output_v1 *xdg_output, + const char *name) +{ + struct monitor *mon = data; + mon->name = strdup(name); +} + +static void +xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output, + const char *description) +{ +} + +static struct zxdg_output_v1_listener xdg_output_listener = { + .logical_position = xdg_output_handle_logical_position, + .logical_size = xdg_output_handle_logical_size, + .done = xdg_output_handle_done, + .name = xdg_output_handle_name, + .description = xdg_output_handle_description, +}; + +static void +handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + LOG_DBG("global: %s, version=%u", interface, version); + struct wayland *wayl = data; + + if (strcmp(interface, wl_compositor_interface.name) == 0) { + wayl->compositor = wl_registry_bind( + wayl->registry, name, &wl_compositor_interface, 4); + } + + else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { + wayl->sub_compositor = wl_registry_bind( + wayl->registry, name, &wl_subcompositor_interface, 1); + } + + else if (strcmp(interface, wl_shm_interface.name) == 0) { + wayl->shm = wl_registry_bind( + wayl->registry, name, &wl_shm_interface, 1); + wl_shm_add_listener(wayl->shm, &shm_listener, wayl); + wl_display_roundtrip(wayl->display); + } + + else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { + wayl->shell = wl_registry_bind( + wayl->registry, name, &xdg_wm_base_interface, 1); + xdg_wm_base_add_listener(wayl->shell, &xdg_wm_base_listener, wayl); + } + + else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) + wayl->xdg_decoration_manager = wl_registry_bind( + wayl->registry, name, &zxdg_decoration_manager_v1_interface, 1); + + else if (strcmp(interface, wl_seat_interface.name) == 0) { + wayl->seat = wl_registry_bind( + wayl->registry, name, &wl_seat_interface, 5); + wl_seat_add_listener(wayl->seat, &seat_listener, wayl); + wl_display_roundtrip(wayl->display); + } + + else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { + wayl->xdg_output_manager = wl_registry_bind( + wayl->registry, name, &zxdg_output_manager_v1_interface, min(version, 2)); + } + + else if (strcmp(interface, wl_output_interface.name) == 0) { + struct wl_output *output = wl_registry_bind( + wayl->registry, name, &wl_output_interface, 3); + + tll_push_back( + wayl->monitors, ((struct monitor){.wayl = wayl, .output = output})); + + struct monitor *mon = &tll_back(wayl->monitors); + wl_output_add_listener(output, &output_listener, mon); + + mon->xdg = zxdg_output_manager_v1_get_xdg_output( + wayl->xdg_output_manager, mon->output); + zxdg_output_v1_add_listener(mon->xdg, &xdg_output_listener, mon); + wl_display_roundtrip(wayl->display); + } + + else if (strcmp(interface, wl_data_device_manager_interface.name) == 0) { + wayl->data_device_manager = wl_registry_bind( + wayl->registry, name, &wl_data_device_manager_interface, 1); + } + + else if (strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) { + wayl->primary_selection_device_manager = wl_registry_bind( + wayl->registry, name, &zwp_primary_selection_device_manager_v1_interface, 1); + } +} + +static void +surface_enter(void *data, struct wl_surface *wl_surface, + struct wl_output *wl_output) { + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_surface(wayl, wl_surface); + + tll_foreach(wayl->monitors, it) { + if (it->item.output == wl_output) { + LOG_DBG("mapped on %s", it->item.name); + 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); + render_reload_cursor_theme(term); + return; + } + } + + LOG_ERR("mapped on unknown output"); +} + +static void +surface_leave(void *data, struct wl_surface *wl_surface, + struct wl_output *wl_output) +{ + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_surface(wayl, wl_surface); + + tll_foreach(term->window->on_outputs, it) { + if (it->item->output != wl_output) + continue; + + LOG_DBG("unmapped from %s", it->item->name); + 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); + render_reload_cursor_theme(term); + return; + } + + LOG_ERR("unmapped from unknown output"); +} + +static const struct wl_surface_listener surface_listener = { + .enter = &surface_enter, + .leave = &surface_leave, +}; + +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); + + 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); +} + +static void +xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) +{ + struct wayland *wayl = data; + struct terminal *term = wayl_terminal_from_xdg_toplevel(wayl, xdg_toplevel); + LOG_DBG("xdg-toplevel: close"); + + term->quit = true; + wl_display_roundtrip(wayl->display); +} + +static const struct xdg_toplevel_listener xdg_toplevel_listener = { + .configure = &xdg_toplevel_configure, + .close = &xdg_toplevel_close, +}; + +static void +xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, + uint32_t serial) +{ + //LOG_DBG("xdg-surface: configure"); + xdg_surface_ack_configure(xdg_surface, serial); +} + +static const struct xdg_surface_listener xdg_surface_listener = { + .configure = &xdg_surface_configure, +}; + +static void +xdg_toplevel_decoration_configure(void *data, + struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, + uint32_t mode) +{ + switch (mode) { + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: + LOG_ERR("unimplemented: client-side decorations"); + break; + + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: + LOG_DBG("using server-side decorations"); + break; + + default: + LOG_ERR("unimplemented: unknown XDG toplevel decoration mode: %u", mode); + break; + } +} + +static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = { + .configure = &xdg_toplevel_decoration_configure, +}; + +static void +handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) +{ + LOG_WARN("global removed: %u", name); + assert(false); +} + +static const struct wl_registry_listener registry_listener = { + .global = &handle_global, + .global_remove = &handle_global_remove, +}; + +struct wayland * +wayl_init(struct fdm *fdm) +{ + struct wayland *wayl = calloc(1, sizeof(*wayl)); + wayl->fdm = fdm; + + wayl->display = wl_display_connect(NULL); + if (wayl->display == NULL) { + LOG_ERR("failed to connect to wayland; no compositor running?"); + goto out; + } + + wayl->registry = wl_display_get_registry(wayl->display); + if (wayl->registry == NULL) { + LOG_ERR("failed to get wayland registry"); + goto out; + } + + wl_registry_add_listener(wayl->registry, ®istry_listener, wayl); + wl_display_roundtrip(wayl->display); + + if (wayl->compositor == NULL) { + LOG_ERR("no compositor"); + goto out; + } + if (wayl->shm == NULL) { + LOG_ERR("no shared memory buffers interface"); + goto out; + } + if (wayl->shell == NULL) { + LOG_ERR("no XDG shell interface"); + goto out; + } + if (!wayl->have_argb8888) { + LOG_ERR("compositor does not support ARGB surfaces"); + goto out; + } + if (wayl->seat == NULL) { + LOG_ERR("no seat available"); + goto out; + } + if (wayl->data_device_manager == NULL) { + LOG_ERR("no clipboard available " + "(wl_data_device_manager not implemented by server)"); + goto out; + } + if (wayl->primary_selection_device_manager == NULL) + LOG_WARN("no primary selection available"); + + tll_foreach(wayl->monitors, it) { + LOG_INFO("%s: %dx%d+%dx%d (scale=%d, refresh=%.2fHz)", + it->item.name, it->item.width_px, it->item.height_px, + it->item.x, it->item.y, it->item.scale, it->item.refresh); + } + + /* Clipboard */ + wayl->data_device = wl_data_device_manager_get_data_device( + wayl->data_device_manager, wayl->seat); + wl_data_device_add_listener(wayl->data_device, &data_device_listener, wayl); + + /* Primary selection */ + if (wayl->primary_selection_device_manager != NULL) { + wayl->primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( + wayl->primary_selection_device_manager, wayl->seat); + zwp_primary_selection_device_v1_add_listener( + wayl->primary_selection_device, &primary_selection_device_listener, wayl); + } + + /* Cursor */ + unsigned cursor_size = 24; + const char *cursor_theme = getenv("XCURSOR_THEME"); + + { + const char *env_cursor_size = getenv("XCURSOR_SIZE"); + if (env_cursor_size != NULL) { + unsigned size; + if (sscanf(env_cursor_size, "%u", &size) == 1) + cursor_size = size; + } + } + + /* Note: theme is (re)loaded on scale and output changes */ + LOG_INFO("cursor theme: %s, size: %u", cursor_theme, cursor_size); + wayl->pointer.size = cursor_size; + wayl->pointer.theme_name = cursor_theme != NULL ? strdup(cursor_theme) : NULL; + + wayl->pointer.surface = wl_compositor_create_surface(wayl->compositor); + if (wayl->pointer.surface == NULL) { + LOG_ERR("failed to create cursor surface"); + goto out; + } + + wayl->kbd.repeat.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK); + if (wayl->kbd.repeat.fd == -1) { + LOG_ERRNO("failed to create keyboard repeat timer FD"); + goto out; + } + + return wayl; + +out: + if (wayl != NULL) + wayl_destroy(wayl); + return NULL; } void @@ -93,6 +557,52 @@ wayl_destroy(struct wayland *wayl) wl_display_disconnect(wayl->display); } +struct wl_window * +wayl_win_init(struct wayland *wayl) +{ + struct wl_window *win = calloc(1, sizeof(*win)); + + win->surface = wl_compositor_create_surface(wayl->compositor); + if (win->surface == NULL) { + LOG_ERR("failed to create wayland surface"); + goto out; + } + + wl_surface_add_listener(win->surface, &surface_listener, wayl); + + win->xdg_surface = xdg_wm_base_get_xdg_surface(wayl->shell, win->surface); + xdg_surface_add_listener(win->xdg_surface, &xdg_surface_listener, wayl); + + win->xdg_toplevel = xdg_surface_get_toplevel(win->xdg_surface); + xdg_toplevel_add_listener(win->xdg_toplevel, &xdg_toplevel_listener, wayl); + + xdg_toplevel_set_app_id(win->xdg_toplevel, "foot"); + + /* Request server-side decorations */ + win->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( + wayl->xdg_decoration_manager, win->xdg_toplevel); + zxdg_toplevel_decoration_v1_set_mode( + win->xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + zxdg_toplevel_decoration_v1_add_listener( + win->xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, wayl); + + /* Scrollback search box */ + win->search_surface = wl_compositor_create_surface(wayl->compositor); + win->search_sub_surface = wl_subcompositor_get_subsurface( + wayl->sub_compositor, win->search_surface, win->surface); + wl_subsurface_set_desync(win->search_sub_surface); + + wl_surface_commit(win->surface); + wl_display_roundtrip(wayl->display); + + return win; + +out: + if (win != NULL) + wayl_win_destroy(win); + return NULL; +} + void wayl_win_destroy(struct wl_window *win) { @@ -116,7 +626,7 @@ wayl_win_destroy(struct wl_window *win) struct terminal * wayl_terminal_from_surface(struct wayland *wayl, struct wl_surface *surface) { - assert(surface == wayl->term->window.surface); + assert(surface == wayl->term->window->surface); return wayl->term; } @@ -124,6 +634,6 @@ struct terminal * wayl_terminal_from_xdg_toplevel(struct wayland *wayl, struct xdg_toplevel *toplevel) { - assert(toplevel == wayl->term->window.xdg_toplevel); + assert(toplevel == wayl->term->window->xdg_toplevel); return wayl->term; } diff --git a/wayland.h b/wayland.h index e0f7cd2f..29c30518 100644 --- a/wayland.h +++ b/wayland.h @@ -9,6 +9,7 @@ #include #include +#include "fdm.h" #include "tllist.h" struct monitor { @@ -89,6 +90,7 @@ struct wl_window { struct terminal; struct wayland { + struct fdm *fdm; struct wl_display *display; struct wl_registry *registry; struct wl_compositor *compositor; @@ -149,8 +151,7 @@ struct wayland { struct terminal *moused; }; -/* TODO: return allocated pointer */ -void wayl_init(struct wayland *wayl); +struct wayland *wayl_init(struct fdm *fdm); void wayl_destroy(struct wayland *wayl); struct terminal *wayl_terminal_from_surface( @@ -160,4 +161,5 @@ struct terminal *wayl_terminal_from_xdg_surface( struct terminal *wayl_terminal_from_xdg_toplevel( struct wayland *wayl, struct xdg_toplevel *toplevel); +struct wl_window *wayl_win_init(struct wayland *wayl); void wayl_win_destroy(struct wl_window *win); -- cgit v1.3