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(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
15 static void free_func(gpointer options);
16 static gboolean run_func(ObActionsData *data, gpointer options);
18 void action_resizerelative_startup()
20 actions_register("ResizeRelative",
27 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
32 o = g_new0(Options, 1);
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);
46 static void free_func(gpointer options)
53 /* Always return FALSE because its not interactive */
54 static gboolean run_func(ObActionsData *data, gpointer options)
59 ObClient *c = data->client;
60 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
65 xoff = -o->left * c->size_inc.width;
66 nw = ow + o->right * c->size_inc.width
67 + o->left * c->size_inc.width;
69 yoff = -o->top * c->size_inc.height;
70 nh = oh + o->bottom * c->size_inc.height
71 + o->top * c->size_inc.height;
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));
79 actions_client_move(data, TRUE);
80 client_move_resize(c, x + xoff, y + yoff, nw, nh);
81 actions_client_move(data, FALSE);