src/video/x11/SDL_x11events.c
author jimtla
Thu, 22 Jul 2010 08:12:28 +0400
changeset 4669 62e6a6e9720b
parent 4661 03dcb795c583
child 4681 5378f2d0754f
permissions -rw-r--r--
Fixed x11 compile bugs.
slouken@1951
     1
/*
slouken@1951
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@4465
    26
#include <signal.h>
slouken@2046
    27
#include <unistd.h>
slouken@4508
    28
#include <limits.h>	/* For INT_MAX */
slouken@2046
    29
slouken@1951
    30
#include "SDL_x11video.h"
slouken@1951
    31
#include "../../events/SDL_events_c.h"
slouken@2940
    32
#include "../../events/SDL_mouse_c.h"
jim@4642
    33
#include "../../events/SDL_touch_c.h"
slouken@1951
    34
slouken@4465
    35
#include "SDL_timer.h"
slouken@3241
    36
#include "SDL_syswm.h"
slouken@3241
    37
jim@4642
    38
#include <stdio.h>
jim@4642
    39
jimtla@4669
    40
#ifdef HAVE_LINUX_INPUT_H
jim@4642
    41
//Touch Input/event* includes
jim@4642
    42
#include <linux/input.h>
jim@4642
    43
#include <fcntl.h>
jimtla@4669
    44
#endif
slouken@4508
    45
/*#define DEBUG_XEVENTS*/
slouken@4508
    46
slouken@1951
    47
static void
slouken@1951
    48
X11_DispatchEvent(_THIS)
slouken@1951
    49
{
slouken@1951
    50
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1951
    51
    SDL_WindowData *data;
slouken@1951
    52
    XEvent xevent;
slouken@1951
    53
    int i;
slouken@1951
    54
slouken@1951
    55
    SDL_zero(xevent);           /* valgrind fix. --ryan. */
slouken@1951
    56
    XNextEvent(videodata->display, &xevent);
slouken@1951
    57
bob@2325
    58
    /* filter events catchs XIM events and sends them to the correct
bob@2325
    59
       handler */
bob@2325
    60
    if (XFilterEvent(&xevent, None) == True) {
bob@2327
    61
#if 0
bob@2328
    62
        printf("Filtered event type = %d display = %d window = %d\n",
bob@2328
    63
               xevent.type, xevent.xany.display, xevent.xany.window);
bob@2325
    64
#endif
bob@2325
    65
        return;
bob@2325
    66
    }
bob@2325
    67
slouken@1951
    68
    /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@4429
    69
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@1951
    70
        SDL_SysWMmsg wmmsg;
slouken@1951
    71
slouken@1951
    72
        SDL_VERSION(&wmmsg.version);
slouken@1951
    73
        wmmsg.subsystem = SDL_SYSWM_X11;
slouken@1951
    74
        wmmsg.event.xevent = xevent;
slouken@1951
    75
        SDL_SendSysWMEvent(&wmmsg);
slouken@1951
    76
    }
slouken@1951
    77
slouken@1951
    78
    data = NULL;
bob@2324
    79
    if (videodata && videodata->windowlist) {
bob@2324
    80
        for (i = 0; i < videodata->numwindows; ++i) {
bob@2324
    81
            if ((videodata->windowlist[i] != NULL) &&
slouken@3685
    82
                (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
bob@2324
    83
                data = videodata->windowlist[i];
bob@2324
    84
                break;
bob@2324
    85
            }
slouken@1951
    86
        }
slouken@1951
    87
    }
slouken@1951
    88
    if (!data) {
slouken@1951
    89
        return;
slouken@1951
    90
    }
bob@2327
    91
#if 0
bob@2328
    92
    printf("type = %d display = %d window = %d\n",
bob@2328
    93
           xevent.type, xevent.xany.display, xevent.xany.window);
bob@2327
    94
#endif
slouken@1951
    95
    switch (xevent.type) {
slouken@1951
    96
slouken@1951
    97
        /* Gaining mouse coverage? */
slouken@1951
    98
    case EnterNotify:{
slouken@1951
    99
#ifdef DEBUG_XEVENTS
bob@3195
   100
            printf("EnterNotify! (%d,%d,%d)\n", 
bob@3195
   101
	           xevent.xcrossing.x,
bob@3195
   102
 	           xevent.xcrossing.y,
bob@3195
   103
                   xevent.xcrossing.mode);
slouken@1951
   104
            if (xevent.xcrossing.mode == NotifyGrab)
slouken@1951
   105
                printf("Mode: NotifyGrab\n");
slouken@1951
   106
            if (xevent.xcrossing.mode == NotifyUngrab)
slouken@1951
   107
                printf("Mode: NotifyUngrab\n");
slouken@1951
   108
#endif
slouken@4465
   109
            SDL_SetMouseFocus(data->window);
slouken@1951
   110
        }
slouken@1951
   111
        break;
slouken@1951
   112
        /* Losing mouse coverage? */
slouken@1951
   113
    case LeaveNotify:{
slouken@1951
   114
#ifdef DEBUG_XEVENTS
bob@3195
   115
            printf("LeaveNotify! (%d,%d,%d)\n", 
bob@3195
   116
	           xevent.xcrossing.x,
bob@3195
   117
 	           xevent.xcrossing.y,
bob@3195
   118
                   xevent.xcrossing.mode);
slouken@1951
   119
            if (xevent.xcrossing.mode == NotifyGrab)
slouken@1951
   120
                printf("Mode: NotifyGrab\n");
slouken@1951
   121
            if (xevent.xcrossing.mode == NotifyUngrab)
slouken@1951
   122
                printf("Mode: NotifyUngrab\n");
slouken@1951
   123
#endif
slouken@3322
   124
            if (xevent.xcrossing.detail != NotifyInferior) {
slouken@4465
   125
                SDL_SetMouseFocus(NULL);
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@4465
   135
            SDL_SetKeyboardFocus(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@4465
   149
            SDL_SetKeyboardFocus(NULL);
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
slouken@4465
   188
            SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
bob@2325
   189
#if 0
slouken@2305
   190
            if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
slouken@2305
   191
                int min_keycode, max_keycode;
slouken@2305
   192
                XDisplayKeycodes(videodata->display, &min_keycode,
slouken@2305
   193
                                 &max_keycode);
slouken@2305
   194
                keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
bob@2299
   195
                fprintf(stderr,
slouken@2305
   196
                        "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
   197
                        keycode, keycode - min_keycode, keysym,
slouken@2305
   198
                        XKeysymToString(keysym));
bob@2299
   199
            }
bob@2295
   200
#endif
bob@2325
   201
            /* */
slouken@2305
   202
            SDL_zero(text);
bob@2325
   203
#ifdef X_HAVE_UTF8_STRING
bob@2325
   204
            if (data->ic) {
bob@2325
   205
                Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
slouken@2738
   206
                                  &keysym, &status);
bob@2325
   207
            }
bob@2325
   208
#else
slouken@2306
   209
            XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
bob@2325
   210
#endif
slouken@2305
   211
            if (*text) {
slouken@4465
   212
                SDL_SendKeyboardText(text);
bob@2300
   213
            }
slouken@1951
   214
        }
slouken@1951
   215
        break;
slouken@1951
   216
slouken@1951
   217
        /* Key release? */
slouken@1951
   218
    case KeyRelease:{
slouken@1951
   219
            KeyCode keycode = xevent.xkey.keycode;
slouken@1951
   220
slouken@1951
   221
#ifdef DEBUG_XEVENTS
slouken@1951
   222
            printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
slouken@1951
   223
#endif
slouken@4465
   224
            SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
slouken@1951
   225
        }
slouken@1951
   226
        break;
slouken@1951
   227
slouken@1951
   228
        /* Have we been iconified? */
slouken@1951
   229
    case UnmapNotify:{
slouken@1951
   230
#ifdef DEBUG_XEVENTS
slouken@1951
   231
            printf("UnmapNotify!\n");
slouken@1951
   232
#endif
slouken@3685
   233
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@3685
   234
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1951
   235
        }
slouken@1951
   236
        break;
slouken@1951
   237
slouken@1951
   238
        /* Have we been restored? */
slouken@1951
   239
    case MapNotify:{
slouken@1951
   240
#ifdef DEBUG_XEVENTS
slouken@1951
   241
            printf("MapNotify!\n");
slouken@1951
   242
#endif
slouken@3685
   243
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@3685
   244
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1951
   245
        }
slouken@1951
   246
        break;
slouken@1951
   247
slouken@1951
   248
        /* Have we been resized or moved? */
slouken@1951
   249
    case ConfigureNotify:{
slouken@1951
   250
#ifdef DEBUG_XEVENTS
slouken@1951
   251
            printf("ConfigureNotify! (resize: %dx%d)\n",
slouken@1951
   252
                   xevent.xconfigure.width, xevent.xconfigure.height);
slouken@1951
   253
#endif
slouken@3685
   254
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
slouken@1951
   255
                                xevent.xconfigure.x, xevent.xconfigure.y);
slouken@3685
   256
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
slouken@1951
   257
                                xevent.xconfigure.width,
slouken@1951
   258
                                xevent.xconfigure.height);
slouken@1951
   259
        }
slouken@1951
   260
        break;
slouken@1951
   261
slouken@1951
   262
        /* Have we been requested to quit (or another client message?) */
slouken@1951
   263
    case ClientMessage:{
slouken@1951
   264
            if ((xevent.xclient.format == 32) &&
slouken@1951
   265
                (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
slouken@1951
   266
slouken@3685
   267
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 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@3685
   277
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
slouken@1951
   278
        }
slouken@1951
   279
        break;
slouken@1951
   280
slouken@4465
   281
    case MotionNotify:{
slouken@4465
   282
#ifdef DEBUG_MOTION
slouken@4465
   283
            printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
slouken@4465
   284
#endif
slouken@4484
   285
            SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
slouken@4465
   286
        }
slouken@4465
   287
        break;
slouken@4465
   288
slouken@4465
   289
    case ButtonPress:{
slouken@4484
   290
            SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button);
slouken@4465
   291
        }
slouken@4465
   292
        break;
slouken@4465
   293
slouken@4465
   294
    case ButtonRelease:{
slouken@4484
   295
            SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button);
slouken@4465
   296
        }
slouken@4465
   297
        break;
slouken@4465
   298
slouken@4508
   299
    /* Copy the selection from XA_CUT_BUFFER0 to the requested property */
slouken@4508
   300
    case SelectionRequest: {
slouken@4508
   301
            Display *display = videodata->display;
slouken@4508
   302
            XSelectionRequestEvent *req;
slouken@4508
   303
            XEvent sevent;
slouken@4508
   304
            int seln_format;
slouken@4508
   305
            unsigned long nbytes;
slouken@4508
   306
            unsigned long overflow;
slouken@4508
   307
            unsigned char *seln_data;
slouken@4508
   308
slouken@4508
   309
            req = &xevent.xselectionrequest;
slouken@4508
   310
#ifdef DEBUG_XEVENTS
slouken@4508
   311
            printf("SelectionRequest (requestor = %ld, target = %ld)\n",
slouken@4508
   312
                req->requestor, req->target);
slouken@4508
   313
#endif
slouken@4508
   314
slouken@4508
   315
            sevent.xselection.type = SelectionNotify;
slouken@4508
   316
            sevent.xselection.display = req->display;
slouken@4508
   317
            sevent.xselection.selection = req->selection;
slouken@4508
   318
            sevent.xselection.target = None;
slouken@4508
   319
            sevent.xselection.property = None;
slouken@4508
   320
            sevent.xselection.requestor = req->requestor;
slouken@4508
   321
            sevent.xselection.time = req->time;
slouken@4508
   322
            if (XGetWindowProperty(display, DefaultRootWindow(display),
slouken@4508
   323
                    XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
slouken@4508
   324
                    &sevent.xselection.target, &seln_format, &nbytes,
slouken@4508
   325
                    &overflow, &seln_data) == Success) {
slouken@4508
   326
                if (sevent.xselection.target == req->target) {
slouken@4508
   327
                    XChangeProperty(display, req->requestor, req->property,
slouken@4508
   328
                        sevent.xselection.target, seln_format, PropModeReplace,
slouken@4508
   329
                        seln_data, nbytes);
slouken@4508
   330
                    sevent.xselection.property = req->property;
slouken@4508
   331
                }
slouken@4508
   332
                XFree(seln_data);
slouken@4508
   333
            }
slouken@4508
   334
            XSendEvent(display, req->requestor, False, 0, &sevent);
slouken@4508
   335
            XSync(display, False);
slouken@4508
   336
        }
slouken@4508
   337
        break;
slouken@4508
   338
slouken@4508
   339
    case SelectionNotify: {
slouken@4508
   340
#ifdef DEBUG_XEVENTS
slouken@4508
   341
            printf("SelectionNotify (requestor = %ld, target = %ld)\n",
slouken@4508
   342
                xevent.xselection.requestor, xevent.xselection.target);
slouken@4508
   343
#endif
slouken@4508
   344
            videodata->selection_waiting = SDL_FALSE;
slouken@4508
   345
        }
slouken@4508
   346
        break;
slouken@4508
   347
slouken@1951
   348
    default:{
slouken@1951
   349
#ifdef DEBUG_XEVENTS
slouken@2940
   350
            printf("Unhandled event %d\n", xevent.type);
slouken@1951
   351
#endif
slouken@1951
   352
        }
slouken@1951
   353
        break;
slouken@1951
   354
    }
slouken@1951
   355
}
slouken@1951
   356
slouken@1951
   357
/* Ack!  XPending() actually performs a blocking read if no events available */
slouken@4472
   358
static int
slouken@1951
   359
X11_Pending(Display * display)
slouken@1951
   360
{
slouken@1951
   361
    /* Flush the display connection and look to see if events are queued */
slouken@1951
   362
    XFlush(display);
slouken@1951
   363
    if (XEventsQueued(display, QueuedAlready)) {
slouken@1951
   364
        return (1);
slouken@1951
   365
    }
slouken@1951
   366
slouken@1951
   367
    /* More drastic measures are required -- see if X is ready to talk */
slouken@1951
   368
    {
slouken@1951
   369
        static struct timeval zero_time;        /* static == 0 */
slouken@1951
   370
        int x11_fd;
slouken@1951
   371
        fd_set fdset;
slouken@1951
   372
slouken@1951
   373
        x11_fd = ConnectionNumber(display);
slouken@1951
   374
        FD_ZERO(&fdset);
slouken@1951
   375
        FD_SET(x11_fd, &fdset);
slouken@1951
   376
        if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
slouken@1951
   377
            return (XPending(display));
slouken@1951
   378
        }
slouken@1951
   379
    }
slouken@1951
   380
slouken@1951
   381
    /* Oh well, nothing is ready .. */
slouken@1951
   382
    return (0);
slouken@1951
   383
}
slouken@1951
   384
slouken@1951
   385
void
slouken@1951
   386
X11_PumpEvents(_THIS)
slouken@1951
   387
{
slouken@1951
   388
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1951
   389
slouken@3025
   390
    /* Update activity every 30 seconds to prevent screensaver */
slouken@3025
   391
    if (_this->suspend_screensaver) {
slouken@3025
   392
        Uint32 now = SDL_GetTicks();
slouken@3025
   393
        if (!data->screensaver_activity ||
slouken@3040
   394
            (int) (now - data->screensaver_activity) >= 30000) {
slouken@3025
   395
            XResetScreenSaver(data->display);
slouken@3025
   396
            data->screensaver_activity = now;
slouken@3025
   397
        }
slouken@3025
   398
    }
slouken@3025
   399
slouken@1951
   400
    /* Keep processing pending events */
slouken@1951
   401
    while (X11_Pending(data->display)) {
slouken@1951
   402
        X11_DispatchEvent(_this);
slouken@1951
   403
    }
jim@4640
   404
jimtla@4669
   405
#ifdef HAVE_LINUX_INPUT_H
jim@4642
   406
    /* Process Touch events - TODO When X gets touch support, use that instead*/
jim@4642
   407
    int i = 0,rd;
jim@4643
   408
    char name[256];
jim@4642
   409
    struct input_event ev[64];
jim@4642
   410
    int size = sizeof (struct input_event);
jim@4645
   411
jim@4642
   412
    for(i = 0;i < SDL_GetNumTouch();++i) {
jim@4642
   413
	SDL_Touch* touch = SDL_GetTouchIndex(i);
jim@4642
   414
	if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
jim@4642
   415
	EventTouchData* data;
jim@4645
   416
	data = (EventTouchData*)(touch->driverdata);
jim@4645
   417
	if(data == NULL) {
jim@4645
   418
	  printf("No driver data\n");
jim@4645
   419
	  continue;
jim@4642
   420
	}
jim@4642
   421
	if(data->eventStream <= 0) 
jim@4642
   422
	    printf("Error: Couldn't open stream\n");
jim@4642
   423
	rd = read(data->eventStream, ev, size * 64);
jim@4642
   424
	//printf("Got %i/%i bytes\n",rd,size);
jim@4642
   425
	if(rd >= size) {
jim@4642
   426
	    for (i = 0; i < rd / sizeof(struct input_event); i++) {
jim@4642
   427
		switch (ev[i].type) {
jim@4642
   428
		case EV_ABS:
jim@4642
   429
		    //printf("Got position x: %i!\n",data->x);
jim@4644
   430
		    switch (ev[i].code) {
jim@4644
   431
			case ABS_X:
jim@4644
   432
			    data->x = ev[i].value;
jim@4644
   433
			    break;
jim@4644
   434
			case ABS_Y:
jim@4644
   435
			    data->y = ev[i].value;
jim@4644
   436
			    break;
jim@4644
   437
			case ABS_PRESSURE:
jim@4644
   438
			    data->pressure = ev[i].value;
jim@4646
   439
			    if(data->pressure < 0) data->pressure = 0;
jim@4644
   440
			    break;
jim@4644
   441
			case ABS_MISC:
jim@4644
   442
			    data->up = SDL_TRUE;
jim@4644
   443
			    data->finger = ev[i].value;
jim@4644
   444
			    break;
jim@4644
   445
			}
jim@4642
   446
		    break;
jim@4642
   447
		case EV_MSC:
jim@4642
   448
		    if(ev[i].code == MSC_SERIAL)
jim@4642
   449
			data->finger = ev[i].value;
jim@4642
   450
		    break;
jim@4642
   451
		case EV_SYN:
jim@4646
   452
		  //printf("Id: %i\n",touch->id); 
jim@4655
   453
		  if(data->up) {
jim@4655
   454
		      SDL_SendFingerDown(touch->id,data->finger,
jim@4655
   455
			  	       SDL_FALSE,data->x,data->y,
jim@4655
   456
				       data->pressure);
jim@4655
   457
		  }
jim@4655
   458
		  else if(data->x >= 0 || data->y >= 0)
jim@4655
   459
		      SDL_SendTouchMotion(touch->id,data->finger, 
jim@4655
   460
					SDL_FALSE,data->x,data->y,
jim@4642
   461
					    data->pressure);
jim@4655
   462
		  
jim@4642
   463
		    //printf("Synched: %i tx: %i, ty: %i\n",
jim@4642
   464
		    //	   data->finger,data->x,data->y);
jim@4642
   465
		    data->x = -1;
jim@4642
   466
		    data->y = -1;
jim@4642
   467
		    data->pressure = -1;
jim@4643
   468
		    data->finger = 0;
jim@4643
   469
		    data->up = SDL_FALSE;
jim@4642
   470
		    
jim@4642
   471
		    break;		
jim@4642
   472
		}
jim@4642
   473
	    }
jim@4642
   474
	}
jim@4642
   475
    }
jimtla@4669
   476
#endif
slouken@1951
   477
}
slouken@1951
   478
slouken@3030
   479
/* This is so wrong it hurts */
slouken@3030
   480
#define GNOME_SCREENSAVER_HACK
slouken@3030
   481
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   482
#include <unistd.h>
slouken@3030
   483
static pid_t screensaver_inhibit_pid;
slouken@3040
   484
static void
slouken@3040
   485
gnome_screensaver_disable()
slouken@3030
   486
{
slouken@3030
   487
    screensaver_inhibit_pid = fork();
slouken@3030
   488
    if (screensaver_inhibit_pid == 0) {
slouken@3031
   489
        close(0);
slouken@3031
   490
        close(1);
slouken@3031
   491
        close(2);
slouken@3030
   492
        execl("/usr/bin/gnome-screensaver-command",
slouken@3030
   493
              "gnome-screensaver-command",
slouken@3030
   494
              "--inhibit",
slouken@3030
   495
              "--reason",
slouken@3040
   496
              "GNOME screensaver doesn't respect MIT-SCREEN-SAVER", NULL);
slouken@3030
   497
        exit(2);
slouken@3030
   498
    }
slouken@3030
   499
}
slouken@3040
   500
static void
slouken@3040
   501
gnome_screensaver_enable()
slouken@3030
   502
{
slouken@3030
   503
    kill(screensaver_inhibit_pid, 15);
slouken@3030
   504
}
slouken@3030
   505
#endif
slouken@3030
   506
slouken@1951
   507
void
slouken@3025
   508
X11_SuspendScreenSaver(_THIS)
slouken@1951
   509
{
slouken@3025
   510
#if SDL_VIDEO_DRIVER_X11_SCRNSAVER
slouken@3025
   511
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@3025
   512
    int dummy;
slouken@3025
   513
    int major_version, minor_version;
slouken@1951
   514
slouken@3030
   515
    if (SDL_X11_HAVE_XSS) {
slouken@3030
   516
        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
slouken@3030
   517
        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
slouken@3030
   518
            !XScreenSaverQueryVersion(data->display,
slouken@3030
   519
                                      &major_version, &minor_version) ||
slouken@3030
   520
            major_version < 1 || (major_version == 1 && minor_version < 1)) {
slouken@3030
   521
            return;
slouken@3030
   522
        }
slouken@3030
   523
slouken@3030
   524
        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
slouken@3030
   525
        XResetScreenSaver(data->display);
slouken@1951
   526
    }
slouken@3030
   527
#endif
slouken@1951
   528
slouken@3030
   529
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   530
    if (_this->suspend_screensaver) {
slouken@3030
   531
        gnome_screensaver_disable();
slouken@3030
   532
    } else {
slouken@3030
   533
        gnome_screensaver_enable();
slouken@3025
   534
    }
slouken@3025
   535
#endif
slouken@1951
   536
}
slouken@1951
   537
slouken@1951
   538
/* vi: set ts=4 sw=4 expandtab: */