17 GSList
*actions
[OB_MOUSE_NUM_ACTIONS
]; /* lists of Action pointers */
20 #define CLIENT_CONTEXT(co, cl) ((cl && cl->type == OB_CLIENT_TYPE_DESKTOP) ? \
21 co == OB_FRAME_CONTEXT_ROOT : \
22 co == OB_FRAME_CONTEXT_CLIENT)
24 /* Array of GSList*s of PointerBinding*s. */
25 static GSList
*bound_contexts
[OB_FRAME_NUM_CONTEXTS
];
27 void mouse_grab_for_client(ObClient
*client
, gboolean grab
)
32 for (i
= 0; i
< OB_FRAME_NUM_CONTEXTS
; ++i
)
33 for (it
= bound_contexts
[i
]; it
!= NULL
; it
= it
->next
) {
34 /* grab/ungrab the button */
35 ObMouseBinding
*b
= it
->data
;
40 if (i
== OB_FRAME_CONTEXT_FRAME
) {
41 win
= client
->frame
->window
;
43 mask
= ButtonPressMask
| ButtonMotionMask
| ButtonReleaseMask
;
44 } else if (CLIENT_CONTEXT(i
, client
)) {
45 win
= client
->frame
->plate
;
46 mode
= GrabModeSync
; /* this is handled in event */
47 mask
= ButtonPressMask
; /* can't catch more than this with Sync
48 mode the release event is
49 manufactured in event() */
53 grab_button_full(b
->button
, b
->state
, win
, mask
, mode
, None
);
55 ungrab_button(b
->button
, b
->state
, win
);
59 static void grab_all_clients(gboolean grab
)
63 for (it
= client_list
; it
!= NULL
; it
= it
->next
)
64 mouse_grab_for_client(it
->data
, grab
);
67 static void clearall()
72 for(i
= 0; i
< OB_FRAME_NUM_CONTEXTS
; ++i
) {
73 for (it
= bound_contexts
[i
]; it
!= NULL
; it
= it
->next
) {
76 ObMouseBinding
*b
= it
->data
;
77 for (j
= 0; j
< OB_MOUSE_NUM_ACTIONS
; ++j
) {
79 for (it
= b
->actions
[j
]; it
; it
= it
->next
) {
80 action_free(it
->data
);
82 g_slist_free(b
->actions
[j
]);
86 g_slist_free(bound_contexts
[i
]);
90 static gboolean
fire_button(ObMouseAction a
, ObFrameContext context
,
91 ObClient
*c
, guint state
,
92 guint button
, int x
, int y
)
97 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
) {
99 if (b
->state
== state
&& b
->button
== button
)
102 /* if not bound, then nothing to do! */
103 if (it
== NULL
) return FALSE
;
105 for (it
= b
->actions
[a
]; it
; it
= it
->next
) {
106 ObAction
*act
= it
->data
;
107 if (act
->func
!= NULL
) {
110 g_assert(act
->func
!= action_moveresize
);
112 if (act
->func
== action_showmenu
) {
113 act
->data
.showmenu
.x
= x
;
114 act
->data
.showmenu
.y
= y
;
117 if (act
->func
== action_desktop_dir
)
119 act
->data
.desktopdir
.final
= FALSE
;
120 act
->data
.desktopdir
.cancel
= FALSE
;
122 if (act
->func
== action_send_to_desktop_dir
)
124 act
->data
.sendtodir
.final
= FALSE
;
125 act
->data
.sendtodir
.cancel
= FALSE
;
128 if (config_desktop_popup
&&
129 (act
->func
== action_desktop_dir
||
130 act
->func
== action_send_to_desktop_dir
))
132 keyboard_interactive_grab(state
, c
, context
, act
);
135 act
->func(&act
->data
);
141 static gboolean
fire_motion(ObMouseAction a
, ObFrameContext context
,
142 ObClient
*c
, guint state
, guint button
,
143 int x_root
, int y_root
, guint32 corner
)
148 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
) {
150 if (b
->state
== state
&& b
->button
== button
)
153 /* if not bound, then nothing to do! */
154 if (it
== NULL
) return FALSE
;
156 for (it
= b
->actions
[a
]; it
; it
= it
->next
) {
157 ObAction
*act
= it
->data
;
158 if (act
->func
!= NULL
) {
161 if (act
->func
== action_moveresize
) {
162 act
->data
.moveresize
.x
= x_root
;
163 act
->data
.moveresize
.y
= y_root
;
164 act
->data
.moveresize
.button
= button
;
165 if (!(act
->data
.moveresize
.corner
==
166 prop_atoms
.net_wm_moveresize_move
||
167 act
->data
.moveresize
.corner
==
168 prop_atoms
.net_wm_moveresize_move_keyboard
||
169 act
->data
.moveresize
.corner
==
170 prop_atoms
.net_wm_moveresize_size_keyboard
))
171 act
->data
.moveresize
.corner
= corner
;
173 g_assert_not_reached();
175 act
->func(&act
->data
);
181 static guint32
pick_corner(int x
, int y
, int cx
, int cy
, int cw
, int ch
)
183 if (x
- cx
< cw
/ 2) {
185 return prop_atoms
.net_wm_moveresize_size_topleft
;
187 return prop_atoms
.net_wm_moveresize_size_bottomleft
;
190 return prop_atoms
.net_wm_moveresize_size_topright
;
192 return prop_atoms
.net_wm_moveresize_size_bottomright
;
196 void mouse_event(ObClient
*client
, ObFrameContext context
, XEvent
*e
)
199 static guint button
= 0, state
= 0, lbutton
= 0;
201 static Window lwindow
= None
;
203 gboolean click
= FALSE
;
204 gboolean dclick
= FALSE
;
208 px
= e
->xbutton
.x_root
;
209 py
= e
->xbutton
.y_root
;
210 button
= e
->xbutton
.button
;
211 state
= e
->xbutton
.state
;
213 fire_button(OB_MOUSE_ACTION_PRESS
, context
,
214 client
, e
->xbutton
.state
,
216 e
->xbutton
.x_root
, e
->xbutton
.y_root
);
218 if (CLIENT_CONTEXT(context
, client
)) {
219 /* Replay the event, so it goes to the client*/
220 XAllowEvents(ob_display
, ReplayPointer
, event_lasttime
);
221 /* Fall through to the release case! */
226 if (e
->xbutton
.button
== button
) {
227 /* clicks are only valid if its released over the window */
230 guint ujunk
, b
, w
, h
;
231 XGetGeometry(ob_display
, e
->xbutton
.window
,
232 &wjunk
, &junk1
, &junk2
, &w
, &h
, &b
, &ujunk
);
233 if (e
->xbutton
.x
>= (signed)-b
&&
234 e
->xbutton
.y
>= (signed)-b
&&
235 e
->xbutton
.x
< (signed)(w
+b
) &&
236 e
->xbutton
.y
< (signed)(h
+b
)) {
238 /* double clicks happen if there were 2 in a row! */
239 if (lbutton
== button
&&
240 lwindow
== e
->xbutton
.window
&&
241 e
->xbutton
.time
- config_mouse_dclicktime
<=
247 lwindow
= e
->xbutton
.window
;
256 ltime
= e
->xbutton
.time
;
258 fire_button(OB_MOUSE_ACTION_RELEASE
, context
,
259 client
, e
->xbutton
.state
,
261 e
->xbutton
.x_root
, e
->xbutton
.y_root
);
263 fire_button(OB_MOUSE_ACTION_CLICK
, context
,
264 client
, e
->xbutton
.state
,
269 fire_button(OB_MOUSE_ACTION_DOUBLE_CLICK
, context
,
270 client
, e
->xbutton
.state
,
278 if (ABS(e
->xmotion
.x_root
- px
) >=
279 config_mouse_threshold
||
280 ABS(e
->xmotion
.y_root
- py
) >=
281 config_mouse_threshold
) {
284 /* You can't drag on buttons */
285 if (context
== OB_FRAME_CONTEXT_MAXIMIZE
||
286 context
== OB_FRAME_CONTEXT_ALLDESKTOPS
||
287 context
== OB_FRAME_CONTEXT_SHADE
||
288 context
== OB_FRAME_CONTEXT_ICONIFY
||
289 context
== OB_FRAME_CONTEXT_ICON
||
290 context
== OB_FRAME_CONTEXT_CLOSE
)
294 corner
= prop_atoms
.net_wm_moveresize_size_bottomright
;
297 pick_corner(e
->xmotion
.x_root
,
299 client
->frame
->area
.x
,
300 client
->frame
->area
.y
,
301 /* use the client size because the frame
302 can be differently sized (shaded
303 windows) and we want this based on the
306 client
->frame
->size
.left
+
307 client
->frame
->size
.right
,
308 client
->area
.height
+
309 client
->frame
->size
.top
+
310 client
->frame
->size
.bottom
);
311 fire_motion(OB_MOUSE_ACTION_MOTION
, context
,
312 client
, state
, button
, px
, py
, corner
);
320 g_assert_not_reached();
324 gboolean
mouse_bind(char *buttonstr
, char *contextstr
, ObMouseAction mact
,
328 ObFrameContext context
;
332 if (!translate_button(buttonstr
, &state
, &button
)) {
333 g_warning("invalid button '%s'", buttonstr
);
337 contextstr
= g_ascii_strdown(contextstr
, -1);
338 context
= frame_context_from_string(contextstr
);
340 g_warning("invalid context '%s'", contextstr
);
346 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
){
348 if (b
->state
== state
&& b
->button
== button
) {
349 b
->actions
[mact
] = g_slist_append(b
->actions
[mact
], action
);
354 grab_all_clients(FALSE
);
356 /* add the binding */
357 b
= g_new0(ObMouseBinding
, 1);
360 b
->actions
[mact
] = g_slist_append(NULL
, action
);
361 bound_contexts
[context
] = g_slist_append(bound_contexts
[context
], b
);
363 grab_all_clients(TRUE
);
372 void mouse_shutdown()
374 grab_all_clients(FALSE
);