-rw-r--r-- | core/launcher/screensaver.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 45da9ed..088ed19 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -1,270 +1,272 @@ | |||
1 | 1 | ||
2 | #include "screensaver.h" | 2 | #include "screensaver.h" |
3 | 3 | ||
4 | #include <qpe/config.h> | 4 | #include <qpe/config.h> |
5 | #include <qpe/power.h> | 5 | #include <qpe/power.h> |
6 | #include <qpe/network.h> | 6 | #include <qpe/network.h> |
7 | 7 | ||
8 | #include <opie/odevice.h> | 8 | #include <opie/odevice.h> |
9 | 9 | ||
10 | 10 | ||
11 | using namespace Opie; | 11 | using namespace Opie; |
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
15 | OpieScreenSaver::OpieScreenSaver ( ) | 15 | OpieScreenSaver::OpieScreenSaver ( ) |
16 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) | 16 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) |
17 | { | 17 | { |
18 | m_disable_suspend = 100; | 18 | m_disable_suspend = 100; |
19 | m_enable_dim = false; | 19 | m_enable_dim = false; |
20 | m_enable_lightoff = false; | 20 | m_enable_lightoff = false; |
21 | m_enable_suspend = false; | 21 | m_enable_suspend = false; |
22 | m_onlylcdoff = false; | 22 | m_onlylcdoff = false; |
23 | 23 | ||
24 | m_enable_dim_ac = false; | 24 | m_enable_dim_ac = false; |
25 | m_enable_lightoff_ac = false; | 25 | m_enable_lightoff_ac = false; |
26 | m_enable_suspend_ac = false; | 26 | m_enable_suspend_ac = false; |
27 | m_onlylcdoff_ac = false; | 27 | m_onlylcdoff_ac = false; |
28 | 28 | ||
29 | m_use_light_sensor = false; | 29 | m_use_light_sensor = false; |
30 | m_backlight_sensor = -1; | 30 | m_backlight_sensor = -1; |
31 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); | 31 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); |
32 | 32 | ||
33 | m_lcd_status = true; | 33 | m_lcd_status = true; |
34 | 34 | ||
35 | m_backlight_normal = -1; | 35 | m_backlight_normal = -1; |
36 | m_backlight_current = -1; | 36 | m_backlight_current = -1; |
37 | m_backlight_forcedoff = false; | 37 | m_backlight_forcedoff = false; |
38 | 38 | ||
39 | m_on_ac = false; | 39 | m_on_ac = false; |
40 | 40 | ||
41 | m_level = -1; | 41 | m_level = -1; |
42 | 42 | ||
43 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 43 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
44 | ODevice::inst ( )-> setDisplayStatus ( true ); | 44 | ODevice::inst ( )-> setDisplayStatus ( true ); |
45 | setBacklight ( -1 ); | 45 | setBacklight ( -1 ); |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | void OpieScreenSaver::restore() | 49 | void OpieScreenSaver::restore() |
50 | { | 50 | { |
51 | m_level = -1; | 51 | m_level = -1; |
52 | 52 | ||
53 | if ( !m_lcd_status ) { // We must have turned it off | 53 | if ( !m_lcd_status ) { // We must have turned it off |
54 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 54 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
55 | m_lcd_status = true; | 55 | m_lcd_status = true; |
56 | } | 56 | } |
57 | 57 | ||
58 | setBacklightInternal ( -1 ); | 58 | setBacklightInternal ( -1 ); |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | bool OpieScreenSaver::save( int level ) | 62 | bool OpieScreenSaver::save( int level ) |
63 | { | 63 | { |
64 | m_level = level; | 64 | m_level = level; |
65 | 65 | ||
66 | switch ( level ) { | 66 | switch ( level ) { |
67 | case 0: | 67 | case 0: |
68 | if (( m_on_ac && m_enable_dim_ac ) || | 68 | if (( m_on_ac && m_enable_dim_ac ) || |
69 | ( !m_on_ac && m_enable_dim )) { | 69 | ( !m_on_ac && m_enable_dim )) { |
70 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) | 70 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) |
71 | setBacklightInternal ( 1 ); // lowest non-off | 71 | setBacklightInternal ( 1 ); // lowest non-off |
72 | } | 72 | } |
73 | return true; | 73 | return true; |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case 1: | 76 | case 1: |
77 | if (( m_on_ac && m_enable_lightoff_ac ) || | 77 | if (( m_on_ac && m_enable_lightoff_ac ) || |
78 | ( !m_on_ac && m_enable_lightoff )) { | 78 | ( !m_on_ac && m_enable_lightoff )) { |
79 | if ( m_disable_suspend > 1 ) | 79 | if ( m_disable_suspend > 1 ) |
80 | setBacklightInternal ( 0 ); // off | 80 | setBacklightInternal ( 0 ); // off |
81 | } | 81 | } |
82 | return true; | 82 | return true; |
83 | break; | 83 | break; |
84 | 84 | ||
85 | case 2: | 85 | case 2: |
86 | if (( m_on_ac && !m_enable_suspend_ac ) || | 86 | if (( m_on_ac && !m_enable_suspend_ac ) || |
87 | ( !m_on_ac && !m_enable_suspend )) { | 87 | ( !m_on_ac && !m_enable_suspend )) { |
88 | return true; | 88 | return true; |
89 | } | 89 | } |
90 | 90 | ||
91 | if (( m_on_ac && m_onlylcdoff_ac ) || | 91 | if (( m_on_ac && m_onlylcdoff_ac ) || |
92 | ( !m_on_ac && m_onlylcdoff )) { | 92 | ( !m_on_ac && m_onlylcdoff )) { |
93 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 93 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
94 | m_lcd_status = false; | 94 | m_lcd_status = false; |
95 | return true; | 95 | return true; |
96 | } | 96 | } |
97 | 97 | ||
98 | // We're going to suspend the whole machine | 98 | // We're going to suspend the whole machine |
99 | 99 | ||
100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { | 100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { |
101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
102 | return true; | 102 | return true; |
103 | } | 103 | } |
104 | 104 | ||
105 | break; | 105 | break; |
106 | } | 106 | } |
107 | return false; | 107 | return false; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) | 111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) |
112 | { | 112 | { |
113 | Config config ( "apm" ); | 113 | Config config ( "apm" ); |
114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
115 | 115 | ||
116 | int v[ 4 ]; | 116 | int v[ 4 ]; |
117 | if ( i1 < 0 ) | 117 | if ( i1 < 0 ) |
118 | i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); | 118 | i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); |
119 | if ( i2 < 0 ) | 119 | if ( i2 < 0 ) |
120 | i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); | 120 | i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); |
121 | if ( i3 < 0 ) | 121 | if ( i3 < 0 ) |
122 | i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); | 122 | i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); |
123 | 123 | ||
124 | if ( m_on_ac ) { | 124 | if ( m_on_ac ) { |
125 | m_enable_dim_ac = ( i1 > 0 ); | 125 | m_enable_dim_ac = ( i1 > 0 ); |
126 | m_enable_lightoff_ac = ( i2 > 0 ); | 126 | m_enable_lightoff_ac = ( i2 > 0 ); |
127 | m_enable_suspend_ac = ( i3 > 0 ); | 127 | m_enable_suspend_ac = ( i3 > 0 ); |
128 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); | 128 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); |
129 | } | 129 | } |
130 | else { | 130 | else { |
131 | m_enable_dim = ( i1 > 0 ); | 131 | m_enable_dim = ( i1 > 0 ); |
132 | m_enable_lightoff = ( i2 > 0 ); | 132 | m_enable_lightoff = ( i2 > 0 ); |
133 | m_enable_suspend = ( i3 > 0 ); | 133 | m_enable_suspend = ( i3 > 0 ); |
134 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); | 134 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); |
135 | } | 135 | } |
136 | 136 | ||
137 | qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 137 | qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
138 | 138 | ||
139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); |
142 | v [ 3 ] = 0; | 142 | v [ 3 ] = 0; |
143 | 143 | ||
144 | if ( !i1 && !i2 && !i3 ) | 144 | if ( !i1 && !i2 && !i3 ) |
145 | QWSServer::setScreenSaverInterval( 0 ); | 145 | QWSServer::setScreenSaverInterval( 0 ); |
146 | else | 146 | else |
147 | QWSServer::setScreenSaverIntervals( v ); | 147 | QWSServer::setScreenSaverIntervals( v ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | void OpieScreenSaver::setInterval ( int interval ) | 151 | void OpieScreenSaver::setInterval ( int interval ) |
152 | { | 152 | { |
153 | setIntervals ( -1, -1, interval ); | 153 | setIntervals ( -1, -1, interval ); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | void OpieScreenSaver::setMode ( int mode ) | 157 | void OpieScreenSaver::setMode ( int mode ) |
158 | { | 158 | { |
159 | if ( mode > m_disable_suspend ) | 159 | if ( mode > m_disable_suspend ) |
160 | setInterval ( -1 ); | 160 | setInterval ( -1 ); |
161 | m_disable_suspend = mode; | 161 | m_disable_suspend = mode; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | void OpieScreenSaver::setBacklight ( int bright ) | 165 | void OpieScreenSaver::setBacklight ( int bright ) |
166 | { | 166 | { |
167 | // Read from config | 167 | // Read from config |
168 | Config config ( "apm" ); | 168 | Config config ( "apm" ); |
169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
170 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); | 170 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
171 | 171 | ||
172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
173 | 173 | ||
174 | //qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 174 | //qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
175 | 175 | ||
176 | killTimers ( ); | 176 | killTimers ( ); |
177 | if ( m_use_light_sensor ) { | 177 | if ( m_use_light_sensor ) { |
178 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); | 178 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); |
179 | 179 | ||
180 | m_sensordata [LS_SensorMin] = 40; | 180 | m_sensordata [LS_SensorMin] = 40; |
181 | m_sensordata [LS_SensorMax] = 215; | 181 | m_sensordata [LS_SensorMax] = 215; |
182 | m_sensordata [LS_LightMin] = 1; | 182 | m_sensordata [LS_LightMin] = 1; |
183 | m_sensordata [LS_LightMax] = 255; | 183 | m_sensordata [LS_LightMax] = 255; |
184 | m_sensordata [LS_Steps] = 12; | 184 | m_sensordata [LS_Steps] = 12; |
185 | m_sensordata [LS_Interval] = 2000; | 185 | m_sensordata [LS_Interval] = 2000; |
186 | 186 | ||
187 | for ( uint i = 0; i < LS_Count; i++ ) { | 187 | for ( uint i = 0; i < LS_Count; i++ ) { |
188 | if ( i < sl. count ( )) | 188 | if ( i < sl. count ( )) |
189 | m_sensordata [i] = sl [i]. toInt ( ); | 189 | m_sensordata [i] = sl [i]. toInt ( ); |
190 | } | 190 | } |
191 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE | ||
192 | m_sensordata [LS_Steps] = 2; | ||
191 | 193 | ||
192 | timerEvent ( 0 ); | 194 | timerEvent ( 0 ); |
193 | startTimer ( m_sensordata [LS_Interval] ); | 195 | startTimer ( m_sensordata [LS_Interval] ); |
194 | } | 196 | } |
195 | 197 | ||
196 | setBacklightInternal ( bright ); | 198 | setBacklightInternal ( bright ); |
197 | } | 199 | } |
198 | 200 | ||
199 | 201 | ||
200 | void OpieScreenSaver::setBacklightInternal ( int bright ) | 202 | void OpieScreenSaver::setBacklightInternal ( int bright ) |
201 | { | 203 | { |
202 | if ( bright == -3 ) { | 204 | if ( bright == -3 ) { |
203 | // Forced on | 205 | // Forced on |
204 | m_backlight_forcedoff = false; | 206 | m_backlight_forcedoff = false; |
205 | bright = -1; | 207 | bright = -1; |
206 | } | 208 | } |
207 | if ( m_backlight_forcedoff && bright != -2 ) | 209 | if ( m_backlight_forcedoff && bright != -2 ) |
208 | return ; | 210 | return ; |
209 | if ( bright == -2 ) { | 211 | if ( bright == -2 ) { |
210 | // Toggle between off and on | 212 | // Toggle between off and on |
211 | bright = m_backlight_current ? 0 : -1; | 213 | bright = m_backlight_current ? 0 : -1; |
212 | m_backlight_forcedoff = !bright; | 214 | m_backlight_forcedoff = !bright; |
213 | } | 215 | } |
214 | if ( bright == -1 ) | 216 | if ( bright == -1 ) |
215 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | 217 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; |
216 | 218 | ||
217 | if ( bright != m_backlight_current ) { | 219 | if ( bright != m_backlight_current ) { |
218 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 220 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
219 | m_backlight_current = bright; | 221 | m_backlight_current = bright; |
220 | } | 222 | } |
221 | } | 223 | } |
222 | 224 | ||
223 | 225 | ||
224 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 226 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
225 | { | 227 | { |
226 | int s = ODevice::inst ( )-> readLightSensor ( ); | 228 | int s = ODevice::inst ( )-> readLightSensor ( ); |
227 | 229 | ||
228 | if ( s < m_sensordata [LS_SensorMin] ) | 230 | if ( s < m_sensordata [LS_SensorMin] ) |
229 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 231 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
230 | else if ( s >= m_sensordata [LS_SensorMax] ) | 232 | else if ( s >= m_sensordata [LS_SensorMax] ) |
231 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 233 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
232 | else { | 234 | else { |
233 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 235 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
234 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 236 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
235 | 237 | ||
236 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; | 238 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 |
237 | 239 | ||
238 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); | 240 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |
239 | } | 241 | } |
240 | if ( !m_backlight_sensor ) | 242 | if ( !m_backlight_sensor ) |
241 | m_backlight_sensor = 1; | 243 | m_backlight_sensor = 1; |
242 | 244 | ||
243 | // qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); | 245 | // qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); |
244 | 246 | ||
245 | if ( m_level <= 0 ) | 247 | if ( m_level <= 0 ) |
246 | setBacklightInternal ( -1 ); | 248 | setBacklightInternal ( -1 ); |
247 | } | 249 | } |
248 | 250 | ||
249 | 251 | ||
250 | void OpieScreenSaver::setDisplayState ( bool on ) | 252 | void OpieScreenSaver::setDisplayState ( bool on ) |
251 | { | 253 | { |
252 | if ( m_lcd_status != on ) { | 254 | if ( m_lcd_status != on ) { |
253 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 255 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
254 | m_lcd_status = on; | 256 | m_lcd_status = on; |
255 | } | 257 | } |
256 | } | 258 | } |
257 | 259 | ||
258 | 260 | ||
259 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 261 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
260 | { | 262 | { |
261 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 263 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
262 | 264 | ||
263 | if ( newonac != m_on_ac ) { | 265 | if ( newonac != m_on_ac ) { |
264 | m_on_ac = newonac; | 266 | m_on_ac = newonac; |
265 | setInterval ( -1 ); | 267 | setInterval ( -1 ); |
266 | setBacklight ( -1 ); | 268 | setBacklight ( -1 ); |
267 | restore ( ); | 269 | restore ( ); |
268 | } | 270 | } |
269 | } | 271 | } |
270 | 272 | ||