summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2011-03-29 15:04:42 +0200
committerMichael Cardell Widerkrantz <mc@hack.org>2011-03-29 15:27:04 +0200
commit91063b16db2ace7d6da14fc7374194cfc1d69254 (patch)
tree610cb520aca7c611080143419f3e50c48ae3f36d
parent3735bdc0e4d3ef7c4a1555f0860c152cf69da7b2 (diff)
downloadmcwm-91063b16db2ace7d6da14fc7374194cfc1d69254.zip
Always work on the currently focused window when moving and resizing
and not in the window the mouse cursor happen to be in when the mouse button is pressed. However, just do move and resize if the mouse cursor is inside the window we care about. There's a limit to sloppy focus. It gets confusing and we might lose focus to another window if we allow move and resize *and continue to put the mouse cursor back to where it was when starting, relative to the window*, as we do now. Removed code for special handling of the root window. We don't use it anyway. Extra checks for focuswin == NULL.
-rw-r--r--NEWS8
-rw-r--r--mcwm.c188
2 files changed, 103 insertions, 93 deletions
diff --git a/NEWS b/NEWS
index d75e077..304724d 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,14 @@
User visible changes
+2011-03-29
+
+ * Sloppy focus didn't really work for move and resize before. When
+ the mouse pointer was outside the window nothing happened. Now
+ fixed. This also means that any panels that we don't know
+ anything about, like dzen2, won't suddenly interfer with resizing
+ if the mouse pointer just happens to be in their window.
+
2011-03-28
* Always raise window when fixing it on all workspaces. When moving
diff --git a/mcwm.c b/mcwm.c
index d717d62..24abe6e 100644
--- a/mcwm.c
+++ b/mcwm.c
@@ -2719,101 +2719,105 @@ void events(void)
e->detail, (long)e->event, e->child, e->event_x,
e->event_y);
- if (e->child != 0)
+ /*
+ * If we don't have any currently focused window, we can't
+ * do anything. We don't want to do anything if the mouse
+ * cursor is in the wrong window (root window or a panel,
+ * for instance). There is a limit to sloppy focus.
+ */
+ if (NULL == focuswin || focuswin->id != e->child)
{
- /*
- * If middle button was pressed, raise window or lower
- * it if it was already on top.
- */
- if (2 == e->detail)
- {
- raiseorlower(focuswin);
- }
- else
- {
- int16_t pointx;
- int16_t pointy;
+ break;
+ }
- /* We're moving or resizing. */
+ /*
+ * XXX if 0 == e->child, we're on the root window. Do
+ * something on the root when mouse buttons are pressed?
+ */
- /*
- * Get and save pointer position inside the window
- * so we can go back to it when we're done moving
- * or resizing.
- */
- if (!getpointer(e->child, &pointx, &pointy))
- {
- break;
- }
+ /*
+ * If middle button was pressed, raise window or lower
+ * it if it was already on top.
+ */
+ if (2 == e->detail)
+ {
+ raiseorlower(focuswin);
+ }
+ else
+ {
+ int16_t pointx;
+ int16_t pointy;
- mode_x = pointx;
- mode_y = pointy;
+ /* We're moving or resizing. */
- /* Raise window. */
- raisewindow(e->child);
+ /*
+ * Get and save pointer position inside the window
+ * so we can go back to it when we're done moving
+ * or resizing.
+ */
+ if (!getpointer(focuswin->id, &pointx, &pointy))
+ {
+ break;
+ }
- /* Get window geometry. */
- if (!getgeom(e->child, &x, &y, &width, &height))
- {
- break;
- }
+ mode_x = pointx;
+ mode_y = pointy;
- /* Mouse button 1 was pressed. */
- if (1 == e->detail)
- {
- mode = MCWM_MOVE;
-
- /*
- * Warp pointer to upper left of window before
- * starting move.
- */
- xcb_warp_pointer(conn, XCB_NONE, e->child, 0, 0, 0, 0,
- 1, 1);
- }
- else
- {
- /* Mouse button 3 was pressed. */
+ /* Raise window. */
+ raisewindow(focuswin->id);
- mode = MCWM_RESIZE;
+ /* Get window geometry. */
+ if (!getgeom(focuswin->id, &x, &y, &width, &height))
+ {
+ break;
+ }
- /* Warp pointer to lower right. */
- xcb_warp_pointer(conn, XCB_NONE, e->child, 0, 0, 0, 0,
- width, height);
- }
+ /* Mouse button 1 was pressed. */
+ if (1 == e->detail)
+ {
+ mode = MCWM_MOVE;
/*
- * Take control of the pointer in the root window
- * and confine it to root.
- *
- * Give us events when the key is released or if
- * any motion occurs with the key held down, but
- * give us only hints about movement. We ask for
- * the position ourselves later.
- *
- * Keep updating everything else.
- *
- * Don't use any new cursor.
+ * Warp pointer to upper left of window before
+ * starting move.
*/
- xcb_grab_pointer(conn, 0, screen->root,
- XCB_EVENT_MASK_BUTTON_RELEASE
- | XCB_EVENT_MASK_BUTTON_MOTION,
- XCB_GRAB_MODE_ASYNC,
- XCB_GRAB_MODE_ASYNC,
- screen->root,
- XCB_NONE,
- XCB_CURRENT_TIME);
-
- xcb_flush(conn);
-
- PDEBUG("mode now : %d\n", mode);
+ xcb_warp_pointer(conn, XCB_NONE, focuswin->id, 0, 0, 0, 0,
+ 1, 1);
}
- } /* subwindow */
- else
- {
+ else
+ {
+ /* Mouse button 3 was pressed. */
+
+ mode = MCWM_RESIZE;
+
+ /* Warp pointer to lower right. */
+ xcb_warp_pointer(conn, XCB_NONE, focuswin->id, 0, 0, 0,
+ 0, width, height);
+ }
+
/*
- * Do something on the root when mouse buttons are
- * pressed?
+ * Take control of the pointer in the root window
+ * and confine it to root.
+ *
+ * Give us events when the key is released or if
+ * any motion occurs with the key held down.
+ *
+ * Keep updating everything else.
+ *
+ * Don't use any new cursor.
*/
+ xcb_grab_pointer(conn, 0, screen->root,
+ XCB_EVENT_MASK_BUTTON_RELEASE
+ | XCB_EVENT_MASK_BUTTON_MOTION,
+ XCB_GRAB_MODE_ASYNC,
+ XCB_GRAB_MODE_ASYNC,
+ screen->root,
+ XCB_NONE,
+ XCB_CURRENT_TIME);
+
+ xcb_flush(conn);
+
+ PDEBUG("mode now : %d\n", mode);
}
}
break;
@@ -2822,30 +2826,28 @@ void events(void)
{
xcb_motion_notify_event_t *e;
+ /*
+ * We can't do anything if we don't have a focused window
+ * or if it's fully maximized.
+ */
+ if (NULL == focuswin || focuswin->maxed)
+ {
+ break;
+ }
+
e = (xcb_motion_notify_event_t *) ev;
/*
* Our pointer is moving and since we even get this event
* we're either resizing or moving a window.
- *
- * We don't bother actually doing anything if we don't
- * have a focused window or if the focused window is
- * totally maximized.
*/
if (mode == MCWM_MOVE)
{
- if (NULL != focuswin && !focuswin->maxed)
- {
- mousemove(focuswin->id, e->root_x, e->root_y);
- }
+ mousemove(focuswin->id, e->root_x, e->root_y);
}
else if (mode == MCWM_RESIZE)
{
- /* Resize. */
- if (NULL != focuswin && !focuswin->maxed)
- {
- mouseresize(focuswin, e->root_x, e->root_y);
- }
+ mouseresize(focuswin, e->root_x, e->root_y);
}
else
{