aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-11-12 17:10:11 -0500
committerGitHub <noreply@github.com>2017-11-12 17:10:11 -0500
commit855c117efdab06bd232a3f0d6e81d7288a0551ed (patch)
treead2aa347b862cc7446a1cc80f5932847e1491fbe /rootston
parenta317ecdab8ef8deb184b72db208794daa4c4a3a0 (diff)
parentf8b43940b1a14e78c5365c9c1d17bfc79f523530 (diff)
Merge pull request #412 from emersion/cursor-scale
Scale cursors on scaled outputs
Diffstat (limited to 'rootston')
-rw-r--r--rootston/cursor.c11
-rw-r--r--rootston/desktop.c24
-rw-r--r--rootston/output.c7
-rw-r--r--rootston/seat.c73
-rw-r--r--rootston/xcursor.c24
5 files changed, 60 insertions, 79 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index cba9e782..ecd5e9a0 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -6,6 +6,7 @@
#elif __FreeBSD__
#include <dev/evdev/input-event-codes.h>
#endif
+#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h>
#include "rootston/xcursor.h"
#include "rootston/cursor.h"
@@ -27,12 +28,6 @@ void roots_cursor_destroy(struct roots_cursor *cursor) {
// 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) {
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
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;
}
if (set_compositor_cursor) {
- struct wlr_xcursor *xcursor = get_default_xcursor(cursor->xcursor_theme);
- cursor_set_xcursor_image(cursor, xcursor->images[0]);
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ ROOTS_XCURSOR_DEFAULT, cursor->cursor);
cursor->cursor_client = NULL;
}
if (view) {
diff --git a/rootston/desktop.c b/rootston/desktop.c
index ef7c9492..1695d007 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -10,11 +10,13 @@
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_output_layout.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/util/log.h>
#include <server-decoration-protocol.h>
#include "rootston/server.h"
#include "rootston/seat.h"
+#include "rootston/xcursor.h"
// TODO replace me with a signal
void view_destroy(struct roots_view *view) {
@@ -335,6 +337,16 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->server = server;
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->compositor = wlr_compositor_create(server->wl_display,
server->renderer);
@@ -356,6 +368,18 @@ struct roots_desktop *desktop_create(struct roots_server *server,
wl_signal_add(&desktop->xwayland->events.new_surface,
&desktop->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
diff --git a/rootston/output.c b/rootston/output.c
index 4b7a4b00..145016b3 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -5,6 +5,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.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/render/matrix.h>
#include <wlr/util/log.h>
@@ -248,6 +249,12 @@ void output_add_notify(struct wl_listener *listener, void *data) {
struct roots_seat *seat;
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_xcursor(seat);
}
diff --git a/rootston/seat.c b/rootston/seat.c
index 1e4d2a23..6d8dc749 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <wayland-server.h>
+#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h>
#include "rootston/xcursor.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;
wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout);
- seat->cursor->xcursor_theme = wlr_xcursor_theme_load("default", 16);
- if (seat->cursor->xcursor_theme == NULL) {
- 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);
- }
+ // TODO: be able to configure per-seat cursor themes
+ seat->cursor->xcursor_manager = desktop->xcursor_manager;
wl_list_init(&seat->cursor->touch_points);
roots_seat_configure_cursor(seat);
+ roots_seat_configure_xcursor(seat);
// add input signals
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) {
- struct wlr_xcursor *xcursor = get_default_xcursor(seat->cursor->xcursor_theme);
- 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);
+ struct roots_output *output;
+ wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
+ if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
+ 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,
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);
}
-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) {
struct roots_cursor *cursor = seat->cursor;
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);
wlr_seat_pointer_clear_focus(seat->seat);
- struct wlr_xcursor *xcursor = get_move_xcursor(seat->cursor->xcursor_theme);
- if (xcursor != NULL) {
- struct wlr_xcursor_image *image = xcursor->images[0];
- seat_set_xcursor_image(seat, image);
- }
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ ROOTS_XCURSOR_MOVE, seat->cursor->cursor);
}
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);
wlr_seat_pointer_clear_focus(seat->seat);
- struct wlr_xcursor *xcursor = get_resize_xcursor(cursor->xcursor_theme, edges);
- if (xcursor != NULL) {
- seat_set_xcursor_image(seat, xcursor->images[0]);
- }
-
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ roots_xcursor_get_resize_name(edges), seat->cursor->cursor);
}
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);
wlr_seat_pointer_clear_focus(seat->seat);
- struct wlr_xcursor *xcursor = get_rotate_xcursor(cursor->xcursor_theme);
- if (xcursor != NULL) {
- seat_set_xcursor_image(seat, xcursor->images[0]);
- }
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ ROOTS_XCURSOR_ROTATE, seat->cursor->cursor);
}
diff --git a/rootston/xcursor.c b/rootston/xcursor.c
index 8697cdc3..74e732c9 100644
--- a/rootston/xcursor.c
+++ b/rootston/xcursor.c
@@ -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"
-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_RIGHT) {
return "ne-resize";
@@ -23,20 +26,3 @@ static const char *get_resize_xcursor_name(uint32_t edges) {
}
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");
-}