]> Dogcows Code - chaz/openbox/commitdiff
add the lexer
authorDana Jansens <danakj@orodu.net>
Wed, 26 Mar 2003 05:06:12 +0000 (05:06 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 26 Mar 2003 05:06:12 +0000 (05:06 +0000)
plugins/mouse/.cvsignore
plugins/mouse/mouserc
plugins/mouse/mouserc_parse.l [new file with mode: 0644]

index 7fe77089fa88a5da2fbe7f1c5a051690b70b8c79..41ed68d80432093ffd97541619cebbde5b09f4fb 100644 (file)
@@ -7,5 +7,4 @@ Makefile.in
 translate.lo
 lex.mparse.c
 lex.mparse.lo
-mouserc_parse.l
 mouserc_parse.lo
index 1f119a027db1bdd71360ab4db37b4c05ea14624f..1ac987a3b8e3dd1f2fc99e01c6561ead139dfca5 100644 (file)
@@ -1,3 +1,52 @@
+# Mouserc - Mouse bindings for Openbox
+
+# Context : The place where the mouse click takes place
+#  * Titlebar - A client's titlebar (the top of the frame)
+#  * Handle - A client's handle (the bottom of the frame)
+#  * Client - A client (the actual window inside the frame, clicks in this
+#                      context also get passed through to the client)
+#  * Frame - A client's entire frame (clicks in this context do not get passed
+#                                    through to the client)
+#  * Icon - A client's icon (in the titlebar)
+#  * AllDesktops - A client's omnipresent button (in the titlebar)
+#  * Iconify - A client's iconify button (in the titlebar)
+#  * Maximize - A client's maximize button (in the titlebar)
+#  * Close - A client's close button (in the titlebar)
+#  * Root - The root window (the desktop background, these are often blocked
+#                            by programs with desktop windows, and are not
+#                            available on rootless X servers (like OSX))
+#  * TLCorner - The top-left corner of the frame (if supported by the
+#                                                engine)
+#  * TRCorner - The top-right corner of the frame (if supported by the
+#                                                 engine)
+#  * BLCorner - The bottom-left corner of the frame (if supported by the
+#                                                   engine)
+#  * BRCorner - The bottom-right corner of the frame (if supported by the
+#                                                    engine)
+#  Other contexts may be created by engines.
+
+# Event : The type of mouse action to bind
+#  * Press - A button is pressed
+#  * Release - A button is released
+#  * Click - A button is pressed and released
+#  * DoubleClick - A button is pressed and released twice quickly
+#  * Drag - A button is held and the mouse is moved
+
+# Button : The mouse button which is performing the Event
+#  A string composed of [<modifier>-]<button>. A button can have 0 or more
+#  modifiers.
+#  Valid modifiers are Mod1 ('A' is an alias for this), Mod2, Mod3, Mod4 ('W'
+#  is an alias for this), and Mod5.
+#  Valid buttons are Left, Right, Middle, Up, Down, or any number > 0
+
+# Action: The action to be performed then the Event occurs with the Button in
+#         the context.
+#  Value actions are:
+#  * Focus  - Focus the client
+#  
+
+# All options are case insensitive.
+
 #Context       Event           Button  Action
 
 Titlebar       Drag            Left    Move
diff --git a/plugins/mouse/mouserc_parse.l b/plugins/mouse/mouserc_parse.l
new file mode 100644 (file)
index 0000000..1a3233c
--- /dev/null
@@ -0,0 +1,228 @@
+%{
+#include "mouse.h"
+#include <glib.h>
+#ifdef HAVE_STDIO_H
+#  include <stdio.h>
+#endif
+
+static int lineno;
+static char *path;
+static gboolean comment;
+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]+
+sep [ \t]+
+white [ \t]*
+
+%%
+
+^{white}# comment = TRUE;
+{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 (!comment) {
+        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);
+    }
+
+    comment = 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;
+    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 (!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;
+    } else if (!g_ascii_strcasecmp(action, "move")) {
+        a = action_new(action_move);
+    } else if (!g_ascii_strcasecmp(action, "resize")) {
+        a = action_new(action_resize);
+    } else {
+        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;
+    comment = FALSE;
+    error = FALSE;
+    context = event = button = action = NULL;
+
+    mparselex();
+
+    g_free(path);
+}
This page took 0.027599 seconds and 4 git commands to generate.