1 #include "kernel/action.h"
2 #include "kernel/parse.h"
3 #include "kernel/prop.h"
6 void mouseparse(ParseToken *token)
8 static char *top = NULL;
9 static char *context = NULL, *button = NULL;
10 static char *arg_str = NULL;
11 static int arg_int = 0;
12 static MouseAction event = -1;
13 static Action *action = NULL;
14 static gboolean err = FALSE;
17 if (token->type == TOKEN_NEWLINE)
19 /* just fall through and free the token */
20 } else if (top == NULL) {
21 if (token->type == TOKEN_IDENTIFIER &&
22 !g_ascii_strcasecmp("mbind", token->data.identifier)) {
23 top = token->data.identifier;
26 yyerror("syntax error (expected mbind)");
29 } else if (context == NULL) {
30 if (token->type == TOKEN_IDENTIFIER) {
31 context = token->data.identifier;
34 yyerror("syntax error (expected Key)");
37 } else if (event == (unsigned) -1) {
38 if (token->type == TOKEN_IDENTIFIER) {
39 if (!g_ascii_strcasecmp("press", token->data.identifier))
40 event = MouseAction_Press;
41 else if (!g_ascii_strcasecmp("release", token->data.identifier))
42 event = MouseAction_Release;
43 else if (!g_ascii_strcasecmp("click", token->data.identifier))
44 event = MouseAction_Click;
45 else if (!g_ascii_strcasecmp("doubleclick",token->data.identifier))
46 event = MouseAction_DClick;
47 else if (!g_ascii_strcasecmp("drag", token->data.identifier))
48 event = MouseAction_Motion;
49 if (event != (unsigned) -1)
52 yyerror("invalid event");
56 yyerror("syntax error (expected event)");
59 } else if (button == NULL) {
60 if (token->type == TOKEN_IDENTIFIER) {
61 button = token->data.identifier;
64 yyerror("syntax error (expected button)");
67 } else if (action == NULL) {
68 if (token->type == TOKEN_IDENTIFIER) {
69 action = action_from_string(token->data.identifier);
71 /* check for valid actions for motion events */
72 if (action->func == action_moveresize)
73 g_message("%d", action->data.moveresize.corner);
74 if (event == MouseAction_Motion) {
75 if (action && (action->func != action_moveresize ||
76 action->data.moveresize.corner ==
77 prop_atoms.net_wm_moveresize_move_keyboard ||
78 action->data.moveresize.corner ==
79 prop_atoms.net_wm_moveresize_size_keyboard)) {
84 if (action && action->func == action_moveresize &&
85 action->data.moveresize.corner !=
86 prop_atoms.net_wm_moveresize_move_keyboard &&
87 action->data.moveresize.corner !=
88 prop_atoms.net_wm_moveresize_size_keyboard) {
97 yyerror("invalid action");
101 yyerror("syntax error (expected action)");
104 } else if (token->type == TOKEN_STRING) {
105 arg_str = token->data.string;
107 } else if (token->type == TOKEN_INTEGER) {
108 arg_int = token->data.integer;
110 } else if (token->type != TOKEN_NEWLINE) {
111 yyerror("syntax error (unexpected trailing token)");
114 /* these use the argument */
115 if (action->func == action_execute || action->func == action_restart)
116 action->data.execute.path = g_strdup(arg_str);
117 else if (action->func == action_showmenu)
118 action->data.showmenu.name = g_strdup(arg_str);
119 if ((action->func == action_desktop ||
120 action->func == action_send_to_desktop) &&
122 action->data.desktop.desk = (unsigned) arg_int - 1;
123 if (action->func == action_move_relative_horz ||
124 action->func == action_move_relative_vert ||
125 action->func == action_resize_relative_horz ||
126 action->func == action_resize_relative_vert)
127 action->data.relative.delta = arg_int;
129 if (mbind(button, context, event, action))
130 action = NULL; /* don't free this if mbind succeeds */
132 yyerror("failed to add mouse binding");
135 g_free(top); top = NULL;
136 g_free(context); context = NULL;
137 g_free(button); button = NULL;
138 g_free(arg_str); arg_str = NULL;
141 action_free(action); action = NULL;
142 parse_free_token(token);