First shot at GTK+ video target for the OLPC laptops. Seriously incomplete, SDL-1.2-olpc
authorRyan C. Gordon <icculus@icculus.org>
Thu, 19 Apr 2007 07:12:30 +0000
branchSDL-1.2-olpc
changeset 4404b8de86ee2ad6
parent 4403 6b794fb2060d
child 4414 2e253188dcd2
First shot at GTK+ video target for the OLPC laptops. Seriously incomplete,
but it's enough to get some bits to a window...
configure.in
include/SDL_config.h.in
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/gtk/SDL_gtkevents.c
src/video/gtk/SDL_gtkevents_c.h
src/video/gtk/SDL_gtkmouse.c
src/video/gtk/SDL_gtkmouse_c.h
src/video/gtk/SDL_gtkvideo.c
src/video/gtk/SDL_gtkvideo.h
     1.1 --- a/configure.in	Thu Apr 19 07:10:05 2007 +0000
     1.2 +++ b/configure.in	Thu Apr 19 07:12:30 2007 +0000
     1.3 @@ -1347,6 +1347,35 @@
     1.4      fi
     1.5  }
     1.6  
     1.7 +dnl Find the GTK+ includes
     1.8 +CheckGTK()
     1.9 +{
    1.10 +    AC_ARG_ENABLE(video-gtk,
    1.11 +AC_HELP_STRING([--enable-video-gtk], [use GTK+ video driver [[default=no]]]),
    1.12 +                  , enable_video_gtk=no)
    1.13 +    if test x$enable_video = xyes -a x$enable_video_gtk = xyes; then
    1.14 +        AC_PATH_PROG(HAVEPKGCONFIG, pkg-config, $PATH)
    1.15 +        if test -z "$HAVEPKGCONFIG"; then
    1.16 +            AC_MSG_ERROR([*** pkg-config not found. Cannot probe for gtk+-2.0.])
    1.17 +        else
    1.18 +            AC_MSG_CHECKING(for GTK+ support)
    1.19 +            video_gtk=no
    1.20 +            $HAVEPKGCONFIG --exists gtk+-2.0
    1.21 +            if test $? -eq 0 ; then
    1.22 +                video_gtk=yes
    1.23 +                have_video=yes
    1.24 +                AC_DEFINE(SDL_VIDEO_DRIVER_GTK)
    1.25 +                SOURCES="$SOURCES $srcdir/src/video/gtk/*.c"
    1.26 +                GTK2_CFLAGS=`$HAVEPKGCONFIG --cflags libglade-2.0 gtk+-2.0`
    1.27 +                GTK2_LIBS=`$HAVEPKGCONFIG --libs libglade-2.0 gtk+-2.0`
    1.28 +                EXTRA_CFLAGS="$EXTRA_CFLAGS $GTK2_CFLAGS"
    1.29 +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS $GTK2_LIBS"
    1.30 +            fi
    1.31 +            AC_MSG_RESULT($video_gtk)
    1.32 +        fi
    1.33 +    fi
    1.34 +}
    1.35 +
    1.36  dnl Set up the QTopia video driver if enabled
    1.37  CheckQtopia()
    1.38  {
    1.39 @@ -2161,6 +2190,7 @@
    1.40          CheckVGL
    1.41          CheckWscons
    1.42          CheckAAlib
    1.43 +        CheckGTK
    1.44          CheckQtopia
    1.45          CheckPicoGUI
    1.46          CheckOpenGLX11
     2.1 --- a/include/SDL_config.h.in	Thu Apr 19 07:10:05 2007 +0000
     2.2 +++ b/include/SDL_config.h.in	Thu Apr 19 07:12:30 2007 +0000
     2.3 @@ -258,6 +258,7 @@
     2.4  #undef SDL_VIDEO_DRIVER_GAPI
     2.5  #undef SDL_VIDEO_DRIVER_GEM
     2.6  #undef SDL_VIDEO_DRIVER_GGI
     2.7 +#undef SDL_VIDEO_DRIVER_GTK
     2.8  #undef SDL_VIDEO_DRIVER_IPOD
     2.9  #undef SDL_VIDEO_DRIVER_NANOX
    2.10  #undef SDL_VIDEO_DRIVER_OS2FS
     3.1 --- a/src/video/SDL_sysvideo.h	Thu Apr 19 07:10:05 2007 +0000
     3.2 +++ b/src/video/SDL_sysvideo.h	Thu Apr 19 07:12:30 2007 +0000
     3.3 @@ -401,6 +401,9 @@
     3.4  #if SDL_VIDEO_DRIVER_AALIB
     3.5  extern VideoBootStrap AALIB_bootstrap;
     3.6  #endif
     3.7 +#if SDL_VIDEO_DRIVER_GTK
     3.8 +extern VideoBootStrap GTKPLUS_bootstrap;
     3.9 +#endif
    3.10  #if SDL_VIDEO_DRIVER_DUMMY
    3.11  extern VideoBootStrap DUMMY_bootstrap;
    3.12  #endif
     4.1 --- a/src/video/SDL_video.c	Thu Apr 19 07:10:05 2007 +0000
     4.2 +++ b/src/video/SDL_video.c	Thu Apr 19 07:12:30 2007 +0000
     4.3 @@ -117,6 +117,9 @@
     4.4  #if SDL_VIDEO_DRIVER_AALIB
     4.5  	&AALIB_bootstrap,
     4.6  #endif
     4.7 +#if SDL_VIDEO_DRIVER_GTK
     4.8 +	&GTKPLUS_bootstrap,
     4.9 +#endif
    4.10  #if SDL_VIDEO_DRIVER_DUMMY
    4.11  	&DUMMY_bootstrap,
    4.12  #endif
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/gtk/SDL_gtkevents.c	Thu Apr 19 07:12:30 2007 +0000
     5.3 @@ -0,0 +1,413 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#include "SDL.h"
    5.28 +#include "../../events/SDL_sysevents.h"
    5.29 +#include "../../events/SDL_events_c.h"
    5.30 +
    5.31 +#include "SDL_gtkvideo.h"
    5.32 +#include "SDL_gtkevents_c.h"
    5.33 +
    5.34 +#define DEBUG_GTKPLUS_EVENTS 0
    5.35 +#if DEBUG_GTKPLUS_EVENTS
    5.36 +#define DEBUG_GTKPLUS_SIGNAL() printf("GTK+: %s\n", __FUNCTION__)
    5.37 +#else
    5.38 +#define DEBUG_GTKPLUS_SIGNAL()
    5.39 +#endif
    5.40 +
    5.41 +static gboolean
    5.42 +signal_enter_notify(GtkWidget *w, GdkEventCrossing *evt, gpointer data)
    5.43 +{
    5.44 +    SET_THIS_POINTER(data);
    5.45 +    DEBUG_GTKPLUS_SIGNAL();
    5.46 +    if ( (evt->mode != GDK_CROSSING_GRAB) &&
    5.47 +         (evt->mode != GDK_CROSSING_UNGRAB) ) {
    5.48 +        if ( this->input_grab == SDL_GRAB_OFF ) {
    5.49 +            SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    5.50 +        }
    5.51 +        SDL_PrivateMouseMotion(0, 0, evt->x, evt->y);
    5.52 +	}
    5.53 +
    5.54 +    return FALSE;  /* don't eat event, in case app connected a handler. */
    5.55 +}
    5.56 +
    5.57 +
    5.58 +static gboolean
    5.59 +signal_leave_notify(GtkWidget *w, GdkEventCrossing *evt, gpointer data)
    5.60 +{
    5.61 +    SET_THIS_POINTER(data);
    5.62 +    DEBUG_GTKPLUS_SIGNAL();
    5.63 +    if ( (evt->mode != GDK_CROSSING_GRAB) &&
    5.64 +         (evt->mode != GDK_CROSSING_UNGRAB) &&
    5.65 +         (evt->detail != GDK_NOTIFY_INFERIOR) ) {
    5.66 +        if ( this->input_grab == SDL_GRAB_OFF ) {
    5.67 +            SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    5.68 +        } else {
    5.69 +            SDL_PrivateMouseMotion(0, 0, evt->x, evt->y);
    5.70 +        }
    5.71 +    }
    5.72 +    return FALSE;  /* don't eat event, in case app connected a handler. */
    5.73 +}
    5.74 +
    5.75 +
    5.76 +static gboolean
    5.77 +signal_focus_in(GtkWidget *w, GdkEventFocus *evt, gpointer data)
    5.78 +{
    5.79 +    DEBUG_GTKPLUS_SIGNAL();
    5.80 +    SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
    5.81 +    return FALSE;  /* don't eat event, in case app connected a handler. */
    5.82 +}
    5.83 +
    5.84 +
    5.85 +static gboolean
    5.86 +signal_focus_out(GtkWidget *w, GdkEventFocus *evt, gpointer data)
    5.87 +{
    5.88 +    DEBUG_GTKPLUS_SIGNAL();
    5.89 +    SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
    5.90 +    return FALSE;  /* don't eat event, in case app connected a handler. */
    5.91 +}
    5.92 +
    5.93 +
    5.94 +#if 0
    5.95 +	    /* Generated upon EnterWindow and FocusIn */
    5.96 +	    case KeymapNotify: {
    5.97 +#ifdef DEBUG_XEVENTS
    5.98 +printf("KeymapNotify!\n");
    5.99 +#endif
   5.100 +		X11_SetKeyboardState(SDL_Display,  xevent.xkeymap.key_vector);
   5.101 +	    }
   5.102 +	    break;
   5.103 +#endif
   5.104 +
   5.105 +
   5.106 +static gboolean
   5.107 +signal_motion_notify(GtkWidget *w, GdkEventMotion *evt, gpointer data)
   5.108 +{
   5.109 +    SET_THIS_POINTER(data);
   5.110 +    DEBUG_GTKPLUS_SIGNAL();
   5.111 +    if ( SDL_VideoSurface ) {
   5.112 +        if ( 0 /* !!! FIXME mouse_relative */ ) {
   5.113 +            SDLGTK_WarpedMotion(this, evt);
   5.114 +        } else {
   5.115 +            SDL_PrivateMouseMotion(0, 0, evt->x, evt->y);
   5.116 +        }
   5.117 +    }
   5.118 +
   5.119 +    return FALSE;  /* don't eat event, in case app connected a handler. */
   5.120 +}
   5.121 +
   5.122 +
   5.123 +static gboolean
   5.124 +signal_button_press(GtkWidget *w, GdkEventButton *evt, gpointer data)
   5.125 +{
   5.126 +    DEBUG_GTKPLUS_SIGNAL();
   5.127 +    SDL_PrivateMouseButton(SDL_PRESSED, evt->button, 0, 0);
   5.128 +    return FALSE;  /* don't eat event, in case app connected a handler. */
   5.129 +}
   5.130 +
   5.131 +static gboolean
   5.132 +signal_button_release(GtkWidget *w, GdkEventButton *evt, gpointer data)
   5.133 +{
   5.134 +    DEBUG_GTKPLUS_SIGNAL();
   5.135 +    SDL_PrivateMouseButton(SDL_RELEASED, evt->button, 0, 0);
   5.136 +    return FALSE;  /* don't eat event, in case app connected a handler. */
   5.137 +}
   5.138 +
   5.139 +static gboolean
   5.140 +signal_expose(GtkWidget *w, GdkEventExpose *evt, gpointer data)
   5.141 +{
   5.142 +    SET_THIS_POINTER(data);
   5.143 +    const GdkRectangle *area = &evt->area;
   5.144 +    SDL_Rect r = { area->x, area->y, area->width, area->height };
   5.145 +    DEBUG_GTKPLUS_SIGNAL();
   5.146 +    this->UpdateRects(this, 1, &r);
   5.147 +    return FALSE;  /* don't eat event, in case app connected a handler. */
   5.148 +}
   5.149 +
   5.150 +
   5.151 +static gboolean
   5.152 +signal_delete(GtkWidget *w, GdkEvent *evt, gpointer data)
   5.153 +{
   5.154 +    DEBUG_GTKPLUS_SIGNAL();
   5.155 +    SDL_PrivateQuit();
   5.156 +    return TRUE;  /* eat event: default handler destroys window! */
   5.157 +}
   5.158 +
   5.159 +
   5.160 +void GTKPLUS_ConnectSignals(_THIS)
   5.161 +{
   5.162 +    gtk_widget_set_events( this->hidden->gtkdrawingarea,
   5.163 +                           GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK |
   5.164 +                           GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
   5.165 +                           GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
   5.166 +                           GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK );
   5.167 +
   5.168 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkwindow),
   5.169 +                       "delete-event",
   5.170 +                       GTK_SIGNAL_FUNC(signal_delete), this);
   5.171 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkdrawingarea),
   5.172 +                       "enter-notify-event",
   5.173 +                       GTK_SIGNAL_FUNC(signal_enter_notify), this);
   5.174 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkdrawingarea),
   5.175 +                       "leave-notify-event",
   5.176 +                       GTK_SIGNAL_FUNC(signal_leave_notify), this);
   5.177 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkwindow),
   5.178 +                       "focus-in-event",
   5.179 +                       GTK_SIGNAL_FUNC(signal_focus_in), this);
   5.180 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkwindow),
   5.181 +                       "focus-out-event",
   5.182 +                       GTK_SIGNAL_FUNC(signal_focus_out), this);
   5.183 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkdrawingarea),
   5.184 +                       "motion-notify-event",
   5.185 +                       GTK_SIGNAL_FUNC(signal_motion_notify), this);
   5.186 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkdrawingarea),
   5.187 +                       "button-press-event",
   5.188 +                       GTK_SIGNAL_FUNC(signal_button_press), this);
   5.189 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkdrawingarea),
   5.190 +                       "button-release-event",
   5.191 +                       GTK_SIGNAL_FUNC(signal_button_release), this);
   5.192 +    gtk_signal_connect(GTK_OBJECT(this->hidden->gtkdrawingarea),
   5.193 +                       "expose-event", GTK_SIGNAL_FUNC(signal_expose), this);
   5.194 +    /* !!! FIXME: more to connect here. */
   5.195 +}
   5.196 +
   5.197 +
   5.198 +
   5.199 +/* !!! FIXME: more to connect here. */
   5.200 +#if 0
   5.201 +	    /* Key press? */
   5.202 +	    case KeyPress: {
   5.203 +		static SDL_keysym saved_keysym;
   5.204 +		SDL_keysym keysym;
   5.205 +		KeyCode keycode = xevent.xkey.keycode;
   5.206 +
   5.207 +#ifdef DEBUG_XEVENTS
   5.208 +printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
   5.209 +#endif
   5.210 +		/* Get the translated SDL virtual keysym */
   5.211 +		if ( keycode ) {
   5.212 +			keysym.scancode = keycode;
   5.213 +			keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
   5.214 +			keysym.mod = KMOD_NONE;
   5.215 +			keysym.unicode = 0;
   5.216 +		} else {
   5.217 +			keysym = saved_keysym;
   5.218 +		}
   5.219 +
   5.220 +		/* If we're not doing translation, we're done! */
   5.221 +		if ( !SDL_TranslateUNICODE ) {
   5.222 +			posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   5.223 +			break;
   5.224 +		}
   5.225 +
   5.226 +		if ( XFilterEvent(&xevent, None) ) {
   5.227 +			if ( xevent.xkey.keycode ) {
   5.228 +				posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   5.229 +			} else {
   5.230 +				/* Save event to be associated with IM text
   5.231 +				   In 1.3 we'll have a text event instead.. */
   5.232 +				saved_keysym = keysym;
   5.233 +			}
   5.234 +			break;
   5.235 +		}
   5.236 +
   5.237 +		/* Look up the translated value for the key event */
   5.238 +#ifdef X_HAVE_UTF8_STRING
   5.239 +		if ( SDL_IC != NULL ) {
   5.240 +			static Status state;
   5.241 +			/* A UTF-8 character can be at most 6 bytes */
   5.242 +			char keybuf[6];
   5.243 +			if ( Xutf8LookupString(SDL_IC, &xevent.xkey,
   5.244 +			                        keybuf, sizeof(keybuf),
   5.245 +			                        NULL, &state) ) {
   5.246 +				keysym.unicode = Utf8ToUcs4((Uint8*)keybuf);
   5.247 +			}
   5.248 +		}
   5.249 +		else
   5.250 +#endif
   5.251 +		{
   5.252 +			static XComposeStatus state;
   5.253 +			char keybuf[32];
   5.254 +
   5.255 +			if ( XLookupString(&xevent.xkey,
   5.256 +			                    keybuf, sizeof(keybuf),
   5.257 +			                    NULL, &state) ) {
   5.258 +				/*
   5.259 +				* FIXME: XLookupString() may yield more than one
   5.260 +				* character, so we need a mechanism to allow for
   5.261 +				* this (perhaps null keypress events with a
   5.262 +				* unicode value)
   5.263 +				*/
   5.264 +				keysym.unicode = (Uint8)keybuf[0];
   5.265 +			}
   5.266 +		}
   5.267 +		posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   5.268 +	    }
   5.269 +	    break;
   5.270 +
   5.271 +	    /* Key release? */
   5.272 +	    case KeyRelease: {
   5.273 +		SDL_keysym keysym;
   5.274 +		KeyCode keycode = xevent.xkey.keycode;
   5.275 +
   5.276 +#ifdef DEBUG_XEVENTS
   5.277 +printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
   5.278 +#endif
   5.279 +		/* Check to see if this is a repeated key */
   5.280 +		if ( X11_KeyRepeat(SDL_Display, &xevent) ) {
   5.281 +			break;
   5.282 +		}
   5.283 +
   5.284 +		/* Get the translated SDL virtual keysym */
   5.285 +		keysym.scancode = keycode;
   5.286 +		keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
   5.287 +		keysym.mod = KMOD_NONE;
   5.288 +		keysym.unicode = 0;
   5.289 +
   5.290 +		posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   5.291 +	    }
   5.292 +	    break;
   5.293 +
   5.294 +	    /* Have we been iconified? */
   5.295 +	    case UnmapNotify: {
   5.296 +#ifdef DEBUG_XEVENTS
   5.297 +printf("UnmapNotify!\n");
   5.298 +#endif
   5.299 +		/* If we're active, make ourselves inactive */
   5.300 +		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
   5.301 +			/* Swap out the gamma before we go inactive */
   5.302 +			X11_SwapVidModeGamma(this);
   5.303 +
   5.304 +			/* Send an internal deactivate event */
   5.305 +			posted = SDL_PrivateAppActive(0,
   5.306 +					SDL_APPACTIVE|SDL_APPINPUTFOCUS);
   5.307 +		}
   5.308 +	    }
   5.309 +	    break;
   5.310 +
   5.311 +	    /* Have we been restored? */
   5.312 +	    case MapNotify: {
   5.313 +#ifdef DEBUG_XEVENTS
   5.314 +printf("MapNotify!\n");
   5.315 +#endif
   5.316 +		/* If we're not active, make ourselves active */
   5.317 +		if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
   5.318 +			/* Send an internal activate event */
   5.319 +			posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);
   5.320 +
   5.321 +			/* Now that we're active, swap the gamma back */
   5.322 +			X11_SwapVidModeGamma(this);
   5.323 +		}
   5.324 +
   5.325 +		if ( SDL_VideoSurface &&
   5.326 +		     (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
   5.327 +			X11_EnterFullScreen(this);
   5.328 +		} else {
   5.329 +			X11_GrabInputNoLock(this, this->input_grab);
   5.330 +		}
   5.331 +		X11_CheckMouseModeNoLock(this);
   5.332 +
   5.333 +		if ( SDL_VideoSurface ) {
   5.334 +			X11_RefreshDisplay(this);
   5.335 +		}
   5.336 +	    }
   5.337 +	    break;
   5.338 +
   5.339 +	    /* Have we been resized or moved? */
   5.340 +	    case ConfigureNotify: {
   5.341 +#ifdef DEBUG_XEVENTS
   5.342 +printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
   5.343 +#endif
   5.344 +		if ( SDL_VideoSurface ) {
   5.345 +		    if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
   5.346 +		        (xevent.xconfigure.height != SDL_VideoSurface->h)) {
   5.347 +			/* FIXME: Find a better fix for the bug with KDE 1.2 */
   5.348 +			if ( ! ((xevent.xconfigure.width == 32) &&
   5.349 +			        (xevent.xconfigure.height == 32)) ) {
   5.350 +				SDL_PrivateResize(xevent.xconfigure.width,
   5.351 +				                  xevent.xconfigure.height);
   5.352 +			}
   5.353 +		    } else {
   5.354 +			/* OpenGL windows need to know about the change */
   5.355 +			if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
   5.356 +				SDL_PrivateExpose();
   5.357 +			}
   5.358 +		    }
   5.359 +		}
   5.360 +	    }
   5.361 +	    break;
   5.362 +
   5.363 +	    /* Have we been requested to quit (or another client message?) */
   5.364 +	    case ClientMessage: {
   5.365 +		if ( (xevent.xclient.format == 32) &&
   5.366 +		     (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) )
   5.367 +		{
   5.368 +			posted = SDL_PrivateQuit();
   5.369 +		} else
   5.370 +		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
   5.371 +			SDL_SysWMmsg wmmsg;
   5.372 +
   5.373 +			SDL_VERSION(&wmmsg.version);
   5.374 +			wmmsg.subsystem = SDL_SYSWM_X11;
   5.375 +			wmmsg.event.xevent = xevent;
   5.376 +			posted = SDL_PrivateSysWMEvent(&wmmsg);
   5.377 +		}
   5.378 +	    }
   5.379 +	    break;
   5.380 +
   5.381 +
   5.382 +
   5.383 +	    default: {
   5.384 +#ifdef DEBUG_XEVENTS
   5.385 +printf("Unhandled event %d\n", xevent.type);
   5.386 +#endif
   5.387 +		/* Only post the event if we're watching for it */
   5.388 +		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
   5.389 +			SDL_SysWMmsg wmmsg;
   5.390 +
   5.391 +			SDL_VERSION(&wmmsg.version);
   5.392 +			wmmsg.subsystem = SDL_SYSWM_X11;
   5.393 +			wmmsg.event.xevent = xevent;
   5.394 +			posted = SDL_PrivateSysWMEvent(&wmmsg);
   5.395 +		}
   5.396 +	    }
   5.397 +	    break;
   5.398 +	}
   5.399 +#endif
   5.400 +
   5.401 +
   5.402 +
   5.403 +void GTKPLUS_PumpEvents(_THIS)
   5.404 +{
   5.405 +    while (gtk_events_pending())
   5.406 +	    gtk_main_iteration();
   5.407 +}
   5.408 +
   5.409 +void GTKPLUS_InitOSKeymap(_THIS)
   5.410 +{
   5.411 +    /* !!! FIXME */
   5.412 +	/* do nothing. */
   5.413 +}
   5.414 +
   5.415 +/* end of SDL_gtkevents.c ... */
   5.416 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/gtk/SDL_gtkevents_c.h	Thu Apr 19 07:12:30 2007 +0000
     6.3 @@ -0,0 +1,34 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997-2006 Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Lesser General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2.1 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Lesser General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Lesser General Public
    6.19 +    License along with this library; if not, write to the Free Software
    6.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@libsdl.org
    6.24 +*/
    6.25 +#include "SDL_config.h"
    6.26 +
    6.27 +#include "SDL_gtkvideo.h"
    6.28 +
    6.29 +/* Variables and functions exported by SDL_sysevents.c to other parts 
    6.30 +   of the native video subsystem (SDL_sysvideo.c)
    6.31 +*/
    6.32 +extern void GTKPLUS_InitOSKeymap(_THIS);
    6.33 +extern void GTKPLUS_PumpEvents(_THIS);
    6.34 +extern void GTKPLUS_ConnectSignals(_THIS);
    6.35 +
    6.36 +/* end of SDL_gtkevents_c.h ... */
    6.37 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/gtk/SDL_gtkmouse.c	Thu Apr 19 07:12:30 2007 +0000
     7.3 @@ -0,0 +1,33 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2006 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Lesser General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2.1 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Lesser General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Lesser General Public
    7.19 +    License along with this library; if not, write to the Free Software
    7.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +#include "SDL_config.h"
    7.26 +
    7.27 +#include "SDL_mouse.h"
    7.28 +#include "../../events/SDL_events_c.h"
    7.29 +
    7.30 +#include "SDL_gtkmouse_c.h"
    7.31 +
    7.32 +
    7.33 +/* The implementation dependent data for the window manager cursor */
    7.34 +struct WMcursor {
    7.35 +	int unused;
    7.36 +};
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/gtk/SDL_gtkmouse_c.h	Thu Apr 19 07:12:30 2007 +0000
     8.3 @@ -0,0 +1,26 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2006 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#include "SDL_gtkvideo.h"
    8.28 +
    8.29 +/* Functions to be exported */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/gtk/SDL_gtkvideo.c	Thu Apr 19 07:12:30 2007 +0000
     9.3 @@ -0,0 +1,643 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2006 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +/*
    9.28 + * GTK+ SDL video driver implementation; this is a little like a pared-down
    9.29 + *  version of the X11 driver. You almost certainly do NOT want this target
    9.30 + *  on a desktop machine. This was written for the One Laptop Per Child
    9.31 + *  project so they wouldn't need to use the SDL_WINDOWID hack with the X11
    9.32 + *  driver and compete for the event queue.
    9.33 + *
    9.34 + * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
    9.35 + *  of this was cut-and-pasted from the dummy video target just to have a
    9.36 + *  starting point for the bare minimum to fill in, and some was lifted from
    9.37 + *  the x11 target.
    9.38 + */
    9.39 +
    9.40 +#include "SDL_video.h"
    9.41 +#include "SDL_mouse.h"
    9.42 +#include "../SDL_sysvideo.h"
    9.43 +#include "../SDL_pixels_c.h"
    9.44 +#include "../../events/SDL_events_c.h"
    9.45 +
    9.46 +#include "SDL_gtkvideo.h"
    9.47 +#include "SDL_gtkevents_c.h"
    9.48 +#include "SDL_gtkmouse_c.h"
    9.49 +
    9.50 +#define GTKPLUSVID_DRIVER_NAME "gtk"
    9.51 +
    9.52 +/* Initialization/Query functions */
    9.53 +static int GTKPLUS_VideoInit(_THIS, SDL_PixelFormat *vformat);
    9.54 +static SDL_Rect **GTKPLUS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
    9.55 +static SDL_Surface *GTKPLUS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    9.56 +static int GTKPLUS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
    9.57 +static void GTKPLUS_VideoQuit(_THIS);
    9.58 +
    9.59 +/* Hardware surface functions */
    9.60 +static int GTKPLUS_AllocHWSurface(_THIS, SDL_Surface *surface);
    9.61 +static int GTKPLUS_LockHWSurface(_THIS, SDL_Surface *surface);
    9.62 +static void GTKPLUS_UnlockHWSurface(_THIS, SDL_Surface *surface);
    9.63 +static void GTKPLUS_FreeHWSurface(_THIS, SDL_Surface *surface);
    9.64 +static void GTKPLUS_SetCaption(_THIS, const char *title, const char *icon);
    9.65 +
    9.66 +/* etc. */
    9.67 +static void GTKPLUS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
    9.68 +
    9.69 +/* GTKPLUS driver bootstrap functions */
    9.70 +
    9.71 +static int do_gtk_init(void)
    9.72 +{
    9.73 +    static int initted = 0;
    9.74 +    if (!initted) {   /* !!! FIXME: I can't see a way to deinit gtk... */
    9.75 +        int tmpargc = 0;
    9.76 +        char *args[] = { NULL, NULL };
    9.77 +        char **tmpargv = args;
    9.78 +        initted = (gtk_init_check(&tmpargc, &tmpargv));
    9.79 +    }
    9.80 +    return initted;
    9.81 +}
    9.82 +
    9.83 +
    9.84 +static int GTKPLUS_Available(void)
    9.85 +{
    9.86 +    return 1;  /* !!! FIXME */
    9.87 +}
    9.88 +
    9.89 +static void GTKPLUS_DeleteDevice(SDL_VideoDevice *device)
    9.90 +{
    9.91 +	SDL_free(device->hidden);
    9.92 +	SDL_free(device);
    9.93 +}
    9.94 +
    9.95 +static SDL_VideoDevice *GTKPLUS_CreateDevice(int devindex)
    9.96 +{
    9.97 +	SDL_VideoDevice *device;
    9.98 +
    9.99 +	/* Initialize all variables that we clean on shutdown */
   9.100 +	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
   9.101 +	if ( device ) {
   9.102 +		SDL_memset(device, 0, (sizeof *device));
   9.103 +		device->hidden = (struct SDL_PrivateVideoData *)
   9.104 +				SDL_malloc((sizeof *device->hidden));
   9.105 +	}
   9.106 +	if ( (device == NULL) || (device->hidden == NULL) ) {
   9.107 +		SDL_OutOfMemory();
   9.108 +		if ( device ) {
   9.109 +			SDL_free(device);
   9.110 +		}
   9.111 +		return(0);
   9.112 +	}
   9.113 +	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
   9.114 +
   9.115 +    device->handles_any_size = 1;
   9.116 +
   9.117 +	/* Set the function pointers */
   9.118 +	device->VideoInit = GTKPLUS_VideoInit;
   9.119 +	device->ListModes = GTKPLUS_ListModes;
   9.120 +	device->SetVideoMode = GTKPLUS_SetVideoMode;
   9.121 +	device->CreateYUVOverlay = NULL;
   9.122 +	device->SetColors = GTKPLUS_SetColors;
   9.123 +	device->UpdateRects = GTKPLUS_UpdateRects;
   9.124 +	device->VideoQuit = GTKPLUS_VideoQuit;
   9.125 +	device->AllocHWSurface = GTKPLUS_AllocHWSurface;
   9.126 +	device->CheckHWBlit = NULL;
   9.127 +	device->FillHWRect = NULL;
   9.128 +	device->SetHWColorKey = NULL;
   9.129 +	device->SetHWAlpha = NULL;
   9.130 +	device->LockHWSurface = GTKPLUS_LockHWSurface;
   9.131 +	device->UnlockHWSurface = GTKPLUS_UnlockHWSurface;
   9.132 +	device->FlipHWSurface = NULL;
   9.133 +	device->FreeHWSurface = GTKPLUS_FreeHWSurface;
   9.134 +	device->SetCaption = GTKPLUS_SetCaption;
   9.135 +	device->SetIcon = NULL;
   9.136 +	device->IconifyWindow = NULL;
   9.137 +	device->GrabInput = NULL;
   9.138 +	device->GetWMInfo = NULL;
   9.139 +	device->InitOSKeymap = GTKPLUS_InitOSKeymap;
   9.140 +	device->PumpEvents = GTKPLUS_PumpEvents;
   9.141 +
   9.142 +	device->free = GTKPLUS_DeleteDevice;
   9.143 +
   9.144 +	return device;
   9.145 +}
   9.146 +
   9.147 +VideoBootStrap GTKPLUS_bootstrap = {
   9.148 +	GTKPLUSVID_DRIVER_NAME, "SDL GTK+ video driver",
   9.149 +	GTKPLUS_Available, GTKPLUS_CreateDevice
   9.150 +};
   9.151 +
   9.152 +
   9.153 +static int add_visual(_THIS, int depth, GdkVisualType vistype)
   9.154 +{
   9.155 +    GdkVisual *vi = gdk_visual_get_best_with_both(depth, vistype);
   9.156 +    if(vi != NULL) {
   9.157 +        g_object_ref(vi);
   9.158 +        this->hidden->visuals[this->hidden->nvisuals++] = vi;
   9.159 +    }
   9.160 +    return(this->hidden->nvisuals);
   9.161 +}
   9.162 +
   9.163 +static int GTKPLUS_GetVideoModes(_THIS)
   9.164 +{
   9.165 +    const gint screen_w = gdk_screen_width();
   9.166 +    const gint screen_h = gdk_screen_height();
   9.167 +    int i, n;
   9.168 +
   9.169 +    {
   9.170 +	/* It's interesting to note that if we allow 32 bit depths (on X11),
   9.171 +	   we get a visual with an alpha mask on composite servers.
   9.172 +        static int depth_list[] = { 32, 24, 16, 15, 8 };
   9.173 +	*/
   9.174 +        static int depth_list[] = { 24, 16, 15, 8 };
   9.175 +        int use_directcolor = 1;
   9.176 +
   9.177 +        /* Search for the visuals in deepest-first order, so that the first
   9.178 +           will be the richest one */
   9.179 +        if ( SDL_getenv("SDL_VIDEO_GTK_NODIRECTCOLOR") ) {
   9.180 +                use_directcolor = 0;
   9.181 +        }
   9.182 +        this->hidden->nvisuals = 0;
   9.183 +        for ( i=0; i<SDL_arraysize(depth_list); ++i ) {
   9.184 +            if ( depth_list[i] > 8 ) {
   9.185 +                if ( use_directcolor ) {
   9.186 +                    add_visual(this, depth_list[i], GDK_VISUAL_DIRECT_COLOR);
   9.187 +                }
   9.188 +                add_visual(this, depth_list[i], GDK_VISUAL_TRUE_COLOR);
   9.189 +            } else {
   9.190 +                add_visual(this, depth_list[i], GDK_VISUAL_PSEUDO_COLOR);
   9.191 +                add_visual(this, depth_list[i], GDK_VISUAL_STATIC_COLOR);
   9.192 +            }
   9.193 +        }
   9.194 +        if ( this->hidden->nvisuals == 0 ) {
   9.195 +            SDL_SetError("Found no sufficiently capable GTK+ visuals");
   9.196 +            return -1;
   9.197 +        }
   9.198 +    }
   9.199 +
   9.200 +    return 0;
   9.201 +}
   9.202 +
   9.203 +
   9.204 +int GTKPLUS_VideoInit(_THIS, SDL_PixelFormat *vformat)
   9.205 +{
   9.206 +    GdkVisual *sysvis = NULL;
   9.207 +    int i;
   9.208 +
   9.209 +    if (!do_gtk_init()) {
   9.210 +        return -1;
   9.211 +    }
   9.212 +
   9.213 +	/* Get the available video modes */
   9.214 +	if(GTKPLUS_GetVideoModes(this) < 0)
   9.215 +	    return -1;
   9.216 +
   9.217 +	/* Determine the current screen size */
   9.218 +	this->info.current_w = gdk_screen_width();
   9.219 +	this->info.current_h = gdk_screen_height();
   9.220 +
   9.221 +	/* Determine the default screen depth:
   9.222 +	   Use the default visual (or at least one with the same depth) */
   9.223 +	this->hidden->display_colormap = gdk_colormap_get_system();  /* !!! FIXME: refcount? */
   9.224 +    sysvis = gdk_visual_get_system();  /* !!! FIXME: refcount? */
   9.225 +
   9.226 +    for(i = 0; i < this->hidden->nvisuals; i++) {
   9.227 +        if(this->hidden->visuals[i]->depth == sysvis->depth)
   9.228 +            break;
   9.229 +    }
   9.230 +
   9.231 +	if(i == this->hidden->nvisuals) {
   9.232 +	    /* default visual was useless, take the deepest one instead */
   9.233 +	    i = 0;
   9.234 +	}
   9.235 +
   9.236 +	this->hidden->visual = this->hidden->visuals[i];
   9.237 +	if ( this->hidden->visual == sysvis ) {  /* !!! FIXME: same pointer? */
   9.238 +	    this->hidden->colormap = this->hidden->display_colormap;
   9.239 +        g_object_ref(this->hidden->colormap);
   9.240 +	} else {
   9.241 +	    this->hidden->colormap = gdk_colormap_new(this->hidden->visual, FALSE);
   9.242 +	}
   9.243 +
   9.244 +    // !!! FIXME: this is not a public GDK symbol!!
   9.245 +	vformat->BitsPerPixel = _gdk_windowing_get_bits_for_depth(
   9.246 +                                gdk_display_get_default(),
   9.247 +                                this->hidden->visuals[i]->depth);
   9.248 +	this->hidden->depth = vformat->BitsPerPixel;
   9.249 +
   9.250 +	if ( vformat->BitsPerPixel > 8 ) {
   9.251 +		vformat->Rmask = this->hidden->visual->red_mask;
   9.252 +	  	vformat->Gmask = this->hidden->visual->green_mask;
   9.253 +	  	vformat->Bmask = this->hidden->visual->blue_mask;
   9.254 +	}
   9.255 +	if ( this->hidden->depth == 32 ) {
   9.256 +		vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask));
   9.257 +	}
   9.258 +
   9.259 +#if 0
   9.260 +	/* Create the fullscreen and managed windows */
   9.261 +	create_aux_windows(this);
   9.262 +
   9.263 +	/* Create the blank cursor */
   9.264 +	SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
   9.265 +					BLANK_CWIDTH, BLANK_CHEIGHT,
   9.266 +						BLANK_CHOTX, BLANK_CHOTY);
   9.267 +
   9.268 +	/* Allow environment override of screensaver disable. */
   9.269 +	env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
   9.270 +	this->hidden->allow_screensaver = ( (env && SDL_atoi(env)) ? 1 : 0 );
   9.271 +#endif
   9.272 +
   9.273 +	/* We're done! */
   9.274 +	gdk_flush();  /* just in case. */
   9.275 +
   9.276 +	/* Fill in some window manager capabilities */
   9.277 +	this->info.wm_available = 1;
   9.278 +
   9.279 +	return(0);
   9.280 +}
   9.281 +
   9.282 +
   9.283 +static GdkVisual *find_visual(_THIS, int bpp)
   9.284 +{
   9.285 +    GdkDisplay *display = gdk_display_get_default();
   9.286 +    int i;
   9.287 +    for ( i = 0; i < this->hidden->nvisuals; i++ ) {
   9.288 +        const int videpth = this->hidden->visuals[i]->depth;
   9.289 +        // !!! FIXME: this is not a public GDK symbol!!
   9.290 +        const int depth = _gdk_windowing_get_bits_for_depth(display, videpth);
   9.291 +        if ( depth == bpp )
   9.292 +            break;
   9.293 +    }
   9.294 +
   9.295 +    if ( i == this->hidden->nvisuals ) {
   9.296 +        SDL_SetError("No matching visual for requested depth");
   9.297 +        return NULL;  /* should never happen */
   9.298 +    }
   9.299 +    return this->hidden->visuals[i];
   9.300 +}
   9.301 +
   9.302 +
   9.303 +SDL_Rect **GTKPLUS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   9.304 +{
   9.305 +    if ((flags & SDL_OPENGL) == 0) {
   9.306 +        if (find_visual(this, format->BitsPerPixel) != NULL) {
   9.307 +       	    return (SDL_Rect **) -1;  /* !!! FIXME: maybe not right. */
   9.308 +        }
   9.309 +    }
   9.310 +    return NULL;  /* unsupported. */
   9.311 +}
   9.312 +
   9.313 +
   9.314 +SDL_Surface *GTKPLUS_SetVideoMode(_THIS, SDL_Surface *current,
   9.315 +				int width, int height, int bpp, Uint32 flags)
   9.316 +{
   9.317 +    Uint32 Amask = 0;
   9.318 +    int vis_change = 0;
   9.319 +    GtkWindow *win = NULL;
   9.320 +    GdkImage *img = NULL;
   9.321 +    GdkVisual *sysvis = gdk_visual_get_system();  /* !!! FIXME: refcount? */
   9.322 +    GdkVisual *vis = find_visual(this, bpp);
   9.323 +    if (vis == NULL) {
   9.324 +		return(NULL);
   9.325 +	}
   9.326 +
   9.327 +    if (flags & SDL_OPENGL) {
   9.328 +		SDL_SetError("No OpenGL support in the GTK+ target");
   9.329 +		return(NULL);
   9.330 +	}
   9.331 +
   9.332 +    /* These are the only flags we allow here... */
   9.333 +    flags &= /*SDL_FULLSCREEN |*/ SDL_RESIZABLE | SDL_NOFRAME | SDL_HWPALETTE;
   9.334 +
   9.335 +	vis_change = (vis != this->hidden->visual);
   9.336 +	this->hidden->visual = vis;
   9.337 +	this->hidden->depth = vis->depth;
   9.338 +
   9.339 +	/* Allocate the new pixel format for this video mode */
   9.340 +	if ( this->hidden->depth == 32 ) {
   9.341 +		Amask = (0xFFFFFFFF & ~(vis->red_mask|vis->green_mask|vis->blue_mask));
   9.342 +	} else {
   9.343 +		Amask = 0;
   9.344 +	}
   9.345 +	if ( ! SDL_ReallocFormat(current, bpp,
   9.346 +			vis->red_mask, vis->green_mask, vis->blue_mask, Amask) ) {
   9.347 +		return NULL;
   9.348 +	}
   9.349 +
   9.350 +	/* Create the appropriate colormap */
   9.351 +	g_object_unref(this->hidden->colormap);
   9.352 +    this->hidden->colormap = NULL;
   9.353 +
   9.354 +	if ( this->hidden->visual->type == GDK_VISUAL_PSEUDO_COLOR ) {
   9.355 +	    int ncolors;
   9.356 +
   9.357 +	    /* Allocate the pixel flags */
   9.358 +	    ncolors = this->hidden->visual->colormap_size;
   9.359 +
   9.360 +	    #if 0
   9.361 +        SDL_XPixels = SDL_malloc(ncolors * sizeof(int));
   9.362 +	    if(SDL_XPixels == NULL) {
   9.363 +            SDL_OutOfMemory();
   9.364 +            return -1;
   9.365 +	    }
   9.366 +	    SDL_memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels));
   9.367 +        #endif
   9.368 +
   9.369 +	    /* always allocate a private colormap on non-default visuals */
   9.370 +	    if ( this->hidden->visual != sysvis ) {
   9.371 +            flags |= SDL_HWPALETTE;
   9.372 +	    }
   9.373 +	    if ( flags & SDL_HWPALETTE ) {
   9.374 +            current->flags |= SDL_HWPALETTE;
   9.375 +            this->hidden->colormap = gdk_colormap_new(this->hidden->visual, TRUE);
   9.376 +	    } else {
   9.377 +            this->hidden->colormap = this->hidden->display_colormap;
   9.378 +            g_object_ref(this->hidden->colormap);
   9.379 +	    }
   9.380 +	} else if ( this->hidden->visual->type == GDK_VISUAL_DIRECT_COLOR ) {
   9.381 +
   9.382 +	    /* Create a colormap which we can manipulate for gamma */
   9.383 +        this->hidden->colormap = gdk_colormap_new(this->hidden->visual, TRUE);
   9.384 +        gdk_flush();
   9.385 +
   9.386 +	    /* Initialize the colormap to the identity mapping */
   9.387 +	    SDL_GetGammaRamp(0, 0, 0);
   9.388 +	    this->screen = current;
   9.389 +#if 0 // !!! FIXME
   9.390 +	    GTKPLUS_SetGammaRamp(this, this->gamma);
   9.391 +#endif
   9.392 +	    this->screen = NULL;
   9.393 +	} else {
   9.394 +	    /* Create a read-only colormap for our window */
   9.395 +        this->hidden->colormap = gdk_colormap_new(this->hidden->visual, FALSE);
   9.396 +	}
   9.397 +
   9.398 +#if 0  // !!! FIXME
   9.399 +	/* Recreate the auxiliary windows, if needed (required for GL) */
   9.400 +	if ( vis_change )
   9.401 +	    create_aux_windows(this);
   9.402 +
   9.403 +	if(current->flags & SDL_HWPALETTE) {
   9.404 +	    /* Since the full-screen window might have got a nonzero background
   9.405 +	       colour (0 is white on some displays), we should reset the
   9.406 +	       background to 0 here since that is what the user expects
   9.407 +	       with a private colormap */
   9.408 +	    XSetWindowBackground(SDL_Display, FSwindow, 0);
   9.409 +	    XClearWindow(SDL_Display, FSwindow);
   9.410 +	}
   9.411 +
   9.412 +	/* resize the (possibly new) window manager window */
   9.413 +	if( !SDL_windowid ) {
   9.414 +	        X11_SetSizeHints(this, w, h, flags);
   9.415 +		window_w = w;
   9.416 +		window_h = h;
   9.417 +		XResizeWindow(SDL_Display, WMwindow, w, h);
   9.418 +	}
   9.419 +#endif
   9.420 +
   9.421 +    if ( this->hidden->gdkimage ) {
   9.422 +        g_object_unref(this->hidden->gdkimage);
   9.423 +        this->hidden->gdkimage = NULL;
   9.424 +    }
   9.425 +
   9.426 +    img = this->hidden->gdkimage = gdk_image_new(GDK_IMAGE_FASTEST,
   9.427 +                                           vis, width, height);
   9.428 +    if (img == NULL) {
   9.429 +		SDL_SetError("Couldn't allocate buffer for requested mode");
   9.430 +		return(NULL);
   9.431 +	}
   9.432 +    gdk_image_set_colormap(this->hidden->gdkimage, this->hidden->colormap);
   9.433 +
   9.434 +	SDL_memset(img->mem, 0, height * img->bpl);
   9.435 +
   9.436 +    if ( this->hidden->gtkwindow == NULL ) {
   9.437 +        this->hidden->gtkdrawingarea = gtk_drawing_area_new();
   9.438 +        if ( this->hidden->gtkdrawingarea == NULL ) {
   9.439 +		    SDL_SetError("Couldn't create drawing area for requested mode");
   9.440 +            g_object_unref(this->hidden->gdkimage);
   9.441 +            this->hidden->gdkimage = NULL;
   9.442 +		    return(NULL);
   9.443 +	    }
   9.444 +
   9.445 +        this->hidden->gtkwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   9.446 +        if ( this->hidden->gtkwindow == NULL ) {
   9.447 +		    SDL_SetError("Couldn't create window for requested mode");
   9.448 +            g_object_unref(this->hidden->gdkimage);
   9.449 +            g_object_unref(this->hidden->gtkdrawingarea);
   9.450 +            this->hidden->gdkimage = NULL;
   9.451 +            this->hidden->gtkdrawingarea = NULL;
   9.452 +		    return(NULL);
   9.453 +	    }
   9.454 +
   9.455 +        gtk_window_set_title(GTK_WINDOW(this->hidden->gtkwindow), "");
   9.456 +        gtk_widget_set_app_paintable(this->hidden->gtkwindow, TRUE);
   9.457 +        gtk_widget_set_app_paintable(this->hidden->gtkdrawingarea, TRUE);
   9.458 +        gtk_widget_set_double_buffered(this->hidden->gtkwindow, FALSE);
   9.459 +        gtk_widget_set_double_buffered(this->hidden->gtkdrawingarea, FALSE);
   9.460 +
   9.461 +        GTKPLUS_ConnectSignals(this);
   9.462 +
   9.463 +        gtk_container_add(GTK_CONTAINER(this->hidden->gtkwindow),
   9.464 +                          this->hidden->gtkdrawingarea);
   9.465 +    }
   9.466 +
   9.467 +    win = GTK_WINDOW(this->hidden->gtkwindow);
   9.468 +    gtk_widget_set_colormap(this->hidden->gtkdrawingarea, this->hidden->colormap);
   9.469 +
   9.470 +// !!! FIXME
   9.471 +#if 0
   9.472 +	/* Cache the window in the server, when possible */
   9.473 +	{
   9.474 +		Screen *xscreen;
   9.475 +		XSetWindowAttributes a;
   9.476 +
   9.477 +		xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen);
   9.478 +		a.backing_store = DoesBackingStore(xscreen);
   9.479 +		if ( a.backing_store != NotUseful ) {
   9.480 +			XChangeWindowAttributes(SDL_Display, SDL_Window,
   9.481 +			                        CWBackingStore, &a);
   9.482 +		}
   9.483 +	}
   9.484 +
   9.485 +	/* Update the internal keyboard state */
   9.486 +	X11_SetKeyboardState(SDL_Display, NULL);
   9.487 +
   9.488 +	/* When the window is first mapped, ignore non-modifier keys */
   9.489 +	{
   9.490 +		Uint8 *keys = SDL_GetKeyState(NULL);
   9.491 +		for ( i = 0; i < SDLK_LAST; ++i ) {
   9.492 +			switch (i) {
   9.493 +			    case SDLK_NUMLOCK:
   9.494 +			    case SDLK_CAPSLOCK:
   9.495 +			    case SDLK_LCTRL:
   9.496 +			    case SDLK_RCTRL:
   9.497 +			    case SDLK_LSHIFT:
   9.498 +			    case SDLK_RSHIFT:
   9.499 +			    case SDLK_LALT:
   9.500 +			    case SDLK_RALT:
   9.501 +			    case SDLK_LMETA:
   9.502 +			    case SDLK_RMETA:
   9.503 +			    case SDLK_MODE:
   9.504 +				break;
   9.505 +			    default:
   9.506 +				keys[i] = SDL_RELEASED;
   9.507 +				break;
   9.508 +			}
   9.509 +		}
   9.510 +	}
   9.511 +
   9.512 +	/* Map them both and go fullscreen, if requested */
   9.513 +	if ( ! SDL_windowid ) {
   9.514 +		XMapWindow(SDL_Display, SDL_Window);
   9.515 +		XMapWindow(SDL_Display, WMwindow);
   9.516 +		X11_WaitMapped(this, WMwindow);
   9.517 +		if ( flags & SDL_FULLSCREEN ) {
   9.518 +			current->flags |= SDL_FULLSCREEN;
   9.519 +			X11_EnterFullScreen(this);
   9.520 +		} else {
   9.521 +			current->flags &= ~SDL_FULLSCREEN;
   9.522 +		}
   9.523 +	}
   9.524 +#endif
   9.525 +
   9.526 +    if ((flags & SDL_FULLSCREEN) == 0) {
   9.527 +        gtk_window_unfullscreen(win);
   9.528 +    } else {
   9.529 +        gtk_window_fullscreen(win);
   9.530 +        flags &= ~SDL_RESIZABLE;
   9.531 +        flags |= SDL_NOFRAME;
   9.532 +    }
   9.533 +
   9.534 +    gtk_window_set_resizable(win, (flags & SDL_RESIZABLE) ? TRUE : FALSE);
   9.535 +    gtk_window_set_decorated(win, (flags & SDL_NOFRAME) ? FALSE : TRUE);
   9.536 +    gtk_window_resize(win, width, height);
   9.537 +    gtk_widget_set_size_request(this->hidden->gtkdrawingarea, width, height);
   9.538 +    gtk_widget_show(this->hidden->gtkdrawingarea);
   9.539 +    gtk_widget_show(this->hidden->gtkwindow);
   9.540 +
   9.541 +	/* Set up the new mode framebuffer */
   9.542 +	current->w = width;
   9.543 +	current->h = height;
   9.544 +    //current->format->depth = vis->bits_per_rgb;
   9.545 +	current->flags = flags | SDL_PREALLOC;
   9.546 +	current->pitch = img->bpl;
   9.547 +	current->pixels = this->hidden->gdkimage->mem;
   9.548 +
   9.549 +	/* We're done */
   9.550 +	return(current);
   9.551 +}
   9.552 +
   9.553 +static void GTKPLUS_SetCaption(_THIS, const char *title, const char *icon)
   9.554 +{
   9.555 +    gtk_window_set_title(GTK_WINDOW(this->hidden->gtkwindow),
   9.556 +                         (const gchar *) title);
   9.557 +}
   9.558 +
   9.559 +/* We don't actually allow hardware surfaces. */
   9.560 +static int GTKPLUS_AllocHWSurface(_THIS, SDL_Surface *surface)
   9.561 +{
   9.562 +	return(-1);
   9.563 +}
   9.564 +
   9.565 +static void GTKPLUS_FreeHWSurface(_THIS, SDL_Surface *surface)
   9.566 +{
   9.567 +}
   9.568 +
   9.569 +/* We need to wait for vertical retrace on page flipped displays */
   9.570 +static int GTKPLUS_LockHWSurface(_THIS, SDL_Surface *surface)
   9.571 +{
   9.572 +	return(0);
   9.573 +}
   9.574 +
   9.575 +static void GTKPLUS_UnlockHWSurface(_THIS, SDL_Surface *surface)
   9.576 +{
   9.577 +}
   9.578 +
   9.579 +static void GTKPLUS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
   9.580 +{
   9.581 +    if ( (this->hidden->gtkdrawingarea != NULL) &&
   9.582 +         (GTK_WIDGET_DRAWABLE(this->hidden->gtkdrawingarea)) &&
   9.583 +         (numrects > 0) ) {
   9.584 +        GdkDrawable *draw = GDK_DRAWABLE(this->hidden->gtkdrawingarea->window);
   9.585 +        if (this->hidden->gc == NULL) {
   9.586 +		    this->hidden->gc = gdk_gc_new(draw);
   9.587 +        }
   9.588 +
   9.589 +        if (this->hidden->gc != NULL) {
   9.590 +            GdkImage *img = this->hidden->gdkimage;
   9.591 +            const SDL_Rect *r = rects;
   9.592 +            int i;
   9.593 +            for (i = 0; i < numrects; i++, r++) {
   9.594 +                const gint x = r->x;
   9.595 +                const gint y = r->y;
   9.596 +                gdk_draw_image(draw, this->hidden->gc, img,
   9.597 +                               x, y, x, y, r->w, r->h);
   9.598 +            }
   9.599 +            gdk_flush(); /* transfer the GdkImage so we can make changes. */
   9.600 +        }
   9.601 +    }
   9.602 +}
   9.603 +
   9.604 +int GTKPLUS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   9.605 +{
   9.606 +	/* !!! FIXME */
   9.607 +	return(0);
   9.608 +}
   9.609 +
   9.610 +/* Note:  If we are terminated, this could be called in the middle of
   9.611 +   another SDL video routine -- notably UpdateRects.
   9.612 +*/
   9.613 +void GTKPLUS_VideoQuit(_THIS)
   9.614 +{
   9.615 +    int i;
   9.616 +
   9.617 +    gdk_flush();
   9.618 +
   9.619 +    if (this->hidden->gc != NULL) {
   9.620 +    	g_object_unref(this->hidden->gc);
   9.621 +        this->hidden->gc = NULL;
   9.622 +    }
   9.623 +
   9.624 +	if ( this->hidden->gtkwindow ) {
   9.625 +        /* this deletes the drawing area widget, too. */
   9.626 +        gtk_widget_destroy(this->hidden->gtkwindow);
   9.627 +        this->hidden->gtkwindow = NULL;
   9.628 +    }
   9.629 +
   9.630 +	if ( this->hidden->gdkimage ) {
   9.631 +        g_object_unref(this->hidden->gdkimage);
   9.632 +        this->hidden->gdkimage = NULL;
   9.633 +    }
   9.634 +
   9.635 +    for (i = 0; i < this->hidden->nvisuals; i++) {
   9.636 +        g_object_unref(this->hidden->visuals[i]);
   9.637 +        this->hidden->visuals[i] = NULL;
   9.638 +    }
   9.639 +    this->hidden->nvisuals = 0;
   9.640 +
   9.641 +	g_object_unref(this->hidden->colormap);
   9.642 +    this->hidden->colormap = NULL;
   9.643 +
   9.644 +    gdk_flush();
   9.645 +}
   9.646 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/gtk/SDL_gtkvideo.h	Thu Apr 19 07:12:30 2007 +0000
    10.3 @@ -0,0 +1,51 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997-2006 Sam Lantinga
    10.7 +
    10.8 +    This library is free software; you can redistribute it and/or
    10.9 +    modify it under the terms of the GNU Lesser General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2.1 of the License, or (at your option) any later version.
   10.12 +
   10.13 +    This library is distributed in the hope that it will be useful,
   10.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +    Lesser General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Lesser General Public
   10.19 +    License along with this library; if not, write to the Free Software
   10.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   10.21 +
   10.22 +    Sam Lantinga
   10.23 +    slouken@libsdl.org
   10.24 +*/
   10.25 +#include "SDL_config.h"
   10.26 +
   10.27 +#ifndef _SDL_gtkvideo_h
   10.28 +#define _SDL_gtkvideo_h
   10.29 +
   10.30 +#include "../SDL_sysvideo.h"
   10.31 +
   10.32 +#include <gtk/gtk.h>
   10.33 +
   10.34 +/* Hidden "this" pointer for the video functions */
   10.35 +#define _THIS	SDL_VideoDevice *this
   10.36 +#define SET_THIS_POINTER(x) SDL_VideoDevice *this = (SDL_VideoDevice *) x
   10.37 +
   10.38 +
   10.39 +/* Private display data */
   10.40 +
   10.41 +struct SDL_PrivateVideoData {
   10.42 +    GdkImage *gdkimage;
   10.43 +    GtkWidget *gtkwindow;
   10.44 +    GtkWidget *gtkdrawingarea;
   10.45 +    GdkVisual *visuals[2*5];    /* at most 2 entries for 8, 15, 16, 24, 32 */
   10.46 +    GdkVisual *visual;
   10.47 +    GdkColormap *colormap;
   10.48 +    GdkColormap *display_colormap;
   10.49 +    GdkGC *gc;
   10.50 +    int nvisuals;
   10.51 +    int depth;
   10.52 +};
   10.53 +
   10.54 +#endif /* _SDL_gtkvideo_h */