aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-19 18:22:56 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-25 13:31:56 +0100
commit3248c823ed1f3bc95b8401a32a2dc12144a88f7d (patch)
treee57f23bb5d371791e2b1b513f5246e7f3ddda3db /sway/input/cursor.c
parentImplement hide_cursor <timeout> command (diff)
downloadsway-3248c823ed1f3bc95b8401a32a2dc12144a88f7d.tar.gz
sway-3248c823ed1f3bc95b8401a32a2dc12144a88f7d.tar.zst
sway-3248c823ed1f3bc95b8401a32a2dc12144a88f7d.zip
Split image_surface handling into own function
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 53ff3a22..efc00754 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -603,7 +603,15 @@ static void handle_activity(struct sway_cursor *cursor) {
603 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 603 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
604 if (cursor->hidden) { 604 if (cursor->hidden) {
605 cursor->hidden = false; 605 cursor->hidden = false;
606 cursor_set_image(cursor, NULL, cursor->image_client); 606 if (cursor->image_surface) {
607 cursor_set_image_surface(cursor, cursor->image_surface,
608 cursor->hotspot_x, cursor->hotspot_y,
609 cursor->image_client);
610 } else {
611 const char *image = cursor->image;
612 cursor->image = NULL;
613 cursor_set_image(cursor, image, cursor->image_client);
614 }
607 } 615 }
608} 616}
609 617
@@ -1297,12 +1305,8 @@ static void handle_request_set_cursor(struct wl_listener *listener,
1297 return; 1305 return;
1298 } 1306 }
1299 1307
1300 cursor->image = NULL; 1308 cursor_set_image_surface(cursor, event->surface, event->hotspot_x,
1301 cursor->image_client = focused_client; 1309 event->hotspot_y, focused_client);
1302 cursor->image_surface = event->surface;
1303 cursor->hotspot_x = event->hotspot_x;
1304 cursor->hotspot_y = event->hotspot_y;
1305 cursor_set_image(cursor, NULL, cursor->image_client);
1306} 1310}
1307 1311
1308void cursor_set_image(struct sway_cursor *cursor, const char *image, 1312void cursor_set_image(struct sway_cursor *cursor, const char *image,
@@ -1310,21 +1314,43 @@ void cursor_set_image(struct sway_cursor *cursor, const char *image,
1310 if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { 1314 if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
1311 return; 1315 return;
1312 } 1316 }
1317
1318 const char *current_image = cursor->image;
1319 cursor->image = image;
1320 cursor->image_surface = NULL;
1321 cursor->hotspot_x = cursor->hotspot_y = 0;
1322 cursor->image_client = client;
1323
1313 if (cursor->hidden) { 1324 if (cursor->hidden) {
1314 return; 1325 return;
1315 } 1326 }
1316 if (!image && cursor->image_surface) { 1327
1317 wlr_cursor_set_surface(cursor->cursor, cursor->image_surface, 1328 if (!image) {
1318 cursor->hotspot_x, cursor->hotspot_y);
1319 } else if (!image) {
1320 wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); 1329 wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0);
1321 } else if (!cursor->image || strcmp(cursor->image, image) != 0) { 1330 } else if (!current_image || strcmp(current_image, image) != 0) {
1322 cursor->image_surface = NULL;
1323 wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image, 1331 wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image,
1324 cursor->cursor); 1332 cursor->cursor);
1325 } 1333 }
1326 cursor->image = image; 1334}
1335
1336void cursor_set_image_surface(struct sway_cursor *cursor,
1337 struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y,
1338 struct wl_client *client) {
1339 if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
1340 return;
1341 }
1342
1343 cursor->image = NULL;
1344 cursor->image_surface = surface;
1345 cursor->hotspot_x = hotspot_x;
1346 cursor->hotspot_y = hotspot_y;
1327 cursor->image_client = client; 1347 cursor->image_client = client;
1348
1349 if (cursor->hidden) {
1350 return;
1351 }
1352
1353 wlr_cursor_set_surface(cursor->cursor, surface, hotspot_x, hotspot_y);
1328} 1354}
1329 1355
1330void sway_cursor_destroy(struct sway_cursor *cursor) { 1356void sway_cursor_destroy(struct sway_cursor *cursor) {