1 #include "openbox/action.h"
2 #include "openbox/action_value.h"
3 #include "openbox/client.h"
4 #include "openbox/screen.h"
5 #include "openbox/frame.h"
6 #include "openbox/config.h"
19 static gpointer setup_func(GHashTable *config);
20 static void free_func(gpointer options);
21 static gboolean run_func(ObActionData *data, gpointer options);
23 void action_resizerelative_startup(void)
25 action_register("ResizeRelative", setup_func, free_func, run_func);
28 static gpointer setup_func(GHashTable *config)
33 o = g_slice_new0(Options);
35 v = g_hash_table_lookup(config, "left");
36 if (v && action_value_is_string(v))
37 action_value_fraction(v, &o->left, &o->left_denom);
38 v = g_hash_table_lookup(config, "right");
39 if (v && action_value_is_string(v))
40 action_value_fraction(v, &o->right, &o->right_denom);
41 v = g_hash_table_lookup(config, "top");
42 if (v && action_value_is_string(v))
43 action_value_fraction(v, &o->top, &o->top_denom);
44 v = g_hash_table_lookup(config, "bottom");
45 if (v && action_value_is_string(v))
46 action_value_fraction(v, &o->bottom, &o->bottom_denom);
51 static void free_func(gpointer o)
53 g_slice_free(Options, o);
56 /* Always return FALSE because its not interactive */
57 static gboolean run_func(ObActionData *data, gpointer options)
62 ObClient *c = data->client;
63 gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
64 gint left = o->left, right = o->right, top = o->top, bottom = o->bottom;
67 left = left * c->area.width / o->left_denom;
69 right = right * c->area.width / o->right_denom;
71 top = top * c->area.height / o->top_denom;
73 bottom = bottom * c->area.height / o->bottom_denom;
75 // When resizing, if the resize has a non-zero value then make sure it
76 // is at least as big as the size increment so the window does actually
81 xoff = -MAX(left, (left ? c->size_inc.width : 0));
82 nw = ow + MAX(right + left, (right + left ? c->size_inc.width : 0));
84 yoff = -MAX(top, (top ? c->size_inc.height : 0));
85 nh = oh + MAX(bottom + top, (bottom + top ? c->size_inc.height : 0));
87 client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
88 xoff = xoff == 0 ? 0 :
89 (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
90 yoff = yoff == 0 ? 0 :
91 (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
93 action_client_move(data, TRUE);
94 client_move_resize(c, x + xoff, y + yoff, nw, nh);
95 action_client_move(data, FALSE);