@@ -122,92 +122,56 @@ static int caca_init_driver(caca_t *kk) | |||
if(var && *var) | |||
{ | |||
#if defined(USE_WIN32) | |||
if(!strcasecmp(var, "win32")) | |||
win32_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "win32")) return win32_install(kk); | |||
#endif | |||
#if defined(USE_CONIO) | |||
if(!strcasecmp(var, "conio")) | |||
conio_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "conio")) return conio_install(kk); | |||
#endif | |||
#if defined(USE_X11) | |||
if(!strcasecmp(var, "x11")) | |||
x11_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "x11")) return x11_install(kk); | |||
#endif | |||
#if defined(USE_GL) | |||
if(!strcasecmp(var, "gl")) | |||
gl_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "gl")) return gl_install(kk); | |||
#endif | |||
#if defined(USE_SLANG) | |||
if(!strcasecmp(var, "slang")) | |||
slang_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "slang")) return slang_install(kk); | |||
#endif | |||
#if defined(USE_NCURSES) | |||
if(!strcasecmp(var, "ncurses")) | |||
ncurses_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "ncurses")) return ncurses_install(kk); | |||
#endif | |||
#if defined(USE_NETWORK) | |||
if(!strcasecmp(var, "network")) | |||
network_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "network")) return network_install(kk); | |||
#endif | |||
#if defined(USE_VGA) | |||
if(!strcasecmp(var, "vga")) | |||
vga_init_driver(kk); | |||
else | |||
if(!strcasecmp(var, "vga")) return vga_install(kk); | |||
#endif | |||
return -1; | |||
return 0; | |||
return -1; | |||
} | |||
#endif | |||
#if defined(USE_WIN32) | |||
win32_init_driver(kk); | |||
return 0; | |||
if(win32_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_CONIO) | |||
conio_init_driver(kk); | |||
return 0; | |||
if(conio_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_VGA) | |||
vga_init_driver(kk); | |||
return 0; | |||
if(vga_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_X11) | |||
#if defined(HAVE_GETENV) | |||
if(getenv("DISPLAY") && *(getenv("DISPLAY"))) | |||
#endif | |||
{ | |||
x11_init_driver(kk); | |||
return 0; | |||
} | |||
if(x11_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_GL) | |||
#if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION) | |||
if(getenv("DISPLAY") && *(getenv("DISPLAY"))) | |||
#endif | |||
{ | |||
gl_init_driver(kk); | |||
return 0; | |||
} | |||
if(gl_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_SLANG) | |||
slang_init_driver(kk); | |||
return 0; | |||
if(slang_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_NCURSES) | |||
ncurses_init_driver(kk); | |||
return 0; | |||
if(ncurses_install(kk) == 0) return 0; | |||
#endif | |||
#if defined(USE_NETWORK) | |||
network_init_driver(kk); | |||
return 0; | |||
if(network_install(kk) == 0) return 0; | |||
#endif | |||
return -1; | |||
@@ -38,6 +38,7 @@ typedef long unsigned int uintptr_t; | |||
/* Graphics driver */ | |||
enum caca_driver | |||
{ | |||
CACA_DRIVER_NONE = 0, | |||
#if defined(USE_CONIO) | |||
CACA_DRIVER_CONIO = 1, | |||
#endif | |||
@@ -62,34 +63,34 @@ enum caca_driver | |||
#if defined(USE_VGA) | |||
CACA_DRIVER_VGA = 8, | |||
#endif | |||
CACA_DRIVER_NONE = 0 | |||
}; | |||
/* Available drivers */ | |||
#if defined(USE_CONIO) | |||
void conio_init_driver(caca_t *); | |||
int conio_install(caca_t *); | |||
#endif | |||
#if defined(USE_GL) | |||
void gl_init_driver(caca_t *); | |||
int gl_install(caca_t *); | |||
#endif | |||
#if defined(USE_NCURSES) | |||
void ncurses_init_driver(caca_t *); | |||
int ncurses_install(caca_t *); | |||
#endif | |||
#if defined(USE_SLANG) | |||
void slang_init_driver(caca_t *); | |||
int slang_install(caca_t *); | |||
#endif | |||
#if defined(USE_WIN32) | |||
void win32_init_driver(caca_t *); | |||
int win32_install(caca_t *); | |||
#endif | |||
#if defined(USE_X11) | |||
void x11_init_driver(caca_t *); | |||
int x11_install(caca_t *); | |||
#endif | |||
#if defined(USE_NETWORK) | |||
void network_init_driver(caca_t *); | |||
int network_install(caca_t *); | |||
#endif | |||
#if defined(USE_VGA) | |||
void vga_init_driver(caca_t *); | |||
int vga_install(caca_t *); | |||
#endif | |||
/* Timer structure */ | |||
struct caca_timer | |||
{ | |||
@@ -128,7 +129,6 @@ struct caca_context | |||
struct resize | |||
{ | |||
int resized; /* A resize event was requested */ | |||
//int acked; /* The event has been acknowledged by the user */ | |||
unsigned w, h; /* Requested width and height */ | |||
} resize; | |||
@@ -151,7 +151,7 @@ static int conio_get_event(caca_t *kk, struct caca_event *ev) | |||
* Driver initialisation | |||
*/ | |||
void conio_init_driver(caca_t *kk) | |||
int conio_install(caca_t *kk) | |||
{ | |||
kk->drv.driver = CACA_DRIVER_CONIO; | |||
@@ -163,6 +163,8 @@ void conio_init_driver(caca_t *kk) | |||
kk->drv.display = conio_display; | |||
kk->drv.handle_resize = conio_handle_resize; | |||
kk->drv.get_event = conio_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_CONIO */ | |||
@@ -106,9 +106,11 @@ static int gl_init_graphics(caca_t *kk) | |||
gl_kk = kk; | |||
#if defined(HAVE_GETENV) | |||
geometry = getenv("CACA_GEOMETRY"); | |||
if(geometry && *geometry) | |||
sscanf(geometry, "%ux%u", &width, &height); | |||
#endif | |||
if(width && height) | |||
_cucul_set_size(kk->qq, width, height); | |||
@@ -445,8 +447,13 @@ static void gl_handle_mouse_motion(int x, int y) | |||
* Driver initialisation | |||
*/ | |||
void gl_init_driver(caca_t *kk) | |||
int gl_install(caca_t *kk) | |||
{ | |||
#if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION) | |||
if(!getenv("DISPLAY") || !*(getenv("DISPLAY"))) | |||
return -1; | |||
#endif | |||
kk->drv.driver = CACA_DRIVER_GL; | |||
kk->drv.init_graphics = gl_init_graphics; | |||
@@ -457,6 +464,8 @@ void gl_init_driver(caca_t *kk) | |||
kk->drv.display = gl_display; | |||
kk->drv.handle_resize = gl_handle_resize; | |||
kk->drv.get_event = gl_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_GL */ | |||
@@ -530,7 +530,7 @@ static void ncurses_write_utf32(uint32_t c) | |||
* Driver initialisation | |||
*/ | |||
void ncurses_init_driver(caca_t *kk) | |||
int ncurses_install(caca_t *kk) | |||
{ | |||
kk->drv.driver = CACA_DRIVER_NCURSES; | |||
@@ -542,6 +542,8 @@ void ncurses_init_driver(caca_t *kk) | |||
kk->drv.display = ncurses_display; | |||
kk->drv.handle_resize = ncurses_handle_resize; | |||
kk->drv.get_event = ncurses_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_NCURSES */ | |||
@@ -550,7 +550,7 @@ ssize_t nonblock_write(int fd, void *buf, size_t len) | |||
* Driver initialisation | |||
*/ | |||
void network_init_driver(caca_t *kk) | |||
int network_install(caca_t *kk) | |||
{ | |||
kk->drv.driver = CACA_DRIVER_NETWORK; | |||
@@ -562,6 +562,8 @@ void network_init_driver(caca_t *kk) | |||
kk->drv.display = network_display; | |||
kk->drv.handle_resize = network_handle_resize; | |||
kk->drv.get_event = network_get_event; | |||
return 0; | |||
} | |||
@@ -468,7 +468,7 @@ static void slang_check_terminal(void) | |||
* Driver initialisation | |||
*/ | |||
void slang_init_driver(caca_t *kk) | |||
int slang_install(caca_t *kk) | |||
{ | |||
kk->drv.driver = CACA_DRIVER_SLANG; | |||
@@ -480,6 +480,8 @@ void slang_init_driver(caca_t *kk) | |||
kk->drv.display = slang_display; | |||
kk->drv.handle_resize = slang_handle_resize; | |||
kk->drv.get_event = slang_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_SLANG */ | |||
@@ -145,7 +145,7 @@ static int vga_get_event(caca_t *kk, struct caca_event *ev) | |||
* Driver initialisation | |||
*/ | |||
void vga_init_driver(caca_t *kk) | |||
int vga_install(caca_t *kk) | |||
{ | |||
kk->drv.driver = CACA_DRIVER_VGA; | |||
@@ -157,6 +157,8 @@ void vga_init_driver(caca_t *kk) | |||
kk->drv.display = vga_display; | |||
kk->drv.handle_resize = vga_handle_resize; | |||
kk->drv.get_event = vga_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_VGA */ | |||
@@ -333,7 +333,7 @@ static int win32_get_event(caca_t *kk, struct caca_event *ev) | |||
* Driver initialisation | |||
*/ | |||
void win32_init_driver(caca_t *kk) | |||
int win32_install(caca_t *kk) | |||
{ | |||
kk->drv.driver = CACA_DRIVER_WIN32; | |||
@@ -345,6 +345,8 @@ void win32_init_driver(caca_t *kk) | |||
kk->drv.display = win32_display; | |||
kk->drv.handle_resize = win32_handle_resize; | |||
kk->drv.get_event = win32_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_WIN32 */ | |||
@@ -92,9 +92,11 @@ static int x11_init_graphics(caca_t *kk) | |||
kk->drv.p = malloc(sizeof(struct driver_private)); | |||
#if defined(HAVE_GETENV) | |||
geometry = getenv("CACA_GEOMETRY"); | |||
if(geometry && *geometry) | |||
sscanf(geometry, "%ux%u", &width, &height); | |||
#endif | |||
if(width && height) | |||
_cucul_set_size(kk->qq, width, height); | |||
@@ -103,10 +105,12 @@ static int x11_init_graphics(caca_t *kk) | |||
if(kk->drv.p->dpy == NULL) | |||
return -1; | |||
#if defined(HAVE_GETENV) | |||
fonts[0] = getenv("CACA_FONT"); | |||
if(fonts[0] && *fonts[0]) | |||
parser = fonts; | |||
else | |||
#endif | |||
parser = fonts + 1; | |||
/* Ignore font errors */ | |||
@@ -543,8 +547,13 @@ static int x11_error_handler(Display *dpy, XErrorEvent *xevent) | |||
* Driver initialisation | |||
*/ | |||
void x11_init_driver(caca_t *kk) | |||
int x11_install(caca_t *kk) | |||
{ | |||
#if defined(HAVE_GETENV) | |||
if(!getenv("DISPLAY") || !*(getenv("DISPLAY"))) | |||
return -1; | |||
#endif | |||
kk->drv.driver = CACA_DRIVER_X11; | |||
kk->drv.init_graphics = x11_init_graphics; | |||
@@ -555,6 +564,8 @@ void x11_init_driver(caca_t *kk) | |||
kk->drv.display = x11_display; | |||
kk->drv.handle_resize = x11_handle_resize; | |||
kk->drv.get_event = x11_get_event; | |||
return 0; | |||
} | |||
#endif /* USE_X11 */ | |||