aboutsummaryrefslogtreecommitdiff
path: root/tinywl
diff options
context:
space:
mode:
authorKalyan Sriram <coder.kalyan@gmail.com>2020-04-23 01:00:06 -0700
committerGitHub <noreply@github.com>2020-04-23 10:00:06 +0200
commit326c8bc818a483bad30f7c2233a8f9e36c73d2c6 (patch)
treea13a7299669dad7bb3982da595d38504686e09d4 /tinywl
parent6129a6f93e97680dfe7e983db2ee7671edb5ffbe (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.
Diffstat (limited to 'tinywl')
-rw-r--r--tinywl/tinywl.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c
index ec2e549a..c44a7175 100644
--- a/tinywl/tinywl.c
+++ b/tinywl/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;
}