summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalyan Sriram <[email protected]>2020-04-23 01:00:06 -0700
committerGitHub <[email protected]>2020-04-23 10:00:06 +0200
commitce07a9bde4cda0a0b0a7ceff1ad568f7761acebc (patch)
tree771e99305cb5f40e9b4565e9966d477fc75939c4
parentbb1fb4bbbf9fa63ee033cb7ca94cdab0dd6523ad (diff)
tinywl: fix geo_box bug in cursor resizing
While trying out the tinywl code, I found that the resize mode was behaving weirdly ... so I looked into code. Turns out the `begin_interactive` method stores the cursor position plus the geo_box position; however, `process_cursor_resize` wasn't taking this into account, causing windows to jump down in size unexpectedly when resized and lose alignment with the cursor. To fix this, I simply added a member to the `tinywl_server` struct that stores the geo_box when the mouse enters grab mode, and I referenced that data in the resize method. I considered polling for this data every time instead of storing it in the server struct, but 1) since changes in this value are not relevant and 2) it could potentially decrease performance (I don't know enough about wlroots to know how much) I decided to just store it. I can change this if desired.
-rw-r--r--tinywl.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/tinywl.c b/tinywl.c
index ec2e549..c44a717 100644
--- a/tinywl.c
+++ b/tinywl.c
@@ -54,6 +54,7 @@ struct tinywl_server {
enum tinywl_cursor_mode cursor_mode;
struct tinywl_view *grabbed_view;
double grab_x, grab_y;
+ struct wlr_box grab_geo_box;
int grab_width, grab_height;
uint32_t resize_edges;
@@ -366,22 +367,22 @@ static void process_cursor_resize(struct tinywl_server *server, uint32_t time) {
int width = server->grab_width;
int height = server->grab_height;
if (server->resize_edges & WLR_EDGE_TOP) {
- y = server->grab_y + dy;
- height -= dy;
+ y = server->grab_y + dy - server->grab_geo_box.y;
+ height -= dy + server->grab_geo_box.y;
if (height < 1) {
y += height;
}
} else if (server->resize_edges & WLR_EDGE_BOTTOM) {
- height += dy;
+ height += dy + server->grab_geo_box.y;
}
if (server->resize_edges & WLR_EDGE_LEFT) {
- x = server->grab_x + dx;
- width -= dx;
+ x = server->grab_x + dx - server->grab_geo_box.x;
+ width -= dx + server->grab_geo_box.x;
if (width < 1) {
x += width;
}
} else if (server->resize_edges & WLR_EDGE_RIGHT) {
- width += dx;
+ width += dx + server->grab_geo_box.x;
}
view->x = x;
view->y = y;
@@ -715,17 +716,16 @@ static void begin_interactive(struct tinywl_view *view,
}
server->grabbed_view = view;
server->cursor_mode = mode;
- struct wlr_box geo_box;
- wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box);
+ wlr_xdg_surface_get_geometry(view->xdg_surface, &server->grab_geo_box);
if (mode == TINYWL_CURSOR_MOVE) {
server->grab_x = server->cursor->x - view->x;
server->grab_y = server->cursor->y - view->y;
} else {
- server->grab_x = server->cursor->x + geo_box.x;
- server->grab_y = server->cursor->y + geo_box.y;
+ server->grab_x = server->cursor->x + server->grab_geo_box.x;
+ server->grab_y = server->cursor->y + server->grab_geo_box.y;
}
- server->grab_width = geo_box.width;
- server->grab_height = geo_box.height;
+ server->grab_width = server->grab_geo_box.width;
+ server->grab_height = server->grab_geo_box.height;
server->resize_edges = edges;
}