Преглед на файлове

* src/graphics.c src/event.c:

+ The ncurses and S-Lang drivers properly return CACA_EVENT_RESIZE.
  * test/event.c:
    + Display CACA_EVENT_RESIZE.
tags/v0.99.beta14
Sam Hocevar sam преди 21 години
родител
ревизия
0bfa4dfe32
променени са 4 файла, в които са добавени 67 реда и са изтрити 53 реда
  1. +3
    -2
      src/caca_internals.h
  2. +22
    -3
      src/event.c
  3. +39
    -48
      src/graphics.c
  4. +3
    -0
      test/event.c

+ 3
- 2
src/caca_internals.h Целия файл

@@ -73,8 +73,8 @@ extern unsigned int _caca_getticks(struct caca_timer *);
/* Cached screen size */
extern unsigned int _caca_width;
extern unsigned int _caca_height;
extern unsigned int _caca_new_width;
extern unsigned int _caca_new_height;
extern int _caca_resize;
extern int _caca_resize_event;

/* Internal libcaca features */
extern enum caca_feature _caca_background;
@@ -87,6 +87,7 @@ extern Display *x11_dpy;
extern Window x11_window;
extern long int x11_event_mask;
extern int x11_font_width, x11_font_height;
extern unsigned int x11_new_width, x11_new_height;
#endif

#if defined(USE_WIN32)


+ 22
- 3
src/event.c Целия файл

@@ -262,8 +262,13 @@ static unsigned int _lowlevel_event(void)
if(w == _caca_width && h == _caca_height)
continue;

_caca_new_width = w;
_caca_new_height = h;
x11_new_width = w;
x11_new_height = h;

if(_caca_resize)
continue;

_caca_resize = 1;

return CACA_EVENT_RESIZE;
}
@@ -341,7 +346,15 @@ static unsigned int _lowlevel_event(void)
#if defined(USE_NCURSES)
if(_caca_driver == CACA_DRIVER_NCURSES)
{
int intkey = getch();
int intkey;

if(_caca_resize_event)
{
_caca_resize_event = 0;
return CACA_EVENT_RESIZE;
}

intkey = getch();
if(intkey == ERR)
return CACA_EVENT_NONE;

@@ -518,6 +531,12 @@ static unsigned int _lowlevel_event(void)
{
int intkey;

if(_caca_resize_event)
{
_caca_resize_event = 0;
return CACA_EVENT_RESIZE;
}

if(!SLang_input_pending(0))
return CACA_EVENT_NONE;



+ 39
- 48
src/graphics.c Целия файл

@@ -85,8 +85,8 @@ typedef unsigned char uint8_t;
#if !defined(_DOXYGEN_SKIP_ME)
unsigned int _caca_width = 0;
unsigned int _caca_height = 0;
unsigned int _caca_new_width = 0;
unsigned int _caca_new_height = 0;
int _caca_resize = 0;
int _caca_resize_event = 0;
#endif

/*
@@ -166,6 +166,7 @@ Window x11_window;
long int x11_event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
| ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
int x11_font_width, x11_font_height;
unsigned int x11_new_width, x11_new_height;
static GC x11_gc;
static Pixmap x11_pixmap;
static uint8_t *x11_char, *x11_attr;
@@ -826,6 +827,8 @@ int _caca_init_graphics(void)
_caca_height * x11_font_height,
DefaultDepth(x11_dpy,
DefaultScreen(x11_dpy)));

x11_new_width = x11_new_height = 0;
}
else
#endif
@@ -907,9 +910,6 @@ int _caca_init_graphics(void)

_caca_scratch_line = malloc(_caca_width + 1);

_caca_new_width = _caca_width;
_caca_new_height = _caca_height;

_caca_delay = 0;
_caca_rendertime = 0;

@@ -1184,8 +1184,11 @@ void caca_refresh(void)
/* Dummy */
}

if(_caca_width != _caca_new_width || _caca_height != _caca_new_height)
if(_caca_resize)
{
_caca_resize = 0;
caca_handle_resize();
}

/* Wait until _caca_delay + time of last call */
ticks += _caca_getticks(&timer);
@@ -1214,32 +1217,30 @@ static void caca_handle_resize(void)
unsigned int old_width = _caca_width;
unsigned int old_height = _caca_height;

_caca_width = _caca_new_width;
_caca_height = _caca_new_height;

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);
}

#if defined(USE_SLANG)
if(_caca_driver == CACA_DRIVER_SLANG)
{
SLsmg_reinit_smg();
SLtt_get_screen_size();
_caca_width = SLtt_Screen_Cols;
_caca_height = SLtt_Screen_Rows;

if(_caca_width != old_width || _caca_height != old_height)
SLsmg_reinit_smg();
}
else
#endif
#if defined(USE_NCURSES)
if(_caca_driver == CACA_DRIVER_NCURSES)
{
resize_term(_caca_height, _caca_width);
wrefresh(curscr);
struct winsize size;

if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
{
_caca_width = size.ws_col;
_caca_height = size.ws_row;
resize_term(_caca_height, _caca_width);
wrefresh(curscr);
}
}
else
#endif
@@ -1252,6 +1253,9 @@ static void caca_handle_resize(void)
#if defined(USE_X11)
if(_caca_driver == CACA_DRIVER_X11)
{
_caca_width = x11_new_width;
_caca_height = x11_new_height;

XFreePixmap(x11_dpy, x11_pixmap);
free(x11_char);
free(x11_attr);
@@ -1277,6 +1281,17 @@ static void caca_handle_resize(void)
{
/* Dummy */
}

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);
}
}

#if defined(USE_SLANG)
@@ -1335,31 +1350,7 @@ static int x11_error_handler(Display *dpy, XErrorEvent *event)
#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 */
}
_caca_resize_event = 1;

signal(SIGWINCH, sigwinch_handler);;
}


+ 3
- 0
test/event.c Целия файл

@@ -137,6 +137,9 @@ static void print_event(int x, int y, unsigned int event)
caca_printf(x, y, "CACA_EVENT_MOUSE_RELEASE %u",
event & 0x00ffffff);
break;
case CACA_EVENT_RESIZE:
caca_printf(x, y, "CACA_EVENT_RESIZE");
break;
default:
caca_printf(x, y, "CACA_EVENT_UNKNOWN");
}


Зареждане…
Отказ
Запис