sgl

annotate 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
rev   line source
nuclear@0 1 #include <stdlib.h>
nuclear@0 2 #include <string.h>
nuclear@0 3 #include "sgl.h"
nuclear@4 4 #include "wsys.h"
nuclear@0 5
nuclear@0 6 struct cbnode {
nuclear@0 7 void (*func[SGL_NUM_CALLBACKS])();
nuclear@0 8 struct cbnode *next;
nuclear@0 9 };
nuclear@0 10
nuclear@4 11 static void notify_wsys(void);
nuclear@4 12
nuclear@0 13 struct cbnode first_cbnode;
nuclear@0 14 struct cbnode *cb = &first_cbnode;
nuclear@0 15
nuclear@0 16 int sgl_push_callbacks(void)
nuclear@0 17 {
nuclear@0 18 struct cbnode *node;
nuclear@0 19
nuclear@0 20 if(!(node = malloc(sizeof *node))) {
nuclear@0 21 return -1;
nuclear@0 22 }
nuclear@0 23 node->next = cb;
nuclear@0 24 cb = node;
nuclear@0 25 sgl_clear_callbacks();
nuclear@0 26 return 0;
nuclear@0 27 }
nuclear@0 28
nuclear@0 29 int sgl_pop_callbacks(void)
nuclear@0 30 {
nuclear@0 31 struct cbnode *node;
nuclear@0 32
nuclear@0 33 if(!cb->next) {
nuclear@0 34 return -1;
nuclear@0 35 }
nuclear@0 36
nuclear@0 37 node = cb;
nuclear@0 38 cb = cb->next;
nuclear@0 39 free(node);
nuclear@4 40
nuclear@4 41 notify_wsys();
nuclear@0 42 return 0;
nuclear@0 43 }
nuclear@0 44
nuclear@0 45 void sgl_clear_callbacks(void)
nuclear@0 46 {
nuclear@0 47 memset(cb->func, 0, sizeof cb->func);
nuclear@4 48 notify_wsys();
nuclear@0 49 }
nuclear@0 50
nuclear@4 51 void sgl_callback(int idx, void (*func)())
nuclear@0 52 {
nuclear@0 53 cb->func[idx] = func;
nuclear@0 54 }
nuclear@4 55
nuclear@4 56 void (*sgl_get_callback(int idx))()
nuclear@4 57 {
nuclear@4 58 return cb->func[idx];
nuclear@4 59 }
nuclear@4 60
nuclear@4 61 /* notify the window system module as to which events are active */
nuclear@4 62 static void notify_wsys(void)
nuclear@4 63 {
nuclear@4 64 int i;
nuclear@4 65 struct wsys_module *ws;
nuclear@4 66
nuclear@4 67 if((ws = sgl_wsys_module())) {
nuclear@4 68 for(i=0; i<SGL_NUM_CALLBACKS; i++) {
nuclear@4 69 ws->set_event(i, cb->func[i] != 0);
nuclear@4 70 }
nuclear@4 71 }
nuclear@4 72 }