1 #include "openbox/actions.h"
2 #include "openbox/stacking.h"
3 #include "openbox/window.h"
4 #include "openbox/event.h"
5 #include "openbox/focus_cycle.h"
6 #include "openbox/openbox.h"
12 gboolean dock_windows
;
13 gboolean desktop_windows
;
14 gboolean all_desktops
;
21 static gboolean cycling
= FALSE
;
23 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
);
24 static gpointer
setup_forward_func(ObParseInst
*i
, xmlDocPtr doc
,
26 static gpointer
setup_backward_func(ObParseInst
*i
, xmlDocPtr doc
,
28 static void free_func(gpointer options
);
29 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
30 static gboolean
i_input_func(guint initial_state
,
34 static void i_cancel_func(gpointer options
);
36 static void end_cycle(gboolean cancel
, guint state
, Options
*o
);
38 void action_cyclewindows_startup(void)
40 actions_register("NextWindow", setup_forward_func
, free_func
,
41 run_func
, i_input_func
, i_cancel_func
);
42 actions_register("PreviousWindow", setup_backward_func
, free_func
,
43 run_func
, i_input_func
, i_cancel_func
);
46 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
)
51 o
= g_new0(Options
, 1);
55 if ((n
= parse_find_node("linear", node
)))
56 o
->linear
= parse_bool(doc
, n
);
57 if ((n
= parse_find_node("dialog", node
)))
58 o
->dialog
= parse_bool(doc
, n
);
59 if ((n
= parse_find_node("bar", node
)))
60 o
->bar
= parse_bool(doc
, n
);
61 if ((n
= parse_find_node("raise", node
)))
62 o
->raise
= parse_bool(doc
, n
);
63 if ((n
= parse_find_node("panels", node
)))
64 o
->dock_windows
= parse_bool(doc
, n
);
65 if ((n
= parse_find_node("desktop", node
)))
66 o
->desktop_windows
= parse_bool(doc
, n
);
67 if ((n
= parse_find_node("allDesktops", node
)))
68 o
->all_desktops
= parse_bool(doc
, n
);
70 if ((n
= parse_find_node("finalactions", node
))) {
73 m
= parse_find_node("action", n
->xmlChildrenNode
);
75 ObActionsAct
*action
= actions_parse(i
, doc
, m
);
76 if (action
) o
->actions
= g_slist_prepend(o
->actions
, action
);
77 m
= parse_find_node("action", m
->next
);
81 o
->actions
= g_slist_prepend(o
->actions
,
82 actions_parse_string("Focus"));
83 o
->actions
= g_slist_prepend(o
->actions
,
84 actions_parse_string("Raise"));
85 o
->actions
= g_slist_prepend(o
->actions
,
86 actions_parse_string("Unshade"));
92 static gpointer
setup_forward_func(ObParseInst
*i
, xmlDocPtr doc
,
95 Options
*o
= setup_func(i
, doc
, node
);
100 static gpointer
setup_backward_func(ObParseInst
*i
, xmlDocPtr doc
,
103 Options
*o
= setup_func(i
, doc
, node
);
108 static void free_func(gpointer options
)
110 Options
*o
= options
;
113 actions_act_unref(o
->actions
->data
);
114 o
->actions
= g_slist_delete_link(o
->actions
, o
->actions
);
120 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
122 Options
*o
= options
;
123 struct _ObClient
*ft
;
125 ft
= focus_cycle(o
->forward
,
137 if (o
->raise
) stacking_temp_raise(CLIENT_AS_WINDOW(ft
));
142 static gboolean
i_input_func(guint initial_state
,
147 if (e
->type
== KeyPress
) {
148 /* Escape cancels no matter what */
149 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
150 end_cycle(TRUE
, e
->xkey
.state
, options
);
154 /* There were no modifiers and they pressed enter */
155 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
) &&
158 end_cycle(FALSE
, e
->xkey
.state
, options
);
162 /* They released the modifiers */
163 else if (e
->type
== KeyRelease
&& initial_state
&&
164 (e
->xkey
.state
& initial_state
) == 0)
166 end_cycle(FALSE
, e
->xkey
.state
, options
);
173 static void i_cancel_func(gpointer options
)
175 /* we get cancelled when we move focus, but we're not cycling anymore, so
178 end_cycle(TRUE
, 0, options
);
181 static void end_cycle(gboolean cancel
, guint state
, Options
*o
)
183 struct _ObClient
*ft
;
185 ft
= focus_cycle(o
->forward
,
197 actions_run_acts(o
->actions
, OB_USER_ACTION_KEYBOARD_KEY
,
198 state
, -1, -1, 0, OB_FRAME_CONTEXT_NONE
, ft
);