summaryrefslogtreecommitdiff
path: root/library
authorllornkcor <llornkcor>2002-04-17 03:20:37 (UTC)
committer llornkcor <llornkcor>2002-04-17 03:20:37 (UTC)
commit4db3abc59c27022211222187a48eb649460c5432 (patch) (unidiff)
tree78fda069e80cadd5eb05c411c8cb5f2725dae6d9 /library
parent530f334d28c6156c4a50ba072b6d638a507c9686 (diff)
downloadopie-4db3abc59c27022211222187a48eb649460c5432.zip
opie-4db3abc59c27022211222187a48eb649460c5432.tar.gz
opie-4db3abc59c27022211222187a48eb649460c5432.tar.bz2
LCD off(only) on suspend patch
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index c154689..ba9db71 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -235,222 +235,249 @@ static int backlight()
235 // Read from config 235 // Read from config
236 Config config( "qpe" ); 236 Config config( "qpe" );
237 config.setGroup( "Screensaver" ); 237 config.setGroup( "Screensaver" );
238 curbl = config.readNumEntry("Brightness",255); 238 curbl = config.readNumEntry("Brightness",255);
239 } 239 }
240 return curbl; 240 return curbl;
241} 241}
242 242
243static void setBacklight(int bright) 243static void setBacklight(int bright)
244{ 244{
245 if ( bright == -3 ) { 245 if ( bright == -3 ) {
246 // Forced on 246 // Forced on
247 forced_off = FALSE; 247 forced_off = FALSE;
248 bright = -1; 248 bright = -1;
249 } 249 }
250 if ( forced_off && bright != -2 ) 250 if ( forced_off && bright != -2 )
251 return; 251 return;
252 if ( bright == -2 ) { 252 if ( bright == -2 ) {
253 // Toggle between off and on 253 // Toggle between off and on
254 bright = curbl ? 0 : -1; 254 bright = curbl ? 0 : -1;
255 forced_off = !bright; 255 forced_off = !bright;
256 } 256 }
257 if ( bright == -1 ) { 257 if ( bright == -1 ) {
258 // Read from config 258 // Read from config
259 Config config( "qpe" ); 259 Config config( "qpe" );
260 config.setGroup( "Screensaver" ); 260 config.setGroup( "Screensaver" );
261 bright = config.readNumEntry("Brightness",255); 261 bright = config.readNumEntry("Brightness",255);
262 } 262 }
263#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 263#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
264 if ( QFile::exists("/usr/bin/bl") ) { 264 if ( QFile::exists("/usr/bin/bl") ) {
265 QString cmd = "/usr/bin/bl 1 "; 265 QString cmd = "/usr/bin/bl 1 ";
266 cmd += bright<=0 ? "0 " : "1 "; 266 cmd += bright<=0 ? "0 " : "1 ";
267 cmd += QString::number(bright); 267 cmd += QString::number(bright);
268 system(cmd.latin1()); 268 system(cmd.latin1());
269#if defined(QT_QWS_EBX) 269#if defined(QT_QWS_EBX)
270 } else if ( QFile::exists("/dev/fl") ) { 270 } else if ( QFile::exists("/dev/fl") ) {
271#define FL_IOCTL_STEP_CONTRAST 100 271#define FL_IOCTL_STEP_CONTRAST 100
272 int fd = open("/dev/fl", O_WRONLY); 272 int fd = open("/dev/fl", O_WRONLY);
273 if (fd >= 0 ) { 273 if (fd >= 0 ) {
274 int steps = qpe_sysBrightnessSteps(); 274 int steps = qpe_sysBrightnessSteps();
275 int bl = ( bright * steps + 127 ) / 255; 275 int bl = ( bright * steps + 127 ) / 255;
276 if ( bright && !bl ) bl = 1; 276 if ( bright && !bl ) bl = 1;
277 bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); 277 bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl);
278 close(fd); 278 close(fd);
279 } 279 }
280 } 280 }
281#elif defined(QT_QWS_IPAQ) 281#elif defined(QT_QWS_IPAQ)
282 } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { 282 } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) {
283 typedef struct { 283 typedef struct {
284 unsigned char mode; 284 unsigned char mode;
285 unsigned char pwr; 285 unsigned char pwr;
286 unsigned char brightness; 286 unsigned char brightness;
287 } FLITE_IN; 287 } FLITE_IN;
288# ifndef FLITE_ON 288# ifndef FLITE_ON
289# ifndef _LINUX_IOCTL_H 289# ifndef _LINUX_IOCTL_H
290# include <linux/ioctl.h> 290# include <linux/ioctl.h>
291# endif 291# endif
292# define FLITE_ON _IOW('f', 7, FLITE_IN) 292# define FLITE_ON _IOW('f', 7, FLITE_IN)
293# endif 293# endif
294 int fd; 294 int fd;
295 if ( QFile::exists("/dev/ts") ) 295 if ( QFile::exists("/dev/ts") )
296 fd = open("/dev/ts", O_WRONLY); 296 fd = open("/dev/ts", O_WRONLY);
297 else 297 else
298 fd = open("/dev/h3600_ts", O_WRONLY); 298 fd = open("/dev/h3600_ts", O_WRONLY);
299 if (fd >= 0 ) { 299 if (fd >= 0 ) {
300 FLITE_IN bl; 300 FLITE_IN bl;
301 bl.mode = 1; 301 bl.mode = 1;
302 bl.pwr = bright ? 1 : 0; 302 bl.pwr = bright ? 1 : 0;
303 bl.brightness = bright; 303 bl.brightness = bright;
304 ioctl(fd, FLITE_ON, &bl); 304 ioctl(fd, FLITE_ON, &bl);
305 close(fd); 305 close(fd);
306 } 306 }
307 } 307 }
308#endif 308#endif
309#endif 309#endif
310 curbl = bright; 310 curbl = bright;
311} 311}
312 312
313void qpe_setBacklight(int bright) { setBacklight(bright); } 313void qpe_setBacklight(int bright) { setBacklight(bright); }
314 314
315static bool dim_on = FALSE; 315static bool dim_on = FALSE;
316static bool lightoff_on = FALSE; 316static bool lightoff_on = FALSE;
317static int disable_suspend = 100; 317static int disable_suspend = 100;
318 318
319static bool powerOnline() 319static bool powerOnline()
320{ 320{
321 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; 321 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;
322} 322}
323 323
324static bool networkOnline() 324static bool networkOnline()
325{ 325{
326 return Network::networkOnline(); 326 return Network::networkOnline();
327} 327}
328 328
329class QPEScreenSaver : public QWSScreenSaver 329class QPEScreenSaver : public QWSScreenSaver
330{ 330{
331private:
332 int LcdOn;
331 333
332public: 334public:
333 QPEScreenSaver() 335 QPEScreenSaver()
334 { 336 {
337 int fd;
338
339 LcdOn = TRUE;
340 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
341 fd=open("/dev/fb0",O_RDWR);
342 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); }
335 } 343 }
336 void restore() 344 void restore()
337 { 345 {
346 if (!LcdOn) // We must have turned it off
347 {
348 int fd;
349 fd=open("/dev/fb0",O_RDWR);
350 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); }
351 }
338 setBacklight(-1); 352 setBacklight(-1);
339 } 353 }
340 bool save(int level) 354 bool save(int level)
341 { 355 {
356 int fd;
357
342 switch ( level ) { 358 switch ( level ) {
343 case 0: 359 case 0:
344 if ( disable_suspend > 0 && dim_on ) { 360 if ( disable_suspend > 0 && dim_on ) {
345 if (backlight() > 1) 361 if (backlight() > 1)
346 setBacklight(1); // lowest non-off 362 setBacklight(1); // lowest non-off
347 } 363 }
348 return TRUE; 364 return TRUE;
349 break; 365 break;
350 case 1: 366 case 1:
351 if ( disable_suspend > 1 && lightoff_on ) { 367 if ( disable_suspend > 1 && lightoff_on ) {
352 setBacklight(0); // off 368 setBacklight(0); // off
353 } 369 }
354 return TRUE; 370 return TRUE;
355 break; 371 break;
356 case 2: 372 case 2:
357 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { 373 Config config( "qpe" );
358 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 374 config.setGroup( "Screensaver" );
359 return TRUE; 375 if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD
360 } 376 {
377 fd=open("/dev/fb0",O_RDWR);
378 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); }
379 LcdOn = FALSE;
380 }
381 else // We're going to suspend the whole machine
382 {
383 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) {
384 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
385 return TRUE;
386 }
387 }
361 break; 388 break;
362 } 389 }
363 return FALSE; 390 return FALSE;
364 } 391 }
365}; 392};
366 393
367static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) 394static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def)
368{ 395{
369 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) 396 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 )
370 return 0; 397 return 0;
371 398
372 if ( interval < 0 ) { 399 if ( interval < 0 ) {
373 // Restore screen blanking and power saving state 400 // Restore screen blanking and power saving state
374 interval = config.readNumEntry( value, def ); 401 interval = config.readNumEntry( value, def );
375 } 402 }
376 return interval; 403 return interval;
377} 404}
378 405
379static void setScreenSaverIntervals(int i1, int i2, int i3) 406static void setScreenSaverIntervals(int i1, int i2, int i3)
380{ 407{
381 Config config( "qpe" ); 408 Config config( "qpe" );
382 config.setGroup( "Screensaver" ); 409 config.setGroup( "Screensaver" );
383 410
384 int v[4]; 411 int v[4];
385 i1 = ssi(i1, config, "Dim","Interval_Dim", 30); 412 i1 = ssi(i1, config, "Dim","Interval_Dim", 30);
386 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); 413 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20);
387 i3 = ssi(i3, config, "","Interval", 60); 414 i3 = ssi(i3, config, "","Interval", 60);
388 415
389 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 416 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
390 417
391 v[0] = QMAX( 1000*i1, 100); 418 v[0] = QMAX( 1000*i1, 100);
392 v[1] = QMAX( 1000*i2, 100); 419 v[1] = QMAX( 1000*i2, 100);
393 v[2] = QMAX( 1000*i3, 100); 420 v[2] = QMAX( 1000*i3, 100);
394 v[3] = 0; 421 v[3] = 0;
395 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); 422 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE );
396 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); 423 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE );
397 if ( !i1 && !i2 && !i3 ) 424 if ( !i1 && !i2 && !i3 )
398 QWSServer::setScreenSaverInterval(0); 425 QWSServer::setScreenSaverInterval(0);
399 else 426 else
400 QWSServer::setScreenSaverIntervals(v); 427 QWSServer::setScreenSaverIntervals(v);
401} 428}
402 429
403static void setScreenSaverInterval(int interval) 430static void setScreenSaverInterval(int interval)
404{ 431{
405 setScreenSaverIntervals(-1,-1,interval); 432 setScreenSaverIntervals(-1,-1,interval);
406} 433}
407 434
408 435
409/*! 436/*!
410 \class QPEApplication qpeapplication.h 437 \class QPEApplication qpeapplication.h
411 \brief The QPEApplication class implements various system services 438 \brief The QPEApplication class implements various system services
412 that are available to all Qtopia applications. 439 that are available to all Qtopia applications.
413 440
414 Simply by using QPEApplication instead of QApplication, a plain Qt 441 Simply by using QPEApplication instead of QApplication, a plain Qt
415 application becomes a Qtopia application. It automatically follows 442 application becomes a Qtopia application. It automatically follows
416 style changes, quits and raises, and in the 443 style changes, quits and raises, and in the
417 case of \link docwidget.html document-oriented\endlink applications, 444 case of \link docwidget.html document-oriented\endlink applications,
418 changes the current displayed document in response to the environment. 445 changes the current displayed document in response to the environment.
419*/ 446*/
420 447
421/*! 448/*!
422 \fn void QPEApplication::clientMoused() 449 \fn void QPEApplication::clientMoused()
423 450
424 \internal 451 \internal
425*/ 452*/
426 453
427/*! 454/*!
428 \fn void QPEApplication::timeChanged(); 455 \fn void QPEApplication::timeChanged();
429 456
430 This signal is emitted when the time jumps forward or backwards 457 This signal is emitted when the time jumps forward or backwards
431 by more than the normal passage of time. 458 by more than the normal passage of time.
432*/ 459*/
433 460
434/*! 461/*!
435 \fn void QPEApplication::clockChanged( bool ampm ); 462 \fn void QPEApplication::clockChanged( bool ampm );
436 463
437 This signal is emitted when the user changes the style 464 This signal is emitted when the user changes the style
438 of clock. If \a ampm is TRUE, the user wants a 12-hour 465 of clock. If \a ampm is TRUE, the user wants a 12-hour
439 AM/PM close, otherwise, they want a 24-hour clock. 466 AM/PM close, otherwise, they want a 24-hour clock.
440*/ 467*/
441 468
442/*! 469/*!
443 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 470 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
444 471
445 This signal is emitted when a message is received on the 472 This signal is emitted when a message is received on the
446 QPE/Application/<i>appname</i> QCop channel for this application. 473 QPE/Application/<i>appname</i> QCop channel for this application.
447 474
448 The slot to which you connect this signal uses \a msg and \a data 475 The slot to which you connect this signal uses \a msg and \a data
449 in the following way: 476 in the following way:
450 477
451\code 478\code
452 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 479 void MyWidget::receive( const QCString& msg, const QByteArray& data )
453 { 480 {
454 QDataStream stream( data, IO_ReadOnly ); 481 QDataStream stream( data, IO_ReadOnly );
455 if ( msg == "someMessage(int,int,int)" ) { 482 if ( msg == "someMessage(int,int,int)" ) {
456 int a,b,c; 483 int a,b,c;