]> Dogcows Code - chaz/openbox/blob - plugins/mouse/mouserc_parse.l
add exit/restart.
[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 white [ \t]*
25
26 %%
27
28 ^{white}#.*\n lineno++;
29 {field} gotfield();
30 \n endofline();
31 [ \t]
32 . error = TRUE;
33
34 %%
35
36 static void gotfield()
37 {
38 if (context == NULL)
39 context = g_strdup(mparsetext);
40 else if (event == NULL)
41 event = g_strdup(mparsetext);
42 else if (button == NULL)
43 button = g_strdup(mparsetext);
44 else if (action == NULL)
45 action = g_strdup(mparsetext);
46 else
47 error = TRUE;
48 }
49
50 static void endofline()
51 {
52 if (!error && context && event && button && action)
53 addbinding();
54 else if (error || context || event || button || action)
55 g_warning("Parser error in '%s' on line %d", path, lineno);
56
57 error = FALSE;
58 g_free(context); g_free(event); g_free(button); g_free(action);
59 context = event = button = action = NULL;
60
61 ++lineno;
62 }
63
64 static void addbinding()
65 {
66 Action *a = NULL;
67 MouseAction mact;
68
69 if (!g_ascii_strcasecmp(event, "press"))
70 mact = MouseAction_Press;
71 else if (!g_ascii_strcasecmp(event, "release"))
72 mact = MouseAction_Release;
73 else if (!g_ascii_strcasecmp(event, "click"))
74 mact = MouseAction_Click;
75 else if (!g_ascii_strcasecmp(event, "doubleclick"))
76 mact = MouseAction_DClick;
77 else if (!g_ascii_strcasecmp(event, "drag"))
78 mact = MouseAction_Motion;
79 else {
80 g_warning("Invalid event '%s' in '%s' on line %d", event, path,
81 lineno);
82 return;
83 }
84
85 a = action_from_string(action);
86
87 if (mact == MouseAction_Motion) {
88 if (a && !(a->func == action_move || a->func == action_resize)) {
89 action_free(a);
90 a = NULL;
91 }
92 /* the below types cannot be used with !motion events, or at all with
93 mouse bindings */
94 } else if (a && (a->func == action_move || a->func == action_resize ||
95 a->func == action_execute || a->func == action_desktop ||
96 a->func == action_move_relative ||
97 a->func == action_resize_relative)) {
98 action_free(a);
99 a = NULL;
100 }
101 if (a == NULL) {
102 g_warning("Invalid action '%s' in '%s' on line %d", action, path,
103 lineno);
104 return;
105 }
106
107 if (!mbind(button, context, mact, a)) {
108 action_free(a);
109 g_warning("Unable to add binding '%s %s %s %s'",
110 context, event, button, action);
111 }
112 }
113
114
115 static int mparsewrap()
116 {
117 g_free(context); g_free(event); g_free(button); g_free(action);
118 return 1;
119 }
120
121 void mouserc_parse()
122 {
123 path = g_build_filename(g_get_home_dir(), ".openbox", "mouserc", NULL);
124 if ((mparsein = fopen(path, "r")) == NULL) {
125 g_free(path);
126 path = g_build_filename(RCDIR, "mouserc", NULL);
127 if ((mparsein = fopen(path, "r")) == NULL) {
128 g_warning("No mouserc file found!");
129 g_free(path);
130 return;
131 }
132 }
133
134 lineno = 1;
135 error = FALSE;
136 context = event = button = action = NULL;
137
138 mparselex();
139
140 g_free(path);
141 }
This page took 0.03914 seconds and 4 git commands to generate.