]> Dogcows Code - chaz/openbox/blob - plugins/mouse/mouserc_parse.l
7563c6f3b044bd963bf18d15438a5326ebd05f4f
[chaz/openbox] / plugins / mouse / mouserc_parse.l
1 %{
2 #include "mouse.h"
3 #include <glib.h>
4 #ifdef HAVE_STDIO_H
5 # include <stdio.h>
6 #endif
7
8 static int lineno;
9 static char *path;
10 static gboolean error;
11
12 static char *context;
13 static char *event;
14 static char *button;
15 static char *action;
16
17 static void endofline();
18 static int mparsewrap();
19 static void gotfield();
20 static void addbinding();
21 %}
22
23 field [A-Za-z0-9][-A-Za-z0-9]*
24 sep [ \t]+
25 white [ \t]*
26
27 %%
28
29 ^{white}\#.+\n lineno++;
30 {field} gotfield();
31 \n endofline();
32 [ \t]
33 . error = TRUE;
34
35 %%
36
37 static void gotfield()
38 {
39 if (context == NULL)
40 context = g_strdup(mparsetext);
41 else if (event == NULL)
42 event = g_strdup(mparsetext);
43 else if (button == NULL)
44 button = g_strdup(mparsetext);
45 else if (action == NULL)
46 action = g_strdup(mparsetext);
47 else
48 error = TRUE;
49 }
50
51 static void endofline()
52 {
53 if (!error && context && event && button && action)
54 addbinding();
55 else if (error || context || event || button || action)
56 g_warning("Parser error in '%s' on line %d", path, lineno);
57
58 error = FALSE;
59 g_free(context); g_free(event); g_free(button); g_free(action);
60 context = event = button = action = NULL;
61
62 ++lineno;
63 }
64
65 static void addbinding()
66 {
67 Action *a;
68 MouseAction mact;
69
70 if (!g_ascii_strcasecmp(event, "press"))
71 mact = MouseAction_Press;
72 else if (!g_ascii_strcasecmp(event, "release"))
73 mact = MouseAction_Release;
74 else if (!g_ascii_strcasecmp(event, "click"))
75 mact = MouseAction_Click;
76 else if (!g_ascii_strcasecmp(event, "doubleclick"))
77 mact = MouseAction_DClick;
78 else if (!g_ascii_strcasecmp(event, "drag"))
79 mact = MouseAction_Motion;
80 else {
81 g_warning("Invalid event '%s' in '%s' on line %d", event, path,
82 lineno);
83 return;
84 }
85
86 if (!g_ascii_strcasecmp(action, "focus")) {
87 a = action_new(action_focus);
88 } else if (!g_ascii_strcasecmp(action, "unfocus")) {
89 a = action_new(action_unfocus);
90 } else if (!g_ascii_strcasecmp(action, "iconify")) {
91 a = action_new(action_iconify);
92 } else if (!g_ascii_strcasecmp(action, "raise")) {
93 a = action_new(action_raise);
94 } else if (!g_ascii_strcasecmp(action, "lower")) {
95 a = action_new(action_lower);
96 } else if (!g_ascii_strcasecmp(action, "focusraise")) {
97 a = action_new(action_focusraise);
98 } else if (!g_ascii_strcasecmp(action, "close")) {
99 a = action_new(action_close);
100 } else if (!g_ascii_strcasecmp(action, "kill")) {
101 a = action_new(action_kill);
102 } else if (!g_ascii_strcasecmp(action, "shade")) {
103 a = action_new(action_shade);
104 } else if (!g_ascii_strcasecmp(action, "unshade")) {
105 a = action_new(action_unshade);
106 } else if (!g_ascii_strcasecmp(action, "toggleshade")) {
107 a = action_new(action_toggle_shade);
108 } else if (!g_ascii_strcasecmp(action, "toggleomnipresent")) {
109 a = action_new(action_toggle_omnipresent);
110 } else if (!g_ascii_strcasecmp(action, "maximizefull")) {
111 a = action_new(action_maximize_full);
112 } else if (!g_ascii_strcasecmp(action, "unmaximizefull")) {
113 a = action_new(action_unmaximize_full);
114 } else if (!g_ascii_strcasecmp(action, "togglemaximizefull")) {
115 a = action_new(action_toggle_maximize_full);
116 } else if (!g_ascii_strcasecmp(action, "maximizehorz")) {
117 a = action_new(action_maximize_horz);
118 } else if (!g_ascii_strcasecmp(action, "unmaximizehorz")) {
119 a = action_new(action_unmaximize_horz);
120 } else if (!g_ascii_strcasecmp(action, "togglemaximizehorz")) {
121 a = action_new(action_toggle_maximize_horz);
122 } else if (!g_ascii_strcasecmp(action, "maximizevert")) {
123 a = action_new(action_maximize_vert);
124 } else if (!g_ascii_strcasecmp(action, "unmaximizevert")) {
125 a = action_new(action_unmaximize_vert);
126 } else if (!g_ascii_strcasecmp(action, "togglemaximizevert")) {
127 a = action_new(action_toggle_maximize_vert);
128 } else if (!g_ascii_strcasecmp(action, "sendtonextdesktop")) {
129 a = action_new(action_send_to_next_desktop);
130 a->data.sendtonextprev.wrap = FALSE;
131 a->data.sendtonextprev.follow = TRUE;
132 } else if (!g_ascii_strcasecmp(action, "sendtonextdesktopwrap")) {
133 a = action_new(action_send_to_next_desktop);
134 a->data.sendtonextprev.wrap = TRUE;
135 a->data.sendtonextprev.follow = TRUE;
136 } else if (!g_ascii_strcasecmp(action, "sendtopreviousdesktop")) {
137 a = action_new(action_send_to_previous_desktop);
138 a->data.sendtonextprev.wrap = FALSE;
139 a->data.sendtonextprev.follow = TRUE;
140 } else if (!g_ascii_strcasecmp(action, "sendtopreviousdesktopwrap")) {
141 a = action_new(action_send_to_previous_desktop);
142 a->data.sendtonextprev.wrap = TRUE;
143 a->data.sendtonextprev.follow = TRUE;
144 } else if (!g_ascii_strcasecmp(action, "nextdesktop")) {
145 a = action_new(action_next_desktop);
146 a->data.nextprevdesktop.wrap = FALSE;
147 } else if (!g_ascii_strcasecmp(action, "nextdesktopwrap")) {
148 a = action_new(action_next_desktop);
149 a->data.nextprevdesktop.wrap = TRUE;
150 } else if (!g_ascii_strcasecmp(action, "previousdesktop")) {
151 a = action_new(action_previous_desktop);
152 a->data.nextprevdesktop.wrap = FALSE;
153 } else if (!g_ascii_strcasecmp(action, "previousdesktopwrap")) {
154 a = action_new(action_previous_desktop);
155 a->data.nextprevdesktop.wrap = TRUE;
156 } else if (!g_ascii_strcasecmp(action, "nextdesktopcolumn")) {
157 a = action_new(action_next_desktop_column);
158 a->data.nextprevdesktop.wrap = FALSE;
159 } else if (!g_ascii_strcasecmp(action, "nextdesktopcolumnwrap")) {
160 a = action_new(action_next_desktop_column);
161 a->data.nextprevdesktop.wrap = TRUE;
162 } else if (!g_ascii_strcasecmp(action, "previousdesktopcolumn")) {
163 a = action_new(action_previous_desktop_column);
164 a->data.nextprevdesktop.wrap = FALSE;
165 } else if (!g_ascii_strcasecmp(action, "previousdesktopcolumnwrap")) {
166 a = action_new(action_previous_desktop_column);
167 a->data.nextprevdesktop.wrap = TRUE;
168 } else if (!g_ascii_strcasecmp(action, "nextdesktoprow")) {
169 a = action_new(action_next_desktop_row);
170 a->data.nextprevdesktop.wrap = FALSE;
171 } else if (!g_ascii_strcasecmp(action, "nextdesktoprowwrap")) {
172 a = action_new(action_next_desktop_row);
173 a->data.nextprevdesktop.wrap = TRUE;
174 } else if (!g_ascii_strcasecmp(action, "previousdesktoprow")) {
175 a = action_new(action_previous_desktop_row);
176 a->data.nextprevdesktop.wrap = FALSE;
177 } else if (!g_ascii_strcasecmp(action, "previousdesktoprowwrap")) {
178 a = action_new(action_previous_desktop_row);
179 a->data.nextprevdesktop.wrap = TRUE;
180 } else if (!g_ascii_strcasecmp(action, "move") &&
181 mact == MouseAction_Motion) {
182 a = action_new(action_move);
183 } else if (!g_ascii_strcasecmp(action, "resize") &&
184 mact == MouseAction_Motion) {
185 a = action_new(action_resize);
186 } else {
187 g_warning("Invalid action '%s' in '%s' on line %d", action, path,
188 lineno);
189 return;
190 }
191
192 if (!mbind(button, context, mact, a)) {
193 action_free(a);
194 g_warning("Unable to add binding '%s %s %s %s'",
195 context, event, button, action);
196 }
197 }
198
199
200 static int mparsewrap()
201 {
202 g_free(context); g_free(event); g_free(button); g_free(action);
203 return 1;
204 }
205
206 void mouserc_parse()
207 {
208 path = g_build_filename(g_get_home_dir(), ".openbox", "mouserc", NULL);
209 if ((mparsein = fopen(path, "r")) == NULL) {
210 g_free(path);
211 path = g_build_filename(RCDIR, "mouserc", NULL);
212 if ((mparsein = fopen(path, "r")) == NULL) {
213 g_warning("No mouserc file found!");
214 g_free(path);
215 return;
216 }
217 }
218
219 lineno = 1;
220 error = FALSE;
221 context = event = button = action = NULL;
222
223 mparselex();
224
225 g_free(path);
226 }
This page took 0.041 seconds and 3 git commands to generate.