+ Resize handling in the ncurses and slang drivers.tags/v0.99.beta14
@@ -15,6 +15,7 @@ AC_PROG_RANLIB | |||||
AC_C_CONST | AC_C_CONST | ||||
AC_C_INLINE | AC_C_INLINE | ||||
AC_TYPE_SIGNAL | |||||
dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right | dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right | ||||
dnl now otherwise it might be set in an obscure if statement. | dnl now otherwise it might be set in an obscure if statement. | ||||
@@ -40,8 +41,10 @@ dnl conditional builds | |||||
AC_ARG_ENABLE(doc, | AC_ARG_ENABLE(doc, | ||||
[ --enable-doc build documentation (needs doxygen and LaTeX)]) | [ --enable-doc build documentation (needs doxygen and LaTeX)]) | ||||
AC_CHECK_HEADERS(sys/time.h inttypes.h endian.h unistd.h) | |||||
AC_CHECK_FUNCS(vsnprintf _vsnprintf getenv putenv strcasecmp usleep gettimeofday) | |||||
AC_CHECK_HEADERS(signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h) | |||||
AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp) | |||||
AC_CHECK_FUNCS(usleep gettimeofday) | |||||
AC_MSG_CHECKING(for Sleep) | AC_MSG_CHECKING(for Sleep) | ||||
AC_TRY_COMPILE([#include <windows.h>],[Sleep(42);], | AC_TRY_COMPILE([#include <windows.h>],[Sleep(42);], | ||||
[AC_MSG_RESULT(yes) | [AC_MSG_RESULT(yes) | ||||
@@ -10,6 +10,8 @@ | |||||
#define HAVE_MEMORY_H 1 | #define HAVE_MEMORY_H 1 | ||||
/* #undef HAVE_NCURSES_H */ | /* #undef HAVE_NCURSES_H */ | ||||
#define HAVE_PUTENV 1 | #define HAVE_PUTENV 1 | ||||
/* #undef HAVE_SIGNAL */ | |||||
/* #undef HAVE_SIGNAL_H */ | |||||
/* #undef HAVE_SLANG_H */ | /* #undef HAVE_SLANG_H */ | ||||
/* #undef HAVE_SLANG_SLANG_H */ | /* #undef HAVE_SLANG_SLANG_H */ | ||||
#define HAVE_SLEEP 1 | #define HAVE_SLEEP 1 | ||||
@@ -18,14 +20,15 @@ | |||||
/* #undef HAVE_STRCASECMP */ | /* #undef HAVE_STRCASECMP */ | ||||
#define HAVE_STRINGS_H 1 | #define HAVE_STRINGS_H 1 | ||||
#define HAVE_STRING_H 1 | #define HAVE_STRING_H 1 | ||||
/* #undef HAVE_SYS_IOCTL_H */ | |||||
#define HAVE_SYS_STAT_H 1 | #define HAVE_SYS_STAT_H 1 | ||||
/* #undef HAVE_SYS_TIME_H */ | |||||
#define HAVE_SYS_TYPES_H 1 | #define HAVE_SYS_TYPES_H 1 | ||||
/* #undef HAVE_UNISTD_H */ | /* #undef HAVE_UNISTD_H */ | ||||
/* #undef HAVE_USLEEP */ | /* #undef HAVE_USLEEP */ | ||||
/* #undef HAVE_VSNPRINTF */ | /* #undef HAVE_VSNPRINTF */ | ||||
#define HAVE_WINDOWS_H 1 | #define HAVE_WINDOWS_H 1 | ||||
/* #undef HAVE_X11_XKBLIB_H */ | /* #undef HAVE_X11_XKBLIB_H */ | ||||
#define HAVE__VSNPRINTF 1 | |||||
/* #undef NO_MINUS_C_MINUS_O */ | /* #undef NO_MINUS_C_MINUS_O */ | ||||
#define PACKAGE "libcaca" | #define PACKAGE "libcaca" | ||||
#define PACKAGE_BUGREPORT "" | #define PACKAGE_BUGREPORT "" | ||||
@@ -33,6 +36,7 @@ | |||||
#define PACKAGE_STRING "" | #define PACKAGE_STRING "" | ||||
#define PACKAGE_TARNAME "" | #define PACKAGE_TARNAME "" | ||||
#define PACKAGE_VERSION "" | #define PACKAGE_VERSION "" | ||||
/* #undef RETSIGTYPE */ | |||||
/* #undef SCREENUPDATE_IN_PC_H */ | /* #undef SCREENUPDATE_IN_PC_H */ | ||||
#define STDC_HEADERS 1 | #define STDC_HEADERS 1 | ||||
/* #undef USE_CONIO */ | /* #undef USE_CONIO */ | ||||
@@ -69,6 +69,13 @@ typedef unsigned char uint8_t; | |||||
#endif | #endif | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#if defined(HAVE_SIGNAL_H) | |||||
# include <signal.h> | |||||
#endif | |||||
#if defined(HAVE_SYS_IOCTL_H) | |||||
# include <sys/ioctl.h> | |||||
#endif | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
@@ -239,6 +246,10 @@ static void caca_handle_resize(void); | |||||
static void slang_init_palette(void); | static void slang_init_palette(void); | ||||
#endif | #endif | ||||
#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG)) | |||||
static RETSIGTYPE sigwinch_handler(int); | |||||
#endif | |||||
#if defined(USE_X11) | #if defined(USE_X11) | ||||
static int x11_error_handler(Display *, XErrorEvent *); | static int x11_error_handler(Display *, XErrorEvent *); | ||||
#endif | #endif | ||||
@@ -563,6 +574,10 @@ void caca_clear(void) | |||||
#if !defined(_DOXYGEN_SKIP_ME) | #if !defined(_DOXYGEN_SKIP_ME) | ||||
int _caca_init_graphics(void) | int _caca_init_graphics(void) | ||||
{ | { | ||||
#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG)) | |||||
signal(SIGWINCH, sigwinch_handler); | |||||
#endif | |||||
#if defined(USE_SLANG) | #if defined(USE_SLANG) | ||||
if(_caca_driver == CACA_DRIVER_SLANG) | if(_caca_driver == CACA_DRIVER_SLANG) | ||||
{ | { | ||||
@@ -1202,23 +1217,29 @@ static void caca_handle_resize(void) | |||||
_caca_width = _caca_new_width; | _caca_width = _caca_new_width; | ||||
_caca_height = _caca_new_height; | _caca_height = _caca_new_height; | ||||
free(_caca_empty_line); | |||||
_caca_empty_line = malloc(_caca_width + 1); | |||||
memset(_caca_empty_line, ' ', _caca_width); | |||||
_caca_empty_line[_caca_width] = '\0'; | |||||
if(_caca_width != old_width) | |||||
{ | |||||
free(_caca_empty_line); | |||||
_caca_empty_line = malloc(_caca_width + 1); | |||||
memset(_caca_empty_line, ' ', _caca_width); | |||||
_caca_empty_line[_caca_width] = '\0'; | |||||
free(_caca_scratch_line); | |||||
_caca_scratch_line = malloc(_caca_width + 1); | |||||
free(_caca_scratch_line); | |||||
_caca_scratch_line = malloc(_caca_width + 1); | |||||
} | |||||
#if defined(USE_SLANG) | #if defined(USE_SLANG) | ||||
if(_caca_driver == CACA_DRIVER_SLANG) | if(_caca_driver == CACA_DRIVER_SLANG) | ||||
{ | { | ||||
SLsmg_reinit_smg(); | |||||
} | } | ||||
else | else | ||||
#endif | #endif | ||||
#if defined(USE_NCURSES) | #if defined(USE_NCURSES) | ||||
if(_caca_driver == CACA_DRIVER_NCURSES) | if(_caca_driver == CACA_DRIVER_NCURSES) | ||||
{ | { | ||||
resize_term(_caca_height, _caca_width); | |||||
wrefresh(curscr); | |||||
} | } | ||||
else | else | ||||
#endif | #endif | ||||
@@ -1311,3 +1332,36 @@ static int x11_error_handler(Display *dpy, XErrorEvent *event) | |||||
} | } | ||||
#endif | #endif | ||||
#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG)) | |||||
static RETSIGTYPE sigwinch_handler(int sig) | |||||
{ | |||||
struct winsize size; | |||||
#if defined(USE_SLANG) | |||||
if(_caca_driver == CACA_DRIVER_SLANG) | |||||
{ | |||||
SLtt_get_screen_size(); | |||||
_caca_new_width = SLtt_Screen_Cols; | |||||
_caca_new_height = SLtt_Screen_Rows; | |||||
} | |||||
else | |||||
#endif | |||||
#if defined(USE_NCURSES) | |||||
if(_caca_driver == CACA_DRIVER_NCURSES) | |||||
{ | |||||
if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) | |||||
{ | |||||
_caca_new_width = size.ws_col; | |||||
_caca_new_height = size.ws_row; | |||||
} | |||||
} | |||||
else | |||||
#endif | |||||
{ | |||||
/* Dummy */ | |||||
} | |||||
signal(SIGWINCH, sigwinch_handler);; | |||||
} | |||||
#endif | |||||