implement wlr_cursor_warp

This commit is contained in:
Tony Crisci 2017-08-24 10:42:05 -04:00
parent dd68f680e4
commit 0cba06dcef
2 changed files with 40 additions and 25 deletions

View file

@ -28,8 +28,17 @@ void wlr_cursor_destroy(struct wlr_cursor *cur);
void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur);
void wlr_cursor_warp(struct wlr_cursor *cur, double x, double y);
/**
* Warp the cursor to the given x and y in layout coordinates. If x and y are
* out of the layout boundaries or constraints, no warp will happen.
*
* Returns true when the mouse warp was successful.
*/
bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y);
/**
* Move the cursor in the direction of the given x and y coordinates.
*/
void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y);
/**

View file

@ -64,18 +64,11 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur) {
cur->state->xcursor = xcur;
}
void wlr_cursor_warp(struct wlr_cursor *cur, double x, double y) {
}
bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y) {
if (!wlr_output_layout_output_at(cur->state->layout, x, y)) {
return false;
}
void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
//struct wlr_output *current_output;
//current_output = wlr_output_layout_output_at(cur->state->layout, cur->x, cur->y);
// TODO handle no layout
assert(cur->state->layout);
double new_x = cur->x + delta_x;
double new_y = cur->y + delta_y;
int hotspot_x = 0;
int hotspot_y = 0;
@ -85,28 +78,41 @@ void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
hotspot_y = image->hotspot_y;
}
if (!wlr_output_layout_output_at(cur->state->layout, new_x, new_y)) {
int closest_x, closest_y;
wlr_output_layout_closest_boundary(cur->state->layout, new_x, new_y,
&closest_x, &closest_y);
new_x = closest_x;
new_y = closest_y;
}
struct wlr_output_layout_output *l_output;
wl_list_for_each(l_output, &cur->state->layout->outputs, link) {
int output_x = new_x;
int output_y = new_y;
int output_x = x;
int output_y = y;
// TODO fix double to int rounding issues
wlr_output_layout_output_coords(cur->state->layout,
l_output->output, &output_x, &output_y);
l_output->output, &output_x, &output_y);
wlr_output_move_cursor(l_output->output, output_x - hotspot_x,
output_y - hotspot_y);
output_y - hotspot_y);
}
cur->x = new_x;
cur->y = new_y;
return true;
}
void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
// TODO handle no layout
assert(cur->state->layout);
int x = cur->x + delta_x;
int y = cur->y + delta_y;
if (!wlr_output_layout_output_at(cur->state->layout, x, y)) {
int closest_x, closest_y;
wlr_output_layout_closest_boundary(cur->state->layout, x, y, &closest_x,
&closest_y);
x = closest_x;
y = closest_y;
}
if (wlr_cursor_warp(cur, x, y)) {
cur->x = x;
cur->y = y;
}
}
static void handle_pointer_motion(struct wl_listener *listener, void *data) {