src/video/x11/SDL_x11events.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 21 Jan 2010 06:21:52 +0000
changeset 3685 64ce267332c6
parent 3322 d9dd6cbba4c0
child 3697 f7b03b6838cb
permissions -rw-r--r--
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
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) &&
slouken@3685
    69
                (videodata->windowlist[i]->xwindow == 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@3685
   100
                SDL_SetMouseFocus(mouse->id, data->window);
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@3685
   135
            SDL_SetKeyboardFocus(videodata->keyboard, data->window);
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@3685
   235
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@3685
   236
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1951
   237
        }
slouken@1951
   238
        break;
slouken@1951
   239
slouken@1951
   240
        /* Have we been restored? */
slouken@1951
   241
    case MapNotify:{
slouken@1951
   242
#ifdef DEBUG_XEVENTS
slouken@1951
   243
            printf("MapNotify!\n");
slouken@1951
   244
#endif
slouken@3685
   245
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@3685
   246
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1951
   247
        }
slouken@1951
   248
        break;
slouken@1951
   249
slouken@1951
   250
        /* Have we been resized or moved? */
slouken@1951
   251
    case ConfigureNotify:{
slouken@1951
   252
#ifdef DEBUG_XEVENTS
slouken@1951
   253
            printf("ConfigureNotify! (resize: %dx%d)\n",
slouken@1951
   254
                   xevent.xconfigure.width, xevent.xconfigure.height);
slouken@1951
   255
#endif
slouken@3685
   256
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
slouken@1951
   257
                                xevent.xconfigure.x, xevent.xconfigure.y);
slouken@3685
   258
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
slouken@1951
   259
                                xevent.xconfigure.width,
slouken@1951
   260
                                xevent.xconfigure.height);
slouken@1951
   261
        }
slouken@1951
   262
        break;
slouken@1951
   263
slouken@1951
   264
        /* Have we been requested to quit (or another client message?) */
slouken@1951
   265
    case ClientMessage:{
slouken@1951
   266
            if ((xevent.xclient.format == 32) &&
slouken@1951
   267
                (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
slouken@1951
   268
slouken@3685
   269
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1951
   270
            }
slouken@1951
   271
        }
slouken@1951
   272
        break;
slouken@1951
   273
slouken@1951
   274
        /* Do we need to refresh ourselves? */
slouken@1951
   275
    case Expose:{
slouken@1951
   276
#ifdef DEBUG_XEVENTS
slouken@1951
   277
            printf("Expose (count = %d)\n", xevent.xexpose.count);
slouken@1951
   278
#endif
slouken@3685
   279
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
slouken@1951
   280
        }
slouken@1951
   281
        break;
slouken@1951
   282
slouken@1951
   283
    default:{
slouken@2942
   284
            for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@2942
   285
                SDL_Mouse *mouse;
slouken@3003
   286
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@2942
   287
                X11_MouseData *data;
slouken@3003
   288
#endif
slouken@2940
   289
slouken@2942
   290
                mouse = SDL_GetMouse(i);
slouken@3003
   291
                if (!mouse->driverdata) {
slouken@2992
   292
                    switch (xevent.type) {
slouken@2992
   293
                    case MotionNotify:
slouken@2992
   294
#ifdef DEBUG_MOTION
slouken@2997
   295
                        printf("X11 motion: %d,%d\n", xevent.xmotion.x,
slouken@2997
   296
                               xevent.xmotion.y);
slouken@2992
   297
#endif
slouken@2997
   298
                        SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x,
slouken@2997
   299
                                            xevent.xmotion.y, 0);
slouken@2992
   300
                        break;
slouken@2992
   301
slouken@2992
   302
                    case ButtonPress:
slouken@2997
   303
                        SDL_SendMouseButton(mouse->id, SDL_PRESSED,
slouken@2997
   304
                                            xevent.xbutton.button);
slouken@2992
   305
                        break;
slouken@2992
   306
slouken@2992
   307
                    case ButtonRelease:
slouken@2997
   308
                        SDL_SendMouseButton(mouse->id, SDL_RELEASED,
slouken@2997
   309
                                            xevent.xbutton.button);
slouken@2992
   310
                        break;
slouken@2992
   311
                    }
slouken@2942
   312
                    continue;
slouken@2942
   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@3040
   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@3040
   418
static void
slouken@3040
   419
gnome_screensaver_disable()
slouken@3030
   420
{
slouken@3030
   421
    screensaver_inhibit_pid = fork();
slouken@3030
   422
    if (screensaver_inhibit_pid == 0) {
slouken@3031
   423
        close(0);
slouken@3031
   424
        close(1);
slouken@3031
   425
        close(2);
slouken@3030
   426
        execl("/usr/bin/gnome-screensaver-command",
slouken@3030
   427
              "gnome-screensaver-command",
slouken@3030
   428
              "--inhibit",
slouken@3030
   429
              "--reason",
slouken@3040
   430
              "GNOME screensaver doesn't respect MIT-SCREEN-SAVER", NULL);
slouken@3030
   431
        exit(2);
slouken@3030
   432
    }
slouken@3030
   433
}
slouken@3040
   434
static void
slouken@3040
   435
gnome_screensaver_enable()
slouken@3030
   436
{
slouken@3030
   437
    kill(screensaver_inhibit_pid, 15);
slouken@3030
   438
}
slouken@3030
   439
#endif
slouken@3030
   440
slouken@1951
   441
void
slouken@3025
   442
X11_SuspendScreenSaver(_THIS)
slouken@1951
   443
{
slouken@3025
   444
#if SDL_VIDEO_DRIVER_X11_SCRNSAVER
slouken@3025
   445
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@3025
   446
    int dummy;
slouken@3025
   447
    int major_version, minor_version;
slouken@1951
   448
slouken@3030
   449
    if (SDL_X11_HAVE_XSS) {
slouken@3030
   450
        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
slouken@3030
   451
        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
slouken@3030
   452
            !XScreenSaverQueryVersion(data->display,
slouken@3030
   453
                                      &major_version, &minor_version) ||
slouken@3030
   454
            major_version < 1 || (major_version == 1 && minor_version < 1)) {
slouken@3030
   455
            return;
slouken@3030
   456
        }
slouken@3030
   457
slouken@3030
   458
        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
slouken@3030
   459
        XResetScreenSaver(data->display);
slouken@1951
   460
    }
slouken@3030
   461
#endif
slouken@1951
   462
slouken@3030
   463
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   464
    if (_this->suspend_screensaver) {
slouken@3030
   465
        gnome_screensaver_disable();
slouken@3030
   466
    } else {
slouken@3030
   467
        gnome_screensaver_enable();
slouken@3025
   468
    }
slouken@3025
   469
#endif
slouken@1951
   470
}
slouken@1951
   471
slouken@1951
   472
/* vi: set ts=4 sw=4 expandtab: */