aboutsummaryrefslogtreecommitdiffstats
path: root/cursor/wayland-cursor.c
diff options
context:
space:
mode:
authorPhilipp Brüschweiler <blei42@gmail.com>2012-09-06 18:54:01 +0200
committerKristian Høgsberg <krh@bitplanet.net>2012-09-10 21:04:55 -0400
commit9ce9336c5704510a3f5a57ef377870764217f2ec (patch)
tree5b38a0021e15f3ce8aeed482c543566c188958b9 /cursor/wayland-cursor.c
parenttests: Quiet warning (diff)
downloadwayland-9ce9336c5704510a3f5a57ef377870764217f2ec.tar
wayland-9ce9336c5704510a3f5a57ef377870764217f2ec.tar.gz
wayland-9ce9336c5704510a3f5a57ef377870764217f2ec.tar.bz2
wayland-9ce9336c5704510a3f5a57ef377870764217f2ec.tar.lz
wayland-9ce9336c5704510a3f5a57ef377870764217f2ec.tar.xz
wayland-9ce9336c5704510a3f5a57ef377870764217f2ec.tar.zst
wayland-9ce9336c5704510a3f5a57ef377870764217f2ec.zip
cursor: Add a default cursor theme
This theme is loaded when the specified cursor theme can not be found. These cursors are extracted from the xorg sources and transformed into raw ARGB data by a small helper program (commited separately).
Diffstat (limited to 'cursor/wayland-cursor.c')
-rw-r--r--cursor/wayland-cursor.c71
1 files changed, 70 insertions, 1 deletions
diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c
index 186ab6f..33fed04 100644
--- a/cursor/wayland-cursor.c
+++ b/cursor/wayland-cursor.c
@@ -181,6 +181,71 @@ wl_cursor_destroy(struct wl_cursor *cursor)
free(cursor);
}
+#include "cursor_data.c"
+
+static struct wl_cursor *
+wl_cursor_create_from_data(struct cursor_metadata *metadata,
+ struct wl_cursor_theme *theme)
+{
+ struct cursor *cursor;
+ struct cursor_image *image;
+ int size;
+
+ cursor = malloc(sizeof *cursor);
+ if (!cursor)
+ return NULL;
+
+ cursor->cursor.image_count = 1;
+ cursor->cursor.images = malloc(sizeof *cursor->cursor.images);
+ if (!cursor->cursor.images) {
+ free(cursor);
+ return NULL;
+ }
+
+ cursor->cursor.name = strdup(metadata->name);
+ cursor->total_delay = 0;
+
+ image = malloc(sizeof *image);
+ if (!image) {
+ free(cursor->cursor.name);
+ free(cursor->cursor.images);
+ free(cursor);
+ return NULL;
+ }
+
+ cursor->cursor.images[0] = (struct wl_cursor_image *) image;
+ image->theme = theme;
+ image->buffer = NULL;
+ image->image.width = metadata->width;
+ image->image.height = metadata->height;
+ image->image.hotspot_x = metadata->hotspot_x;
+ image->image.hotspot_y = metadata->hotspot_y;
+ image->image.delay = 0;
+
+ size = metadata->width * metadata->height * sizeof(uint32_t);
+ image->offset = shm_pool_allocate(theme->pool, size);
+ memcpy(theme->pool->data + image->offset,
+ cursor_data + metadata->offset, size);
+
+ return &cursor->cursor;
+}
+
+static void
+load_default_theme(struct wl_cursor_theme *theme)
+{
+ uint32_t i;
+
+ free(theme->name);
+ theme->name = strdup("default");
+
+ theme->cursor_count = ARRAY_LENGTH(cursor_metadata);;
+ theme->cursors = malloc(theme->cursor_count * sizeof(*theme->cursors));
+
+ for (i = 0; i < theme->cursor_count; ++i)
+ theme->cursors[i] =
+ wl_cursor_create_from_data(&cursor_metadata[i], theme);
+}
+
static struct wl_cursor *
wl_cursor_create_from_xcursor_images(XcursorImages *images,
struct wl_cursor_theme *theme)
@@ -261,7 +326,8 @@ load_callback(XcursorImages *images, void *data)
* \param shm The compositor's shm interface.
*
* \return An object representing the theme that should be destroyed with
- * wl_cursor_theme_destroy() or %NULL on error.
+ * wl_cursor_theme_destroy() or %NULL on error. If no theme with the given
+ * name exists, a default theme will be loaded.
*/
WL_EXPORT struct wl_cursor_theme *
wl_cursor_theme_load(const char *name, int size, struct wl_shm *shm)
@@ -290,6 +356,9 @@ wl_cursor_theme_load(const char *name, int size, struct wl_shm *shm)
xcursor_load_theme(name, size, load_callback, theme);
+ if (theme->cursor_count == 0)
+ load_default_theme(theme);
+
return theme;
}