Explorar el Código

* src/io.c:

+ Mouse support in the X11 driver.
tags/v0.99.beta14
Sam Hocevar sam hace 21 años
padre
commit
0d638c2e57
Se han modificado 3 ficheros con 34 adiciones y 3 borrados
  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 Ver fichero

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

#endif /* __CACA_INTERNALS_H__ */

+ 4
- 2
src/graphics.c Ver fichero

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

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

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

XSync(x11_dpy, False);



+ 29
- 1
src/io.c Ver fichero

@@ -128,6 +128,11 @@ unsigned int caca_get_event(void)
}
#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')
return CACA_EVENT_KEY_PRESS | _pop_key();

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

@@ -267,11 +274,32 @@ static unsigned int _read_key(void)
#endif
#if defined(USE_X11)
case CACA_DRIVER_X11:
while(XCheckWindowEvent(x11_dpy, x11_window, KeyPressMask, &event)
while(XCheckWindowEvent(x11_dpy, x11_window, event_mask, &event)
== True)
{
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)
continue;



Cargando…
Cancelar
Guardar