parent
2dccb11741
commit
8605243459
@ -1,44 +1,14 @@
|
||||
#ifndef _ROOTSTON_XCURSOR_H
|
||||
#define _ROOTSTON_XCURSOR_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/xcursor.h>
|
||||
#include <wlr/xwayland.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define ROOTS_XCURSOR_SIZE 16
|
||||
|
||||
struct roots_xcursor_scaled_theme {
|
||||
uint32_t scale;
|
||||
struct wlr_xcursor_theme *theme;
|
||||
struct wl_list link;
|
||||
};
|
||||
#define ROOTS_XCURSOR_DEFAULT "left_ptr"
|
||||
#define ROOTS_XCURSOR_MOVE "grabbing"
|
||||
#define ROOTS_XCURSOR_ROTATE "grabbing"
|
||||
|
||||
struct roots_xcursor_theme {
|
||||
char *name;
|
||||
struct wl_list scaled_themes; // roots_xcursor_scaled_theme::link
|
||||
};
|
||||
|
||||
struct roots_xcursor_theme *roots_xcursor_theme_create(const char *name);
|
||||
|
||||
void roots_xcursor_theme_destroy(struct roots_xcursor_theme *theme);
|
||||
|
||||
int roots_xcursor_theme_load(struct roots_xcursor_theme *theme,
|
||||
uint32_t scale);
|
||||
|
||||
void roots_xcursor_theme_set_default(struct roots_xcursor_theme *theme,
|
||||
struct wlr_cursor *cursor);
|
||||
|
||||
void roots_xcursor_theme_set_move(struct roots_xcursor_theme *theme,
|
||||
struct wlr_cursor *cursor);
|
||||
|
||||
void roots_xcursor_theme_set_resize(struct roots_xcursor_theme *theme,
|
||||
struct wlr_cursor *cursor, uint32_t edges);
|
||||
|
||||
void roots_xcursor_theme_set_rotate(struct roots_xcursor_theme *theme,
|
||||
struct wlr_cursor *cursor);
|
||||
|
||||
void roots_xcursor_theme_xwayland_set_default(struct roots_xcursor_theme *theme,
|
||||
struct wlr_xwayland *xwayland);
|
||||
const char *roots_xcursor_get_resize_name(uint32_t edges);
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,53 @@
|
||||
#ifndef WLR_TYPES_WLR_XCURSOR_MANAGER_H
|
||||
#define WLR_TYPES_WLR_XCURSOR_MANAGER_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/xcursor.h>
|
||||
|
||||
/**
|
||||
* A scaled XCursor theme.
|
||||
*/
|
||||
struct wlr_xcursor_manager_theme {
|
||||
uint32_t scale;
|
||||
struct wlr_xcursor_theme *theme;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manage multiple XCursor themes with different scales and set `wlr_cursor`
|
||||
* images.
|
||||
*
|
||||
* This manager can be used to display cursor images on multiple outputs having
|
||||
* different scale factors.
|
||||
*/
|
||||
struct wlr_xcursor_manager {
|
||||
char *name;
|
||||
uint32_t size;
|
||||
struct wl_list scaled_themes; // wlr_xcursor_manager_theme::link
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new XCursor manager. After initialization, scaled themes need to be
|
||||
* loaded with `wlr_xcursor_manager_load`. `size` is the unscaled cursor theme
|
||||
* size.
|
||||
*/
|
||||
struct wlr_xcursor_manager *wlr_xcursor_manager_create(const char *name,
|
||||
uint32_t size);
|
||||
|
||||
void wlr_xcursor_manager_destroy(struct wlr_xcursor_manager *manager);
|
||||
|
||||
int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
|
||||
uint32_t scale);
|
||||
|
||||
struct wlr_xcursor *wlr_xcursor_manager_get_xcursor(
|
||||
struct wlr_xcursor_manager *manager, const char *name, uint32_t scale);
|
||||
|
||||
/**
|
||||
* Set a `wlr_cursor` image. The manager uses all currently loaded scaled
|
||||
* themes.
|
||||
*/
|
||||
void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager,
|
||||
const char *name, struct wlr_cursor *cursor);
|
||||
|
||||
#endif
|
@ -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…
Reference in new issue