Diffstat (limited to 'core/launcher/screensaver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/screensaver.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index e544c61..6aaab3a 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -1,34 +1,34 @@ | |||
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/network.h> | 5 | #include <qpe/network.h> |
6 | 6 | ||
7 | #include <opie2/odevice.h> | 7 | #include <opie2/odevice.h> |
8 | 8 | ||
9 | 9 | ||
10 | using namespace Opie; | 10 | using namespace Opie::Core; |
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
14 | OpieScreenSaver::OpieScreenSaver ( ) | 14 | OpieScreenSaver::OpieScreenSaver ( ) |
15 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) | 15 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) |
16 | { | 16 | { |
17 | m_disable_suspend = 100; | 17 | m_disable_suspend = 100; |
18 | m_enable_dim = false; | 18 | m_enable_dim = false; |
19 | m_enable_lightoff = false; | 19 | m_enable_lightoff = false; |
20 | m_enable_suspend = false; | 20 | m_enable_suspend = false; |
21 | m_onlylcdoff = false; | 21 | m_onlylcdoff = false; |
22 | 22 | ||
23 | m_enable_dim_ac = false; | 23 | m_enable_dim_ac = false; |
24 | m_enable_lightoff_ac = false; | 24 | m_enable_lightoff_ac = false; |
25 | m_enable_suspend_ac = false; | 25 | m_enable_suspend_ac = false; |
26 | m_onlylcdoff_ac = false; | 26 | m_onlylcdoff_ac = false; |
27 | 27 | ||
28 | m_use_light_sensor = false; | 28 | m_use_light_sensor = false; |
29 | m_backlight_sensor = -1; | 29 | m_backlight_sensor = -1; |
30 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); | 30 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); |
31 | 31 | ||
32 | m_lcd_status = true; | 32 | m_lcd_status = true; |
33 | 33 | ||
34 | m_backlight_normal = -1; | 34 | m_backlight_normal = -1; |
@@ -136,49 +136,49 @@ void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) | |||
136 | { | 136 | { |
137 | Config config ( "apm" ); | 137 | Config config ( "apm" ); |
138 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 138 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
139 | 139 | ||
140 | int v[ 4 ]; | 140 | int v[ 4 ]; |
141 | if ( dim < 0 ) | 141 | if ( dim < 0 ) |
142 | dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); | 142 | dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); |
143 | if ( lightoff < 0 ) | 143 | if ( lightoff < 0 ) |
144 | lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); | 144 | lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); |
145 | if ( suspend < 0 ) | 145 | if ( suspend < 0 ) |
146 | suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); | 146 | suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); |
147 | 147 | ||
148 | if ( m_on_ac ) { | 148 | if ( m_on_ac ) { |
149 | m_enable_dim_ac = ( dim > 0 ); | 149 | m_enable_dim_ac = ( dim > 0 ); |
150 | m_enable_lightoff_ac = ( lightoff > 0 ); | 150 | m_enable_lightoff_ac = ( lightoff > 0 ); |
151 | m_enable_suspend_ac = ( suspend > 0 ); | 151 | m_enable_suspend_ac = ( suspend > 0 ); |
152 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); | 152 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); |
153 | } | 153 | } |
154 | else { | 154 | else { |
155 | m_enable_dim = ( dim > 0 ); | 155 | m_enable_dim = ( dim > 0 ); |
156 | m_enable_lightoff = ( lightoff > 0 ); | 156 | m_enable_lightoff = ( lightoff > 0 ); |
157 | m_enable_suspend = ( suspend > 0 ); | 157 | m_enable_suspend = ( suspend > 0 ); |
158 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); | 158 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); |
159 | } | 159 | } |
160 | 160 | ||
161 | //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); | 161 | //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); |
162 | 162 | ||
163 | v [ 0 ] = QMAX( 1000 * dim, 100 ); | 163 | v [ 0 ] = QMAX( 1000 * dim, 100 ); |
164 | v [ 1 ] = QMAX( 1000 * lightoff, 100 ); | 164 | v [ 1 ] = QMAX( 1000 * lightoff, 100 ); |
165 | v [ 2 ] = QMAX( 1000 * suspend, 100 ); | 165 | v [ 2 ] = QMAX( 1000 * suspend, 100 ); |
166 | v [ 3 ] = 0; | 166 | v [ 3 ] = 0; |
167 | 167 | ||
168 | if ( !dim && !lightoff && !suspend ) | 168 | if ( !dim && !lightoff && !suspend ) |
169 | QWSServer::setScreenSaverInterval( 0 ); | 169 | QWSServer::setScreenSaverInterval( 0 ); |
170 | else | 170 | else |
171 | QWSServer::setScreenSaverIntervals( v ); | 171 | QWSServer::setScreenSaverIntervals( v ); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * Set suspend time. Will read the dim and lcd-off times from the config file. | 176 | * Set suspend time. Will read the dim and lcd-off times from the config file. |
177 | * | 177 | * |
178 | * @param suspend time in seconds to go into APM suspend, -1 to | 178 | * @param suspend time in seconds to go into APM suspend, -1 to |
179 | * read value from config file, 0 to disable | 179 | * read value from config file, 0 to disable |
180 | */ | 180 | */ |
181 | void OpieScreenSaver::setInterval ( int interval ) | 181 | void OpieScreenSaver::setInterval ( int interval ) |
182 | { | 182 | { |
183 | setIntervals ( -1, -1, interval ); | 183 | setIntervals ( -1, -1, interval ); |
184 | } | 184 | } |
@@ -194,56 +194,56 @@ void OpieScreenSaver::setMode ( int mode ) | |||
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Set display brightness | 196 | * Set display brightness |
197 | * | 197 | * |
198 | * Get's default values for backlight, contrast and light sensor from config file. | 198 | * Get's default values for backlight, contrast and light sensor from config file. |
199 | * | 199 | * |
200 | * @param bright desired brighness (-1 to use automatic sensor data or value | 200 | * @param bright desired brighness (-1 to use automatic sensor data or value |
201 | * from config file, -2 to toggle backlight on and off, -3 to | 201 | * from config file, -2 to toggle backlight on and off, -3 to |
202 | * force backlight off) | 202 | * force backlight off) |
203 | */ | 203 | */ |
204 | void OpieScreenSaver::setBacklight ( int bright ) | 204 | void OpieScreenSaver::setBacklight ( int bright ) |
205 | { | 205 | { |
206 | // Read from config | 206 | // Read from config |
207 | Config config ( "apm" ); | 207 | Config config ( "apm" ); |
208 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 208 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
209 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); | 209 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
210 | int contrast = config. readNumEntry ( "Contrast", 127); | 210 | int contrast = config. readNumEntry ( "Contrast", 127); |
211 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 211 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
212 | 212 | ||
213 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 213 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
214 | 214 | ||
215 | killTimers ( ); | 215 | killTimers ( ); |
216 | if (( bright < 0 ) && m_use_light_sensor ) { | 216 | if (( bright < 0 ) && m_use_light_sensor ) { |
217 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); | 217 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); |
218 | 218 | ||
219 | m_sensordata [LS_SensorMin] = 40; | 219 | m_sensordata [LS_SensorMin] = 40; |
220 | m_sensordata [LS_SensorMax] = 215; | 220 | m_sensordata [LS_SensorMax] = 215; |
221 | m_sensordata [LS_LightMin] = 1; | 221 | m_sensordata [LS_LightMin] = 1; |
222 | m_sensordata [LS_LightMax] = 255; | 222 | m_sensordata [LS_LightMax] = 255; |
223 | m_sensordata [LS_Steps] = 12; | 223 | m_sensordata [LS_Steps] = 12; |
224 | m_sensordata [LS_Interval] = 2000; | 224 | m_sensordata [LS_Interval] = 2000; |
225 | 225 | ||
226 | for ( uint i = 0; i < LS_Count; i++ ) { | 226 | for ( uint i = 0; i < LS_Count; i++ ) { |
227 | if ( i < sl. count ( )) | 227 | if ( i < sl. count ( )) |
228 | m_sensordata [i] = sl [i]. toInt ( ); | 228 | m_sensordata [i] = sl [i]. toInt ( ); |
229 | } | 229 | } |
230 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE | 230 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE |
231 | m_sensordata [LS_Steps] = 2; | 231 | m_sensordata [LS_Steps] = 2; |
232 | 232 | ||
233 | timerEvent ( 0 ); | 233 | timerEvent ( 0 ); |
234 | startTimer ( m_sensordata [LS_Interval] ); | 234 | startTimer ( m_sensordata [LS_Interval] ); |
235 | } | 235 | } |
236 | 236 | ||
237 | setBacklightInternal ( bright ); | 237 | setBacklightInternal ( bright ); |
238 | ODevice::inst ( )-> setDisplayContrast(contrast); | 238 | ODevice::inst ( )-> setDisplayContrast(contrast); |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | /** | 242 | /** |
243 | * Internal brightness setting method | 243 | * Internal brightness setting method |
244 | * | 244 | * |
245 | * Get's default values for backlight and light sensor from config file. | 245 | * Get's default values for backlight and light sensor from config file. |
246 | * | 246 | * |
247 | * @param bright desired brighness (-1 to use automatic sensor data or value | 247 | * @param bright desired brighness (-1 to use automatic sensor data or value |
248 | * from config file, -2 to toggle backlight on and off, -3 to | 248 | * from config file, -2 to toggle backlight on and off, -3 to |
249 | * force backlight off) | 249 | * force backlight off) |
@@ -258,71 +258,71 @@ void OpieScreenSaver::setBacklightInternal ( int bright ) | |||
258 | if ( m_backlight_forcedoff && bright != -2 ) | 258 | if ( m_backlight_forcedoff && bright != -2 ) |
259 | return ; | 259 | return ; |
260 | if ( bright == -2 ) { | 260 | if ( bright == -2 ) { |
261 | // Toggle between off and on | 261 | // Toggle between off and on |
262 | bright = m_backlight_current ? 0 : -1; | 262 | bright = m_backlight_current ? 0 : -1; |
263 | m_backlight_forcedoff = !bright; | 263 | m_backlight_forcedoff = !bright; |
264 | } | 264 | } |
265 | if ( bright == -1 ) | 265 | if ( bright == -1 ) |
266 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | 266 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; |
267 | 267 | ||
268 | if ( bright != m_backlight_current ) { | 268 | if ( bright != m_backlight_current ) { |
269 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 269 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
270 | m_backlight_current = bright; | 270 | m_backlight_current = bright; |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | /** | 275 | /** |
276 | * Timer event used for automatic setting the backlight according to a light sensor | 276 | * Timer event used for automatic setting the backlight according to a light sensor |
277 | * and to set the default brightness | 277 | * and to set the default brightness |
278 | */ | 278 | */ |
279 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 279 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
280 | { | 280 | { |
281 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); | 281 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); |
282 | 282 | ||
283 | if ( s < m_sensordata [LS_SensorMin] ) | 283 | if ( s < m_sensordata [LS_SensorMin] ) |
284 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 284 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
285 | else if ( s >= m_sensordata [LS_SensorMax] ) | 285 | else if ( s >= m_sensordata [LS_SensorMax] ) |
286 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 286 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
287 | else { | 287 | else { |
288 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 288 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
289 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 289 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
290 | 290 | ||
291 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 | 291 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 |
292 | 292 | ||
293 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); | 293 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |
294 | } | 294 | } |
295 | 295 | ||
296 | //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] ); | 296 | //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] ); |
297 | 297 | ||
298 | if ( m_level <= 0 ) | 298 | if ( m_level <= 0 ) |
299 | setBacklightInternal ( -1 ); | 299 | setBacklightInternal ( -1 ); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | /** | 303 | /** |
304 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. | 304 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. |
305 | */ | 305 | */ |
306 | void OpieScreenSaver::setDisplayState ( bool on ) | 306 | void OpieScreenSaver::setDisplayState ( bool on ) |
307 | { | 307 | { |
308 | if ( m_lcd_status != on ) { | 308 | if ( m_lcd_status != on ) { |
309 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 309 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
310 | m_lcd_status = on; | 310 | m_lcd_status = on; |
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | /** | 315 | /** |
316 | * Set display to default ac/battery settings when power status changed. | 316 | * Set display to default ac/battery settings when power status changed. |
317 | */ | 317 | */ |
318 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 318 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
319 | { | 319 | { |
320 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 320 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
321 | 321 | ||
322 | if ( newonac != m_on_ac ) { | 322 | if ( newonac != m_on_ac ) { |
323 | m_on_ac = newonac; | 323 | m_on_ac = newonac; |
324 | setInterval ( -1 ); | 324 | setInterval ( -1 ); |
325 | setBacklight ( -1 ); | 325 | setBacklight ( -1 ); |
326 | restore ( ); | 326 | restore ( ); |
327 | } | 327 | } |
328 | } | 328 | } |