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 void free_func(gpointer options);
16 static gboolean run_func(ObActionsData *data, gpointer options);
18 void action_resizerelative_startup(void)
20 actions_register("ResizeRelative", setup_func, free_func, run_func);
23 static gpointer setup_func(xmlNodePtr node)
28 o = g_slice_new0(Options);
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);
44 static void free_func(gpointer o)
46 g_slice_free(Options, o);
49 /* Always return FALSE because its not interactive */
50 static gboolean run_func(ObActionsData *data, gpointer options)
55 ObClient *c = data->client;
56 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
61 xoff = -o->left * c->size_inc.width;
62 nw = ow + o->right * c->size_inc.width
63 + o->left * c->size_inc.width;
65 yoff = -o->top * c->size_inc.height;
66 nh = oh + o->bottom * c->size_inc.height
67 + o->top * c->size_inc.height;
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));
75 actions_client_move(data, TRUE);
76 client_move_resize(c, x + xoff, y + yoff, nw, nh);
77 actions_client_move(data, FALSE);