]> Dogcows Code - chaz/openbox/blob - openbox/actions/directionalcyclewindows.c
add the directionalcyclewindows action
[chaz/openbox] / openbox / actions / directionalcyclewindows.c
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"
6 #include "gettext.h"
7
8 typedef struct {
9 gboolean dialog;
10 gboolean dock_windows;
11 gboolean desktop_windows;
12 ObDirection direction;
13 GSList *actions;
14 } Options;
15
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,
20 XEvent *e,
21 gpointer options,
22 gboolean *used);
23 static void i_cancel_func(gpointer options);
24
25 static void end_cycle(gboolean cancel, guint state, Options *o);
26
27 void action_directionalcyclewindows_startup()
28 {
29 actions_register("DirectionalCycleWindows",
30 setup_func,
31 free_func,
32 run_func,
33 i_input_func,
34 i_cancel_func);
35 }
36
37 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
38 {
39 xmlNodePtr n;
40 Options *o;
41
42 o = g_new0(Options, 1);
43 o->dialog = TRUE;
44
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 o->direction = OB_DIRECTION_NORTH;
55 else if (!g_ascii_strcasecmp(s, "northwest"))
56 o->direction = OB_DIRECTION_NORTHWEST;
57 else if (!g_ascii_strcasecmp(s, "northeast"))
58 o->direction = OB_DIRECTION_NORTHEAST;
59 else if (!g_ascii_strcasecmp(s, "west"))
60 o->direction = OB_DIRECTION_WEST;
61 else if (!g_ascii_strcasecmp(s, "east"))
62 o->direction = OB_DIRECTION_EAST;
63 else if (!g_ascii_strcasecmp(s, "south"))
64 o->direction = OB_DIRECTION_NORTH;
65 else if (!g_ascii_strcasecmp(s, "southwest"))
66 o->direction = OB_DIRECTION_NORTHWEST;
67 else if (!g_ascii_strcasecmp(s, "southeast"))
68 o->direction = OB_DIRECTION_NORTHEAST;
69 g_free(s);
70 }
71
72 if ((n = parse_find_node("actions", node))) {
73 xmlNodePtr m;
74
75 m = parse_find_node("action", n->xmlChildrenNode);
76 while (m) {
77 ObActionsAct *action = actions_parse(i, doc, m);
78 if (action) o->actions = g_slist_prepend(o->actions, action);
79 m = parse_find_node("action", m->next);
80 }
81 }
82 return o;
83 }
84
85 static void free_func(gpointer options)
86 {
87 Options *o = options;
88
89 g_free(o);
90 }
91
92 static gboolean run_func(ObActionsData *data, gpointer options)
93 {
94 Options *o = options;
95
96 /* if using focus_delay, stop the timer now so that focus doesn't go moving
97 on us */
98 event_halt_focus_delay();
99
100 focus_directional_cycle(o->direction,
101 o->dock_windows,
102 o->desktop_windows,
103 TRUE,
104 o->dialog,
105 FALSE, FALSE);
106
107 return TRUE;
108 }
109
110 static gboolean i_input_func(guint initial_state,
111 XEvent *e,
112 gpointer options,
113 gboolean *used)
114 {
115 if (e->type == KeyPress) {
116 /* Escape cancels no matter what */
117 if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE)) {
118 end_cycle(TRUE, e->xkey.state, options);
119 return FALSE;
120 }
121
122 /* There were no modifiers and they pressed enter */
123 else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN) &&
124 !initial_state)
125 {
126 end_cycle(FALSE, e->xkey.state, options);
127 return FALSE;
128 }
129 }
130 /* They released the modifiers */
131 else if (e->type == KeyRelease && initial_state &&
132 (e->xkey.state & initial_state) == 0)
133 {
134 end_cycle(FALSE, e->xkey.state, options);
135 return FALSE;
136 }
137
138 return TRUE;
139 }
140
141 static void i_cancel_func(gpointer options)
142 {
143 end_cycle(TRUE, 0, options);
144 }
145
146 static void end_cycle(gboolean cancel, guint state, Options *o)
147 {
148 struct _ObClient *ft;
149
150 ft = focus_directional_cycle(o->direction,
151 o->dock_windows,
152 o->desktop_windows,
153 TRUE,
154 o->dialog,
155 TRUE, cancel);
156
157 if (ft) {
158 actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
159 state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, ft);
160 }
161 }
This page took 0.042448 seconds and 4 git commands to generate.