Add all the action names used in 3.4 so configs don't break
[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 /* 3.4-compatibility */
15 static gpointer setup_north_func(xmlNodePtr node);
16 static gpointer setup_south_func(xmlNodePtr node);
17 static gpointer setup_east_func(xmlNodePtr node);
18 static gpointer setup_west_func(xmlNodePtr node);
19
20 void action_movetoedge_startup(void)
21 {
22     actions_register("MoveToEdge", setup_func, g_free, run_func, NULL, NULL);
23     /* 3.4-compatibility */
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_func(xmlNodePtr node)
35 {
36     xmlNodePtr n;
37     Options *o;
38
39     o = g_new0(Options, 1);
40     o->dir = OB_DIRECTION_NORTH;
41
42     if ((n = obt_parse_find_node(node, "direction"))) {
43         gchar *s = obt_parse_node_string(n);
44         if (!g_ascii_strcasecmp(s, "north") ||
45             !g_ascii_strcasecmp(s, "up"))
46             o->dir = OB_DIRECTION_NORTH;
47         else if (!g_ascii_strcasecmp(s, "south") ||
48                  !g_ascii_strcasecmp(s, "down"))
49             o->dir = OB_DIRECTION_SOUTH;
50         else if (!g_ascii_strcasecmp(s, "west") ||
51                  !g_ascii_strcasecmp(s, "left"))
52             o->dir = OB_DIRECTION_WEST;
53         else if (!g_ascii_strcasecmp(s, "east") ||
54                  !g_ascii_strcasecmp(s, "right"))
55             o->dir = OB_DIRECTION_EAST;
56         g_free(s);
57     }
58
59     return o;
60 }
61
62 /* Always return FALSE because its not interactive */
63 static gboolean run_func(ObActionsData *data, gpointer options)
64 {
65     Options *o = options;
66
67     if (data->client) {
68         gint x, y;
69
70         client_find_move_directional(data->client, o->dir, &x, &y);
71         if (x != data->client->area.x || y != data->client->area.y) {
72             actions_client_move(data, TRUE);
73             client_move(data->client, x, y);
74             actions_client_move(data, FALSE);
75         }
76     }
77
78     return FALSE;
79 }
80
81 /* 3.4-compatibility */
82 static gpointer setup_north_func(xmlNodePtr node)
83 {
84     Options *o = g_new0(Options, 1);
85     o->dir = OB_DIRECTION_NORTH;
86     return o;
87 }
88
89 static gpointer setup_south_func(xmlNodePtr node)
90 {
91     Options *o = g_new0(Options, 1);
92     o->dir = OB_DIRECTION_SOUTH;
93     return o;
94 }
95
96 static gpointer setup_east_func(xmlNodePtr node)
97 {
98     Options *o = g_new0(Options, 1);
99     o->dir = OB_DIRECTION_EAST;
100     return o;
101 }
102
103 static gpointer setup_west_func(xmlNodePtr node)
104 {
105     Options *o = g_new0(Options, 1);
106     o->dir = OB_DIRECTION_WEST;
107     return o;
108 }
109