Browse Source

* src/io.c:

+ Mouse support in the X11 driver.
tags/v0.99.beta14
Sam Hocevar sam 21 years ago
parent
commit
0d638c2e57
3 changed files with 34 additions and 3 deletions
  1. +1
    -0
      src/caca_internals.h
  2. +4
    -2
      src/graphics.c
  3. +29
    -1
      src/io.c

+ 1
- 0
src/caca_internals.h View File

@@ -67,6 +67,7 @@ extern enum caca_feature _caca_antialiasing;
#include <X11/Xlib.h> #include <X11/Xlib.h>
extern Display *x11_dpy; extern Display *x11_dpy;
extern Window x11_window; extern Window x11_window;
extern int x11_font_width, x11_font_height;
#endif #endif


#endif /* __CACA_INTERNALS_H__ */ #endif /* __CACA_INTERNALS_H__ */

+ 4
- 2
src/graphics.c View File

@@ -81,13 +81,14 @@ static char *conio_screen;
#if defined(USE_X11) #if defined(USE_X11)
Display *x11_dpy; Display *x11_dpy;
Window x11_window; Window x11_window;
int x11_font_width, x11_font_height;
static GC x11_gc; static GC x11_gc;
static Pixmap x11_pixmap; static Pixmap x11_pixmap;
static int *x11_screen; static int *x11_screen;
static int x11_colors[16]; static int x11_colors[16];
static Font x11_font; static Font x11_font;
static XFontStruct *x11_font_struct; static XFontStruct *x11_font_struct;
static int x11_font_width, x11_font_height, x11_font_offset;
static int x11_font_offset;
#endif #endif


static char *_caca_empty_line; static char *_caca_empty_line;
@@ -604,7 +605,8 @@ int _caca_init_graphics(void)
break; break;
} }


XSelectInput(x11_dpy, x11_window, KeyPressMask);
XSelectInput(x11_dpy, x11_window,
KeyPressMask | ButtonPressMask | PointerMotionMask);


XSync(x11_dpy, False); XSync(x11_dpy, False);




+ 29
- 1
src/io.c View File

@@ -128,6 +128,11 @@ unsigned int caca_get_event(void)
} }
#endif #endif


/* If it's already a special event, return it */
if((keybuf[0] & ~0xff) != 0)
return _pop_key();

/* If it's not an escape sequence, return the key */
if(keybuf[0] != '\x1b') if(keybuf[0] != '\x1b')
return CACA_EVENT_KEY_PRESS | _pop_key(); return CACA_EVENT_KEY_PRESS | _pop_key();


@@ -247,6 +252,8 @@ static unsigned int _read_key(void)
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
XEvent event; XEvent event;
static int x11_x = 0, x11_y = 0;
long int event_mask = KeyPressMask | ButtonPressMask | PointerMotionMask;
char key; char key;
#endif #endif


@@ -267,11 +274,32 @@ static unsigned int _read_key(void)
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
case CACA_DRIVER_X11: case CACA_DRIVER_X11:
while(XCheckWindowEvent(x11_dpy, x11_window, KeyPressMask, &event)
while(XCheckWindowEvent(x11_dpy, x11_window, event_mask, &event)
== True) == True)
{ {
KeySym keysym; KeySym keysym;


if(event.type == MotionNotify)
{
x11_x = event.xmotion.x;
x11_y = event.xmotion.y;
continue;
}

if(event.type == ButtonPress)
{
unsigned int x = x11_x / x11_font_width;
unsigned int y = x11_y / x11_font_height;

if(x >= _caca_width)
x = _caca_width - 1;
if(y >= _caca_height)
y = _caca_height - 1;

return CACA_EVENT_MOUSE_CLICK
| (1 << 16) | (x << 8) | (y << 0);
}

if(event.type != KeyPress) if(event.type != KeyPress)
continue; continue;




Loading…
Cancel
Save