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 void free_func(gpointer o);
16 static gboolean run_func(ObActionsData *data, gpointer options);
17 /* 3.4-compatibility */
18 static gpointer setup_north_func(xmlNodePtr node);
19 static gpointer setup_south_func(xmlNodePtr node);
20 static gpointer setup_east_func(xmlNodePtr node);
21 static gpointer setup_west_func(xmlNodePtr node);
23 void action_growtoedge_startup(void)
25 actions_register("GrowToEdge", setup_func,
27 actions_register("ShrinkToEdge", setup_shrink_func,
29 /* 3.4-compatibility */
30 actions_register("GrowToEdgeNorth", setup_north_func, free_func, run_func);
31 actions_register("GrowToEdgeSouth", setup_south_func, free_func, run_func);
32 actions_register("GrowToEdgeEast", setup_east_func, free_func, run_func);
33 actions_register("GrowToEdgeWest", setup_west_func, free_func, run_func);
36 static gpointer setup_func(xmlNodePtr node)
41 o = g_slice_new0(Options);
42 o->dir = OB_DIRECTION_NORTH;
45 if ((n = obt_xml_find_node(node, "direction"))) {
46 gchar *s = obt_xml_node_string(n);
47 if (!g_ascii_strcasecmp(s, "north") ||
48 !g_ascii_strcasecmp(s, "up"))
49 o->dir = OB_DIRECTION_NORTH;
50 else if (!g_ascii_strcasecmp(s, "south") ||
51 !g_ascii_strcasecmp(s, "down"))
52 o->dir = OB_DIRECTION_SOUTH;
53 else if (!g_ascii_strcasecmp(s, "west") ||
54 !g_ascii_strcasecmp(s, "left"))
55 o->dir = OB_DIRECTION_WEST;
56 else if (!g_ascii_strcasecmp(s, "east") ||
57 !g_ascii_strcasecmp(s, "right"))
58 o->dir = OB_DIRECTION_EAST;
65 static gpointer setup_shrink_func(xmlNodePtr node)
75 static gboolean do_grow(ObActionsData *data, gint x, gint y, gint w, gint h)
77 gint realw, realh, lw, lh;
81 client_try_configure(data->client, &x, &y, &realw, &realh,
83 /* if it's going to be resized smaller than it intended, don't
84 move the window over */
85 if (x != data->client->area.x) x += w - realw;
86 if (y != data->client->area.y) y += h - realh;
88 if (x != data->client->area.x || y != data->client->area.y ||
89 realw != data->client->area.width ||
90 realh != data->client->area.height)
92 actions_client_move(data, TRUE);
93 client_move_resize(data->client, x, y, realw, realh);
94 actions_client_move(data, FALSE);
100 static void free_func(gpointer o)
102 g_slice_free(Options, o);
105 /* Always return FALSE because its not interactive */
106 static gboolean run_func(ObActionsData *data, gpointer options)
108 Options *o = options;
114 /* don't allow vertical resize if shaded */
115 ((o->dir == OB_DIRECTION_NORTH || o->dir == OB_DIRECTION_SOUTH) &&
116 data->client->shaded))
123 client_find_resize_directional(data->client, o->dir, TRUE,
125 if (do_grow(data, x, y, w, h))
129 /* we couldn't grow, so try shrink! */
130 opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH :
131 (o->dir == OB_DIRECTION_SOUTH ? OB_DIRECTION_NORTH :
132 (o->dir == OB_DIRECTION_EAST ? OB_DIRECTION_WEST :
133 OB_DIRECTION_EAST)));
134 client_find_resize_directional(data->client, opp, FALSE,
137 case OB_DIRECTION_NORTH:
138 half = data->client->area.y + data->client->area.height / 2;
144 case OB_DIRECTION_SOUTH:
145 half = data->client->area.height / 2;
149 case OB_DIRECTION_WEST:
150 half = data->client->area.x + data->client->area.width / 2;
156 case OB_DIRECTION_EAST:
157 half = data->client->area.width / 2;
161 default: g_assert_not_reached();
163 if (do_grow(data, x, y, w, h))
169 /* 3.4-compatibility */
170 static gpointer setup_north_func(xmlNodePtr node)
172 Options *o = g_slice_new0(Options);
174 o->dir = OB_DIRECTION_NORTH;
178 static gpointer setup_south_func(xmlNodePtr node)
180 Options *o = g_slice_new0(Options);
182 o->dir = OB_DIRECTION_SOUTH;
186 static gpointer setup_east_func(xmlNodePtr node)
188 Options *o = g_slice_new0(Options);
190 o->dir = OB_DIRECTION_EAST;
194 static gpointer setup_west_func(xmlNodePtr node)
196 Options *o = g_slice_new0(Options);
198 o->dir = OB_DIRECTION_WEST;