]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/movetoedge.c
Actions say what kind of filter they would like by default (one window or all)
[dana/openbox.git] / openbox / actions / movetoedge.c
1 #include "openbox/action.h"
2 #include "openbox/action_value.h"
3 #include "openbox/misc.h"
4 #include "openbox/client.h"
5 #include "openbox/frame.h"
6 #include "openbox/geom.h"
7 #include <glib.h>
8
9 typedef struct {
10     ObDirection dir;
11 } Options;
12
13 static gpointer setup_func(GHashTable *config);
14 static void free_func(gpointer o);
15 static gboolean run_func(ObActionData *data, gpointer options);
16
17 void action_movetoedge_startup(void)
18 {
19     action_register("MoveToEdge", OB_ACTION_DEFAULT_FILTER_SINGLE,
20                     setup_func, free_func, run_func);
21 }
22
23 static gpointer setup_func(GHashTable *config)
24 {
25     ObActionValue *v;
26     Options *o;
27
28     o = g_slice_new0(Options);
29     o->dir = OB_DIRECTION_NORTH;
30
31     v = g_hash_table_lookup(config, "direction");
32     if (v && action_value_is_string(v)) {
33         const gchar *s = action_value_string(v);
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     }
47
48     return o;
49 }
50
51 static void free_func(gpointer o)
52 {
53     g_slice_free(Options, o);
54 }
55
56 /* Always return FALSE because its not interactive */
57 static gboolean run_func(ObActionData *data, gpointer options)
58 {
59     Options *o = options;
60
61     if (data->client) {
62         gint x, y;
63
64         client_find_move_directional(data->client, o->dir, &x, &y);
65         if (x != data->client->area.x || y != data->client->area.y) {
66             action_client_move(data, TRUE);
67             client_move(data->client, x, y);
68             action_client_move(data, FALSE);
69         }
70     }
71
72     return FALSE;
73 }