sgl

view src/cb.c @ 5:0570e27e5ebc

pretty much done with the basic functionality and GLX shit
author John Tsiombikas <nuclear@siggraph.org>
date Fri, 13 May 2011 07:49:47 +0300
parents 648f8604d2b2
children 0cb438c86b98
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_set_callback(int idx, void (*func)())
52 {
53 struct wsys_module *ws;
55 cb->func[idx] = func;
57 if((ws = sgl_wsys_module())) {
58 ws->set_event(idx, func != 0);
59 }
60 }
62 void (*sgl_get_callback(int idx))()
63 {
64 return cb->func[idx];
65 }
67 /* notify the window system module as to which events are active */
68 static void notify_wsys(void)
69 {
70 int i;
71 struct wsys_module *ws;
73 if((ws = sgl_wsys_module())) {
74 for(i=0; i<SGL_NUM_CALLBACKS; i++) {
75 ws->set_event(i, cb->func[i] != 0);
76 }
77 }
78 }