]>
Dogcows Code - chaz/openbox/blob - 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"
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"))) {
101 gchar
*s
= obt_xml_node_string(n
);
102 if (!g_ascii_strcasecmp(s
, "current"))
103 o
->desktop_current
= TRUE
;
104 if (!g_ascii_strcasecmp(s
, "other"))
105 o
->desktop_other
= TRUE
;
107 o
->desktop_number
= atoi(s
);
109 if ((n
= obt_xml_find_node(node
, "omnipresent"))) {
110 if (obt_xml_node_bool(n
))
111 o
->omnipresent_on
= TRUE
;
113 o
->omnipresent_off
= TRUE
;
115 if ((n
= obt_xml_find_node(node
, "title"))) {
117 if ((s
= obt_xml_node_string(n
))) {
118 o
->matchtitle
= g_pattern_spec_new(s
);
123 if ((n
= obt_xml_find_node(node
, "then"))) {
126 m
= obt_xml_find_node(n
->children
, "action");
128 ObActionsAct
*action
= actions_parse(m
);
129 if (action
) o
->thenacts
= g_slist_append(o
->thenacts
, action
);
130 m
= obt_xml_find_node(m
->next
, "action");
133 if ((n
= obt_xml_find_node(node
, "else"))) {
136 m
= obt_xml_find_node(n
->children
, "action");
138 ObActionsAct
*action
= actions_parse(m
);
139 if (action
) o
->elseacts
= g_slist_append(o
->elseacts
, action
);
140 m
= obt_xml_find_node(m
->next
, "action");
147 static void free_func(gpointer options
)
149 Options
*o
= options
;
151 while (o
->thenacts
) {
152 actions_act_unref(o
->thenacts
->data
);
153 o
->thenacts
= g_slist_delete_link(o
->thenacts
, o
->thenacts
);
155 while (o
->elseacts
) {
156 actions_act_unref(o
->elseacts
->data
);
157 o
->elseacts
= g_slist_delete_link(o
->elseacts
, o
->elseacts
);
160 g_pattern_spec_free(o
->matchtitle
);
162 g_slice_free(Options
, o
);
165 /* Always return FALSE because its not interactive */
166 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
168 Options
*o
= options
;
170 ObClient
*c
= data
->client
;
173 (!o
->shaded_on
|| c
->shaded
) &&
174 (!o
->shaded_off
|| !c
->shaded
) &&
175 (!o
->iconic_on
|| c
->iconic
) &&
176 (!o
->iconic_off
|| !c
->iconic
) &&
177 (!o
->maxhorz_on
|| c
->max_horz
) &&
178 (!o
->maxhorz_off
|| !c
->max_horz
) &&
179 (!o
->maxvert_on
|| c
->max_vert
) &&
180 (!o
->maxvert_off
|| !c
->max_vert
) &&
181 (!o
->maxfull_on
|| (c
->max_vert
&& c
->max_horz
)) &&
182 (!o
->maxfull_off
|| !(c
->max_vert
&& c
->max_horz
)) &&
183 (!o
->focused
|| (c
== focus_client
)) &&
184 (!o
->unfocused
|| !(c
== focus_client
)) &&
185 (!o
->urgent_on
|| (c
->urgent
|| c
->demands_attention
)) &&
186 (!o
->urgent_off
|| !(c
->urgent
|| c
->demands_attention
)) &&
187 (!o
->decor_off
|| (c
->undecorated
|| !(c
->decorations
& OB_FRAME_DECOR_TITLEBAR
))) &&
188 (!o
->decor_on
|| (!c
->undecorated
&& (c
->decorations
& OB_FRAME_DECOR_TITLEBAR
))) &&
189 (!o
->omnipresent_on
|| (c
->desktop
== DESKTOP_ALL
)) &&
190 (!o
->omnipresent_off
|| (c
->desktop
!= DESKTOP_ALL
)) &&
191 (!o
->desktop_current
|| ((c
->desktop
== screen_desktop
) ||
192 (c
->desktop
== DESKTOP_ALL
))) &&
193 (!o
->desktop_other
|| ((c
->desktop
!= screen_desktop
) &&
194 (c
->desktop
!= DESKTOP_ALL
))) &&
195 (!o
->desktop_number
|| ((c
->desktop
== o
->desktop_number
- 1) ||
196 (c
->desktop
== DESKTOP_ALL
))) &&
198 (g_pattern_match_string(o
->matchtitle
, c
->original_title
))))
205 actions_run_acts(acts
, data
->uact
, data
->state
,
206 data
->x
, data
->y
, data
->button
,
207 data
->context
, data
->client
);
This page took 0.048991 seconds and 4 git commands to generate.