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 guint screendesktop_number;
32 GPatternSpec *matchtitle;
37 static gpointer setup_func(xmlNodePtr node);
38 static void free_func(gpointer options);
39 static gboolean run_func(ObActionsData *data, gpointer options);
41 void action_if_startup(void)
43 actions_register("If", setup_func, free_func, run_func);
46 static gpointer setup_func(xmlNodePtr node)
51 o = g_slice_new0(Options);
53 if ((n = obt_xml_find_node(node, "shaded"))) {
54 if (obt_xml_node_bool(n))
59 if ((n = obt_xml_find_node(node, "maximized"))) {
60 if (obt_xml_node_bool(n))
63 o->maxfull_off = TRUE;
65 if ((n = obt_xml_find_node(node, "maximizedhorizontal"))) {
66 if (obt_xml_node_bool(n))
69 o->maxhorz_off = TRUE;
71 if ((n = obt_xml_find_node(node, "maximizedvertical"))) {
72 if (obt_xml_node_bool(n))
75 o->maxvert_off = TRUE;
77 if ((n = obt_xml_find_node(node, "iconified"))) {
78 if (obt_xml_node_bool(n))
83 if ((n = obt_xml_find_node(node, "focused"))) {
84 if (obt_xml_node_bool(n))
89 if ((n = obt_xml_find_node(node, "urgent"))) {
90 if (obt_xml_node_bool(n))
95 if ((n = obt_xml_find_node(node, "undecorated"))) {
96 if (obt_xml_node_bool(n))
101 if ((n = obt_xml_find_node(node, "desktop"))) {
103 if ((s = obt_xml_node_string(n))) {
104 if (!g_ascii_strcasecmp(s, "current"))
105 o->desktop_current = TRUE;
106 if (!g_ascii_strcasecmp(s, "other"))
107 o->desktop_other = TRUE;
109 o->desktop_number = atoi(s);
113 if ((n = obt_xml_find_node(node, "omnipresent"))) {
114 if (obt_xml_node_bool(n))
115 o->omnipresent_on = TRUE;
117 o->omnipresent_off = TRUE;
118 if ((n = obt_xml_find_node(node, "activedesktop"))) {
119 o->screendesktop_number = obt_xml_node_int(n);
121 if ((n = obt_xml_find_node(node, "title"))) {
123 if ((s = obt_xml_node_string(n))) {
124 o->matchtitle = g_pattern_spec_new(s);
129 if ((n = obt_xml_find_node(node, "then"))) {
132 m = obt_xml_find_node(n->children, "action");
134 ObActionsAct *action = actions_parse(m);
135 if (action) o->thenacts = g_slist_append(o->thenacts, action);
136 m = obt_xml_find_node(m->next, "action");
139 if ((n = obt_xml_find_node(node, "else"))) {
142 m = obt_xml_find_node(n->children, "action");
144 ObActionsAct *action = actions_parse(m);
145 if (action) o->elseacts = g_slist_append(o->elseacts, action);
146 m = obt_xml_find_node(m->next, "action");
153 static void free_func(gpointer options)
155 Options *o = options;
157 while (o->thenacts) {
158 actions_act_unref(o->thenacts->data);
159 o->thenacts = g_slist_delete_link(o->thenacts, o->thenacts);
161 while (o->elseacts) {
162 actions_act_unref(o->elseacts->data);
163 o->elseacts = g_slist_delete_link(o->elseacts, o->elseacts);
166 g_pattern_spec_free(o->matchtitle);
168 g_slice_free(Options, o);
171 /* Always return FALSE because its not interactive */
172 static gboolean run_func(ObActionsData *data, gpointer options)
174 Options *o = options;
176 ObClient *c = data->client;
179 (!o->shaded_on || c->shaded) &&
180 (!o->shaded_off || !c->shaded) &&
181 (!o->iconic_on || c->iconic) &&
182 (!o->iconic_off || !c->iconic) &&
183 (!o->maxhorz_on || c->max_horz) &&
184 (!o->maxhorz_off || !c->max_horz) &&
185 (!o->maxvert_on || c->max_vert) &&
186 (!o->maxvert_off || !c->max_vert) &&
187 (!o->maxfull_on || (c->max_vert && c->max_horz)) &&
188 (!o->maxfull_off || !(c->max_vert && c->max_horz)) &&
189 (!o->focused || (c == focus_client)) &&
190 (!o->unfocused || !(c == focus_client)) &&
191 (!o->urgent_on || (c->urgent || c->demands_attention)) &&
192 (!o->urgent_off || !(c->urgent || c->demands_attention)) &&
193 (!o->decor_off || (c->undecorated || !(c->decorations & OB_FRAME_DECOR_TITLEBAR))) &&
194 (!o->decor_on || (!c->undecorated && (c->decorations & OB_FRAME_DECOR_TITLEBAR))) &&
195 (!o->omnipresent_on || (c->desktop == DESKTOP_ALL)) &&
196 (!o->omnipresent_off || (c->desktop != DESKTOP_ALL)) &&
197 (!o->desktop_current || ((c->desktop == screen_desktop) ||
198 (c->desktop == DESKTOP_ALL))) &&
199 (!o->desktop_other || ((c->desktop != screen_desktop) &&
200 (c->desktop != DESKTOP_ALL))) &&
201 (!o->desktop_number || ((c->desktop == o->desktop_number - 1) ||
202 (c->desktop == DESKTOP_ALL))) &&
203 (!o->screendesktop_number || screen_desktop == o->screendesktop_number - 1) &&
205 (g_pattern_match_string(o->matchtitle, c->original_title))))
212 actions_run_acts(acts, data->uact, data->state,
213 data->x, data->y, data->button,
214 data->context, data->client);