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