From 91ebde9e8842678e0d0704dc7945b2b84aba314f Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 26 Mar 2003 12:52:32 +0000 Subject: load keybindings from keysrc --- plugins/keyboard/keysrc.yacc | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 plugins/keyboard/keysrc.yacc (limited to 'plugins/keyboard/keysrc.yacc') 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 +#ifdef HAVE_STDIO_H +# include +#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; +%token STRING +%token FIELD +%token EXECUTE +%token RESTART +%token DESKTOP + +%type 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); + } +} -- cgit v1.2.3