From c47082506714f458e999f6ff1bf3099dfc4c0c0c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 8 Jul 2020 16:45:26 +0200 Subject: wip: multi-seat support Compiles and runs, but mouse, clipboard and other things have been disabled. --- osc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'osc.c') diff --git a/osc.c b/osc.c index a2702595..1a72cb12 100644 --- a/osc.c +++ b/osc.c @@ -52,6 +52,9 @@ osc_to_clipboard(struct terminal *term, const char *target, } } + (void)to_clipboard; + (void)to_primary; +#if 0 if (to_clipboard) { char *copy = strdup(decoded); if (!text_to_clipboard(term, copy, term->wl->input_serial)) @@ -63,7 +66,7 @@ osc_to_clipboard(struct terminal *term, const char *target, if (!text_to_primary(term, copy, term->wl->input_serial)) free(copy); } - +#endif free(decoded); } @@ -73,6 +76,7 @@ struct clip_context { int idx; }; +#if 0 static void from_clipboard_cb(const char *text, size_t size, void *user) { @@ -117,7 +121,8 @@ from_clipboard_cb(const char *text, size_t size, void *user) term_to_slave(term, chunk, strlen(chunk)); free(chunk); } - +#endif +#if 0 static void from_clipboard_done(void *user) { @@ -133,7 +138,7 @@ from_clipboard_done(void *user) term_to_slave(term, "\033\\", 2); free(ctx); } - +#endif static void osc_from_clipboard(struct terminal *term, const char *source) { @@ -158,6 +163,7 @@ osc_from_clipboard(struct terminal *term, const char *source) struct clip_context *ctx = malloc(sizeof(*ctx)); *ctx = (struct clip_context) {.term = term}; +#if 0 switch (src) { case 'c': text_from_clipboard( @@ -170,6 +176,7 @@ osc_from_clipboard(struct terminal *term, const char *source) text_from_primary(term, &from_clipboard_cb, &from_clipboard_done, ctx); break; } +#endif } static void -- cgit v1.3 From 11373a65616e4062dc625021b4259e8d227ed5e8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 8 Jul 2020 19:28:08 +0200 Subject: multi-seat: re-enable OSC 52 support --- osc.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'osc.c') diff --git a/osc.c b/osc.c index 1a72cb12..3183f196 100644 --- a/osc.c +++ b/osc.c @@ -52,31 +52,42 @@ osc_to_clipboard(struct terminal *term, const char *target, } } - (void)to_clipboard; - (void)to_primary; -#if 0 + /* Find a seat in which the terminal has focus */ + struct seat *seat = NULL; + tll_foreach(term->wl->seats, it) { + if (it->item.kbd_focus == term) { + seat = &it->item; + break; + } + } + + if (seat == NULL) { + LOG_WARN("OSC52: client tried to write to clipboard data while window was unfocused"); + return; + } + if (to_clipboard) { char *copy = strdup(decoded); - if (!text_to_clipboard(term, copy, term->wl->input_serial)) + if (!text_to_clipboard(seat, term, copy, seat->input_serial)) free(copy); } if (to_primary) { char *copy = strdup(decoded); - if (!text_to_primary(term, copy, term->wl->input_serial)) + if (!text_to_primary(seat, term, copy, seat->input_serial)) free(copy); } -#endif + free(decoded); } struct clip_context { + struct seat *seat; struct terminal *term; uint8_t buf[3]; int idx; }; -#if 0 static void from_clipboard_cb(const char *text, size_t size, void *user) { @@ -121,8 +132,7 @@ from_clipboard_cb(const char *text, size_t size, void *user) term_to_slave(term, chunk, strlen(chunk)); free(chunk); } -#endif -#if 0 + static void from_clipboard_done(void *user) { @@ -138,7 +148,7 @@ from_clipboard_done(void *user) term_to_slave(term, "\033\\", 2); free(ctx); } -#endif + static void osc_from_clipboard(struct terminal *term, const char *source) { @@ -156,27 +166,40 @@ osc_from_clipboard(struct terminal *term, const char *source) if (src == 0) return; + /* Find a seat in which the terminal has focus */ + struct seat *seat = NULL; + tll_foreach(term->wl->seats, it) { + if (it->item.kbd_focus == term) { + seat = &it->item; + break; + } + } + + if (seat == NULL) { + LOG_WARN("OSC52: client tried to read clipboard data while window was unfocused"); + return; + } + term_to_slave(term, "\033]52;", 5); term_to_slave(term, &src, 1); term_to_slave(term, ";", 1); struct clip_context *ctx = malloc(sizeof(*ctx)); - *ctx = (struct clip_context) {.term = term}; + *ctx = (struct clip_context) {.seat = seat, .term = term}; -#if 0 switch (src) { case 'c': text_from_clipboard( - term, term->wl->input_serial, + seat, term, seat->input_serial, &from_clipboard_cb, &from_clipboard_done, ctx); break; case 's': case 'p': - text_from_primary(term, &from_clipboard_cb, &from_clipboard_done, ctx); + text_from_primary( + seat, term, &from_clipboard_cb, &from_clipboard_done, ctx); break; } -#endif } static void -- cgit v1.3 From 71584aed388935908588686e5df7ec42855f3698 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 9 Jul 2020 11:20:46 +0200 Subject: seat: use separate 'enter' serials for keyboard and mouse --- input.c | 10 ++++++---- osc.c | 7 +++---- selection.c | 4 ++-- selection.h | 2 +- wayland.h | 3 ++- 5 files changed, 14 insertions(+), 12 deletions(-) (limited to 'osc.c') diff --git a/input.c b/input.c index f0024a0d..bc35ad56 100644 --- a/input.c +++ b/input.c @@ -306,7 +306,7 @@ keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, term_kbd_focus_in(term); seat->kbd_focus = term; - seat->input_serial = serial; + seat->kbd.serial = serial; } static bool @@ -773,7 +773,7 @@ const struct wl_keyboard_listener keyboard_listener = { void input_repeat(struct seat *seat, uint32_t key) { - keyboard_key(seat, NULL, seat->input_serial, 0, key, XKB_KEY_DOWN); + keyboard_key(seat, NULL, seat->kbd.serial, 0, key, XKB_KEY_DOWN); } static bool @@ -842,6 +842,8 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, struct wl_window *win = wl_surface_get_user_data(surface); struct terminal *term = win->term; + seat->pointer.serial = serial; + LOG_DBG("pointer-enter: pointer=%p, serial=%u, surface = %p, new-moused = %p", wl_pointer, serial, surface, term); @@ -1297,8 +1299,8 @@ mouse_scroll(struct seat *seat, int amount) xkb_keycode_t key = button == BTN_BACK ? key_arrow_up : key_arrow_down; for (int i = 0; i < amount; i++) - keyboard_key(seat, NULL, seat->input_serial, 0, key - 8, XKB_KEY_DOWN); - keyboard_key(seat, NULL, seat->input_serial, 0, key - 8, XKB_KEY_UP); + keyboard_key(seat, NULL, seat->kbd.serial, 0, key - 8, XKB_KEY_DOWN); + keyboard_key(seat, NULL, seat->kbd.serial, 0, key - 8, XKB_KEY_UP); } else { if (!term_mouse_grabbed(term, seat)) { for (int i = 0; i < amount; i++) { diff --git a/osc.c b/osc.c index 3183f196..42bef722 100644 --- a/osc.c +++ b/osc.c @@ -68,13 +68,13 @@ osc_to_clipboard(struct terminal *term, const char *target, if (to_clipboard) { char *copy = strdup(decoded); - if (!text_to_clipboard(seat, term, copy, seat->input_serial)) + if (!text_to_clipboard(seat, term, copy, seat->kbd.serial)) free(copy); } if (to_primary) { char *copy = strdup(decoded); - if (!text_to_primary(seat, term, copy, seat->input_serial)) + if (!text_to_primary(seat, term, copy, seat->kbd.serial)) free(copy); } @@ -190,8 +190,7 @@ osc_from_clipboard(struct terminal *term, const char *source) switch (src) { case 'c': text_from_clipboard( - seat, term, seat->input_serial, - &from_clipboard_cb, &from_clipboard_done, ctx); + seat, term, &from_clipboard_cb, &from_clipboard_done, ctx); break; case 's': diff --git a/selection.c b/selection.c index f097e37b..62f131b1 100644 --- a/selection.c +++ b/selection.c @@ -1087,7 +1087,7 @@ begin_receive_clipboard(struct terminal *term, int read_fd, } void -text_from_clipboard(struct seat *seat, struct terminal *term, uint32_t serial, +text_from_clipboard(struct seat *seat, struct terminal *term, void (*cb)(const char *data, size_t size, void *user), void (*done)(void *user), void *user) { @@ -1142,7 +1142,7 @@ selection_from_clipboard(struct seat *seat, struct terminal *term, uint32_t seri term_to_slave(term, "\033[200~", 6); text_from_clipboard( - seat, term, serial, &from_clipboard_cb, &from_clipboard_done, term); + seat, term, &from_clipboard_cb, &from_clipboard_done, term); } bool diff --git a/selection.h b/selection.h index 52b0f1a3..bd995855 100644 --- a/selection.h +++ b/selection.h @@ -59,7 +59,7 @@ bool text_to_primary( * point). */ void text_from_clipboard( - struct seat *seat, struct terminal *term, uint32_t serial, + struct seat *seat, struct terminal *term, void (*cb)(const char *data, size_t size, void *user), void (*done)(void *user), void *user); diff --git a/wayland.h b/wayland.h index f703883e..0b136c04 100644 --- a/wayland.h +++ b/wayland.h @@ -106,6 +106,8 @@ struct seat { /* Keyboard state */ struct wl_keyboard *wl_keyboard; struct { + uint32_t serial; + struct xkb_context *xkb; struct xkb_keymap *xkb_keymap; struct xkb_state *xkb_state; @@ -171,7 +173,6 @@ struct seat { } mouse; /* Clipboard */ - uint32_t input_serial; struct wl_data_device *data_device; struct zwp_primary_selection_device_v1 *primary_selection_device; -- cgit v1.3