1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/focus_cycle.h"
4 #include "openbox/openbox.h"
10 gboolean dock_windows
;
11 gboolean desktop_windows
;
12 gboolean all_desktops
;
17 static gboolean cycling
= FALSE
;
19 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
);
20 static gpointer
setup_forward_func(ObParseInst
*i
, xmlDocPtr doc
,
22 static gpointer
setup_backward_func(ObParseInst
*i
, xmlDocPtr doc
,
24 static void free_func(gpointer options
);
25 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
26 static gboolean
i_input_func(guint initial_state
,
30 static void i_cancel_func(gpointer options
);
32 static void end_cycle(gboolean cancel
, guint state
, Options
*o
);
34 void action_cyclewindows_startup(void)
36 actions_register("NextWindow", setup_forward_func
, free_func
,
37 run_func
, i_input_func
, i_cancel_func
);
38 actions_register("PreviousWindow", setup_backward_func
, free_func
,
39 run_func
, i_input_func
, i_cancel_func
);
42 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
)
47 o
= g_new0(Options
, 1);
50 if ((n
= parse_find_node("linear", node
)))
51 o
->linear
= parse_bool(doc
, n
);
52 if ((n
= parse_find_node("dialog", node
)))
53 o
->dialog
= parse_bool(doc
, n
);
54 if ((n
= parse_find_node("panels", node
)))
55 o
->dock_windows
= parse_bool(doc
, n
);
56 if ((n
= parse_find_node("desktop", node
)))
57 o
->desktop_windows
= parse_bool(doc
, n
);
58 if ((n
= parse_find_node("allDesktops", node
)))
59 o
->all_desktops
= parse_bool(doc
, n
);
61 if ((n
= parse_find_node("finalactions", node
))) {
64 m
= parse_find_node("action", n
->xmlChildrenNode
);
66 ObActionsAct
*action
= actions_parse(i
, doc
, m
);
67 if (action
) o
->actions
= g_slist_prepend(o
->actions
, action
);
68 m
= parse_find_node("action", m
->next
);
72 o
->actions
= g_slist_prepend(o
->actions
,
73 actions_parse_string("Focus"));
74 o
->actions
= g_slist_prepend(o
->actions
,
75 actions_parse_string("Raise"));
76 o
->actions
= g_slist_prepend(o
->actions
,
77 actions_parse_string("Unshade"));
83 static gpointer
setup_forward_func(ObParseInst
*i
, xmlDocPtr doc
,
86 Options
*o
= setup_func(i
, doc
, node
);
91 static gpointer
setup_backward_func(ObParseInst
*i
, xmlDocPtr doc
,
94 Options
*o
= setup_func(i
, doc
, node
);
99 static void free_func(gpointer options
)
101 Options
*o
= options
;
104 actions_act_unref(o
->actions
->data
);
105 o
->actions
= g_slist_delete_link(o
->actions
, o
->actions
);
111 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
113 Options
*o
= options
;
115 focus_cycle(o
->forward
,
128 static gboolean
i_input_func(guint initial_state
,
133 if (e
->type
== KeyPress
) {
134 /* Escape cancels no matter what */
135 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
136 end_cycle(TRUE
, e
->xkey
.state
, options
);
140 /* There were no modifiers and they pressed enter */
141 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
) &&
144 end_cycle(FALSE
, e
->xkey
.state
, options
);
148 /* They released the modifiers */
149 else if (e
->type
== KeyRelease
&& initial_state
&&
150 (e
->xkey
.state
& initial_state
) == 0)
152 end_cycle(FALSE
, e
->xkey
.state
, options
);
159 static void i_cancel_func(gpointer options
)
161 /* we get cancelled when we move focus, but we're not cycling anymore, so
164 end_cycle(TRUE
, 0, options
);
167 static void end_cycle(gboolean cancel
, guint state
, Options
*o
)
169 struct _ObClient
*ft
;
171 ft
= focus_cycle(o
->forward
,
182 actions_run_acts(o
->actions
, OB_USER_ACTION_KEYBOARD_KEY
,
183 state
, -1, -1, 0, OB_FRAME_CONTEXT_NONE
, ft
);