]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/actions/movetoedge.c
Merge branch 'backport' into 3.4-working
[mikachu/openbox.git] / openbox / actions / movetoedge.c
1 #include "openbox/actions.h"
2 #include "openbox/misc.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
5 #include "openbox/geom.h"
6 #include <glib.h>
7
8 typedef struct {
9     ObDirection dir;
10 } Options;
11
12 static gpointer setup_north_func(ObParseInst *i, xmlDocPtr doc,
13                                  xmlNodePtr node);
14 static gpointer setup_south_func(ObParseInst *i, xmlDocPtr doc,
15                                  xmlNodePtr node);
16 static gpointer setup_east_func(ObParseInst *i, xmlDocPtr doc,
17                                 xmlNodePtr node);
18 static gpointer setup_west_func(ObParseInst *i, xmlDocPtr doc,
19                                 xmlNodePtr node);
20 static gboolean run_func(ObActionsData *data, gpointer options);
21
22 void action_movetoedge_startup(void)
23 {
24     actions_register("MoveToEdgeNorth", setup_north_func, g_free, run_func,
25                      NULL, NULL);
26     actions_register("MoveToEdgeSouth", setup_south_func, g_free, run_func,
27                      NULL, NULL);
28     actions_register("MoveToEdgeEast", setup_east_func, g_free, run_func,
29                      NULL, NULL);
30     actions_register("MoveToEdgeWest", setup_west_func, g_free, run_func,
31                      NULL, NULL);
32 }
33
34 static gpointer setup_north_func(ObParseInst *i, xmlDocPtr doc,
35                                  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, xmlDocPtr doc,
43                                  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, xmlDocPtr doc,
51                                  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, xmlDocPtr doc,
59                                  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;
73
74         client_find_move_directional(data->client, o->dir, &x, &y);
75         if (x != data->client->area.x || y != data->client->area.y) {
76             actions_client_move(data, TRUE);
77             client_move(data->client, x, y);
78             actions_client_move(data, FALSE);
79         }
80     }
81
82     return FALSE;
83 }