Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11video.h @ 4139:568c9b3c0167 SDL-1.2
* Added configure option --enable-screensaver, to allow enabling the screensaver by default.
* Use XResetScreenSaver() instead of disabling screensaver entirely.
Full discussion summary from Erik on the SDL mailing list:
Current behaviour
=================
SDL changes the user's display power management settings without
permission from the user and without telling the user.
The interface that it uses to do so is DPMSDisable/DPMSEnable, which
should only ever be used by configuration utilities like KControl, never
by normal application programs, let alone by the libraries that they
use. Using an interface that is not at all intended for what SDL tries
to achieve means that it will not work as it should. Firstly, the power
management is completely disabled during the whole lifetime of the SDL
program, not only when it should be. Secondly, it makes SDL
non-reentrant, meaning that things will break when multiple SDL programs
are clients of the same X server simultaneously. Thirdly, no cleanup
mechanism ensures that the setting is restored if the client does not do
that (for example if it crashes).
In addition to that, this interface is broken on xorg,
[http://bugs.freedesktop.org/show_bug.cgi?id=13962], so what SDL tries
to do does not work at all on that implementation of the X Window
System. (The reason that the DPMSEnable works in KControl is that it
calls DPMSSetTimeout immediately after,
[http://websvn.kde.org/tags/KDE/3.5.9/kdebase/kcontrol/energy/energy.cpp?annotate=774532#l343]).
The problems that the current behaviour causes
==============================================
1. Information leak. When the user is away, someone might see what the
user has on the display when the user counts on the screensaver
preventing this. This does not even require physical access to the
workstation, it is enough to see it from a distance.
2. Draining battery. An SDL program that runs on a laptop will quickly
drain the battery while the user is away. The system will soon shut down
and require recharging before being usable again, while it should in
fact have consumed very little energy if the user's settings would have
been obeyed.
3. Wasting energy. Even if battery issues are not considered, energy as
such is wasted.
4. Display wear. The display may be worn out.
The problems that the current behaviour tries to solve
======================================================
1. Preventing screensaver while playing movies.
Many SDL applications are media players. They have reasons to prevent
screensavers from being activated while a movie is being played. When a
user clicks on the play button it can be interpreted as saying "play
this movie, but do not turn off the display while playing it, because I
will watch it even though I do not interact with the system".
2. Preventing screensaver when some input bypasses X.
Sometimes SDL uses input from another source than the X server, so
that the X server is bypassed. This obviously breaks the screensaver
handling. SDL tries to work around that.
3. Preventing screensaver when all input bypasses X.
There is something called Direct Graphics Access mode, where a
program takes control of both the display and the input devices from the
X server. This obviously means that the X server can not handle the
screensaver alone, since screensaver handling depends on input handling.
SDL does not do what it should to help the X server to handle the
screensaver. Nor does SDL take care of screeensaver handling itself. SDL
simply disables the screensaver completely.
How the problems should be solved
=================================
The correct way for an application program to prevent the screensaver
under X is to call XResetScreenSaver. This was recently discovered and
implemented by the mplayer developers,
[http://svn.mplayerhq.hu/mplayer?view=rev&revision=25637]. SDL needs to
wrap this in an API call (SDL_ResetScreenSaver) and implement it for the
other video targets (if they do not have a corresponding call, SDL
should do what it takes on that particular target, for example sending
fake key events).
1. When a movie is played, the player should reset the screensaver when
the animation is advanced to a new frame. The same applies to anything
similar, like slideshows.
2. When the X server is handling input, it must handle all input
(keyboards, mice, gamepads, ...). This is necessary, not only to be able
to handle the screensaver, but also so that it can send the events to
the correct (the currently active) client. If there is an input device
that the X server can not handle for some reason (such as lack of Plug
and Play capability), the program that handles the device as a
workaround must simulate what would happen if the X server would have
handled the device, by calling XResetScreenSaver when input is received
from the device.
3. When the X server is not handling the input, it depends on the
program that does to call XResetScreenSaver whenever an input event
occurs. Alternatively the program must handle the screensaver countdown
internally and call XActivateScreenSaver.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 29 Feb 2008 13:55:44 +0000 |
parents | c5c3c772f5aa |
children | a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1306
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
242
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 #ifndef _SDL_x11video_h | |
25 #define _SDL_x11video_h | |
26 | |
27 #include <X11/Xlib.h> | |
28 #include <X11/Xutil.h> | |
29 #include <X11/Xatom.h> | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
30 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
31 #include "SDL_mouse.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
32 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
33 |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
34 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
35 #include "../Xext/extensions/xf86dga.h" |
0 | 36 #endif |
1765 | 37 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
38 #include "../Xext/extensions/Xinerama.h" | |
39 #endif | |
40 #if SDL_VIDEO_DRIVER_X11_XRANDR | |
41 #include <X11/extensions/Xrandr.h> | |
42 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
43 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
44 #include "../Xext/extensions/xf86vmode.h" |
0 | 45 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
46 #if SDL_VIDEO_DRIVER_X11_XME |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
47 #include "../Xext/extensions/xme.h" |
242
4bcb29d3769c
Added support for Xi Graphics XME fullscreen extension
Sam Lantinga <slouken@libsdl.org>
parents:
227
diff
changeset
|
48 #endif |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
49 |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
50 #include "SDL_x11dyn.h" |
0 | 51 |
52 /* Hidden "this" pointer for the video functions */ | |
53 #define _THIS SDL_VideoDevice *this | |
54 | |
55 /* Private display data */ | |
56 struct SDL_PrivateVideoData { | |
57 int local_X11; /* Flag: true if local display */ | |
58 Display *X11_Display; /* Used for events and window management */ | |
59 Display *GFX_Display; /* Used for graphics and colormap stuff */ | |
60 Visual *SDL_Visual; /* The visual used by our window */ | |
61 Window WMwindow; /* Input window, managed by window manager */ | |
62 Window FSwindow; /* Fullscreen window, completely unmanaged */ | |
63 Window SDL_Window; /* Shared by both displays (no X security?) */ | |
64 Atom WM_DELETE_WINDOW; /* "close-window" protocol atom */ | |
65 WMcursor *BlankCursor; /* The invisible cursor */ | |
1178
9867f3d86e44
Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
66 XIM X11_IM; /* Used to communicate with the input method (IM) server */ |
9867f3d86e44
Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
67 XIC X11_IC; /* Used for retaining the state, properties, and semantics of communication with the input method (IM) server */ |
0 | 68 |
69 char *SDL_windowid; /* Flag: true if we have been passed a window */ | |
70 | |
71 /* Direct Graphics Access extension information */ | |
72 int using_dga; | |
73 | |
74 #ifndef NO_SHARED_MEMORY | |
75 /* MIT shared memory extension information */ | |
76 int use_mitshm; | |
77 XShmSegmentInfo shminfo; | |
78 #endif | |
79 | |
80 /* The variables used for displaying graphics */ | |
81 XImage *Ximage; /* The X image for our window */ | |
82 GC gc; /* The graphic context for drawing */ | |
83 | |
84 /* The current width and height of the fullscreen mode */ | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
85 int window_w; |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
86 int window_h; |
0 | 87 |
88 /* Support for internal mouse warping */ | |
89 struct { | |
90 int x; | |
91 int y; | |
92 } mouse_last; | |
93 struct { | |
94 int numerator; | |
95 int denominator; | |
96 int threshold; | |
97 } mouse_accel; | |
98 int mouse_relative; | |
99 | |
100 /* The current list of available video modes */ | |
101 SDL_Rect **modelist; | |
102 | |
103 /* available visuals of interest to us, sorted deepest first */ | |
104 struct { | |
105 Visual *visual; | |
106 int depth; /* number of significant bits/pixel */ | |
107 int bpp; /* pixel quantum in bits */ | |
108 } visuals[2*5]; /* at most 2 entries for 8, 15, 16, 24, 32 */ | |
109 int nvisuals; | |
110 | |
111 Visual *vis; /* current visual in use */ | |
112 int depth; /* current visual depth (not bpp) */ | |
113 | |
114 /* Variables used by the X11 video mode code */ | |
1765 | 115 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
116 SDL_NAME(XineramaScreenInfo) xinerama_info; | |
117 #endif | |
118 #if SDL_VIDEO_DRIVER_X11_XRANDR | |
119 XRRScreenConfiguration* screen_config; | |
120 int saved_size_id; | |
121 Rotation saved_rotation; | |
122 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
123 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
270
diff
changeset
|
124 SDL_NAME(XF86VidModeModeInfo) saved_mode; |
0 | 125 struct { |
126 int x, y; | |
127 } saved_view; | |
128 #endif | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
129 #if SDL_VIDEO_DRIVER_X11_XME /* XiG XME fullscreen */ |
242
4bcb29d3769c
Added support for Xi Graphics XME fullscreen extension
Sam Lantinga <slouken@libsdl.org>
parents:
227
diff
changeset
|
130 XiGMiscResolutionInfo saved_res; |
4bcb29d3769c
Added support for Xi Graphics XME fullscreen extension
Sam Lantinga <slouken@libsdl.org>
parents:
227
diff
changeset
|
131 #endif |
4bcb29d3769c
Added support for Xi Graphics XME fullscreen extension
Sam Lantinga <slouken@libsdl.org>
parents:
227
diff
changeset
|
132 |
1765 | 133 int use_xinerama; |
134 int use_xrandr; | |
0 | 135 int use_vidmode; |
1765 | 136 int use_xme; |
0 | 137 int currently_fullscreen; |
138 | |
139 /* Automatic mode switching support (entering/leaving fullscreen) */ | |
140 Uint32 switch_waiting; | |
141 Uint32 switch_time; | |
142 | |
143 /* Prevent too many XSync() calls */ | |
144 int blit_queued; | |
145 | |
146 /* Colormap handling */ | |
147 Colormap DisplayColormap; /* The default display colormap */ | |
148 Colormap XColorMap; /* The current window colormap */ | |
149 int *XPixels; /* pixels value allocation counts */ | |
150 float gamma_saved[3]; /* Saved gamma values for VidMode gamma */ | |
151 int gamma_changed; /* flag: has VidMode gamma been modified? */ | |
152 | |
153 short *iconcolors; /* List of colors used by the icon */ | |
1783 | 154 |
155 /* Screensaver settings */ | |
4139
568c9b3c0167
* Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents:
3936
diff
changeset
|
156 int allow_screensaver; |
0 | 157 }; |
158 | |
159 /* Old variable names */ | |
160 #define local_X11 (this->hidden->local_X11) | |
161 #define SDL_Display (this->hidden->X11_Display) | |
162 #define GFX_Display (this->hidden->GFX_Display) | |
163 #define SDL_Screen DefaultScreen(this->hidden->X11_Display) | |
164 #define SDL_Visual (this->hidden->vis) | |
165 #define SDL_Root RootWindow(SDL_Display, SDL_Screen) | |
166 #define WMwindow (this->hidden->WMwindow) | |
167 #define FSwindow (this->hidden->FSwindow) | |
168 #define SDL_Window (this->hidden->SDL_Window) | |
169 #define WM_DELETE_WINDOW (this->hidden->WM_DELETE_WINDOW) | |
170 #define SDL_BlankCursor (this->hidden->BlankCursor) | |
1327 | 171 #define SDL_IM (this->hidden->X11_IM) |
172 #define SDL_IC (this->hidden->X11_IC) | |
0 | 173 #define SDL_windowid (this->hidden->SDL_windowid) |
174 #define using_dga (this->hidden->using_dga) | |
175 #define use_mitshm (this->hidden->use_mitshm) | |
176 #define shminfo (this->hidden->shminfo) | |
177 #define SDL_Ximage (this->hidden->Ximage) | |
178 #define SDL_GC (this->hidden->gc) | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
179 #define window_w (this->hidden->window_w) |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
180 #define window_h (this->hidden->window_h) |
0 | 181 #define mouse_last (this->hidden->mouse_last) |
182 #define mouse_accel (this->hidden->mouse_accel) | |
183 #define mouse_relative (this->hidden->mouse_relative) | |
184 #define SDL_modelist (this->hidden->modelist) | |
1765 | 185 #define xinerama_info (this->hidden->xinerama_info) |
0 | 186 #define saved_mode (this->hidden->saved_mode) |
187 #define saved_view (this->hidden->saved_view) | |
242
4bcb29d3769c
Added support for Xi Graphics XME fullscreen extension
Sam Lantinga <slouken@libsdl.org>
parents:
227
diff
changeset
|
188 #define saved_res (this->hidden->saved_res) |
1589
34cca785be57
Xrandr support in the X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents:
1545
diff
changeset
|
189 #define screen_config (this->hidden->screen_config) |
34cca785be57
Xrandr support in the X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents:
1545
diff
changeset
|
190 #define saved_size_id (this->hidden->saved_size_id) |
34cca785be57
Xrandr support in the X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents:
1545
diff
changeset
|
191 #define saved_rotation (this->hidden->saved_rotation) |
1765 | 192 #define use_xinerama (this->hidden->use_xinerama) |
0 | 193 #define use_vidmode (this->hidden->use_vidmode) |
1765 | 194 #define use_xrandr (this->hidden->use_xrandr) |
195 #define use_xme (this->hidden->use_xme) | |
0 | 196 #define currently_fullscreen (this->hidden->currently_fullscreen) |
197 #define switch_waiting (this->hidden->switch_waiting) | |
198 #define switch_time (this->hidden->switch_time) | |
199 #define blit_queued (this->hidden->blit_queued) | |
200 #define SDL_DisplayColormap (this->hidden->DisplayColormap) | |
201 #define SDL_PrivateColormap (this->hidden->PrivateColormap) | |
202 #define SDL_XColorMap (this->hidden->XColorMap) | |
203 #define SDL_XPixels (this->hidden->XPixels) | |
204 #define gamma_saved (this->hidden->gamma_saved) | |
205 #define gamma_changed (this->hidden->gamma_changed) | |
206 #define SDL_iconcolors (this->hidden->iconcolors) | |
4139
568c9b3c0167
* Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents:
3936
diff
changeset
|
207 #define allow_screensaver (this->hidden->allow_screensaver) |
568c9b3c0167
* Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents:
3936
diff
changeset
|
208 |
0 | 209 /* Some versions of XFree86 have bugs - detect if this is one of them */ |
210 #define BUGGY_XFREE86(condition, buggy_version) \ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
211 ((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \ |
0 | 212 (VendorRelease(SDL_Display) condition buggy_version)) |
213 | |
214 #endif /* _SDL_x11video_h */ |