diff options
Diffstat (limited to 'openbox')
| -rw-r--r-- | openbox/config.c | 20 | ||||
| -rw-r--r-- | openbox/config.h | 5 | ||||
| -rw-r--r-- | openbox/moveresize.c | 25 | ||||
| -rw-r--r-- | openbox/plugin.c | 1 | ||||
| -rw-r--r-- | openbox/resist.c | 256 | ||||
| -rw-r--r-- | openbox/resist.h | 11 |
6 files changed, 306 insertions, 12 deletions
diff --git a/openbox/config.c b/openbox/config.c index a3c236fc..d03ba031 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -38,6 +38,9 @@ gint config_mouse_dclicktime; gchar *config_menu_path; +gint config_resist_win; +gint config_resist_edge; + gchar *expand_tilde(const gchar *f) { if (!f) @@ -348,6 +351,18 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d) } } +static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, + void *d) +{ + xmlNodePtr n; + + node = node->xmlChildrenNode; + if ((n = parse_find_node("strength", node))) + config_resist_win = parse_int(doc, n); + if ((n = parse_find_node("screen_edge_strength", node))) + config_resist_edge = parse_int(doc, n); +} + void config_startup(ObParseInst *i) { config_focus_new = TRUE; @@ -395,6 +410,11 @@ void config_startup(ObParseInst *i) parse_register(i, "mouse", parse_mouse, NULL); + config_resist_win = 10; + config_resist_edge = 10; + + parse_register(i, "resistance", parse_resistance, NULL); + config_menu_path = NULL; parse_register(i, "menu", parse_menu, NULL); diff --git a/openbox/config.h b/openbox/config.h index ab1b7493..98a5340b 100644 --- a/openbox/config.h +++ b/openbox/config.h @@ -67,6 +67,11 @@ extern gint config_mouse_threshold; double-click */ extern gint config_mouse_dclicktime; +/*! Number of pixels to resist while crossing another window's edge */ +gint config_resist_win; +/*! Number of pixels to resist while crossing a screen's edge */ +gint config_resist_edge; + /*! User-specified path to the menu file */ extern gchar *config_menu_path; diff --git a/openbox/moveresize.c b/openbox/moveresize.c index 564bf711..14abd5cd 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -6,6 +6,7 @@ #include "frame.h" #include "dispatch.h" #include "openbox.h" +#include "resist.h" #include "popup.h" #include "config.h" #include "render/render.h" @@ -72,12 +73,8 @@ void moveresize_start(ObClient *c, int x, int y, guint b, guint32 cnr) start_ch = c->area.height; start_x = x; start_y = y; - if (corner == prop_atoms.net_wm_moveresize_move_keyboard || - corner == prop_atoms.net_wm_moveresize_size_keyboard) - button = 0; /* mouse can't end it without being pressed first */ - else - button = b; corner = cnr; + button = b; if (corner == prop_atoms.net_wm_moveresize_move || corner == prop_atoms.net_wm_moveresize_move_keyboard) { @@ -145,10 +142,13 @@ void moveresize_end(gboolean cancel) moveresize_client = NULL; } -static void do_move() +static void do_move(gboolean resist) { Rect *a; + if (resist) + resist_move(moveresize_client, &cur_x, &cur_y); + dispatch_move(moveresize_client, &cur_x, &cur_y); /* get where the client should be */ @@ -164,7 +164,7 @@ static void do_move() moveresize_client->frame->area.y - a->y); } -static void do_resize() +static void do_resize(gboolean resist) { /* dispatch_resize needs the frame size */ cur_x += moveresize_client->frame->size.left + @@ -172,6 +172,9 @@ static void do_resize() cur_y += moveresize_client->frame->size.top + moveresize_client->frame->size.bottom; + if (resist) + resist_size(moveresize_client, &cur_x, &cur_y, lockcorner); + dispatch_resize(moveresize_client, &cur_x, &cur_y, lockcorner); cur_x -= moveresize_client->frame->size.left + @@ -207,7 +210,7 @@ void moveresize_event(XEvent *e) if (moving) { cur_x = start_cx + e->xmotion.x_root - start_x; cur_y = start_cy + e->xmotion.y_root - start_y; - do_move(); + do_move(TRUE); } else { if (corner == prop_atoms.net_wm_moveresize_size_topleft) { cur_x = start_cw - (e->xmotion.x_root - start_x); @@ -250,7 +253,7 @@ void moveresize_event(XEvent *e) } else g_assert_not_reached(); - do_resize(); + do_resize(TRUE); } } else if (e->type == KeyPress) { if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE)) @@ -269,7 +272,7 @@ void moveresize_event(XEvent *e) cur_y -= MAX(4, moveresize_client->size_inc.height); else return; - do_resize(); + do_resize(FALSE); } else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) { if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT)) cur_x += 4; @@ -281,7 +284,7 @@ void moveresize_event(XEvent *e) cur_y -= 4; else return; - do_move(); + do_move(FALSE); } } } diff --git a/openbox/plugin.c b/openbox/plugin.c index 9b8e2d59..18c55064 100644 --- a/openbox/plugin.c +++ b/openbox/plugin.c @@ -158,7 +158,6 @@ void plugin_loadall(ObParseInst *i) if (io == NULL) { /* load the default plugins */ plugin_open("placement", i); - plugin_open("resistance", i); /* XXX rm me when the parser loads me magically */ plugin_open("client_menu", i); diff --git a/openbox/resist.c b/openbox/resist.c new file mode 100644 index 00000000..a41c5a9d --- /dev/null +++ b/openbox/resist.c @@ -0,0 +1,256 @@ +#include "dispatch.h" +#include "client.h" +#include "frame.h" +#include "stacking.h" +#include "screen.h" +#include "config.h" +#include "parser/parse.h" + +#include <glib.h> + +void resist_move(ObClient *c, gint *x, gint *y) +{ + GList *it; + Rect *area; + guint i; + gint l, t, r, b; /* requested edges */ + gint al, at, ar, ab; /* screen area edges */ + gint cl, ct, cr, cb; /* current edges */ + gint w, h; /* current size */ + ObClient *snapx = NULL, *snapy = NULL; + + w = c->frame->area.width; + h = c->frame->area.height; + + l = *x; + t = *y; + r = l + w - 1; + b = t + h - 1; + + cl = c->frame->area.x; + ct = c->frame->area.y; + cr = cl + c->frame->area.width - 1; + cb = ct + c->frame->area.height - 1; + + /* snap to other clients */ + if (config_resist_win) + for (it = stacking_list; it != NULL; it = it->next) { + ObClient *target; + int 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; + + tl = target->frame->area.x - 1; + tt = target->frame->area.y - 1; + tr = tl + target->frame->area.width + 1; + tb = tt + target->frame->area.height + 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; + } + } + } + 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 (snapx && snapy) break; + } + + /* get the screen boundaries */ + if (config_resist_edge) { + for (i = 0; i < screen_num_monitors; ++i) { + area = screen_area_monitor(c->desktop, i); + + if (!RECT_INTERSECTS_RECT(*area, c->frame->area)) + continue; + + al = area->x; + at = area->y; + ar = al + area->width - 1; + ab = at + area->height - 1; + + /* snap to screen edges */ + 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; + 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; + } + } +} + +void resist_size(ObClient *c, gint *w, gint *h, ObCorner corn) +{ + GList *it; + ObClient *target; /* target */ + gint l, t, r, b; /* my left, top, right and bottom sides */ + gint dlt, drb; /* my destination left/top and right/bottom sides */ + gint tl, tt, tr, tb; /* target's left, top, right and bottom bottom sides*/ + Rect *area; + gint al, at, ar, ab; /* screen boundaries */ + ObClient *snapx = NULL, *snapy = NULL; + + /* don't snap windows with size increments */ + if (c->size_inc.width > 1 || c->size_inc.height > 1) + return; + + l = c->frame->area.x; + r = l + c->frame->area.width - 1; + t = c->frame->area.y; + b = t + c->frame->area.height - 1; + + /* get the screen boundaries */ + area = screen_area(c->desktop); + al = area->x; + at = area->y; + ar = al + area->width - 1; + ab = at + area->height - 1; + + /* snap to other windows */ + if (config_resist_win) { + for (it = stacking_list; it != NULL; it = it->next) { + if (!WINDOW_IS_CLIENT(it->data)) + continue; + target = it->data; + + /* don't snap to invisibles or ourself */ + if (!target->frame->visible || target == c) continue; + + tl = target->frame->area.x; + tr = target->frame->area.x + target->frame->area.width - 1; + tt = target->frame->area.y; + tb = target->frame->area.y + target->frame->area.height - 1; + + 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; + } + } + } + + 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; + } + } + } + + /* snapped both ways */ + if (snapx && snapy) break; + } + } + + /* snap to screen edges */ + + 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; + 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; + 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; + 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; + break; + } + } +} diff --git a/openbox/resist.h b/openbox/resist.h new file mode 100644 index 00000000..4031ac24 --- /dev/null +++ b/openbox/resist.h @@ -0,0 +1,11 @@ +#ifndef ob__resist_h +#define ob__resist_h + +struct _ObClient; + +#include <glib.h> + +void resist_move(struct _ObClient *c, gint *x, gint *y); +void resist_size(struct _ObClient *c, gint *w, gint *h, ObCorner corn); + +#endif |
