]> Dogcows Code - chaz/openbox/blob - plugins/mouse/mouseparse.c
fix up support for moveresize. make keyboard grabs Async so that i can hit escape...
[chaz/openbox] / plugins / mouse / mouseparse.c
1 #include "kernel/action.h"
2 #include "kernel/parse.h"
3 #include "kernel/prop.h"
4 #include "mouse.h"
5
6 void mouseparse(ParseToken *token)
7 {
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;
15
16 if (err) {
17 if (token->type == TOKEN_NEWLINE)
18 err = FALSE;
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;
24 return;
25 } else {
26 yyerror("syntax error (expected mbind)");
27 err = TRUE;
28 }
29 } else if (context == NULL) {
30 if (token->type == TOKEN_IDENTIFIER) {
31 context = token->data.identifier;
32 return;
33 } else {
34 yyerror("syntax error (expected Key)");
35 err = TRUE;
36 }
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)
50 return;
51 else {
52 yyerror("invalid event");
53 err = TRUE;
54 }
55 } else {
56 yyerror("syntax error (expected event)");
57 err = TRUE;
58 }
59 } else if (button == NULL) {
60 if (token->type == TOKEN_IDENTIFIER) {
61 button = token->data.identifier;
62 return;
63 } else {
64 yyerror("syntax error (expected button)");
65 err = TRUE;
66 }
67 } else if (action == NULL) {
68 if (token->type == TOKEN_IDENTIFIER) {
69 action = action_from_string(token->data.identifier);
70
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)) {
78 action_free(action);
79 action = NULL;
80 }
81 } else {
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) {
87 action_free(action);
88 action = NULL;
89 }
90 }
91
92 if (action != NULL) {
93 return;
94 } else {
95 yyerror("invalid action");
96 err = TRUE;
97 }
98 } else {
99 yyerror("syntax error (expected action)");
100 err = TRUE;
101 }
102 } else if (token->type == TOKEN_STRING) {
103 arg_str = token->data.string;
104 return;
105 } else if (token->type == TOKEN_INTEGER) {
106 arg_int = token->data.integer;
107 return;
108 } else if (token->type != TOKEN_NEWLINE) {
109 yyerror("syntax error (unexpected trailing token)");
110 } else {
111
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) &&
119 arg_int)
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;
126
127 if (mbind(button, context, event, action))
128 action = NULL; /* don't free this if mbind succeeds */
129 else
130 yyerror("failed to add mouse binding");
131 }
132
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;
137 arg_int = 0;
138 event = -1;
139 action_free(action); action = NULL;
140 parse_free_token(token);
141 }
This page took 0.041674 seconds and 4 git commands to generate.