]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/movetoedge.c
Use ObConfigValue to parse gravity coords, remove parse special functions from config...
[dana/openbox.git] / openbox / actions / movetoedge.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/config_value.h"
4 #include "openbox/misc.h"
5 #include "openbox/client.h"
6 #include "openbox/client_set.h"
7 #include "openbox/frame.h"
8 #include "openbox/geom.h"
9 #include <glib.h>
10
11 typedef struct {
12     ObDirection dir;
13 } Options;
14
15 static gpointer setup_func(GHashTable *config);
16 static void free_func(gpointer o);
17 static gboolean run_func(const ObClientSet *set,
18                          const ObActionListRun *data, gpointer options);
19
20 void action_movetoedge_startup(void)
21 {
22     action_register("MoveToEdge", OB_ACTION_DEFAULT_FILTER_SINGLE,
23                     setup_func, free_func, run_func);
24 }
25
26 static gpointer setup_func(GHashTable *config)
27 {
28     ObConfigValue *v;
29     Options *o;
30
31     o = g_slice_new0(Options);
32     o->dir = OB_DIRECTION_NORTH;
33
34     v = g_hash_table_lookup(config, "direction");
35     if (v && config_value_is_string(v)) {
36         const gchar *s = config_value_string(v);
37         if (!g_ascii_strcasecmp(s, "north") ||
38             !g_ascii_strcasecmp(s, "up"))
39             o->dir = OB_DIRECTION_NORTH;
40         else if (!g_ascii_strcasecmp(s, "south") ||
41                  !g_ascii_strcasecmp(s, "down"))
42             o->dir = OB_DIRECTION_SOUTH;
43         else if (!g_ascii_strcasecmp(s, "west") ||
44                  !g_ascii_strcasecmp(s, "left"))
45             o->dir = OB_DIRECTION_WEST;
46         else if (!g_ascii_strcasecmp(s, "east") ||
47                  !g_ascii_strcasecmp(s, "right"))
48             o->dir = OB_DIRECTION_EAST;
49     }
50
51     return o;
52 }
53
54 static void free_func(gpointer o)
55 {
56     g_slice_free(Options, o);
57 }
58
59 static gboolean each_run(ObClient *c, const ObActionListRun *data,
60                          gpointer options)
61 {
62     Options *o = options;
63     gint x, y;
64
65     client_find_move_directional(c, o->dir, &x, &y);
66     if (x != c->area.x || y != c->area.y)
67         client_move(c, x, y);
68     return TRUE;
69 }
70
71 /* Always return FALSE because its not interactive */
72 static gboolean run_func(const ObClientSet *set,
73                          const ObActionListRun *data, gpointer options)
74 {
75     if (!client_set_is_empty(set)) {
76         action_client_move(data, TRUE);
77         client_set_run(set, data, each_run, options);
78         action_client_move(data, FALSE);
79     }
80     return FALSE;
81 }