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"
26 gboolean omnipresent_on;
27 gboolean omnipresent_off;
28 gboolean desktop_current;
29 gboolean desktop_other;
31 GPatternSpec *matchtitle;
36 static gpointer setup_func(xmlNodePtr node);
37 static void free_func(gpointer options);
38 static gboolean run_func(ObActionsData *data, gpointer options);
40 void action_if_startup(void)
42 actions_register("If", setup_func, free_func, run_func);
45 static gpointer setup_func(xmlNodePtr node)
50 o = g_slice_new0(Options);
52 if ((n = obt_xml_find_node(node, "shaded"))) {
53 if (obt_xml_node_bool(n))
58 if ((n = obt_xml_find_node(node, "maximized"))) {
59 if (obt_xml_node_bool(n))
62 o->maxfull_off = TRUE;
64 if ((n = obt_xml_find_node(node, "maximizedhorizontal"))) {
65 if (obt_xml_node_bool(n))
68 o->maxhorz_off = TRUE;
70 if ((n = obt_xml_find_node(node, "maximizedvertical"))) {
71 if (obt_xml_node_bool(n))
74 o->maxvert_off = TRUE;
76 if ((n = obt_xml_find_node(node, "iconified"))) {
77 if (obt_xml_node_bool(n))
82 if ((n = obt_xml_find_node(node, "focused"))) {
83 if (obt_xml_node_bool(n))
88 if ((n = obt_xml_find_node(node, "urgent"))) {
89 if (obt_xml_node_bool(n))
94 if ((n = obt_xml_find_node(node, "undecorated"))) {
95 if (obt_xml_node_bool(n))
100 if ((n = obt_xml_find_node(node, "desktop"))) {
102 if ((s = obt_xml_node_string(n))) {
103 if (!g_ascii_strcasecmp(s, "current"))
104 o->desktop_current = TRUE;
105 if (!g_ascii_strcasecmp(s, "other"))
106 o->desktop_other = TRUE;
108 o->desktop_number = atoi(s);
112 if ((n = obt_xml_find_node(node, "omnipresent"))) {
113 if (obt_xml_node_bool(n))
114 o->omnipresent_on = TRUE;
116 o->omnipresent_off = TRUE;
118 if ((n = obt_xml_find_node(node, "title"))) {
120 if ((s = obt_xml_node_string(n))) {
121 o->matchtitle = g_pattern_spec_new(s);
126 if ((n = obt_xml_find_node(node, "then"))) {
129 m = obt_xml_find_node(n->children, "action");
131 ObActionsAct *action = actions_parse(m);
132 if (action) o->thenacts = g_slist_append(o->thenacts, action);
133 m = obt_xml_find_node(m->next, "action");
136 if ((n = obt_xml_find_node(node, "else"))) {
139 m = obt_xml_find_node(n->children, "action");
141 ObActionsAct *action = actions_parse(m);
142 if (action) o->elseacts = g_slist_append(o->elseacts, action);
143 m = obt_xml_find_node(m->next, "action");
150 static void free_func(gpointer options)
152 Options *o = options;
154 while (o->thenacts) {
155 actions_act_unref(o->thenacts->data);
156 o->thenacts = g_slist_delete_link(o->thenacts, o->thenacts);
158 while (o->elseacts) {
159 actions_act_unref(o->elseacts->data);
160 o->elseacts = g_slist_delete_link(o->elseacts, o->elseacts);
163 g_pattern_spec_free(o->matchtitle);
165 g_slice_free(Options, o);
168 /* Always return FALSE because its not interactive */
169 static gboolean run_func(ObActionsData *data, gpointer options)
171 Options *o = options;
173 ObClient *c = data->client;
176 (!o->shaded_on || c->shaded) &&
177 (!o->shaded_off || !c->shaded) &&
178 (!o->iconic_on || c->iconic) &&
179 (!o->iconic_off || !c->iconic) &&
180 (!o->maxhorz_on || c->max_horz) &&
181 (!o->maxhorz_off || !c->max_horz) &&
182 (!o->maxvert_on || c->max_vert) &&
183 (!o->maxvert_off || !c->max_vert) &&
184 (!o->maxfull_on || (c->max_vert && c->max_horz)) &&
185 (!o->maxfull_off || !(c->max_vert && c->max_horz)) &&
186 (!o->focused || (c == focus_client)) &&
187 (!o->unfocused || !(c == focus_client)) &&
188 (!o->urgent_on || (c->urgent || c->demands_attention)) &&
189 (!o->urgent_off || !(c->urgent || c->demands_attention)) &&
190 (!o->decor_off || (c->undecorated || !(c->decorations & OB_FRAME_DECOR_TITLEBAR))) &&
191 (!o->decor_on || (!c->undecorated && (c->decorations & OB_FRAME_DECOR_TITLEBAR))) &&
192 (!o->omnipresent_on || (c->desktop == DESKTOP_ALL)) &&
193 (!o->omnipresent_off || (c->desktop != DESKTOP_ALL)) &&
194 (!o->desktop_current || ((c->desktop == screen_desktop) ||
195 (c->desktop == DESKTOP_ALL))) &&
196 (!o->desktop_other || ((c->desktop != screen_desktop) &&
197 (c->desktop != DESKTOP_ALL))) &&
198 (!o->desktop_number || ((c->desktop == o->desktop_number - 1) ||
199 (c->desktop == DESKTOP_ALL))) &&
201 (g_pattern_match_string(o->matchtitle, c->original_title))))
208 actions_run_acts(acts, data->uact, data->state,
209 data->x, data->y, data->button,
210 data->context, data->client);