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);
16 /* 3.4-compatibility */
17 static gpointer setup_north_func(xmlNodePtr node);
18 static gpointer setup_south_func(xmlNodePtr node);
19 static gpointer setup_east_func(xmlNodePtr node);
20 static gpointer setup_west_func(xmlNodePtr node);
22 void action_growtoedge_startup(void)
24 actions_register("GrowToEdge", setup_func,
25 g_free, run_func, NULL, NULL);
26 actions_register("ShrinkToEdge", setup_shrink_func,
27 g_free, run_func, NULL, NULL);
28 /* 3.4-compatibility */
29 actions_register("GrowToEdgeNorth", setup_north_func, g_free, run_func,
31 actions_register("GrowToEdgeSouth", setup_south_func, g_free, run_func,
33 actions_register("GrowToEdgeEast", setup_east_func, g_free, run_func,
35 actions_register("GrowToEdgeWest", setup_west_func, g_free, run_func,
39 static gpointer setup_func(xmlNodePtr node)
44 o = g_new0(Options, 1);
45 o->dir = OB_DIRECTION_NORTH;
48 if ((n = obt_parse_find_node(node, "direction"))) {
49 gchar *s = obt_parse_node_string(n);
50 if (!g_ascii_strcasecmp(s, "north") ||
51 !g_ascii_strcasecmp(s, "up"))
52 o->dir = OB_DIRECTION_NORTH;
53 else if (!g_ascii_strcasecmp(s, "south") ||
54 !g_ascii_strcasecmp(s, "down"))
55 o->dir = OB_DIRECTION_SOUTH;
56 else if (!g_ascii_strcasecmp(s, "west") ||
57 !g_ascii_strcasecmp(s, "left"))
58 o->dir = OB_DIRECTION_WEST;
59 else if (!g_ascii_strcasecmp(s, "east") ||
60 !g_ascii_strcasecmp(s, "right"))
61 o->dir = OB_DIRECTION_EAST;
68 static gpointer setup_shrink_func(xmlNodePtr node)
78 static gboolean do_grow(ObActionsData *data, gint x, gint y, gint w, gint h)
80 gint realw, realh, lw, lh;
84 client_try_configure(data->client, &x, &y, &realw, &realh,
86 /* if it's going to be resized smaller than it intended, don't
87 move the window over */
88 if (x != data->client->area.x) x += w - realw;
89 if (y != data->client->area.y) y += h - realh;
91 if (x != data->client->area.x || y != data->client->area.y ||
92 realw != data->client->area.width ||
93 realh != data->client->area.height)
95 actions_client_move(data, TRUE);
96 client_move_resize(data->client, x, y, realw, realh);
97 actions_client_move(data, FALSE);
103 /* Always return FALSE because its not interactive */
104 static gboolean run_func(ObActionsData *data, gpointer options)
106 Options *o = options;
112 /* don't allow vertical resize if shaded */
113 ((o->dir == OB_DIRECTION_NORTH || o->dir == OB_DIRECTION_SOUTH) &&
114 data->client->shaded))
121 client_find_resize_directional(data->client, o->dir, TRUE,
123 if (do_grow(data, x, y, w, h))
127 /* we couldn't grow, so try shrink! */
128 opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH :
129 (o->dir == OB_DIRECTION_SOUTH ? OB_DIRECTION_NORTH :
130 (o->dir == OB_DIRECTION_EAST ? OB_DIRECTION_WEST :
131 OB_DIRECTION_EAST)));
132 client_find_resize_directional(data->client, opp, FALSE,
135 case OB_DIRECTION_NORTH:
136 half = data->client->area.y + data->client->area.height / 2;
142 case OB_DIRECTION_SOUTH:
143 half = data->client->area.height / 2;
147 case OB_DIRECTION_WEST:
148 half = data->client->area.x + data->client->area.width / 2;
154 case OB_DIRECTION_EAST:
155 half = data->client->area.width / 2;
159 default: g_assert_not_reached();
161 if (do_grow(data, x, y, w, h))
167 /* 3.4-compatibility */
168 static gpointer setup_north_func(xmlNodePtr node)
170 Options *o = g_new0(Options, 1);
172 o->dir = OB_DIRECTION_NORTH;
176 static gpointer setup_south_func(xmlNodePtr node)
178 Options *o = g_new0(Options, 1);
180 o->dir = OB_DIRECTION_SOUTH;
184 static gpointer setup_east_func(xmlNodePtr node)
186 Options *o = g_new0(Options, 1);
188 o->dir = OB_DIRECTION_EAST;
192 static gpointer setup_west_func(xmlNodePtr node)
194 Options *o = g_new0(Options, 1);
196 o->dir = OB_DIRECTION_WEST;