#include <X11/Xlib.h>
#include <glib.h>
+/* how far windows move and resize with the keyboard arrows */
+#define KEY_DIST 4
+
gboolean moveresize_in_progress = FALSE;
ObClient *moveresize_client = NULL;
#ifdef SYNC
moveresize_client = NULL;
}
-static void do_move(gboolean resist)
+static void do_move(gboolean keyboard)
{
- if (resist) {
- resist_move_windows(moveresize_client, &cur_x, &cur_y);
- resist_move_monitors(moveresize_client, &cur_x, &cur_y);
- }
+ gint resist;
+
+ if (keyboard) resist = KEY_DIST - 1; /* resist for one key press */
+ else resist = config_resist_win;
+ resist_move_windows(moveresize_client, resist, &cur_x, &cur_y);
+ if (!keyboard) resist = config_resist_edge;
+ resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y);
client_configure(moveresize_client, cur_x, cur_y,
moveresize_client->area.width,
moveresize_client->area.height, TRUE, FALSE);
if (config_resize_popup_show == 2) /* == "Always" */
popup_coords(moveresize_client, "%d x %d",
- moveresize_client->frame->area.x,
- moveresize_client->frame->area.y);
+ moveresize_client->frame->area.x,
+ moveresize_client->frame->area.y);
}
static void do_resize()
moveresize_client->logical_size.height);
}
-static void calc_resize(gboolean resist)
+static void calc_resize(gboolean keyboard)
{
+ gint resist;
+
/* resist_size_* needs the frame size */
cur_x += moveresize_client->frame->size.left +
moveresize_client->frame->size.right;
cur_y += moveresize_client->frame->size.top +
moveresize_client->frame->size.bottom;
- if (resist) {
- resist_size_windows(moveresize_client, &cur_x, &cur_y, lockcorner);
- resist_size_monitors(moveresize_client, &cur_x, &cur_y, lockcorner);
- }
+ if (keyboard) resist = KEY_DIST - 1; /* resist for one key press */
+ else resist = config_resist_win;
+ resist_size_windows(moveresize_client, resist, &cur_x, &cur_y, lockcorner);
+ if (!keyboard) resist = config_resist_edge;
+ resist_size_monitors(moveresize_client, resist, &cur_x, &cur_y,lockcorner);
cur_x -= moveresize_client->frame->size.left +
moveresize_client->frame->size.right;
if (moving) {
cur_x = start_cx + e->xmotion.x_root - start_x;
cur_y = start_cy + e->xmotion.y_root - start_y;
- do_move(TRUE);
+ do_move(FALSE);
} else {
if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
cur_x = start_cw - (e->xmotion.x_root - start_x);
} else
g_assert_not_reached();
- calc_resize(TRUE);
+ calc_resize(FALSE);
do_resize();
}
used = TRUE;
gint dx = 0, dy = 0, ox = cur_x, oy = cur_y;
if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
- dx = MAX(4, moveresize_client->size_inc.width);
+ dx = MAX(KEY_DIST, moveresize_client->size_inc.width);
else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
- dx = -MAX(4, moveresize_client->size_inc.width);
+ dx = -MAX(KEY_DIST, moveresize_client->size_inc.width);
else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
- dy = MAX(4, moveresize_client->size_inc.height);
+ dy = MAX(KEY_DIST, moveresize_client->size_inc.height);
else /* if (e->xkey.keycode == ob_keycode(OB_KEY_UP)) */
- dy = -MAX(4, moveresize_client->size_inc.height);
+ dy = -MAX(KEY_DIST, moveresize_client->size_inc.height);
cur_x += dx;
cur_y += dy;
while (XCheckTypedEvent(ob_display, MotionNotify, &ce));
}
- do_resize(FALSE);
+ calc_resize(TRUE);
+ do_resize();
/* because the cursor moves even though the window does
not nessesarily (resistance), this adjusts where the curor
gint opx, px, opy, py;
if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
- dx = 4;
+ dx = KEY_DIST;
else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
- dx = -4;
+ dx = -KEY_DIST;
else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
- dy = 4;
+ dy = KEY_DIST;
else /* if (e->xkey.keycode == ob_keycode(OB_KEY_UP)) */
- dy = -4;
+ dy = -KEY_DIST;
cur_x += dx;
cur_y += dy;
}
screen_pointer_pos(&px, &py);
- do_move(FALSE);
+ do_move(TRUE);
/* because the cursor moves even though the window does
not nessesarily (resistance), this adjusts where the curor
#include <glib.h>
-void resist_move_windows(ObClient *c, gint *x, gint *y)
+void resist_move_windows(ObClient *c, gint resist, gint *x, gint *y)
{
GList *it;
gint l, t, r, b; /* requested edges */
gint w, h; /* current size */
ObClient *snapx = NULL, *snapy = NULL;
+ if (!resist) return;
+
w = c->frame->area.width;
h = c->frame->area.height;
cr = RECT_RIGHT(c->frame->area);
cb = RECT_BOTTOM(c->frame->area);
- if (config_resist_win)
- for (it = stacking_list; it; it = g_list_next(it)) {
- ObClient *target;
- gint tl, tt, tr, tb; /* 1 past the target's edges on each side */
-
- if (!WINDOW_IS_CLIENT(it->data))
- continue;
- target = it->data;
-
- /* don't snap to self or non-visibles */
- if (!target->frame->visible || target == c) continue;
-
- /* don't snap to windows in layers beneath */
- if(target->layer < c->layer && !config_resist_layers_below)
- continue;
-
- tl = RECT_LEFT(target->frame->area) - 1;
- tt = RECT_TOP(target->frame->area) - 1;
- tr = RECT_RIGHT(target->frame->area) + 1;
- tb = RECT_BOTTOM(target->frame->area) + 1;
-
- /* snapx and snapy ensure that the window snaps to the top-most
- window edge available, without going all the way from
- bottom-to-top in the stacking list
- */
- if (snapx == NULL) {
- if (ct < tb && cb > tt) {
- if (cl >= tr && l < tr && l >= tr - config_resist_win)
- *x = tr, snapx = target;
- else if (cr <= tl && r > tl &&
- r <= tl + config_resist_win)
- *x = tl - w + 1, snapx = target;
- if (snapx != NULL) {
- /* try to corner snap to the window */
- if (ct > tt && t <= tt &&
- t > tt - config_resist_win)
- *y = tt + 1, snapy = target;
- else if (cb < tb && b >= tb &&
- b < tb + config_resist_win)
- *y = tb - h, snapy = target;
- }
+ for (it = stacking_list; it; it = g_list_next(it)) {
+ ObClient *target;
+ gint tl, tt, tr, tb; /* 1 past the target's edges on each side */
+
+ if (!WINDOW_IS_CLIENT(it->data))
+ continue;
+ target = it->data;
+
+ /* don't snap to self or non-visibles */
+ if (!target->frame->visible || target == c) continue;
+
+ /* don't snap to windows in layers beneath */
+ if(target->layer < c->layer && !config_resist_layers_below)
+ continue;
+
+ tl = RECT_LEFT(target->frame->area) - 1;
+ tt = RECT_TOP(target->frame->area) - 1;
+ tr = RECT_RIGHT(target->frame->area) + 1;
+ tb = RECT_BOTTOM(target->frame->area) + 1;
+
+ /* snapx and snapy ensure that the window snaps to the top-most
+ window edge available, without going all the way from
+ bottom-to-top in the stacking list
+ */
+ if (snapx == NULL) {
+ if (ct < tb && cb > tt) {
+ if (cl >= tr && l < tr && l >= tr - resist)
+ *x = tr, snapx = target;
+ else if (cr <= tl && r > tl &&
+ r <= tl + resist)
+ *x = tl - w + 1, snapx = target;
+ if (snapx != NULL) {
+ /* try to corner snap to the window */
+ if (ct > tt && t <= tt &&
+ t > tt - resist)
+ *y = tt + 1, snapy = target;
+ else if (cb < tb && b >= tb &&
+ b < tb + resist)
+ *y = tb - h, snapy = target;
}
}
- if (snapy == NULL) {
- if (cl < tr && cr > tl) {
- if (ct >= tb && t < tb && t >= tb - config_resist_win)
- *y = tb, snapy = target;
- else if (cb <= tt && b > tt &&
- b <= tt + config_resist_win)
- *y = tt - h + 1, snapy = target;
- if (snapy != NULL) {
- /* try to corner snap to the window */
- if (cl > tl && l <= tl &&
- l > tl - config_resist_win)
- *x = tl + 1, snapx = target;
- else if (cr < tr && r >= tr &&
- r < tr + config_resist_win)
- *x = tr - w, snapx = target;
- }
+ }
+ if (snapy == NULL) {
+ if (cl < tr && cr > tl) {
+ if (ct >= tb && t < tb && t >= tb - resist)
+ *y = tb, snapy = target;
+ else if (cb <= tt && b > tt &&
+ b <= tt + resist)
+ *y = tt - h + 1, snapy = target;
+ if (snapy != NULL) {
+ /* try to corner snap to the window */
+ if (cl > tl && l <= tl &&
+ l > tl - resist)
+ *x = tl + 1, snapx = target;
+ else if (cr < tr && r >= tr &&
+ r < tr + resist)
+ *x = tr - w, snapx = target;
}
}
-
- if (snapx && snapy) break;
}
+
+ if (snapx && snapy) break;
+ }
}
-void resist_move_monitors(ObClient *c, gint *x, gint *y)
+void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y)
{
Rect *area, *parea;
guint i;
gint cl, ct, cr, cb; /* current edges */
gint w, h; /* current size */
+ if (!resist) return;
+
w = c->frame->area.width;
h = c->frame->area.height;
cr = RECT_RIGHT(c->frame->area);
cb = RECT_BOTTOM(c->frame->area);
- if (config_resist_edge) {
- for (i = 0; i < screen_num_monitors; ++i) {
- area = screen_area_monitor(c->desktop, i);
- parea = screen_physical_area_monitor(i);
-
- if (!RECT_INTERSECTS_RECT(*parea, c->frame->area))
- continue;
-
- al = RECT_LEFT(*area);
- at = RECT_TOP(*area);
- ar = RECT_RIGHT(*area);
- ab = RECT_BOTTOM(*area);
- pl = RECT_LEFT(*parea);
- pt = RECT_TOP(*parea);
- pr = RECT_RIGHT(*parea);
- pb = RECT_BOTTOM(*parea);
-
- if (cl >= al && l < al && l >= al - config_resist_edge)
- *x = al;
- else if (cr <= ar && r > ar && r <= ar + config_resist_edge)
- *x = ar - w + 1;
- else if (cl >= pl && l < pl && l >= pl - config_resist_edge)
- *x = pl;
- else if (cr <= pr && r > pr && r <= pr + config_resist_edge)
- *x = pr - w + 1;
-
- if (ct >= at && t < at && t >= at - config_resist_edge)
- *y = at;
- else if (cb <= ab && b > ab && b < ab + config_resist_edge)
- *y = ab - h + 1;
- else if (ct >= pt && t < pt && t >= pt - config_resist_edge)
- *y = pt;
- else if (cb <= pb && b > pb && b < pb + config_resist_edge)
- *y = pb - h + 1;
- }
+ for (i = 0; i < screen_num_monitors; ++i) {
+ area = screen_area_monitor(c->desktop, i);
+ parea = screen_physical_area_monitor(i);
+
+ if (!RECT_INTERSECTS_RECT(*parea, c->frame->area))
+ continue;
+
+ al = RECT_LEFT(*area);
+ at = RECT_TOP(*area);
+ ar = RECT_RIGHT(*area);
+ ab = RECT_BOTTOM(*area);
+ pl = RECT_LEFT(*parea);
+ pt = RECT_TOP(*parea);
+ pr = RECT_RIGHT(*parea);
+ pb = RECT_BOTTOM(*parea);
+
+ if (cl >= al && l < al && l >= al - resist)
+ *x = al;
+ else if (cr <= ar && r > ar && r <= ar + resist)
+ *x = ar - w + 1;
+ else if (cl >= pl && l < pl && l >= pl - resist)
+ *x = pl;
+ else if (cr <= pr && r > pr && r <= pr + resist)
+ *x = pr - w + 1;
+
+ if (ct >= at && t < at && t >= at - resist)
+ *y = at;
+ else if (cb <= ab && b > ab && b < ab + resist)
+ *y = ab - h + 1;
+ else if (ct >= pt && t < pt && t >= pt - resist)
+ *y = pt;
+ else if (cb <= pb && b > pb && b < pb + resist)
+ *y = pb - h + 1;
}
}
-void resist_size_windows(ObClient *c, gint *w, gint *h, ObCorner corn)
+void resist_size_windows(ObClient *c, gint resist, gint *w, gint *h,
+ ObCorner corn)
{
GList *it;
ObClient *target; /* target */
gint incw, inch;
ObClient *snapx = NULL, *snapy = NULL;
+ if (!resist) return;
+
incw = c->size_inc.width;
inch = c->size_inc.height;
t = RECT_TOP(c->frame->area);
b = RECT_BOTTOM(c->frame->area);
- if (config_resist_win) {
- for (it = stacking_list; it; it = g_list_next(it)) {
- if (!WINDOW_IS_CLIENT(it->data))
- continue;
- target = it->data;
-
- /* don't snap to invisibles or ourself */
- if (!target->frame->visible || target == c) continue;
-
- /* don't snap to windows in layers beneath */
- if(target->layer < c->layer && !config_resist_layers_below)
- continue;
-
- tl = RECT_LEFT(target->frame->area);
- tr = RECT_RIGHT(target->frame->area);
- tt = RECT_TOP(target->frame->area);
- tb = RECT_BOTTOM(target->frame->area);
-
- if (snapx == NULL) {
- /* horizontal snapping */
- if (t < tb && b > tt) {
- switch (corn) {
- case OB_CORNER_TOPLEFT:
- case OB_CORNER_BOTTOMLEFT:
- dlt = l;
- drb = r + *w - c->frame->area.width;
- if (r < tl && drb >= tl &&
- drb < tl + config_resist_win)
- *w = tl - l, snapx = target;
- break;
- case OB_CORNER_TOPRIGHT:
- case OB_CORNER_BOTTOMRIGHT:
- dlt = l - *w + c->frame->area.width;
- drb = r;
- if (l > tr && dlt <= tr &&
- dlt > tr - config_resist_win)
- *w = r - tr, snapx = target;
- break;
- }
+ for (it = stacking_list; it; it = g_list_next(it)) {
+ if (!WINDOW_IS_CLIENT(it->data))
+ continue;
+ target = it->data;
+
+ /* don't snap to invisibles or ourself */
+ if (!target->frame->visible || target == c) continue;
+
+ /* don't snap to windows in layers beneath */
+ if(target->layer < c->layer && !config_resist_layers_below)
+ continue;
+
+ tl = RECT_LEFT(target->frame->area);
+ tr = RECT_RIGHT(target->frame->area);
+ tt = RECT_TOP(target->frame->area);
+ tb = RECT_BOTTOM(target->frame->area);
+
+ if (snapx == NULL) {
+ /* horizontal snapping */
+ if (t < tb && b > tt) {
+ switch (corn) {
+ case OB_CORNER_TOPLEFT:
+ case OB_CORNER_BOTTOMLEFT:
+ dlt = l;
+ drb = r + *w - c->frame->area.width;
+ if (r < tl && drb >= tl &&
+ drb < tl + resist)
+ *w = tl - l, snapx = target;
+ break;
+ case OB_CORNER_TOPRIGHT:
+ case OB_CORNER_BOTTOMRIGHT:
+ dlt = l - *w + c->frame->area.width;
+ drb = r;
+ if (l > tr && dlt <= tr &&
+ dlt > tr - resist)
+ *w = r - tr, snapx = target;
+ break;
}
}
+ }
- if (snapy == NULL) {
- /* vertical snapping */
- if (l < tr && r > tl) {
- switch (corn) {
- case OB_CORNER_TOPLEFT:
- case OB_CORNER_TOPRIGHT:
- dlt = t;
- drb = b + *h - c->frame->area.height;
- if (b < tt && drb >= tt &&
- drb < tt + config_resist_win)
- *h = tt - t, snapy = target;
- break;
- case OB_CORNER_BOTTOMLEFT:
- case OB_CORNER_BOTTOMRIGHT:
- dlt = t - *h + c->frame->area.height;
- drb = b;
- if (t > tb && dlt <= tb &&
- dlt > tb - config_resist_win)
- *h = b - tb, snapy = target;
- break;
- }
+ if (snapy == NULL) {
+ /* vertical snapping */
+ if (l < tr && r > tl) {
+ switch (corn) {
+ case OB_CORNER_TOPLEFT:
+ case OB_CORNER_TOPRIGHT:
+ dlt = t;
+ drb = b + *h - c->frame->area.height;
+ if (b < tt && drb >= tt &&
+ drb < tt + resist)
+ *h = tt - t, snapy = target;
+ break;
+ case OB_CORNER_BOTTOMLEFT:
+ case OB_CORNER_BOTTOMRIGHT:
+ dlt = t - *h + c->frame->area.height;
+ drb = b;
+ if (t > tb && dlt <= tb &&
+ dlt > tb - resist)
+ *h = b - tb, snapy = target;
+ break;
}
}
-
- /* snapped both ways */
- if (snapx && snapy) break;
}
+
+ /* snapped both ways */
+ if (snapx && snapy) break;
}
}
-void resist_size_monitors(ObClient *c, gint *w, gint *h, ObCorner corn)
+void resist_size_monitors(ObClient *c, gint resist, gint *w, gint *h,
+ ObCorner corn)
{
gint l, t, r, b; /* my left, top, right and bottom sides */
gint dlt, drb; /* my destination left/top and right/bottom sides */
gint incw, inch;
guint i;
+ if (!resist) return;
+
l = RECT_LEFT(c->frame->area);
r = RECT_RIGHT(c->frame->area);
t = RECT_TOP(c->frame->area);
pr = RECT_RIGHT(*parea);
pb = RECT_BOTTOM(*parea);
- if (config_resist_edge) {
- /* horizontal snapping */
- switch (corn) {
- case OB_CORNER_TOPLEFT:
- case OB_CORNER_BOTTOMLEFT:
- dlt = l;
- drb = r + *w - c->frame->area.width;
- if (r <= ar && drb > ar && drb <= ar + config_resist_edge)
- *w = ar - l + 1;
- else if (r <= pr && drb > pr && drb <= pr + config_resist_edge)
- *w = pr - l + 1;
- break;
- case OB_CORNER_TOPRIGHT:
- case OB_CORNER_BOTTOMRIGHT:
- dlt = l - *w + c->frame->area.width;
- drb = r;
- if (l >= al && dlt < al && dlt >= al - config_resist_edge)
- *w = r - al + 1;
- else if (l >= pl && dlt < pl && dlt >= pl - config_resist_edge)
- *w = r - pl + 1;
- break;
- }
+ /* horizontal snapping */
+ switch (corn) {
+ case OB_CORNER_TOPLEFT:
+ case OB_CORNER_BOTTOMLEFT:
+ dlt = l;
+ drb = r + *w - c->frame->area.width;
+ if (r <= ar && drb > ar && drb <= ar + resist)
+ *w = ar - l + 1;
+ else if (r <= pr && drb > pr && drb <= pr + resist)
+ *w = pr - l + 1;
+ break;
+ case OB_CORNER_TOPRIGHT:
+ case OB_CORNER_BOTTOMRIGHT:
+ dlt = l - *w + c->frame->area.width;
+ drb = r;
+ if (l >= al && dlt < al && dlt >= al - resist)
+ *w = r - al + 1;
+ else if (l >= pl && dlt < pl && dlt >= pl - resist)
+ *w = r - pl + 1;
+ break;
+ }
- /* vertical snapping */
- switch (corn) {
- case OB_CORNER_TOPLEFT:
- case OB_CORNER_TOPRIGHT:
- dlt = t;
- drb = b + *h - c->frame->area.height;
- if (b <= ab && drb > ab && drb <= ab + config_resist_edge)
- *h = ab - t + 1;
- else if (b <= pb && drb > pb && drb <= pb + config_resist_edge)
- *h = pb - t + 1;
- break;
- case OB_CORNER_BOTTOMLEFT:
- case OB_CORNER_BOTTOMRIGHT:
- dlt = t - *h + c->frame->area.height;
- drb = b;
- if (t >= at && dlt < at && dlt >= at - config_resist_edge)
- *h = b - at + 1;
- else if (t >= pt && dlt < pt && dlt >= pt - config_resist_edge)
- *h = b - pt + 1;
- break;
- }
+ /* vertical snapping */
+ switch (corn) {
+ case OB_CORNER_TOPLEFT:
+ case OB_CORNER_TOPRIGHT:
+ dlt = t;
+ drb = b + *h - c->frame->area.height;
+ if (b <= ab && drb > ab && drb <= ab + resist)
+ *h = ab - t + 1;
+ else if (b <= pb && drb > pb && drb <= pb + resist)
+ *h = pb - t + 1;
+ break;
+ case OB_CORNER_BOTTOMLEFT:
+ case OB_CORNER_BOTTOMRIGHT:
+ dlt = t - *h + c->frame->area.height;
+ drb = b;
+ if (t >= at && dlt < at && dlt >= at - resist)
+ *h = b - at + 1;
+ else if (t >= pt && dlt < pt && dlt >= pt - resist)
+ *h = b - pt + 1;
+ break;
}
}
}