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. --- render.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 391115d6..2a8869ee 100644 --- a/render.c +++ b/render.c @@ -1938,14 +1938,15 @@ render_resize_force(struct terminal *term, int width, int height) { return maybe_resize(term, width, height, true); } - +#if 0 static void xcursor_callback( void *data, struct wl_callback *wl_callback, uint32_t callback_data); - static const struct wl_callback_listener xcursor_listener = { .done = &xcursor_callback, }; +#endif +#if 0 static void render_xcursor_update(struct wayland *wayl, const struct terminal *term) { @@ -1984,7 +1985,9 @@ render_xcursor_update(struct wayland *wayl, const struct terminal *term) wl_surface_commit(wayl->pointer.surface); } +#endif +#if 0 static void xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data) { @@ -1999,12 +2002,13 @@ xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_ wayl->pointer.pending_terminal = NULL; } } +#endif static void fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) { struct renderer *renderer = data; - struct wayland *wayl = renderer->wayl; + //struct wayland *wayl = renderer->wayl; tll_foreach(renderer->wayl->terms, it) { struct terminal *term = it->item; @@ -2061,6 +2065,7 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) } } +#if 0 if (wayl->pointer.pending_terminal != NULL) { if (wayl->pointer.xcursor_callback == NULL) { render_xcursor_update(wayl, wayl->pointer.pending_terminal); @@ -2069,6 +2074,7 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) /* Frame callback will call render_xcursor_update() */ } } +#endif } void @@ -2100,6 +2106,7 @@ render_refresh_search(struct terminal *term) bool render_xcursor_set(struct terminal *term) { +#if 0 struct wayland *wayl = term->wl; if (wayl->pointer.theme == NULL) @@ -2122,4 +2129,6 @@ render_xcursor_set(struct terminal *term) /* FDM hook takes care of actual rendering */ wayl->pointer.pending_terminal = term; return true; +#endif + return true; } -- cgit v1.3 From be2490022d445bef2c5c00336aecf2bd9dd25ee7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 8 Jul 2020 18:08:39 +0200 Subject: multi-seat: enable xcursor theme support again --- input.c | 8 ++-- render.c | 90 ++++++++++++++++++++------------------------- render.h | 2 +- terminal.c | 21 +++++++---- wayland.c | 122 ++++++++++++++++++++++--------------------------------------- wayland.h | 4 +- 6 files changed, 104 insertions(+), 143 deletions(-) (limited to 'render.c') diff --git a/input.c b/input.c index 75a80b2f..176d9809 100644 --- a/input.c +++ b/input.c @@ -861,7 +861,7 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_SEARCH: case TERM_SURF_TITLE: term->xcursor = "left_ptr"; - render_xcursor_set(term); + render_xcursor_set(seat, term); break; case TERM_SURF_BORDER_LEFT: @@ -869,14 +869,14 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: term->xcursor = xcursor_for_csd_border(term, x, y); - render_xcursor_set(term); + render_xcursor_set(seat, term); break; case TERM_SURF_BUTTON_MINIMIZE: case TERM_SURF_BUTTON_MAXIMIZE: case TERM_SURF_BUTTON_CLOSE: term->xcursor = "left_ptr"; - render_xcursor_set(term); + render_xcursor_set(seat, term); render_refresh_csd(term); break; @@ -994,7 +994,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: term->xcursor = xcursor_for_csd_border(term, x, y); - render_xcursor_set(term); + render_xcursor_set(seat, term); break; case TERM_SURF_GRID: { diff --git a/render.c b/render.c index 2a8869ee..8fb0fd6f 100644 --- a/render.c +++ b/render.c @@ -1938,77 +1938,72 @@ render_resize_force(struct terminal *term, int width, int height) { return maybe_resize(term, width, height, true); } -#if 0 + static void xcursor_callback( void *data, struct wl_callback *wl_callback, uint32_t callback_data); static const struct wl_callback_listener xcursor_listener = { .done = &xcursor_callback, }; -#endif -#if 0 static void -render_xcursor_update(struct wayland *wayl, const struct terminal *term) +render_xcursor_update(struct seat *seat, const struct terminal *term) { /* If called from a frame callback, we may no longer have mouse focus */ - if (wayl->mouse_focus != term) + if (seat->mouse_focus != term) return; - wayl->pointer.cursor = wl_cursor_theme_get_cursor(wayl->pointer.theme, term->xcursor); - if (wayl->pointer.cursor == NULL) { + seat->pointer.cursor = wl_cursor_theme_get_cursor(seat->pointer.theme, term->xcursor); + if (seat->pointer.cursor == NULL) { LOG_ERR("%s: failed to load xcursor pointer '%s'", - wayl->pointer.theme_name, term->xcursor); + seat->pointer.theme_name, term->xcursor); return; } - wayl->pointer.xcursor = term->xcursor; + seat->pointer.xcursor = term->xcursor; const int scale = term->scale; - struct wl_cursor_image *image = wayl->pointer.cursor->images[0]; + struct wl_cursor_image *image = seat->pointer.cursor->images[0]; wl_surface_attach( - wayl->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0); + seat->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0); wl_pointer_set_cursor( - wayl->pointer.pointer, wayl->pointer.serial, - wayl->pointer.surface, + seat->wl_pointer, seat->pointer.serial, + seat->pointer.surface, image->hotspot_x / scale, image->hotspot_y / scale); wl_surface_damage_buffer( - wayl->pointer.surface, 0, 0, INT32_MAX, INT32_MAX); + seat->pointer.surface, 0, 0, INT32_MAX, INT32_MAX); - wl_surface_set_buffer_scale(wayl->pointer.surface, scale); + wl_surface_set_buffer_scale(seat->pointer.surface, scale); - assert(wayl->pointer.xcursor_callback == NULL); - wayl->pointer.xcursor_callback = wl_surface_frame(wayl->pointer.surface); - wl_callback_add_listener(wayl->pointer.xcursor_callback, &xcursor_listener, wayl); + assert(seat->pointer.xcursor_callback == NULL); + seat->pointer.xcursor_callback = wl_surface_frame(seat->pointer.surface); + wl_callback_add_listener(seat->pointer.xcursor_callback, &xcursor_listener, seat); - wl_surface_commit(wayl->pointer.surface); + wl_surface_commit(seat->pointer.surface); } -#endif -#if 0 static void xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data) { - struct wayland *wayl = data; + struct seat *seat = data; - assert(wayl->pointer.xcursor_callback == wl_callback); + assert(seat->pointer.xcursor_callback == wl_callback); wl_callback_destroy(wl_callback); - wayl->pointer.xcursor_callback = NULL; + seat->pointer.xcursor_callback = NULL; - if (wayl->pointer.pending_terminal != NULL) { - render_xcursor_update(wayl, wayl->pointer.pending_terminal); - wayl->pointer.pending_terminal = NULL; + if (seat->pointer.pending_terminal != NULL) { + render_xcursor_update(seat, seat->pointer.pending_terminal); + seat->pointer.pending_terminal = NULL; } } -#endif static void fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) { struct renderer *renderer = data; - //struct wayland *wayl = renderer->wayl; + struct wayland *wayl = renderer->wayl; tll_foreach(renderer->wayl->terms, it) { struct terminal *term = it->item; @@ -2065,16 +2060,16 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) } } -#if 0 - if (wayl->pointer.pending_terminal != NULL) { - if (wayl->pointer.xcursor_callback == NULL) { - render_xcursor_update(wayl, wayl->pointer.pending_terminal); - wayl->pointer.pending_terminal = NULL; - } else { - /* Frame callback will call render_xcursor_update() */ + tll_foreach(wayl->seats, it) { + if (it->item.pointer.pending_terminal != NULL) { + if (it->item.pointer.xcursor_callback == NULL) { + render_xcursor_update(&it->item, it->item.pointer.pending_terminal); + it->item.pointer.pending_terminal = NULL; + } else { + /* Frame callback will call render_xcursor_update() */ + } } } -#endif } void @@ -2104,31 +2099,26 @@ render_refresh_search(struct terminal *term) } bool -render_xcursor_set(struct terminal *term) +render_xcursor_set(struct seat *seat, struct terminal *term) { -#if 0 - struct wayland *wayl = term->wl; - - if (wayl->pointer.theme == NULL) + if (seat->pointer.theme == NULL) return false; - if (wayl->mouse_focus == NULL) { - wayl->pointer.xcursor = NULL; - wayl->pointer.pending_terminal = NULL; + if (seat->mouse_focus == NULL) { + seat->pointer.xcursor = NULL; + seat->pointer.pending_terminal = NULL; return true; } - if (wayl->mouse_focus != term) { + if (seat->mouse_focus != term) { /* This terminal doesn't have mouse focus */ return true; } - if (wayl->pointer.xcursor == term->xcursor) + if (seat->pointer.xcursor == term->xcursor) return true; /* FDM hook takes care of actual rendering */ - wayl->pointer.pending_terminal = term; - return true; -#endif + seat->pointer.pending_terminal = term; return true; } diff --git a/render.h b/render.h index 0c03f125..4640145b 100644 --- a/render.h +++ b/render.h @@ -16,7 +16,7 @@ void render_refresh(struct terminal *term); void render_refresh_csd(struct terminal *term); void render_refresh_search(struct terminal *term); void render_refresh_title(struct terminal *term); -bool render_xcursor_set(struct terminal *term); +bool render_xcursor_set(struct seat *seat, struct terminal *term); struct render_worker_context { int my_id; diff --git a/terminal.c b/terminal.c index ec46bb76..add0d199 100644 --- a/terminal.c +++ b/terminal.c @@ -2071,13 +2071,17 @@ term_mouse_grabbed(const struct terminal *term) /* * Mouse is grabbed by us, regardless of whether mouse tracking has been enabled or not. */ -#if 0 - return - term->wl->kbd_focus == term && - term->wl->kbd.shift && - !term->wl->kbd.alt && /*!term->wl->kbd.ctrl &&*/ !term->wl->kbd.meta; -#endif - return true; + tll_foreach(term->wl->seats, it) { + const struct seat *seat = &it->item; + + if (seat->kbd_focus == term && + seat->kbd.shift && + !seat->kbd.alt && /*!seat->kbd.ctrl &&*/ !seat->kbd.meta) + { + return true; + } + } + return false; } void @@ -2227,7 +2231,8 @@ term_xcursor_update(struct terminal *term) selection_enabled(term) ? XCURSOR_TEXT : XCURSOR_LEFT_PTR; - render_xcursor_set(term); + tll_foreach(term->wl->seats, it) + render_xcursor_set(&it->item, term); } void diff --git a/wayland.c b/wayland.c index da4f658f..19f8ce3e 100644 --- a/wayland.c +++ b/wayland.c @@ -30,8 +30,7 @@ #include "selection.h" #include "util.h" -static bool wayl_reload_cursor_theme( - struct wayland *wayl, struct terminal *term); +static bool wayl_reload_cursor_theme(struct seat *seat, struct terminal *term); static void csd_instantiate(struct wl_window *win) @@ -202,7 +201,9 @@ update_term_for_output_change(struct terminal *term) render_resize(term, term->width / term->scale, term->height / term->scale); term_font_dpi_changed(term); term_font_subpixel_changed(term); - wayl_reload_cursor_theme(term->wl, term); + + tll_foreach(term->wl->seats, it) + wayl_reload_cursor_theme(&it->item, term); } static void @@ -697,6 +698,9 @@ handle_global(void *data, struct wl_registry *registry, } else primary_selection_device = NULL; + struct wl_surface *pointer_surf + = wl_compositor_create_surface(wayl->compositor); + tll_push_back(wayl->seats, ((struct seat){ .wayl = wayl, .wl_seat = wl_seat, @@ -706,6 +710,11 @@ handle_global(void *data, struct wl_registry *registry, .fd = repeat_fd, }, }, + .pointer = { + .surface = pointer_surf, + .size = wayl->xcursor_size, + .theme_name = wayl->xcursor_theme != NULL ? strdup(wayl->xcursor_theme) : NULL, + }, .data_device = data_device, .primary_selection_device = primary_selection_device, })); @@ -882,6 +891,24 @@ wayl_init(const struct config *conf, struct fdm *fdm) wayl->fdm = fdm; wayl->fd = -1; + /* XCursor */ + const char *xcursor_theme = getenv("XCURSOR_THEME"); + if (xcursor_theme != NULL) + wayl->xcursor_theme = strdup(xcursor_theme); + wayl->xcursor_size = 24; + + { + const char *env_cursor_size = getenv("XCURSOR_SIZE"); + if (env_cursor_size != NULL) { + unsigned size; + if (sscanf(env_cursor_size, "%u", &size) == 1) + wayl->xcursor_size = size; + } + } + + LOG_INFO("cursor theme: %s, size: %u", + wayl->xcursor_theme, wayl->xcursor_size); + if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) { LOG_ERR("failed to add FDM hook"); goto out; @@ -950,45 +977,7 @@ wayl_init(const struct config *conf, struct fdm *fdm) } #if 0 - /* 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; - } #endif - /* All wayland initialization done - make it so */ - wl_display_roundtrip(wayl->display); wayl->fd = wl_display_get_fd(wayl->display); if (fcntl(wayl->fd, F_SETFL, fcntl(wayl->fd, F_GETFL) | O_NONBLOCK) < 0) { @@ -1043,34 +1032,12 @@ wayl_destroy(struct wayland *wayl) 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->presentation != NULL) wp_presentation_destroy(wayl->presentation); - -#if 0 - if (wayl->clipboard.data_source != NULL) - wl_data_source_destroy(wayl->clipboard.data_source); - if (wayl->clipboard.data_offer != NULL) - wl_data_offer_destroy(wayl->clipboard.data_offer); - free(wayl->clipboard.text); - if (wayl->primary.data_source != NULL) - zwp_primary_selection_source_v1_destroy(wayl->primary.data_source); - if (wayl->primary.data_offer != NULL) - zwp_primary_selection_offer_v1_destroy(wayl->primary.data_offer); - free(wayl->primary.text); - - if (wayl->data_device != NULL) - wl_data_device_destroy(wayl->data_device); -#endif if (wayl->data_device_manager != NULL) wl_data_device_manager_destroy(wayl->data_device_manager); -#if 0 - if (wayl->primary_selection_device != NULL) - zwp_primary_selection_device_v1_destroy(wayl->primary_selection_device); -#endif if (wayl->primary_selection_device_manager != NULL) zwp_primary_selection_device_manager_v1_destroy(wayl->primary_selection_device_manager); if (wayl->shm != NULL) @@ -1083,10 +1050,10 @@ wayl_destroy(struct wayland *wayl) wl_registry_destroy(wayl->registry); if (wayl->fd != -1) fdm_del_no_close(wayl->fdm, wayl->fd); - if (wayl->display != NULL) { + if (wayl->display != NULL) wl_display_disconnect(wayl->display); - } + free(wayl->xcursor_theme); free(wayl); } @@ -1222,32 +1189,29 @@ wayl_win_destroy(struct wl_window *win) } static bool -wayl_reload_cursor_theme(struct wayland *wayl, struct terminal *term) +wayl_reload_cursor_theme(struct seat *seat, struct terminal *term) { -#if 0 - if (wayl->pointer.size == 0) + if (seat->pointer.size == 0) return true; - if (wayl->pointer.theme != NULL) { - wl_cursor_theme_destroy(wayl->pointer.theme); - wayl->pointer.theme = NULL; - wayl->pointer.cursor = NULL; + if (seat->pointer.theme != NULL) { + wl_cursor_theme_destroy(seat->pointer.theme); + seat->pointer.theme = NULL; + seat->pointer.cursor = NULL; } LOG_DBG("reloading cursor theme: %s@%d", - wayl->pointer.theme_name, wayl->pointer.size); + seat->pointer.theme_name, seat->pointer.size); - wayl->pointer.theme = wl_cursor_theme_load( - wayl->pointer.theme_name, wayl->pointer.size * term->scale, wayl->shm); + seat->pointer.theme = wl_cursor_theme_load( + seat->pointer.theme_name, seat->pointer.size * term->scale, seat->wayl->shm); - if (wayl->pointer.theme == NULL) { + if (seat->pointer.theme == NULL) { LOG_ERR("failed to load cursor theme"); return false; } - return render_xcursor_set(term); -#endif - return true; + return render_xcursor_set(seat, term); } void diff --git a/wayland.h b/wayland.h index 15dc6057..1232563f 100644 --- a/wayland.h +++ b/wayland.h @@ -311,12 +311,14 @@ struct wayland { struct wp_presentation *presentation; uint32_t presentation_clock_id; - bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ tll(struct seat) seats; tll(struct terminal *) terms; + + char *xcursor_theme; + unsigned xcursor_size; }; struct wayland *wayl_init(const struct config *conf, struct fdm *fdm); -- cgit v1.3 From 4e48d550efba98ebecf4b60045004e52c585c52d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 9 Jul 2020 09:52:11 +0200 Subject: multi-seat: improve handling of multiple (mouse) pointers * xcursor always set for all pointers * xcursor sometimes not updated when it should be * mouse grabbed state wasn't per seat, but global (i.e. "does at least one seat enable mouse grabbing") * selection enabled state wasn't per seat --- input.c | 71 ++++++++++++++++++++++++++++++++----------------------------- render.c | 34 ++++++++++++++--------------- render.h | 2 +- selection.c | 4 ++-- selection.h | 2 +- terminal.c | 55 +++++++++++++++++++++-------------------------- terminal.h | 15 +++++++++++-- wayland.h | 4 ++-- 8 files changed, 97 insertions(+), 90 deletions(-) (limited to 'render.c') diff --git a/input.c b/input.c index 1caf46b3..f0024a0d 100644 --- a/input.c +++ b/input.c @@ -817,14 +817,14 @@ is_bottom_right(const struct terminal *term, int x, int y) static const char * xcursor_for_csd_border(struct terminal *term, int x, int y) { - if (is_top_left(term, x, y)) return "top_left_corner"; - else if (is_top_right(term, x, y)) return "top_right_corner"; - else if (is_bottom_left(term, x, y)) return "bottom_left_corner"; - else if (is_bottom_right(term, x, y)) return "bottom_right_corner"; - else if (term->active_surface == TERM_SURF_BORDER_LEFT) return "left_side"; - else if (term->active_surface == TERM_SURF_BORDER_RIGHT) return "right_side"; - else if (term->active_surface == TERM_SURF_BORDER_TOP) return "top_side"; - else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return"bottom_side"; + if (is_top_left(term, x, y)) return XCURSOR_TOP_LEFT_CORNER; + else if (is_top_right(term, x, y)) return XCURSOR_TOP_RIGHT_CORNER; + else if (is_bottom_left(term, x, y)) return XCURSOR_BOTTOM_LEFT_CORNER; + else if (is_bottom_right(term, x, y)) return XCURSOR_BOTTOM_RIGHT_CORNER; + else if (term->active_surface == TERM_SURF_BORDER_LEFT) return XCURSOR_LEFT_SIDE; + else if (term->active_surface == TERM_SURF_BORDER_RIGHT) return XCURSOR_RIGHT_SIDE; + else if (term->active_surface == TERM_SURF_BORDER_TOP) return XCURSOR_TOP_SIDE; + else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return XCURSOR_BOTTOM_SIDE; else { assert(false); return NULL; @@ -862,23 +862,20 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_SEARCH: case TERM_SURF_TITLE: - term->xcursor = "left_ptr"; - render_xcursor_set(seat, term); + render_xcursor_set(seat, term, XCURSOR_LEFT_PTR); break; case TERM_SURF_BORDER_LEFT: case TERM_SURF_BORDER_RIGHT: case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: - term->xcursor = xcursor_for_csd_border(term, x, y); - render_xcursor_set(seat, term); + render_xcursor_set(seat, term, xcursor_for_csd_border(term, x, y)); break; case TERM_SURF_BUTTON_MINIMIZE: case TERM_SURF_BUTTON_MAXIMIZE: case TERM_SURF_BUTTON_CLOSE: - term->xcursor = "left_ptr"; - render_xcursor_set(seat, term); + render_xcursor_set(seat, term, XCURSOR_LEFT_PTR); render_refresh_csd(term); break; @@ -903,7 +900,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, /* A cursor frame callback may never be called if the pointer leaves our surface */ wl_callback_destroy(seat->pointer.xcursor_callback); seat->pointer.xcursor_callback = NULL; - seat->pointer.pending_terminal = NULL; + seat->pointer.xcursor_pending = false; seat->pointer.xcursor = NULL; } @@ -995,8 +992,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BORDER_RIGHT: case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: - term->xcursor = xcursor_for_csd_border(term, x, y); - render_xcursor_set(seat, term); + render_xcursor_set(seat, term, xcursor_for_csd_border(term, x, y)); break; case TERM_SURF_GRID: { @@ -1021,9 +1017,11 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, if (update_selection && !update_selection_early) selection_update(term, col, row); - term_mouse_motion( - term, seat->mouse.button, seat->mouse.row, seat->mouse.col, - seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + if (!term_mouse_grabbed(term, seat)) { + term_mouse_motion( + term, seat->mouse.button, seat->mouse.row, seat->mouse.col, + seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + } break; } } @@ -1190,7 +1188,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (button == BTN_LEFT && seat->mouse.count <= 3) { selection_cancel(term); - if (selection_enabled(term)) { + if (selection_enabled(term, seat)) { switch (seat->mouse.count) { case 1: selection_start( @@ -1212,7 +1210,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } else if (button == BTN_RIGHT && seat->mouse.count == 1) { - if (selection_enabled(term)) { + if (selection_enabled(term, seat)) { selection_extend( seat, term, seat->mouse.col, seat->mouse.row, serial); } @@ -1238,9 +1236,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } } - term_mouse_down( - term, button, seat->mouse.row, seat->mouse.col, - seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + if (!term_mouse_grabbed(term, seat)) { + term_mouse_down( + term, button, seat->mouse.row, seat->mouse.col, + seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + } break; } @@ -1248,9 +1248,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (button == BTN_LEFT && term->selection.end.col != -1) selection_finalize(seat, term, serial); - term_mouse_up( - term, button, seat->mouse.row, seat->mouse.col, - seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + if (!term_mouse_grabbed(term, seat)) { + term_mouse_up( + term, button, seat->mouse.row, seat->mouse.col, + seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + } break; } break; @@ -1298,15 +1300,16 @@ mouse_scroll(struct seat *seat, int amount) 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); } else { - for (int i = 0; i < amount; i++) { - term_mouse_down( + if (!term_mouse_grabbed(term, seat)) { + for (int i = 0; i < amount; i++) { + term_mouse_down( + term, button, seat->mouse.row, seat->mouse.col, + seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); + } + term_mouse_up( term, button, seat->mouse.row, seat->mouse.col, seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); } - term_mouse_up( - term, button, seat->mouse.row, seat->mouse.col, - seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); - scrollback(term, amount); } } diff --git a/render.c b/render.c index 8fb0fd6f..603f9c2d 100644 --- a/render.c +++ b/render.c @@ -1946,22 +1946,22 @@ static const struct wl_callback_listener xcursor_listener = { }; static void -render_xcursor_update(struct seat *seat, const struct terminal *term) +render_xcursor_update(struct seat *seat) { /* If called from a frame callback, we may no longer have mouse focus */ - if (seat->mouse_focus != term) + if (!seat->mouse_focus) return; - seat->pointer.cursor = wl_cursor_theme_get_cursor(seat->pointer.theme, term->xcursor); + seat->pointer.cursor = wl_cursor_theme_get_cursor( + seat->pointer.theme, seat->pointer.xcursor); + if (seat->pointer.cursor == NULL) { LOG_ERR("%s: failed to load xcursor pointer '%s'", - seat->pointer.theme_name, term->xcursor); + seat->pointer.theme_name, seat->pointer.xcursor); return; } - seat->pointer.xcursor = term->xcursor; - - const int scale = term->scale; + const int scale = seat->pointer.scale; struct wl_cursor_image *image = seat->pointer.cursor->images[0]; wl_surface_attach( @@ -1993,9 +1993,9 @@ xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_ wl_callback_destroy(wl_callback); seat->pointer.xcursor_callback = NULL; - if (seat->pointer.pending_terminal != NULL) { - render_xcursor_update(seat, seat->pointer.pending_terminal); - seat->pointer.pending_terminal = NULL; + if (seat->pointer.xcursor_pending) { + render_xcursor_update(seat); + seat->pointer.xcursor_pending = false; } } @@ -2061,10 +2061,10 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) } tll_foreach(wayl->seats, it) { - if (it->item.pointer.pending_terminal != NULL) { + if (it->item.pointer.xcursor_pending) { if (it->item.pointer.xcursor_callback == NULL) { - render_xcursor_update(&it->item, it->item.pointer.pending_terminal); - it->item.pointer.pending_terminal = NULL; + render_xcursor_update(&it->item); + it->item.pointer.xcursor_pending = false; } else { /* Frame callback will call render_xcursor_update() */ } @@ -2099,14 +2099,13 @@ render_refresh_search(struct terminal *term) } bool -render_xcursor_set(struct seat *seat, struct terminal *term) +render_xcursor_set(struct seat *seat, struct terminal *term, const char *xcursor) { if (seat->pointer.theme == NULL) return false; if (seat->mouse_focus == NULL) { seat->pointer.xcursor = NULL; - seat->pointer.pending_terminal = NULL; return true; } @@ -2115,10 +2114,11 @@ render_xcursor_set(struct seat *seat, struct terminal *term) return true; } - if (seat->pointer.xcursor == term->xcursor) + if (seat->pointer.xcursor == xcursor) return true; /* FDM hook takes care of actual rendering */ - seat->pointer.pending_terminal = term; + seat->pointer.xcursor_pending = true; + seat->pointer.xcursor = xcursor; return true; } diff --git a/render.h b/render.h index 4640145b..05c79322 100644 --- a/render.h +++ b/render.h @@ -16,7 +16,7 @@ void render_refresh(struct terminal *term); void render_refresh_csd(struct terminal *term); void render_refresh_search(struct terminal *term); void render_refresh_title(struct terminal *term); -bool render_xcursor_set(struct seat *seat, struct terminal *term); +bool render_xcursor_set(struct seat *seat, struct terminal *term, const char *xcursor); struct render_worker_context { int my_id; diff --git a/selection.c b/selection.c index 2c8176dd..f097e37b 100644 --- a/selection.c +++ b/selection.c @@ -21,11 +21,11 @@ #include "vt.h" bool -selection_enabled(const struct terminal *term) +selection_enabled(const struct terminal *term, struct seat *seat) { return term->mouse_tracking == MOUSE_NONE || - term_mouse_grabbed(term) || + term_mouse_grabbed(term, seat) || term->is_searching; } diff --git a/selection.h b/selection.h index e049f182..52b0f1a3 100644 --- a/selection.h +++ b/selection.h @@ -8,7 +8,7 @@ extern const struct wl_data_device_listener data_device_listener; extern const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener; -bool selection_enabled(const struct terminal *term); +bool selection_enabled(const struct terminal *term, struct seat *seat); void selection_start( struct terminal *term, int col, int row, enum selection_kind kind); void selection_update(struct terminal *term, int col, int row); diff --git a/terminal.c b/terminal.c index 96c83644..1e7ddabe 100644 --- a/terminal.c +++ b/terminal.c @@ -34,9 +34,17 @@ #define PTMX_TIMING 0 -static const char *const XCURSOR_LEFT_PTR = "left_ptr"; -static const char *const XCURSOR_TEXT = "text"; -//static const char *const XCURSOR_HAND2 = "hand2"; +const char *const XCURSOR_LEFT_PTR = "left_ptr"; +const char *const XCURSOR_TEXT = "text"; +//const char *const XCURSOR_HAND2 = "hand2"; +const char *const XCURSOR_TOP_LEFT_CORNER = "top_left_corner"; +const char *const XCURSOR_TOP_RIGHT_CORNER = "top_right_corner"; +const char *const XCURSOR_BOTTOM_LEFT_CORNER = "bottom_left_corner"; +const char *const XCURSOR_BOTTOM_RIGHT_CORNER = "bottom_right_corner"; +const char *const XCURSOR_LEFT_SIDE = "left_side"; +const char *const XCURSOR_RIGHT_SIDE = "right_side"; +const char *const XCURSOR_TOP_SIDE = "top_side"; +const char *const XCURSOR_BOTTOM_SIDE = "bottom_side"; bool term_to_slave(struct terminal *term, const void *_data, size_t len) @@ -889,7 +897,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .text = conf->cursor.color.text, .cursor = conf->cursor.color.cursor, }, - .xcursor = "text", .selection = { .start = {-1, -1}, .end = {-1, -1}, @@ -2068,31 +2075,20 @@ report_mouse_motion(struct terminal *term, int encoded_button, int row, int col) } bool -term_mouse_grabbed(const struct terminal *term) +term_mouse_grabbed(const struct terminal *term, struct seat *seat) { /* * Mouse is grabbed by us, regardless of whether mouse tracking has been enabled or not. */ - tll_foreach(term->wl->seats, it) { - const struct seat *seat = &it->item; - - if (seat->kbd_focus == term && - seat->kbd.shift && - !seat->kbd.alt && /*!seat->kbd.ctrl &&*/ !seat->kbd.meta) - { - return true; - } - } - return false; + return seat->kbd_focus == term && + seat->kbd.shift && + !seat->kbd.alt && /*!seat->kbd.ctrl &&*/ !seat->kbd.meta; } void term_mouse_down(struct terminal *term, int button, int row, int col, bool _shift, bool _alt, bool _ctrl) { - if (term_mouse_grabbed(term)) - return; - /* Map libevent button event code to X button number */ int xbutton = linux_mouse_button_to_x(button); if (xbutton == -1) @@ -2131,9 +2127,6 @@ void term_mouse_up(struct terminal *term, int button, int row, int col, bool _shift, bool _alt, bool _ctrl) { - if (term_mouse_grabbed(term)) - return; - /* Map libevent button event code to X button number */ int xbutton = linux_mouse_button_to_x(button); if (xbutton == -1) @@ -2176,9 +2169,6 @@ void term_mouse_motion(struct terminal *term, int button, int row, int col, bool _shift, bool _alt, bool _ctrl) { - if (term_mouse_grabbed(term)) - return; - int encoded = 0; if (button != 0) { @@ -2225,13 +2215,16 @@ term_mouse_motion(struct terminal *term, int button, int row, int col, void term_xcursor_update(struct terminal *term) { - term->xcursor = - term->is_searching ? XCURSOR_LEFT_PTR : /* TODO: something different? */ - selection_enabled(term) ? XCURSOR_TEXT : - XCURSOR_LEFT_PTR; + tll_foreach(term->wl->seats, it) { + struct seat *seat = &it->item; - tll_foreach(term->wl->seats, it) - render_xcursor_set(&it->item, term); + const char *xcursor + = term->is_searching ? XCURSOR_LEFT_PTR : /* TODO: something different? */ + selection_enabled(term, seat) ? XCURSOR_TEXT : + XCURSOR_LEFT_PTR; + + render_xcursor_set(seat, term, xcursor); + } } void diff --git a/terminal.h b/terminal.h index 604511da..8316795f 100644 --- a/terminal.h +++ b/terminal.h @@ -305,7 +305,6 @@ struct terminal { uint32_t text; uint32_t cursor; } cursor_color; - const char *xcursor; struct { enum selection_kind kind; @@ -439,6 +438,18 @@ struct terminal { char *cwd; }; +extern const char *const XCURSOR_LEFT_PTR; +extern const char *const XCURSOR_TEXT; +//extern const char *const XCURSOR_HAND2; +extern const char *const XCURSOR_TOP_LEFT_CORNER; +extern const char *const XCURSOR_TOP_RIGHT_CORNER; +extern const char *const XCURSOR_BOTTOM_LEFT_CORNER; +extern const char *const XCURSOR_BOTTOM_RIGHT_CORNER; +extern const char *const XCURSOR_LEFT_SIDE; +extern const char *const XCURSOR_RIGHT_SIDE; +extern const char *const XCURSOR_TOP_SIDE; +extern const char *const XCURSOR_BOTTOM_SIDE; + struct config; struct terminal *term_init( const struct config *conf, struct fdm *fdm, struct reaper *reaper, @@ -518,7 +529,7 @@ void term_mouse_up( void term_mouse_motion( struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl); -bool term_mouse_grabbed(const struct terminal *term); +bool term_mouse_grabbed(const struct terminal *term, struct seat *seat); void term_xcursor_update(struct terminal *term); void term_set_window_title(struct terminal *term, const char *title); diff --git a/wayland.h b/wayland.h index 489f485d..f703883e 100644 --- a/wayland.h +++ b/wayland.h @@ -148,10 +148,10 @@ struct seat { int size; int scale; char *theme_name; - const char *xcursor; - const struct terminal *pending_terminal; + const char *xcursor; struct wl_callback *xcursor_callback; + bool xcursor_pending; } pointer; struct { -- cgit v1.3 From bf62519d8330204b12e9e3743fb332e3abde0ed0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 10 Jul 2020 12:06:55 +0200 Subject: wayland: read XCURSOR_{THEME,SIZE} in reload_xcursor theme --- render.c | 3 +-- wayland.c | 42 +++++++++++++++--------------------------- wayland.h | 5 ----- 3 files changed, 16 insertions(+), 34 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 603f9c2d..670b9282 100644 --- a/render.c +++ b/render.c @@ -1956,8 +1956,7 @@ render_xcursor_update(struct seat *seat) seat->pointer.theme, seat->pointer.xcursor); if (seat->pointer.cursor == NULL) { - LOG_ERR("%s: failed to load xcursor pointer '%s'", - seat->pointer.theme_name, seat->pointer.xcursor); + LOG_ERR("failed to load xcursor pointer '%s'", seat->pointer.xcursor); return; } diff --git a/wayland.c b/wayland.c index 38ef57f0..2ba385fa 100644 --- a/wayland.c +++ b/wayland.c @@ -96,7 +96,6 @@ seat_destroy(struct seat *seat) if (seat->kbd.repeat.fd >= 0) fdm_del(seat->wayl->fdm, seat->kbd.repeat.fd); - free(seat->pointer.theme_name); if (seat->pointer.theme != NULL) wl_cursor_theme_destroy(seat->pointer.theme); if (seat->pointer.surface != NULL) @@ -718,8 +717,6 @@ handle_global(void *data, struct wl_registry *registry, }, .pointer = { .surface = pointer_surf, - .size = wayl->xcursor_size, - .theme_name = wayl->xcursor_theme != NULL ? strdup(wayl->xcursor_theme) : NULL, }, .data_device = data_device, .primary_selection_device = primary_selection_device, @@ -926,23 +923,6 @@ wayl_init(const struct config *conf, struct fdm *fdm) wayl->fdm = fdm; wayl->fd = -1; - /* XCursor */ - const char *xcursor_theme = getenv("XCURSOR_THEME"); - if (xcursor_theme != NULL) - wayl->xcursor_theme = strdup(xcursor_theme); - wayl->xcursor_size = 24; - - { - const char *env_cursor_size = getenv("XCURSOR_SIZE"); - if (env_cursor_size != NULL) { - unsigned size; - if (sscanf(env_cursor_size, "%u", &size) == 1) - wayl->xcursor_size = size; - } - } - - LOG_INFO("XCURSOR_THEME=%s, XCURSOR_SIZE=%u", wayl->xcursor_theme, wayl->xcursor_size); - if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) { LOG_ERR("failed to add FDM hook"); goto out; @@ -1085,7 +1065,6 @@ wayl_destroy(struct wayland *wayl) if (wayl->display != NULL) wl_display_disconnect(wayl->display); - free(wayl->xcursor_theme); free(wayl); } @@ -1223,9 +1202,6 @@ wayl_win_destroy(struct wl_window *win) bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale) { - if (seat->pointer.size == 0) - return true; - if (seat->pointer.theme != NULL && seat->pointer.scale == new_scale) { /* We already have a theme loaded, and the scale hasn't changed */ return true; @@ -1238,11 +1214,23 @@ wayl_reload_xcursor_theme(struct seat *seat, int new_scale) seat->pointer.cursor = NULL; } - LOG_DBG("reloading cursor theme: %s@%d", - seat->pointer.theme_name, seat->pointer.size); + const char *xcursor_theme = getenv("XCURSOR_THEME"); + int xcursor_size = 24; + + { + const char *env_cursor_size = getenv("XCURSOR_SIZE"); + if (env_cursor_size != NULL) { + unsigned size; + if (sscanf(env_cursor_size, "%u", &size) == 1) + xcursor_size = size; + } + } + + LOG_INFO("cursor theme: %s, size: %u, scale: %d", + xcursor_theme, xcursor_size, new_scale); seat->pointer.theme = wl_cursor_theme_load( - seat->pointer.theme_name, seat->pointer.size * new_scale, seat->wayl->shm); + xcursor_theme, xcursor_size * new_scale, seat->wayl->shm); if (seat->pointer.theme == NULL) { LOG_ERR("failed to load cursor theme"); diff --git a/wayland.h b/wayland.h index 0b136c04..224853a6 100644 --- a/wayland.h +++ b/wayland.h @@ -147,9 +147,7 @@ struct seat { struct wl_surface *surface; struct wl_cursor_theme *theme; struct wl_cursor *cursor; - int size; int scale; - char *theme_name; const char *xcursor; struct wl_callback *xcursor_callback; @@ -318,9 +316,6 @@ struct wayland { tll(struct seat) seats; tll(struct terminal *) terms; - - char *xcursor_theme; - unsigned xcursor_size; }; struct wayland *wayl_init(const struct config *conf, struct fdm *fdm); -- cgit v1.3