author | llornkcor <llornkcor> | 2002-04-17 03:20:37 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-17 03:20:37 (UTC) |
commit | 4db3abc59c27022211222187a48eb649460c5432 (patch) (side-by-side diff) | |
tree | 78fda069e80cadd5eb05c411c8cb5f2725dae6d9 | |
parent | 530f334d28c6156c4a50ba072b6d638a507c9686 (diff) | |
download | opie-4db3abc59c27022211222187a48eb649460c5432.zip opie-4db3abc59c27022211222187a48eb649460c5432.tar.gz opie-4db3abc59c27022211222187a48eb649460c5432.tar.bz2 |
LCD off(only) on suspend patch
-rw-r--r-- | library/qpeapplication.cpp | 35 |
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 @@ -139,414 +139,441 @@ public: ResourceMimeFactory() { setFilePath( Global::helpPath() ); setExtensionType("html","text/html;charset=UTF-8"); } const QMimeSource* data(const QString& abs_name) const { const QMimeSource* r = QMimeSourceFactory::data(abs_name); if ( !r ) { int sl = abs_name.length(); do { sl = abs_name.findRev('/',sl-1); QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; int dot = name.findRev('.'); if ( dot >= 0 ) name = name.left(dot); QImage img = Resource::loadImage(name); if ( !img.isNull() ) r = new QImageDrag(img); } while (!r && sl>0); } return r; } }; static int muted=0; static int micMuted=0; static void setVolume(int t=0, int percent=-1) { switch (t) { case 0: { Config cfg("Sound"); cfg.setGroup("System"); if ( percent < 0 ) percent = cfg.readNumEntry("Volume",50); int fd = 0; if ((fd = open("/dev/mixer", O_RDWR))>=0) { int vol = muted ? 0 : percent; // set both channels to same volume vol |= vol << 8; ioctl(fd, MIXER_WRITE(0), &vol); ::close(fd); } } break; } } static void setMic(int t=0, int percent=-1) { switch (t) { case 0: { Config cfg("Sound"); cfg.setGroup("System"); if ( percent < 0 ) percent = cfg.readNumEntry("Mic",50); int fd = 0; int mic = micMuted ? 0 : percent; if ((fd = open("/dev/mixer", O_RDWR))>=0) { ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); ::close(fd); } } break; } } int qpe_sysBrightnessSteps() { #if defined(QT_QWS_IPAQ) return 255; #elif defined(QT_QWS_EBX) return 4; #else return 255; // ? #endif } static int& hack(int& i) { #if QT_VERSION <= 230 && defined(QT_NO_CODECS) // These should be created, but aren't in Qt 2.3.0 (void)new QUtf8Codec; (void)new QUtf16Codec; #endif return i; } static bool forced_off = FALSE; static int curbl=-1; static int backlight() { if ( curbl == -1 ) { // Read from config Config config( "qpe" ); config.setGroup( "Screensaver" ); curbl = config.readNumEntry("Brightness",255); } return curbl; } static void setBacklight(int bright) { if ( bright == -3 ) { // Forced on forced_off = FALSE; bright = -1; } if ( forced_off && bright != -2 ) return; if ( bright == -2 ) { // Toggle between off and on bright = curbl ? 0 : -1; forced_off = !bright; } if ( bright == -1 ) { // Read from config Config config( "qpe" ); config.setGroup( "Screensaver" ); bright = config.readNumEntry("Brightness",255); } #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) if ( QFile::exists("/usr/bin/bl") ) { QString cmd = "/usr/bin/bl 1 "; cmd += bright<=0 ? "0 " : "1 "; cmd += QString::number(bright); system(cmd.latin1()); #if defined(QT_QWS_EBX) } else if ( QFile::exists("/dev/fl") ) { #define FL_IOCTL_STEP_CONTRAST 100 int fd = open("/dev/fl", O_WRONLY); if (fd >= 0 ) { int steps = qpe_sysBrightnessSteps(); int bl = ( bright * steps + 127 ) / 255; if ( bright && !bl ) bl = 1; bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); close(fd); } } #elif defined(QT_QWS_IPAQ) } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { typedef struct { unsigned char mode; unsigned char pwr; unsigned char brightness; } FLITE_IN; # ifndef FLITE_ON # ifndef _LINUX_IOCTL_H # include <linux/ioctl.h> # endif # define FLITE_ON _IOW('f', 7, FLITE_IN) # endif int fd; if ( QFile::exists("/dev/ts") ) fd = open("/dev/ts", O_WRONLY); else fd = open("/dev/h3600_ts", O_WRONLY); if (fd >= 0 ) { FLITE_IN bl; bl.mode = 1; bl.pwr = bright ? 1 : 0; bl.brightness = bright; ioctl(fd, FLITE_ON, &bl); close(fd); } } #endif #endif curbl = bright; } void qpe_setBacklight(int bright) { setBacklight(bright); } static bool dim_on = FALSE; static bool lightoff_on = FALSE; static int disable_suspend = 100; static bool powerOnline() { return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; } static bool networkOnline() { return Network::networkOnline(); } class QPEScreenSaver : public QWSScreenSaver { +private: + int LcdOn; public: QPEScreenSaver() { + int fd; + + LcdOn = TRUE; + // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) + fd=open("/dev/fb0",O_RDWR); + if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } } void restore() { + if (!LcdOn) // We must have turned it off + { + int fd; + fd=open("/dev/fb0",O_RDWR); + if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } + } setBacklight(-1); } bool save(int level) { + int fd; + switch ( level ) { case 0: if ( disable_suspend > 0 && dim_on ) { if (backlight() > 1) setBacklight(1); // lowest non-off } return TRUE; break; case 1: if ( disable_suspend > 1 && lightoff_on ) { setBacklight(0); // off } return TRUE; break; case 2: - if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { - QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); - return TRUE; - } + Config config( "qpe" ); + config.setGroup( "Screensaver" ); + if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD + { + fd=open("/dev/fb0",O_RDWR); + if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); } + LcdOn = FALSE; + } + else // We're going to suspend the whole machine + { + if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { + QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); + return TRUE; + } + } break; } return FALSE; } }; static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) { if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) return 0; if ( interval < 0 ) { // Restore screen blanking and power saving state interval = config.readNumEntry( value, def ); } return interval; } static void setScreenSaverIntervals(int i1, int i2, int i3) { Config config( "qpe" ); config.setGroup( "Screensaver" ); int v[4]; i1 = ssi(i1, config, "Dim","Interval_Dim", 30); i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); i3 = ssi(i3, config, "","Interval", 60); //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); v[0] = QMAX( 1000*i1, 100); v[1] = QMAX( 1000*i2, 100); v[2] = QMAX( 1000*i3, 100); v[3] = 0; dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); if ( !i1 && !i2 && !i3 ) QWSServer::setScreenSaverInterval(0); else QWSServer::setScreenSaverIntervals(v); } static void setScreenSaverInterval(int interval) { setScreenSaverIntervals(-1,-1,interval); } /*! \class QPEApplication qpeapplication.h \brief The QPEApplication class implements various system services that are available to all Qtopia applications. Simply by using QPEApplication instead of QApplication, a plain Qt application becomes a Qtopia application. It automatically follows style changes, quits and raises, and in the case of \link docwidget.html document-oriented\endlink applications, changes the current displayed document in response to the environment. */ /*! \fn void QPEApplication::clientMoused() \internal */ /*! \fn void QPEApplication::timeChanged(); This signal is emitted when the time jumps forward or backwards by more than the normal passage of time. */ /*! \fn void QPEApplication::clockChanged( bool ampm ); This signal is emitted when the user changes the style of clock. If \a ampm is TRUE, the user wants a 12-hour AM/PM close, otherwise, they want a 24-hour clock. */ /*! \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) This signal is emitted when a message is received on the QPE/Application/<i>appname</i> QCop channel for this application. The slot to which you connect this signal uses \a msg and \a data in the following way: \code void MyWidget::receive( const QCString& msg, const QByteArray& data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } else if ( msg == "otherMessage(QString)" ) { ... } } \endcode \sa qcop.html */ /*! Constructs a QPEApplication just as you would construct a QApplication, passing \a argc, \a argv, and \a t. */ QPEApplication::QPEApplication( int& argc, char **argv, Type t ) : QApplication( hack(argc), argv, t ) { int dw = desktop()->width(); if ( dw < 200 ) { setFont( QFont( "helvetica", 8 ) ); AppLnk::setSmallIconSize(10); AppLnk::setBigIconSize(28); } d = new QPEApplicationData; QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit())); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QString qcopfn("/tmp/qcop-msg-"); qcopfn += QString(argv[0]); // append command name QFile f(qcopfn); if ( f.open(IO_ReadOnly) ) { flock(f.handle(), LOCK_EX); } sysChannel = new QCopChannel( "QPE/System", this ); connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); QCString channel = QCString(argv[0]); channel.replace(QRegExp(".*/"),""); d->appName = channel; channel = "QPE/Application/" + channel; pidChannel = new QCopChannel( channel, this); connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(pidMessage(const QCString &, const QByteArray &))); if ( f.isOpen() ) { d->keep_running = FALSE; QDataStream ds(&f); QCString channel, message; QByteArray data; while(!ds.atEnd()) { ds >> channel >> message >> data; d->enqueueQCop(channel,message,data); } flock(f.handle(), LOCK_UN); f.close(); f.remove(); } for (int a=0; a<argc; a++) { if ( qstrcmp(argv[a],"-preload")==0 ) { argv[a] = argv[a+1]; a++; d->preloaded = TRUE; argc-=1; } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { argv[a] = argv[a+1]; a++; d->preloaded = TRUE; d->forceshow = TRUE; argc-=1; } } /* overide stored arguments */ setArgs(argc, argv); #endif qwsSetDecoration( new QPEDecoration() ); #ifndef QT_NO_TRANSLATION QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { QString lang = *it; QTranslator * trans; QString tfn; |