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