+ Beginning of an X11 driver. Currently we merely open the window and
check keyboard events.
tags/v0.99.beta14
| @@ -23,6 +23,8 @@ AC_ARG_ENABLE(slang, | |||||
| [ --enable-slang slang graphics support (default disabled)]) | [ --enable-slang slang graphics support (default disabled)]) | ||||
| AC_ARG_ENABLE(conio, | AC_ARG_ENABLE(conio, | ||||
| [ --enable-conio DOS conio.h graphics support (default disabled)]) | [ --enable-conio DOS conio.h graphics support (default disabled)]) | ||||
| AC_ARG_ENABLE(x11, | |||||
| [ --enable-x11 X11 support (default disabled)]) | |||||
| AC_CHECK_HEADERS(inttypes.h endian.h) | AC_CHECK_HEADERS(inttypes.h endian.h) | ||||
| AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp) | AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp) | ||||
| @@ -41,6 +43,20 @@ elif test "${enable_slang}" = "yes"; then | |||||
| AC_CHECK_LIB(slang,SLkp_init,:,AC_MSG_ERROR([cannot find slang library])) | AC_CHECK_LIB(slang,SLkp_init,:,AC_MSG_ERROR([cannot find slang library])) | ||||
| AC_DEFINE(USE_SLANG, 1, Define if the backend driver is slang) | AC_DEFINE(USE_SLANG, 1, Define if the backend driver is slang) | ||||
| CACA_LIBS="${CACA_LIBS} -lslang" | CACA_LIBS="${CACA_LIBS} -lslang" | ||||
| elif test "${enable_x11}" = "yes"; then | |||||
| AC_PATH_X | |||||
| AC_CHECK_LIB(X11, XOpenDisplay, | |||||
| [ac_cv_my_have_x11=yes | |||||
| X_CFLAGS="-I${x_includes}" | |||||
| X_LIBS="-lX11 -L${x_libraries}"], | |||||
| [ac_cv_my_have_x11=no], | |||||
| [[-lXt -L${x_libraries}]]) | |||||
| if test "${ac_cv_my_have_x11}" != "yes"; then | |||||
| AC_MSG_ERROR([cannot find X11 development files]) | |||||
| fi | |||||
| AC_DEFINE(USE_X11, 1, Define if the backend driver is X11) | |||||
| CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}" | |||||
| CACA_LIBS="${CACA_LIBS} ${X_LIBS}" | |||||
| elif test "${enable_ncurses}" != "no"; then | elif test "${enable_ncurses}" != "no"; then | ||||
| AC_CHECK_HEADER(ncurses.h,:,AC_MSG_ERROR([cannot find ncurses headers])) | AC_CHECK_HEADER(ncurses.h,:,AC_MSG_ERROR([cannot find ncurses headers])) | ||||
| AC_CHECK_LIB(ncurses,initscr,:,AC_MSG_ERROR([cannot find ncurses library])) | AC_CHECK_LIB(ncurses,initscr,:,AC_MSG_ERROR([cannot find ncurses library])) | ||||
| @@ -38,6 +38,8 @@ | |||||
| #elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
| # include <dos.h> | # include <dos.h> | ||||
| # include <conio.h> | # include <conio.h> | ||||
| #elif defined(USE_X11) | |||||
| # include <X11/Xlib.h> | |||||
| #else | #else | ||||
| # error "no graphics library detected" | # error "no graphics library detected" | ||||
| #endif | #endif | ||||
| @@ -113,6 +115,9 @@ int caca_init(void) | |||||
| _setcursortype(_NOCURSOR); | _setcursortype(_NOCURSOR); | ||||
| clrscr(); | clrscr(); | ||||
| #elif defined(USE_X11) | |||||
| /* Nothing to do */ | |||||
| #endif | #endif | ||||
| if(_caca_init_graphics()) | if(_caca_init_graphics()) | ||||
| return -1; | return -1; | ||||
| @@ -229,6 +234,8 @@ const char *caca_get_feature_name(enum caca_feature feature) | |||||
| void caca_end(void) | void caca_end(void) | ||||
| { | { | ||||
| _caca_end_graphics(); | |||||
| #if defined(USE_SLANG) | #if defined(USE_SLANG) | ||||
| SLtt_set_mouse_mode(0, 0); | SLtt_set_mouse_mode(0, 0); | ||||
| SLtt_set_cursor_visibility(1); | SLtt_set_cursor_visibility(1); | ||||
| @@ -245,6 +252,8 @@ void caca_end(void) | |||||
| gotoxy(_caca_width, _caca_height); | gotoxy(_caca_width, _caca_height); | ||||
| cputs("\r\n"); | cputs("\r\n"); | ||||
| _setcursortype(_NORMALCURSOR); | _setcursortype(_NORMALCURSOR); | ||||
| #elif defined(USE_X11) | |||||
| /* Nothing to do */ | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -294,7 +303,8 @@ static void caca_init_features(void) | |||||
| static void caca_init_terminal(void) | static void caca_init_terminal(void) | ||||
| { | { | ||||
| #if defined(HAVE_GETENV) && defined(HAVE_PUTENV) | |||||
| #if defined(HAVE_GETENV) && defined(HAVE_PUTENV) \ | |||||
| && (defined(USE_SLANG) || defined(USE_NCURSES)) | |||||
| char *term, *colorterm, *other; | char *term, *colorterm, *other; | ||||
| term = getenv("TERM"); | term = getenv("TERM"); | ||||
| @@ -31,6 +31,7 @@ | |||||
| #define __CACA_INTERNALS_H__ | #define __CACA_INTERNALS_H__ | ||||
| extern int _caca_init_graphics(void); | extern int _caca_init_graphics(void); | ||||
| extern int _caca_end_graphics(void); | |||||
| /* Cached screen size */ | /* Cached screen size */ | ||||
| extern unsigned int _caca_width; | extern unsigned int _caca_width; | ||||
| @@ -41,4 +42,10 @@ extern enum caca_feature _caca_background; | |||||
| extern enum caca_feature _caca_dithering; | extern enum caca_feature _caca_dithering; | ||||
| extern enum caca_feature _caca_antialiasing; | extern enum caca_feature _caca_antialiasing; | ||||
| #if defined(USE_X11) | |||||
| #include <X11/Xlib.h> | |||||
| extern Display *_caca_dpy; | |||||
| extern Window _caca_window; | |||||
| #endif | |||||
| #endif /* __CACA_INTERNALS_H__ */ | #endif /* __CACA_INTERNALS_H__ */ | ||||
| @@ -38,6 +38,8 @@ | |||||
| # if defined(SCREENUPDATE_IN_PC_H) | # if defined(SCREENUPDATE_IN_PC_H) | ||||
| # include <pc.h> | # include <pc.h> | ||||
| # endif | # endif | ||||
| #elif defined(USE_X11) | |||||
| # include <X11/Xlib.h> | |||||
| #else | #else | ||||
| # error "no graphics library detected" | # error "no graphics library detected" | ||||
| #endif | #endif | ||||
| @@ -75,6 +77,12 @@ static struct text_info ti; | |||||
| static char *_caca_screen; | static char *_caca_screen; | ||||
| #endif | #endif | ||||
| #if defined(USE_X11) | |||||
| Display *_caca_dpy; | |||||
| Window _caca_window; | |||||
| GC _caca_gc; | |||||
| #endif | |||||
| static char *_caca_empty_line; | static char *_caca_empty_line; | ||||
| static char *_caca_scratch_line; | static char *_caca_scratch_line; | ||||
| @@ -98,6 +106,8 @@ void caca_set_color(enum caca_color fgcolor, enum caca_color bgcolor) | |||||
| #elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
| textbackground(bgcolor); | textbackground(bgcolor); | ||||
| textcolor(fgcolor); | textcolor(fgcolor); | ||||
| #elif defined(USE_X11) | |||||
| /* FIXME */ | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -132,6 +142,8 @@ void caca_putchar(int x, int y, char c) | |||||
| data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; | data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; | ||||
| // gotoxy(x + 1, y + 1); | // gotoxy(x + 1, y + 1); | ||||
| // putch(c); | // putch(c); | ||||
| #elif defined(USE_X11) | |||||
| /* FIXME */ | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -175,6 +187,8 @@ void caca_putstr(int x, int y, const char *s) | |||||
| } | } | ||||
| // gotoxy(x + 1, y + 1); | // gotoxy(x + 1, y + 1); | ||||
| // cputs(s); | // cputs(s); | ||||
| #elif defined(USE_X11) | |||||
| /* FIXME */ | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -335,6 +349,42 @@ int _caca_init_graphics(void) | |||||
| _caca_width = ti.screenwidth; | _caca_width = ti.screenwidth; | ||||
| _caca_height = ti.screenheight; | _caca_height = ti.screenheight; | ||||
| #elif defined(USE_X11) | |||||
| int black_color; | |||||
| int white_color; | |||||
| _caca_dpy = XOpenDisplay(NULL); | |||||
| if(_caca_dpy == NULL) | |||||
| return -1; | |||||
| black_color = BlackPixel(_caca_dpy, DefaultScreen(_caca_dpy)); | |||||
| white_color = WhitePixel(_caca_dpy, DefaultScreen(_caca_dpy)); | |||||
| _caca_window = XCreateSimpleWindow(_caca_dpy, DefaultRootWindow(_caca_dpy), | |||||
| 0, 0, 400, 300, 0, | |||||
| black_color, black_color); | |||||
| XSelectInput(_caca_dpy, _caca_window, StructureNotifyMask); | |||||
| XMapWindow(_caca_dpy, _caca_window); | |||||
| _caca_gc = XCreateGC(_caca_dpy, _caca_window, 0, NULL); | |||||
| XSetForeground(_caca_dpy, _caca_gc, white_color); | |||||
| for(;;) | |||||
| { | |||||
| XEvent event; | |||||
| XNextEvent(_caca_dpy, &event); | |||||
| if (event.type == MapNotify) | |||||
| break; | |||||
| } | |||||
| XSelectInput(_caca_dpy, _caca_window, KeyPressMask); | |||||
| /* FIXME */ | |||||
| _caca_width = 80; | |||||
| _caca_height = 24; | |||||
| XSync(_caca_dpy, False); | |||||
| #endif | #endif | ||||
| _caca_empty_line = malloc(_caca_width + 1); | _caca_empty_line = malloc(_caca_width + 1); | ||||
| memset(_caca_empty_line, ' ', _caca_width); | memset(_caca_empty_line, ' ', _caca_width); | ||||
| @@ -348,6 +398,26 @@ int _caca_init_graphics(void) | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| int _caca_end_graphics(void) | |||||
| { | |||||
| #if defined(USE_SLANG) | |||||
| /* Nothing to do */ | |||||
| #elif defined(USE_NCURSES) | |||||
| /* Nothing to do */ | |||||
| #elif defined(USE_CONIO) | |||||
| free(_caca_screen); | |||||
| #elif defined(USE_X11) | |||||
| XSync(_caca_dpy, False); | |||||
| XFreeGC(_caca_dpy, _caca_gc); | |||||
| XUnmapWindow(_caca_dpy, _caca_window); | |||||
| XDestroyWindow(_caca_dpy, _caca_window); | |||||
| XCloseDisplay(_caca_dpy); | |||||
| #endif | |||||
| free(_caca_empty_line); | |||||
| return 0; | |||||
| } | |||||
| void caca_set_delay(unsigned int usec) | void caca_set_delay(unsigned int usec) | ||||
| { | { | ||||
| _caca_delay = usec; | _caca_delay = usec; | ||||
| @@ -394,6 +464,9 @@ void caca_refresh(void) | |||||
| # else | # else | ||||
| /* FIXME */ | /* FIXME */ | ||||
| # endif | # endif | ||||
| #elif defined(USE_X11) | |||||
| /* FIXME */ | |||||
| XFlush(_caca_dpy); | |||||
| #endif | #endif | ||||
| /* Wait until _caca_delay + time of last call */ | /* Wait until _caca_delay + time of last call */ | ||||
| @@ -35,6 +35,9 @@ | |||||
| # include <curses.h> | # include <curses.h> | ||||
| #elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
| # include <conio.h> | # include <conio.h> | ||||
| #elif defined(USE_X11) | |||||
| # include <X11/Xlib.h> | |||||
| # include <X11/Xutil.h> | |||||
| #else | #else | ||||
| # error "no graphics library detected" | # error "no graphics library detected" | ||||
| #endif | #endif | ||||
| @@ -204,6 +207,23 @@ static unsigned int _read_key(void) | |||||
| return (key == ERR) ? 0 : key; | return (key == ERR) ? 0 : key; | ||||
| #elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
| return _conio_kbhit() ? getch() : 0; | return _conio_kbhit() ? getch() : 0; | ||||
| #elif defined(USE_X11) | |||||
| XEvent event; | |||||
| char key; | |||||
| while(XCheckWindowEvent(_caca_dpy, _caca_window, KeyPressMask, &event) | |||||
| == True) | |||||
| { | |||||
| if(event.type == KeyPress) | |||||
| { | |||||
| //KeySym keysym; | |||||
| //keysym = XKeycodeToKeysym(_caca_dpy, event.xkey.keycode, 0); | |||||
| if(XLookupString(&event.xkey, &key, 1, NULL, NULL)) | |||||
| return key; | |||||
| } | |||||
| } | |||||
| return 0; | |||||
| #endif | #endif | ||||
| } | } | ||||