]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/growtoedge.c
Merge branch 'master' into 3.4-working
[dana/openbox.git] / openbox / actions / growtoedge.c
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"
6 #include <glib.h>
7
8 typedef struct {
9     ObDirection dir;
10 } Options;
11
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);
21
22 void action_growtoedge_startup()
23 {
24     actions_register("GrowToEdgeNorth", setup_north_func, g_free, run_func,
25                      NULL, NULL);
26     actions_register("GrowToEdgeSouth", setup_south_func, g_free, run_func,
27                      NULL, NULL);
28     actions_register("GrowToEdgeEast", setup_east_func, g_free, run_func,
29                      NULL, NULL);
30     actions_register("GrowToEdgeWest", setup_west_func, g_free, run_func,
31                      NULL, NULL);
32 }
33
34 static gpointer setup_north_func(ObParseInst *i,
35                                  xmlDocPtr doc, xmlNodePtr node)
36 {
37     Options *o = g_new0(Options, 1);
38     o->dir = OB_DIRECTION_NORTH;
39     return o;
40 }
41
42 static gpointer setup_south_func(ObParseInst *i,
43                                  xmlDocPtr doc, xmlNodePtr node)
44 {
45     Options *o = g_new0(Options, 1);
46     o->dir = OB_DIRECTION_SOUTH;
47     return o;
48 }
49
50 static gpointer setup_east_func(ObParseInst *i,
51                                 xmlDocPtr doc, xmlNodePtr node)
52 {
53     Options *o = g_new0(Options, 1);
54     o->dir = OB_DIRECTION_EAST;
55     return o;
56 }
57
58 static gpointer setup_west_func(ObParseInst *i,
59                                 xmlDocPtr doc, xmlNodePtr node)
60 {
61     Options *o = g_new0(Options, 1);
62     o->dir = OB_DIRECTION_WEST;
63     return o;
64 }
65
66 /* Always return FALSE because its not interactive */
67 static gboolean run_func(ObActionsData *data, gpointer options)
68 {
69     Options *o = options;
70
71     if (data->client) {
72         gint x, y, w, h, realw, realh, lw, lh;
73
74         /* don't allow vertical resize if shaded */
75         if (o->dir != OB_DIRECTION_NORTH || o->dir != OB_DIRECTION_SOUTH ||
76             !data->client->shaded)
77         {
78             client_find_resize_directional(data->client, o->dir, TRUE,
79                                            &x, &y, &w, &h);
80             realw = w;
81             realh = h;
82             client_try_configure(data->client, &x, &y, &realw, &realh,
83                                  &lw, &lh, TRUE);
84             /* if it's going to be resized smaller than it intended, don't
85                move the window over */
86             if (x != data->client->area.x) x += w - realw;
87             if (y != data->client->area.y) y += h - realh;
88
89             if (x != data->client->area.x || y != data->client->area.y ||
90                 w != data->client->area.width ||
91                 h != data->client->area.height)
92             {
93                 actions_client_move(data, TRUE);
94                 client_move_resize(data->client, x, y, realw, realh);
95                 actions_client_move(data, FALSE);
96             }
97         }
98     }
99
100     return FALSE;
101 }