summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/screensaver.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
index 088ed19..b9bb64c 100644
--- a/core/launcher/screensaver.cpp
+++ b/core/launcher/screensaver.cpp
@@ -1,272 +1,270 @@
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
11using namespace Opie; 11using namespace Opie;
12 12
13 13
14 14
15OpieScreenSaver::OpieScreenSaver ( ) 15OpieScreenSaver::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
49void OpieScreenSaver::restore() 49void 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
62bool OpieScreenSaver::save( int level ) 62bool 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
111void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) 111void 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
151void OpieScreenSaver::setInterval ( int interval ) 151void OpieScreenSaver::setInterval ( int interval )
152{ 152{
153 setIntervals ( -1, -1, interval ); 153 setIntervals ( -1, -1, interval );
154} 154}
155 155
156 156
157void OpieScreenSaver::setMode ( int mode ) 157void 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
165void OpieScreenSaver::setBacklight ( int bright ) 165void 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 (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 );
175 175
176 killTimers ( ); 176 killTimers ( );
177 if ( m_use_light_sensor ) { 177 if (( bright < 0 ) && 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 191 if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE
192 m_sensordata [LS_Steps] = 2; 192 m_sensordata [LS_Steps] = 2;
193 193
194 timerEvent ( 0 ); 194 timerEvent ( 0 );
195 startTimer ( m_sensordata [LS_Interval] ); 195 startTimer ( m_sensordata [LS_Interval] );
196 } 196 }
197 197
198 setBacklightInternal ( bright ); 198 setBacklightInternal ( bright );
199} 199}
200 200
201 201
202void OpieScreenSaver::setBacklightInternal ( int bright ) 202void OpieScreenSaver::setBacklightInternal ( int bright )
203{ 203{
204 if ( bright == -3 ) { 204 if ( bright == -3 ) {
205 // Forced on 205 // Forced on
206 m_backlight_forcedoff = false; 206 m_backlight_forcedoff = false;
207 bright = -1; 207 bright = -1;
208 } 208 }
209 if ( m_backlight_forcedoff && bright != -2 ) 209 if ( m_backlight_forcedoff && bright != -2 )
210 return ; 210 return ;
211 if ( bright == -2 ) { 211 if ( bright == -2 ) {
212 // Toggle between off and on 212 // Toggle between off and on
213 bright = m_backlight_current ? 0 : -1; 213 bright = m_backlight_current ? 0 : -1;
214 m_backlight_forcedoff = !bright; 214 m_backlight_forcedoff = !bright;
215 } 215 }
216 if ( bright == -1 ) 216 if ( bright == -1 )
217 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; 217 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal;
218 218
219 if ( bright != m_backlight_current ) { 219 if ( bright != m_backlight_current ) {
220 ODevice::inst ( )-> setDisplayBrightness ( bright ); 220 ODevice::inst ( )-> setDisplayBrightness ( bright );
221 m_backlight_current = bright; 221 m_backlight_current = bright;
222 } 222 }
223} 223}
224 224
225 225
226void OpieScreenSaver::timerEvent ( QTimerEvent * ) 226void OpieScreenSaver::timerEvent ( QTimerEvent * )
227{ 227{
228 int s = ODevice::inst ( )-> readLightSensor ( ); 228 int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( );
229 229
230 if ( s < m_sensordata [LS_SensorMin] ) 230 if ( s < m_sensordata [LS_SensorMin] )
231 m_backlight_sensor = m_sensordata [LS_LightMax]; 231 m_backlight_sensor = m_sensordata [LS_LightMax];
232 else if ( s >= m_sensordata [LS_SensorMax] ) 232 else if ( s >= m_sensordata [LS_SensorMax] )
233 m_backlight_sensor = m_sensordata [LS_LightMin]; 233 m_backlight_sensor = m_sensordata [LS_LightMin];
234 else { 234 else {
235 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; 235 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin];
236 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; 236 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin];
237 237
238 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 238 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0
239 239
240 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 );
241 } 241 }
242 if ( !m_backlight_sensor )
243 m_backlight_sensor = 1;
244 242
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] ); 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] );
246 244
247 if ( m_level <= 0 ) 245 if ( m_level <= 0 )
248 setBacklightInternal ( -1 ); 246 setBacklightInternal ( -1 );
249} 247}
250 248
251 249
252void OpieScreenSaver::setDisplayState ( bool on ) 250void OpieScreenSaver::setDisplayState ( bool on )
253{ 251{
254 if ( m_lcd_status != on ) { 252 if ( m_lcd_status != on ) {
255 ODevice::inst ( ) -> setDisplayStatus ( on ); 253 ODevice::inst ( ) -> setDisplayStatus ( on );
256 m_lcd_status = on; 254 m_lcd_status = on;
257 } 255 }
258} 256}
259 257
260 258
261void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) 259void OpieScreenSaver::powerStatusChanged ( PowerStatus ps )
262{ 260{
263 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); 261 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online );
264 262
265 if ( newonac != m_on_ac ) { 263 if ( newonac != m_on_ac ) {
266 m_on_ac = newonac; 264 m_on_ac = newonac;
267 setInterval ( -1 ); 265 setInterval ( -1 );
268 setBacklight ( -1 ); 266 setBacklight ( -1 );
269 restore ( ); 267 restore ( );
270 } 268 }
271} 269}
272 270