let you use "last" in desktop action
[dana/openbox.git] / openbox / actions / desktop.c
1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include <glib.h>
4
5 typedef struct {
6     gboolean last;
7     guint desktop;
8 } Options;
9
10 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
11 static void     free_func(gpointer options);
12 static gboolean run_func(ObActionsData *data, gpointer options);
13
14 void action_desktop_startup()
15 {
16     actions_register("Desktop",
17                      setup_func,
18                      free_func,
19                      run_func,
20                      NULL, NULL);
21 }
22
23 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
24 {
25     xmlNodePtr n;
26     Options *o;
27
28     o = g_new0(Options, 1);
29
30     if ((n = parse_find_node("desktop", node))) {
31         gchar *s = parse_string(doc, n);
32         if (!g_ascii_strcasecmp(s, "last"))
33             o->last = TRUE;
34         else
35             o->desktop = parse_int(doc, n) - 1;
36         g_free(s);
37     }
38     return o;
39 }
40
41 static void free_func(gpointer options)
42 {
43     Options *o = options;
44
45     g_free(o);
46 }
47
48 /* Always return FALSE because its not interactive */
49 static gboolean run_func(ObActionsData *data, gpointer options)
50 {
51     Options *o = options;
52     guint d;
53
54     if (o->last)
55         d = screen_last_desktop;
56     else
57         d = o->desktop;
58
59     if (d < screen_num_desktops)
60         screen_set_desktop(d, TRUE);
61
62     return FALSE;
63 }