2017-11-12 10:10:56 +00:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
|
|
|
|
|
|
|
struct wlr_xcursor_manager *wlr_xcursor_manager_create(const char *name,
|
|
|
|
uint32_t size) {
|
|
|
|
struct wlr_xcursor_manager *manager =
|
|
|
|
calloc(1, sizeof(struct wlr_xcursor_manager));
|
|
|
|
if (manager == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (name != NULL) {
|
|
|
|
manager->name = strdup(name);
|
|
|
|
}
|
|
|
|
manager->size = size;
|
|
|
|
wl_list_init(&manager->scaled_themes);
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_xcursor_manager_destroy(struct wlr_xcursor_manager *manager) {
|
|
|
|
if (manager == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_xcursor_manager_theme *theme, *tmp;
|
|
|
|
wl_list_for_each_safe(theme, tmp, &manager->scaled_themes, link) {
|
|
|
|
wl_list_remove(&theme->link);
|
|
|
|
wlr_xcursor_theme_destroy(theme->theme);
|
|
|
|
free(theme);
|
|
|
|
}
|
|
|
|
free(manager->name);
|
|
|
|
free(manager);
|
|
|
|
}
|
|
|
|
|
2020-05-14 15:45:42 +00:00
|
|
|
bool wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
|
2017-12-15 00:00:03 +00:00
|
|
|
float scale) {
|
2017-11-12 10:10:56 +00:00
|
|
|
struct wlr_xcursor_manager_theme *theme;
|
|
|
|
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
|
|
|
if (theme->scale == scale) {
|
2020-05-14 15:45:42 +00:00
|
|
|
return true;
|
2017-11-12 10:10:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
theme = calloc(1, sizeof(struct wlr_xcursor_manager_theme));
|
|
|
|
if (theme == NULL) {
|
2020-05-14 15:45:42 +00:00
|
|
|
return false;
|
2017-11-12 10:10:56 +00:00
|
|
|
}
|
|
|
|
theme->scale = scale;
|
2017-11-18 08:47:53 +00:00
|
|
|
theme->theme = wlr_xcursor_theme_load(manager->name, manager->size * scale);
|
2017-11-12 10:10:56 +00:00
|
|
|
if (theme->theme == NULL) {
|
|
|
|
free(theme);
|
2020-05-14 15:45:42 +00:00
|
|
|
return false;
|
2017-11-12 10:10:56 +00:00
|
|
|
}
|
|
|
|
wl_list_insert(&manager->scaled_themes, &theme->link);
|
2020-05-14 15:45:42 +00:00
|
|
|
return true;
|
2017-11-12 10:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xcursor *wlr_xcursor_manager_get_xcursor(
|
2017-12-15 00:00:03 +00:00
|
|
|
struct wlr_xcursor_manager *manager, const char *name, float scale) {
|
2017-11-12 10:10:56 +00:00
|
|
|
struct wlr_xcursor_manager_theme *theme;
|
|
|
|
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
|
|
|
if (theme->scale == scale) {
|
|
|
|
return wlr_xcursor_theme_get_cursor(theme->theme, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager,
|
|
|
|
const char *name, struct wlr_cursor *cursor) {
|
|
|
|
struct wlr_xcursor_manager_theme *theme;
|
|
|
|
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
|
|
|
struct wlr_xcursor *xcursor =
|
|
|
|
wlr_xcursor_theme_get_cursor(theme->theme, name);
|
|
|
|
if (xcursor == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
2018-03-24 22:30:28 +00:00
|
|
|
wlr_cursor_set_image(cursor, image->buffer, image->width * 4,
|
2017-11-12 10:10:56 +00:00
|
|
|
image->width, image->height, image->hotspot_x, image->hotspot_y,
|
|
|
|
theme->scale);
|
|
|
|
}
|
|
|
|
}
|