]> icculus.org git repositories - dana/openbox.git/blob - plugins/keyboard/keysrc.yacc
use the number for sendtodesktop
[dana/openbox.git] / plugins / keyboard / keysrc.yacc
1 %{
2 #include "keyboard.h"
3 #include "../../kernel/action.h"
4 #include <glib.h>
5 #ifdef HAVE_STDIO_H
6 #  include <stdio.h>
7 #endif
8
9 extern int kparselex();
10 extern int kparselineno;
11 extern FILE *kparsein;  /* lexer input */
12
13 void kparseerror(char *s);
14 static void addbinding(GList *keylist, char *action, char *path, int num);
15
16 static char *path;
17 %}
18
19 %union {
20     char *string;
21     int integer;
22     GList *list;
23 }
24
25 %token <integer> INTEGER
26 %token <string> STRING
27 %token <string> FIELD
28 %token <string> DESKTOP
29
30 %type <list> fields
31
32 %%
33
34 config:
35   | config '\n'
36   | config fields FIELD '\n' { addbinding($2, $3, NULL, 0); }
37   | config fields FIELD INTEGER '\n' { addbinding($2, $3, NULL, $4); }
38   | config fields FIELD STRING '\n' { addbinding($2, $3, $4, 0); }
39   ;
40
41 fields:
42   FIELD { $$ = g_list_append(NULL, $1); }
43   | fields FIELD { $$ = g_list_append($1, $2); }
44   ;
45
46 %%
47
48 void kparseerror(char *s) {
49     g_warning("Parser error in '%s' on line %d", path, kparselineno);
50 }
51
52 void keysrc_parse()
53 {
54     path = g_build_filename(g_get_home_dir(), ".openbox", "keysrc", NULL);
55     if ((kparsein = fopen(path, "r")) == NULL) {
56         g_free(path);
57         path = g_build_filename(RCDIR, "keysrc", NULL);
58         if ((kparsein = fopen(path, "r")) == NULL) {
59             g_warning("No keysrc file found!");
60             g_free(path);
61             return;
62         }
63     }
64
65     kparselineno = 1;
66
67     kparseparse();
68 }
69
70 static void addbinding(GList *keylist, char *action, char *apath, int num)
71 {
72     Action *a;
73
74     a = action_from_string(action);
75
76     /* no move/resize with the keyboard */
77     if (a && (a->func == action_move || a->func == action_resize)) {
78         action_free(a);
79         a = NULL;
80     }
81     if (a == NULL) {
82         g_warning("Invalid action '%s' in '%s' on line %d", action, apath,
83                   kparselineno - 1);
84         return;
85     }
86     /* these have extra data! */
87     if (a->func == action_execute || a->func == action_restart)
88         a->data.execute.path = apath;
89     else
90         g_free(apath);
91     if (a->func == action_desktop || a->func == action_send_to_desktop)
92         a->data.desktop.desk = (unsigned) num - 1;
93     if (a->func == action_move_relative_horz ||
94         a->func == action_move_relative_vert ||
95         a->func == action_resize_relative_horz ||
96         a->func == action_resize_relative_vert)
97         a->data.relative.delta = num;
98
99     if (!kbind(keylist, a)) {
100         action_free(a);
101         g_warning("Unable to add binding in '%s' on line %d", path,
102                   kparselineno - 1);
103     }
104 }