Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gamma.c @ 4554:4deaba8b1b42 SDL-1.2
Fixed bug 1015
Don't set the WM_TRANSIENT_FOR property to an invalid value - delete it instead.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 18 Jul 2010 11:37:12 -0700 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 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:
1168
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:
1168
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:
1168
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:
1168
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:
1168
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:
1168
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:
232
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 #include "SDL.h" | |
25 #include "SDL_events.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
26 #include "../../events/SDL_events_c.h" |
0 | 27 #include "SDL_x11video.h" |
28 | |
29 /* From the X server sources... */ | |
30 #define MAX_GAMMA 10.0 | |
31 #define MIN_GAMMA (1.0/MAX_GAMMA) | |
32 | |
33 static int X11_SetGammaNoLock(_THIS, float red, float green, float blue) | |
34 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
35 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
100
a1c973c35fef
Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
36 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
37 SDL_NAME(XF86VidModeGamma) gamma; |
0 | 38 Bool succeeded; |
39 | |
40 /* Clamp the gamma values */ | |
41 if ( red < MIN_GAMMA ) { | |
42 gamma.red = MIN_GAMMA; | |
43 } else | |
44 if ( red > MAX_GAMMA ) { | |
45 gamma.red = MAX_GAMMA; | |
46 } else { | |
47 gamma.red = red; | |
48 } | |
49 if ( green < MIN_GAMMA ) { | |
50 gamma.green = MIN_GAMMA; | |
51 } else | |
52 if ( green > MAX_GAMMA ) { | |
53 gamma.green = MAX_GAMMA; | |
54 } else { | |
55 gamma.green = green; | |
56 } | |
57 if ( blue < MIN_GAMMA ) { | |
58 gamma.blue = MIN_GAMMA; | |
59 } else | |
60 if ( blue > MAX_GAMMA ) { | |
61 gamma.blue = MAX_GAMMA; | |
62 } else { | |
63 gamma.blue = blue; | |
64 } | |
65 if ( SDL_GetAppState() & SDL_APPACTIVE ) { | |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
66 succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma); |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
67 XSync(SDL_Display, False); |
0 | 68 } else { |
69 gamma_saved[0] = gamma.red; | |
70 gamma_saved[1] = gamma.green; | |
71 gamma_saved[2] = gamma.blue; | |
72 succeeded = True; | |
73 } | |
74 if ( succeeded ) { | |
75 ++gamma_changed; | |
76 } | |
77 return succeeded ? 0 : -1; | |
78 } | |
79 #endif | |
80 SDL_SetError("Gamma correction not supported"); | |
81 return -1; | |
82 } | |
83 int X11_SetVidModeGamma(_THIS, float red, float green, float blue) | |
84 { | |
85 int result; | |
86 | |
87 SDL_Lock_EventThread(); | |
88 result = X11_SetGammaNoLock(this, red, green, blue); | |
89 SDL_Unlock_EventThread(); | |
90 | |
91 return(result); | |
92 } | |
93 | |
94 static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) | |
95 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
96 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
445
98d778ed4abf
Fixed video crash on older XFree86 servers
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 SDL_NAME(XF86VidModeGamma) gamma; |
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
99 if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) { |
0 | 100 *red = gamma.red; |
101 *green = gamma.green; | |
102 *blue = gamma.blue; | |
103 return 0; | |
104 } | |
105 return -1; | |
106 } | |
107 #endif | |
108 return -1; | |
109 } | |
110 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) | |
111 { | |
112 int result; | |
113 | |
114 SDL_Lock_EventThread(); | |
115 result = X11_GetGammaNoLock(this, red, green, blue); | |
116 SDL_Unlock_EventThread(); | |
117 | |
118 return(result); | |
119 } | |
120 | |
121 void X11_SaveVidModeGamma(_THIS) | |
122 { | |
123 /* Try to save the current gamma, otherwise disable gamma control */ | |
124 if ( X11_GetGammaNoLock(this, | |
125 &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]) < 0 ) { | |
126 this->SetGamma = 0; | |
127 this->GetGamma = 0; | |
128 } | |
129 gamma_changed = 0; | |
130 } | |
131 void X11_SwapVidModeGamma(_THIS) | |
132 { | |
133 float new_gamma[3]; | |
134 | |
135 if ( gamma_changed ) { | |
136 new_gamma[0] = gamma_saved[0]; | |
137 new_gamma[1] = gamma_saved[1]; | |
138 new_gamma[2] = gamma_saved[2]; | |
139 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]); | |
140 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]); | |
141 } | |
142 } |