17 GSList *actions[NUM_MOUSEACTION]; /* lists of Action pointers */
20 /* Array of GSList*s of PointerBinding*s. */
21 static GSList *bound_contexts[OB_FRAME_NUM_CONTEXTS];
23 void mouse_grab_for_client(ObClient *client, gboolean grab)
28 for (i = 0; i < OB_FRAME_NUM_CONTEXTS; ++i)
29 for (it = bound_contexts[i]; it != NULL; it = it->next) {
30 /* grab/ungrab the button */
31 ObMouseBinding *b = it->data;
36 if (i == OB_FRAME_CONTEXT_FRAME) {
37 win = client->frame->window;
39 mask = ButtonPressMask | ButtonMotionMask | ButtonReleaseMask;
40 } else if (i == OB_FRAME_CONTEXT_CLIENT) {
41 win = client->frame->plate;
42 mode = GrabModeSync; /* this is handled in event */
43 mask = ButtonPressMask; /* can't catch more than this with Sync
44 mode the release event is
45 manufactured in event() */
49 grab_button_full(b->button, b->state, win, mask, mode, None);
51 ungrab_button(b->button, b->state, win);
55 static void grab_all_clients(gboolean grab)
59 for (it = client_list; it != NULL; it = it->next)
60 mouse_grab_for_client(it->data, grab);
63 static void clearall()
68 for(i = 0; i < OB_FRAME_NUM_CONTEXTS; ++i) {
69 for (it = bound_contexts[i]; it != NULL; it = it->next) {
72 ObMouseBinding *b = it->data;
73 for (j = 0; j < NUM_MOUSEACTION; ++j) {
75 for (it = b->actions[j]; it; it = it->next) {
76 action_free(it->data);
78 g_slist_free(b->actions[j]);
82 g_slist_free(bound_contexts[i]);
86 static void fire_button(ObMouseAction a, ObFrameContext context,
87 ObClient *c, guint state,
88 guint button, int x, int y)
93 g_message("%d %d %d", context, state, button);
95 for (it = bound_contexts[context]; it != NULL; it = it->next) {
97 if (b->state == state && b->button == button)
100 /* if not bound, then nothing to do! */
101 if (it == NULL) return;
103 for (it = b->actions[a]; it; it = it->next) {
104 ObAction *act = it->data;
105 if (act->func != NULL) {
108 g_assert(act->func != action_moveresize);
110 if (act->func == action_showmenu) {
111 act->data.showmenu.x = x;
112 act->data.showmenu.y = y;
115 if (act->func == action_desktop_dir)
117 act->data.desktopdir.final = FALSE;
118 act->data.desktopdir.cancel = FALSE;
120 if (act->func == action_send_to_desktop_dir)
122 act->data.sendtodir.final = FALSE;
123 act->data.sendtodir.cancel = FALSE;
126 if ((act->func == action_desktop_dir ||
127 act->func == action_send_to_desktop_dir)) {
128 keyboard_interactive_grab(state, c, context, act);
133 act->func(&act->data);
138 static void fire_motion(ObMouseAction a, ObFrameContext context, ObClient *c,
139 guint state, guint button, int x_root, int y_root,
145 for (it = bound_contexts[context]; it != NULL; it = it->next) {
147 if (b->state == state && b->button == button)
150 /* if not bound, then nothing to do! */
151 if (it == NULL) return;
153 for (it = b->actions[a]; it; it = it->next) {
154 ObAction *act = it->data;
155 if (act->func != NULL) {
158 if (act->func == action_moveresize) {
159 act->data.moveresize.x = x_root;
160 act->data.moveresize.y = y_root;
161 act->data.moveresize.button = button;
162 if (!(act->data.moveresize.corner ==
163 prop_atoms.net_wm_moveresize_move ||
164 act->data.moveresize.corner ==
165 prop_atoms.net_wm_moveresize_move_keyboard ||
166 act->data.moveresize.corner ==
167 prop_atoms.net_wm_moveresize_size_keyboard))
168 act->data.moveresize.corner = corner;
170 g_assert_not_reached();
172 act->func(&act->data);
177 static guint32 pick_corner(int x, int y, int cx, int cy, int cw, int ch)
179 if (x - cx < cw / 2) {
181 return prop_atoms.net_wm_moveresize_size_topleft;
183 return prop_atoms.net_wm_moveresize_size_bottomleft;
186 return prop_atoms.net_wm_moveresize_size_topright;
188 return prop_atoms.net_wm_moveresize_size_bottomright;
192 void mouse_event(ObClient *client, ObFrameContext context, XEvent *e)
195 static guint button = 0, state = 0, lbutton = 0;
197 static Window lwindow = None;
199 gboolean click = FALSE;
200 gboolean dclick = FALSE;
204 px = e->xbutton.x_root;
205 py = e->xbutton.y_root;
206 button = e->xbutton.button;
207 state = e->xbutton.state;
209 fire_button(MouseAction_Press, context,
210 client, e->xbutton.state,
212 e->xbutton.x_root, e->xbutton.y_root);
214 if (context == OB_FRAME_CONTEXT_CLIENT) {
215 /* Replay the event, so it goes to the client*/
216 XAllowEvents(ob_display, ReplayPointer, event_lasttime);
217 /* Fall through to the release case! */
222 if (e->xbutton.button == button) {
223 /* clicks are only valid if its released over the window */
226 guint ujunk, b, w, h;
227 XGetGeometry(ob_display, e->xbutton.window,
228 &wjunk, &junk1, &junk2, &w, &h, &b, &ujunk);
229 if (e->xbutton.x >= (signed)-b &&
230 e->xbutton.y >= (signed)-b &&
231 e->xbutton.x < (signed)(w+b) &&
232 e->xbutton.y < (signed)(h+b)) {
234 /* double clicks happen if there were 2 in a row! */
235 if (lbutton == button &&
236 lwindow == e->xbutton.window &&
237 e->xbutton.time - config_mouse_dclicktime <=
243 lwindow = e->xbutton.window;
252 ltime = e->xbutton.time;
254 fire_button(MouseAction_Release, context,
255 client, e->xbutton.state,
257 e->xbutton.x_root, e->xbutton.y_root);
259 fire_button(MouseAction_Click, context,
260 client, e->xbutton.state,
265 fire_button(MouseAction_DClick, context,
266 client, e->xbutton.state,
274 if (ABS(e->xmotion.x_root - px) >=
275 config_mouse_threshold ||
276 ABS(e->xmotion.y_root - py) >=
277 config_mouse_threshold) {
280 /* You can't drag on buttons */
281 if (context == OB_FRAME_CONTEXT_MAXIMIZE ||
282 context == OB_FRAME_CONTEXT_ALLDESKTOPS ||
283 context == OB_FRAME_CONTEXT_SHADE ||
284 context == OB_FRAME_CONTEXT_ICONIFY ||
285 context == OB_FRAME_CONTEXT_ICON ||
286 context == OB_FRAME_CONTEXT_CLOSE)
290 corner = prop_atoms.net_wm_moveresize_size_bottomright;
293 pick_corner(e->xmotion.x_root,
295 client->frame->area.x,
296 client->frame->area.y,
297 /* use the client size because the frame
298 can be differently sized (shaded
299 windows) and we want this based on the
302 client->frame->size.left +
303 client->frame->size.right,
304 client->area.height +
305 client->frame->size.top +
306 client->frame->size.bottom);
307 fire_motion(MouseAction_Motion, context,
308 client, state, button, px, py, corner);
316 g_assert_not_reached();
320 gboolean mouse_bind(char *buttonstr, char *contextstr, ObMouseAction mact,
324 ObFrameContext context;
328 if (!translate_button(buttonstr, &state, &button)) {
329 g_warning("invalid button '%s'", buttonstr);
333 contextstr = g_ascii_strdown(contextstr, -1);
334 context = frame_context_from_string(contextstr);
336 g_warning("invalid context '%s'", contextstr);
342 for (it = bound_contexts[context]; it != NULL; it = it->next){
344 if (b->state == state && b->button == button) {
345 b->actions[mact] = g_slist_append(b->actions[mact], action);
350 grab_all_clients(FALSE);
352 /* add the binding */
353 b = g_new0(ObMouseBinding, 1);
356 b->actions[mact] = g_slist_append(NULL, action);
357 bound_contexts[context] = g_slist_append(bound_contexts[context], b);
359 grab_all_clients(TRUE);
368 void mouse_shutdown()
370 grab_all_clients(FALSE);