Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gamma.c @ 563:04dcaf3da918
Massive Quartz input enhancements from Darrell Walisser. His email:
Enclosed is a patch that addresses the following:
--Various minor cleanups.
Removed dead/obsolete code, made some style cleanups
--Mouse Events
Now keep track of what button(s) were pressed so we know when to send
the mouse up event. This fixes the case where the mouse is dragged
outside of the game window and released (in which case we want to send
the mouse up event even though the mouse is outside the game window).
--Input Grabbing
Here is my take on the grabbing situation, which is the basis for the
new implementation.
There are 3 grab states, ungrabbed (UG), visible (VG), and invisible
(IG). Both VG and IG keep the mouse constrained to the window and
produce relative motion events. In VG the cursor is visible (duh), in
IG it is not. In VG, absolute motion events also work.
There are 6 actions that can affect grabbing:
1. Set Fullscreen/Window (F/W). In fullscreen, a visible grab should do
nothing. However, a fullscreen visible grab can be treated just like a
windowed visible grab, which is what I have done to help simplify
things.
2. Cursor hide/show (H/S). If the cursor is hidden when grabbing, the
grab is an invisible grab. If the cursor is visible, the grab should
just constrain the mouse to the window.
3. Input grab/ungrab(G/U). If grabbed, the cursor should be confined to
the window as should the keyboard input. On Mac OS X, the keyboard
input is implicitly grabbed by confining the cursor, except for
command-tab which can switch away from the application. Should the
window come to the foreground if the application is deactivated and
grab input is called? This isn't necessary in this implementation
because the grab state will be asserted upon activation.
Using my notation, these are all the cases that need to be handled
(state + action = new state).
UG+U = UG
UG+G = VG or IG, if cursor is visible or not
UG+H = UG
UG+S = UG
VG+U = UG
VG+G = VG
VG+H = IG
VG+S = VG
IG+U = UG
IG+G = IG
IG+H = IG
IG+S = VG
The cases that result in the same state can be ignored in the code,
which cuts it down to just 5 cases.
Another issue is what happens when the app loses/gains input focus from
deactivate/activate or iconify/deiconify. I think that if input focus
is ever lost (outside of SDL's control), the grab state should be
suspended and the cursor should become visible and active again. When
regained, the cursor should reappear in its original location and/or
grab state. This way, when reactivating the cursor is still in the same
position as before so apps shouldn't get confused when the next motion
event comes in. This is what I've done in this patch.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 27 Dec 2002 20:52:41 +0000 |
parents | 98d778ed4abf |
children | b8d311d90021 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
292
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
232
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include "SDL.h" | |
29 #include "SDL_events.h" | |
30 #include "SDL_events_c.h" | |
31 #include "SDL_x11video.h" | |
32 | |
33 /* From the X server sources... */ | |
34 #define MAX_GAMMA 10.0 | |
35 #define MIN_GAMMA (1.0/MAX_GAMMA) | |
36 | |
37 static int X11_SetGammaNoLock(_THIS, float red, float green, float blue) | |
38 { | |
39 #ifdef XFREE86_VMGAMMA | |
100
a1c973c35fef
Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
40 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
41 SDL_NAME(XF86VidModeGamma) gamma; |
0 | 42 Bool succeeded; |
43 | |
44 /* Clamp the gamma values */ | |
45 if ( red < MIN_GAMMA ) { | |
46 gamma.red = MIN_GAMMA; | |
47 } else | |
48 if ( red > MAX_GAMMA ) { | |
49 gamma.red = MAX_GAMMA; | |
50 } else { | |
51 gamma.red = red; | |
52 } | |
53 if ( green < MIN_GAMMA ) { | |
54 gamma.green = MIN_GAMMA; | |
55 } else | |
56 if ( green > MAX_GAMMA ) { | |
57 gamma.green = MAX_GAMMA; | |
58 } else { | |
59 gamma.green = green; | |
60 } | |
61 if ( blue < MIN_GAMMA ) { | |
62 gamma.blue = MIN_GAMMA; | |
63 } else | |
64 if ( blue > MAX_GAMMA ) { | |
65 gamma.blue = MAX_GAMMA; | |
66 } else { | |
67 gamma.blue = blue; | |
68 } | |
69 if ( SDL_GetAppState() & SDL_APPACTIVE ) { | |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
70 succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma); |
0 | 71 XSync(SDL_Display, False); |
72 } else { | |
73 gamma_saved[0] = gamma.red; | |
74 gamma_saved[1] = gamma.green; | |
75 gamma_saved[2] = gamma.blue; | |
76 succeeded = True; | |
77 } | |
78 if ( succeeded ) { | |
79 ++gamma_changed; | |
80 } | |
81 return succeeded ? 0 : -1; | |
82 } | |
83 #endif | |
84 SDL_SetError("Gamma correction not supported"); | |
85 return -1; | |
86 } | |
87 int X11_SetVidModeGamma(_THIS, float red, float green, float blue) | |
88 { | |
89 int result; | |
90 | |
91 SDL_Lock_EventThread(); | |
92 result = X11_SetGammaNoLock(this, red, green, blue); | |
93 SDL_Unlock_EventThread(); | |
94 | |
95 return(result); | |
96 } | |
97 | |
98 static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) | |
99 { | |
100 #ifdef XFREE86_VMGAMMA | |
445
98d778ed4abf
Fixed video crash on older XFree86 servers
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
101 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 SDL_NAME(XF86VidModeGamma) gamma; |
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) { |
0 | 104 *red = gamma.red; |
105 *green = gamma.green; | |
106 *blue = gamma.blue; | |
107 return 0; | |
108 } | |
109 return -1; | |
110 } | |
111 #endif | |
112 return -1; | |
113 } | |
114 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) | |
115 { | |
116 int result; | |
117 | |
118 SDL_Lock_EventThread(); | |
119 result = X11_GetGammaNoLock(this, red, green, blue); | |
120 SDL_Unlock_EventThread(); | |
121 | |
122 return(result); | |
123 } | |
124 | |
125 void X11_SaveVidModeGamma(_THIS) | |
126 { | |
127 /* Try to save the current gamma, otherwise disable gamma control */ | |
128 if ( X11_GetGammaNoLock(this, | |
129 &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]) < 0 ) { | |
130 this->SetGamma = 0; | |
131 this->GetGamma = 0; | |
132 } | |
133 gamma_changed = 0; | |
134 } | |
135 void X11_SwapVidModeGamma(_THIS) | |
136 { | |
137 float new_gamma[3]; | |
138 | |
139 if ( gamma_changed ) { | |
140 new_gamma[0] = gamma_saved[0]; | |
141 new_gamma[1] = gamma_saved[1]; | |
142 new_gamma[2] = gamma_saved[2]; | |
143 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]); | |
144 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]); | |
145 } | |
146 } |