src/video/x11/SDL_x11events.c
author Jim Grandpre <jim.tla@gmail.com>
Mon, 31 May 2010 00:24:37 -0400
changeset 4645 0375d020e7e3
parent 4644 fb500b3e1717
child 4646 eea1bf53effa
permissions -rw-r--r--
Auto-detects Wacom touch devices.
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@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"
jim@4642
    31
#include "../../events/SDL_touch_c.h"
slouken@1951
    32
slouken@3241
    33
#include "SDL_syswm.h"
slouken@3241
    34
jim@4642
    35
#include <stdio.h>
jim@4642
    36
jim@4642
    37
//Touch Input/event* includes
jim@4642
    38
#include <linux/input.h>
jim@4642
    39
#include <fcntl.h>
jim@4642
    40
slouken@1951
    41
static void
slouken@1951
    42
X11_DispatchEvent(_THIS)
slouken@1951
    43
{
slouken@1951
    44
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1951
    45
    SDL_WindowData *data;
slouken@1951
    46
    XEvent xevent;
slouken@1951
    47
    int i;
slouken@1951
    48
slouken@1951
    49
    SDL_zero(xevent);           /* valgrind fix. --ryan. */
slouken@1951
    50
    XNextEvent(videodata->display, &xevent);
slouken@1951
    51
bob@2325
    52
    /* filter events catchs XIM events and sends them to the correct
bob@2325
    53
       handler */
bob@2325
    54
    if (XFilterEvent(&xevent, None) == True) {
bob@2327
    55
#if 0
bob@2328
    56
        printf("Filtered event type = %d display = %d window = %d\n",
bob@2328
    57
               xevent.type, xevent.xany.display, xevent.xany.window);
bob@2325
    58
#endif
bob@2325
    59
        return;
bob@2325
    60
    }
bob@2325
    61
slouken@1951
    62
    /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@4429
    63
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@1951
    64
        SDL_SysWMmsg wmmsg;
slouken@1951
    65
slouken@1951
    66
        SDL_VERSION(&wmmsg.version);
slouken@1951
    67
        wmmsg.subsystem = SDL_SYSWM_X11;
slouken@1951
    68
        wmmsg.event.xevent = xevent;
slouken@1951
    69
        SDL_SendSysWMEvent(&wmmsg);
slouken@1951
    70
    }
slouken@1951
    71
slouken@1951
    72
    data = NULL;
bob@2324
    73
    if (videodata && videodata->windowlist) {
bob@2324
    74
        for (i = 0; i < videodata->numwindows; ++i) {
bob@2324
    75
            if ((videodata->windowlist[i] != NULL) &&
slouken@3685
    76
                (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
bob@2324
    77
                data = videodata->windowlist[i];
bob@2324
    78
                break;
bob@2324
    79
            }
slouken@1951
    80
        }
slouken@1951
    81
    }
slouken@1951
    82
    if (!data) {
slouken@1951
    83
        return;
slouken@1951
    84
    }
bob@2327
    85
#if 0
bob@2328
    86
    printf("type = %d display = %d window = %d\n",
bob@2328
    87
           xevent.type, xevent.xany.display, xevent.xany.window);
bob@2327
    88
#endif
slouken@1951
    89
    switch (xevent.type) {
slouken@1951
    90
slouken@1951
    91
        /* Gaining mouse coverage? */
slouken@1951
    92
    case EnterNotify:{
slouken@1951
    93
#ifdef DEBUG_XEVENTS
bob@3195
    94
            printf("EnterNotify! (%d,%d,%d)\n", 
bob@3195
    95
	           xevent.xcrossing.x,
bob@3195
    96
 	           xevent.xcrossing.y,
bob@3195
    97
                   xevent.xcrossing.mode);
slouken@1951
    98
            if (xevent.xcrossing.mode == NotifyGrab)
slouken@1951
    99
                printf("Mode: NotifyGrab\n");
slouken@1951
   100
            if (xevent.xcrossing.mode == NotifyUngrab)
slouken@1951
   101
                printf("Mode: NotifyUngrab\n");
slouken@1951
   102
#endif
bob@3195
   103
#if 1
slouken@3322
   104
            /* FIXME: Should we reset data for all mice? */
slouken@3322
   105
            for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@3322
   106
                SDL_Mouse *mouse = SDL_GetMouse(i);
slouken@3685
   107
                SDL_SetMouseFocus(mouse->id, data->window);
slouken@3322
   108
            }
slouken@2940
   109
#endif
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) {
bob@3195
   125
#if 1
slouken@2940
   126
                /* FIXME: Should we reset data for all mice? */
slouken@3322
   127
	        for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@3322
   128
		    SDL_Mouse *mouse = SDL_GetMouse(i);
slouken@3322
   129
		    SDL_SetMouseFocus(mouse->id, 0);
slouken@3322
   130
	        }
slouken@2940
   131
#endif
slouken@1951
   132
            }
slouken@1951
   133
        }
slouken@1951
   134
        break;
slouken@1951
   135
slouken@1951
   136
        /* Gaining input focus? */
slouken@1951
   137
    case FocusIn:{
slouken@1951
   138
#ifdef DEBUG_XEVENTS
slouken@1951
   139
            printf("FocusIn!\n");
slouken@1951
   140
#endif
slouken@3685
   141
            SDL_SetKeyboardFocus(videodata->keyboard, data->window);
slouken@1951
   142
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   143
            if (data->ic) {
slouken@1951
   144
                XSetICFocus(data->ic);
slouken@1951
   145
            }
slouken@1951
   146
#endif
slouken@1951
   147
        }
slouken@1951
   148
        break;
slouken@1951
   149
slouken@1951
   150
        /* Losing input focus? */
slouken@1951
   151
    case FocusOut:{
slouken@1951
   152
#ifdef DEBUG_XEVENTS
slouken@1951
   153
            printf("FocusOut!\n");
slouken@1951
   154
#endif
slouken@1951
   155
            SDL_SetKeyboardFocus(videodata->keyboard, 0);
slouken@1951
   156
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   157
            if (data->ic) {
slouken@1951
   158
                XUnsetICFocus(data->ic);
slouken@1951
   159
            }
slouken@1951
   160
#endif
slouken@1951
   161
        }
slouken@1951
   162
        break;
slouken@1951
   163
slouken@1951
   164
        /* Generated upon EnterWindow and FocusIn */
slouken@1951
   165
    case KeymapNotify:{
slouken@1951
   166
#ifdef DEBUG_XEVENTS
slouken@1951
   167
            printf("KeymapNotify!\n");
slouken@1951
   168
#endif
slouken@1951
   169
            /* FIXME:
slouken@1951
   170
               X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
slouken@1951
   171
             */
slouken@1951
   172
        }
slouken@1951
   173
        break;
slouken@1951
   174
slouken@2305
   175
        /* Has the keyboard layout changed? */
slouken@2305
   176
    case MappingNotify:{
slouken@2305
   177
#ifdef DEBUG_XEVENTS
slouken@2305
   178
            printf("MappingNotify!\n");
slouken@2305
   179
#endif
slouken@2306
   180
            X11_UpdateKeymap(_this);
slouken@2305
   181
        }
slouken@2305
   182
        break;
slouken@2305
   183
slouken@1951
   184
        /* Key press? */
slouken@1951
   185
    case KeyPress:{
slouken@1951
   186
            KeyCode keycode = xevent.xkey.keycode;
bob@2300
   187
            KeySym keysym = NoSymbol;
slouken@2306
   188
            char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
bob@2325
   189
            Status status = 0;
slouken@1951
   190
slouken@1951
   191
#ifdef DEBUG_XEVENTS
slouken@1951
   192
            printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
slouken@1951
   193
#endif
bob@2299
   194
            SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED,
slouken@2305
   195
                                videodata->key_layout[keycode]);
bob@2325
   196
#if 0
slouken@2305
   197
            if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
slouken@2305
   198
                int min_keycode, max_keycode;
slouken@2305
   199
                XDisplayKeycodes(videodata->display, &min_keycode,
slouken@2305
   200
                                 &max_keycode);
slouken@2305
   201
                keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
bob@2299
   202
                fprintf(stderr,
slouken@2305
   203
                        "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
   204
                        keycode, keycode - min_keycode, keysym,
slouken@2305
   205
                        XKeysymToString(keysym));
bob@2299
   206
            }
bob@2295
   207
#endif
bob@2325
   208
            /* */
slouken@2305
   209
            SDL_zero(text);
bob@2325
   210
#ifdef X_HAVE_UTF8_STRING
bob@2325
   211
            if (data->ic) {
bob@2325
   212
                Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
slouken@2738
   213
                                  &keysym, &status);
bob@2325
   214
            }
bob@2325
   215
#else
slouken@2306
   216
            XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
bob@2325
   217
#endif
slouken@2305
   218
            if (*text) {
bob@2300
   219
                SDL_SendKeyboardText(videodata->keyboard, text);
bob@2300
   220
            }
slouken@1951
   221
        }
slouken@1951
   222
        break;
slouken@1951
   223
slouken@1951
   224
        /* Key release? */
slouken@1951
   225
    case KeyRelease:{
slouken@1951
   226
            KeyCode keycode = xevent.xkey.keycode;
slouken@1951
   227
slouken@1951
   228
#ifdef DEBUG_XEVENTS
slouken@1951
   229
            printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
slouken@1951
   230
#endif
bob@2295
   231
            SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED,
slouken@2305
   232
                                videodata->key_layout[keycode]);
slouken@1951
   233
        }
slouken@1951
   234
        break;
slouken@1951
   235
slouken@1951
   236
        /* Have we been iconified? */
slouken@1951
   237
    case UnmapNotify:{
slouken@1951
   238
#ifdef DEBUG_XEVENTS
slouken@1951
   239
            printf("UnmapNotify!\n");
slouken@1951
   240
#endif
slouken@3685
   241
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@3685
   242
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1951
   243
        }
slouken@1951
   244
        break;
slouken@1951
   245
slouken@1951
   246
        /* Have we been restored? */
slouken@1951
   247
    case MapNotify:{
slouken@1951
   248
#ifdef DEBUG_XEVENTS
slouken@1951
   249
            printf("MapNotify!\n");
slouken@1951
   250
#endif
slouken@3685
   251
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@3685
   252
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 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@3685
   262
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
slouken@1951
   263
                                xevent.xconfigure.x, xevent.xconfigure.y);
slouken@3685
   264
            SDL_SendWindowEvent(data->window, 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@3685
   275
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1951
   276
            }
slouken@1951
   277
        }
slouken@1951
   278
        break;
slouken@1951
   279
slouken@1951
   280
        /* Do we need to refresh ourselves? */
slouken@1951
   281
    case Expose:{
slouken@1951
   282
#ifdef DEBUG_XEVENTS
slouken@1951
   283
            printf("Expose (count = %d)\n", xevent.xexpose.count);
slouken@1951
   284
#endif
slouken@3685
   285
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
slouken@1951
   286
        }
slouken@1951
   287
        break;
slouken@1951
   288
slouken@1951
   289
    default:{
slouken@2942
   290
            for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@2942
   291
                SDL_Mouse *mouse;
slouken@3003
   292
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@2942
   293
                X11_MouseData *data;
slouken@3003
   294
#endif
slouken@2940
   295
slouken@2942
   296
                mouse = SDL_GetMouse(i);
slouken@3003
   297
                if (!mouse->driverdata) {
slouken@2992
   298
                    switch (xevent.type) {
slouken@2992
   299
                    case MotionNotify:
slouken@2992
   300
#ifdef DEBUG_MOTION
slouken@2997
   301
                        printf("X11 motion: %d,%d\n", xevent.xmotion.x,
slouken@2997
   302
                               xevent.xmotion.y);
slouken@2992
   303
#endif
slouken@2997
   304
                        SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x,
slouken@2997
   305
                                            xevent.xmotion.y, 0);
slouken@2992
   306
                        break;
slouken@2992
   307
slouken@2992
   308
                    case ButtonPress:
slouken@2997
   309
                        SDL_SendMouseButton(mouse->id, SDL_PRESSED,
slouken@2997
   310
                                            xevent.xbutton.button);
slouken@2992
   311
                        break;
slouken@2992
   312
slouken@2992
   313
                    case ButtonRelease:
slouken@2997
   314
                        SDL_SendMouseButton(mouse->id, SDL_RELEASED,
slouken@2997
   315
                                            xevent.xbutton.button);
slouken@2992
   316
                        break;
slouken@2992
   317
                    }
slouken@2942
   318
                    continue;
slouken@2942
   319
                }
slouken@3003
   320
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@3003
   321
                data = (X11_MouseData *) mouse->driverdata;
slouken@3003
   322
                if (xevent.type == data->motion) {
slouken@2942
   323
                    XDeviceMotionEvent *move =
slouken@2942
   324
                        (XDeviceMotionEvent *) & xevent;
slouken@2942
   325
#ifdef DEBUG_MOTION
slouken@2942
   326
                    printf("X11 motion: %d,%d\n", move->x, move->y);
slouken@2942
   327
#endif
slouken@2942
   328
                    SDL_SendMouseMotion(move->deviceid, 0, move->x, move->y,
slouken@2942
   329
                                        move->axis_data[2]);
slouken@2942
   330
                    return;
slouken@2942
   331
                }
slouken@3003
   332
                if (xevent.type == data->button_pressed) {
slouken@2942
   333
                    XDeviceButtonPressedEvent *pressed =
slouken@2942
   334
                        (XDeviceButtonPressedEvent *) & xevent;
slouken@2942
   335
                    SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED,
slouken@2942
   336
                                        pressed->button);
slouken@2942
   337
                    return;
slouken@2942
   338
                }
slouken@3003
   339
                if (xevent.type == data->button_released) {
slouken@2942
   340
                    XDeviceButtonReleasedEvent *released =
slouken@2942
   341
                        (XDeviceButtonReleasedEvent *) & xevent;
slouken@2942
   342
                    SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
slouken@2942
   343
                                        released->button);
slouken@2942
   344
                    return;
slouken@2942
   345
                }
slouken@2942
   346
                if (xevent.type == data->proximity_in) {
slouken@2942
   347
                    XProximityNotifyEvent *proximity =
slouken@2942
   348
                        (XProximityNotifyEvent *) & xevent;
slouken@2942
   349
                    SDL_SendProximity(proximity->deviceid, proximity->x,
slouken@2942
   350
                                      proximity->y, SDL_PROXIMITYIN);
slouken@2942
   351
                    return;
slouken@2942
   352
                }
slouken@2942
   353
                if (xevent.type == data->proximity_out) {
slouken@2942
   354
                    XProximityNotifyEvent *proximity =
slouken@2942
   355
                        (XProximityNotifyEvent *) & xevent;
slouken@2942
   356
                    SDL_SendProximity(proximity->deviceid, proximity->x,
slouken@2942
   357
                                      proximity->y, SDL_PROXIMITYOUT);
slouken@2942
   358
                    return;
slouken@2942
   359
                }
slouken@3003
   360
#endif
slouken@2940
   361
            }
slouken@1951
   362
#ifdef DEBUG_XEVENTS
slouken@2940
   363
            printf("Unhandled event %d\n", xevent.type);
slouken@1951
   364
#endif
slouken@1951
   365
        }
slouken@1951
   366
        break;
slouken@1951
   367
    }
slouken@1951
   368
}
slouken@1951
   369
slouken@1951
   370
/* Ack!  XPending() actually performs a blocking read if no events available */
slouken@1951
   371
int
slouken@1951
   372
X11_Pending(Display * display)
slouken@1951
   373
{
slouken@1951
   374
    /* Flush the display connection and look to see if events are queued */
slouken@1951
   375
    XFlush(display);
slouken@1951
   376
    if (XEventsQueued(display, QueuedAlready)) {
slouken@1951
   377
        return (1);
slouken@1951
   378
    }
slouken@1951
   379
slouken@1951
   380
    /* More drastic measures are required -- see if X is ready to talk */
slouken@1951
   381
    {
slouken@1951
   382
        static struct timeval zero_time;        /* static == 0 */
slouken@1951
   383
        int x11_fd;
slouken@1951
   384
        fd_set fdset;
slouken@1951
   385
slouken@1951
   386
        x11_fd = ConnectionNumber(display);
slouken@1951
   387
        FD_ZERO(&fdset);
slouken@1951
   388
        FD_SET(x11_fd, &fdset);
slouken@1951
   389
        if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
slouken@1951
   390
            return (XPending(display));
slouken@1951
   391
        }
slouken@1951
   392
    }
slouken@1951
   393
slouken@1951
   394
    /* Oh well, nothing is ready .. */
slouken@1951
   395
    return (0);
slouken@1951
   396
}
slouken@1951
   397
slouken@1951
   398
void
slouken@1951
   399
X11_PumpEvents(_THIS)
slouken@1951
   400
{
slouken@1951
   401
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1951
   402
slouken@3025
   403
    /* Update activity every 30 seconds to prevent screensaver */
slouken@3025
   404
    if (_this->suspend_screensaver) {
slouken@3025
   405
        Uint32 now = SDL_GetTicks();
slouken@3025
   406
        if (!data->screensaver_activity ||
slouken@3040
   407
            (int) (now - data->screensaver_activity) >= 30000) {
slouken@3025
   408
            XResetScreenSaver(data->display);
slouken@3025
   409
            data->screensaver_activity = now;
slouken@3025
   410
        }
slouken@3025
   411
    }
slouken@3025
   412
slouken@1951
   413
    /* Keep processing pending events */
slouken@1951
   414
    while (X11_Pending(data->display)) {
slouken@1951
   415
        X11_DispatchEvent(_this);
slouken@1951
   416
    }
jim@4640
   417
jim@4640
   418
jim@4642
   419
    /* Process Touch events - TODO When X gets touch support, use that instead*/
jim@4642
   420
    int i = 0,rd;
jim@4643
   421
    char name[256];
jim@4642
   422
    struct input_event ev[64];
jim@4642
   423
    int size = sizeof (struct input_event);
jim@4645
   424
jim@4642
   425
    for(i = 0;i < SDL_GetNumTouch();++i) {
jim@4642
   426
	SDL_Touch* touch = SDL_GetTouchIndex(i);
jim@4642
   427
	if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
jim@4642
   428
	EventTouchData* data;
jim@4645
   429
	data = (EventTouchData*)(touch->driverdata);
jim@4645
   430
	if(data == NULL) {
jim@4645
   431
	  printf("No driver data\n");
jim@4645
   432
	  continue;
jim@4642
   433
	}
jim@4642
   434
	if(data->eventStream <= 0) 
jim@4642
   435
	    printf("Error: Couldn't open stream\n");
jim@4642
   436
	rd = read(data->eventStream, ev, size * 64);
jim@4642
   437
	//printf("Got %i/%i bytes\n",rd,size);
jim@4642
   438
	if(rd >= size) {
jim@4642
   439
	    for (i = 0; i < rd / sizeof(struct input_event); i++) {
jim@4642
   440
		switch (ev[i].type) {
jim@4642
   441
		case EV_ABS:
jim@4642
   442
		    //printf("Got position x: %i!\n",data->x);
jim@4644
   443
		    switch (ev[i].code) {
jim@4644
   444
			case ABS_X:
jim@4644
   445
			    data->x = ev[i].value;
jim@4644
   446
			    break;
jim@4644
   447
			case ABS_Y:
jim@4644
   448
			    data->y = ev[i].value;
jim@4644
   449
			    break;
jim@4644
   450
			case ABS_PRESSURE:
jim@4644
   451
			    data->pressure = ev[i].value;
jim@4644
   452
			    break;
jim@4644
   453
			case ABS_MISC:
jim@4644
   454
			    data->up = SDL_TRUE;
jim@4644
   455
			    data->finger = ev[i].value;
jim@4644
   456
			    break;
jim@4644
   457
			}
jim@4642
   458
		    break;
jim@4642
   459
		case EV_MSC:
jim@4642
   460
		    if(ev[i].code == MSC_SERIAL)
jim@4642
   461
			data->finger = ev[i].value;
jim@4642
   462
		    break;
jim@4642
   463
		case EV_SYN:
jim@4645
   464
  		    printf("Id: %i\n",touch->id); 
jim@4642
   465
		    if(data->x >= 0 || data->y >= 0)
jim@4642
   466
			SDL_SendTouchMotion(touch->id,data->finger, 
jim@4642
   467
					    SDL_FALSE,data->x,data->y,
jim@4642
   468
					    data->pressure);
jim@4643
   469
		    if(data->up) 
jim@4643
   470
			SDL_SendFingerDown(touch->id,data->finger,
jim@4643
   471
					   SDL_FALSE,data->x,data->y,
jim@4643
   472
					   data->pressure);
jim@4642
   473
		    //printf("Synched: %i tx: %i, ty: %i\n",
jim@4642
   474
		    //	   data->finger,data->x,data->y);
jim@4642
   475
		    data->x = -1;
jim@4642
   476
		    data->y = -1;
jim@4642
   477
		    data->pressure = -1;
jim@4643
   478
		    data->finger = 0;
jim@4643
   479
		    data->up = SDL_FALSE;
jim@4642
   480
		    
jim@4642
   481
		    break;		
jim@4642
   482
		}
jim@4642
   483
	    }
jim@4642
   484
	}
jim@4642
   485
    }
slouken@1951
   486
}
slouken@1951
   487
slouken@3030
   488
/* This is so wrong it hurts */
slouken@3030
   489
#define GNOME_SCREENSAVER_HACK
slouken@3030
   490
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   491
#include <unistd.h>
slouken@3030
   492
static pid_t screensaver_inhibit_pid;
slouken@3040
   493
static void
slouken@3040
   494
gnome_screensaver_disable()
slouken@3030
   495
{
slouken@3030
   496
    screensaver_inhibit_pid = fork();
slouken@3030
   497
    if (screensaver_inhibit_pid == 0) {
slouken@3031
   498
        close(0);
slouken@3031
   499
        close(1);
slouken@3031
   500
        close(2);
slouken@3030
   501
        execl("/usr/bin/gnome-screensaver-command",
slouken@3030
   502
              "gnome-screensaver-command",
slouken@3030
   503
              "--inhibit",
slouken@3030
   504
              "--reason",
slouken@3040
   505
              "GNOME screensaver doesn't respect MIT-SCREEN-SAVER", NULL);
slouken@3030
   506
        exit(2);
slouken@3030
   507
    }
slouken@3030
   508
}
slouken@3040
   509
static void
slouken@3040
   510
gnome_screensaver_enable()
slouken@3030
   511
{
slouken@3030
   512
    kill(screensaver_inhibit_pid, 15);
slouken@3030
   513
}
slouken@3030
   514
#endif
slouken@3030
   515
slouken@1951
   516
void
slouken@3025
   517
X11_SuspendScreenSaver(_THIS)
slouken@1951
   518
{
slouken@3025
   519
#if SDL_VIDEO_DRIVER_X11_SCRNSAVER
slouken@3025
   520
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@3025
   521
    int dummy;
slouken@3025
   522
    int major_version, minor_version;
slouken@1951
   523
slouken@3030
   524
    if (SDL_X11_HAVE_XSS) {
slouken@3030
   525
        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
slouken@3030
   526
        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
slouken@3030
   527
            !XScreenSaverQueryVersion(data->display,
slouken@3030
   528
                                      &major_version, &minor_version) ||
slouken@3030
   529
            major_version < 1 || (major_version == 1 && minor_version < 1)) {
slouken@3030
   530
            return;
slouken@3030
   531
        }
slouken@3030
   532
slouken@3030
   533
        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
slouken@3030
   534
        XResetScreenSaver(data->display);
slouken@1951
   535
    }
slouken@3030
   536
#endif
slouken@1951
   537
slouken@3030
   538
#ifdef GNOME_SCREENSAVER_HACK
slouken@3030
   539
    if (_this->suspend_screensaver) {
slouken@3030
   540
        gnome_screensaver_disable();
slouken@3030
   541
    } else {
slouken@3030
   542
        gnome_screensaver_enable();
slouken@3025
   543
    }
slouken@3025
   544
#endif
slouken@1951
   545
}
slouken@1951
   546
slouken@1951
   547
/* vi: set ts=4 sw=4 expandtab: */