mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
implement wlr_cursor_warp
This commit is contained in:
parent
dd68f680e4
commit
0cba06dcef
2 changed files with 40 additions and 25 deletions
|
@ -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_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);
|
void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -64,18 +64,11 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur) {
|
||||||
cur->state->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_x = 0;
|
||||||
int hotspot_y = 0;
|
int hotspot_y = 0;
|
||||||
|
|
||||||
|
@ -85,18 +78,11 @@ void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
|
||||||
hotspot_y = image->hotspot_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;
|
struct wlr_output_layout_output *l_output;
|
||||||
wl_list_for_each(l_output, &cur->state->layout->outputs, link) {
|
wl_list_for_each(l_output, &cur->state->layout->outputs, link) {
|
||||||
int output_x = new_x;
|
int output_x = x;
|
||||||
int output_y = new_y;
|
int output_y = y;
|
||||||
|
|
||||||
// TODO fix double to int rounding issues
|
// TODO fix double to int rounding issues
|
||||||
wlr_output_layout_output_coords(cur->state->layout,
|
wlr_output_layout_output_coords(cur->state->layout,
|
||||||
|
@ -105,8 +91,28 @@ void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
|
||||||
output_y - hotspot_y);
|
output_y - hotspot_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur->x = new_x;
|
return true;
|
||||||
cur->y = new_y;
|
}
|
||||||
|
|
||||||
|
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) {
|
static void handle_pointer_motion(struct wl_listener *listener, void *data) {
|
||||||
|
|
Loading…
Reference in a new issue