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 */
14 static gpointer setup_func(xmlNodePtr node);
15 static gboolean run_func(ObActionsData *data, gpointer options);
17 void action_resizerelative_startup(void)
19 actions_register("ResizeRelative", setup_func, g_free, run_func,
23 static gpointer setup_func(xmlNodePtr node)
28 o = g_new0(Options, 1);
30 if ((n = obt_parse_find_node(node, "left")))
31 o->left = obt_parse_node_int(n);
32 if ((n = obt_parse_find_node(node, "right")))
33 o->right = obt_parse_node_int(n);
34 if ((n = obt_parse_find_node(node, "top")) ||
35 (n = obt_parse_find_node(node, "up")))
36 o->top = obt_parse_node_int(n);
37 if ((n = obt_parse_find_node(node, "bottom")) ||
38 (n = obt_parse_find_node(node, "down")))
39 o->bottom = obt_parse_node_int(n);
44 /* Always return FALSE because its not interactive */
45 static gboolean run_func(ObActionsData *data, gpointer options)
50 ObClient *c = data->client;
51 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
56 xoff = -o->left * c->size_inc.width;
57 nw = ow + o->right * c->size_inc.width
58 + o->left * c->size_inc.width;
60 yoff = -o->top * c->size_inc.height;
61 nh = oh + o->bottom * c->size_inc.height
62 + o->top * c->size_inc.height;
64 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
65 xoff = xoff == 0 ? 0 :
66 (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
67 yoff = yoff == 0 ? 0 :
68 (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
70 actions_client_move(data, TRUE);
71 client_move_resize(c, x + xoff, y + yoff, nw, nh);
72 actions_client_move(data, FALSE);