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
;
156 obe
.data
.c
.num
[2] = 0;
164 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
170 void dispatch_ob(EventType e
, int num0
, int num1
)
177 obe
.data
.o
.num
[0] = num0
;
178 obe
.data
.o
.num
[1] = num1
;
186 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
192 void dispatch_signal(int signal
)
195 EventType e
= Event_Signal
;
200 obe
.data
.s
.signal
= signal
;
208 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
214 void dispatch_move(Client
*c
, int *x
, int *y
)
218 EventType e
= Event_Client_Moving
;
222 obe
.data
.c
.client
= c
;
223 obe
.data
.c
.num
[0] = *x
;
224 obe
.data
.c
.num
[1] = *y
;
232 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
237 *x
= obe
.data
.c
.num
[0];
238 *y
= obe
.data
.c
.num
[1];
241 void dispatch_resize(Client
*c
, int *w
, int *h
, Corner corner
)
245 EventType e
= Event_Client_Resizing
;
249 obe
.data
.c
.client
= c
;
250 obe
.data
.c
.num
[0] = *w
;
251 obe
.data
.c
.num
[1] = *h
;
252 obe
.data
.c
.num
[2] = corner
;
260 for (it
= funcs
[i
]; it
!= NULL
; it
= it
->next
) {
265 *w
= obe
.data
.c
.num
[0];
266 *h
= obe
.data
.c
.num
[1];