diff options
Diffstat (limited to 'wayland/client.c')
-rw-r--r-- | wayland/client.c | 43 |
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 | ||
48 | static 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 | |||
55 | static void pointer_handle_leave(void *data, struct wl_pointer *pointer, | ||
56 | uint32_t serial, struct wl_surface *surface) { | ||
57 | } | ||
58 | |||
59 | static 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 | |||
63 | static 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 | |||
67 | static void pointer_handle_axis(void *data, struct wl_pointer *pointer, | ||
68 | uint32_t time, uint32_t axis, wl_fixed_t value) { | ||
69 | } | ||
70 | |||
71 | static 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 | |||
47 | static void registry_global(void *data, struct wl_registry *registry, | 79 | static 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 | ||