sway xcursor manager

This commit is contained in:
Tony Crisci 2017-12-09 11:51:28 -05:00
parent d76e745b73
commit 7c67bea942
3 changed files with 41 additions and 0 deletions

View file

@ -5,6 +5,7 @@
struct sway_cursor {
struct wlr_cursor *cursor;
struct wlr_xcursor_manager *xcursor_manager;
struct wl_listener motion;
struct wl_listener motion_absolute;

View file

@ -18,4 +18,6 @@ void sway_seat_add_device(struct sway_seat *seat,
void sway_seat_remove_device(struct sway_seat *seat,
struct wlr_input_device *device);
void sway_seat_configure_xcursor(struct sway_seat *seat);
#endif

View file

@ -1,8 +1,10 @@
#define _XOPEN_SOURCE 700
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include "sway/input/seat.h"
#include "sway/input/cursor.h"
#include "sway/input/input-manager.h"
#include "sway/output.h"
#include "log.h"
struct sway_seat *sway_seat_create(struct wl_display *display,
@ -29,6 +31,8 @@ struct sway_seat *sway_seat_create(struct wl_display *display,
WL_SEAT_CAPABILITY_POINTER |
WL_SEAT_CAPABILITY_TOUCH);
sway_seat_configure_xcursor(seat);
return seat;
}
@ -74,3 +78,37 @@ void sway_seat_remove_device(struct sway_seat *seat,
break;
}
}
void sway_seat_configure_xcursor(struct sway_seat *seat) {
// TODO configure theme and size
const char *cursor_theme = "default";
if (seat->cursor->xcursor_manager) {
wlr_xcursor_manager_destroy(seat->cursor->xcursor_manager);
}
seat->cursor->xcursor_manager =
wlr_xcursor_manager_create(NULL, 24);
if (sway_assert(seat->cursor->xcursor_manager,
"Cannot create XCursor manager for theme %s", cursor_theme)) {
return;
}
for (int i = 0; i < root_container.children->length; ++i) {
swayc_t *output_container = root_container.children->items[i];
struct wlr_output *output =
output_container->sway_output->wlr_output;
bool result =
wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
output->scale);
sway_assert(result,
"Cannot load xcursor theme for output '%s' with scale %d",
output->name, output->scale);
}
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
"left_ptr", seat->cursor->cursor);
wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,
seat->cursor->cursor->y);
}