summaryrefslogtreecommitdiff
path: root/plugins/keyboard/keysrc.yacc
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-03-26 12:52:32 +0000
committerDana Jansens <danakj@orodu.net>2003-03-26 12:52:32 +0000
commit91ebde9e8842678e0d0704dc7945b2b84aba314f (patch)
tree8a7350529e86af79f865336112ab5cc37f354707 /plugins/keyboard/keysrc.yacc
parent59ad2e319a58af43ca77cda7307888e5ae34ea2a (diff)
load keybindings from keysrc
Diffstat (limited to 'plugins/keyboard/keysrc.yacc')
-rw-r--r--plugins/keyboard/keysrc.yacc101
1 files changed, 101 insertions, 0 deletions
diff --git a/plugins/keyboard/keysrc.yacc b/plugins/keyboard/keysrc.yacc
new file mode 100644
index 00000000..8772fa17
--- /dev/null
+++ b/plugins/keyboard/keysrc.yacc
@@ -0,0 +1,101 @@
+%{
+#include "keyboard.h"
+#include "../../kernel/action.h"
+#include <glib.h>
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+
+extern int kparselex();
+extern int kparselineno;
+extern FILE *kparsein; /* lexer input */
+
+void kparseerror(char *s);
+static void addbinding(GList *keylist, char *action, char *path, int num);
+
+static char *path;
+%}
+
+%union {
+ char *string;
+ int integer;
+ GList *list;
+}
+
+%token <integer> INTEGER;
+%token <string> STRING
+%token <string> FIELD
+%token <string> EXECUTE
+%token <string> RESTART
+%token <string> DESKTOP
+
+%type <list> fields
+
+%%
+
+config:
+ | config '\n'
+ | config fields FIELD '\n' { addbinding($2, $3, NULL, 0); }
+ | config fields DESKTOP INTEGER '\n' { addbinding($2, $3, NULL, $4); }
+ | config fields RESTART '\n' { addbinding($2, $3, NULL, 0); }
+ | config fields EXECUTE STRING '\n' { addbinding($2, $3, $4, 0); }
+ | config fields RESTART STRING '\n' { addbinding($2, $3, $4, 0); }
+ ;
+
+fields:
+ FIELD { $$ = g_list_prepend(NULL, $1); }
+ | fields FIELD { $$ = g_list_prepend($1, $2); }
+ ;
+
+%%
+
+void kparseerror(char *s) {
+ g_warning("Parser error in '%s' on line %d", path, kparselineno);
+}
+
+void keysrc_parse()
+{
+ path = g_build_filename(g_get_home_dir(), ".openbox", "keysrc", NULL);
+ if ((kparsein = fopen(path, "r")) == NULL) {
+ g_free(path);
+ path = g_build_filename(RCDIR, "keysrc", NULL);
+ if ((kparsein = fopen(path, "r")) == NULL) {
+ g_warning("No keysrc file found!");
+ g_free(path);
+ return;
+ }
+ }
+
+ kparselineno = 1;
+
+ kparseparse();
+}
+
+static void addbinding(GList *keylist, char *action, char *apath, int num)
+{
+ Action *a;
+
+ a = action_from_string(action);
+
+ /* no move/resize with the keyboard */
+ if (a && (a->func == action_move || a->func == action_resize)) {
+ action_free(a);
+ a = NULL;
+ }
+ if (a == NULL) {
+ g_warning("Invalid action '%s' in '%s' on line %d", action, apath,
+ kparselineno - 1);
+ return;
+ }
+ /* these have extra data! */
+ if (a->func == action_execute || a->func == action_restart)
+ a->data.execute.path = apath;
+ if (a->func == action_desktop)
+ a->data.desktop.desk = (unsigned) num + 1;
+
+ if (!kbind(keylist, a)) {
+ action_free(a);
+ g_warning("Unable to add binding in '%s' on line %d", path,
+ kparselineno - 1);
+ }
+}