]> Dogcows Code - chaz/openbox/blob - plugins/resistance.c
rm the edge_resistance option.. just dont load the plugin!
[chaz/openbox] / plugins / resistance.c
1 #include "../kernel/dispatch.h"
2 #include "../kernel/client.h"
3 #include "../kernel/frame.h"
4 #include "../kernel/stacking.h"
5 #include "../kernel/screen.h"
6 #include <glib.h>
7
8 static int resistance = 10;
9 static gboolean window_resistance = TRUE; /* window-to-window */
10
11 static void resist(Client *c, int *x, int *y)
12 {
13 GList *it;
14 Rect *area;
15 int l, t, r, b; /* requested edges */
16 int al, at, ar, ab; /* screen area edges */
17 int cl, ct, cr, cb; /* current edges */
18 int w, h; /* current size */
19 gboolean snapx = FALSE, snapy = FALSE;
20
21 w = c->frame->area.width;
22 h = c->frame->area.height;
23
24 l = *x;
25 t = *y;
26 r = l + w - 1;
27 b = t + h - 1;
28
29 cl = c->frame->area.x;
30 ct = c->frame->area.y;
31 cr = cl + c->frame->area.width - 1;
32 cb = ct + c->frame->area.height - 1;
33
34 /* snap to other clients */
35 if (window_resistance)
36 for (it = stacking_list; it != NULL; it = it->next) {
37 Client *target;
38 int tl, tt, tr, tb; /* 1 past the target's edges on each side */
39
40 target = it->data;
41
42 tl = target->frame->area.x - 1;
43 tt = target->frame->area.y - 1;
44 tr = tl + target->frame->area.width + 1;
45 tb = tt + target->frame->area.height + 1;
46
47 /* snapx and snapy ensure that the window snaps to the top-most
48 window edge available, without going all the way from
49 bottom-to-top in the stacking list
50 */
51 if (!snapx && cl >= tr && l < tr && l >= tr - resistance)
52 *x = tr, snapx = TRUE;
53 else if (!snapx && cr <= tl && r > tl && r <= tl + resistance)
54 *x = tl - w + 1, snapx = TRUE;
55 else if (!snapy && ct >= tb && t < tb && t >= tb - resistance)
56 *y = tb, snapy = TRUE;
57 else if (!snapy && cb <= tt && b > tt && b <= tt + resistance)
58 *y = tt - h + 1, snapy = TRUE;
59
60 if (snapx && snapy) break;
61 }
62
63 /* get the screen boundaries */
64 area = screen_area(c->desktop);
65 al = area->x;
66 at = area->y;
67 ar = al + area->width - 1;
68 ab = at + area->height - 1;
69
70 /* snap to screen edges */
71 if (cl >= al && l < al && l >= al - resistance)
72 *x = al;
73 else if (cr <= ar && r > ar && r <= ar + resistance)
74 *x = ar - w + 1;
75 if (ct >= at && t < at && t >= at - resistance)
76 *y = at;
77 else if (cb <= ab && b > ab && b < ab + resistance)
78 *y = ab - h + 1;
79 }
80
81 static void event(ObEvent *e, void *foo)
82 {
83 g_assert(e->type == Event_Client_Moving);
84
85 resist(e->data.c.client, &e->data.c.num[0], &e->data.c.num[1]);
86 }
87
88 void plugin_startup()
89 {
90 dispatch_register(Event_Client_Moving, (EventHandler)event, NULL);
91 }
92
93 void plugin_shutdown()
94 {
95 dispatch_register(0, (EventHandler)event, NULL);
96 }
This page took 0.041028 seconds and 5 git commands to generate.