annotate src/video/x11/SDL_x11window.c @ 3218:81773a1eac83

Patch from David Carre: I fixed a bug in the "SDL_DestroyRenderer()" function in the pandora x11 renderer (in fact the bug was in the "X11_GLES_MakeCurrent()" function) that was causing a crash when exiting SDL. There was a problem while terminating the x11 egl window, that was preventing to quit/close SDL/SDL-window then reload SDL/SDL-window inside the same application.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 30 Jul 2009 14:53:57 +0000
parents 494559cc723b
children 5859d0a0c519
rev   line source
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2725
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_syswm.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "../SDL_sysvideo.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "../../events/SDL_keyboard_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: 2931
diff changeset
27 #include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #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: 2931
diff changeset
30 #include "SDL_x11mouse.h"
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
31 #include "SDL_x11gamma.h"
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
32 #include "../Xext/extensions/StdCmap.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
34 #ifdef SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
35 #include "SDL_x11opengles.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
36 #endif
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
37
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
38 #define _NET_WM_STATE_REMOVE 0l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
39 #define _NET_WM_STATE_ADD 1l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
40 #define _NET_WM_STATE_TOGGLE 2l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
41
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
42 static void
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
43 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
44 {
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
45 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
46 SDL_DisplayData *displaydata =
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
47 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
48 XWindowAttributes attr;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
49
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
50 XGetWindowAttributes(data->display, RootWindow(data->display,
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
51 displaydata->screen),
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
52 &attr);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
53 if (w) {
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
54 *w = attr.width;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
55 }
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
56 if (h) {
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
57 *h = attr.height;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
58 }
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
59 }
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
60
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 static int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 int numwindows = videodata->numwindows;
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
67 int windowlistlength = videodata->windowlistlength;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 SDL_WindowData **windowlist = videodata->windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
69 int index;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 /* Allocate the window data */
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
72 data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 data->windowID = window->id;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 data->window = w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 data->ic =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 XNResourceName, videodata->classname, XNResourceClass,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 videodata->classname, NULL);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 data->created = created;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 data->videodata = videodata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
91 /* Associate the data with the 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
92
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
93 if (numwindows < windowlistlength) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
94 windowlist[numwindows] = data;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
95 videodata->numwindows++;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
96 } else {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
97 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
98 (SDL_WindowData **) SDL_realloc(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
99 (numwindows +
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
100 1) * sizeof(*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
101 if (!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
102 SDL_OutOfMemory();
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
103 SDL_free(data);
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
104 return -1;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
105 }
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
106 windowlist[numwindows] = data;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
107 videodata->numwindows++;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
108 videodata->windowlistlength++;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
109 videodata->windowlist = windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
110 }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
111
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 /* Fill in the SDL window with the window data */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 XWindowAttributes attrib;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 XGetWindowAttributes(data->videodata->display, w, &attrib);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 window->x = attrib.x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 window->y = attrib.y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 window->w = attrib.width;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 window->h = attrib.height;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 if (attrib.map_state != IsUnmapped) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 window->flags |= SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 window->flags &= ~SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
127
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
128 {
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
129 Atom _NET_WM_STATE =
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
130 XInternAtom(data->videodata->display, "_NET_WM_STATE", False);
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
131 Atom _NET_WM_STATE_MAXIMIZED_VERT =
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
132 XInternAtom(data->videodata->display,
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
133 "_NET_WM_STATE_MAXIMIZED_VERT", False);
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
134 Atom _NET_WM_STATE_MAXIMIZED_HORZ =
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
135 XInternAtom(data->videodata->display,
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
136 "_NET_WM_STATE_MAXIMIZED_HORZ", False);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
137 Atom actualType;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
138 int actualFormat;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
139 unsigned long i, numItems, bytesAfter;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
140 unsigned char *propertyValue = NULL;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
141 long maxLength = 1024;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
142
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
143 if (XGetWindowProperty(data->videodata->display, w, _NET_WM_STATE,
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
144 0l, maxLength, False, XA_ATOM, &actualType,
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
145 &actualFormat, &numItems, &bytesAfter,
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
146 &propertyValue) == Success) {
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
147 Atom *atoms = (Atom *) propertyValue;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
148 int maximized = 0;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
149
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
150 for (i = 0; i < numItems; ++i) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
151 if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
152 maximized |= 1;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
153 } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
154 maximized |= 2;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
155 }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
156 /* Might also want to check the following properties:
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
157 _NET_WM_STATE_ABOVE, _NET_WM_STATE_FULLSCREEN
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
158 */
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
159 }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
160 if (maximized == 3) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
161 window->flags |= SDL_WINDOW_MAXIMIZED;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
162 }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
163 XFree(propertyValue);
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
164 }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
165 }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
166
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 /* FIXME: How can I tell?
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 DWORD style = GetWindowLong(hwnd, GWL_STYLE);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 if (style & WS_VISIBLE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 if (style & (WS_BORDER | WS_THICKFRAME)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 window->flags &= ~SDL_WINDOW_BORDERLESS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 window->flags |= SDL_WINDOW_BORDERLESS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 if (style & WS_THICKFRAME) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 window->flags |= SDL_WINDOW_RESIZABLE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 window->flags &= ~SDL_WINDOW_RESIZABLE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 if (style & WS_MAXIMIZE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 window->flags |= SDL_WINDOW_MAXIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 window->flags &= ~SDL_WINDOW_MAXIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 if (style & WS_MINIMIZE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 window->flags |= SDL_WINDOW_MINIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 window->flags &= ~SDL_WINDOW_MINIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 if (GetFocus() == hwnd) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 int index = data->videodata->keyboard;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 window->flags |= SDL_WINDOW_INPUT_FOCUS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 SDL_SetKeyboardFocus(index, data->windowID);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 RECT rect;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 GetClientRect(hwnd, &rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 ClientToScreen(hwnd, (LPPOINT) & rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 ClipCursor(&rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 /* All done! */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 window->driverdata = data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 X11_CreateWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 SDL_DisplayData *displaydata =
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
217 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 Visual *visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 int depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 XSetWindowAttributes xattr;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 int x, y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 Window w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 XSizeHints *sizehints;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 XWMHints *wmhints;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 XClassHint *classhints;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 #if SDL_VIDEO_DRIVER_X11_XINERAMA
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 /* FIXME
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 if ( use_xinerama ) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 x = xinerama_info.x_org;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 y = xinerama_info.y_org;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 #endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
235 #ifdef SDL_VIDEO_OPENGL_GLX
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 if (window->flags & SDL_WINDOW_OPENGL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
237 XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
238
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
239 vinfo = X11_GL_GetVisual(_this, data->display, displaydata->screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
240 if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
241 return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
242 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
243 visual = vinfo->visual;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
244 depth = vinfo->depth;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
245 XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
246 } else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
247 #endif
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
248 #ifdef SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
249 if (window->flags & SDL_WINDOW_OPENGL) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
250 XVisualInfo *vinfo;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
251
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
252 vinfo = X11_GLES_GetVisual(_this, data->display, displaydata->screen);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
253 if (!vinfo) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
254 return -1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
255 }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
256 visual = vinfo->visual;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
257 depth = vinfo->depth;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
258 XFree(vinfo);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
259 } else
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
260 #endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
261 {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 visual = displaydata->visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 depth = displaydata->depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 if (window->flags & SDL_WINDOW_FULLSCREEN) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 xattr.override_redirect = True;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 xattr.override_redirect = False;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 xattr.background_pixel = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 xattr.border_pixel = 0;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
273
2945
e38423786728 Fixed DirectColor visual window creation problem
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
274 if (visual->class == PseudoColor) {
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
275 printf("asking for PseudoColor\n");
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
276
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
277 Status status;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
278 XStandardColormap cmap;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
279 XColor *colorcells;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
280 Colormap colormap;
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
281 Sint32 pix;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
282 Sint32 ncolors;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
283 Sint32 nbits;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
284 Sint32 rmax, gmax, bmax;
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
285 Sint32 rwidth, gwidth, bwidth;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
286 Sint32 rmask, gmask, bmask;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
287 Sint32 rshift, gshift, bshift;
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
288 Sint32 r, g, b;
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
289
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
290 /* Is the colormap we need already registered in SDL? */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
291 if (colormap =
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
292 X11_LookupColormap(data->display,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
293 displaydata->screen, visual->visualid)) {
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
294 xattr.colormap = colormap;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
295 /* printf("found existing colormap\n"); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
296 } else {
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
297 /* The colormap is not known to SDL so we will create it */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
298 colormap = XCreateColormap(data->display,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
299 RootWindow(data->display,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
300 displaydata->screen),
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
301 visual, AllocAll);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
302 /* printf("colormap = %x\n", colormap); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
303
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
304 /* If we can't create a colormap, then we must die */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
305 if (!colormap) {
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
306 SDL_SetError
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
307 ("Couldn't create window: Could not create writable colormap");
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
308 return -1;
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
309 }
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
310
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
311 /* OK, we got a colormap, now fill it in as best as we can */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
312
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
313 colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
314 if (NULL == colorcells) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
315 SDL_SetError("out of memory in X11_CreateWindow");
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
316 return -1;
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
317 }
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
318
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
319 ncolors = visual->map_entries;
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
320 nbits = visual->bits_per_rgb;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
321
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
322 /* printf("ncolors = %d nbits = %d\n", ncolors, nbits); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
323
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
324 /* what if ncolors != (1 << nbits)? That can happen on a
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
325 true PseudoColor display. I'm assuming that we will
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
326 always have ncolors == (1 << nbits) */
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
327
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
328 /* I'm making a lot of assumptions here. */
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
329
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
330 /* Compute the width of each field. If there is one extra
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
331 bit, give it to green. If there are two extra bits give
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
332 them to red and greed. We can get extra bits when the
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
333 number of bits per pixel is not a multiple of 3. For
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
334 example when we have 16 bits per pixel and need a 5/6/5
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
335 layout for the RGB fields */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
336
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
337 rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
338 gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0);
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
339 bwidth = (nbits / 3);
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
340
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
341 rshift = gwidth + bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
342 gshift = bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
343 bshift = 0;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
344
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
345 rmax = 1 << rwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
346 gmax = 1 << gwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
347 bmax = 1 << bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
348
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
349 rmask = rmax - 1;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
350 gmask = gmax - 1;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
351 bmask = bmax - 1;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
352
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
353 /* printf("red mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
354 /* printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
355 /* printf("blue mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
356
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
357 /* build the color table pixel values */
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
358 pix = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
359 for (r = 0; r < rmax; r++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
360 for (g = 0; g < gmax; g++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
361 for (b = 0; b < bmax; b++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
362 colorcells[pix].pixel =
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
363 (r << rshift) | (g << gshift) | (b << bshift);
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
364 colorcells[pix].red = (0xffff * r) / rmask;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
365 colorcells[pix].green = (0xffff * g) / gmask;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
366 colorcells[pix].blue = (0xffff * b) / bmask;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
367 /* printf("%4x:%4x [%4x %4x %4x]\n", */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
368 /* pix, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
369 /* colorcells[pix].pixel, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
370 /* colorcells[pix].red, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
371 /* colorcells[pix].green, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
372 /* colorcells[pix].blue); */
3052
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
373 pix++;
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
374 }
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
375 }
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
376 }
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
377
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
378 /* status = */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
379 /* XStoreColors(data->display, colormap, colorcells, ncolors); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
380
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
381 xattr.colormap = colormap;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
382 X11_TrackColormap(data->display, displaydata->screen,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
383 colormap, visual, NULL);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
384
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
385 SDL_free(colorcells);
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
386 }
2945
e38423786728 Fixed DirectColor visual window creation problem
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
387 } else if (visual->class == DirectColor) {
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
388 Status status;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
389 XStandardColormap cmap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
390 XColor *colorcells;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
391 Colormap colormap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
392 int i;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
393 int ncolors;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
394 int rmax, gmax, bmax;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
395 int rmask, gmask, bmask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
396 int rshift, gshift, bshift;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
397
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
398 /* Is the colormap we need already registered in SDL? */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
399 if (colormap =
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
400 X11_LookupColormap(data->display,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
401 displaydata->screen, visual->visualid)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
402 xattr.colormap = colormap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
403 /* printf("found existing colormap\n"); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
404 } else {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
405 /* The colormap is not known to SDL so we will create it */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
406 colormap = XCreateColormap(data->display,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
407 RootWindow(data->display,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
408 displaydata->screen),
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
409 visual, AllocAll);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
410 /* printf("colormap = %x\n", colormap); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
411
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
412 /* If we can't create a colormap, then we must die */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
413 if (!colormap) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
414 SDL_SetError
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
415 ("Couldn't create window: Could not create writable colormap");
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
416 return -1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
417 }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
418
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
419 /* OK, we got a colormap, now fill it in as best as we can */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
420
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
421 colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
422 if (NULL == colorcells) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
423 SDL_SetError("out of memory in X11_CreateWindow");
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
424 return -1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
425 }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
426 ncolors = visual->map_entries;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
427 rmax = 0xffff;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
428 gmax = 0xffff;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
429 bmax = 0xffff;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
430
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
431 rshift = 0;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
432 rmask = visual->red_mask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
433 while (0 == (rmask & 1)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
434 rshift++;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
435 rmask >>= 1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
436 }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
437
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
438 /* printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
439
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
440 gshift = 0;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
441 gmask = visual->green_mask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
442 while (0 == (gmask & 1)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
443 gshift++;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
444 gmask >>= 1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
445 }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
446
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
447 /* printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
448
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
449 bshift = 0;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
450 bmask = visual->blue_mask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
451 while (0 == (bmask & 1)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
452 bshift++;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
453 bmask >>= 1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
454 }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
455
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
456 /* printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
457
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
458 /* build the color table pixel values */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
459 for (i = 0; i < ncolors; i++) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
460 Uint32 red = (rmax * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
461 Uint32 green = (gmax * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
462 Uint32 blue = (bmax * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
463
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
464 Uint32 rbits = (rmask * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
465 Uint32 gbits = (gmask * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
466 Uint32 bbits = (bmask * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
467
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
468 Uint32 pix =
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
469 (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
470
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
471 colorcells[i].pixel = pix;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
472
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
473 colorcells[i].red = red;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
474 colorcells[i].green = green;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
475 colorcells[i].blue = blue;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
476
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
477 colorcells[i].flags = DoRed | DoGreen | DoBlue;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
478 /* printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
479 }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
480
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
481 status =
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
482 XStoreColors(data->display, colormap, colorcells, ncolors);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
483
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
484 xattr.colormap = colormap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
485 X11_TrackColormap(data->display, displaydata->screen,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
486 colormap, visual, colorcells);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
487
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
488 SDL_free(colorcells);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
489 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 xattr.colormap =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 XCreateColormap(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 RootWindow(data->display, displaydata->screen),
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 visual, AllocNone);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
497 if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
498 || window->x == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
499 X11_GetDisplaySize(_this, window, &x, NULL);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
500 x = (x - window->w) / 2;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 x = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 x = window->x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 }
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
506 if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
507 || window->y == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
508 X11_GetDisplaySize(_this, window, NULL, &y);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
509 y = (y - window->h) / 2;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 y = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 y = window->y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 w = XCreateWindow(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 RootWindow(data->display, displaydata->screen), x, y,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 window->w, window->h, 0, depth, InputOutput, visual,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 CWColormap), &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
521 if (!w) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
522 SDL_SetError("Couldn't create window");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
523 return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
524 }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
525 #if SDL_VIDEO_DRIVER_PANDORA
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
526 /* Create the GLES window surface */
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
527 _this->gles_data->egl_surface =
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
528 _this->gles_data->eglCreateWindowSurface(_this->gles_data->
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
529 egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
530 _this->gles_data->egl_config,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
531 (NativeWindowType) w, NULL);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
532
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
533 if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
534 SDL_SetError("Could not create GLES window surface");
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
535 return -1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
536 }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
537 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 sizehints = XAllocSizeHints();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 if (sizehints) {
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
541 if ((window->flags & SDL_WINDOW_RESIZABLE)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
542 && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 sizehints->min_width = 32;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 sizehints->min_height = 32;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 sizehints->max_height = 4096;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 sizehints->max_width = 4096;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 sizehints->min_width = sizehints->max_width = window->w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 sizehints->min_height = sizehints->max_height = window->h;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 sizehints->flags = PMaxSize | PMinSize;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 if (!(window->flags & SDL_WINDOW_FULLSCREEN)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 && window->x != SDL_WINDOWPOS_UNDEFINED
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 && window->y != SDL_WINDOWPOS_UNDEFINED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 sizehints->x = x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 sizehints->y = y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 sizehints->flags |= USPosition;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 XSetWMNormalHints(data->display, w, sizehints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 XFree(sizehints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
563 if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 SDL_bool set;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 Atom WM_HINTS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 /* We haven't modified the window manager hints yet */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 set = SDL_FALSE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 /* First try to set MWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 /* Hints used by Motif compliant window managers */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 struct
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 unsigned long flags;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 unsigned long functions;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 unsigned long decorations;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 long input_mode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 unsigned long status;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 } MWMHints = {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 (1L << 1), 0, 0, 0, 0};
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 XChangeProperty(data->display, w, WM_HINTS, WM_HINTS, 32,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 PropModeReplace, (unsigned char *) &MWMHints,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 sizeof(MWMHints) / sizeof(long));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 set = SDL_TRUE;
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 /* Now try to set KWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 long KWMHints = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 XChangeProperty(data->display, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 WM_HINTS, WM_HINTS, 32,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 PropModeReplace,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 (unsigned char *) &KWMHints,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 sizeof(KWMHints) / sizeof(long));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 /* Now try to set GNOME hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 long GNOMEHints = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 XChangeProperty(data->display, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 WM_HINTS, WM_HINTS, 32,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 PropModeReplace,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 (unsigned char *) &GNOMEHints,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 sizeof(GNOMEHints) / sizeof(long));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 /* Finally set the transient hints if necessary */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 if (!set) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 XSetTransientForHint(data->display, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 RootWindow(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 displaydata->screen));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 SDL_bool set;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 Atom WM_HINTS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 /* We haven't modified the window manager hints yet */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 set = SDL_FALSE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626 /* First try to unset MWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627 WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 XDeleteProperty(data->display, w, WM_HINTS);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 set = SDL_TRUE;
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 /* Now try to unset KWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 XDeleteProperty(data->display, w, WM_HINTS);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 /* Now try to unset GNOME hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641 XDeleteProperty(data->display, w, WM_HINTS);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 /* Finally unset the transient hints if necessary */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 if (!set) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 /* NOTE: Does this work? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647 XSetTransientForHint(data->display, w, None);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
651 /* Tell KDE to keep fullscreen windows on top */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 if (window->flags & SDL_WINDOW_FULLSCREEN) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653 XEvent ev;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 long mask;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
655
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 SDL_zero(ev);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
657 ev.xclient.type = ClientMessage;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
658 ev.xclient.window = RootWindow(data->display, displaydata->screen);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
659 ev.xclient.message_type =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
660 XInternAtom(data->display, "KWM_KEEP_ON_TOP", False);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
661 ev.xclient.format = 32;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
662 ev.xclient.data.l[0] = w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
663 ev.xclient.data.l[1] = CurrentTime;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664 XSendEvent(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665 RootWindow(data->display, displaydata->screen), False,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 SubstructureRedirectMask, &ev);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 }
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 /* Set the input hints so we get keyboard input */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 wmhints = XAllocWMHints();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 if (wmhints) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 wmhints->input = True;
1956
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
673 wmhints->flags = InputHint;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 XSetWMHints(data->display, w, wmhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675 XFree(wmhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
678 /* Set the class hints so we can get an icon (AfterStep) */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679 classhints = XAllocClassHint();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680 if (classhints != NULL) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 classhints->res_name = data->classname;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 classhints->res_class = data->classname;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
683 XSetClassHint(data->display, w, classhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
684 XFree(classhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
687 /* Allow the window to be deleted by the window manager */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688 XSetWMProtocols(data->display, w, &data->WM_DELETE_WINDOW, 1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
689
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690 if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
691 XDestroyWindow(data->display, w);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692 return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693 }
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
694 #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
695 {
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
696 Uint32 fevent = 0;
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
697 pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
698 XNFilterEvents, &fevent, NULL);
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
699 XSelectInput(data->display, w,
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
700 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
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
701 ExposureMask | ButtonPressMask | ButtonReleaseMask |
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
702 PointerMotionMask | KeyPressMask | KeyReleaseMask |
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
703 PropertyChangeMask | StructureNotifyMask |
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
704 KeymapStateMask | fevent));
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
705 }
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
706 #else
2718
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
707 {
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
708 XSelectInput(data->display, w,
2725
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
709 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
710 ExposureMask | ButtonPressMask | ButtonReleaseMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
711 PointerMotionMask | KeyPressMask | KeyReleaseMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
712 PropertyChangeMask | StructureNotifyMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
713 KeymapStateMask));
2718
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
714 }
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
715 #endif
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
716
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: 2931
diff changeset
717 #if SDL_VIDEO_DRIVER_X11_XINPUT
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2325
diff changeset
718 /* we're informing the display what extension events we want to receive from it */
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: 2931
diff changeset
719 {
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: 2931
diff changeset
720 int i, j, n = 0;
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: 2931
diff changeset
721 XEventClass xevents[256];
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: 2931
diff changeset
722
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: 2931
diff changeset
723 for (i = 0; i < SDL_GetNumMice(); ++i) {
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: 2931
diff changeset
724 SDL_Mouse *mouse;
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: 2931
diff changeset
725 X11_MouseData *data;
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: 2931
diff changeset
726
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: 2931
diff changeset
727 mouse = SDL_GetMouse(i);
2942
Sam Lantinga <slouken@libsdl.org>
parents: 2940
diff changeset
728 data = (X11_MouseData *) mouse->driverdata;
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: 2931
diff changeset
729 if (!data) {
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: 2931
diff changeset
730 continue;
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: 2931
diff changeset
731 }
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: 2931
diff changeset
732
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: 2931
diff changeset
733 for (j = 0; j < data->num_xevents; ++j) {
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: 2931
diff changeset
734 xevents[n++] = data->xevents[j];
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: 2931
diff changeset
735 }
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: 2931
diff changeset
736 }
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: 2931
diff changeset
737 if (n > 0) {
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: 2931
diff changeset
738 XSelectExtensionEvent(data->display, w, xevents, n);
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: 2931
diff changeset
739 }
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: 2931
diff changeset
740 }
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: 2931
diff changeset
741 #endif
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2325
diff changeset
742
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
743 return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
744 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
745
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
746 int
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
747 X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
748 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
749 Window w = (Window) data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
750
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
751 /* FIXME: Query the title from the existing window */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
752
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
753 if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
754 return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
755 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
756 return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
757 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
758
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
759 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760 X11_SetWindowTitle(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
761 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
762 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
763 Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
764 XTextProperty titleprop, iconprop;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
765 Status status;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766 const char *title = window->title;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
767 const char *icon = NULL;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
770 Atom _NET_WM_NAME = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
771 Atom _NET_WM_ICON_NAME = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
773 /* Look up some useful Atoms */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
774 if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
775 _NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", False);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
776 _NET_WM_ICON_NAME = XInternAtom(display, "_NET_WM_ICON_NAME", False);
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 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
780 if (title != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
781 char *title_locale = SDL_iconv_utf8_locale(title);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
782 if (!title_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
783 SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
784 return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
785 }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
786 status = XStringListToTextProperty(&title_locale, 1, &titleprop);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
787 SDL_free(title_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788 if (status) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
789 XSetTextProperty(display, data->window, &titleprop, XA_WM_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
790 XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
791 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
792 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793 if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
794 status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795 Xutf8TextListToTextProperty(display, (char **) &title, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
796 XUTF8StringStyle, &titleprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
797 if (status == Success) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
798 XSetTextProperty(display, data->window, &titleprop,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
799 _NET_WM_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
800 XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
802 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
803 #endif
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 if (icon != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
806 char *icon_locale = SDL_iconv_utf8_locale(icon);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
807 if (!icon_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
809 return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
811 status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
812 SDL_free(icon_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813 if (status) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 XSetTextProperty(display, data->window, &iconprop,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
815 XA_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
816 XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819 if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820 status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821 Xutf8TextListToTextProperty(display, (char **) &icon, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
822 XUTF8StringStyle, &iconprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 if (status == Success) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
824 XSetTextProperty(display, data->window, &iconprop,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
825 _NET_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
826 XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
828 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
829 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
830 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
832
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
833 void
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
834 X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
835 {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
836 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
837 Display *display = data->videodata->display;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
838 Atom _NET_WM_ICON = XInternAtom(display, "_NET_WM_ICON", False);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
839
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
840 if (icon) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
841 SDL_PixelFormat format;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
842 SDL_Surface *surface;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
843 int propsize;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
844 Uint32 *propdata;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
845
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
846 /* Convert the icon to ARGB for modern window managers */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
847 SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
848 0xFF000000);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
849 surface = SDL_ConvertSurface(icon, &format, 0);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
850 if (!surface) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
851 return;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
852 }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
853
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
854 /* Set the _NET_WM_ICON property */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
855 propsize = 2 + (icon->w * icon->h);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
856 propdata = SDL_malloc(propsize * sizeof(Uint32));
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
857 if (propdata) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
858 propdata[0] = icon->w;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
859 propdata[1] = icon->h;
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
860 SDL_memcpy(&propdata[2], surface->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
861 surface->h * surface->pitch);
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
862 XChangeProperty(display, data->window, _NET_WM_ICON, XA_CARDINAL,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
863 32, PropModeReplace, (unsigned char *) propdata,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
864 propsize);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
865 }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
866 SDL_FreeSurface(surface);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
867 } else {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
868 XDeleteProperty(display, data->window, _NET_WM_ICON);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
869 }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
870 }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
871
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
872 void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
873 X11_SetWindowPosition(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
874 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
875 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
876 SDL_DisplayData *displaydata =
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
877 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
878 Display *display = data->videodata->display;
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
879 int x, y;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
880
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
881 if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
882 || window->x == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
883 X11_GetDisplaySize(_this, window, &x, NULL);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
884 x = (x - window->w) / 2;
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
885 } else {
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
886 x = window->x;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
887 }
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
888 if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
889 || window->y == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
890 X11_GetDisplaySize(_this, window, NULL, &y);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
891 y = (y - window->h) / 2;
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
892 } else {
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
893 y = window->y;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
894 }
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
895 XMoveWindow(display, data->window, x, y);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
896 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
897
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
898 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
899 X11_SetWindowSize(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
900 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
901 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
902 Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
903
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
904 XResizeWindow(display, data->window, window->w, window->h);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
905 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
906
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
907 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
908 X11_ShowWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
909 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
910 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
911 Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
912
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
913 XMapRaised(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
914 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
915
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
916 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
917 X11_HideWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
918 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
919 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
920 Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
921
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
922 XUnmapWindow(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
923 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
924
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
925 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
926 X11_RaiseWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
927 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
928 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
929 Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
930
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
931 XRaiseWindow(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
932 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
933
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
934 static void
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
935 X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
936 {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
937 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
938 SDL_DisplayData *displaydata =
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
939 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
940 Display *display = data->videodata->display;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
941 Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", False);
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
942 Atom _NET_WM_STATE_MAXIMIZED_VERT =
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
943 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
944 Atom _NET_WM_STATE_MAXIMIZED_HORZ =
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
945 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
946 XEvent e;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
947
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
948 e.xany.type = ClientMessage;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
949 e.xany.window = data->window;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
950 e.xclient.message_type = _NET_WM_STATE;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
951 e.xclient.format = 32;
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
952 e.xclient.data.l[0] =
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
953 maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
954 e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
955 e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
956 e.xclient.data.l[3] = 0l;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
957 e.xclient.data.l[4] = 0l;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
958
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
959 XSendEvent(display, RootWindow(display, displaydata->screen), 0,
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
960 SubstructureNotifyMask | SubstructureRedirectMask, &e);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
961 }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
962
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
963 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
964 X11_MaximizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
965 {
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
966 X11_SetWindowMaximized(_this, window, SDL_TRUE);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
967 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
968
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
969 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
970 X11_MinimizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
971 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
972 X11_HideWindow(_this, window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
973 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
974
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
975 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
976 X11_RestoreWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
977 {
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
978 X11_SetWindowMaximized(_this, window, SDL_FALSE);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
979 X11_ShowWindow(_this, window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
980 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
981
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
982 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
983 X11_SetWindowGrab(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
984 {
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
985 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
986 Display *display = data->videodata->display;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
987
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
988 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
989 && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
990 /* Try to grab the mouse */
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
991 for (;;) {
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
992 int result =
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
993 XGrabPointer(display, data->window, True, 0, GrabModeAsync,
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
994 GrabModeAsync, data->window, None, CurrentTime);
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
995 if (result == GrabSuccess) {
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
996 break;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
997 }
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
998 SDL_Delay(100);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
999 }
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1000
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1001 /* Raise the window if we grab the mouse */
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1002 XRaiseWindow(display, data->window);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1003
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1004 /* Now grab the keyboard */
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
1005 XGrabKeyboard(display, data->window, True, GrabModeAsync,
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
1006 GrabModeAsync, CurrentTime);
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1007 } else {
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1008 XUngrabPointer(display, CurrentTime);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1009 XUngrabKeyboard(display, CurrentTime);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
1010 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1011 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1012
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1013 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1014 X11_DestroyWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1015 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1016 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1017 window->driverdata = NULL;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1018
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1019 if (data) {
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1020 SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1021 Display *display = videodata->display;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1022 int numwindows = videodata->numwindows;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1023 SDL_WindowData **windowlist = videodata->windowlist;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1024 int i;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1025
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1026 if (windowlist) {
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
1027 for (i = 0; i < 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
1028 if (windowlist[i] && (windowlist[i]->windowID == window->id)) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
1029 windowlist[i] = windowlist[numwindows - 1];
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
1030 windowlist[numwindows - 1] = NULL;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
1031 videodata->numwindows--;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
1032 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
1033 }
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1034 }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
1035 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1036 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1037 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1038 XDestroyIC(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1039 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1040 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1041 if (data->created) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1042 XDestroyWindow(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1043 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1044 SDL_free(data);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1045 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1046 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1047
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1048 SDL_bool
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1049 X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1050 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1051 if (info->version.major <= SDL_MAJOR_VERSION) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1052 /* FIXME! */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1053 return SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1054 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1055 SDL_SetError("Application not compiled with SDL %d.%d\n",
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1056 SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1057 return SDL_FALSE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1058 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1059 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1060
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1061 /* vi: set ts=4 sw=4 expandtab: */