2 #include "extensions.h"
12 /* an array of GSList*s of Func*s */
13 static GSList
**funcs
;
15 void dispatch_startup()
26 funcs
= g_new0(GSList
*, i
);
29 void dispatch_shutdown()
35 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1) {
36 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
)
38 g_slist_free(funcs
[i
]);
45 void dispatch_register(EventMask mask
, EventHandler h
, void *data
)
53 /* add to masks it needs to be registered for */
56 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1)
58 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
60 if (f
->h
== h
&& f
->data
== data
)
63 if (it
== NULL
) { /* wasn't already regged */
67 funcs
[i
] = g_slist_append(funcs
[i
], f
);
69 m
^= j
; /* remove from the mask */
71 g_assert(j
>= EVENT_RANGE
); /* an invalid event is in the mask */
74 /* remove from masks its not registered for anymore */
75 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1) {
77 for (it
= funcs
[i
]; it
!= NULL
; it
= next
) {
80 if (f
->h
== h
&& f
->data
== data
) {
82 funcs
[i
] = g_slist_delete_link(funcs
[i
], it
);
88 void dispatch_x(XEvent
*xe
, ObClient
*c
)
97 e
= Event_X_EnterNotify
;
100 e
= Event_X_LeaveNotify
;
103 e
= Event_X_KeyPress
;
106 e
= Event_X_KeyRelease
;
109 e
= Event_X_ButtonPress
;
112 e
= Event_X_ButtonRelease
;
115 e
= Event_X_MotionNotify
;
119 if (xe
->type
== extensions_xkb_event_basep
) {
120 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
131 obe
.data
.x
.client
= c
;
139 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
145 void dispatch_client(EventType e
, ObClient
*c
, int num0
, int num1
)
154 obe
.data
.c
.client
= c
;
155 obe
.data
.c
.num
[0] = num0
;
156 obe
.data
.c
.num
[1] = num1
;
157 obe
.data
.c
.num
[2] = 0;
165 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
171 void dispatch_ob(EventType e
, int num0
, int num1
)
178 obe
.data
.o
.num
[0] = num0
;
179 obe
.data
.o
.num
[1] = num1
;
187 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
193 void dispatch_signal(int signal
)
196 EventType e
= Event_Signal
;
201 obe
.data
.s
.signal
= signal
;
209 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
215 void dispatch_move(ObClient
*c
, int *x
, int *y
)
219 EventType e
= Event_Client_Moving
;
223 obe
.data
.c
.client
= c
;
224 obe
.data
.c
.num
[0] = *x
;
225 obe
.data
.c
.num
[1] = *y
;
233 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
238 *x
= obe
.data
.c
.num
[0];
239 *y
= obe
.data
.c
.num
[1];
242 void dispatch_resize(ObClient
*c
, int *w
, int *h
, ObCorner corner
)
246 EventType e
= Event_Client_Resizing
;
250 obe
.data
.c
.client
= c
;
251 obe
.data
.c
.num
[0] = *w
;
252 obe
.data
.c
.num
[1] = *h
;
253 obe
.data
.c
.num
[2] = corner
;
261 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
266 *w
= obe
.data
.c
.num
[0];
267 *h
= obe
.data
.c
.num
[1];