2 #include "extensions.h"
11 /* an array of GSList*s of Func*s */
12 static GSList
**funcs
;
14 void dispatch_startup()
25 funcs
= g_new(GSList
*, i
);
27 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1)
31 void dispatch_shutdown()
37 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1) {
38 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
)
40 g_slist_free(funcs
[i
]);
47 void dispatch_register(EventMask mask
, EventHandler h
, void *data
)
55 /* add to masks it needs to be registered for */
58 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1)
60 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
62 if (f
->h
== h
&& f
->data
== data
)
65 if (it
== NULL
) { /* wasn't already regged */
69 funcs
[i
] = g_slist_append(funcs
[i
], f
);
71 m
^= j
; /* remove from the mask */
73 g_assert(j
>= EVENT_RANGE
); /* an invalid event is in the mask */
76 /* remove from masks its not registered for anymore */
77 for (i
= 0, j
= 1; j
< EVENT_RANGE
; ++i
, j
<<= 1) {
79 for (it
= funcs
[i
]; it
!= NULL
; it
= next
) {
82 if (f
->h
== h
&& f
->data
== data
) {
84 funcs
[i
] = g_slist_delete_link(funcs
[i
], it
);
90 void dispatch_x(XEvent
*xe
, Client
*c
)
99 e
= Event_X_EnterNotify
;
102 e
= Event_X_LeaveNotify
;
105 e
= Event_X_KeyPress
;
108 e
= Event_X_KeyRelease
;
111 e
= Event_X_ButtonPress
;
114 e
= Event_X_ButtonRelease
;
117 e
= Event_X_MotionNotify
;
121 if (xe
->type
== extensions_xkb_event_basep
) {
122 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
133 obe
.data
.x
.client
= c
;
141 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
147 void dispatch_client(EventType e
, Client
*c
, int num0
, int num1
)
156 obe
.data
.c
.client
= c
;
157 obe
.data
.c
.num
[0] = num0
;
158 obe
.data
.c
.num
[1] = num1
;
166 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
172 void dispatch_ob(EventType e
, int num0
, int num1
)
179 obe
.data
.o
.num
[0] = num0
;
180 obe
.data
.o
.num
[1] = num1
;
188 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
194 void dispatch_signal(int signal
)
197 EventType e
= Event_Signal
;
202 obe
.data
.s
.signal
= signal
;
210 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
216 void dispatch_move(Client
*c
, int *x
, int *y
)
219 EventType e
= Event_Client_Moving
;
224 obe
.data
.c
.client
= c
;
225 obe
.data
.c
.num
[0] = *x
;
226 obe
.data
.c
.num
[1] = *y
;
234 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
239 *x
= obe
.data
.c
.num
[0];
240 *y
= obe
.data
.c
.num
[1];