Merge branch 'backport' into work
[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_func(xmlNodePtr node);
13 static gboolean run_func(ObActionsData *data, gpointer options);
14
15 void action_movetoedge_startup(void)
16 {
17     actions_register("MoveToEdge", setup_func, g_free, run_func, NULL, NULL);
18 }
19
20 static gpointer setup_func(xmlNodePtr node)
21 {
22     xmlNodePtr n;
23     Options *o;
24
25     o = g_new0(Options, 1);
26     o->dir = OB_DIRECTION_NORTH;
27
28     if ((n = obt_parse_find_node(node, "direction"))) {
29         gchar *s = obt_parse_node_string(n);
30         if (!g_ascii_strcasecmp(s, "north") ||
31             !g_ascii_strcasecmp(s, "up"))
32             o->dir = OB_DIRECTION_NORTH;
33         else if (!g_ascii_strcasecmp(s, "south") ||
34                  !g_ascii_strcasecmp(s, "down"))
35             o->dir = OB_DIRECTION_SOUTH;
36         else if (!g_ascii_strcasecmp(s, "west") ||
37                  !g_ascii_strcasecmp(s, "left"))
38             o->dir = OB_DIRECTION_WEST;
39         else if (!g_ascii_strcasecmp(s, "east") ||
40                  !g_ascii_strcasecmp(s, "right"))
41             o->dir = OB_DIRECTION_EAST;
42         g_free(s);
43     }
44
45     return o;
46 }
47
48 /* Always return FALSE because its not interactive */
49 static gboolean run_func(ObActionsData *data, gpointer options)
50 {
51     Options *o = options;
52
53     if (data->client) {
54         gint x, y;
55
56         client_find_move_directional(data->client, o->dir, &x, &y);
57         if (x != data->client->area.x || y != data->client->area.y) {
58             actions_client_move(data, TRUE);
59             client_move(data->client, x, y);
60             actions_client_move(data, FALSE);
61         }
62     }
63
64     return FALSE;
65 }