]> Dogcows Code - chaz/openbox/blob - openbox/actions/addremovedesktop.c
Merge branch 'm4/master'
[chaz/openbox] / openbox / actions / addremovedesktop.c
1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include <glib.h>
4
5 typedef struct {
6 gboolean current;
7 gboolean add;
8 } Options;
9
10 static gpointer setup_func(xmlNodePtr node);
11 static gpointer setup_add_func(xmlNodePtr node);
12 static gpointer setup_remove_func(xmlNodePtr node);
13 static void free_func(gpointer o);
14 static gboolean run_func(ObActionsData *data, gpointer options);
15 /* 3.4-compatibility */
16 static gpointer setup_addcurrent_func(xmlNodePtr node);
17 static gpointer setup_addlast_func(xmlNodePtr node);
18 static gpointer setup_removecurrent_func(xmlNodePtr node);
19 static gpointer setup_removelast_func(xmlNodePtr node);
20
21 void action_addremovedesktop_startup(void)
22 {
23 actions_register("AddDesktop", setup_add_func, free_func, run_func);
24 actions_register("RemoveDesktop", setup_remove_func, free_func, run_func);
25
26 /* 3.4-compatibility */
27 actions_register("AddDesktopLast", setup_addlast_func,
28 free_func, run_func);
29 actions_register("RemoveDesktopLast", setup_removelast_func,
30 free_func, run_func);
31 actions_register("AddDesktopCurrent", setup_addcurrent_func,
32 free_func, run_func);
33 actions_register("RemoveDesktopCurrent", setup_removecurrent_func,
34 free_func, run_func);
35 }
36
37 static gpointer setup_func(xmlNodePtr node)
38 {
39 xmlNodePtr n;
40 Options *o;
41
42 o = g_slice_new0(Options);
43
44 if ((n = obt_xml_find_node(node, "where"))) {
45 gchar *s = obt_xml_node_string(n);
46 if (!g_ascii_strcasecmp(s, "last"))
47 o->current = FALSE;
48 else if (!g_ascii_strcasecmp(s, "current"))
49 o->current = TRUE;
50 g_free(s);
51 }
52
53 return o;
54 }
55
56 static gpointer setup_add_func(xmlNodePtr node)
57 {
58 Options *o = setup_func(node);
59 o->add = TRUE;
60 return o;
61 }
62
63 static gpointer setup_remove_func(xmlNodePtr node)
64 {
65 Options *o = setup_func(node);
66 o->add = FALSE;
67 return o;
68 }
69
70 static void free_func(gpointer o)
71 {
72 g_slice_free(Options, o);
73 }
74
75 /* Always return FALSE because its not interactive */
76 static gboolean run_func(ObActionsData *data, gpointer options)
77 {
78 Options *o = options;
79
80 actions_client_move(data, TRUE);
81
82 if (o->add)
83 screen_add_desktop(o->current);
84 else
85 screen_remove_desktop(o->current);
86
87 actions_client_move(data, FALSE);
88
89 return FALSE;
90 }
91
92 /* 3.4-compatibility */
93 static gpointer setup_addcurrent_func(xmlNodePtr node)
94 {
95 Options *o = setup_add_func(node);
96 o->current = TRUE;
97 return o;
98 }
99
100 static gpointer setup_addlast_func(xmlNodePtr node)
101 {
102 Options *o = setup_add_func(node);
103 o->current = FALSE;
104 return o;
105 }
106
107 static gpointer setup_removecurrent_func(xmlNodePtr node)
108 {
109 Options *o = setup_remove_func(node);
110 o->current = TRUE;
111 return o;
112 }
113
114 static gpointer setup_removelast_func(xmlNodePtr node)
115 {
116 Options *o = setup_remove_func(node);
117 o->current = FALSE;
118 return o;
119 }
This page took 0.039198 seconds and 4 git commands to generate.