diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-12-19 18:22:56 -0500 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-12-25 13:31:56 +0100 |
commit | 3248c823ed1f3bc95b8401a32a2dc12144a88f7d (patch) | |
tree | e57f23bb5d371791e2b1b513f5246e7f3ddda3db | |
parent | Implement hide_cursor <timeout> command (diff) | |
download | sway-3248c823ed1f3bc95b8401a32a2dc12144a88f7d.tar.gz sway-3248c823ed1f3bc95b8401a32a2dc12144a88f7d.tar.zst sway-3248c823ed1f3bc95b8401a32a2dc12144a88f7d.zip |
Split image_surface handling into own function
-rw-r--r-- | include/sway/input/cursor.h | 4 | ||||
-rw-r--r-- | sway/input/cursor.c | 54 |
2 files changed, 44 insertions, 14 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 8677f1b1..21a26f68 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -73,6 +73,10 @@ void dispatch_cursor_button(struct sway_cursor *cursor, | |||
73 | void cursor_set_image(struct sway_cursor *cursor, const char *image, | 73 | void cursor_set_image(struct sway_cursor *cursor, const char *image, |
74 | struct wl_client *client); | 74 | struct wl_client *client); |
75 | 75 | ||
76 | void cursor_set_image_surface(struct sway_cursor *cursor, | ||
77 | struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y, | ||
78 | struct wl_client *client); | ||
79 | |||
76 | void cursor_warp_to_container(struct sway_cursor *cursor, | 80 | void cursor_warp_to_container(struct sway_cursor *cursor, |
77 | struct sway_container *container); | 81 | struct sway_container *container); |
78 | 82 | ||
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 | ||
1308 | void cursor_set_image(struct sway_cursor *cursor, const char *image, | 1312 | void 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 | |||
1336 | void 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 | ||
1330 | void sway_cursor_destroy(struct sway_cursor *cursor) { | 1356 | void sway_cursor_destroy(struct sway_cursor *cursor) { |