src/video/x11/SDL_x11events.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 03 Oct 2012 13:37:44 -0700
changeset 6542 5c1b8ed19212
parent 6504 100c49578dba
child 6637 31e3f5b04120
permissions -rw-r--r--
Keep track of the configure events we've received from the X server. When programmatically resizing a window on Unity 3D, we'll get a move event with the old size before we get a size event with the new size, and we don't want to clobber our internal state with the old size.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
     7
  arising from the use of this software.
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    11
  freely, subject to the following restrictions:
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5530
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    24
2046
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
    25
#include <sys/types.h>
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
    26
#include <sys/time.h>
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    27
#include <signal.h>
2046
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
    28
#include <unistd.h>
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
    29
#include <limits.h> /* For INT_MAX */
2046
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
    30
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "SDL_x11video.h"
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
    32
#include "SDL_x11video.h"
4934
a5b86644c208 Fixed compiling X11 touch interface
Sam Lantinga <slouken@libsdl.org>
parents: 4902
diff changeset
    33
#include "SDL_x11touch.h"
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6311
diff changeset
    34
#include "SDL_x11xinput2.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "../../events/SDL_events_c.h"
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    36
#include "../../events/SDL_mouse_c.h"
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    37
#include "../../events/SDL_touch_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    39
#include "SDL_timer.h"
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3195
diff changeset
    40
#include "SDL_syswm.h"
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3195
diff changeset
    41
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    42
#include <stdio.h>
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    43
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4669
diff changeset
    44
#ifdef SDL_INPUT_LINUXEV
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    45
//Touch Input/event* includes
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    46
#include <linux/input.h>
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    47
#include <fcntl.h>
4669
62e6a6e9720b Fixed x11 compile bugs.
jimtla
parents: 4661
diff changeset
    48
#endif
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
    49
6474
39087ac884d7 Added debug define (commented out)
Sam Lantinga <slouken@libsdl.org>
parents: 6432
diff changeset
    50
/*#define DEBUG_XEVENTS*/
39087ac884d7 Added debug define (commented out)
Sam Lantinga <slouken@libsdl.org>
parents: 6432
diff changeset
    51
4565
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    52
/* Check to see if this is a repeated key.
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    53
   (idea shamelessly lifted from GII -- thanks guys! :)
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    54
 */
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    55
static SDL_bool X11_KeyRepeat(Display *display, XEvent *event)
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    56
{
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    57
    XEvent peekevent;
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    58
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    59
    if (XPending(display)) {
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    60
        XPeekEvent(display, &peekevent);
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    61
        if ((peekevent.type == KeyPress) &&
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    62
            (peekevent.xkey.keycode == event->xkey.keycode) &&
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    63
            ((peekevent.xkey.time-event->xkey.time) < 2)) {
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    64
            return SDL_TRUE;
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    65
        }
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    66
    }
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    67
    return SDL_FALSE;
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    68
}
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
    69
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    70
static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    71
{
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    72
    XEvent peekevent;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    73
    if (XPending(display)) {
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    74
        /* according to the xlib docs, no specific mouse wheel events exist.
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    75
           however, mouse wheel events trigger a button press and a button release
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    76
           immediately. thus, checking if the same button was released at the same
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    77
           time as it was pressed, should be an adequate hack to derive a mouse 
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    78
           wheel event. */
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    79
        XPeekEvent(display,&peekevent);
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    80
        if ((peekevent.type           == ButtonRelease) &&
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    81
            (peekevent.xbutton.button == event->xbutton.button) &&
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    82
            (peekevent.xbutton.time   == event->xbutton.time)) {
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    83
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    84
            /* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse,
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    85
               Button4 maps to wheel up, Button5 maps to wheel down. */
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    86
            if (event->xbutton.button == Button4) {
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    87
                *ticks = 1;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    88
            }
6184
976d9ec6c290 Fixed bug 1305 - mouse wheel scroll-down event created when mouse wheel is pressed down
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    89
            else if (event->xbutton.button == Button5) {
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    90
                *ticks = -1;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    91
            }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    92
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    93
            /* remove the following release event, as this is now a wheel event */
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    94
            XNextEvent(display,&peekevent);
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    95
            return SDL_TRUE;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    96
        }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    97
    }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    98
    return SDL_FALSE;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    99
}
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   100
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   101
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   102
#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   103
static void X11_HandleGenericEvent(SDL_VideoData *videodata,XEvent event)
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   104
{
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   105
    XGenericEventCookie *cookie = &event.xcookie;
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   106
    XGetEventData(videodata->display, cookie);
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6311
diff changeset
   107
    X11_HandleXinput2Event(videodata,cookie);
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   108
    XFreeEventData(videodata->display,cookie);
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   109
}
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   110
#endif /* SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   111
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   112
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   113
static void
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   114
X11_DispatchFocusIn(SDL_WindowData *data)
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   115
{
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   116
#ifdef DEBUG_XEVENTS
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   117
    printf("window %p: Dispatching FocusIn\n", data);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   118
#endif
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   119
    SDL_SetKeyboardFocus(data->window);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   120
#ifdef X_HAVE_UTF8_STRING
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   121
    if (data->ic) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   122
        XSetICFocus(data->ic);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   123
    }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   124
#endif
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   125
}
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   126
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   127
static void
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   128
X11_DispatchFocusOut(SDL_WindowData *data)
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   129
{
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   130
#ifdef DEBUG_XEVENTS
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   131
    printf("window %p: Dispatching FocusOut\n", data);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   132
#endif
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   133
    SDL_SetKeyboardFocus(NULL);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   134
#ifdef X_HAVE_UTF8_STRING
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   135
    if (data->ic) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   136
        XUnsetICFocus(data->ic);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   137
    }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   138
#endif
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   139
}
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   140
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   141
static void
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   142
X11_DispatchMapNotify(SDL_WindowData *data)
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   143
{
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   144
    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   145
    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   146
}
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   147
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   148
static void
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   149
X11_DispatchUnmapNotify(SDL_WindowData *data)
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   150
{
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   151
    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   152
    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   153
}
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   154
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
static void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
X11_DispatchEvent(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   159
    Display *display = videodata->display;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    XEvent xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    int i;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    SDL_zero(xevent);           /* valgrind fix. --ryan. */
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   165
    XNextEvent(display, &xevent);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   167
    /* filter events catchs XIM events and sends them to the correct
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   168
       handler */
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   169
    if (XFilterEvent(&xevent, None) == True) {
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2326
diff changeset
   170
#if 0
2328
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2327
diff changeset
   171
        printf("Filtered event type = %d display = %d window = %d\n",
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2327
diff changeset
   172
               xevent.type, xevent.xany.display, xevent.xany.window);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   173
#endif
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   174
        return;
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   175
    }
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   176
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    /* Send a SDL_SYSWMEVENT if the application wants them */
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   178
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
        SDL_SysWMmsg wmmsg;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
        SDL_VERSION(&wmmsg.version);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
        wmmsg.subsystem = SDL_SYSWM_X11;
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4934
diff changeset
   183
        wmmsg.msg.x11.event = xevent;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
        SDL_SendSysWMEvent(&wmmsg);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   187
#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   188
    if(xevent.type == GenericEvent) {
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   189
        X11_HandleGenericEvent(videodata,xevent);
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   190
        return;
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   191
    }
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   192
#endif
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   193
6476
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   194
#if 0
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   195
    printf("type = %d display = %d window = %d\n",
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   196
           xevent.type, xevent.xany.display, xevent.xany.window);
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   197
#endif
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   198
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    data = NULL;
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   200
    if (videodata && videodata->windowlist) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   201
        for (i = 0; i < videodata->numwindows; ++i) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   202
            if ((videodata->windowlist[i] != NULL) &&
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3322
diff changeset
   203
                (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   204
                data = videodata->windowlist[i];
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   205
                break;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   206
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
        return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
    }
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   212
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
    switch (xevent.type) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
        /* Gaining mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
    case EnterNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   218
            printf("window %p: EnterNotify! (%d,%d,%d)\n", data,
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   219
                   xevent.xcrossing.x,
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   220
                   xevent.xcrossing.y,
3195
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
   221
                   xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
            if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
                printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
            if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
                printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
#endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   227
            SDL_SetMouseFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
        /* Losing mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    case LeaveNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   233
            printf("window %p: LeaveNotify! (%d,%d,%d)\n", data,
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   234
                   xevent.xcrossing.x,
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   235
                   xevent.xcrossing.y,
3195
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
   236
                   xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
            if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
                printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
            if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
                printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
#endif
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   242
            if (xevent.xcrossing.mode != NotifyGrab &&
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   243
                xevent.xcrossing.mode != NotifyUngrab &&
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   244
                xevent.xcrossing.detail != NotifyInferior) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   245
                SDL_SetMouseFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
        /* Gaining input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
    case FocusIn:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   253
            printf("window %p: FocusIn!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
#endif
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   255
            data->pending_focus = PENDING_FOCUS_IN;
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   256
            data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_IN_TIME;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
        /* Losing input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
    case FocusOut:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   263
            printf("window %p: FocusOut!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
#endif
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   265
            data->pending_focus = PENDING_FOCUS_OUT;
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   266
            data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_OUT_TIME;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
        /* Generated upon EnterWindow and FocusIn */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
    case KeymapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   273
            printf("window %p: KeymapNotify!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
            /* FIXME:
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
               X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
             */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   281
        /* Has the keyboard layout changed? */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   282
    case MappingNotify:{
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   283
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   284
            printf("window %p: MappingNotify!\n", data);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   285
#endif
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   286
            X11_UpdateKeymap(_this);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   287
        }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   288
        break;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   289
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
        /* Key press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    case KeyPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
            KeyCode keycode = xevent.xkey.keycode;
2300
c97ad1abe05b Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents: 2299
diff changeset
   293
            KeySym keysym = NoSymbol;
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   294
            char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   295
            Status status = 0;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   298
            printf("window %p: KeyPress (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
#endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   300
            SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
4535
ce811c9247da Added back in a little more debugging for the X11 keyboard code
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   301
#if 1
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5603
diff changeset
   302
            if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN) {
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   303
                int min_keycode, max_keycode;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   304
                XDisplayKeycodes(display, &min_keycode, &max_keycode);
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6316
diff changeset
   305
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6316
diff changeset
   306
                keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6316
diff changeset
   307
#else
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   308
                keysym = XKeycodeToKeysym(display, keycode, 0);
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6316
diff changeset
   309
#endif
2299
a7cbc25071b6 Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
Bob Pendleton <bob@pendleton.com>
parents: 2295
diff changeset
   310
                fprintf(stderr,
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
   311
                        "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%lX (%s).\n",
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   312
                        keycode, keycode - min_keycode, keysym,
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   313
                        XKeysymToString(keysym));
2299
a7cbc25071b6 Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
Bob Pendleton <bob@pendleton.com>
parents: 2295
diff changeset
   314
            }
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 2046
diff changeset
   315
#endif
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   316
            /* */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   317
            SDL_zero(text);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   318
#ifdef X_HAVE_UTF8_STRING
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   319
            if (data->ic) {
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   320
                Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
2738
79c1bd651f04 Fixed a bunch of compile warnings on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
   321
                                  &keysym, &status);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   322
            }
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   323
#else
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   324
            XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   325
#endif
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   326
            if (*text) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   327
                SDL_SendKeyboardText(text);
2300
c97ad1abe05b Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents: 2299
diff changeset
   328
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
        /* Key release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    case KeyRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
            KeyCode keycode = xevent.xkey.keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   337
            printf("window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
#endif
4565
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   339
            if (X11_KeyRepeat(display, &xevent)) {
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   340
                /* We're about to get a repeated key down, ignore the key up */
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   341
                break;
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   342
            }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   343
            SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
        /* Have we been iconified? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
    case UnmapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   350
            printf("window %p: UnmapNotify!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
#endif
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   352
            X11_DispatchUnmapNotify(data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
        /* Have we been restored? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
    case MapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   359
            printf("window %p: MapNotify!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
#endif
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   361
            X11_DispatchMapNotify(data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
        /* Have we been resized or moved? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
    case ConfigureNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
#ifdef DEBUG_XEVENTS
6542
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   368
            printf("window %p: ConfigureNotify! (position: %d,%d, size: %dx%d)\n", data,
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   369
                   xevent.xconfigure.x, xevent.xconfigure.y,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
                   xevent.xconfigure.width, xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
#endif
6542
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   372
            if (xevent.xconfigure.x != data->last_xconfigure.x ||
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   373
                xevent.xconfigure.y != data->last_xconfigure.y) {
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   374
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   375
                                    xevent.xconfigure.x, xevent.xconfigure.y);
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   376
            }
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   377
            if (xevent.xconfigure.width != data->last_xconfigure.width ||
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   378
                xevent.xconfigure.height != data->last_xconfigure.height) {
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   379
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   380
                                    xevent.xconfigure.width,
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   381
                                    xevent.xconfigure.height);
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   382
            }
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   383
            data->last_xconfigure = xevent.xconfigure;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
        /* Have we been requested to quit (or another client message?) */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
    case ClientMessage:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
            if ((xevent.xclient.format == 32) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
                (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3322
diff changeset
   392
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
        /* Do we need to refresh ourselves? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    case Expose:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   400
            printf("window %p: Expose (count = %d)\n", data, xevent.xexpose.count);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
#endif
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3322
diff changeset
   402
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   406
    case MotionNotify:{
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   407
            SDL_Mouse *mouse = SDL_GetMouse();  
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   408
            if(!mouse->relative_mode) {
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   409
#ifdef DEBUG_MOTION
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   410
                printf("window %p: X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   411
#endif
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   412
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   413
                SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   414
            }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   415
        }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   416
        break;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   417
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   418
    case ButtonPress:{
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   419
            int ticks = 0;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   420
            if (X11_IsWheelEvent(display,&xevent,&ticks) == SDL_TRUE) {
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   421
                SDL_SendMouseWheel(data->window, 0, ticks);
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   422
            }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   423
            else {
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   424
                SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button);
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   425
            }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   426
        }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   427
        break;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   428
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   429
    case ButtonRelease:{
4484
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
   430
            SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button);
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   431
        }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   432
        break;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   433
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   434
    case PropertyNotify:{
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   435
#ifdef DEBUG_XEVENTS
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   436
            unsigned char *propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   437
            int status, real_format;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   438
            Atom real_type;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   439
            unsigned long items_read, items_left, i;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   440
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   441
            char *name = XGetAtomName(display, xevent.xproperty.atom);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   442
            if (name) {
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   443
                printf("window %p: PropertyNotify: %s %s\n", data, name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed");
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   444
                XFree(name);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   445
            }
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   446
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   447
            status = XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
   448
            if (status == Success && items_read > 0) {
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   449
                if (real_type == XA_INTEGER) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   450
                    int *values = (int *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   451
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   452
                    printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   453
                    for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   454
                        printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   455
                    }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   456
                    printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   457
                } else if (real_type == XA_CARDINAL) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   458
                    if (real_format == 32) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   459
                        Uint32 *values = (Uint32 *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   460
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   461
                        printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   462
                        for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   463
                            printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   464
                        }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   465
                        printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   466
                    } else if (real_format == 16) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   467
                        Uint16 *values = (Uint16 *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   468
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   469
                        printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   470
                        for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   471
                            printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   472
                        }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   473
                        printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   474
                    } else if (real_format == 8) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   475
                        Uint8 *values = (Uint8 *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   476
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   477
                        printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   478
                        for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   479
                            printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   480
                        }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   481
                        printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   482
                    }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   483
                } else if (real_type == XA_STRING ||
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   484
                           real_type == videodata->UTF8_STRING) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   485
                    printf("{ \"%s\" }\n", propdata);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   486
                } else if (real_type == XA_ATOM) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   487
                    Atom *atoms = (Atom *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   488
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   489
                    printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   490
                    for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   491
                        char *name = XGetAtomName(display, atoms[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   492
                        if (name) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   493
                            printf(" %s", name);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   494
                            XFree(name);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   495
                        }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   496
                    }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   497
                    printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   498
                } else {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   499
                    char *name = XGetAtomName(display, real_type);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   500
                    printf("Unknown type: %ld (%s)\n", real_type, name ? name : "UNKNOWN");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   501
                    if (name) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   502
                        XFree(name);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   503
                    }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   504
                }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   505
            }
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   506
            if (status == Success) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   507
                XFree(propdata);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   508
            }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   509
#endif /* DEBUG_XEVENTS */
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   510
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   511
            if (xevent.xproperty.atom == data->videodata->_NET_WM_STATE) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   512
                /* Get the new state from the window manager.
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   513
                   Compositing window managers can alter visibility of windows
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   514
                   without ever mapping / unmapping them, so we handle that here,
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   515
                   because they use the NETWM protocol to notify us of changes.
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   516
                 */
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   517
                Uint32 flags = X11_GetNetWMState(_this, xevent.xproperty.window);
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   518
                if ((flags^data->window->flags) & SDL_WINDOW_HIDDEN) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   519
                    if (flags & SDL_WINDOW_HIDDEN) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   520
                        X11_DispatchUnmapNotify(data);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   521
                    } else {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   522
                        X11_DispatchMapNotify(data);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   523
                    }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   524
                }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6476
diff changeset
   525
            }
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   526
        }
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   527
        break;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
   528
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   529
    /* Copy the selection from XA_CUT_BUFFER0 to the requested property */
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   530
    case SelectionRequest: {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   531
            XSelectionRequestEvent *req;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   532
            XEvent sevent;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   533
            int seln_format;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   534
            unsigned long nbytes;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   535
            unsigned long overflow;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   536
            unsigned char *seln_data;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   537
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   538
            req = &xevent.xselectionrequest;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   539
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   540
            printf("window %p: SelectionRequest (requestor = %ld, target = %ld)\n", data,
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   541
                req->requestor, req->target);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   542
#endif
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   543
4524
a256e1dadf3f Zero any fields not explicitly filled in.
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   544
            SDL_zero(sevent);
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
   545
            sevent.xany.type = SelectionNotify;
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   546
            sevent.xselection.selection = req->selection;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   547
            sevent.xselection.target = None;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   548
            sevent.xselection.property = None;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   549
            sevent.xselection.requestor = req->requestor;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   550
            sevent.xselection.time = req->time;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   551
            if (XGetWindowProperty(display, DefaultRootWindow(display),
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   552
                    XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   553
                    &sevent.xselection.target, &seln_format, &nbytes,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   554
                    &overflow, &seln_data) == Success) {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   555
                if (sevent.xselection.target == req->target) {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   556
                    XChangeProperty(display, req->requestor, req->property,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   557
                        sevent.xselection.target, seln_format, PropModeReplace,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   558
                        seln_data, nbytes);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   559
                    sevent.xselection.property = req->property;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   560
                }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   561
                XFree(seln_data);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   562
            }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   563
            XSendEvent(display, req->requestor, False, 0, &sevent);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   564
            XSync(display, False);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   565
        }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   566
        break;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   567
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   568
    case SelectionNotify: {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   569
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   570
            printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data,
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   571
                xevent.xselection.requestor, xevent.xselection.target);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   572
#endif
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   573
            videodata->selection_waiting = SDL_FALSE;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   574
        }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   575
        break;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
   576
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   577
    default:{
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
#ifdef DEBUG_XEVENTS
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   579
            printf("window %p: Unhandled event %d\n", data, xevent.type);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   586
static void
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   587
X11_HandleFocusChanges(_THIS)
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   588
{
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   589
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   590
    int i;
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   591
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   592
    if (videodata && videodata->windowlist) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   593
        for (i = 0; i < videodata->numwindows; ++i) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   594
            SDL_WindowData *data = videodata->windowlist[i];
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   595
            if (data && data->pending_focus != PENDING_FOCUS_NONE) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   596
                Uint32 now = SDL_GetTicks();
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   597
                if ( (int)(data->pending_focus_time-now) <= 0 ) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   598
                    if ( data->pending_focus == PENDING_FOCUS_IN ) {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   599
                        X11_DispatchFocusIn(data);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   600
                    } else {
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   601
                        X11_DispatchFocusOut(data);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   602
                    }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   603
                    data->pending_focus = PENDING_FOCUS_NONE;
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   604
                }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   605
            }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   606
        }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   607
    }
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   608
}
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
/* Ack!  XPending() actually performs a blocking read if no events available */
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   610
static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
X11_Pending(Display * display)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
    /* Flush the display connection and look to see if events are queued */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
    XFlush(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
    if (XEventsQueued(display, QueuedAlready)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
        return (1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
    /* More drastic measures are required -- see if X is ready to talk */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
    {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
        static struct timeval zero_time;        /* static == 0 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   622
        int x11_fd;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
        fd_set fdset;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
        x11_fd = ConnectionNumber(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
        FD_ZERO(&fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
        FD_SET(x11_fd, &fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
        if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
            return (XPending(display));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
    /* Oh well, nothing is ready .. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
    return (0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5603
diff changeset
   637
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5603
diff changeset
   638
/* !!! FIXME: this should be exposed in a header, or something. */
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5603
diff changeset
   639
int SDL_GetNumTouch(void);
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5603
diff changeset
   640
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5603
diff changeset
   641
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
X11_PumpEvents(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   645
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   647
    /* Update activity every 30 seconds to prevent screensaver */
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   648
    if (_this->suspend_screensaver) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   649
        Uint32 now = SDL_GetTicks();
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   650
        if (!data->screensaver_activity ||
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
   651
            (int) (now - data->screensaver_activity) >= 30000) {
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   652
            XResetScreenSaver(data->display);
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   653
            data->screensaver_activity = now;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   654
        }
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6316
diff changeset
   655
    }   
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   656
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
    /* Keep processing pending events */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   658
    while (X11_Pending(data->display)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
        X11_DispatchEvent(_this);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
    }
6504
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   661
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   662
    /* FIXME: Only need to do this when there are pending focus changes */
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   663
    X11_HandleFocusChanges(_this);
100c49578dba We need to queue the focus in/out changes because they may occur during video mode changes and we can respond to them by triggering more mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 6487
diff changeset
   664
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6311
diff changeset
   665
    /*Dont process evtouch events if XInput2 multitouch is supported*/
6432
de49d33b829e Fixed typo in function name.
Ryan C. Gordon <icculus@icculus.org>
parents: 6318
diff changeset
   666
    if(X11_Xinput2IsMultitouchSupported()) {
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6311
diff changeset
   667
        return;
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6311
diff changeset
   668
    }
4640
f068a6dfc858 Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
Jim Grandpre <jim.tla@gmail.com>
parents: 4429
diff changeset
   669
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4669
diff changeset
   670
#ifdef SDL_INPUT_LINUXEV
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6311
diff changeset
   671
    /* Process Touch events*/
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   672
    int i = 0,rd;
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   673
    struct input_event ev[64];
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   674
    int size = sizeof (struct input_event);
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
   675
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   676
/* !!! FIXME: clean the tabstops out of here. */
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   677
    for(i = 0;i < SDL_GetNumTouch();++i) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   678
	SDL_Touch* touch = SDL_GetTouchIndex(i);
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   679
	if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   680
	EventTouchData* data;
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
   681
	data = (EventTouchData*)(touch->driverdata);
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
   682
	if(data == NULL) {
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
   683
	  printf("No driver data\n");
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
   684
	  continue;
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   685
	}
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   686
	if(data->eventStream <= 0) 
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   687
	    printf("Error: Couldn't open stream\n");
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   688
	rd = read(data->eventStream, ev, size * 64);
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   689
	if(rd >= size) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   690
	    for (i = 0; i < rd / sizeof(struct input_event); i++) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   691
		switch (ev[i].type) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   692
		case EV_ABS:
4644
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   693
		    switch (ev[i].code) {
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   694
			case ABS_X:
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   695
			    data->x = ev[i].value;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   696
			    break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   697
			case ABS_Y:
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   698
			    data->y = ev[i].value;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   699
			    break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   700
			case ABS_PRESSURE:
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   701
			    data->pressure = ev[i].value;
4646
eea1bf53effa Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents: 4645
diff changeset
   702
			    if(data->pressure < 0) data->pressure = 0;
4644
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   703
			    break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   704
			case ABS_MISC:
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
   705
			    if(ev[i].value == 0)
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
   706
			        data->up = SDL_TRUE;			    
4644
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   707
			    break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
   708
			}
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   709
		    break;
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   710
		case EV_MSC:
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   711
			if(ev[i].code == MSC_SERIAL)
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   712
				data->finger = ev[i].value;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   713
			break;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   714
		case EV_KEY:
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   715
			if(ev[i].code == BTN_TOUCH)
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   716
			    if(ev[i].value == 0)
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   717
			        data->up = SDL_TRUE;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   718
			break;
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   719
		case EV_SYN:
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   720
		  if(!data->down) {
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   721
		      data->down = SDL_TRUE;
4655
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
   722
		      SDL_SendFingerDown(touch->id,data->finger,
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   723
		    		  data->down, data->x, data->y,
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   724
		    		  data->pressure);
4655
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
   725
		  }
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   726
		  else if(!data->up)
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
   727
		    SDL_SendTouchMotion(touch->id,data->finger, 
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   728
					SDL_FALSE, data->x,data->y,
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
   729
					data->pressure);
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   730
		  else
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   731
		  {
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   732
		      data->down = SDL_FALSE;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   733
			  SDL_SendFingerDown(touch->id,data->finger,
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   734
					  data->down, data->x,data->y,
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   735
					  data->pressure);
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   736
			  data->x = -1;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   737
			  data->y = -1;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   738
			  data->pressure = -1;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   739
			  data->finger = 0;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   740
			  data->up = SDL_FALSE;
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   741
		  }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
   742
		  break;		
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   743
		}
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   744
	    }
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   745
	}
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
   746
    }
4669
62e6a6e9720b Fixed x11 compile bugs.
jimtla
parents: 4661
diff changeset
   747
#endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   749
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   750
/* This is so wrong it hurts */
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   751
#define GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   752
#ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   753
#include <unistd.h>
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   754
static pid_t screensaver_inhibit_pid;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
   755
static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
   756
gnome_screensaver_disable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   757
{
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   758
    screensaver_inhibit_pid = fork();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   759
    if (screensaver_inhibit_pid == 0) {
3031
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
   760
        close(0);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
   761
        close(1);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
   762
        close(2);
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   763
        execl("/usr/bin/gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   764
              "gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   765
              "--inhibit",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   766
              "--reason",
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
   767
              "GNOME screensaver doesn't respect MIT-SCREEN-SAVER", NULL);
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   768
        exit(2);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   769
    }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   770
}
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
   771
static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
   772
gnome_screensaver_enable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   773
{
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   774
    kill(screensaver_inhibit_pid, 15);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   775
}
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   776
#endif
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   777
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
void
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   779
X11_SuspendScreenSaver(_THIS)
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
{
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   781
#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   782
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   783
    int dummy;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   784
    int major_version, minor_version;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   786
    if (SDL_X11_HAVE_XSS) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   787
        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   788
        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   789
            !XScreenSaverQueryVersion(data->display,
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   790
                                      &major_version, &minor_version) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   791
            major_version < 1 || (major_version == 1 && minor_version < 1)) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   792
            return;
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   793
        }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   795
        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   796
        XResetScreenSaver(data->display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   797
    }
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   798
#endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   800
#ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   801
    if (_this->suspend_screensaver) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   802
        gnome_screensaver_disable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   803
    } else {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   804
        gnome_screensaver_enable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
   805
    }
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
   806
#endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   808
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
   809
#endif /* SDL_VIDEO_DRIVER_X11 */
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
   810
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
/* vi: set ts=4 sw=4 expandtab: */