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 actions_client_locked(data) ||
99 /* don't allow vertical resize if shaded */
100 ((o->dir == OB_DIRECTION_NORTH || o->dir == OB_DIRECTION_SOUTH) &&
101 data->client->shaded))
108 client_find_resize_directional(data->client, o->dir, TRUE,
110 if (do_grow(data, x, y, w, h))
114 /* we couldn't grow, so try shrink! */
115 opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH :
116 (o->dir == OB_DIRECTION_SOUTH ? OB_DIRECTION_NORTH :
117 (o->dir == OB_DIRECTION_EAST ? OB_DIRECTION_WEST :
118 OB_DIRECTION_EAST)));
119 client_find_resize_directional(data->client, opp, FALSE,
122 case OB_DIRECTION_NORTH:
123 half = data->client->area.y + data->client->area.height / 2;
129 case OB_DIRECTION_SOUTH:
130 half = data->client->area.height / 2;
134 case OB_DIRECTION_WEST:
135 half = data->client->area.x + data->client->area.width / 2;
141 case OB_DIRECTION_EAST:
142 half = data->client->area.width / 2;
146 default: g_assert_not_reached();
148 if (do_grow(data, x, y, w, h))