mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-27 06:59:46 -05:00
Introduce wlr_xcursor_manager
This commit is contained in:
parent
2dccb11741
commit
8605243459
13 changed files with 180 additions and 167 deletions
|
|
@ -20,8 +20,9 @@ lib_wlr_types = static_library(
|
|||
'wlr_tablet_pad.c',
|
||||
'wlr_tablet_tool.c',
|
||||
'wlr_touch.c',
|
||||
'wlr_xdg_shell_v6.c',
|
||||
'wlr_wl_shell.c',
|
||||
'wlr_xcursor_manager.c',
|
||||
'wlr_xdg_shell_v6.c',
|
||||
),
|
||||
include_directories: wlr_inc,
|
||||
dependencies: [wayland_server, pixman, wlr_protos],
|
||||
|
|
|
|||
84
types/wlr_xcursor_manager.c
Normal file
84
types/wlr_xcursor_manager.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
|
||||
uint32_t scale) {
|
||||
struct wlr_xcursor_manager_theme *theme;
|
||||
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
||||
if (theme->scale == scale) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
theme = calloc(1, sizeof(struct wlr_xcursor_manager_theme));
|
||||
if (theme == NULL) {
|
||||
return 1;
|
||||
}
|
||||
theme->scale = scale;
|
||||
theme->theme = wlr_xcursor_theme_load(NULL, manager->size * scale);
|
||||
if (theme->theme == NULL) {
|
||||
free(theme);
|
||||
return 1;
|
||||
}
|
||||
wl_list_insert(&manager->scaled_themes, &theme->link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct wlr_xcursor *wlr_xcursor_manager_get_xcursor(
|
||||
struct wlr_xcursor_manager *manager, const char *name, uint32_t scale) {
|
||||
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];
|
||||
wlr_cursor_set_image(cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y,
|
||||
theme->scale);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue