]> Dogcows Code - chaz/openbox/blob - openbox/actions/desktop.c
3132a4fc253573453ab0107162de6b4a8b15caea
[chaz/openbox] / openbox / actions / desktop.c
1 #include "openbox/actions.h"
2 #include "openbox/screen.h"
3 #include "openbox/client.h"
4 #include <glib.h>
5
6 typedef enum {
7 LAST,
8 RELATIVE,
9 ABSOLUTE
10 } SwitchType;
11
12 typedef struct {
13 SwitchType type;
14 union {
15 struct {
16 guint desktop;
17 } abs;
18
19 struct {
20 gboolean linear;
21 gboolean wrap;
22 ObDirection dir;
23 } rel;
24 }
25 gboolean send;
26 gboolean follow;
27 } Options;
28
29 static gpointer setup_switch_func(ObParseInst *i, xmlDocPtr doc,
30 xmlNodePtr node);
31 static gpointer setup_send_func(ObParseInst *i, xmlDocPtr doc,
32 xmlNodePtr node);
33 static gboolean run_func(ObActionsData *data, gpointer options);
34
35 void action_desktop_startup()
36 {
37 actions_register("SwitchToDesktop", setup_switch_func, g_free, run_func,
38 NULL, NULL);
39 actions_register("SendToDesktop", setup_send_func, g_free, run_func,
40 NULL, NULL);
41 }
42
43 static gpointer setup_switch_func(ObParseInst *i, xmlDocPtr doc,
44 xmlNodePtr node)
45 {
46 xmlNodePtr n;
47 Options *o;
48
49 o = g_new0(Options, 1);
50 /* don't go anywhere if theres no options given */
51 o->type = ABSOLUTE;
52 o->abs.desktop = screen_desktop;
53 /* wrap by default - it's handy! */
54 o->rel.wrap = TRUE;
55
56 if ((n = parse_find_node("to", node))) {
57 gchar *s = parse_string(doc, n);
58 if (!g_ascii_strcasecmp(s, "last") ||
59 !g_ascii_strcasecmp(s, "previous"))
60 o->type = LAST;
61 else if (!g_ascii_strcasecmp(s, "next")) {
62 o->type = RELATIVE;
63 o->rel.linear = TRUE;
64 o->rel.dir = OB_DIRECTION_EAST;
65 }
66 else if (!g_ascii_strcasecmp(s, "previous")) {
67 o->type = RELATIVE;
68 o->rel.linear = TRUE;
69 o->rel.dir = OB_DIRECTION_WEST;
70 }
71 else if (!g_ascii_strcasecmp(s, "north") ||
72 !g_ascii_strcasecmp(s, "up")) {
73 o->type = RELATIVE;
74 o->rel.dir = OB_DIRECTION_NORTH;
75 }
76 else if (!g_ascii_strcasecmp(s, "south") ||
77 !g_ascii_strcasecmp(s, "down")) {
78 o->type = RELATIVE;
79 o->rel.dir = OB_DIRECTION_SOUTH;
80 }
81 else if (!g_ascii_strcasecmp(s, "west") ||
82 !g_ascii_strcasecmp(s, "left")) {
83 o->type = RELATIVE;
84 o->rel.dir = OB_DIRECTION_WEST;
85 }
86 else if (!g_ascii_strcasecmp(s, "east") ||
87 !g_ascii_strcasecmp(s, "right")) {
88 o->type = RELATIVE;
89 o->rel.dir = OB_DIRECTION_EAST;
90 }
91 else {
92 o->type = ABSOLUTE;
93 o->abs.desktop = parse_int(doc, n) - 1;
94 }
95 g_free(s);
96 }
97
98 if ((n = parse_find_node("wrap", node)))
99 o->rel.wrap = parse_bool(doc, n);
100
101 return o;
102 }
103
104 static gpointer setup_send_func(ObParseInst *i, xmlDocPtr doc,
105 xmlNodePtr node)
106 {
107 Options *o = setup_switch_func(i, doc, node);
108 o->send = TRUE;
109 o->follow = TRUE;
110
111 if ((n = parse_find_node("follow", node)))
112 o->follow = parse_bool(doc, n);
113
114 return o;
115 }
116
117 /* Always return FALSE because its not interactive */
118 static gboolean run_func(ObActionsData *data, gpointer options)
119 {
120 Options *o = options;
121 guint d;
122
123
124
125 switch (o->type) {
126 case LAST:
127 d = screen_last_desktop;
128 break;
129 case ABSOLUTE:
130 d = o->abs.desktop;
131 break;
132 case RELATIVE:
133 d = screen_cycle_desktop(o->abs.dir,
134 o->abs.wrap,
135 o->abs.linear,
136 FALSE, TRUE, FALSE);
137 break;
138 }
139
140 if (d < screen_num_desktops && d != screen_desktop) {
141 gboolean go = TRUE;
142
143 if (o->send && data->client && client_normal(data->client)) {
144 client_set_desktop(data->client, d, o->follow, FALSE);
145 go = o->follow;
146 }
147
148 if (go) screen_set_desktop(d, TRUE);
149 }
150 return FALSE;
151 }
This page took 0.036105 seconds and 3 git commands to generate.