src/video/x11/SDL_x11events.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 15 Dec 2009 08:11:06 +0000
changeset 3565 f43c8f688f77
parent 3322 d9dd6cbba4c0
child 3685 64ce267332c6
permissions -rw-r--r--
Fixed bug #906

Added better error reporting for OpenGL context creation failing.
slouken@1951
     1
/*
slouken@1951
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@1951
     4
slouken@1951
     5
    This library is free software; you can redistribute it and/or
slouken@1951
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1951
     7
    License as published by the Free Software Foundation; either
slouken@1951
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1951
     9
slouken@1951
    10
    This library is distributed in the hope that it will be useful,
slouken@1951
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1951
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1951
    13
    Lesser General Public License for more details.
slouken@1951
    14
slouken@1951
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1951
    16
    License along with this library; if not, write to the Free Software
slouken@1951
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1951
    18
slouken@1951
    19
    Sam Lantinga
slouken@1951
    20
    slouken@libsdl.org
slouken@1951
    21
*/
slouken@1951
    22
#include "SDL_config.h"
slouken@1951
    23
slouken@2046
    24
#include <sys/types.h>
slouken@2046
    25
#include <sys/time.h>
slouken@2046
    26
#include <unistd.h>
slouken@2046
    27
slouken@1951
    28
#include "SDL_x11video.h"
slouken@1951
    29
#include "../../events/SDL_events_c.h"
slouken@2940
    30
#include "../../events/SDL_mouse_c.h"
slouken@1951
    31
slouken@3241
    32
#include "SDL_syswm.h"
slouken@3241
    33
slouken@1951
    34
static void
slouken@1951
    35
X11_DispatchEvent(_THIS)
slouken@1951
    36
{
slouken@1951
    37
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1951
    38
    SDL_WindowData *data;
slouken@1951
    39
    XEvent xevent;
slouken@1951
    40
    int i;
slouken@1951
    41
slouken@1951
    42
    SDL_zero(xevent);           /* valgrind fix. --ryan. */
slouken@1951
    43
    XNextEvent(videodata->display, &xevent);
slouken@1951
    44
bob@2325
    45
    /* filter events catchs XIM events and sends them to the correct
bob@2325
    46
       handler */
bob@2325
    47
    if (XFilterEvent(&xevent, None) == True) {
bob@2327
    48
#if 0
bob@2328
    49
        printf("Filtered event type = %d display = %d window = %d\n",
bob@2328
    50
               xevent.type, xevent.xany.display, xevent.xany.window);
bob@2325
    51
#endif
bob@2325
    52
        return;
bob@2325
    53
    }
bob@2325
    54
slouken@1951
    55
    /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@1951
    56
    if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
slouken@1951
    57
        SDL_SysWMmsg wmmsg;
slouken@1951
    58
slouken@1951
    59
        SDL_VERSION(&wmmsg.version);
slouken@1951
    60
        wmmsg.subsystem = SDL_SYSWM_X11;
slouken@1951
    61
        wmmsg.event.xevent = xevent;
slouken@1951
    62
        SDL_SendSysWMEvent(&wmmsg);
slouken@1951
    63
    }
slouken@1951
    64
slouken@1951
    65
    data = NULL;
bob@2324
    66
    if (videodata && videodata->windowlist) {
bob@2324
    67
        for (i = 0; i < videodata->numwindows; ++i) {
bob@2324
    68
            if ((videodata->windowlist[i] != NULL) &&
bob@2324
    69
                (videodata->windowlist[i]->window == xevent.xany.window)) {
bob@2324
    70
                data = videodata->windowlist[i];
bob@2324
    71
                break;
bob@2324
    72
            }
slouken@1951
    73
        }
slouken@1951
    74
    }
slouken@1951
    75
    if (!data) {
slouken@1951
    76
        return;
slouken@1951
    77
    }
bob@2327
    78
#if 0
bob@2328
    79
    printf("type = %d display = %d window = %d\n",
bob@2328
    80
           xevent.type, xevent.xany.display, xevent.xany.window);
bob@2327
    81
#endif
slouken@1951
    82
    switch (xevent.type) {
slouken@1951
    83
slouken@1951
    84
        /* Gaining mouse coverage? */
slouken@1951
    85
    case EnterNotify:{
slouken@1951
    86
#ifdef DEBUG_XEVENTS
bob@3195
    87
            printf("EnterNotify! (%d,%d,%d)\n", 
bob@3195
    88
	           xevent.xcrossing.x,
bob@3195
    89
 	           xevent.xcrossing.y,
bob@3195
    90
                   xevent.xcrossing.mode);
slouken@1951
    91
            if (xevent.xcrossing.mode == NotifyGrab)
slouken@1951
    92
                printf("Mode: NotifyGrab\n");
slouken@1951
    93
            if (xevent.xcrossing.mode == NotifyUngrab)
slouken@1951
    94
                printf("Mode: NotifyUngrab\n");
slouken@1951
    95
#endif
bob@3195
    96
#if 1
slouken@3322
    97
            /* FIXME: Should we reset data for all mice? */
slouken@3322
    98
            for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@3322
    99
                SDL_Mouse *mouse = SDL_GetMouse(i);
slouken@3322
   100
                SDL_SetMouseFocus(mouse->id, data->windowID);
slouken@3322
   101
            }
slouken@2940
   102
#endif
slouken@1951
   103
        }
slouken@1951
   104
        break;
slouken@1951
   105
slouken@1951
   106
        /* Losing mouse coverage? */
slouken@1951
   107
    case LeaveNotify:{
slouken@1951
   108
#ifdef DEBUG_XEVENTS
bob@3195
   109
            printf("LeaveNotify! (%d,%d,%d)\n", 
bob@3195
   110
	           xevent.xcrossing.x,
bob@3195
   111
 	           xevent.xcrossing.y,
bob@3195
   112
                   xevent.xcrossing.mode);
slouken@1951
   113
            if (xevent.xcrossing.mode == NotifyGrab)
slouken@1951
   114
                printf("Mode: NotifyGrab\n");
slouken@1951
   115
            if (xevent.xcrossing.mode == NotifyUngrab)
slouken@1951
   116
                printf("Mode: NotifyUngrab\n");
slouken@1951
   117
#endif
slouken@3322
   118
            if (xevent.xcrossing.detail != NotifyInferior) {
bob@3195
   119
#if 1
slouken@2940
   120
                /* FIXME: Should we reset data for all mice? */
slouken@3322
   121
	        for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@3322
   122
		    SDL_Mouse *mouse = SDL_GetMouse(i);
slouken@3322
   123
		    SDL_SetMouseFocus(mouse->id, 0);
slouken@3322
   124
	        }
slouken@2940
   125
#endif
slouken@1951
   126
            }
slouken@1951
   127
        }
slouken@1951
   128
        break;
slouken@1951
   129
slouken@1951
   130
        /* Gaining input focus? */
slouken@1951
   131
    case FocusIn:{
slouken@1951
   132
#ifdef DEBUG_XEVENTS
slouken@1951
   133
            printf("FocusIn!\n");
slouken@1951
   134
#endif
slouken@1951
   135
            SDL_SetKeyboardFocus(videodata->keyboard, data->windowID);
slouken@1951
   136
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   137
            if (data->ic) {
slouken@1951
   138
                XSetICFocus(data->ic);
slouken@1951
   139
            }
slouken@1951
   140
#endif
slouken@1951
   141
        }
slouken@1951
   142
        break;
slouken@1951
   143
slouken@1951
   144
        /* Losing input focus? */
slouken@1951
   145
    case FocusOut:{
slouken@1951
   146
#ifdef DEBUG_XEVENTS
slouken@1951
   147
            printf("FocusOut!\n");
slouken@1951
   148
#endif
slouken@1951
   149
            SDL_SetKeyboardFocus(videodata->keyboard, 0);
slouken@1951
   150
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   151
            if (data->ic) {
slouken@1951
   152
                XUnsetICFocus(data->ic);
slouken@1951
   153
            }
slouken@1951
   154
#endif
slouken@1951
   155
        }
slouken@1951
   156
        break;
slouken@1951
   157
slouken@1951
   158
        /* Generated upon EnterWindow and FocusIn */
slouken@1951
   159
    case KeymapNotify:{
slouken@1951
   160
#ifdef DEBUG_XEVENTS
slouken@1951
   161
            printf("KeymapNotify!\n");
slouken@1951
   162
#endif
slouken@1951
   163
            /* FIXME:
slouken@1951
   164
               X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
slouken@1951
   165
             */
slouken@1951
   166
        }
slouken@1951
   167
        break;
slouken@1951
   168
slouken@2305
   169
        /* Has the keyboard layout changed? */
slouken@2305
   170
    case MappingNotify:{
slouken@2305
   171
#ifdef DEBUG_XEVENTS
slouken@2305
   172
            printf("MappingNotify!\n");
slouken@2305
   173
#endif
slouken@2306
   174
            X11_UpdateKeymap(_this);
slouken@2305
   175
        }
slouken@2305
   176
        break;
slouken@2305
   177
slouken@1951
   178
        /* Key press? */
slouken@1951
   179
    case KeyPress:{
slouken@1951
   180
            KeyCode keycode = xevent.xkey.keycode;
bob@2300
   181
            KeySym keysym = NoSymbol;
slouken@2306
   182
            char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
bob@2325
   183
            Status status = 0;
slouken@1951
   184
slouken@1951
   185
#ifdef DEBUG_XEVENTS
slouken@1951
   186
            printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
slouken@1951
   187
#endif
bob@2299
   188
            SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED,
slouken@2305
   189
                                videodata->key_layout[keycode]);
bob@2325
   190
#if 0
slouken@2305
   191
            if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
slouken@2305
   192
                int min_keycode, max_keycode;
slouken@2305
   193
                XDisplayKeycodes(videodata->display, &min_keycode,
slouken@2305
   194
                                 &max_keycode);
slouken@2305
   195
                keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
bob@2299
   196
                fprintf(stderr,
slouken@2305
   197
                        "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%X (%s).\n",
slouken@2305
   198
                        keycode, keycode - min_keycode, keysym,
slouken@2305
   199
                        XKeysymToString(keysym));
bob@2299
   200
            }
bob@2295
   201
#endif
bob@2325
   202
            /* */
slouken@2305
   203
            SDL_zero(text);
bob@2325
   204
#ifdef X_HAVE_UTF8_STRING
bob@2325
   205
            if (data->ic) {
bob@2325
   206
                Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
slouken@2738
   207
                                  &keysym, &status);
bob@2325
   208
            }
bob@2325
   209
#else
slouken@2306
   210
            XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
bob@2325
   211
#endif
slouken@2305
   212
            if (*text) {
bob@2300
   213
                SDL_SendKeyboardText(videodata->keyboard, text);
bob@2300
   214
            }
slouken@1951
   215
        }
slouken@1951
   216
        break;
slouken@1951
   217
slouken@1951
   218
        /* Key release? */
slouken@1951
   219
    case KeyRelease:{
slouken@1951
   220
            KeyCode keycode = xevent.xkey.keycode;
slouken@1951
   221
slouken@1951
   222
#ifdef DEBUG_XEVENTS
slouken@1951
   223
            printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
slouken@1951
   224
#endif
bob@2295
   225
            SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED,
slouken@2305
   226
                                videodata->key_layout[keycode]);
slouken@1951
   227
        }
slouken@1951
   228
        break;
slouken@1951
   229
slouken@1951
   230
        /* Have we been iconified? */
slouken@1951
   231
    case UnmapNotify:{
slouken@1951
   232
#ifdef DEBUG_XEVENTS
slouken@1951
   233
            printf("UnmapNotify!\n");
slouken@1951
   234
#endif
slouken@1951
   235
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1951
   236
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MINIMIZED, 0,
slouken@1951
   237
                                0);
slouken@1951
   238
        }
slouken@1951
   239
        break;
slouken@1951
   240
slouken@1951
   241
        /* Have we been restored? */
slouken@1951
   242
    case MapNotify:{
slouken@1951
   243
#ifdef DEBUG_XEVENTS
slouken@1951
   244
            printf("MapNotify!\n");
slouken@1951
   245
#endif
slouken@1951
   246
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1951
   247
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESTORED, 0,
slouken@1951
   248
                                0);
slouken@1951
   249
        }
slouken@1951
   250
        break;
slouken@1951
   251
slouken@1951
   252
        /* Have we been resized or moved? */
slouken@1951
   253
    case ConfigureNotify:{
slouken@1951
   254
#ifdef DEBUG_XEVENTS
slouken@1951
   255
            printf("ConfigureNotify! (resize: %dx%d)\n",
slouken@1951
   256
                   xevent.xconfigure.width, xevent.xconfigure.height);
slouken@1951
   257
#endif
slouken@1951
   258
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MOVED,
slouken@1951
   259
                                xevent.xconfigure.x, xevent.xconfigure.y);
slouken@1951
   260
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESIZED,
slouken@1951
   261
                                xevent.xconfigure.width,
slouken@1951
   262
                                xevent.xconfigure.height);
slouken@1951
   263
        }
slouken@1951
   264
        break;
slouken@1951
   265
slouken@1951
   266
        /* Have we been requested to quit (or another client message?) */
slouken@1951
   267
    case ClientMessage:{
slouken@1951
   268
            if ((xevent.xclient.format == 32) &&
slouken@1951
   269
                (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
slouken@1951
   270
slouken@1951
   271
                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_CLOSE, 0,
slouken@1951
   272
                                    0);
slouken@1951
   273
            }
slouken@1951
   274
        }
slouken@1951
   275
        break;
slouken@1951
   276
slouken@1951
   277
        /* Do we need to refresh ourselves? */
slouken@1951
   278
    case Expose:{
slouken@1951
   279
#ifdef DEBUG_XEVENTS
slouken@1951
   280
            printf("Expose (count = %d)\n", xevent.xexpose.count);
slouken@1951
   281
#endif
slouken@1951
   282
            SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED, 0,
slouken@1951
   283
                                0);
slouken@1951
   284
        }
slouken@1951
   285
        break;
slouken@1951
   286
slouken@1951
   287
    default:{
slouken@2942
   288
            for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@2942
   289
                SDL_Mouse *mouse;
slouken@3003
   290
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@2942
   291
                X11_MouseData *data;
slouken@3003
   292
#endif
slouken@2940
   293
slouken@2942
   294
                mouse = SDL_GetMouse(i);
slouken@3003
   295
                if (!mouse->driverdata) {
slouken@2992
   296
                    switch (xevent.type) {
slouken@2992
   297
                    case MotionNotify:
slouken@2992
   298
#ifdef DEBUG_MOTION
slouken@2997
   299
                        printf("X11 motion: %d,%d\n", xevent.xmotion.x,
slouken@2997
   300
                               xevent.xmotion.y);
slouken@2992
   301
#endif
slouken@2997
   302
                        SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x,
slouken@2997
   303
                                            xevent.xmotion.y, 0);
slouken@2992
   304
                        break;
slouken@2992
   305
slouken@2992
   306
                    case ButtonPress:
slouken@2997
   307
                        SDL_SendMouseButton(mouse->id, SDL_PRESSED,
slouken@2997
   308
                                            xevent.xbutton.button);
slouken@2992
   309
                        break;
slouken@2992
   310
slouken@2992
   311
                    case ButtonRelease:
slouken@2997
   312
                        SDL_SendMouseButton(mouse->id, SDL_RELEASED,
slouken@2997
   313
                                            xevent.xbutton.button);
slouken@2992
   314
                        break;
slouken@2992
   315
                    }
slouken@2942
   316
                    continue;
slouken@2942
   317
                }
slouken@3003
   318
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@3003
   319
                data = (X11_MouseData *) mouse->driverdata;
slouken@3003
   320
                if (xevent.type == data->motion) {
slouken@2942
   321
                    XDeviceMotionEvent *move =
slouken@2942
   322
                        (XDeviceMotionEvent *) & xevent;
slouken@2942
   323
#ifdef DEBUG_MOTION
slouken@2942
   324
                    printf("X11 motion: %d,%d\n", move->x, move->y);
slouken@2942
   325
#endif
slouken@2942
   326
                    SDL_SendMouseMotion(move->deviceid, 0, move->x, move->y,
slouken@2942
   327
                                        move->axis_data[2]);
slouken@2942
   328
                    return;
slouken@2942
   329
                }
slouken@3003
   330
                if (xevent.type == data->button_pressed) {
slouken@2942
   331
                    XDeviceButtonPressedEvent *pressed =
slouken@2942
   332
                        (XDeviceButtonPressedEvent *) & xevent;
slouken@2942
   333
                    SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED,
slouken@2942
   334
                                        pressed->button);
slouken@2942
   335
                    return;
slouken@2942
   336
                }
slouken@3003
   337
                if (xevent.type == data->button_released) {
slouken@2942
   338
                    XDeviceButtonReleasedEvent *released =
slouken@2942
   339
                        (XDeviceButtonReleasedEvent *) & xevent;
slouken@2942
   340
                    SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
slouken@2942
   341
                                        released->button);
slouken@2942
   342
                    return;
slouken@2942
   343
                }
slouken@2942
   344
                if (xevent.type == data->proximity_in) {
slouken@2942
   345
                    XProximityNotifyEvent *proximity =
slouken@2942
   346
                        (XProximityNotifyEvent *) & xevent;
slouken@2942
   347
                    SDL_SendProximity(proximity->deviceid, proximity->x,
slouken@2942
   348
                                      proximity->y, SDL_PROXIMITYIN);
slouken@2942
   349
                    return;
slouken@2942
   350
                }
slouken@2942
   351
                if (xevent.type == data->proximity_out) {
slouken@2942
   352
                    XProximityNotifyEvent *proximity =
slouken@2942
   353
                        (XProximityNotifyEvent *) & xevent;
slouken@2942
   354
                    SDL_SendProximity(proximity->deviceid, proximity->x,
slouken@2942
   355
                                      proximity->y, SDL_PROXIMITYOUT);
slouken@2942
   356
                    return;
slouken@2942
   357
                }
slouken@3003
   358
#endif
slouken@2940
   359
            }
slouken@1951
   360
#ifdef DEBUG_XEVENTS
slouken@2940
   361
            printf("Unhandled event %d\n", xevent.type);
slouken@1951
   362
#endif
slouken@1951
   363
        }
slouken@1951
   364
        break;
slouken@1951
   365
    }
slouken@1951
   366
}
slouken@1951
   367
slouken@1951
   368
/* Ack!  XPending() actually performs a blocking read if no events available */
slouken@1951
   369
int
slouken@1951
   370
X11_Pending(Display * display)
slouken@1951
   371
{
slouken@1951
   372
    /* Flush the display connection and look to see if events are queued */
slouken@1951
   373
    XFlush(display);
slouken@1951
   374
    if (XEventsQueued(display, QueuedAlready)) {
slouken@1951
   375
        return (1);
slouken@1951
   376
    }
slouken@1951
   377
slouken@1951
   378
    /* More drastic measures are required -- see if X is ready to talk */
slouken@1951
   379
    {
slouken@1951
   380
        static struct timeval zero_time;        /* static == 0 */
slouken@1951
   381
        int x11_fd;
slouken@1951
   382
        fd_set fdset;
slouken@1951
   383
slouken@1951
   384
        x11_fd = ConnectionNumber(display);
slouken@1951
   385
        FD_ZERO(&fdset);
slouken@1951
   386
        FD_SET(x11_fd, &fdset);
slouken@1951
   387
        if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
slouken@1951
   388
            return (XPending(display));
slouken@1951
   389
        }
slouken@1951
   390
    }
slouken@1951
   391
slouken@1951
   392
    /* Oh well, nothing is ready .. */
slouken@1951
   393
    return (0);
slouken@1951
   394
}
slouken@1951
   395
slouken@1951
   396
void
slouken@1951
   397
X11_PumpEvents(_THIS)
slouken@1951
   398
{
slouken@1951
   399
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1951
   400
slouken@3025
   401
    /* Update activity every 30 seconds to prevent screensaver */
slouken@3025
   402
    if (_this->suspend_screensaver) {
slouken@3025
   403
        Uint32 now = SDL_GetTicks();
slouken@3025
   404
        if (!data->screensaver_activity ||
slouken@3040
   405
            (int) (now - data->screensaver_activity) >= 30000) {
slouken@3025
   406
            XResetScreenSaver(data->display);
slouken@3025
   407
            data->screensaver_activity = now;
slouken@3025
   408
        }
slouken@3025
   409
    }
slouken@3025
   410
slouken@1951
   411
    /* Keep processing pending events */
slouken@1951
   412
    while (X11_Pending(data->display)) {
slouken@1951
   413
        X11_DispatchEvent(_this);
slouken@1951
   414
    }
slouken@1951
   415
}
slouken@1951
   416
slouken@3030
   417
/* This is so wrong it hurts */
slouken@3030
   418
#define GNOME_SCREENSAVER_HACK
slouken@3030
   419
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   420
#include <unistd.h>
slouken@3030
   421
static pid_t screensaver_inhibit_pid;
slouken@3040
   422
static void
slouken@3040
   423
gnome_screensaver_disable()
slouken@3030
   424
{
slouken@3030
   425
    screensaver_inhibit_pid = fork();
slouken@3030
   426
    if (screensaver_inhibit_pid == 0) {
slouken@3031
   427
        close(0);
slouken@3031
   428
        close(1);
slouken@3031
   429
        close(2);
slouken@3030
   430
        execl("/usr/bin/gnome-screensaver-command",
slouken@3030
   431
              "gnome-screensaver-command",
slouken@3030
   432
              "--inhibit",
slouken@3030
   433
              "--reason",
slouken@3040
   434
              "GNOME screensaver doesn't respect MIT-SCREEN-SAVER", NULL);
slouken@3030
   435
        exit(2);
slouken@3030
   436
    }
slouken@3030
   437
}
slouken@3040
   438
static void
slouken@3040
   439
gnome_screensaver_enable()
slouken@3030
   440
{
slouken@3030
   441
    kill(screensaver_inhibit_pid, 15);
slouken@3030
   442
}
slouken@3030
   443
#endif
slouken@3030
   444
slouken@1951
   445
void
slouken@3025
   446
X11_SuspendScreenSaver(_THIS)
slouken@1951
   447
{
slouken@3025
   448
#if SDL_VIDEO_DRIVER_X11_SCRNSAVER
slouken@3025
   449
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@3025
   450
    int dummy;
slouken@3025
   451
    int major_version, minor_version;
slouken@1951
   452
slouken@3030
   453
    if (SDL_X11_HAVE_XSS) {
slouken@3030
   454
        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
slouken@3030
   455
        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
slouken@3030
   456
            !XScreenSaverQueryVersion(data->display,
slouken@3030
   457
                                      &major_version, &minor_version) ||
slouken@3030
   458
            major_version < 1 || (major_version == 1 && minor_version < 1)) {
slouken@3030
   459
            return;
slouken@3030
   460
        }
slouken@3030
   461
slouken@3030
   462
        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
slouken@3030
   463
        XResetScreenSaver(data->display);
slouken@1951
   464
    }
slouken@3030
   465
#endif
slouken@1951
   466
slouken@3030
   467
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   468
    if (_this->suspend_screensaver) {
slouken@3030
   469
        gnome_screensaver_disable();
slouken@3030
   470
    } else {
slouken@3030
   471
        gnome_screensaver_enable();
slouken@3025
   472
    }
slouken@3025
   473
#endif
slouken@1951
   474
}
slouken@1951
   475
slouken@1951
   476
/* vi: set ts=4 sw=4 expandtab: */