From 0969bf758b258b328f48ee360b30764b08a7d145 Mon Sep 17 00:00:00 2001 From: Rouven Czerwinski Date: Mon, 15 Oct 2018 16:18:46 +0200 Subject: cursor: functions to warp cursor to container and workspace The new functions allow a cursor to be warped without changing the focus. This is a preparation commit to handle cursor warping not only in seat_set_focus_warp. --- sway/input/cursor.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'sway/input/cursor.c') 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 @@ #include #include #include +#include #include "list.h" #include "log.h" #include "config.h" @@ -1271,4 +1272,44 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { cursor->cursor = wlr_cursor; return cursor; + +} + +/** + * Warps the cursor to the middle of the container argument. + * Does nothing if the cursor is already inside the container. + * If container is NULL, returns without doing anything. + */ +void cursor_warp_to_container(struct sway_cursor *cursor, + struct sway_container *container) { + if (!container) { + return; + } + + struct wlr_box box; + container_get_box(container, &box); + if (wlr_box_contains_point(&box, cursor->cursor->x, cursor->cursor->y)) { + return; + } + + double x = container->x + container->width / 2.0; + double y = container->y + container->height / 2.0; + + wlr_cursor_warp(cursor->cursor, NULL, x, y); +} + +/** + * Warps the cursor to the middle of the workspace argument. + * If workspace is NULL, returns without doing anything. + */ +void cursor_warp_to_workspace(struct sway_cursor *cursor, + struct sway_workspace *workspace) { + if (!workspace) { + return; + } + + double x = workspace->x + workspace->width / 2.0; + double y = workspace->y + workspace->height / 2.0; + + wlr_cursor_warp(cursor->cursor, NULL, x, y); } -- cgit v1.2.3-54-g00ecf