mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
Add support for cursor-shape-v1
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4106
This commit is contained in:
parent
dc634c4a13
commit
6bd11ad0df
|
@ -145,4 +145,6 @@ uint32_t get_mouse_button(const char *name, char **error);
|
|||
|
||||
const char *get_mouse_button_name(uint32_t button);
|
||||
|
||||
void handle_request_set_cursor_shape(struct wl_listener *listener, void *data);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -120,6 +120,8 @@ struct sway_server {
|
|||
struct wl_listener xdg_activation_v1_request_activate;
|
||||
struct wl_listener xdg_activation_v1_new_token;
|
||||
|
||||
struct wl_listener request_set_cursor_shape;
|
||||
|
||||
struct wl_list pending_launcher_ctxs; // launcher_ctx::link
|
||||
|
||||
// The timeout for transactions, after which a transaction is applied
|
||||
|
|
|
@ -13,6 +13,7 @@ protocols = [
|
|||
wl_protocol_dir / 'unstable/tablet/tablet-unstable-v2.xml',
|
||||
wl_protocol_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml',
|
||||
wl_protocol_dir / 'staging/content-type/content-type-v1.xml',
|
||||
wl_protocol_dir / 'staging/cursor-shape/cursor-shape-v1.xml',
|
||||
'wlr-layer-shell-unstable-v1.xml',
|
||||
'idle.xml',
|
||||
'wlr-input-inhibitor-unstable-v1.xml',
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <time.h>
|
||||
#include <strings.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_cursor_shape_v1.h>
|
||||
#include <wlr/types/wlr_idle.h>
|
||||
#include <wlr/types/wlr_pointer.h>
|
||||
#include <wlr/types/wlr_touch.h>
|
||||
|
@ -1467,3 +1468,26 @@ void sway_cursor_constrain(struct sway_cursor *cursor,
|
|||
wl_signal_add(&constraint->surface->events.commit,
|
||||
&cursor->constraint_commit);
|
||||
}
|
||||
|
||||
void handle_request_set_cursor_shape(struct wl_listener *listener, void *data) {
|
||||
const struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data;
|
||||
struct sway_seat *seat = event->seat_client->seat->data;
|
||||
|
||||
if (!seatop_allows_set_cursor(seat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wl_client *focused_client = NULL;
|
||||
struct wlr_surface *focused_surface = seat->wlr_seat->pointer_state.focused_surface;
|
||||
if (focused_surface != NULL) {
|
||||
focused_client = wl_resource_get_client(focused_surface->resource);
|
||||
}
|
||||
|
||||
// TODO: check cursor mode
|
||||
if (focused_client == NULL || event->seat_client->client != focused_client) {
|
||||
sway_log(SWAY_DEBUG, "denying request to set cursor from unfocused client");
|
||||
return;
|
||||
}
|
||||
|
||||
cursor_set_image(seat->cursor, wlr_cursor_shape_v1_name(event->shape), focused_client);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_content_type_v1.h>
|
||||
#include <wlr/types/wlr_cursor_shape_v1.h>
|
||||
#include <wlr/types/wlr_data_control_v1.h>
|
||||
#include <wlr/types/wlr_drm.h>
|
||||
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
||||
|
@ -44,6 +45,7 @@
|
|||
#include "sway/input/input-manager.h"
|
||||
#include "sway/output.h"
|
||||
#include "sway/server.h"
|
||||
#include "sway/input/cursor.h"
|
||||
#include "sway/tree/root.h"
|
||||
|
||||
#if HAVE_XWAYLAND
|
||||
|
@ -235,6 +237,11 @@ bool server_init(struct sway_server *server) {
|
|||
wl_signal_add(&server->xdg_activation_v1->events.new_token,
|
||||
&server->xdg_activation_v1_new_token);
|
||||
|
||||
struct wlr_cursor_shape_manager_v1 *cursor_shape_manager =
|
||||
wlr_cursor_shape_manager_v1_create(server->wl_display, 1);
|
||||
server->request_set_cursor_shape.notify = handle_request_set_cursor_shape;
|
||||
wl_signal_add(&cursor_shape_manager->events.request_set_shape, &server->request_set_cursor_shape);
|
||||
|
||||
wl_list_init(&server->pending_launcher_ctxs);
|
||||
|
||||
// Avoid using "wayland-0" as display socket
|
||||
|
|
Loading…
Reference in a new issue