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