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