]> Dogcows Code - chaz/openbox/blob - openbox/actions/if.c
Don't run actions in If in reverse order.
[chaz/openbox] / openbox / actions / if.c
1 #include "openbox/actions.h"
2 #include "openbox/misc.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
5 #include "openbox/screen.h"
6 #include "openbox/focus.h"
7 #include <glib.h>
8
9 typedef struct {
10 gboolean shaded_on;
11 gboolean shaded_off;
12 gboolean maxvert_on;
13 gboolean maxvert_off;
14 gboolean maxhorz_on;
15 gboolean maxhorz_off;
16 gboolean maxfull_on;
17 gboolean maxfull_off;
18 gboolean iconic_on;
19 gboolean iconic_off;
20 gboolean focused;
21 gboolean unfocused;
22 GSList *thenacts;
23 GSList *elseacts;
24 } Options;
25
26 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
27 static void free_func(gpointer options);
28 static gboolean run_func(ObActionsData *data, gpointer options);
29
30 void action_if_startup(void)
31 {
32 actions_register("If",
33 setup_func,
34 free_func,
35 run_func,
36 NULL, NULL);
37 }
38
39 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
40 {
41 xmlNodePtr n;
42 Options *o;
43
44 o = g_new0(Options, 1);
45
46 if ((n = parse_find_node("shaded", node))) {
47 if (parse_bool(doc, n))
48 o->shaded_on = TRUE;
49 else
50 o->shaded_off = TRUE;
51 }
52 if ((n = parse_find_node("maximized", node))) {
53 if (parse_bool(doc, n))
54 o->maxfull_on = TRUE;
55 else
56 o->maxfull_off = TRUE;
57 }
58 if ((n = parse_find_node("maximizedhorizontal", node))) {
59 if (parse_bool(doc, n))
60 o->maxhorz_on = TRUE;
61 else
62 o->maxhorz_off = TRUE;
63 }
64 if ((n = parse_find_node("maximizedvertical", node))) {
65 if (parse_bool(doc, n))
66 o->maxvert_on = TRUE;
67 else
68 o->maxvert_off = TRUE;
69 }
70 if ((n = parse_find_node("iconified", node))) {
71 if (parse_bool(doc, n))
72 o->iconic_on = TRUE;
73 else
74 o->iconic_off = TRUE;
75 }
76 if ((n = parse_find_node("focused", node))) {
77 if (parse_bool(doc, n))
78 o->focused = TRUE;
79 else
80 o->unfocused = TRUE;
81 }
82
83 if ((n = parse_find_node("then", node))) {
84 xmlNodePtr m;
85
86 m = parse_find_node("action", n->xmlChildrenNode);
87 while (m) {
88 ObActionsAct *action = actions_parse(i, doc, m);
89 if (action) o->thenacts = g_slist_append(o->thenacts, action);
90 m = parse_find_node("action", m->next);
91 }
92 }
93 if ((n = parse_find_node("else", node))) {
94 xmlNodePtr m;
95
96 m = parse_find_node("action", n->xmlChildrenNode);
97 while (m) {
98 ObActionsAct *action = actions_parse(i, doc, m);
99 if (action) o->elseacts = g_slist_append(o->elseacts, action);
100 m = parse_find_node("action", m->next);
101 }
102 }
103
104 return o;
105 }
106
107 static void free_func(gpointer options)
108 {
109 Options *o = options;
110
111 g_free(o);
112 }
113
114 /* Always return FALSE because its not interactive */
115 static gboolean run_func(ObActionsData *data, gpointer options)
116 {
117 Options *o = options;
118 GSList *acts;
119 ObClient *c = data->client;
120
121 if ((!o->shaded_on || (c && c->shaded)) &&
122 (!o->shaded_off || (c && !c->shaded)) &&
123 (!o->iconic_on || (c && c->iconic)) &&
124 (!o->iconic_off || (c && !c->iconic)) &&
125 (!o->maxhorz_on || (c && c->max_horz)) &&
126 (!o->maxhorz_off || (c && !c->max_horz)) &&
127 (!o->maxvert_on || (c && c->max_vert)) &&
128 (!o->maxvert_off || (c && !c->max_vert)) &&
129 (!o->maxfull_on || (c && c->max_vert && c->max_horz)) &&
130 (!o->maxfull_off || (c && !(c->max_vert && c->max_horz))) &&
131 (!o->focused || (c && (c == focus_client))) &&
132 (!o->unfocused || (c && !(c == focus_client))))
133 {
134 acts = o->thenacts;
135 }
136 else
137 acts = o->elseacts;
138
139 actions_run_acts(acts, data->uact, data->state,
140 data->x, data->y, data->button,
141 data->context, data->client);
142
143 return FALSE;
144 }
This page took 0.041557 seconds and 5 git commands to generate.