Add support for using relative expressions in move and resize actions
Have MoveResizeTo use config_parse_gravity_coord instead of duplicating it locally Allow MoveResizeTo positions and sizes and per app positions to be relative to screen size Rename to config_parse_relative_number so it can be used for sizes too Add relative numbers to width/height in MoveResizeTo Add relative numbers to MoveRelative Add relative numbers to ResizeRelative, these are for the client size, not screen size
This commit is contained in:
parent
1c637efcbb
commit
7a679dd198
7 changed files with 113 additions and 61 deletions
|
@ -2,11 +2,14 @@
|
|||
#include "openbox/client.h"
|
||||
#include "openbox/screen.h"
|
||||
#include "openbox/frame.h"
|
||||
#include "openbox/config.h"
|
||||
#include <stdlib.h> /* for atoi */
|
||||
|
||||
typedef struct {
|
||||
gint x;
|
||||
gint x_denom;
|
||||
gint y;
|
||||
gint y_denom;
|
||||
} Options;
|
||||
|
||||
static gpointer setup_func(xmlNodePtr node);
|
||||
|
@ -22,13 +25,20 @@ static gpointer setup_func(xmlNodePtr node)
|
|||
{
|
||||
xmlNodePtr n;
|
||||
Options *o;
|
||||
gchar *s;
|
||||
|
||||
o = g_slice_new0(Options);
|
||||
|
||||
if ((n = obt_xml_find_node(node, "x")))
|
||||
o->x = obt_xml_node_int(n);
|
||||
if ((n = obt_xml_find_node(node, "y")))
|
||||
o->y = obt_xml_node_int(n);
|
||||
if ((n = obt_xml_find_node(node, "x"))) {
|
||||
s = obt_xml_node_string(n);
|
||||
config_parse_relative_number(s, &o->x, &o->x_denom);
|
||||
g_free(s);
|
||||
}
|
||||
if ((n = obt_xml_find_node(node, "y"))) {
|
||||
s = obt_xml_node_string(n);
|
||||
config_parse_relative_number(s, &o->y, &o->y_denom);
|
||||
g_free(s);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
@ -48,8 +58,19 @@ static gboolean run_func(ObActionsData *data, gpointer options)
|
|||
gint x, y, lw, lh, w, h;
|
||||
|
||||
c = data->client;
|
||||
x = c->area.x + o->x;
|
||||
y = c->area.y + o->y;
|
||||
x = o->x;
|
||||
y = o->y;
|
||||
if (o->x_denom || o->y_denom) {
|
||||
const Rect *carea;
|
||||
|
||||
carea = screen_area(c->desktop, client_monitor(c), NULL);
|
||||
if (o->x_denom)
|
||||
x = (x * carea->width) / o->x_denom;
|
||||
if (o->y_denom)
|
||||
y = (y * carea->height) / o->y_denom;
|
||||
}
|
||||
x = c->area.x + x;
|
||||
y = c->area.y + y;
|
||||
w = c->area.width;
|
||||
h = c->area.height;
|
||||
client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "openbox/client.h"
|
||||
#include "openbox/screen.h"
|
||||
#include "openbox/frame.h"
|
||||
#include "openbox/config.h"
|
||||
#include <stdlib.h> /* for atoi */
|
||||
|
||||
enum {
|
||||
|
@ -12,14 +13,12 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
gboolean xcenter;
|
||||
gboolean ycenter;
|
||||
gboolean xopposite;
|
||||
gboolean yopposite;
|
||||
gint x;
|
||||
gint y;
|
||||
GravityCoord x;
|
||||
GravityCoord y;
|
||||
gint w;
|
||||
gint w_denom;
|
||||
gint h;
|
||||
gint h_denom;
|
||||
gint monitor;
|
||||
} Options;
|
||||
|
||||
|
@ -36,53 +35,34 @@ void action_moveresizeto_startup(void)
|
|||
actions_register("MoveToCenter", setup_center_func, free_func, run_func);
|
||||
}
|
||||
|
||||
static void parse_coord(xmlNodePtr n, gint *pos,
|
||||
gboolean *opposite, gboolean *center)
|
||||
{
|
||||
gchar *s = obt_xml_node_string(n);
|
||||
if (g_ascii_strcasecmp(s, "current") != 0) {
|
||||
if (!g_ascii_strcasecmp(s, "center"))
|
||||
*center = TRUE;
|
||||
else {
|
||||
if (s[0] == '-')
|
||||
*opposite = TRUE;
|
||||
if (s[0] == '-' || s[0] == '+')
|
||||
*pos = atoi(s+1);
|
||||
else
|
||||
*pos = atoi(s);
|
||||
}
|
||||
}
|
||||
g_free(s);
|
||||
}
|
||||
|
||||
static gpointer setup_func(xmlNodePtr node)
|
||||
{
|
||||
xmlNodePtr n;
|
||||
Options *o;
|
||||
|
||||
o = g_slice_new0(Options);
|
||||
o->x = G_MININT;
|
||||
o->y = G_MININT;
|
||||
o->x.pos = G_MININT;
|
||||
o->y.pos = G_MININT;
|
||||
o->w = G_MININT;
|
||||
o->h = G_MININT;
|
||||
o->monitor = CURRENT_MONITOR;
|
||||
|
||||
if ((n = obt_xml_find_node(node, "x")))
|
||||
parse_coord(n, &o->x, &o->xopposite, &o->xcenter);
|
||||
config_parse_gravity_coord(n, &o->x);
|
||||
|
||||
if ((n = obt_xml_find_node(node, "y")))
|
||||
parse_coord(n, &o->y, &o->yopposite, &o->ycenter);
|
||||
config_parse_gravity_coord(n, &o->y);
|
||||
|
||||
if ((n = obt_xml_find_node(node, "width"))) {
|
||||
gchar *s = obt_xml_node_string(n);
|
||||
if (g_ascii_strcasecmp(s, "current") != 0)
|
||||
o->w = obt_xml_node_int(n);
|
||||
config_parse_relative_number(s, &o->w, &o->w_denom);
|
||||
g_free(s);
|
||||
}
|
||||
if ((n = obt_xml_find_node(node, "height"))) {
|
||||
gchar *s = obt_xml_node_string(n);
|
||||
if (g_ascii_strcasecmp(s, "current") != 0)
|
||||
o->h = obt_xml_node_int(n);
|
||||
config_parse_relative_number(s, &o->h, &o->h_denom);
|
||||
g_free(s);
|
||||
}
|
||||
|
||||
|
@ -141,9 +121,11 @@ static gboolean run_func(ObActionsData *data, gpointer options)
|
|||
|
||||
w = o->w;
|
||||
if (w == G_MININT) w = c->area.width;
|
||||
else if (o->w_denom) w = (w * area->width) / o->w_denom;
|
||||
|
||||
h = o->h;
|
||||
if (h == G_MININT) h = c->area.height;
|
||||
else if (o->h_denom) h = (h * area->height) / o->h_denom;
|
||||
|
||||
/* it might not be able to resize how they requested, so find out what
|
||||
it will actually be resized to */
|
||||
|
@ -155,16 +137,20 @@ static gboolean run_func(ObActionsData *data, gpointer options)
|
|||
w += c->frame->size.left + c->frame->size.right;
|
||||
h += c->frame->size.top + c->frame->size.bottom;
|
||||
|
||||
x = o->x;
|
||||
if (o->xcenter) x = (area->width - w) / 2;
|
||||
x = o->x.pos;
|
||||
if (o->x.denom)
|
||||
x = (x * area->width) / o->x.denom;
|
||||
if (o->x.center) x = (area->width - w) / 2;
|
||||
else if (x == G_MININT) x = c->frame->area.x - carea->x;
|
||||
else if (o->xopposite) x = area->width - w - x;
|
||||
else if (o->x.opposite) x = area->width - w - x;
|
||||
x += area->x;
|
||||
|
||||
y = o->y;
|
||||
if (o->ycenter) y = (area->height - h) / 2;
|
||||
y = o->y.pos;
|
||||
if (o->y.denom)
|
||||
y = (y * area->height) / o->y.denom;
|
||||
if (o->y.center) y = (area->height - h) / 2;
|
||||
else if (y == G_MININT) y = c->frame->area.y - carea->y;
|
||||
else if (o->yopposite) y = area->height - h - y;
|
||||
else if (o->y.opposite) y = area->height - h - y;
|
||||
y += area->y;
|
||||
|
||||
/* get the client's size back */
|
||||
|
@ -193,12 +179,12 @@ static gpointer setup_center_func(xmlNodePtr node)
|
|||
Options *o;
|
||||
|
||||
o = g_slice_new0(Options);
|
||||
o->x = G_MININT;
|
||||
o->y = G_MININT;
|
||||
o->x.pos = G_MININT;
|
||||
o->y.pos = G_MININT;
|
||||
o->w = G_MININT;
|
||||
o->h = G_MININT;
|
||||
o->monitor = -1;
|
||||
o->xcenter = TRUE;
|
||||
o->ycenter = TRUE;
|
||||
o->x.center = TRUE;
|
||||
o->y.center = TRUE;
|
||||
return o;
|
||||
}
|
||||
|
|
|
@ -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 :
|
||||
|
|
|
@ -154,18 +154,29 @@ void config_app_settings_copy_non_defaults(const ObAppSettings *src,
|
|||
}
|
||||
}
|
||||
|
||||
static void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c)
|
||||
void config_parse_relative_number(gchar *s, gint *num, gint *denom)
|
||||
{
|
||||
*num = strtol(s, &s, 10);
|
||||
|
||||
if (*s == '%') {
|
||||
*denom = 100;
|
||||
} else if (*s == '/') {
|
||||
*denom = atoi(s+1);
|
||||
}
|
||||
}
|
||||
|
||||
void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c)
|
||||
{
|
||||
gchar *s = obt_xml_node_string(node);
|
||||
if (!g_ascii_strcasecmp(s, "center"))
|
||||
c->center = TRUE;
|
||||
else {
|
||||
gchar *ps = s;
|
||||
if (s[0] == '-')
|
||||
c->opposite = TRUE;
|
||||
if (s[0] == '-' || s[0] == '+')
|
||||
c->pos = atoi(s+1);
|
||||
else
|
||||
c->pos = atoi(s);
|
||||
ps++;
|
||||
config_parse_relative_number(ps, &c->pos, &c->denom);
|
||||
}
|
||||
g_free(s);
|
||||
}
|
||||
|
|
|
@ -215,5 +215,10 @@ ObAppSettings* config_create_app_settings(void);
|
|||
src. */
|
||||
void config_app_settings_copy_non_defaults(const ObAppSettings *src,
|
||||
ObAppSettings *dest);
|
||||
/*! Parses an x geometry style position, with some extensions like ratios
|
||||
and percentages */
|
||||
void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c);
|
||||
/*! Parses a rational number or percentage into num and denom */
|
||||
void config_parse_relative_number(gchar *s, gint *num, gint *denom);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
typedef struct _GravityCoord {
|
||||
gint pos;
|
||||
gint denom;
|
||||
gboolean center;
|
||||
gboolean opposite;
|
||||
} GravityCoord;
|
||||
|
|
|
@ -406,6 +406,8 @@ static gboolean place_per_app_setting(ObClient *client, gint *x, gint *y,
|
|||
settings->position.x.pos;
|
||||
else
|
||||
*x = screen->x + settings->position.x.pos;
|
||||
if (settings->position.x.denom)
|
||||
*x = (*x * screen->width) / settings->position.x.denom;
|
||||
|
||||
if (settings->position.y.center)
|
||||
*y = screen->y + screen->height / 2 - client->area.height / 2;
|
||||
|
@ -414,6 +416,8 @@ static gboolean place_per_app_setting(ObClient *client, gint *x, gint *y,
|
|||
settings->position.y.pos;
|
||||
else
|
||||
*y = screen->y + settings->position.y.pos;
|
||||
if (settings->position.y.denom)
|
||||
*y = (*y * screen->height) / settings->position.y.denom;
|
||||
|
||||
g_slice_free(Rect, screen);
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in a new issue