add directionaldesktop action
[mikachu/openbox.git] / openbox / actions / directionaldesktop.c
1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include <glib.h>
4
5 typedef struct {
6     gboolean linear;
7     gboolean wrap;
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_directionaldesktop_startup()
16 {
17     actions_register("DirectionalDesktop",
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->wrap = TRUE;
31     o->dir = OB_DIRECTION_EAST;
32
33     if ((n = parse_find_node("wrap", node)))
34         o->wrap = parse_bool(doc, n);
35     if ((n = parse_find_node("direction", node))) {
36         gchar *s = parse_string(doc, n);
37         if (!g_ascii_strcasecmp(s, "next")) {
38             o->linear = TRUE;
39             o->dir = OB_DIRECTION_EAST;
40         }
41         else if (!g_ascii_strcasecmp(s, "previous")) {
42             o->linear = TRUE;
43             o->dir = OB_DIRECTION_WEST;
44         }
45         else if (!g_ascii_strcasecmp(s, "north") ||
46                  !g_ascii_strcasecmp(s, "up"))
47             o->dir = OB_DIRECTION_NORTH;
48         else if (!g_ascii_strcasecmp(s, "south") ||
49                  !g_ascii_strcasecmp(s, "down"))
50             o->dir = OB_DIRECTION_SOUTH;
51         else if (!g_ascii_strcasecmp(s, "west") ||
52                  !g_ascii_strcasecmp(s, "left"))
53             o->dir = OB_DIRECTION_WEST;
54         else if (!g_ascii_strcasecmp(s, "east") ||
55                  !g_ascii_strcasecmp(s, "right"))
56             o->dir = OB_DIRECTION_EAST;
57         g_free(s);
58     }
59
60     return o;
61 }
62
63 static void free_func(gpointer options)
64 {
65     Options *o = options;
66
67     g_free(o);
68 }
69
70 /* Always return FALSE because its not interactive */
71 static gboolean run_func(ObActionsData *data, gpointer options)
72 {
73     Options *o = options;
74     guint d;
75
76     d = screen_cycle_desktop(o->dir,
77                              o->wrap,
78                              o->linear,
79                              FALSE, TRUE, FALSE);
80     if (d != screen_desktop)
81         screen_set_desktop(d, TRUE);
82
83     return FALSE;
84 }