Merge pull request #412 from emersion/cursor-scale

Scale cursors on scaled outputs
This commit is contained in:
Drew DeVault 2017-11-12 17:10:11 -05:00 committed by GitHub
commit 855c117efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 233 additions and 96 deletions

View file

@ -86,7 +86,7 @@ static void handle_output_add(struct output_state *ostate) {
struct wlr_xcursor_image *image = sample->xcursor->images[0]; struct wlr_xcursor_image *image = sample->xcursor->images[0];
wlr_cursor_set_image(cursor->cursor, image->buffer, image->width, wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y); image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
wlr_cursor_warp(cursor->cursor, NULL, cursor->cursor->x, wlr_cursor_warp(cursor->cursor, NULL, cursor->cursor->x,
cursor->cursor->y); cursor->cursor->y);
@ -150,7 +150,7 @@ static void handle_input_add(struct compositor_state *state,
struct wlr_xcursor_image *image = sample->xcursor->images[0]; struct wlr_xcursor_image *image = sample->xcursor->images[0];
wlr_cursor_set_image(cursor->cursor, image->buffer, image->width, wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y); image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
wl_list_insert(&sample->cursors, &cursor->link); wl_list_insert(&sample->cursors, &cursor->link);
} }

View file

@ -110,7 +110,7 @@ static void handle_output_add(struct output_state *ostate) {
struct wlr_xcursor_image *image = sample->xcursor->images[0]; struct wlr_xcursor_image *image = sample->xcursor->images[0];
wlr_cursor_set_image(sample->cursor, image->buffer, image->width, wlr_cursor_set_image(sample->cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y); image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y); wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y);
} }
@ -321,7 +321,7 @@ int main(int argc, char *argv[]) {
struct wlr_xcursor_image *image = state.xcursor->images[0]; struct wlr_xcursor_image *image = state.xcursor->images[0];
wlr_cursor_set_image(state.cursor, image->buffer, image->width, wlr_cursor_set_image(state.cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y); image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
compositor_init(&compositor); compositor_init(&compositor);
if (!wlr_backend_start(compositor.backend)) { if (!wlr_backend_start(compositor.backend)) {

View file

@ -30,7 +30,7 @@ struct roots_cursor {
enum roots_cursor_mode mode; enum roots_cursor_mode mode;
// state from input (review if this is necessary) // state from input (review if this is necessary)
struct wlr_xcursor_theme *xcursor_theme; struct wlr_xcursor_manager *xcursor_manager;
struct wlr_seat *wl_seat; struct wlr_seat *wl_seat;
struct wl_client *cursor_client; struct wl_client *cursor_client;
int offs_x, offs_y; int offs_x, offs_y;

View file

@ -7,6 +7,7 @@
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_screenshooter.h> #include <wlr/types/wlr_screenshooter.h>
#include <wlr/types/wlr_list.h> #include <wlr/types/wlr_list.h>
@ -31,6 +32,7 @@ struct roots_desktop {
struct roots_config *config; struct roots_config *config;
struct wlr_output_layout *layout; struct wlr_output_layout *layout;
struct wlr_xcursor_manager *xcursor_manager;
struct wlr_compositor *compositor; struct wlr_compositor *compositor;
struct wlr_wl_shell *wl_shell; struct wlr_wl_shell *wl_shell;

View file

@ -1,15 +1,14 @@
#ifndef _ROOTSTON_XCURSOR_H #ifndef _ROOTSTON_XCURSOR_H
#define _ROOTSTON_XCURSOR_H #define _ROOTSTON_XCURSOR_H
#include <wlr/xcursor.h> #include <stdint.h>
struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme); #define ROOTS_XCURSOR_SIZE 16
struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme); #define ROOTS_XCURSOR_DEFAULT "left_ptr"
#define ROOTS_XCURSOR_MOVE "grabbing"
#define ROOTS_XCURSOR_ROTATE "grabbing"
struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme, const char *roots_xcursor_get_resize_name(uint32_t edges);
uint32_t edges);
struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme);
#endif #endif

View file

@ -6,7 +6,6 @@
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_box.h> #include <wlr/types/wlr_box.h>
#include <wlr/xcursor.h>
struct wlr_cursor_state; struct wlr_cursor_state;
@ -60,9 +59,22 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev, void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
double delta_x, double delta_y); double delta_x, double delta_y);
/**
* Set the cursor image. stride is given in bytes. If pixels is NULL, hides the
* cursor.
*
* If scale isn't zero, the image is only set on outputs having the provided
* scale.
*/
void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels, void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels,
int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x,
int32_t hotspot_y); int32_t hotspot_y, uint32_t scale);
/**
* Set the cursor surface. The surface can be committed to update the cursor
* image. The surface position is substracted from the hotspot. A NULL surface
* commit hides the cursor.
*/
void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface, void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface,
int32_t hotspot_x, int32_t hotspot_y); int32_t hotspot_x, int32_t hotspot_y);

View file

@ -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

View file

@ -61,7 +61,7 @@ struct wlr_xcursor_theme *wlr_xcursor_theme_load(const char *name, int size);
void wlr_xcursor_theme_destroy(struct wlr_xcursor_theme *theme); void wlr_xcursor_theme_destroy(struct wlr_xcursor_theme *theme);
struct wlr_xcursor *wlr_xcursor_theme_get_cursor( struct wlr_xcursor *wlr_xcursor_theme_get_cursor(
struct wlr_xcursor_theme *theme, const char *name); struct wlr_xcursor_theme *theme, const char *name);
int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time); int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time);

View file

@ -6,6 +6,7 @@
#elif __FreeBSD__ #elif __FreeBSD__
#include <dev/evdev/input-event-codes.h> #include <dev/evdev/input-event-codes.h>
#endif #endif
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "rootston/xcursor.h" #include "rootston/xcursor.h"
#include "rootston/cursor.h" #include "rootston/cursor.h"
@ -27,12 +28,6 @@ void roots_cursor_destroy(struct roots_cursor *cursor) {
// TODO // TODO
} }
static void cursor_set_xcursor_image(struct roots_cursor *cursor,
struct wlr_xcursor_image *image) {
wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y);
}
static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) { static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) {
struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct roots_desktop *desktop = cursor->seat->input->server->desktop;
struct roots_seat *seat = cursor->seat; struct roots_seat *seat = cursor->seat;
@ -50,8 +45,8 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t
set_compositor_cursor = view_client != cursor->cursor_client; set_compositor_cursor = view_client != cursor->cursor_client;
} }
if (set_compositor_cursor) { if (set_compositor_cursor) {
struct wlr_xcursor *xcursor = get_default_xcursor(cursor->xcursor_theme); wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
cursor_set_xcursor_image(cursor, xcursor->images[0]); ROOTS_XCURSOR_DEFAULT, cursor->cursor);
cursor->cursor_client = NULL; cursor->cursor_client = NULL;
} }
if (view) { if (view) {

View file

@ -10,11 +10,13 @@
#include <wlr/types/wlr_server_decoration.h> #include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <server-decoration-protocol.h> #include <server-decoration-protocol.h>
#include "rootston/server.h" #include "rootston/server.h"
#include "rootston/seat.h" #include "rootston/seat.h"
#include "rootston/xcursor.h"
// TODO replace me with a signal // TODO replace me with a signal
void view_destroy(struct roots_view *view) { void view_destroy(struct roots_view *view) {
@ -335,6 +337,16 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->server = server; desktop->server = server;
desktop->config = config; desktop->config = config;
desktop->xcursor_manager = wlr_xcursor_manager_create(NULL,
ROOTS_XCURSOR_SIZE);
if (desktop->xcursor_manager == NULL) {
wlr_log(L_ERROR, "Cannot create XCursor manager");
wlr_list_free(desktop->views);
free(desktop);
return NULL;
}
desktop->layout = wlr_output_layout_create(); desktop->layout = wlr_output_layout_create();
desktop->compositor = wlr_compositor_create(server->wl_display, desktop->compositor = wlr_compositor_create(server->wl_display,
server->renderer); server->renderer);
@ -356,6 +368,18 @@ struct roots_desktop *desktop_create(struct roots_server *server,
wl_signal_add(&desktop->xwayland->events.new_surface, wl_signal_add(&desktop->xwayland->events.new_surface,
&desktop->xwayland_surface); &desktop->xwayland_surface);
desktop->xwayland_surface.notify = handle_xwayland_surface; desktop->xwayland_surface.notify = handle_xwayland_surface;
if (wlr_xcursor_manager_load(desktop->xcursor_manager, 1)) {
wlr_log(L_ERROR, "Cannot load XWayland XCursor theme");
}
struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(
desktop->xcursor_manager, ROOTS_XCURSOR_DEFAULT, 1);
if (xcursor != NULL) {
struct wlr_xcursor_image *image = xcursor->images[0];
wlr_xwayland_set_cursor(desktop->xwayland, image->buffer,
image->width, image->width, image->height, image->hotspot_x,
image->hotspot_y);
}
} }
#endif #endif

View file

@ -5,6 +5,7 @@
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
@ -248,6 +249,12 @@ void output_add_notify(struct wl_listener *listener, void *data) {
struct roots_seat *seat; struct roots_seat *seat;
wl_list_for_each(seat, &input->seats, link) { wl_list_for_each(seat, &input->seats, link) {
if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
wlr_output->scale)) {
wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' "
"with scale %d", wlr_output->name, wlr_output->scale);
}
roots_seat_configure_cursor(seat); roots_seat_configure_cursor(seat);
roots_seat_configure_xcursor(seat); roots_seat_configure_xcursor(seat);
} }

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "rootston/xcursor.h" #include "rootston/xcursor.h"
#include "rootston/input.h" #include "rootston/input.h"
@ -184,38 +185,13 @@ static void roots_seat_init_cursor(struct roots_seat *seat) {
struct roots_desktop *desktop = seat->input->server->desktop; struct roots_desktop *desktop = seat->input->server->desktop;
wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout); wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout);
seat->cursor->xcursor_theme = wlr_xcursor_theme_load("default", 16); // TODO: be able to configure per-seat cursor themes
if (seat->cursor->xcursor_theme == NULL) { seat->cursor->xcursor_manager = desktop->xcursor_manager;
wlr_log(L_ERROR, "Cannot load xcursor theme");
roots_cursor_destroy(seat->cursor);
seat->cursor = NULL;
return;
}
struct wlr_xcursor *xcursor = get_default_xcursor(seat->cursor->xcursor_theme);
if (xcursor == NULL) {
wlr_log(L_ERROR, "Cannot load xcursor from theme");
wlr_xcursor_theme_destroy(seat->cursor->xcursor_theme);
roots_cursor_destroy(seat->cursor);
seat->cursor = NULL;
return;
}
struct wlr_xcursor_image *image = xcursor->images[0];
wlr_cursor_set_image(seat->cursor->cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y);
// XXX: xwayland will always have the theme of the last created seat
if (seat->input->server->desktop->xwayland != NULL) {
wlr_xwayland_set_cursor(seat->input->server->desktop->xwayland,
image->buffer, image->width, image->width,
image->height, image->hotspot_x,
image->hotspot_y);
}
wl_list_init(&seat->cursor->touch_points); wl_list_init(&seat->cursor->touch_points);
roots_seat_configure_cursor(seat); roots_seat_configure_cursor(seat);
roots_seat_configure_xcursor(seat);
// add input signals // add input signals
wl_signal_add(&wlr_cursor->events.motion, &seat->cursor->motion); wl_signal_add(&wlr_cursor->events.motion, &seat->cursor->motion);
@ -471,11 +447,18 @@ void roots_seat_remove_device(struct roots_seat *seat,
} }
void roots_seat_configure_xcursor(struct roots_seat *seat) { void roots_seat_configure_xcursor(struct roots_seat *seat) {
struct wlr_xcursor *xcursor = get_default_xcursor(seat->cursor->xcursor_theme); struct roots_output *output;
struct wlr_xcursor_image *image = xcursor->images[0]; wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
wlr_cursor_set_image(seat->cursor->cursor, image->buffer, image->width, if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
image->width, image->height, image->hotspot_x, image->hotspot_y); output->wlr_output->scale)) {
wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' "
"with scale %d", output->wlr_output->name,
output->wlr_output->scale);
}
}
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
ROOTS_XCURSOR_DEFAULT, seat->cursor->cursor);
wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,
seat->cursor->cursor->y); seat->cursor->cursor->y);
} }
@ -537,12 +520,6 @@ void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface); wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface);
} }
static void seat_set_xcursor_image(struct roots_seat *seat, struct
wlr_xcursor_image *image) {
wlr_cursor_set_image(seat->cursor->cursor, image->buffer, image->width,
image->width, image->height, image->hotspot_x, image->hotspot_y);
}
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
struct roots_cursor *cursor = seat->cursor; struct roots_cursor *cursor = seat->cursor;
cursor->mode = ROOTS_CURSOR_MOVE; cursor->mode = ROOTS_CURSOR_MOVE;
@ -558,11 +535,8 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
view_maximize(view, false); view_maximize(view, false);
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
struct wlr_xcursor *xcursor = get_move_xcursor(seat->cursor->xcursor_theme); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
if (xcursor != NULL) { ROOTS_XCURSOR_MOVE, seat->cursor->cursor);
struct wlr_xcursor_image *image = xcursor->images[0];
seat_set_xcursor_image(seat, image);
}
} }
void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
@ -588,11 +562,8 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
view_maximize(view, false); view_maximize(view, false);
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
struct wlr_xcursor *xcursor = get_resize_xcursor(cursor->xcursor_theme, edges); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
if (xcursor != NULL) { roots_xcursor_get_resize_name(edges), seat->cursor->cursor);
seat_set_xcursor_image(seat, xcursor->images[0]);
}
} }
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {
@ -604,8 +575,6 @@ void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {
view_maximize(view, false); view_maximize(view, false);
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
struct wlr_xcursor *xcursor = get_rotate_xcursor(cursor->xcursor_theme); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
if (xcursor != NULL) { ROOTS_XCURSOR_ROTATE, seat->cursor->cursor);
seat_set_xcursor_image(seat, xcursor->images[0]);
}
} }

View file

@ -1,7 +1,10 @@
#include <wlr/types/wlr_cursor.h> #define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <string.h>
#include "rootston/xcursor.h"
#include "rootston/input.h" #include "rootston/input.h"
static const char *get_resize_xcursor_name(uint32_t edges) { const char *roots_xcursor_get_resize_name(uint32_t edges) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "ne-resize"; return "ne-resize";
@ -23,20 +26,3 @@ static const char *get_resize_xcursor_name(uint32_t edges) {
} }
return "se-resize"; // fallback return "se-resize"; // fallback
} }
struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme) {
return wlr_xcursor_theme_get_cursor(theme, "left_ptr");
}
struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme) {
return wlr_xcursor_theme_get_cursor(theme, "grabbing");
}
struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme,
uint32_t edges) {
return wlr_xcursor_theme_get_cursor(theme, get_resize_xcursor_name(edges));
}
struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme) {
return wlr_xcursor_theme_get_cursor(theme, "grabbing");
}

View file

@ -20,8 +20,9 @@ lib_wlr_types = static_library(
'wlr_tablet_pad.c', 'wlr_tablet_pad.c',
'wlr_tablet_tool.c', 'wlr_tablet_tool.c',
'wlr_touch.c', 'wlr_touch.c',
'wlr_xdg_shell_v6.c',
'wlr_wl_shell.c', 'wlr_wl_shell.c',
'wlr_xcursor_manager.c',
'wlr_xdg_shell_v6.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [wayland_server, pixman, wlr_protos], dependencies: [wayland_server, pixman, wlr_protos],

View file

@ -299,9 +299,14 @@ void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels, void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels,
int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x,
int32_t hotspot_y) { int32_t hotspot_y, uint32_t scale) {
struct wlr_cursor_output_cursor *output_cursor; struct wlr_cursor_output_cursor *output_cursor;
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) { wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
if (scale != 0 &&
output_cursor->output_cursor->output->scale != scale) {
continue;
}
wlr_output_cursor_set_image(output_cursor->output_cursor, pixels, wlr_output_cursor_set_image(output_cursor->output_cursor, pixels,
stride, width, height, hotspot_x, hotspot_y); stride, width, height, hotspot_x, hotspot_y);
} }

View 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);
}
}