]> Dogcows Code - chaz/openbox/blob - openbox/actions/resizerelative.c
more using g_slice_new() instead of g_new()
[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(xmlNodePtr node);
15 static void free_func(gpointer options);
16 static gboolean run_func(ObActionsData *data, gpointer options);
17
18 void action_resizerelative_startup(void)
19 {
20 actions_register("ResizeRelative", setup_func, free_func, run_func);
21 }
22
23 static gpointer setup_func(xmlNodePtr node)
24 {
25 xmlNodePtr n;
26 Options *o;
27
28 o = g_slice_new0(Options);
29
30 if ((n = obt_xml_find_node(node, "left")))
31 o->left = obt_xml_node_int(n);
32 if ((n = obt_xml_find_node(node, "right")))
33 o->right = obt_xml_node_int(n);
34 if ((n = obt_xml_find_node(node, "top")) ||
35 (n = obt_xml_find_node(node, "up")))
36 o->top = obt_xml_node_int(n);
37 if ((n = obt_xml_find_node(node, "bottom")) ||
38 (n = obt_xml_find_node(node, "down")))
39 o->bottom = obt_xml_node_int(n);
40
41 return o;
42 }
43
44 static void free_func(gpointer o)
45 {
46 g_slice_free(Options, o);
47 }
48
49 /* Always return FALSE because its not interactive */
50 static gboolean run_func(ObActionsData *data, gpointer options)
51 {
52 Options *o = options;
53
54 if (data->client) {
55 ObClient *c = data->client;
56 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
57
58 x = c->area.x;
59 y = c->area.y;
60 ow = c->area.width;
61 xoff = -o->left * c->size_inc.width;
62 nw = ow + o->right * c->size_inc.width
63 + o->left * c->size_inc.width;
64 oh = c->area.height;
65 yoff = -o->top * c->size_inc.height;
66 nh = oh + o->bottom * c->size_inc.height
67 + o->top * c->size_inc.height;
68
69 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
70 xoff = xoff == 0 ? 0 :
71 (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
72 yoff = yoff == 0 ? 0 :
73 (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
74
75 actions_client_move(data, TRUE);
76 client_move_resize(c, x + xoff, y + yoff, nw, nh);
77 actions_client_move(data, FALSE);
78 }
79
80 return FALSE;
81 }
This page took 0.032946 seconds and 4 git commands to generate.