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 (event == MouseAction_Motion) {
73 if (action && (action->func != action_moveresize ||
74 action->data.moveresize.corner ==
75 prop_atoms.net_wm_moveresize_move_keyboard ||
76 action->data.moveresize.corner ==
77 prop_atoms.net_wm_moveresize_size_keyboard)) {
82 if (action && action->func == action_moveresize &&
83 action->data.moveresize.corner !=
84 prop_atoms.net_wm_moveresize_move_keyboard &&
85 action->data.moveresize.corner !=
86 prop_atoms.net_wm_moveresize_size_keyboard) {
95 yyerror("invalid action");
99 yyerror("syntax error (expected action)");
102 } else if (token->type == TOKEN_STRING) {
103 arg_str = token->data.string;
105 } else if (token->type == TOKEN_INTEGER) {
106 arg_int = token->data.integer;
108 } else if (token->type != TOKEN_NEWLINE) {
109 yyerror("syntax error (unexpected trailing token)");
112 /* these use the argument */
113 if (action->func == action_execute || action->func == action_restart)
114 action->data.execute.path = g_strdup(arg_str);
115 else if (action->func == action_showmenu)
116 action->data.showmenu.name = g_strdup(arg_str);
117 if ((action->func == action_desktop ||
118 action->func == action_send_to_desktop) &&
120 action->data.desktop.desk = (unsigned) arg_int - 1;
121 if (action->func == action_move_relative_horz ||
122 action->func == action_move_relative_vert ||
123 action->func == action_resize_relative_horz ||
124 action->func == action_resize_relative_vert)
125 action->data.relative.delta = arg_int;
127 if (mbind(button, context, event, action))
128 action = NULL; /* don't free this if mbind succeeds */
130 yyerror("failed to add mouse binding");
133 g_free(top); top = NULL;
134 g_free(context); context = NULL;
135 g_free(button); button = NULL;
136 g_free(arg_str); arg_str = NULL;
139 action_free(action); action = NULL;
140 parse_free_token(token);