sgl
view src/cb.c @ 4:648f8604d2b2
cont. x11 module
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Thu, 12 May 2011 11:04:10 +0300 |
parents | 40491760d6e3 |
children | 0570e27e5ebc |
line source
1 #include <stdlib.h>
2 #include <string.h>
3 #include "sgl.h"
4 #include "wsys.h"
6 struct cbnode {
7 void (*func[SGL_NUM_CALLBACKS])();
8 struct cbnode *next;
9 };
11 static void notify_wsys(void);
13 struct cbnode first_cbnode;
14 struct cbnode *cb = &first_cbnode;
16 int sgl_push_callbacks(void)
17 {
18 struct cbnode *node;
20 if(!(node = malloc(sizeof *node))) {
21 return -1;
22 }
23 node->next = cb;
24 cb = node;
25 sgl_clear_callbacks();
26 return 0;
27 }
29 int sgl_pop_callbacks(void)
30 {
31 struct cbnode *node;
33 if(!cb->next) {
34 return -1;
35 }
37 node = cb;
38 cb = cb->next;
39 free(node);
41 notify_wsys();
42 return 0;
43 }
45 void sgl_clear_callbacks(void)
46 {
47 memset(cb->func, 0, sizeof cb->func);
48 notify_wsys();
49 }
51 void sgl_callback(int idx, void (*func)())
52 {
53 cb->func[idx] = func;
54 }
56 void (*sgl_get_callback(int idx))()
57 {
58 return cb->func[idx];
59 }
61 /* notify the window system module as to which events are active */
62 static void notify_wsys(void)
63 {
64 int i;
65 struct wsys_module *ws;
67 if((ws = sgl_wsys_module())) {
68 for(i=0; i<SGL_NUM_CALLBACKS; i++) {
69 ws->set_event(i, cb->func[i] != 0);
70 }
71 }
72 }