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.
This commit is contained in:
Rouven Czerwinski 2018-10-15 16:18:46 +02:00
parent 892446a0b6
commit 0969bf758b
2 changed files with 47 additions and 1 deletions

View file

@ -48,4 +48,9 @@ void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
void cursor_set_image(struct sway_cursor *cursor, const char *image, void cursor_set_image(struct sway_cursor *cursor, const char *image,
struct wl_client *client); struct wl_client *client);
void cursor_warp_to_container(struct sway_cursor *cursor,
struct sway_container *container);
void cursor_warp_to_workspace(struct sway_cursor *cursor,
struct sway_workspace *workspace);
#endif #endif

View file

@ -9,6 +9,7 @@
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_box.h>
#include "list.h" #include "list.h"
#include "log.h" #include "log.h"
#include "config.h" #include "config.h"
@ -1271,4 +1272,44 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
cursor->cursor = wlr_cursor; cursor->cursor = wlr_cursor;
return 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);
} }