]> Dogcows Code - chaz/openbox/blob - openbox/actions/resizerelative.c
fix the remaining reversed actions_client_move
[chaz/openbox] / openbox / actions / resizerelative.c
1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include <stdlib.h> /* for atoi */
6
7 typedef struct {
8 gint left;
9 gint right;
10 gint top;
11 gint bottom;
12 } Options;
13
14 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
15 static void free_func(gpointer options);
16 static gboolean run_func(ObActionsData *data, gpointer options);
17
18 void action_resizerelative_startup()
19 {
20 actions_register("ResizeRelative",
21 setup_func,
22 free_func,
23 run_func,
24 NULL, NULL);
25 }
26
27 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
28 {
29 xmlNodePtr n;
30 Options *o;
31
32 o = g_new0(Options, 1);
33
34 if ((n = parse_find_node("left", node)))
35 o->left = parse_int(doc, n);
36 if ((n = parse_find_node("right", node)))
37 o->right = parse_int(doc, n);
38 if ((n = parse_find_node("top", node)))
39 o->top = parse_int(doc, n);
40 if ((n = parse_find_node("bottom", node)))
41 o->bottom = parse_int(doc, n);
42
43 return o;
44 }
45
46 static void free_func(gpointer options)
47 {
48 Options *o = options;
49
50 g_free(o);
51 }
52
53 /* Always return FALSE because its not interactive */
54 static gboolean run_func(ObActionsData *data, gpointer options)
55 {
56 Options *o = options;
57
58 if (data->client) {
59 ObClient *c = data->client;
60 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
61
62 x = c->area.x;
63 y = c->area.y;
64 ow = c->area.width;
65 xoff = -o->left * c->size_inc.width;
66 nw = ow + o->right * c->size_inc.width
67 + o->left * c->size_inc.width;
68 oh = c->area.height;
69 yoff = -o->top * c->size_inc.height;
70 nh = oh + o->bottom * c->size_inc.height
71 + o->top * c->size_inc.height;
72
73 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
74 xoff = xoff == 0 ? 0 :
75 (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
76 yoff = yoff == 0 ? 0 :
77 (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
78
79 actions_client_move(data, TRUE);
80 client_move_resize(c, x + xoff, y + yoff, nw, nh);
81 actions_client_move(data, FALSE);
82 }
83
84 return FALSE;
85 }
This page took 0.04128 seconds and 5 git commands to generate.