summaryrefslogtreecommitdiff
path: root/mcwm.c
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2010-07-17 23:43:53 +0200
committerMichael Cardell Widerkrantz <mc@hack.org>2010-07-17 23:43:53 +0200
commit3c59627fada0a6b57089ba3a11ba939b00223f19 (patch)
treeeefa9442d7bed9f75d7f68b59b7abc221d994910 /mcwm.c
parent32753c6361efe893005572939ac08488fe9f4183 (diff)
downloadmcwm-3c59627fada0a6b57089ba3a11ba939b00223f19.zip
Keep window relative pointer position when resizing with keyboard. If
the old relative pointer coordinates are outside the new geometry, warp the pointer to the middle of the window.
Diffstat (limited to 'mcwm.c')
-rw-r--r--mcwm.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/mcwm.c b/mcwm.c
index 394c7b6..8fc4541 100644
--- a/mcwm.c
+++ b/mcwm.c
@@ -1280,8 +1280,13 @@ void resize(xcb_drawable_t win, uint32_t width, uint32_t height)
void resizestep(struct client *client, char direction)
{
xcb_get_geometry_reply_t *geom;
- int width;
- int height;
+ xcb_query_pointer_reply_t *pointer;
+ int16_t start_x;
+ int16_t start_y;
+ int16_t x;
+ int16_t y;
+ int16_t width;
+ int16_t height;
xcb_size_hints_t hints;
int step_x = MOVE_STEP;
int step_y = MOVE_STEP;
@@ -1293,6 +1298,19 @@ void resizestep(struct client *client, char direction)
}
win = client->id;
+
+ pointer = xcb_query_pointer_reply(
+ conn, xcb_query_pointer(conn, win), 0);
+
+ if (NULL == pointer)
+ {
+ return;
+ }
+
+ start_x = pointer->win_x;
+ start_y = pointer->win_y;
+
+ free(pointer);
raisewindow(win);
@@ -1338,7 +1356,7 @@ void resizestep(struct client *client, char direction)
height = geom->height;
if (width < 0)
{
- width = 0;
+ goto bad;
}
break;
@@ -1377,11 +1395,32 @@ void resizestep(struct client *client, char direction)
resize(win, width, height);
/*
- * Move cursor into the middle of the window so we don't lose the
- * pointer to another window.
+ * Move pointer to the original position relative window if that's
+ * still inside the window. Otherwise, move to the middle of the
+ * window. If we don't do this we might lose the focus to another
+ * window.
*/
+
+ if (start_x > geom->width)
+ {
+ x = geom->width / 2;
+ }
+ else
+ {
+ x = start_x;
+ }
+
+ if (start_y > geom->height)
+ {
+ y = geom->height / 2;
+ }
+ else
+ {
+ y = start_y;
+ }
+
xcb_warp_pointer(conn, XCB_NONE, win, 0, 0, 0, 0,
- width / 2, height / 2);
+ x, y);
xcb_flush(conn);