Add complementing ShrinkToEdge action.

This commit is contained in:
Mikael Magnusson 2007-10-03 14:05:15 +02:00
parent f55ae9e569
commit 9586ad246d

View file

@ -7,9 +7,11 @@
typedef struct { typedef struct {
ObDirection dir; ObDirection dir;
gboolean shrink;
} Options; } Options;
static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
static gpointer setup_shrink_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
static void free_func(gpointer options); static void free_func(gpointer options);
static gboolean run_func(ObActionsData *data, gpointer options); static gboolean run_func(ObActionsData *data, gpointer options);
@ -20,6 +22,12 @@ void action_growtoedge_startup()
free_func, free_func,
run_func, run_func,
NULL, NULL); NULL, NULL);
actions_register("ShrinkToEdge",
setup_shrink_func,
free_func,
run_func,
NULL, NULL);
} }
static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
@ -29,6 +37,7 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
o = g_new0(Options, 1); o = g_new0(Options, 1);
o->dir = OB_DIRECTION_NORTH; o->dir = OB_DIRECTION_NORTH;
o->shrink = FALSE;
if ((n = parse_find_node("direction", node))) { if ((n = parse_find_node("direction", node))) {
gchar *s = parse_string(doc, n); gchar *s = parse_string(doc, n);
@ -50,6 +59,16 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
return o; return o;
} }
static gpointer setup_shrink_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
{
Options *o;
o = setup_func(i, doc, node);
o->shrink = TRUE;
return o;
}
static void free_func(gpointer options) static void free_func(gpointer options)
{ {
Options *o = options; Options *o = options;
@ -98,11 +117,13 @@ static gboolean run_func(ObActionsData *data, gpointer options)
return FALSE; return FALSE;
} }
/* try grow */ if (!o->shrink) {
client_find_resize_directional(data->client, o->dir, TRUE, /* try grow */
&x, &y, &w, &h); client_find_resize_directional(data->client, o->dir, TRUE,
if (do_grow(data, x, y, w, h)) &x, &y, &w, &h);
return FALSE; if (do_grow(data, x, y, w, h))
return FALSE;
}
/* we couldn't grow, so try shrink! */ /* we couldn't grow, so try shrink! */
opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH : opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH :