get wl_cursor from default cursor theme.
name: "left_ptr"
image_count: 1
image[0]->width: 10, height: 16, hotspot_x: 1, hotspot_y: 1
Change-Id: I7438282d007647aeab3fd9bcb0c5eaf5dc5f155b
static void wl_backend_server_finish(struct ds_wl_backend_server *server);
static int wl_backend_handle_dispatch_events(int fd, uint32_t mask,
void *data);
+static void create_cursor(struct ds_wl_backend *wl_backend);
WL_EXPORT struct ds_backend *
ds_wl_backend_create(struct wl_display *display, const char *server_name)
goto err_bind;
}
+ create_cursor(wl_backend);
+
return true;
err_bind:
static void
wl_backend_server_finish(struct ds_wl_backend_server *server)
{
+ wl_cursor_theme_destroy(server->backend->cursor_theme);
xdg_wm_base_destroy(server->xdg_wm_base);
wl_compositor_destroy(server->compositor);
wl_registry_destroy(server->registry);
return count;
}
+
+static void
+create_cursor(struct ds_wl_backend *wl_backend)
+{
+ struct ds_wl_backend_server *server = &wl_backend->server;
+
+ wl_backend->cursor_theme = wl_cursor_theme_load(NULL, 32, server->shm);
+ if (!wl_backend->cursor_theme) {
+ ds_err("Failed to load cursor theme");
+ return;
+ }
+
+ wl_backend->cursor = wl_cursor_theme_get_cursor(wl_backend->cursor_theme, "left_ptr");
+ if (!wl_backend->cursor) {
+ ds_err("Failed to create default cursor (name: left_ptr)\n");
+ return;
+ }
+ ds_inf("Succeeded to create default cursor (name: left_ptr)\n");
+}
\ No newline at end of file
#include "libds/interfaces/keyboard.h"
#include "libds/interfaces/touch.h"
+#include <wayland-cursor.h>
+
struct ds_wl_backend_server
{
struct ds_wl_backend *backend;
struct ds_wl_backend_server server;
size_t requested_outputs;
+
+ struct wl_cursor_theme *cursor_theme;
+ struct wl_cursor *cursor;
};
struct ds_wl_buffer
libds_deps += [
dependency('wayland-client', required: true),
+ dependency('wayland-cursor', required: true),
]
wl_signal_emit(&backend->base.events.new_output, &output->base);
- ds_dbg("Wayland output(%p) created", output);
+ output->cursor.surface = wl_compositor_create_surface(backend->server.compositor);
+ if (!output->cursor.surface)
+ ds_log_errno(DS_ERR, "Could not create cursor surface");
+
+ ds_inf("Wayland output(%p) created", output);
return output;
static void output_update_cursor(struct ds_wl_output *output)
{
struct ds_wl_pointer *pointer = output->cursor.pointer;
+ struct wl_buffer *buffer;
+ struct wl_cursor_image *image;
+
+ if (!output->backend->cursor)
+ return;
+
+ image = output->backend->cursor->images[0];
+ buffer = wl_cursor_image_get_buffer(image);
+ if (!buffer)
+ return;
+
+ output->cursor.hotspot_x = image->hotspot_x;
+ output->cursor.hotspot_y = image->hotspot_y;
wl_pointer_set_cursor(pointer->wl_pointer, output->cursor.enter_serial,
output->cursor.surface, output->cursor.hotspot_x,
output->cursor.hotspot_y);
+ wl_surface_attach(output->cursor.surface, buffer, 0, 0);
+ wl_surface_damage(output->cursor.surface, 0, 0, image->width, image->height);
+ wl_surface_commit(output->cursor.surface);
}
static struct ds_wl_output *
if (output->surface)
wl_surface_destroy(output->surface);
+ if (output->cursor.surface)
+ wl_surface_destroy(output->cursor.surface);
+
wl_display_flush(output->backend->server.display);
free(output);
uint32_t callback_data)
{
struct ds_wl_seat *seat = data;
+ struct ds_wl_backend_server *server;
wl_callback_destroy(seat->initial_info_cb);
seat->initial_info_cb = NULL;