]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/actions/movetofromedge.c
rewrote the movetoedge code so it works with both types of edges (to edge and from...
[mikachu/openbox.git] / openbox / actions / movetofromedge.c
1 #include "openbox/actions.h"
2 #include "openbox/misc.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
5 #include <glib.h>
6
7 typedef struct {
8     ObDirection dir;
9 } Options;
10
11 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
12 static void     free_func(gpointer options);
13 static gboolean run_func(ObActionsData *data, gpointer options);
14
15 void action_movetofromedge_startup()
16 {
17     actions_register("MoveToEdge",
18                      setup_func,
19                      free_func,
20                      run_func,
21                      NULL, NULL);
22 }
23
24 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
25 {
26     xmlNodePtr n;
27     Options *o;
28
29     o = g_new0(Options, 1);
30     o->dir = OB_DIRECTION_NORTH;
31
32     if ((n = parse_find_node("direction", node))) {
33         gchar *s = parse_string(doc, n);
34         if (!g_ascii_strcasecmp(s, "north") ||
35             !g_ascii_strcasecmp(s, "up"))
36             o->dir = OB_DIRECTION_NORTH;
37         else if (!g_ascii_strcasecmp(s, "south") ||
38                  !g_ascii_strcasecmp(s, "down"))
39             o->dir = OB_DIRECTION_SOUTH;
40         else if (!g_ascii_strcasecmp(s, "west") ||
41                  !g_ascii_strcasecmp(s, "left"))
42             o->dir = OB_DIRECTION_WEST;
43         else if (!g_ascii_strcasecmp(s, "east") ||
44                  !g_ascii_strcasecmp(s, "right"))
45             o->dir = OB_DIRECTION_EAST;
46         g_free(s);
47     }
48
49     return o;
50 }
51
52 static void free_func(gpointer options)
53 {
54     Options *o = options;
55
56     g_free(o);
57 }
58
59 /* Always return FALSE because its not interactive */
60 static gboolean run_func(ObActionsData *data, gpointer options)
61 {
62     Options *o = options;
63
64     if (data->client) {
65         gint x, y;
66
67         client_find_move_directional(data->client, o->dir, &x, &y);
68         if (x != data->client->area.x || y != data->client->area.y) {
69             actions_client_move(data, FALSE);
70             client_move(data->client, x, y);
71             actions_client_move(data, TRUE);
72         }
73     }
74
75     return FALSE;
76 }