src/video/x11/SDL_x11events.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 26 May 2015 21:29:45 -0400
changeset 9652 b5a26bd8b0e7
parent 9639 044cafe15108
child 9666 7099e2df7b29
permissions -rw-r--r--
X11: generate clipboard update events (thanks, "chw"!). Partially fixes Bugzilla #2266.
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
9619
b94b6d0bff0f Updated the copyright year to 2015
Sam Lantinga <slouken@libsdl.org>
parents: 9582
diff changeset
     3
  Copyright (C) 1997-2015 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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8071
diff changeset
    21
#include "../../SDL_internal.h"
1951
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"
4934
a5b86644c208 Fixed compiling X11 touch interface
Sam Lantinga <slouken@libsdl.org>
parents: 4902
diff changeset
    32
#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
    33
#include "SDL_x11xinput2.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#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
    35
#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
    36
#include "../../events/SDL_touch_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
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
    38
#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
    39
#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
    40
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    41
#include <stdio.h>
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
    42
8946
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    43
#ifndef _NET_WM_MOVERESIZE_SIZE_TOPLEFT
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    44
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT      0
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    45
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    46
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    47
#ifndef _NET_WM_MOVERESIZE_SIZE_TOP
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    48
#define _NET_WM_MOVERESIZE_SIZE_TOP          1
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    49
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    50
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    51
#ifndef _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    52
#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT     2
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    53
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    54
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    55
#ifndef _NET_WM_MOVERESIZE_SIZE_RIGHT
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    56
#define _NET_WM_MOVERESIZE_SIZE_RIGHT        3
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    57
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    58
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    59
#ifndef _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    60
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT  4
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    61
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    62
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    63
#ifndef _NET_WM_MOVERESIZE_SIZE_BOTTOM
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    64
#define _NET_WM_MOVERESIZE_SIZE_BOTTOM       5
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    65
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    66
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    67
#ifndef _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    68
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT   6
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    69
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    70
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    71
#ifndef _NET_WM_MOVERESIZE_SIZE_LEFT
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    72
#define _NET_WM_MOVERESIZE_SIZE_LEFT         7
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    73
#endif
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    74
8934
57fe4bf1b84b Don't hardcode an 8 here.
Ryan C. Gordon <icculus@icculus.org>
parents: 8933
diff changeset
    75
#ifndef _NET_WM_MOVERESIZE_MOVE
8946
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
    76
#define _NET_WM_MOVERESIZE_MOVE              8
8934
57fe4bf1b84b Don't hardcode an 8 here.
Ryan C. Gordon <icculus@icculus.org>
parents: 8933
diff changeset
    77
#endif
57fe4bf1b84b Don't hardcode an 8 here.
Ryan C. Gordon <icculus@icculus.org>
parents: 8933
diff changeset
    78
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    79
typedef struct {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
    80
    unsigned char *data;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
    81
    int format, count;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
    82
    Atom type;
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    83
} SDL_x11Prop;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    84
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    85
/* Reads property
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
    86
   Must call X11_XFree on results
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    87
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
    88
static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop)
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    89
{
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    90
    unsigned char *ret=NULL;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    91
    Atom type;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    92
    int fmt;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    93
    unsigned long count;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    94
    unsigned long bytes_left;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
    95
    int bytes_fetch = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
    96
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
    97
    do {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
    98
        if (ret != 0) X11_XFree(ret);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
    99
        X11_XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   100
        bytes_fetch += bytes_left;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   101
    } while (bytes_left != 0);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
   102
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   103
    p->data=ret;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   104
    p->format=fmt;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   105
    p->count=count;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   106
    p->type=type;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   107
}
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   108
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   109
/* Find text-uri-list in a list of targets and return it's atom
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   110
   if available, else return None */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   111
static Atom X11_PickTarget(Display *disp, Atom list[], int list_count)
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   112
{
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   113
    Atom request = None;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   114
    char *name;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   115
    int i;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   116
    for (i=0; i < list_count && request == None; i++) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   117
        name = X11_XGetAtomName(disp, list[i]);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   118
        if (strcmp("text/uri-list", name)==0) request = list[i];
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   119
        X11_XFree(name);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   120
    }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   121
    return request;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   122
}
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   123
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   124
/* Wrapper for X11_PickTarget for a maximum of three targets, a special
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   125
   case in the Xdnd protocol */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   126
static Atom X11_PickTargetFromAtoms(Display *disp, Atom a0, Atom a1, Atom a2)
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   127
{
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   128
    int count=0;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   129
    Atom atom[3];
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   130
    if (a0 != None) atom[count++] = a0;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   131
    if (a1 != None) atom[count++] = a1;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   132
    if (a2 != None) atom[count++] = a2;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   133
    return X11_PickTarget(disp, atom, count);
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   134
}
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   135
/* #define DEBUG_XEVENTS */
6474
39087ac884d7 Added debug define (commented out)
Sam Lantinga <slouken@libsdl.org>
parents: 6432
diff changeset
   136
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   137
struct KeyRepeatCheckData
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   138
{
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   139
    XEvent *event;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   140
    SDL_bool found;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   141
};
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   142
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   143
static Bool X11_KeyRepeatCheckIfEvent(Display *display, XEvent *chkev,
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   144
    XPointer arg)
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   145
{
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   146
    struct KeyRepeatCheckData *d = (struct KeyRepeatCheckData *) arg;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   147
    if (chkev->type == KeyPress &&
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   148
        chkev->xkey.keycode == d->event->xkey.keycode &&
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   149
        chkev->xkey.time - d->event->xkey.time < 2)
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   150
        d->found = SDL_TRUE;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   151
    return False;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   152
}
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   153
4565
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   154
/* 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
   155
   (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
   156
 */
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   157
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
   158
{
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   159
    XEvent dummyev;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   160
    struct KeyRepeatCheckData d;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   161
    d.event = event;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   162
    d.found = SDL_FALSE;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   163
    if (X11_XPending(display))
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   164
        X11_XCheckIfEvent(display, &dummyev, X11_KeyRepeatCheckIfEvent,
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   165
            (XPointer) &d);
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   166
    return d.found;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   167
}
4565
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   168
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   169
static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev,
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   170
    XPointer arg)
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   171
{
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   172
    XEvent *event = (XEvent *) arg;
7749
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   173
    /* we only handle buttons 4 and 5 - false positive avoidance */
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   174
    if (chkev->type == ButtonRelease &&
7749
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   175
        (event->xbutton.button == Button4 || event->xbutton.button == Button5) &&
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   176
        chkev->xbutton.button == event->xbutton.button &&
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   177
        chkev->xbutton.time == event->xbutton.time)
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   178
        return True;
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   179
    return False;
4565
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   180
}
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   181
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   182
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
   183
{
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   184
    XEvent relevent;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   185
    if (X11_XPending(display)) {
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   186
        /* 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
   187
           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
   188
           immediately. thus, checking if the same button was released at the same
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
   189
           time as it was pressed, should be an adequate hack to derive a mouse
7749
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   190
           wheel event.
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   191
           However, there is broken and unusual hardware out there...
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   192
           - False positive: a button for which a release event is
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   193
             generated (or synthesised) immediately.
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   194
           - False negative: a wheel which, when rolled, doesn't have
6073ad385c9b # User Darren Salt <devspam@moreofthesa.me.uk>
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   195
             a release event generated immediately. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   196
        if (X11_XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
7475
c244bc85fb84 Workaround crash bug in libXi <= 1.4.1 (thanks, Steve!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7402
diff changeset
   197
            (XPointer) event)) {
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   198
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   199
            /* 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
   200
               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
   201
            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
   202
                *ticks = 1;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   203
            }
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
   204
            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
   205
                *ticks = -1;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   206
            }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   207
            return SDL_TRUE;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   208
        }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   209
    }
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   210
    return SDL_FALSE;
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   211
}
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   212
8870
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   213
/* Decodes URI escape sequences in string buf of len bytes
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   214
   (excluding the terminating NULL byte) in-place. Since
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   215
   URI-encoded characters take three times the space of
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   216
   normal characters, this should not be an issue.
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   217
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   218
   Returns the number of decoded bytes that wound up in
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   219
   the buffer, excluding the terminating NULL byte.
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   220
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   221
   The buffer is guaranteed to be NULL-terminated but
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   222
   may contain embedded NULL bytes.
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   223
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   224
   On error, -1 is returned.
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   225
 */
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   226
int X11_URIDecode(char *buf, int len) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   227
    int ri, wi, di;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   228
    char decode = '\0';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   229
    if (buf == NULL || len < 0) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   230
        errno = EINVAL;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   231
        return -1;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   232
    }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   233
    if (len == 0) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   234
        len = SDL_strlen(buf);
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   235
    }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   236
    for (ri = 0, wi = 0, di = 0; ri < len && wi < len; ri += 1) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   237
        if (di == 0) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   238
            /* start decoding */
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   239
            if (buf[ri] == '%') {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   240
                decode = '\0';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   241
                di += 1;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   242
                continue;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   243
            }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   244
            /* normal write */
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   245
            buf[wi] = buf[ri];
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   246
            wi += 1;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   247
            continue;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   248
        } else if (di == 1 || di == 2) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   249
            char off = '\0';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   250
            char isa = buf[ri] >= 'a' && buf[ri] <= 'f';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   251
            char isA = buf[ri] >= 'A' && buf[ri] <= 'F';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   252
            char isn = buf[ri] >= '0' && buf[ri] <= '9';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   253
            if (!(isa || isA || isn)) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   254
                /* not a hexadecimal */
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   255
                int sri;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   256
                for (sri = ri - di; sri <= ri; sri += 1) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   257
                    buf[wi] = buf[sri];
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   258
                    wi += 1;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   259
                }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   260
                di = 0;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   261
                continue;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   262
            }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   263
            /* itsy bitsy magicsy */
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   264
            if (isn) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   265
                off = 0 - '0';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   266
            } else if (isa) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   267
                off = 10 - 'a';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   268
            } else if (isA) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   269
                off = 10 - 'A';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   270
            }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   271
            decode |= (buf[ri] + off) << (2 - di) * 4;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   272
            if (di == 2) {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   273
                buf[wi] = decode;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   274
                wi += 1;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   275
                di = 0;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   276
            } else {
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   277
                di += 1;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   278
            }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   279
            continue;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   280
        }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   281
    }
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   282
    buf[wi] = '\0';
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   283
    return wi;
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   284
}
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   285
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   286
/* Convert URI to local filename
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   287
   return filename if possible, else NULL
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   288
*/
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   289
static char* X11_URIToLocal(char* uri) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   290
    char *file = NULL;
7679
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7678
diff changeset
   291
    SDL_bool local;
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   292
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   293
    if (memcmp(uri,"file:/",6) == 0) uri += 6;      /* local file? */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   294
    else if (strstr(uri,":/") != NULL) return file; /* wrong scheme */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   295
7679
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7678
diff changeset
   296
    local = uri[0] != '/' || ( uri[0] != '\0' && uri[1] == '/' );
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   297
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   298
    /* got a hostname? */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   299
    if ( !local && uri[0] == '/' && uri[2] != '/' ) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   300
      char* hostname_end = strchr( uri+1, '/' );
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   301
      if ( hostname_end != NULL ) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   302
          char hostname[ 257 ];
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   303
          if ( gethostname( hostname, 255 ) == 0 ) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   304
            hostname[ 256 ] = '\0';
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   305
            if ( memcmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   306
                uri = hostname_end + 1;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   307
                local = SDL_TRUE;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   308
            }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   309
          }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   310
      }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   311
    }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   312
    if ( local ) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   313
      file = uri;
8870
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   314
      /* Convert URI escape sequences to real characters */
cd1113741ade Fixed bug 2567 - x11: Local dropped files are not URI-decoded
Sam Lantinga <slouken@libsdl.org>
parents: 8819
diff changeset
   315
      X11_URIDecode(file, 0);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   316
      if ( uri[1] == '/' ) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   317
          file++;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   318
      } else {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   319
          file--;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   320
      }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   321
    }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   322
    return file;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   323
}
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   324
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   325
#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
   326
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
   327
{
7402
235c9aaeefd1 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 7396
diff changeset
   328
    /* event is a union, so cookie == &event, but this is type safe. */
235c9aaeefd1 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 7396
diff changeset
   329
    XGenericEventCookie *cookie = &event.xcookie;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   330
    if (X11_XGetEventData(videodata->display, cookie)) {
7214
5b31583ecf9e Only free EventData if it's successfully retrieved.
Edward Rudd <urkle@outoforder.cc>
parents: 7199
diff changeset
   331
        X11_HandleXinput2Event(videodata, cookie);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   332
        X11_XFreeEventData(videodata->display, cookie);
7214
5b31583ecf9e Only free EventData if it's successfully retrieved.
Edward Rudd <urkle@outoforder.cc>
parents: 7199
diff changeset
   333
    }
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   334
}
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   335
#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
   336
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   337
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
   338
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
   339
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
   340
{
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
   341
#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
   342
    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
   343
#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
   344
    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
   345
#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
   346
    if (data->ic) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   347
        X11_XSetICFocus(data->ic);
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
   348
    }
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
   349
#endif
9096
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   350
#ifdef SDL_USE_IBUS
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   351
    SDL_IBus_SetFocus(SDL_TRUE);
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   352
#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
   353
}
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
   354
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
   355
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
   356
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
   357
{
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
   358
#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
   359
    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
   360
#endif
7902
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   361
    /* If another window has already processed a focus in, then don't try to
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   362
     * remove focus here.  Doing so will incorrectly remove focus from that
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   363
     * window, and the focus lost event for this window will have already
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   364
     * been dispatched anyway. */
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   365
    if (data->window == SDL_GetKeyboardFocus()) {
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   366
        SDL_SetKeyboardFocus(NULL);
0c2e2b91eeea Fixed bug 1990 - focus/keyboard events not generated correctly for multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 7885
diff changeset
   367
    }
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
   368
#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
   369
    if (data->ic) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   370
        X11_XUnsetICFocus(data->ic);
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
   371
    }
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
   372
#endif
9096
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   373
#ifdef SDL_USE_IBUS
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   374
    SDL_IBus_SetFocus(SDL_FALSE);
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   375
#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
   376
}
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
   377
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
   378
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
   379
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
   380
{
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
   381
    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
   382
    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
   383
}
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
   384
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
   385
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
   386
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
   387
{
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
   388
    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
   389
    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
   390
}
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   391
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
static void
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   393
InitiateWindowMove(_THIS, const SDL_WindowData *data, const SDL_Point *point)
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   394
{
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   395
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   396
    SDL_Window* window = data->window;
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   397
    Display *display = viddata->display;
8954
7bcc8257809d Patched to compile with -Werror=declaration-after-statement
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   398
    XEvent evt;
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   399
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   400
    /* !!! FIXME: we need to regrab this if necessary when the drag is done. */
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   401
    X11_XUngrabPointer(display, 0L);
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   402
    X11_XFlush(display);
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   403
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   404
    evt.xclient.type = ClientMessage;
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   405
    evt.xclient.window = data->xwindow;
8946
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   406
    evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", True);
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   407
    evt.xclient.format = 32;
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   408
    evt.xclient.data.l[0] = window->x + point->x;
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   409
    evt.xclient.data.l[1] = window->y + point->y;
8934
57fe4bf1b84b Don't hardcode an 8 here.
Ryan C. Gordon <icculus@icculus.org>
parents: 8933
diff changeset
   410
    evt.xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE;
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   411
    evt.xclient.data.l[3] = Button1;
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   412
    evt.xclient.data.l[4] = 0;
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   413
    X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   414
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   415
    X11_XSync(display, 0);
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   416
}
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   417
8946
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   418
static void
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   419
InitiateWindowResize(_THIS, const SDL_WindowData *data, const SDL_Point *point, int direction)
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   420
{
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   421
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   422
    SDL_Window* window = data->window;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   423
    Display *display = viddata->display;
8954
7bcc8257809d Patched to compile with -Werror=declaration-after-statement
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   424
    XEvent evt;
8946
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   425
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   426
    if (direction < _NET_WM_MOVERESIZE_SIZE_TOPLEFT || direction > _NET_WM_MOVERESIZE_SIZE_LEFT)
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   427
        return;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   428
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   429
    /* !!! FIXME: we need to regrab this if necessary when the drag is done. */
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   430
    X11_XUngrabPointer(display, 0L);
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   431
    X11_XFlush(display);
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   432
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   433
    evt.xclient.type = ClientMessage;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   434
    evt.xclient.window = data->xwindow;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   435
    evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", True);
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   436
    evt.xclient.format = 32;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   437
    evt.xclient.data.l[0] = window->x + point->x;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   438
    evt.xclient.data.l[1] = window->y + point->y;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   439
    evt.xclient.data.l[2] = direction;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   440
    evt.xclient.data.l[3] = Button1;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   441
    evt.xclient.data.l[4] = 0;
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   442
    X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   443
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   444
    X11_XSync(display, 0);
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   445
}
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   446
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   447
static SDL_bool
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8934
diff changeset
   448
ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev)
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   449
{
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8934
diff changeset
   450
    SDL_Window *window = data->window;
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   451
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8934
diff changeset
   452
    if (window->hit_test) {
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   453
        const SDL_Point point = { xev->xbutton.x, xev->xbutton.y };
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8934
diff changeset
   454
        const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
9555
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   455
        static const int directions[] = {
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   456
            _NET_WM_MOVERESIZE_SIZE_TOPLEFT, _NET_WM_MOVERESIZE_SIZE_TOP,
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   457
            _NET_WM_MOVERESIZE_SIZE_TOPRIGHT, _NET_WM_MOVERESIZE_SIZE_RIGHT,
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   458
            _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, _NET_WM_MOVERESIZE_SIZE_BOTTOM,
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   459
            _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, _NET_WM_MOVERESIZE_SIZE_LEFT
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   460
        };
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   461
8946
c9592936dffc Added SDL_HITTEST_RESIZE_*, and implemented for X11.
Ionut Leonte <ionut.leonte@gmail.com>
parents: 8935
diff changeset
   462
        switch (rc) {
9555
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   463
            case SDL_HITTEST_DRAGGABLE:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   464
                InitiateWindowMove(_this, data, &point);
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   465
                return SDL_TRUE;
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   466
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   467
            case SDL_HITTEST_RESIZE_TOPLEFT:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   468
            case SDL_HITTEST_RESIZE_TOP:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   469
            case SDL_HITTEST_RESIZE_TOPRIGHT:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   470
            case SDL_HITTEST_RESIZE_RIGHT:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   471
            case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   472
            case SDL_HITTEST_RESIZE_BOTTOM:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   473
            case SDL_HITTEST_RESIZE_BOTTOMLEFT:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   474
            case SDL_HITTEST_RESIZE_LEFT:
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   475
                InitiateWindowResize(_this, data, &point, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   476
                return SDL_TRUE;
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   477
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   478
            default: return SDL_FALSE;
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   479
        }
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   480
    }
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   481
9555
fff4b6354b99 Make X11 and Wayland ProcessHitTest() code less verbose.
Ryan C. Gordon <icculus@icculus.org>
parents: 9331
diff changeset
   482
    return SDL_FALSE;
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   483
}
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   484
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   485
static void
9133
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   486
ReconcileKeyboardState(_THIS, const SDL_WindowData *data)
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   487
{
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   488
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   489
    Display *display = viddata->display;
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   490
    char keys[32];
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   491
    int keycode = 0;
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   492
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   493
    X11_XQueryKeymap( display, keys );
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   494
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   495
    while ( keycode < 256 ) {
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   496
        if ( keys[keycode / 8] & (1 << (keycode % 8)) ) {
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   497
            SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode]);
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   498
        } else {
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   499
            SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode]);
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   500
        }
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   501
        keycode++;
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   502
    }
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   503
}
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   504
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   505
static void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
X11_DispatchEvent(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
    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
   509
    Display *display = videodata->display;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
    SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
    XEvent xevent;
7943
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   512
    int orig_event_type;
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   513
    KeyCode orig_keycode;
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   514
    XClientMessageEvent m;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
    int i;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
    SDL_zero(xevent);           /* valgrind fix. --ryan. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   518
    X11_XNextEvent(display, &xevent);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
7943
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   520
    /* Save the original keycode for dead keys, which are filtered out by
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   521
       the XFilterEvent() call below.
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   522
    */
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   523
    orig_event_type = xevent.type;
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   524
    if (orig_event_type == KeyPress || orig_event_type == KeyRelease) {
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   525
        orig_keycode = xevent.xkey.keycode;
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   526
    } else {
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   527
        orig_keycode = 0;
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   528
    }
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   529
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   530
    /* filter events catchs XIM events and sends them to the correct handler */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   531
    if (X11_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
   532
#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
   533
        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
   534
               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
   535
#endif
7943
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   536
        if (orig_keycode) {
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   537
            /* Make sure dead key press/release events are sent */
8819
728adb496260 Fixed bug 2526, but regressed delivering dead key presses
Sam Lantinga <slouken@libsdl.org>
parents: 8706
diff changeset
   538
            /* Actually, don't do this because it causes double-delivery
728adb496260 Fixed bug 2526, but regressed delivering dead key presses
Sam Lantinga <slouken@libsdl.org>
parents: 8706
diff changeset
   539
               of some keys on Ubuntu 14.04 (bug 2526)
7943
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   540
            SDL_Scancode scancode = videodata->key_layout[orig_keycode];
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   541
            if (orig_event_type == KeyPress) {
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   542
                SDL_SendKeyboardKey(SDL_PRESSED, scancode);
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   543
            } else {
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   544
                SDL_SendKeyboardKey(SDL_RELEASED, scancode);
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   545
            }
8819
728adb496260 Fixed bug 2526, but regressed delivering dead key presses
Sam Lantinga <slouken@libsdl.org>
parents: 8706
diff changeset
   546
            */
7943
713c6a333c33 Fixed issue with dead key press/release events being filtered out.
Sam Lantinga <slouken@libsdl.org>
parents: 7942
diff changeset
   547
        }
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
   548
        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
   549
    }
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
   550
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
    /* 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
   552
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
        SDL_SysWMmsg wmmsg;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
        SDL_VERSION(&wmmsg.version);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
        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
   557
        wmmsg.msg.x11.event = xevent;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
        SDL_SendSysWMEvent(&wmmsg);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   561
#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
   562
    if(xevent.type == GenericEvent) {
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   563
        X11_HandleGenericEvent(videodata,xevent);
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   564
        return;
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   565
    }
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   566
#endif
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   567
6476
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   568
#if 0
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   569
    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
   570
           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
   571
#endif
9010d6830cdf Show events from all windows (for the legacy fullscreen case)
Sam Lantinga <slouken@libsdl.org>
parents: 6474
diff changeset
   572
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
    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
   574
    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
   575
        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
   576
            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
   577
                (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
   578
                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
   579
                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
   580
            }
1951
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
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
    if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
        return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
    }
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
   586
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
    switch (xevent.type) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
        /* Gaining mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
    case EnterNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
#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
   592
            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
   593
                   xevent.xcrossing.x,
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   594
                   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
   595
                   xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
            if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
                printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
            if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
                printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
#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
   601
            SDL_SetMouseFocus(data->window);
7097
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   602
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   603
            if (!SDL_GetMouse()->relative_mode) {
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   604
                SDL_SendMouseMotion(data->window, 0, 0, xevent.xcrossing.x, xevent.xcrossing.y);
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   605
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
        /* Losing mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
    case LeaveNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
#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
   611
            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
   612
                   xevent.xcrossing.x,
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   613
                   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
   614
                   xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
            if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
                printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
            if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
                printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
#endif
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7021
diff changeset
   620
            if (!SDL_GetMouse()->relative_mode) {
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7021
diff changeset
   621
                SDL_SendMouseMotion(data->window, 0, 0, xevent.xcrossing.x, xevent.xcrossing.y);
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7021
diff changeset
   622
            }
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7021
diff changeset
   623
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   624
            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
   625
                xevent.xcrossing.mode != NotifyUngrab &&
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
   626
                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
   627
                SDL_SetMouseFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
        break;
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
        /* Gaining input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
    case FocusIn:{
7945
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   634
            if (xevent.xfocus.mode == NotifyGrab || xevent.xfocus.mode == NotifyUngrab) {
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   635
                /* Someone is handling a global hotkey, ignore it */
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   636
#ifdef DEBUG_XEVENTS
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   637
                printf("window %p: FocusIn (NotifyGrab/NotifyUngrab, ignoring)\n", data);
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   638
#endif
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   639
                break;
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   640
            }
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   641
6660
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   642
            if (xevent.xfocus.detail == NotifyInferior) {
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   643
#ifdef DEBUG_XEVENTS
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   644
                printf("window %p: FocusIn (NotifierInferior, ignoring)\n", data);
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   645
#endif
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   646
                break;
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   647
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
#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
   649
            printf("window %p: FocusIn!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
#endif
6661
cd8befc0a969 Reset the keyboard when we lose input focus
Sam Lantinga <slouken@libsdl.org>
parents: 6660
diff changeset
   651
            if (data->pending_focus == PENDING_FOCUS_OUT &&
cd8befc0a969 Reset the keyboard when we lose input focus
Sam Lantinga <slouken@libsdl.org>
parents: 6660
diff changeset
   652
                data->window == SDL_GetKeyboardFocus()) {
9133
52f185c2d019 [X11] Reconcile logical keyboard state with physical state on FocusIn
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 9096
diff changeset
   653
                ReconcileKeyboardState(_this, data);
6661
cd8befc0a969 Reset the keyboard when we lose input focus
Sam Lantinga <slouken@libsdl.org>
parents: 6660
diff changeset
   654
            }
9319
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   655
            if (!videodata->last_mode_change_deadline) /* no recent mode changes */
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   656
            {
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   657
                data->pending_focus = PENDING_FOCUS_NONE;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   658
                data->pending_focus_time = 0;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   659
                X11_DispatchFocusIn(data);
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   660
            }
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   661
            else
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   662
            {
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   663
                data->pending_focus = PENDING_FOCUS_IN;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   664
                data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   665
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   666
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   668
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   669
        /* Losing input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
    case FocusOut:{
7945
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   671
            if (xevent.xfocus.mode == NotifyGrab || xevent.xfocus.mode == NotifyUngrab) {
7942
a1c4c17410e8 Hopefully fixed focus problems when handling a global hotkey on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 7902
diff changeset
   672
                /* Someone is handling a global hotkey, ignore it */
a1c4c17410e8 Hopefully fixed focus problems when handling a global hotkey on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 7902
diff changeset
   673
#ifdef DEBUG_XEVENTS
7945
764129077d18 [X11] Ignore both NotifyGrab and NotifyUngrab modes in FocusIn/FocusOut events
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7943
diff changeset
   674
                printf("window %p: FocusOut (NotifyGrab/NotifyUngrab, ignoring)\n", data);
7942
a1c4c17410e8 Hopefully fixed focus problems when handling a global hotkey on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 7902
diff changeset
   675
#endif
a1c4c17410e8 Hopefully fixed focus problems when handling a global hotkey on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 7902
diff changeset
   676
                break;
a1c4c17410e8 Hopefully fixed focus problems when handling a global hotkey on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 7902
diff changeset
   677
            }
6660
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   678
            if (xevent.xfocus.detail == NotifyInferior) {
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   679
                /* We still have focus if a child gets focus */
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   680
#ifdef DEBUG_XEVENTS
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   681
                printf("window %p: FocusOut (NotifierInferior, ignoring)\n", data);
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   682
#endif
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   683
                break;
4fa0723e6874 Don't lose focus if a child window gains focus
Sam Lantinga <slouken@libsdl.org>
parents: 6659
diff changeset
   684
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
#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
   686
            printf("window %p: FocusOut!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
#endif
9319
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   688
            if (!videodata->last_mode_change_deadline) /* no recent mode changes */
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   689
            {
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   690
                data->pending_focus = PENDING_FOCUS_NONE;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   691
                data->pending_focus_time = 0;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   692
                X11_DispatchFocusOut(data);
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   693
            }
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   694
            else
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   695
            {
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   696
                data->pending_focus = PENDING_FOCUS_OUT;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   697
                data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME;
ad4f430cc9f5 X11: Don't delay delivery of focus events unless we just changed vidmodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 9257
diff changeset
   698
            }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
        /* Generated upon EnterWindow and FocusIn */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
    case KeymapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   704
#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
   705
            printf("window %p: KeymapNotify!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
            /* FIXME:
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   708
               X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
             */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   713
        /* Has the keyboard layout changed? */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   714
    case MappingNotify:{
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   715
#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
   716
            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
   717
#endif
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   718
            X11_UpdateKeymap(_this);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   719
        }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   720
        break;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   721
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
        /* Key press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
    case KeyPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   724
            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
   725
            KeySym keysym = NoSymbol;
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   726
            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
   727
            Status status = 0;
9096
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   728
            SDL_bool handled_by_ime = SDL_FALSE;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   730
#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
   731
            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
   732
#endif
4535
ce811c9247da Added back in a little more debugging for the X11 keyboard code
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   733
#if 1
7638
783d1cff9b20 Don't print "unrecognized key" message for an X11 keycode of 0. This can happen with composed characters.
Sam Lantinga <slouken@libsdl.org>
parents: 7475
diff changeset
   734
            if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN && keycode) {
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   735
                int min_keycode, max_keycode;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   736
                X11_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
   737
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   738
                keysym = X11_XkbKeycodeToKeysym(display, keycode, 0, 0);
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6316
diff changeset
   739
#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
   740
                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
   741
#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
   742
                fprintf(stderr,
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
   743
                        "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
   744
                        keycode, keycode - min_keycode, keysym,
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   745
                        X11_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
   746
            }
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
   747
#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
   748
            /* */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
   749
            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
   750
#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
   751
            if (data->ic) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   752
                X11_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
   753
                                  &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
   754
            }
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
   755
#else
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   756
            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
   757
#endif
9582
e0e2e94ce5ea X11: send keypress events before textinput events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9578
diff changeset
   758
8889
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   759
#ifdef SDL_USE_IBUS
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   760
            if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
9582
e0e2e94ce5ea X11: send keypress events before textinput events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9578
diff changeset
   761
                handled_by_ime = SDL_IBus_ProcessKeyEvent(keysym, 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
   762
            }
9096
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   763
#endif
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   764
            if (!handled_by_ime) {
8889
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   765
                SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
9582
e0e2e94ce5ea X11: send keypress events before textinput events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9578
diff changeset
   766
                if(*text) {
e0e2e94ce5ea X11: send keypress events before textinput events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9578
diff changeset
   767
                    SDL_SendKeyboardText(text);
e0e2e94ce5ea X11: send keypress events before textinput events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9578
diff changeset
   768
                }
8889
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   769
            }
9096
6454f71d6f15 Improvements to the IBus related code:
Alex Baines <alex@abaines.me.uk>
parents: 9090
diff changeset
   770
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   771
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   772
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   773
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   774
        /* Key release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   775
    case KeyRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   776
            KeyCode keycode = xevent.xkey.keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   777
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
#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
   779
            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
   780
#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
   781
            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
   782
                /* 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
   783
                break;
e2d46c5c7483 Fixed key repeat detection on X11, and simplified the code for everyone else.
Sam Lantinga <slouken@libsdl.org>
parents: 4560
diff changeset
   784
            }
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
   785
            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
   786
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
        /* Have we been iconified? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
    case UnmapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
#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
   792
            printf("window %p: UnmapNotify!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
#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
   794
            X11_DispatchUnmapNotify(data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   795
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   796
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   797
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   798
        /* Have we been restored? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
    case MapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
#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
   801
            printf("window %p: MapNotify!\n", data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
#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
   803
            X11_DispatchMapNotify(data);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   806
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
        /* Have we been resized or moved? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   808
    case ConfigureNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   809
#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
   810
            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
   811
                   xevent.xconfigure.x, xevent.xconfigure.y,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
                   xevent.xconfigure.width, xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
#endif
7838
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   814
            long border_left = 0;
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   815
            long border_top = 0;
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   816
            if (data->xwindow) {
7839
d2804f8153fe Fixed compiling with the new X11 symbol wrapping
Sam Lantinga <slouken@libsdl.org>
parents: 7838
diff changeset
   817
                Atom _net_frame_extents = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0);
8706
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   818
                Atom type;
7838
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   819
                int format;
8706
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   820
                unsigned long nitems, bytes_after;
7838
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   821
                unsigned char *property;
8706
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   822
                if (X11_XGetWindowProperty(display, data->xwindow,
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   823
                        _net_frame_extents, 0, 16, 0,
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   824
                        XA_CARDINAL, &type, &format,
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   825
                        &nitems, &bytes_after, &property) == Success) {
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   826
                    if (type != None && nitems == 4)
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   827
                    {
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   828
                        border_left = ((long*)property)[0];
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   829
                        border_top = ((long*)property)[2];
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   830
                    }
0c9660fdf9bf Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents: 8681
diff changeset
   831
                    X11_XFree(property);
7885
a8bd63b33636 Fix regression causing crashes when running without a window manager.
Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
parents: 7857
diff changeset
   832
                }
7838
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   833
            }
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   834
6542
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   835
            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
   836
                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
   837
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
7838
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   838
                                    xevent.xconfigure.x - border_left,
909b0d7fe4dd Fix bug 1300 by querying current border size in ConfigureNotify, and adjusting window coordinates accordingly.
Stefanos Apostolopoulos <stapostol@gmail.com>
parents: 7827
diff changeset
   839
                                    xevent.xconfigure.y - border_top);
8889
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   840
#ifdef SDL_USE_IBUS
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   841
                if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   842
                    /* Update IBus candidate list position */
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   843
                    SDL_IBus_UpdateTextRect(NULL);
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   844
                }
26a6243b27c2 Add IBus IME Support, move DBus code to its own file. (v3.3 squashed)
Alex Baines <alex@abaines.me.uk>
parents: 8870
diff changeset
   845
#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
   846
            }
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   847
            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
   848
                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
   849
                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
   850
                                    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
   851
                                    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
   852
            }
5c1b8ed19212 Keep track of the configure events we've received from the X server.
Sam Lantinga <slouken@libsdl.org>
parents: 6504
diff changeset
   853
            data->last_xconfigure = xevent.xconfigure;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   854
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   856
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   857
        /* 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
   858
    case ClientMessage:{
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   859
9245
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   860
            static int xdnd_version=0;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
   861
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   862
            if (xevent.xclient.message_type == videodata->XdndEnter) {
9245
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   863
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   864
                SDL_bool use_list = xevent.xclient.data.l[1] & 1;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   865
                data->xdnd_source = xevent.xclient.data.l[0];
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   866
                xdnd_version = ( xevent.xclient.data.l[1] >> 24);
9245
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   867
#ifdef DEBUG_XEVENTS
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   868
                printf("XID of source window : %ld\n", data->xdnd_source);
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   869
                printf("Protocol version to use : %ld\n", xdnd_version);
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   870
                printf("More then 3 data types : %ld\n", use_list); 
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   871
#endif
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   872
 
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   873
                if (use_list) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   874
                    /* fetch conversion targets */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   875
                    SDL_x11Prop p;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   876
                    X11_ReadProperty(&p, display, data->xdnd_source, videodata->XdndTypeList);
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   877
                    /* pick one */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   878
                    data->xdnd_req = X11_PickTarget(display, (Atom*)p.data, p.count);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   879
                    X11_XFree(p.data);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   880
                } else {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   881
                    /* pick from list of three */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   882
                    data->xdnd_req = X11_PickTargetFromAtoms(display, xevent.xclient.data.l[2], xevent.xclient.data.l[3], xevent.xclient.data.l[4]);
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   883
                }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   884
            }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   885
            else if (xevent.xclient.message_type == videodata->XdndPosition) {
9245
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   886
            
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   887
#ifdef DEBUG_XEVENTS
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   888
                Atom act= videodata->XdndActionCopy;
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   889
                if(xdnd_version >= 2) {
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   890
                    act = xevent.xclient.data.l[4];
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   891
                }
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   892
                printf("Action requested by user is : %s\n", X11_XGetAtomName(display , act));
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   893
#endif
104f3bcfbf45 Fixed bug 2676 - xdnd_version check issue in case ClientMessage
Sam Lantinga <slouken@libsdl.org>
parents: 9186
diff changeset
   894
                
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
   895
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   896
                /* reply with status */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   897
                memset(&m, 0, sizeof(XClientMessageEvent));
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   898
                m.type = ClientMessage;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   899
                m.display = xevent.xclient.display;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   900
                m.window = xevent.xclient.data.l[0];
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   901
                m.message_type = videodata->XdndStatus;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   902
                m.format=32;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   903
                m.data.l[0] = data->xwindow;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   904
                m.data.l[1] = (data->xdnd_req != None);
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   905
                m.data.l[2] = 0; /* specify an empty rectangle */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   906
                m.data.l[3] = 0;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   907
                m.data.l[4] = videodata->XdndActionCopy; /* we only accept copying anyway */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
   908
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   909
                X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   910
                X11_XFlush(display);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   911
            }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   912
            else if(xevent.xclient.message_type == videodata->XdndDrop) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   913
                if (data->xdnd_req == None) {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   914
                    /* say again - not interested! */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   915
                    memset(&m, 0, sizeof(XClientMessageEvent));
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   916
                    m.type = ClientMessage;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   917
                    m.display = xevent.xclient.display;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   918
                    m.window = xevent.xclient.data.l[0];
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   919
                    m.message_type = videodata->XdndFinished;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   920
                    m.format=32;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   921
                    m.data.l[0] = data->xwindow;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   922
                    m.data.l[1] = 0;
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   923
                    m.data.l[2] = None; /* fail! */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   924
                    X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   925
                } else {
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   926
                    /* convert */
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   927
                    if(xdnd_version >= 1) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   928
                        X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   929
                    } else {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   930
                        X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   931
                    }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   932
                }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   933
            }
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   934
            else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
6637
31e3f5b04120 WM_DELETE_WINDOW should check that the event message_type is WM_PROTOCOLS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6542
diff changeset
   935
                (xevent.xclient.format == 32) &&
6638
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   936
                (xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) {
6659
4016ef96095a Fixed XBadWindow error when iconified under Unity3D
Sam Lantinga <slouken@libsdl.org>
parents: 6638
diff changeset
   937
                Window root = DefaultRootWindow(display);
6638
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   938
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   939
#ifdef DEBUG_XEVENTS
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   940
                printf("window %p: _NET_WM_PING\n", data);
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   941
#endif
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   942
                xevent.xclient.window = root;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
   943
                X11_XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
6638
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   944
                break;
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   945
            }
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   946
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   947
            else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   948
                (xevent.xclient.format == 32) &&
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   949
                (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
   950
6638
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   951
#ifdef DEBUG_XEVENTS
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   952
                printf("window %p: WM_DELETE_WINDOW\n", data);
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   953
#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
   954
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
6638
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6637
diff changeset
   955
                break;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   956
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   957
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   958
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   959
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   960
        /* Do we need to refresh ourselves? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   961
    case Expose:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   962
#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
   963
            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
   964
#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
   965
            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
   966
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   967
        break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   968
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
   969
    case MotionNotify:{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7097
diff changeset
   970
            SDL_Mouse *mouse = SDL_GetMouse();
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 7945
diff changeset
   971
            if(!mouse->relative_mode || mouse->relative_mode_warp) {
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   972
#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
   973
                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
   974
#endif
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   975
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   976
                SDL_SendMouseMotion(data->window, 0, 0, xevent.xmotion.x, xevent.xmotion.y);
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6184
diff changeset
   977
            }
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
   978
        }
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
   979
        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
   980
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
   981
    case ButtonPress:{
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   982
            int ticks = 0;
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   983
            if (X11_IsWheelEvent(display,&xevent,&ticks)) {
9257
6f41196c2d6b add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event
Edward Rudd <urkle@outoforder.cc>
parents: 9245
diff changeset
   984
                SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL);
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   985
            } else {
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   986
                if(xevent.xbutton.button == Button1) {
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8934
diff changeset
   987
                    if (ProcessHitTest(_this, data, &xevent)) {
8933
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   988
                        break;  /* don't pass this event on to app. */
063ef6957a12 Some updates for the X11 drag areas work.
Ryan C. Gordon <icculus@icculus.org>
parents: 8932
diff changeset
   989
                    }
8932
7eacbfcbb313 Initial work on X11 implementation of SDL_SetWindowDragAreas().
Damian Kaczmarek <rush@rushbase.net>
parents: 8706
diff changeset
   990
                }
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   991
                SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
5530
4e46a7b6773d Fixed bug 1173 (No mouse wheel event on linux/x11)
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   992
            }
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
   993
        }
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
   994
        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
   995
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
   996
    case ButtonRelease:{
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   997
            SDL_SendMouseButton(data->window, 0, 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
   998
        }
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
   999
        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
  1000
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
  1001
    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
  1002
#ifdef DEBUG_XEVENTS
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
  1003
            unsigned char *propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
  1004
            int status, real_format;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
  1005
            Atom real_type;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
  1006
            unsigned long items_read, items_left, i;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
  1007
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
  1008
            char *name = X11_XGetAtomName(display, xevent.xproperty.atom);
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
  1009
            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
  1010
                printf("window %p: PropertyNotify: %s %s\n", data, name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed");
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
  1011
                X11_XFree(name);
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
  1012
            }
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
  1013
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7749
diff changeset
  1014
            status = X11_XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);