10 #include "translate.h"
17 GSList
*actions
[OB_NUM_MOUSE_ACTIONS
]; /* lists of Action pointers */
20 #define FRAME_CONTEXT(co, cl) ((cl && cl->type != OB_CLIENT_TYPE_DESKTOP) ? \
21 co == OB_FRAME_CONTEXT_FRAME : FALSE)
22 #define CLIENT_CONTEXT(co, cl) ((cl && cl->type == OB_CLIENT_TYPE_DESKTOP) ? \
23 co == OB_FRAME_CONTEXT_DESKTOP : \
24 co == OB_FRAME_CONTEXT_CLIENT)
26 /* Array of GSList*s of PointerBinding*s. */
27 static GSList
*bound_contexts
[OB_FRAME_NUM_CONTEXTS
];
29 void mouse_grab_for_client(ObClient
*client
, gboolean grab
)
34 for (i
= 0; i
< OB_FRAME_NUM_CONTEXTS
; ++i
)
35 for (it
= bound_contexts
[i
]; it
!= NULL
; it
= g_slist_next(it
)) {
36 /* grab/ungrab the button */
37 ObMouseBinding
*b
= it
->data
;
42 if (FRAME_CONTEXT(i
, client
)) {
43 win
= client
->frame
->window
;
45 mask
= ButtonPressMask
| ButtonMotionMask
| ButtonReleaseMask
;
46 } else if (CLIENT_CONTEXT(i
, client
)) {
47 win
= client
->frame
->plate
;
48 mode
= GrabModeSync
; /* this is handled in event */
49 mask
= ButtonPressMask
; /* can't catch more than this with Sync
50 mode the release event is
51 manufactured in event() */
55 grab_button_full(b
->button
, b
->state
, win
, mask
, mode
,
58 ungrab_button(b
->button
, b
->state
, win
);
62 static void grab_all_clients(gboolean grab
)
66 for (it
= client_list
; it
!= NULL
; it
= it
->next
)
67 mouse_grab_for_client(it
->data
, grab
);
70 static void clearall()
75 for(i
= 0; i
< OB_FRAME_NUM_CONTEXTS
; ++i
) {
76 for (it
= bound_contexts
[i
]; it
!= NULL
; it
= it
->next
) {
77 ObMouseBinding
*b
= it
->data
;
80 for (j
= 0; j
< OB_NUM_MOUSE_ACTIONS
; ++j
) {
83 for (it
= b
->actions
[j
]; it
; it
= it
->next
)
84 action_free(it
->data
);
85 g_slist_free(b
->actions
[j
]);
89 g_slist_free(bound_contexts
[i
]);
90 bound_contexts
[i
] = NULL
;
94 static gboolean
fire_binding(ObMouseAction a
, ObFrameContext context
,
95 ObClient
*c
, guint state
,
96 guint button
, int x
, int y
)
101 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
) {
103 if (b
->state
== state
&& b
->button
== button
)
106 /* if not bound, then nothing to do! */
107 if (it
== NULL
) return FALSE
;
109 for (it
= b
->actions
[a
]; it
; it
= it
->next
)
110 action_run_mouse(it
->data
, c
, state
, button
, x
, y
);
114 void mouse_event(ObClient
*client
, XEvent
*e
)
117 static guint button
= 0, state
= 0, lbutton
= 0;
118 static Window lwindow
= None
;
121 ObFrameContext context
;
122 gboolean click
= FALSE
;
123 gboolean dclick
= FALSE
;
125 context
= frame_context(client
, e
->xany
.window
);
129 px
= e
->xbutton
.x_root
;
130 py
= e
->xbutton
.y_root
;
131 button
= e
->xbutton
.button
;
132 state
= e
->xbutton
.state
;
134 fire_binding(OB_MOUSE_ACTION_PRESS
, context
,
135 client
, e
->xbutton
.state
,
137 e
->xbutton
.x_root
, e
->xbutton
.y_root
);
139 if (CLIENT_CONTEXT(context
, client
)) {
140 /* Replay the event, so it goes to the client*/
141 XAllowEvents(ob_display
, ReplayPointer
, event_lasttime
);
142 /* Fall through to the release case! */
147 if (e
->xbutton
.button
== button
) {
148 /* clicks are only valid if its released over the window */
151 guint ujunk
, b
, w
, h
;
152 xerror_set_ignore(TRUE
);
153 junk1
= XGetGeometry(ob_display
, e
->xbutton
.window
,
154 &wjunk
, &junk1
, &junk2
, &w
, &h
, &b
, &ujunk
);
155 xerror_set_ignore(FALSE
);
157 if (e
->xbutton
.x
>= (signed)-b
&&
158 e
->xbutton
.y
>= (signed)-b
&&
159 e
->xbutton
.x
< (signed)(w
+b
) &&
160 e
->xbutton
.y
< (signed)(h
+b
)) {
162 /* double clicks happen if there were 2 in a row! */
163 if (lbutton
== button
&&
164 lwindow
== e
->xbutton
.window
&&
165 e
->xbutton
.time
- config_mouse_dclicktime
<=
171 lwindow
= e
->xbutton
.window
;
181 ltime
= e
->xbutton
.time
;
183 fire_binding(OB_MOUSE_ACTION_RELEASE
, context
,
184 client
, e
->xbutton
.state
,
186 e
->xbutton
.x_root
, e
->xbutton
.y_root
);
188 fire_binding(OB_MOUSE_ACTION_CLICK
, context
,
189 client
, e
->xbutton
.state
,
194 fire_binding(OB_MOUSE_ACTION_DOUBLE_CLICK
, context
,
195 client
, e
->xbutton
.state
,
203 if (ABS(e
->xmotion
.x_root
- px
) >=
204 config_mouse_threshold
||
205 ABS(e
->xmotion
.y_root
- py
) >=
206 config_mouse_threshold
) {
208 /* You can't drag on buttons */
209 if (context
== OB_FRAME_CONTEXT_MAXIMIZE
||
210 context
== OB_FRAME_CONTEXT_ALLDESKTOPS
||
211 context
== OB_FRAME_CONTEXT_SHADE
||
212 context
== OB_FRAME_CONTEXT_ICONIFY
||
213 context
== OB_FRAME_CONTEXT_ICON
||
214 context
== OB_FRAME_CONTEXT_CLOSE
)
217 fire_binding(OB_MOUSE_ACTION_MOTION
, context
,
218 client
, state
, button
, px
, py
);
226 g_assert_not_reached();
230 gboolean
mouse_bind(char *buttonstr
, char *contextstr
, ObMouseAction mact
,
234 ObFrameContext context
;
238 if (!translate_button(buttonstr
, &state
, &button
)) {
239 g_warning("invalid button '%s'", buttonstr
);
243 contextstr
= g_ascii_strdown(contextstr
, -1);
244 context
= frame_context_from_string(contextstr
);
246 g_warning("invalid context '%s'", contextstr
);
252 for (it
= bound_contexts
[context
]; it
!= NULL
; it
= it
->next
){
254 if (b
->state
== state
&& b
->button
== button
) {
255 b
->actions
[mact
] = g_slist_append(b
->actions
[mact
], action
);
260 /* when there are no modifiers in the binding, then the action cannot
262 if (!state
&& action
->data
.any
.interactive
) {
263 action
->data
.any
.interactive
= FALSE
;
264 action
->data
.inter
.final
= TRUE
;
267 /* add the binding */
268 b
= g_new0(ObMouseBinding
, 1);
271 b
->actions
[mact
] = g_slist_append(NULL
, action
);
272 bound_contexts
[context
] = g_slist_append(bound_contexts
[context
], b
);
277 void mouse_startup(gboolean reconfig
)
279 grab_all_clients(TRUE
);
282 void mouse_shutdown(gboolean reconfig
)
284 grab_all_clients(FALSE
);