1 #include "openbox/actions.h"
2 #include "openbox/misc.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
5 #include "openbox/screen.h"
13 static gpointer setup_func(xmlNodePtr node);
14 static gpointer setup_shrink_func(xmlNodePtr node);
15 static gboolean run_func(ObActionsData *data, gpointer options);
17 void action_growtoedge_startup(void)
19 actions_register("GrowToEdge", setup_func,
20 g_free, run_func, NULL, NULL);
21 actions_register("ShrinkToEdge", setup_shrink_func,
22 g_free, run_func, NULL, NULL);
25 static gpointer setup_func(xmlNodePtr node)
30 o = g_new0(Options, 1);
31 o->dir = OB_DIRECTION_NORTH;
34 if ((n = obt_parse_find_node(node, "direction"))) {
35 gchar *s = obt_parse_node_string(n);
36 if (!g_ascii_strcasecmp(s, "north") ||
37 !g_ascii_strcasecmp(s, "up"))
38 o->dir = OB_DIRECTION_NORTH;
39 else if (!g_ascii_strcasecmp(s, "south") ||
40 !g_ascii_strcasecmp(s, "down"))
41 o->dir = OB_DIRECTION_SOUTH;
42 else if (!g_ascii_strcasecmp(s, "west") ||
43 !g_ascii_strcasecmp(s, "left"))
44 o->dir = OB_DIRECTION_WEST;
45 else if (!g_ascii_strcasecmp(s, "east") ||
46 !g_ascii_strcasecmp(s, "right"))
47 o->dir = OB_DIRECTION_EAST;
54 static gpointer setup_shrink_func(xmlNodePtr node)
64 static gboolean do_grow(ObActionsData *data, gint x, gint y, gint w, gint h)
66 gint realw, realh, lw, lh;
70 client_try_configure(data->client, &x, &y, &realw, &realh,
72 /* if it's going to be resized smaller than it intended, don't
73 move the window over */
74 if (x != data->client->area.x) x += w - realw;
75 if (y != data->client->area.y) y += h - realh;
77 if (x != data->client->area.x || y != data->client->area.y ||
78 realw != data->client->area.width ||
79 realh != data->client->area.height)
81 actions_client_move(data, TRUE);
82 client_move_resize(data->client, x, y, realw, realh);
83 actions_client_move(data, FALSE);
89 /* Always return FALSE because its not interactive */
90 static gboolean run_func(ObActionsData *data, gpointer options)
98 /* don't allow vertical resize if shaded */
99 ((o->dir == OB_DIRECTION_NORTH || o->dir == OB_DIRECTION_SOUTH) &&
100 data->client->shaded))
107 client_find_resize_directional(data->client, o->dir, TRUE,
109 if (do_grow(data, x, y, w, h))
113 /* we couldn't grow, so try shrink! */
114 opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH :
115 (o->dir == OB_DIRECTION_SOUTH ? OB_DIRECTION_NORTH :
116 (o->dir == OB_DIRECTION_EAST ? OB_DIRECTION_WEST :
117 OB_DIRECTION_EAST)));
118 client_find_resize_directional(data->client, opp, FALSE,
121 case OB_DIRECTION_NORTH:
122 half = data->client->area.y + data->client->area.height / 2;
128 case OB_DIRECTION_SOUTH:
129 half = data->client->area.height / 2;
133 case OB_DIRECTION_WEST:
134 half = data->client->area.x + data->client->area.width / 2;
140 case OB_DIRECTION_EAST:
141 half = data->client->area.width / 2;
145 default: g_assert_not_reached();
147 if (do_grow(data, x, y, w, h))