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"
8 #include "obt/keyboard.h"
12 gboolean dock_windows
;
13 gboolean desktop_windows
;
14 gboolean only_hilite_windows
;
15 gboolean all_desktops
;
19 ObFocusCyclePopupMode dialog_mode
;
23 /* options for after we're done */
24 gboolean cancel
; /* did the user cancel or not */
25 guint state
; /* keyboard state when finished */
28 static gpointer
setup_func(xmlNodePtr node
,
29 ObActionsIPreFunc
*pre
,
30 ObActionsIInputFunc
*in
,
31 ObActionsICancelFunc
*c
,
32 ObActionsIPostFunc
*post
);
33 static gpointer
setup_forward_func(xmlNodePtr node
,
34 ObActionsIPreFunc
*pre
,
35 ObActionsIInputFunc
*in
,
36 ObActionsICancelFunc
*c
,
37 ObActionsIPostFunc
*post
);
38 static gpointer
setup_backward_func(xmlNodePtr node
,
39 ObActionsIPreFunc
*pre
,
40 ObActionsIInputFunc
*in
,
41 ObActionsICancelFunc
*c
,
42 ObActionsIPostFunc
*post
);
43 static void free_func(gpointer options
);
44 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
45 static gboolean
i_input_func(guint initial_state
,
50 static void i_cancel_func(gpointer options
);
51 static void i_post_func(gpointer options
);
53 void action_cyclewindows_startup(void)
55 actions_register_i("NextWindow", setup_forward_func
, free_func
, run_func
);
56 actions_register_i("PreviousWindow", setup_backward_func
, free_func
,
60 static gpointer
setup_func(xmlNodePtr node
,
61 ObActionsIPreFunc
*pre
,
62 ObActionsIInputFunc
*input
,
63 ObActionsICancelFunc
*cancel
,
64 ObActionsIPostFunc
*post
)
69 o
= g_slice_new0(Options
);
71 o
->dialog_mode
= OB_FOCUS_CYCLE_POPUP_MODE_LIST
;
73 if ((n
= obt_xml_find_node(node
, "linear")))
74 o
->linear
= obt_xml_node_bool(n
);
75 if ((n
= obt_xml_find_node(node
, "dialog"))) {
76 if (obt_xml_node_contains(n
, "none"))
77 o
->dialog_mode
= OB_FOCUS_CYCLE_POPUP_MODE_NONE
;
78 else if (obt_xml_node_contains(n
, "icons"))
79 o
->dialog_mode
= OB_FOCUS_CYCLE_POPUP_MODE_ICONS
;
81 if ((n
= obt_xml_find_node(node
, "bar")))
82 o
->bar
= obt_xml_node_bool(n
);
83 if ((n
= obt_xml_find_node(node
, "raise")))
84 o
->raise
= obt_xml_node_bool(n
);
85 if ((n
= obt_xml_find_node(node
, "panels")))
86 o
->dock_windows
= obt_xml_node_bool(n
);
87 if ((n
= obt_xml_find_node(node
, "hilite")))
88 o
->only_hilite_windows
= obt_xml_node_bool(n
);
89 if ((n
= obt_xml_find_node(node
, "desktop")))
90 o
->desktop_windows
= obt_xml_node_bool(n
);
91 if ((n
= obt_xml_find_node(node
, "allDesktops")))
92 o
->all_desktops
= obt_xml_node_bool(n
);
94 if ((n
= obt_xml_find_node(node
, "finalactions"))) {
97 m
= obt_xml_find_node(n
->children
, "action");
99 ObActionsAct
*action
= actions_parse(m
);
100 if (action
) o
->actions
= g_slist_append(o
->actions
, action
);
101 m
= obt_xml_find_node(m
->next
, "action");
105 o
->actions
= g_slist_prepend(o
->actions
,
106 actions_parse_string("Focus"));
107 o
->actions
= g_slist_prepend(o
->actions
,
108 actions_parse_string("Raise"));
109 o
->actions
= g_slist_prepend(o
->actions
,
110 actions_parse_string("Unshade"));
113 *input
= i_input_func
;
114 *cancel
= i_cancel_func
;
119 static gpointer
setup_forward_func(xmlNodePtr node
,
120 ObActionsIPreFunc
*pre
,
121 ObActionsIInputFunc
*input
,
122 ObActionsICancelFunc
*cancel
,
123 ObActionsIPostFunc
*post
)
125 Options
*o
= setup_func(node
, pre
, input
, cancel
, post
);
130 static gpointer
setup_backward_func(xmlNodePtr node
,
131 ObActionsIPreFunc
*pre
,
132 ObActionsIInputFunc
*input
,
133 ObActionsICancelFunc
*cancel
,
134 ObActionsIPostFunc
*post
)
136 Options
*o
= setup_func(node
, pre
, input
, cancel
, post
);
141 static void free_func(gpointer options
)
143 Options
*o
= options
;
146 actions_act_unref(o
->actions
->data
);
147 o
->actions
= g_slist_delete_link(o
->actions
, o
->actions
);
150 g_slice_free(Options
, o
);
153 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
155 Options
*o
= options
;
156 struct _ObClient
*ft
;
158 ft
= focus_cycle(o
->forward
,
160 !o
->only_hilite_windows
,
170 if (o
->raise
&& ft
) stacking_temp_raise(CLIENT_AS_WINDOW(ft
));
175 static gboolean
i_input_func(guint initial_state
,
181 Options
*o
= options
;
184 mods
= obt_keyboard_only_modmasks(e
->xkey
.state
);
185 if (e
->type
== KeyRelease
) {
186 /* remove from the state the mask of the modifier key being
187 released, if it is a modifier key being released that is */
188 mods
&= ~obt_keyboard_keyevent_to_modmask(e
);
191 if (e
->type
== KeyPress
) {
192 KeySym sym
= obt_keyboard_keypress_to_keysym(e
);
194 /* Escape cancels no matter what */
195 if (sym
== XK_Escape
) {
197 o
->state
= e
->xkey
.state
;
201 /* There were no modifiers and they pressed enter */
202 else if ((sym
== XK_Return
|| sym
== XK_KP_Enter
) && !initial_state
) {
204 o
->state
= e
->xkey
.state
;
208 /* They released the modifiers */
209 else if (e
->type
== KeyRelease
&& initial_state
&& !(mods
& initial_state
))
212 o
->state
= e
->xkey
.state
;
219 static void i_cancel_func(gpointer options
)
221 Options
*o
= options
;
226 static void i_post_func(gpointer options
)
228 Options
*o
= options
;
229 struct _ObClient
*ft
;
231 ft
= focus_cycle(o
->forward
,
233 !o
->only_hilite_windows
,
243 actions_run_acts(o
->actions
, OB_USER_ACTION_KEYBOARD_KEY
,
244 o
->state
, -1, -1, 0, OB_FRAME_CONTEXT_NONE
, ft
);