src/video/dga/SDL_dgaevents.c
changeset 0 74212992fb08
child 101 825b2fa28e2e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/dga/SDL_dgaevents.c	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,109 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* Handle the event stream, converting DGA events into SDL events */
    1.32 +
    1.33 +#include <stdio.h>
    1.34 +#include <X11/Xlib.h>
    1.35 +#include <X11/extensions/xf86dga.h>
    1.36 +
    1.37 +#include "SDL_sysvideo.h"
    1.38 +#include "SDL_events_c.h"
    1.39 +#include "SDL_dgavideo.h"
    1.40 +#include "SDL_dgaevents_c.h"
    1.41 +
    1.42 +/* Heheh we're using X11 event code */
    1.43 +extern int X11_Pending(Display *display);
    1.44 +extern void X11_InitKeymap(void);
    1.45 +extern SDL_keysym *X11_TranslateKey(Display *display, XKeyEvent *xkey,
    1.46 +				    KeyCode kc, SDL_keysym *keysym);
    1.47 +
    1.48 +static int DGA_DispatchEvent(_THIS)
    1.49 +{
    1.50 +	int posted;
    1.51 +	XDGAEvent xevent;
    1.52 +
    1.53 +	XNextEvent(DGA_Display, (XEvent *)&xevent);
    1.54 +
    1.55 +	posted = 0;
    1.56 +	xevent.type -= DGA_event_base;
    1.57 +	switch (xevent.type) {
    1.58 +
    1.59 +	    /* Mouse motion? */
    1.60 +	    case MotionNotify: {
    1.61 +		if ( SDL_VideoSurface ) {
    1.62 +			posted = SDL_PrivateMouseMotion(0, 1,
    1.63 +					xevent.xmotion.dx, xevent.xmotion.dy);
    1.64 +		}
    1.65 +	    }
    1.66 +	    break;
    1.67 +
    1.68 +	    /* Mouse button press? */
    1.69 +	    case ButtonPress: {
    1.70 +		posted = SDL_PrivateMouseButton(SDL_PRESSED, 
    1.71 +					xevent.xbutton.button, 0, 0);
    1.72 +	    }
    1.73 +	    break;
    1.74 +
    1.75 +	    /* Mouse button release? */
    1.76 +	    case ButtonRelease: {
    1.77 +		posted = SDL_PrivateMouseButton(SDL_RELEASED, 
    1.78 +					xevent.xbutton.button, 0, 0);
    1.79 +	    }
    1.80 +	    break;
    1.81 +
    1.82 +	    /* Key press or release? */
    1.83 +	    case KeyPress:
    1.84 +	    case KeyRelease: {
    1.85 +		SDL_keysym keysym;
    1.86 +		XKeyEvent xkey;
    1.87 +
    1.88 +		XDGAKeyEventToXKeyEvent(&xevent.xkey, &xkey);
    1.89 +		posted = SDL_PrivateKeyboard((xevent.type == KeyPress), 
    1.90 +					X11_TranslateKey(DGA_Display,
    1.91 +							 &xkey, xkey.keycode,
    1.92 +							 &keysym));
    1.93 +	    }
    1.94 +	    break;
    1.95 +
    1.96 +	}
    1.97 +	return(posted);
    1.98 +}
    1.99 +
   1.100 +void DGA_PumpEvents(_THIS)
   1.101 +{
   1.102 +	/* Keep processing pending events */
   1.103 +	while ( X11_Pending(DGA_Display) ) {
   1.104 +		DGA_DispatchEvent(this);
   1.105 +	}
   1.106 +}
   1.107 +
   1.108 +void DGA_InitOSKeymap(_THIS)
   1.109 +{
   1.110 +	X11_InitKeymap();
   1.111 +}
   1.112 +