all repos — openbox @ 68fdcde19b3b1b1ae4c503bd082bb149549f13ea

openbox fork - make it a bit more like ryudo

plugins/mouse/mouserc_parse.l (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
%{
#include "mouse.h"
#include <glib.h>
#ifdef HAVE_STDIO_H
#  include <stdio.h>
#endif

static int lineno;
static char *path;
static gboolean error;

static char *context;
static char *event;
static char *button;
static char *action;

static void endofline();
static int mparsewrap();
static void gotfield();
static void addbinding();
%}

field [A-Za-z0-9][-A-Za-z0-9]*
white [ \t]*

%%

^{white}#.*\n lineno++;
{field} gotfield();
\n endofline();
[ \t]
. error = TRUE;

%%

static void gotfield()
{
    if (context == NULL)
        context = g_strdup(mparsetext);
    else if (event == NULL)
        event = g_strdup(mparsetext);
    else if (button == NULL)
        button = g_strdup(mparsetext);
    else if (action == NULL)
        action = g_strdup(mparsetext);
    else
        error = TRUE;
}

static void endofline()
{
    if (!error && context && event && button && action)
        addbinding();
    else if (error || context || event || button || action)
        g_warning("Parser error in '%s' on line %d", path, lineno);

    error = FALSE;
    g_free(context); g_free(event); g_free(button); g_free(action);
    context = event = button = action = NULL;

    ++lineno;
}

static void addbinding()
{
    Action *a = NULL;
    MouseAction mact;

    if (!g_ascii_strcasecmp(event, "press"))
        mact = MouseAction_Press;
    else if (!g_ascii_strcasecmp(event, "release"))
        mact = MouseAction_Release;
    else if (!g_ascii_strcasecmp(event, "click"))
        mact = MouseAction_Click;
    else if (!g_ascii_strcasecmp(event, "doubleclick"))
        mact = MouseAction_DClick;
    else if (!g_ascii_strcasecmp(event, "drag"))
        mact = MouseAction_Motion;
    else {
        g_warning("Invalid event '%s' in '%s' on line %d", event, path,
                  lineno);
        return;
    }

    if (mact == MouseAction_Motion) {
        if (!g_ascii_strcasecmp(action, "move") &&
            mact == MouseAction_Motion) {
            a = action_new(action_move);
        } else if (!g_ascii_strcasecmp(action, "resize") &&
                   mact == MouseAction_Motion) {
            a = action_new(action_resize);
        }
    } else {
        if (!g_ascii_strcasecmp(action, "focus")) {
            a = action_new(action_focus);
        } else if (!g_ascii_strcasecmp(action, "unfocus")) {
            a = action_new(action_unfocus);
        } else if (!g_ascii_strcasecmp(action, "iconify")) {
            a = action_new(action_iconify);
        } else if (!g_ascii_strcasecmp(action, "raise")) {
            a = action_new(action_raise);
        } else if (!g_ascii_strcasecmp(action, "lower")) {
            a = action_new(action_lower);
        } else if (!g_ascii_strcasecmp(action, "focusraise")) {
            a = action_new(action_focusraise);
        } else if (!g_ascii_strcasecmp(action, "close")) {
            a = action_new(action_close);
        } else if (!g_ascii_strcasecmp(action, "kill")) {
            a = action_new(action_kill);
        } else if (!g_ascii_strcasecmp(action, "shade")) {
            a = action_new(action_shade);
        } else if (!g_ascii_strcasecmp(action, "unshade")) {
            a = action_new(action_unshade);
        } else if (!g_ascii_strcasecmp(action, "toggleshade")) {
            a = action_new(action_toggle_shade);
        } else if (!g_ascii_strcasecmp(action, "toggleomnipresent")) {
            a = action_new(action_toggle_omnipresent);
        } else if (!g_ascii_strcasecmp(action, "maximizefull")) {
            a = action_new(action_maximize_full);
        } else if (!g_ascii_strcasecmp(action, "unmaximizefull")) {
            a = action_new(action_unmaximize_full);
        } else if (!g_ascii_strcasecmp(action, "togglemaximizefull")) {
            a = action_new(action_toggle_maximize_full);
        } else if (!g_ascii_strcasecmp(action, "maximizehorz")) {
            a = action_new(action_maximize_horz);
        } else if (!g_ascii_strcasecmp(action, "unmaximizehorz")) {
            a = action_new(action_unmaximize_horz);
        } else if (!g_ascii_strcasecmp(action, "togglemaximizehorz")) {
            a = action_new(action_toggle_maximize_horz);
        } else if (!g_ascii_strcasecmp(action, "maximizevert")) {
            a = action_new(action_maximize_vert);
        } else if (!g_ascii_strcasecmp(action, "unmaximizevert")) {
            a = action_new(action_unmaximize_vert);
        } else if (!g_ascii_strcasecmp(action, "togglemaximizevert")) {
            a = action_new(action_toggle_maximize_vert);
        } else if (!g_ascii_strcasecmp(action, "sendtonextdesktop")) {
            a = action_new(action_send_to_next_desktop);
            a->data.sendtonextprev.wrap = FALSE;
            a->data.sendtonextprev.follow = TRUE;
        } else if (!g_ascii_strcasecmp(action, "sendtonextdesktopwrap")) {
            a = action_new(action_send_to_next_desktop);
            a->data.sendtonextprev.wrap = TRUE;
            a->data.sendtonextprev.follow = TRUE;
        } else if (!g_ascii_strcasecmp(action, "sendtopreviousdesktop")) {
            a = action_new(action_send_to_previous_desktop);
            a->data.sendtonextprev.wrap = FALSE;
            a->data.sendtonextprev.follow = TRUE;
        } else if (!g_ascii_strcasecmp(action, "sendtopreviousdesktopwrap")) {
            a = action_new(action_send_to_previous_desktop);
            a->data.sendtonextprev.wrap = TRUE;
            a->data.sendtonextprev.follow = TRUE;
        } else if (!g_ascii_strcasecmp(action, "nextdesktop")) {
            a = action_new(action_next_desktop);
            a->data.nextprevdesktop.wrap = FALSE;
        } else if (!g_ascii_strcasecmp(action, "nextdesktopwrap")) {
            a = action_new(action_next_desktop);
            a->data.nextprevdesktop.wrap = TRUE;
        } else if (!g_ascii_strcasecmp(action, "previousdesktop")) {
            a = action_new(action_previous_desktop);
            a->data.nextprevdesktop.wrap = FALSE;
        } else if (!g_ascii_strcasecmp(action, "previousdesktopwrap")) {
            a = action_new(action_previous_desktop);
            a->data.nextprevdesktop.wrap = TRUE;
        } else if (!g_ascii_strcasecmp(action, "nextdesktopcolumn")) {
            a = action_new(action_next_desktop_column);
            a->data.nextprevdesktop.wrap = FALSE;
        } else if (!g_ascii_strcasecmp(action, "nextdesktopcolumnwrap")) {
            a = action_new(action_next_desktop_column);
            a->data.nextprevdesktop.wrap = TRUE;
        } else if (!g_ascii_strcasecmp(action, "previousdesktopcolumn")) {
            a = action_new(action_previous_desktop_column);
            a->data.nextprevdesktop.wrap = FALSE;
        } else if (!g_ascii_strcasecmp(action, "previousdesktopcolumnwrap")) {
            a = action_new(action_previous_desktop_column);
            a->data.nextprevdesktop.wrap = TRUE;
        } else if (!g_ascii_strcasecmp(action, "nextdesktoprow")) {
            a = action_new(action_next_desktop_row);
            a->data.nextprevdesktop.wrap = FALSE;
        } else if (!g_ascii_strcasecmp(action, "nextdesktoprowwrap")) {
            a = action_new(action_next_desktop_row);
            a->data.nextprevdesktop.wrap = TRUE;
        } else if (!g_ascii_strcasecmp(action, "previousdesktoprow")) {
            a = action_new(action_previous_desktop_row);
            a->data.nextprevdesktop.wrap = FALSE;
        } else if (!g_ascii_strcasecmp(action, "previousdesktoprowwrap")) {
            a = action_new(action_previous_desktop_row);
            a->data.nextprevdesktop.wrap = TRUE;
        }
    }
    if (a == NULL) {
        g_warning("Invalid action '%s' in '%s' on line %d", action, path,
                  lineno);
        return;
    }

    if (!mbind(button, context, mact, a)) {
        action_free(a);
        g_warning("Unable to add binding '%s %s %s %s'",
                  context, event, button, action);
    }
}


static int mparsewrap()
{
    g_free(context); g_free(event); g_free(button); g_free(action);
    return 1;
}

void mouserc_parse()
{
    path = g_build_filename(g_get_home_dir(), ".openbox", "mouserc", NULL);
    if ((mparsein = fopen(path, "r")) == NULL) {
        g_free(path);
        path = g_build_filename(RCDIR, "mouserc", NULL);
        if ((mparsein = fopen(path, "r")) == NULL) {
            g_warning("No mouserc file found!");
            g_free(path);
            return;
        }
    }

    lineno = 1;
    error = FALSE;
    context = event = button = action = NULL;

    mparselex();

    g_free(path);
}