]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/addremovedesktop.c
Add action_list_run.c/h with action_list_run() and struct ObActionListRun.
[dana/openbox.git] / openbox / actions / addremovedesktop.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/action_value.h"
4 #include "openbox/screen.h"
5 #include <glib.h>
6
7 typedef struct {
8     gboolean current;
9     gboolean add;
10 } Options;
11
12 static gpointer setup_func(GHashTable *config);
13 static gpointer setup_add_func(GHashTable *config);
14 static gpointer setup_remove_func(GHashTable *config);
15 static void free_func(gpointer o);
16 static gboolean run_func(const ObActionListRun *data, gpointer options);
17
18 void action_addremovedesktop_startup(void)
19 {
20     action_register("AddDesktop", OB_ACTION_DEFAULT_FILTER_EMPTY,
21                     setup_add_func, free_func, run_func);
22     action_register("RemoveDesktop", OB_ACTION_DEFAULT_FILTER_EMPTY,
23                     setup_remove_func, free_func, run_func);
24 }
25
26 static gpointer setup_func(GHashTable *config)
27 {
28     ObActionValue *v;
29     Options *o;
30
31     o = g_slice_new0(Options);
32
33     v = g_hash_table_lookup(config, "where");
34     if (v && action_value_is_string(v)) {
35         const gchar *s = action_value_string(v);
36         if (!g_ascii_strcasecmp(s, "last"))
37             o->current = FALSE;
38         else if (!g_ascii_strcasecmp(s, "current"))
39             o->current = TRUE;
40     }
41
42     return o;
43 }
44
45 static gpointer setup_add_func(GHashTable *config)
46 {
47     Options *o = setup_func(config);
48     o->add = TRUE;
49     return o;
50 }
51
52 static gpointer setup_remove_func(GHashTable *config)
53 {
54     Options *o = setup_func(config);
55     o->add = FALSE;
56     return o;
57 }
58
59 static void free_func(gpointer o)
60 {
61     g_slice_free(Options, o);
62 }
63
64 /* Always return FALSE because its not interactive */
65 static gboolean run_func(const ObActionListRun *data, gpointer options)
66 {
67     Options *o = options;
68
69     action_client_move(data, TRUE);
70
71     if (o->add)
72         screen_add_desktop(o->current);
73     else
74         screen_remove_desktop(o->current);
75
76     action_client_move(data, FALSE);
77
78     return FALSE;
79 }