summaryrefslogtreecommitdiffstats
path: root/wayland
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-18 19:38:42 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-18 19:38:42 -0500
commit7a40eb6de646ffd50aa7b5b60f3c05273c0a6951 (patch)
treeaa3cac15c63d8af7cbb9598163a1f41db5738241 /wayland
parentGenerate protocol headers (diff)
downloadsway-7a40eb6de646ffd50aa7b5b60f3c05273c0a6951.tar.gz
sway-7a40eb6de646ffd50aa7b5b60f3c05273c0a6951.tar.zst
sway-7a40eb6de646ffd50aa7b5b60f3c05273c0a6951.zip
Support cursors over wayland clients
Apparently wayland has fucking client-side cursors, too
Diffstat (limited to 'wayland')
-rw-r--r--wayland/client.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/wayland/client.c b/wayland/client.c
index 190d5ecb..be93709b 100644
--- a/wayland/client.c
+++ b/wayland/client.c
@@ -1,4 +1,5 @@
1#include <wayland-client.h> 1#include <wayland-client.h>
2#include <wayland-cursor.h>
2#include "wayland-xdg-shell-client-protocol.h" 3#include "wayland-xdg-shell-client-protocol.h"
3#include <cairo/cairo.h> 4#include <cairo/cairo.h>
4#include <pango/pangocairo.h> 5#include <pango/pangocairo.h>
@@ -44,6 +45,37 @@ static const struct wl_output_listener output_listener = {
44 .scale = display_handle_scale 45 .scale = display_handle_scale
45}; 46};
46 47
48static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
49 uint32_t serial, struct wl_surface *surface, wl_fixed_t sx_w, wl_fixed_t sy_w) {
50 struct client_state *state = data;
51 struct wl_cursor_image *image = state->cursor.cursor->images[0];
52 wl_pointer_set_cursor(pointer, serial, state->cursor.surface, image->hotspot_x, image->hotspot_y);
53}
54
55static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
56 uint32_t serial, struct wl_surface *surface) {
57}
58
59static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
60 uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) {
61}
62
63static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
64 uint32_t time, uint32_t button, uint32_t state_w) {
65}
66
67static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
68 uint32_t time, uint32_t axis, wl_fixed_t value) {
69}
70
71static const struct wl_pointer_listener pointer_listener = {
72 .enter = pointer_handle_enter,
73 .leave = pointer_handle_leave,
74 .motion = pointer_handle_motion,
75 .button = pointer_handle_button,
76 .axis = pointer_handle_axis
77};
78
47static void registry_global(void *data, struct wl_registry *registry, 79static void registry_global(void *data, struct wl_registry *registry,
48 uint32_t name, const char *interface, uint32_t version) { 80 uint32_t name, const char *interface, uint32_t version) {
49 struct client_state *state = data; 81 struct client_state *state = data;
@@ -57,6 +89,7 @@ static void registry_global(void *data, struct wl_registry *registry,
57 } else if (strcmp(interface, wl_seat_interface.name) == 0) { 89 } else if (strcmp(interface, wl_seat_interface.name) == 0) {
58 state->seat = wl_registry_bind(registry, name, &wl_seat_interface, version); 90 state->seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
59 state->pointer = wl_seat_get_pointer(state->seat); 91 state->pointer = wl_seat_get_pointer(state->seat);
92 wl_pointer_add_listener(state->pointer, &pointer_listener, state);
60 } else if (strcmp(interface, wl_output_interface.name) == 0) { 93 } else if (strcmp(interface, wl_output_interface.name) == 0) {
61 struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, version); 94 struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, version);
62 struct output_state *ostate = malloc(sizeof(struct output_state)); 95 struct output_state *ostate = malloc(sizeof(struct output_state));
@@ -111,6 +144,16 @@ struct client_state *client_setup(uint32_t width, uint32_t height) {
111 wl_shell_surface_add_listener(state->shell_surface, &surface_listener, state); 144 wl_shell_surface_add_listener(state->shell_surface, &surface_listener, state);
112 wl_shell_surface_set_toplevel(state->shell_surface); 145 wl_shell_surface_set_toplevel(state->shell_surface);
113 146
147 state->cursor.cursor_theme = wl_cursor_theme_load("default", 32, state->shm); // TODO: let you customize this
148 state->cursor.cursor = wl_cursor_theme_get_cursor(state->cursor.cursor_theme, "left_ptr");
149 state->cursor.surface = wl_compositor_create_surface(state->compositor);
150
151 struct wl_cursor_image *image = state->cursor.cursor->images[0];
152 struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
153 wl_surface_attach(state->cursor.surface, cursor_buf, 0, 0);
154 wl_surface_damage(state->cursor.surface, 0, 0, image->width, image->height);
155 wl_surface_commit(state->cursor.surface);
156
114 return state; 157 return state;
115} 158}
116 159