1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include "openbox/config.h"
6 #include <stdlib.h> /* for atoi */
19 static gpointer setup_func(xmlNodePtr node);
20 static void free_func(gpointer options);
21 static gboolean run_func(ObActionsData *data, gpointer options);
23 void action_resizerelative_startup(void)
25 actions_register("ResizeRelative", setup_func, free_func, run_func);
28 static void xml_node_relative(xmlNodePtr n, gint *num, gint *denom)
32 s = obt_xml_node_string(n);
33 config_parse_relative_number(s, num, denom);
37 static gpointer setup_func(xmlNodePtr node)
42 o = g_slice_new0(Options);
44 if ((n = obt_xml_find_node(node, "left")))
45 xml_node_relative(n, &o->left, &o->left_denom);
46 if ((n = obt_xml_find_node(node, "right")))
47 xml_node_relative(n, &o->right, &o->right_denom);
48 if ((n = obt_xml_find_node(node, "top")) ||
49 (n = obt_xml_find_node(node, "up")))
50 xml_node_relative(n, &o->top, &o->top_denom);
51 if ((n = obt_xml_find_node(node, "bottom")) ||
52 (n = obt_xml_find_node(node, "down")))
53 xml_node_relative(n, &o->bottom, &o->bottom_denom);
58 static void free_func(gpointer o)
60 g_slice_free(Options, o);
63 /* Always return FALSE because its not interactive */
64 static gboolean run_func(ObActionsData *data, gpointer options)
69 ObClient *c = data->client;
70 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
71 gint left = o->left, right = o->right, top = o->top, bottom = o->bottom;
74 left = (left * c->area.width / c->size_inc.width) / o->left_denom;
76 right = (right * c->area.width / c->size_inc.width) / o->right_denom;
78 top = (top * c->area.height / c->size_inc.height) / o->top_denom;
80 bottom = (bottom * c->area.height / c->size_inc.height) / o->bottom_denom;
85 xoff = -left * c->size_inc.width;
86 nw = ow + right * c->size_inc.width
87 + left * c->size_inc.width;
89 yoff = -top * c->size_inc.height;
90 nh = oh + bottom * c->size_inc.height
91 + top * c->size_inc.height;
93 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
94 xoff = xoff == 0 ? 0 :
95 (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
96 yoff = yoff == 0 ? 0 :
97 (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
99 actions_client_move(data, TRUE);
100 client_move_resize(c, x + xoff, y + yoff, nw, nh);
101 actions_client_move(data, FALSE);