# HG changeset patch # User John Tsiombikas # Date 1305094183 -10800 # Node ID 1b6c5dadb46091aa14ef9782600eb752367e3df3 # Parent e55e71da991d7b70076c8afabc37888308239a49 started hacking the X11 module diff -r e55e71da991d -r 1b6c5dadb460 configure --- a/configure Wed May 11 05:53:26 2011 +0300 +++ b/configure Wed May 11 09:09:43 2011 +0300 @@ -7,7 +7,7 @@ echo "/* this file is generated by $0, do not edit */" for m in $modules; do - echo "int sgl_register_$m();" + echo "void sgl_register_$m();" done echo diff -r e55e71da991d -r 1b6c5dadb460 src/sgl.c --- a/src/sgl.c Wed May 11 05:53:26 2011 +0300 +++ b/src/sgl.c Wed May 11 09:09:43 2011 +0300 @@ -1,11 +1,11 @@ #include "sgl.h" +void sgl_register_modules(void); + int sgl_init(void) { - /*if(wsys_init() <= 0) { - fprintf(stderr, "no window system modules found\n"); - return -1; - }*/ + sgl_register_modules(); + sgl_sort_modules(); return 0; } diff -r e55e71da991d -r 1b6c5dadb460 src/wsys.c --- a/src/wsys.c Wed May 11 05:53:26 2011 +0300 +++ b/src/wsys.c Wed May 11 09:09:43 2011 +0300 @@ -1,6 +1,10 @@ #include #include "wsys.h" +static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2); +static struct wsys_module *msort(struct wsys_module *list, int count); + + struct wsys_module *wslist; int wscount; @@ -12,6 +16,16 @@ return 0; } +void sgl_sort_modules(void) +{ + wslist = msort(wslist, wscount); +} + +struct wsys_module *sgl_wsys_module(void) +{ + return wslist; +} + #define APPEND(node) \ do { \ if(!res) { \ diff -r e55e71da991d -r 1b6c5dadb460 src/wsys.h --- a/src/wsys.h Wed May 11 05:53:26 2011 +0300 +++ b/src/wsys.h Wed May 11 09:09:43 2011 +0300 @@ -10,13 +10,14 @@ int (*set_vidmode)(int, int, int); int (*get_vidmode)(int*, int*, int*); - int (*window)(int, int, unsigned int); - void (*close_win)(int); + int (*create_window)(int, int, unsigned int); + void (*close_window)(int); struct wsys_module *next; }; int sgl_register_module(struct wsys_module *ws); +void sgl_sort_modules(void); struct wsys_module *sgl_wsys_module(void); void dbg(void); diff -r e55e71da991d -r 1b6c5dadb460 src/wsys_x11.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wsys_x11.c Wed May 11 09:09:43 2011 +0300 @@ -0,0 +1,97 @@ +#include +#include +#include "wsys.h" + +struct window { + Window win; + GLXContext ctx; + struct window *next; +}; + +static int init(void); +static void shutdown(void); +static int set_vidmode(int xsz, int ysz, int bpp); +static int get_vidmode(int *xsz, int *ysz, int *bpp); +static int create_window(int xsz, int ysz, unsigned int flags); +static void close_window(int id); + +static struct wsys_module ws = { + "x11-glx", 0, + init, + shutdown, + set_vidmode, + get_vidmode, + create_window, + close_window, + 0 +}; + +static Display *dpy; +static int scr; +static struct window *winlist; + + +void sgl_register_x11(void) +{ + sgl_register_module(&ws); +} + +static int init(void) +{ + winlist = 0; + + if(!(dpy = XOpenDisplay(0))) { + return -1; + } + scr = DefaultScreen(dpy); + + return 0; +} + +static void shutdown(void) +{ + while(winlist) { + struct window *win = winlist; + winlist = winlist->next; + + glXDestroyContext(dpy, win->ctx); + XCloseWindow(dpy, win->win); + free(win); + } + XCloseDisplay(dpy); + dpy = 0; +} + +static int set_vidmode(int xsz, int ysz, int bpp) +{ + /* TODO */ +} + +static int get_vidmode(int *xsz, int *ysz, int *bpp) +{ + /* TODO */ +} + +static int create_window(int xsz, int ysz, unsigned int flags) +{ +} + +static void close_window(int id) +{ + struct window dummy, *win, *prev; + dummy.next = winlist; + + prev = &dummy; + win = prev->next; + + while(win) { + if(win->win == id) { + glXDestroyContext(dpy, win->ctx); + XCloseWindow(dpy, win->win); + prev->next = win->next; + free(win); + return; + } + win = win->next; + } +}