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"
12 static gpointer setup_north_func(ObParseInst *i,
13 xmlDocPtr doc, xmlNodePtr node);
14 static gpointer setup_south_func(ObParseInst *i,
15 xmlDocPtr doc, xmlNodePtr node);
16 static gpointer setup_east_func(ObParseInst *i,
17 xmlDocPtr doc, xmlNodePtr node);
18 static gpointer setup_west_func(ObParseInst *i,
19 xmlDocPtr doc, xmlNodePtr node);
20 static gboolean run_func(ObActionsData *data, gpointer options);
22 void action_growtoedge_startup(void)
24 actions_register("GrowToEdgeNorth", setup_north_func, g_free, run_func,
26 actions_register("GrowToEdgeSouth", setup_south_func, g_free, run_func,
28 actions_register("GrowToEdgeEast", setup_east_func, g_free, run_func,
30 actions_register("GrowToEdgeWest", setup_west_func, g_free, run_func,
34 static gpointer setup_north_func(ObParseInst *i,
35 xmlDocPtr doc, xmlNodePtr node)
37 Options *o = g_new0(Options, 1);
38 o->dir = OB_DIRECTION_NORTH;
42 static gpointer setup_south_func(ObParseInst *i,
43 xmlDocPtr doc, xmlNodePtr node)
45 Options *o = g_new0(Options, 1);
46 o->dir = OB_DIRECTION_SOUTH;
50 static gpointer setup_east_func(ObParseInst *i,
51 xmlDocPtr doc, xmlNodePtr node)
53 Options *o = g_new0(Options, 1);
54 o->dir = OB_DIRECTION_EAST;
58 static gpointer setup_west_func(ObParseInst *i,
59 xmlDocPtr doc, xmlNodePtr node)
61 Options *o = g_new0(Options, 1);
62 o->dir = OB_DIRECTION_WEST;
66 static gboolean do_grow(ObActionsData *data, gint x, gint y, gint w, gint h)
68 gint realw, realh, lw, lh;
72 client_try_configure(data->client, &x, &y, &realw, &realh,
74 /* if it's going to be resized smaller than it intended, don't
75 move the window over */
76 if (x != data->client->area.x) x += w - realw;
77 if (y != data->client->area.y) y += h - realh;
79 if (x != data->client->area.x || y != data->client->area.y ||
80 realw != data->client->area.width ||
81 realh != data->client->area.height)
83 actions_client_move(data, TRUE);
84 client_move_resize(data->client, x, y, realw, realh);
85 actions_client_move(data, FALSE);
91 /* Always return FALSE because its not interactive */
92 static gboolean run_func(ObActionsData *data, gpointer options)
100 /* don't allow vertical resize if shaded */
101 ((o->dir == OB_DIRECTION_NORTH || o->dir == OB_DIRECTION_SOUTH) &&
102 data->client->shaded))
108 client_find_resize_directional(data->client, o->dir, TRUE,
110 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))