summaryrefslogtreecommitdiff
path: root/openbox/actions/resizerelative.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbox/actions/resizerelative.c')
-rw-r--r--openbox/actions/resizerelative.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/openbox/actions/resizerelative.c b/openbox/actions/resizerelative.c
index 1d42df23..d5910ceb 100644
--- a/openbox/actions/resizerelative.c
+++ b/openbox/actions/resizerelative.c
@@ -2,13 +2,18 @@
#include "openbox/client.h"
#include "openbox/screen.h"
#include "openbox/frame.h"
+#include "openbox/config.h"
#include <stdlib.h> /* for atoi */
typedef struct {
gint left;
+ gint left_denom;
gint right;
+ gint right_denom;
gint top;
+ gint top_denom;
gint bottom;
+ gint bottom_denom;
} Options;
static gpointer setup_func(xmlNodePtr node);
@@ -20,6 +25,15 @@ void action_resizerelative_startup(void)
actions_register("ResizeRelative", setup_func, free_func, run_func);
}
+static void xml_node_relative(xmlNodePtr n, gint *num, gint *denom)
+{
+ gchar *s;
+
+ s = obt_xml_node_string(n);
+ config_parse_relative_number(s, num, denom);
+ g_free(s);
+}
+
static gpointer setup_func(xmlNodePtr node)
{
xmlNodePtr n;
@@ -28,15 +42,15 @@ static gpointer setup_func(xmlNodePtr node)
o = g_slice_new0(Options);
if ((n = obt_xml_find_node(node, "left")))
- o->left = obt_xml_node_int(n);
+ xml_node_relative(n, &o->left, &o->left_denom);
if ((n = obt_xml_find_node(node, "right")))
- o->right = obt_xml_node_int(n);
+ xml_node_relative(n, &o->right, &o->right_denom);
if ((n = obt_xml_find_node(node, "top")) ||
(n = obt_xml_find_node(node, "up")))
- o->top = obt_xml_node_int(n);
+ xml_node_relative(n, &o->top, &o->top_denom);
if ((n = obt_xml_find_node(node, "bottom")) ||
(n = obt_xml_find_node(node, "down")))
- o->bottom = obt_xml_node_int(n);
+ xml_node_relative(n, &o->bottom, &o->bottom_denom);
return o;
}
@@ -54,17 +68,27 @@ static gboolean run_func(ObActionsData *data, gpointer options)
if (data->client) {
ObClient *c = data->client;
gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
+ gint left = o->left, right = o->right, top = o->top, bottom = o->bottom;
+
+ if (o->left_denom)
+ left = (left * c->area.width / c->size_inc.width) / o->left_denom;
+ if (o->right_denom)
+ right = (right * c->area.width / c->size_inc.width) / o->right_denom;
+ if (o->top_denom)
+ top = (top * c->area.height / c->size_inc.height) / o->top_denom;
+ if (o->bottom_denom)
+ bottom = (bottom * c->area.height / c->size_inc.height) / o->bottom_denom;
x = c->area.x;
y = c->area.y;
ow = c->area.width;
- xoff = -o->left * c->size_inc.width;
- nw = ow + o->right * c->size_inc.width
- + o->left * c->size_inc.width;
+ xoff = -left * c->size_inc.width;
+ nw = ow + right * c->size_inc.width
+ + left * c->size_inc.width;
oh = c->area.height;
- yoff = -o->top * c->size_inc.height;
- nh = oh + o->bottom * c->size_inc.height
- + o->top * c->size_inc.height;
+ yoff = -top * c->size_inc.height;
+ nh = oh + bottom * c->size_inc.height
+ + top * c->size_inc.height;
client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
xoff = xoff == 0 ? 0 :