1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/focus_cycle.h"
4 #include "openbox/openbox.h"
5 #include "openbox/misc.h"
10 gboolean dock_windows
;
11 gboolean desktop_windows
;
12 ObDirection direction
;
16 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
);
17 static void free_func(gpointer options
);
18 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
19 static gboolean
i_input_func(guint initial_state
,
23 static void i_cancel_func(gpointer options
);
25 static void end_cycle(gboolean cancel
, guint state
, Options
*o
);
27 void action_directionalcyclewindows_startup()
29 actions_register("DirectionalCycleWindows",
37 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
)
42 o
= g_new0(Options
, 1);
45 if ((n
= parse_find_node("dialog", node
)))
46 o
->dialog
= parse_bool(doc
, n
);
47 if ((n
= parse_find_node("panels", node
)))
48 o
->dock_windows
= parse_bool(doc
, n
);
49 if ((n
= parse_find_node("desktop", node
)))
50 o
->desktop_windows
= parse_bool(doc
, n
);
51 if ((n
= parse_find_node("direction", node
))) {
52 gchar
*s
= parse_string(doc
, n
);
53 if (!g_ascii_strcasecmp(s
, "north") ||
54 !g_ascii_strcasecmp(s
, "up"))
55 o
->direction
= OB_DIRECTION_NORTH
;
56 else if (!g_ascii_strcasecmp(s
, "northwest"))
57 o
->direction
= OB_DIRECTION_NORTHWEST
;
58 else if (!g_ascii_strcasecmp(s
, "northeast"))
59 o
->direction
= OB_DIRECTION_NORTHEAST
;
60 else if (!g_ascii_strcasecmp(s
, "west") ||
61 !g_ascii_strcasecmp(s
, "left"))
62 o
->direction
= OB_DIRECTION_WEST
;
63 else if (!g_ascii_strcasecmp(s
, "east") ||
64 !g_ascii_strcasecmp(s
, "right"))
65 o
->direction
= OB_DIRECTION_EAST
;
66 else if (!g_ascii_strcasecmp(s
, "south") ||
67 !g_ascii_strcasecmp(s
, "down"))
68 o
->direction
= OB_DIRECTION_SOUTH
;
69 else if (!g_ascii_strcasecmp(s
, "southwest"))
70 o
->direction
= OB_DIRECTION_SOUTHWEST
;
71 else if (!g_ascii_strcasecmp(s
, "southeast"))
72 o
->direction
= OB_DIRECTION_SOUTHEAST
;
76 if ((n
= parse_find_node("finalactions", node
))) {
79 m
= parse_find_node("action", n
->xmlChildrenNode
);
81 ObActionsAct
*action
= actions_parse(i
, doc
, m
);
82 if (action
) o
->actions
= g_slist_prepend(o
->actions
, action
);
83 m
= parse_find_node("action", m
->next
);
89 static void free_func(gpointer options
)
96 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
100 /* if using focus_delay, stop the timer now so that focus doesn't go moving
102 event_halt_focus_delay();
104 focus_directional_cycle(o
->direction
,
114 static gboolean
i_input_func(guint initial_state
,
119 if (e
->type
== KeyPress
) {
120 /* Escape cancels no matter what */
121 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
122 end_cycle(TRUE
, e
->xkey
.state
, options
);
126 /* There were no modifiers and they pressed enter */
127 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
) &&
130 end_cycle(FALSE
, e
->xkey
.state
, options
);
134 /* They released the modifiers */
135 else if (e
->type
== KeyRelease
&& initial_state
&&
136 (e
->xkey
.state
& initial_state
) == 0)
138 end_cycle(FALSE
, e
->xkey
.state
, options
);
145 static void i_cancel_func(gpointer options
)
147 end_cycle(TRUE
, 0, options
);
150 static void end_cycle(gboolean cancel
, guint state
, Options
*o
)
152 struct _ObClient
*ft
;
154 ft
= focus_directional_cycle(o
->direction
,
162 actions_run_acts(o
->actions
, OB_USER_ACTION_KEYBOARD_KEY
,
163 state
, -1, -1, 0, OB_FRAME_CONTEXT_NONE
, ft
);