author | Michael Sartain <mikesart@valvesoftware.com> |
Tue, 05 Feb 2013 12:09:59 -0800 | |
changeset 6834 | dce4e1d1eca3 |
parent 6817 | 93103b719488 |
child 6885 | 700f1b25f77f |
permissions | -rw-r--r-- |
1950
a344e42bce3b
Started work on the new X11 driver.
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:
5505
diff
changeset
|
2 |
Simple DirectMedia Layer |
6138 | 3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
1950
a344e42bce3b
Started work on the new X11 driver.
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:
5505
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:
5505
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:
5505
diff
changeset
|
7 |
arising from the use of this software. |
1950
a344e42bce3b
Started work on the new X11 driver.
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:
5505
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:
5505
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:
5505
diff
changeset
|
11 |
freely, subject to the following restrictions: |
1950
a344e42bce3b
Started work on the new X11 driver.
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:
5505
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:
5505
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:
5505
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:
5505
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5505
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:
5505
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:
5505
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
*/ |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
#include "SDL_config.h" |
5471
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
22 |
|
5481
22dfc3958dc3
Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents:
5471
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:
5471
diff
changeset
|
24 |
|
6675
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
25 |
#include <X11/cursorfont.h> |
5471
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
26 |
#include "SDL_assert.h" |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
#include "SDL_x11video.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
|
28 |
#include "SDL_x11mouse.h" |
6316
a89c79a3f0cd
1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents:
6311
diff
changeset
|
29 |
#include "SDL_x11xinput2.h" |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
#include "../../events/SDL_mouse_c.h" |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
|
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
32 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
33 |
/* FIXME: Find a better place to put this... */ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
34 |
static Cursor x11_empty_cursor = None; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
35 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
36 |
static Display * |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
37 |
GetDisplay(void) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
38 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
39 |
return ((SDL_VideoData *)SDL_GetVideoDevice()->driverdata)->display; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
40 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
41 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
42 |
static Cursor |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
43 |
X11_CreateEmptyCursor() |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
44 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
45 |
if (x11_empty_cursor == None) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
46 |
Display *display = GetDisplay(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
47 |
char data[1]; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
48 |
XColor color; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
49 |
Pixmap pixmap; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
50 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
51 |
SDL_zero(data); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
52 |
color.red = color.green = color.blue = 0; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
53 |
pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display), |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
54 |
data, 1, 1); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
55 |
if (pixmap) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
56 |
x11_empty_cursor = XCreatePixmapCursor(display, pixmap, pixmap, |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
57 |
&color, &color, 0, 0); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
58 |
XFreePixmap(display, pixmap); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
59 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
60 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
61 |
return x11_empty_cursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
62 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
63 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
64 |
static void |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
65 |
X11_DestroyEmptyCursor(void) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
66 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
67 |
if (x11_empty_cursor != None) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
68 |
XFreeCursor(GetDisplay(), x11_empty_cursor); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
69 |
x11_empty_cursor = None; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
70 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
71 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
72 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
73 |
static SDL_Cursor * |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
74 |
X11_CreateDefaultCursor() |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
75 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
76 |
SDL_Cursor *cursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
77 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
78 |
cursor = SDL_calloc(1, sizeof(*cursor)); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
79 |
if (cursor) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
80 |
/* None is used to indicate the default cursor */ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
81 |
cursor->driverdata = (void*)None; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
82 |
} else { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
83 |
SDL_OutOfMemory(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
84 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
85 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
86 |
return cursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
87 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
88 |
|
5471
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
89 |
#if SDL_VIDEO_DRIVER_X11_XCURSOR |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
90 |
static Cursor |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
91 |
X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y) |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
92 |
{ |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
93 |
Display *display = GetDisplay(); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
94 |
Cursor cursor = None; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
95 |
XcursorImage *image; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
96 |
|
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
97 |
image = XcursorImageCreate(surface->w, surface->h); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
98 |
if (!image) { |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
99 |
SDL_OutOfMemory(); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
100 |
return None; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
101 |
} |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
102 |
image->xhot = hot_x; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
103 |
image->yhot = hot_y; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
104 |
image->delay = 0; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
105 |
|
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
106 |
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
107 |
SDL_assert(surface->pitch == surface->w * 4); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
108 |
SDL_memcpy(image->pixels, surface->pixels, surface->h * surface->pitch); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
109 |
|
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
110 |
cursor = XcursorImageLoadCursor(display, image); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
111 |
|
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
112 |
XcursorImageDestroy(image); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
113 |
|
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
114 |
return cursor; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
115 |
} |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
116 |
#endif /* SDL_VIDEO_DRIVER_X11_XCURSOR */ |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
117 |
|
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
118 |
static Cursor |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
119 |
X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
120 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
121 |
Display *display = GetDisplay(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
122 |
XColor fg, bg; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
123 |
Cursor cursor = None; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
124 |
Uint32 *ptr; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
125 |
Uint8 *data_bits, *mask_bits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
126 |
Pixmap data_pixmap, mask_pixmap; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
127 |
int x, y; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
128 |
unsigned int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
129 |
unsigned int width_bytes = ((surface->w + 7) & ~7) / 8; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
130 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
131 |
data_bits = SDL_calloc(1, surface->h * width_bytes); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
132 |
mask_bits = SDL_calloc(1, surface->h * width_bytes); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
133 |
if (!data_bits || !mask_bits) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
134 |
SDL_OutOfMemory(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
135 |
return None; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
136 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
137 |
|
5471
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
138 |
/* Code below assumes ARGB pixel format */ |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
139 |
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
140 |
|
5981
75caa8a7d559
Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
141 |
rfg = gfg = bfg = rbg = gbg = bbg = fgBits = bgBits = 0; |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
142 |
for (y = 0; y < surface->h; ++y) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
143 |
ptr = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
144 |
for (x = 0; x < surface->w; ++x) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
145 |
int alpha = (*ptr >> 24) & 0xff; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
146 |
int red = (*ptr >> 16) & 0xff; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
147 |
int green = (*ptr >> 8) & 0xff; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
148 |
int blue = (*ptr >> 0) & 0xff; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
149 |
if (alpha > 25) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
150 |
mask_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8)); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
151 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
152 |
if ((red + green + blue) > 0x40) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
153 |
fgBits++; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
154 |
rfg += red; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
155 |
gfg += green; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
156 |
bfg += blue; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
157 |
data_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8)); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
158 |
} else { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
159 |
bgBits++; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
160 |
rbg += red; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
161 |
gbg += green; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
162 |
bbg += blue; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
163 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
164 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
165 |
++ptr; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
166 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
167 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
168 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
169 |
if (fgBits) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
170 |
fg.red = rfg * 257 / fgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
171 |
fg.green = gfg * 257 / fgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
172 |
fg.blue = bfg * 257 / fgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
173 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
174 |
else fg.red = fg.green = fg.blue = 0; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
175 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
176 |
if (bgBits) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
177 |
bg.red = rbg * 257 / bgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
178 |
bg.green = gbg * 257 / bgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
179 |
bg.blue = bbg * 257 / bgBits; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
180 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
181 |
else bg.red = bg.green = bg.blue = 0; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
182 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
183 |
data_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display), |
5505
c4bb4c8ea6fd
Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents:
5481
diff
changeset
|
184 |
(char*)data_bits, |
c4bb4c8ea6fd
Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents:
5481
diff
changeset
|
185 |
surface->w, surface->h); |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
186 |
mask_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display), |
5505
c4bb4c8ea6fd
Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents:
5481
diff
changeset
|
187 |
(char*)mask_bits, |
c4bb4c8ea6fd
Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents:
5481
diff
changeset
|
188 |
surface->w, surface->h); |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
189 |
cursor = XCreatePixmapCursor(display, data_pixmap, mask_pixmap, |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
190 |
&fg, &bg, hot_x, hot_y); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
191 |
XFreePixmap(display, data_pixmap); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
192 |
XFreePixmap(display, mask_pixmap); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
193 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
194 |
return cursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
195 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
196 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
197 |
static SDL_Cursor * |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
198 |
X11_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
199 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
200 |
SDL_Cursor *cursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
201 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
202 |
cursor = SDL_calloc(1, sizeof(*cursor)); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
203 |
if (cursor) { |
5471
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
204 |
Cursor x11_cursor = None; |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
205 |
|
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
206 |
#if SDL_VIDEO_DRIVER_X11_XCURSOR |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
207 |
if (SDL_X11_HAVE_XCURSOR) { |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
208 |
x11_cursor = X11_CreateXCursorCursor(surface, hot_x, hot_y); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
209 |
} |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
210 |
#endif |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
211 |
if (x11_cursor == None) { |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
212 |
x11_cursor = X11_CreatePixmapCursor(surface, hot_x, hot_y); |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
213 |
} |
179adad3ae6f
Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents:
5470
diff
changeset
|
214 |
cursor->driverdata = (void*)x11_cursor; |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
215 |
} else { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
216 |
SDL_OutOfMemory(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
217 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
218 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
219 |
return cursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
220 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
221 |
|
6675
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
222 |
static SDL_Cursor * |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
223 |
X11_CreateSystemCursor(SDL_SystemCursor id) |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
224 |
{ |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
225 |
SDL_Cursor *cursor; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
226 |
unsigned int shape; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
227 |
|
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
228 |
switch(id) |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
229 |
{ |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
230 |
default: |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
231 |
SDL_assert(0); |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
232 |
return NULL; |
6834
dce4e1d1eca3
Use left facing arrow instead of right facing arrow for system cursor.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6817
diff
changeset
|
233 |
// X Font Cursors reference: |
dce4e1d1eca3
Use left facing arrow instead of right facing arrow for system cursor.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6817
diff
changeset
|
234 |
// http://tronche.com/gui/x/xlib/appendix/b/ |
dce4e1d1eca3
Use left facing arrow instead of right facing arrow for system cursor.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6817
diff
changeset
|
235 |
case SDL_SYSTEM_CURSOR_ARROW: shape = XC_left_ptr; break; |
6675
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
236 |
case SDL_SYSTEM_CURSOR_IBEAM: shape = XC_xterm; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
237 |
case SDL_SYSTEM_CURSOR_WAIT: shape = XC_watch; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
238 |
case SDL_SYSTEM_CURSOR_CROSSHAIR: shape = XC_tcross; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
239 |
case SDL_SYSTEM_CURSOR_WAITARROW: shape = XC_watch; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
240 |
case SDL_SYSTEM_CURSOR_SIZENWSE: shape = XC_fleur; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
241 |
case SDL_SYSTEM_CURSOR_SIZENESW: shape = XC_fleur; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
242 |
case SDL_SYSTEM_CURSOR_SIZEWE: shape = XC_sb_h_double_arrow; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
243 |
case SDL_SYSTEM_CURSOR_SIZENS: shape = XC_sb_v_double_arrow; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
244 |
case SDL_SYSTEM_CURSOR_SIZEALL: shape = XC_fleur; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
245 |
case SDL_SYSTEM_CURSOR_NO: shape = XC_pirate; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
246 |
case SDL_SYSTEM_CURSOR_HAND: shape = XC_hand2; break; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
247 |
} |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
248 |
|
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
249 |
cursor = SDL_calloc(1, sizeof(*cursor)); |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
250 |
if (cursor) { |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
251 |
Cursor x11_cursor; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
252 |
|
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
253 |
x11_cursor = XCreateFontCursor(GetDisplay(), shape); |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
254 |
|
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
255 |
cursor->driverdata = (void*)x11_cursor; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
256 |
} else { |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
257 |
SDL_OutOfMemory(); |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
258 |
} |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
259 |
|
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
260 |
return cursor; |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
261 |
} |
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
262 |
|
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
263 |
static void |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
264 |
X11_FreeCursor(SDL_Cursor * cursor) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
265 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
266 |
Cursor x11_cursor = (Cursor)cursor->driverdata; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
267 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
268 |
if (x11_cursor != None) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
269 |
XFreeCursor(GetDisplay(), x11_cursor); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
270 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
271 |
SDL_free(cursor); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
272 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
273 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
274 |
static int |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
275 |
X11_ShowCursor(SDL_Cursor * cursor) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
276 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
277 |
Cursor x11_cursor = 0; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
278 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
279 |
if (cursor) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
280 |
x11_cursor = (Cursor)cursor->driverdata; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
281 |
} else { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
282 |
x11_cursor = X11_CreateEmptyCursor(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
283 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
284 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
285 |
/* FIXME: Is there a better way than this? */ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
286 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
287 |
SDL_VideoDevice *video = SDL_GetVideoDevice(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
288 |
Display *display = GetDisplay(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
289 |
SDL_Window *window; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
290 |
SDL_WindowData *data; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
291 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
292 |
for (window = video->windows; window; window = window->next) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
293 |
data = (SDL_WindowData *)window->driverdata; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
294 |
if (x11_cursor != None) { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
295 |
XDefineCursor(display, data->xwindow, x11_cursor); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
296 |
} else { |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
297 |
XUndefineCursor(display, data->xwindow); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
298 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
299 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
300 |
XFlush(display); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
301 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
302 |
return 0; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
303 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
304 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
305 |
static void |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
306 |
X11_WarpMouse(SDL_Window * window, int x, int y) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
307 |
{ |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
308 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
309 |
Display *display = data->videodata->display; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
310 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
311 |
XWarpPointer(display, None, data->xwindow, 0, 0, 0, 0, x, y); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
312 |
XSync(display, False); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
313 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
314 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
315 |
static int |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
316 |
X11_SetRelativeMouseMode(SDL_bool enabled) |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
317 |
{ |
6311
4e5e46f43438
Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
318 |
#if SDL_VIDEO_DRIVER_X11_XINPUT2 |
6316
a89c79a3f0cd
1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents:
6311
diff
changeset
|
319 |
if(X11_Xinput2IsInitialized()) |
a89c79a3f0cd
1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents:
6311
diff
changeset
|
320 |
return 0; |
6311
4e5e46f43438
Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
321 |
#else |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
322 |
SDL_Unsupported(); |
6316
a89c79a3f0cd
1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents:
6311
diff
changeset
|
323 |
#endif |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
324 |
return -1; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
325 |
} |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
326 |
|
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 |
X11_InitMouse(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 |
{ |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
330 |
SDL_Mouse *mouse = SDL_GetMouse(); |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
331 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
332 |
mouse->CreateCursor = X11_CreateCursor; |
6675
20f3cdea0fd2
Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents:
6316
diff
changeset
|
333 |
mouse->CreateSystemCursor = X11_CreateSystemCursor; |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
334 |
mouse->ShowCursor = X11_ShowCursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
335 |
mouse->FreeCursor = X11_FreeCursor; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
336 |
mouse->WarpMouse = X11_WarpMouse; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
337 |
mouse->SetRelativeMouseMode = X11_SetRelativeMouseMode; |
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
338 |
|
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
339 |
SDL_SetDefaultCursor(X11_CreateDefaultCursor()); |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 |
} |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 |
|
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 |
X11_QuitMouse(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 |
{ |
5470
8f5e10ec4faf
Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
345 |
X11_DestroyEmptyCursor(); |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 |
} |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 |
|
5481
22dfc3958dc3
Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents:
5471
diff
changeset
|
348 |
#endif /* SDL_VIDEO_DRIVER_X11 */ |
22dfc3958dc3
Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents:
5471
diff
changeset
|
349 |
|
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 |
/* vi: set ts=4 sw=4 expandtab: */ |