diff options
-rw-r--r-- | include/sway/input/cursor.h | 7 | ||||
-rw-r--r-- | sway/input/cursor.c | 41 |
2 files changed, 47 insertions, 1 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 4d47ab42..5556ea11 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -46,6 +46,11 @@ void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, | |||
46 | uint32_t button, enum wlr_button_state state); | 46 | uint32_t button, enum wlr_button_state state); |
47 | 47 | ||
48 | void cursor_set_image(struct sway_cursor *cursor, const char *image, | 48 | void cursor_set_image(struct sway_cursor *cursor, const char *image, |
49 | struct wl_client *client); | 49 | struct wl_client *client); |
50 | 50 | ||
51 | void cursor_warp_to_container(struct sway_cursor *cursor, | ||
52 | struct sway_container *container); | ||
53 | |||
54 | void cursor_warp_to_workspace(struct sway_cursor *cursor, | ||
55 | struct sway_workspace *workspace); | ||
51 | #endif | 56 | #endif |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 5c446299..21e104ec 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <wlr/types/wlr_cursor.h> | 9 | #include <wlr/types/wlr_cursor.h> |
10 | #include <wlr/types/wlr_xcursor_manager.h> | 10 | #include <wlr/types/wlr_xcursor_manager.h> |
11 | #include <wlr/types/wlr_idle.h> | 11 | #include <wlr/types/wlr_idle.h> |
12 | #include <wlr/types/wlr_box.h> | ||
12 | #include "list.h" | 13 | #include "list.h" |
13 | #include "log.h" | 14 | #include "log.h" |
14 | #include "config.h" | 15 | #include "config.h" |
@@ -1271,4 +1272,44 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
1271 | cursor->cursor = wlr_cursor; | 1272 | cursor->cursor = wlr_cursor; |
1272 | 1273 | ||
1273 | return cursor; | 1274 | return cursor; |
1275 | |||
1276 | } | ||
1277 | |||
1278 | /** | ||
1279 | * Warps the cursor to the middle of the container argument. | ||
1280 | * Does nothing if the cursor is already inside the container. | ||
1281 | * If container is NULL, returns without doing anything. | ||
1282 | */ | ||
1283 | void cursor_warp_to_container(struct sway_cursor *cursor, | ||
1284 | struct sway_container *container) { | ||
1285 | if (!container) { | ||
1286 | return; | ||
1287 | } | ||
1288 | |||
1289 | struct wlr_box box; | ||
1290 | container_get_box(container, &box); | ||
1291 | if (wlr_box_contains_point(&box, cursor->cursor->x, cursor->cursor->y)) { | ||
1292 | return; | ||
1293 | } | ||
1294 | |||
1295 | double x = container->x + container->width / 2.0; | ||
1296 | double y = container->y + container->height / 2.0; | ||
1297 | |||
1298 | wlr_cursor_warp(cursor->cursor, NULL, x, y); | ||
1299 | } | ||
1300 | |||
1301 | /** | ||
1302 | * Warps the cursor to the middle of the workspace argument. | ||
1303 | * If workspace is NULL, returns without doing anything. | ||
1304 | */ | ||
1305 | void cursor_warp_to_workspace(struct sway_cursor *cursor, | ||
1306 | struct sway_workspace *workspace) { | ||
1307 | if (!workspace) { | ||
1308 | return; | ||
1309 | } | ||
1310 | |||
1311 | double x = workspace->x + workspace->width / 2.0; | ||
1312 | double y = workspace->y + workspace->height / 2.0; | ||
1313 | |||
1314 | wlr_cursor_warp(cursor->cursor, NULL, x, y); | ||
1274 | } | 1315 | } |