From e03e1d62da1f794deaa29acca417ca69a912c429 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 26 Oct 2006 08:16:43 +0000 Subject: [PATCH] * Allow to create the initial canvas with a zero size. Either the application resizes it later, or the driver changes it to fit the display. --- caca/driver_gl.c | 6 ++---- caca/driver_raw.c | 12 ++++++++++++ caca/driver_win32.c | 4 ++-- caca/driver_x11.c | 5 ++--- cucul/cucul.c | 14 +------------- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/caca/driver_gl.c b/caca/driver_gl.c index 987fe46..5e7440c 100644 --- a/caca/driver_gl.c +++ b/caca/driver_gl.c @@ -86,7 +86,7 @@ static int gl_init_graphics(caca_display_t *dp) char const *geometry; char *argv[2] = { "", NULL }; char const * const * fonts; - unsigned int width = 0, height = 0; + unsigned int width = dp->cv->width, height = dp->cv->height; int argc = 1; dp->drv.p = malloc(sizeof(struct driver_private)); @@ -99,9 +99,7 @@ static int gl_init_graphics(caca_display_t *dp) sscanf(geometry, "%ux%u", &width, &height); #endif - if(width && height) - _cucul_set_canvas_size(dp->cv, width, height); - + _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); /* Load a libcucul internal font */ fonts = cucul_get_font_list(); diff --git a/caca/driver_raw.c b/caca/driver_raw.c index 873154e..72070b5 100644 --- a/caca/driver_raw.c +++ b/caca/driver_raw.c @@ -21,6 +21,7 @@ #if !defined(__KERNEL__) #include +#include #include "caca.h" #include "caca_internals.h" @@ -29,6 +30,17 @@ static int raw_init_graphics(caca_display_t *dp) { + unsigned int width = dp->cv->width, height = dp->cv->height; + char const *geometry; + +#if defined(HAVE_GETENV) + geometry = getenv("CACA_GEOMETRY"); + if(geometry && *geometry) + sscanf(geometry, "%ux%u", &width, &height); +#endif + + _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24); + return 0; } diff --git a/caca/driver_win32.c b/caca/driver_win32.c index e39f3ed..06ec832 100644 --- a/caca/driver_win32.c +++ b/caca/driver_win32.c @@ -112,8 +112,8 @@ static int win32_init_graphics(caca_display_t *dp) return -1; /* Set the new console size */ - size.X = dp->cv->width; - size.Y = dp->cv->height; + size.X = dp->cv->width ? dp->cv->width : 80; + size.Y = dp->cv->height ? dp->cv->height : 25; SetConsoleScreenBufferSize(dp->drv.p->screen, size); rect.Left = rect.Top = 0; diff --git a/caca/driver_x11.c b/caca/driver_x11.c index 9f81aa6..ef36f56 100644 --- a/caca/driver_x11.c +++ b/caca/driver_x11.c @@ -67,7 +67,7 @@ static int x11_init_graphics(caca_display_t *dp) int (*old_error_handler)(Display *, XErrorEvent *); char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; char const *geometry; - unsigned int width = 0, height = 0; + unsigned int width = dp->cv->width, height = dp->cv->height; int i; dp->drv.p = malloc(sizeof(struct driver_private)); @@ -78,8 +78,7 @@ static int x11_init_graphics(caca_display_t *dp) sscanf(geometry, "%ux%u", &width, &height); #endif - if(width && height) - _cucul_set_canvas_size(dp->cv, width, height); + _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); dp->drv.p->dpy = XOpenDisplay(NULL); if(dp->drv.p->dpy == NULL) diff --git a/cucul/cucul.c b/cucul/cucul.c index 5edeafc..167ce5d 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -43,9 +43,6 @@ * \e libcucul function to be called in a function. cucul_free_canvas() * should be called at the end of the program to free all allocated resources. * - * If one of the desired canvas coordinates is zero, a default canvas size - * of 80x32 is used instead. - * * If an error occurs, NULL is returned and \b errno is set accordingly: * - \c ENOMEM Not enough memory for the requested canvas size. * @@ -56,7 +53,6 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) { cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t)); - int ret; if(!cv) goto nomem; @@ -88,15 +84,7 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) cv->allchars[0] = NULL; cv->allattr[0] = NULL; - /* Initialise to a default size. 80x32 is arbitrary but matches AAlib's - * default X11 window. When a graphic driver attaches to us, it can set - * a different size. */ - if(width && height) - ret = _cucul_set_canvas_size(cv, width, height); - else - ret = _cucul_set_canvas_size(cv, 80, 32); - - if(ret < 0) + if(_cucul_set_canvas_size(cv, width, height) < 0) { #if defined(HAVE_ERRNO_H) int saved_errno = errno;