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"
11 gboolean dock_windows
;
12 gboolean desktop_windows
;
13 gboolean all_desktops
;
17 ObFocusCyclePopupMode dialog_mode
;
21 static gboolean cycling
= FALSE
;
23 static gpointer
setup_func(xmlNodePtr node
);
24 static gpointer
setup_forward_func(xmlNodePtr node
);
25 static gpointer
setup_backward_func(xmlNodePtr node
);
26 static void free_func(gpointer options
);
27 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
28 static gboolean
i_input_func(guint initial_state
,
32 static void i_cancel_func(gpointer options
);
34 static void end_cycle(gboolean cancel
, guint state
, Options
*o
);
36 void action_cyclewindows_startup(void)
38 actions_register("NextWindow", setup_forward_func
, free_func
,
39 run_func
, i_input_func
, i_cancel_func
);
40 actions_register("PreviousWindow", setup_backward_func
, free_func
,
41 run_func
, i_input_func
, i_cancel_func
);
44 static gpointer
setup_func(xmlNodePtr node
)
49 o
= g_new0(Options
, 1);
51 o
->dialog_mode
= OB_FOCUS_CYCLE_POPUP_MODE_LIST
;
53 if ((n
= obt_parse_find_node(node
, "linear")))
54 o
->linear
= obt_parse_node_bool(n
);
55 if ((n
= obt_parse_find_node(node
, "dialog"))) {
56 if (obt_parse_node_contains(n
, "none"))
57 o
->dialog_mode
= OB_FOCUS_CYCLE_POPUP_MODE_NONE
;
58 else if (obt_parse_node_contains(n
, "icons"))
59 o
->dialog_mode
= OB_FOCUS_CYCLE_POPUP_MODE_ICONS
;
61 if ((n
= obt_parse_find_node(node
, "bar")))
62 o
->bar
= obt_parse_node_bool(n
);
63 if ((n
= obt_parse_find_node(node
, "raise")))
64 o
->raise
= obt_parse_node_bool(n
);
65 if ((n
= obt_parse_find_node(node
, "panels")))
66 o
->dock_windows
= obt_parse_node_bool(n
);
67 if ((n
= obt_parse_find_node(node
, "desktop")))
68 o
->desktop_windows
= obt_parse_node_bool(n
);
69 if ((n
= obt_parse_find_node(node
, "allDesktops")))
70 o
->all_desktops
= obt_parse_node_bool(n
);
72 if ((n
= obt_parse_find_node(node
, "finalactions"))) {
75 m
= obt_parse_find_node(n
->children
, "action");
77 ObActionsAct
*action
= actions_parse(m
);
78 if (action
) o
->actions
= g_slist_prepend(o
->actions
, action
);
79 m
= obt_parse_find_node(m
->next
, "action");
83 o
->actions
= g_slist_prepend(o
->actions
,
84 actions_parse_string("Focus"));
85 o
->actions
= g_slist_prepend(o
->actions
,
86 actions_parse_string("Raise"));
87 o
->actions
= g_slist_prepend(o
->actions
,
88 actions_parse_string("Unshade"));
94 static gpointer
setup_forward_func(xmlNodePtr node
)
96 Options
*o
= setup_func(node
);
101 static gpointer
setup_backward_func(xmlNodePtr node
)
103 Options
*o
= setup_func(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
&& ft
) 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
);