2 #include "extensions.h"
11 /* an array of GSList*s of Func*s */
12 static GSList
**funcs
;
14 void dispatch_startup()
25 funcs
= g_new0(GSList
*, i
);
28 void dispatch_shutdown()
34 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1) {
35 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
)
37 g_slist_free(funcs
[i
]);
44 void dispatch_register(EventMask mask
, EventHandler h
, void *data
)
52 /* add to masks it needs to be registered for */
55 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1)
57 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
59 if (f
->h
== h
&& f
->data
== data
)
62 if (it
== NULL
) { /* wasn't already regged */
66 funcs
[i
] = g_slist_append(funcs
[i
], f
);
68 m
^= j
; /* remove from the mask */
70 g_assert(j
>= EVENT_RANGE
); /* an invalid event is in the mask */
73 /* remove from masks its not registered for anymore */
74 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1) {
76 for (it
= funcs
[i
]; it
!= NULL
; it
= next
) {
79 if (f
->h
== h
&& f
->data
== data
) {
81 funcs
[i
] = g_slist_delete_link(funcs
[i
], it
);
87 void dispatch_x(XEvent
*xe
, Client
*c
)
96 e
= Event_X_EnterNotify
;
99 e
= Event_X_LeaveNotify
;
102 e
= Event_X_KeyPress
;
105 e
= Event_X_KeyRelease
;
108 e
= Event_X_ButtonPress
;
111 e
= Event_X_ButtonRelease
;
114 e
= Event_X_MotionNotify
;
118 if (xe
->type
== extensions_xkb_event_basep
) {
119 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
130 obe
.data
.x
.client
= c
;
138 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
144 void dispatch_client(EventType e
, Client
*c
, int num0
, int num1
)
153 obe
.data
.c
.client
= c
;
154 obe
.data
.c
.num
[0] = num0
;
155 obe
.data
.c
.num
[1] = num1
;
163 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
169 void dispatch_ob(EventType e
, int num0
, int num1
)
176 obe
.data
.o
.num
[0] = num0
;
177 obe
.data
.o
.num
[1] = num1
;
185 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
191 void dispatch_signal(int signal
)
194 EventType e
= Event_Signal
;
199 obe
.data
.s
.signal
= signal
;
207 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
213 void dispatch_move(Client
*c
, int *x
, int *y
)
216 EventType e
= Event_Client_Moving
;
221 obe
.data
.c
.client
= c
;
222 obe
.data
.c
.num
[0] = *x
;
223 obe
.data
.c
.num
[1] = *y
;
231 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
236 *x
= obe
.data
.c
.num
[0];
237 *y
= obe
.data
.c
.num
[1];