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 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
) {
95 if (b
->state
== state
&& b
->button
== button
)
98 /* if not bound, then nothing to do! */
99 if (it
== NULL
) return;
101 for (it
= b
->actions
[a
]; it
; it
= it
->next
) {
102 ObAction
*act
= it
->data
;
103 if (act
->func
!= NULL
) {
106 g_assert(act
->func
!= action_moveresize
);
108 if (act
->func
== action_showmenu
) {
109 act
->data
.showmenu
.x
= x
;
110 act
->data
.showmenu
.y
= y
;
113 if (act
->func
== action_desktop_dir
)
115 act
->data
.desktopdir
.final
= FALSE
;
116 act
->data
.desktopdir
.cancel
= FALSE
;
118 if (act
->func
== action_send_to_desktop_dir
)
120 act
->data
.sendtodir
.final
= FALSE
;
121 act
->data
.sendtodir
.cancel
= FALSE
;
124 if (config_desktop_popup
&&
125 (act
->func
== action_desktop_dir
||
126 act
->func
== action_send_to_desktop_dir
))
128 keyboard_interactive_grab(state
, c
, context
, act
);
131 act
->func(&act
->data
);
136 static void fire_motion(ObMouseAction a
, ObFrameContext context
, ObClient
*c
,
137 guint state
, guint button
, int x_root
, int y_root
,
143 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
) {
145 if (b
->state
== state
&& b
->button
== button
)
148 /* if not bound, then nothing to do! */
149 if (it
== NULL
) return;
151 for (it
= b
->actions
[a
]; it
; it
= it
->next
) {
152 ObAction
*act
= it
->data
;
153 if (act
->func
!= NULL
) {
156 if (act
->func
== action_moveresize
) {
157 act
->data
.moveresize
.x
= x_root
;
158 act
->data
.moveresize
.y
= y_root
;
159 act
->data
.moveresize
.button
= button
;
160 if (!(act
->data
.moveresize
.corner
==
161 prop_atoms
.net_wm_moveresize_move
||
162 act
->data
.moveresize
.corner
==
163 prop_atoms
.net_wm_moveresize_move_keyboard
||
164 act
->data
.moveresize
.corner
==
165 prop_atoms
.net_wm_moveresize_size_keyboard
))
166 act
->data
.moveresize
.corner
= corner
;
168 g_assert_not_reached();
170 act
->func(&act
->data
);
175 static guint32
pick_corner(int x
, int y
, int cx
, int cy
, int cw
, int ch
)
177 if (x
- cx
< cw
/ 2) {
179 return prop_atoms
.net_wm_moveresize_size_topleft
;
181 return prop_atoms
.net_wm_moveresize_size_bottomleft
;
184 return prop_atoms
.net_wm_moveresize_size_topright
;
186 return prop_atoms
.net_wm_moveresize_size_bottomright
;
190 void mouse_event(ObClient
*client
, ObFrameContext context
, XEvent
*e
)
193 static guint button
= 0, state
= 0, lbutton
= 0;
195 static Window lwindow
= None
;
197 gboolean click
= FALSE
;
198 gboolean dclick
= FALSE
;
202 px
= e
->xbutton
.x_root
;
203 py
= e
->xbutton
.y_root
;
204 button
= e
->xbutton
.button
;
205 state
= e
->xbutton
.state
;
207 fire_button(MouseAction_Press
, context
,
208 client
, e
->xbutton
.state
,
210 e
->xbutton
.x_root
, e
->xbutton
.y_root
);
212 if (context
== OB_FRAME_CONTEXT_CLIENT
) {
213 /* Replay the event, so it goes to the client*/
214 XAllowEvents(ob_display
, ReplayPointer
, event_lasttime
);
215 /* Fall through to the release case! */
220 if (e
->xbutton
.button
== button
) {
221 /* clicks are only valid if its released over the window */
224 guint ujunk
, b
, w
, h
;
225 XGetGeometry(ob_display
, e
->xbutton
.window
,
226 &wjunk
, &junk1
, &junk2
, &w
, &h
, &b
, &ujunk
);
227 if (e
->xbutton
.x
>= (signed)-b
&&
228 e
->xbutton
.y
>= (signed)-b
&&
229 e
->xbutton
.x
< (signed)(w
+b
) &&
230 e
->xbutton
.y
< (signed)(h
+b
)) {
232 /* double clicks happen if there were 2 in a row! */
233 if (lbutton
== button
&&
234 lwindow
== e
->xbutton
.window
&&
235 e
->xbutton
.time
- config_mouse_dclicktime
<=
241 lwindow
= e
->xbutton
.window
;
250 ltime
= e
->xbutton
.time
;
252 fire_button(MouseAction_Release
, context
,
253 client
, e
->xbutton
.state
,
255 e
->xbutton
.x_root
, e
->xbutton
.y_root
);
257 fire_button(MouseAction_Click
, context
,
258 client
, e
->xbutton
.state
,
263 fire_button(MouseAction_DClick
, context
,
264 client
, e
->xbutton
.state
,
272 if (ABS(e
->xmotion
.x_root
- px
) >=
273 config_mouse_threshold
||
274 ABS(e
->xmotion
.y_root
- py
) >=
275 config_mouse_threshold
) {
278 /* You can't drag on buttons */
279 if (context
== OB_FRAME_CONTEXT_MAXIMIZE
||
280 context
== OB_FRAME_CONTEXT_ALLDESKTOPS
||
281 context
== OB_FRAME_CONTEXT_SHADE
||
282 context
== OB_FRAME_CONTEXT_ICONIFY
||
283 context
== OB_FRAME_CONTEXT_ICON
||
284 context
== OB_FRAME_CONTEXT_CLOSE
)
288 corner
= prop_atoms
.net_wm_moveresize_size_bottomright
;
291 pick_corner(e
->xmotion
.x_root
,
293 client
->frame
->area
.x
,
294 client
->frame
->area
.y
,
295 /* use the client size because the frame
296 can be differently sized (shaded
297 windows) and we want this based on the
300 client
->frame
->size
.left
+
301 client
->frame
->size
.right
,
302 client
->area
.height
+
303 client
->frame
->size
.top
+
304 client
->frame
->size
.bottom
);
305 fire_motion(MouseAction_Motion
, context
,
306 client
, state
, button
, px
, py
, corner
);
314 g_assert_not_reached();
318 gboolean
mouse_bind(char *buttonstr
, char *contextstr
, ObMouseAction mact
,
322 ObFrameContext context
;
326 if (!translate_button(buttonstr
, &state
, &button
)) {
327 g_warning("invalid button '%s'", buttonstr
);
331 contextstr
= g_ascii_strdown(contextstr
, -1);
332 context
= frame_context_from_string(contextstr
);
334 g_warning("invalid context '%s'", contextstr
);
340 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
){
342 if (b
->state
== state
&& b
->button
== button
) {
343 b
->actions
[mact
] = g_slist_append(b
->actions
[mact
], action
);
348 grab_all_clients(FALSE
);
350 /* add the binding */
351 b
= g_new0(ObMouseBinding
, 1);
354 b
->actions
[mact
] = g_slist_append(NULL
, action
);
355 bound_contexts
[context
] = g_slist_append(bound_contexts
[context
], b
);
357 grab_all_clients(TRUE
);
366 void mouse_shutdown()
368 grab_all_clients(FALSE
);