Changeset 273


Ignore:
Timestamp:
Dec 24, 2003, 4:35:07 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • src/io.c: + Mouse support in the X11 driver.
Location:
libcaca/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/caca_internals.h

    r268 r273  
    6868extern Display *x11_dpy;
    6969extern Window x11_window;
     70extern int x11_font_width, x11_font_height;
    7071#endif
    7172
  • libcaca/trunk/src/graphics.c

    r272 r273  
    8282Display *x11_dpy;
    8383Window x11_window;
     84int x11_font_width, x11_font_height;
    8485static GC x11_gc;
    8586static Pixmap x11_pixmap;
     
    8889static Font x11_font;
    8990static XFontStruct *x11_font_struct;
    90 static int x11_font_width, x11_font_height, x11_font_offset;
     91static int x11_font_offset;
    9192#endif
    9293
     
    605606        }
    606607
    607         XSelectInput(x11_dpy, x11_window, KeyPressMask);
     608        XSelectInput(x11_dpy, x11_window,
     609                     KeyPressMask | ButtonPressMask | PointerMotionMask);
    608610
    609611        XSync(x11_dpy, False);
  • libcaca/trunk/src/io.c

    r269 r273  
    129129#endif
    130130
     131    /* If it's already a special event, return it */
     132    if((keybuf[0] & ~0xff) != 0)
     133        return _pop_key();
     134
     135    /* If it's not an escape sequence, return the key */
    131136    if(keybuf[0] != '\x1b')
    132137        return CACA_EVENT_KEY_PRESS | _pop_key();
     
    248253#if defined(USE_X11)
    249254    XEvent event;
     255    static int x11_x = 0, x11_y = 0;
     256    long int event_mask = KeyPressMask | ButtonPressMask | PointerMotionMask;
    250257    char key;
    251258#endif
     
    268275#if defined(USE_X11)
    269276    case CACA_DRIVER_X11:
    270         while(XCheckWindowEvent(x11_dpy, x11_window, KeyPressMask, &event)
     277        while(XCheckWindowEvent(x11_dpy, x11_window, event_mask, &event)
    271278               == True)
    272279        {
    273280            KeySym keysym;
     281
     282            if(event.type == MotionNotify)
     283            {
     284                x11_x = event.xmotion.x;
     285                x11_y = event.xmotion.y;
     286                continue;
     287            }
     288
     289            if(event.type == ButtonPress)
     290            {
     291                unsigned int x = x11_x / x11_font_width;
     292                unsigned int y = x11_y / x11_font_height;
     293
     294                if(x >= _caca_width)
     295                    x = _caca_width - 1;
     296                if(y >= _caca_height)
     297                    y = _caca_height - 1;
     298
     299                return CACA_EVENT_MOUSE_CLICK
     300                        | (1 << 16) | (x << 8) | (y << 0);
     301            }
    274302
    275303            if(event.type != KeyPress)
Note: See TracChangeset for help on using the changeset viewer.