author | sandman <sandman> | 2002-09-30 00:29:12 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-30 00:29:12 (UTC) |
commit | f6e9cebd79044b1ca54648ecdadd13db8c4673dc (patch) (side-by-side diff) | |
tree | e29985455734329ee31e14d04b2d613eafabb6a0 /core/opie-login/main.cpp | |
parent | b53db7a5a334fdd53bd86e8b50587f1dae41cfba (diff) | |
download | opie-f6e9cebd79044b1ca54648ecdadd13db8c4673dc.zip opie-f6e9cebd79044b1ca54648ecdadd13db8c4673dc.tar.gz opie-f6e9cebd79044b1ca54648ecdadd13db8c4673dc.tar.bz2 |
- added an option to quit to console
- launcher is now started via a login shell
- font is "hardcoded" to helvetica
- screen saver is "hardcoded" to 30/20/60 secs
(this should make opie-login usable, regardless of any
(miss)-configuration of the normal OPIE appearance)
-rw-r--r-- | core/opie-login/main.cpp | 257 |
1 files changed, 151 insertions, 106 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 44d6f8d..718009a 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp @@ -5,160 +5,194 @@ #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> +#include <signal.h> #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> +#include <qpe/qpestyle.h> +#include <qpe/power.h> #include <opie/odevice.h> #include <qwindowsystem_qws.h> #include <qfile.h> #include "loginwindowimpl.h" #include "calibrate.h" - + int login_main ( int argc, char **argv ); +void sigusr1 ( int sig ); +void exit_closelog ( ); + int main ( int argc, char **argv ) { - if ( geteuid ( ) != 0 ) { - fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); + if ( ::geteuid ( ) != 0 ) { + ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); return 1; } // struct rlimit rl; -// getrlimit ( RLIMIT_NOFILE, &rl ); - +// ::getrlimit ( RLIMIT_NOFILE, &rl ); + // for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) -// close ( i ); +// ::close ( i ); + + ::setpgid ( 0, 0 ); + ::setsid ( ); + + ::signal ( SIGUSR1, sigusr1 ); + + ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); + ::atexit ( exit_closelog ); - setpgid ( 0, 0 ); - setsid ( ); - - openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); - while ( true ) { - pid_t child = fork ( ); - + pid_t child = ::fork ( ); + if ( child < 0 ) { - syslog ( LOG_ERR, "Could not fork process" ); + ::syslog ( LOG_ERR, "Could not fork process" ); break; - + } else if ( child > 0 ) { int status = 0; - - while ( waitpid ( child, &status, 0 ) < 0 ) { } + + while ( ::waitpid ( child, &status, 0 ) < 0 ) { } } else { - exit ( login_main ( argc, argv )); + ::exit ( login_main ( argc, argv )); } } - closelog ( ); + return 0; } +void sigusr1 ( int /*sig*/ ) +{ + ::exit ( 0 ); +} -class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter +void exit_closelog ( ) { -public: - ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" ) - { - bool doinst = false; - - m_model = ODevice::inst ( )-> model ( ); - m_power_timer = 0; - - switch ( m_model ) { - case OMODEL_iPAQ_H31xx: - case OMODEL_iPAQ_H36xx: - case OMODEL_iPAQ_H37xx: - case OMODEL_iPAQ_H38xx: doinst = true; - break; - default : break; - } - if ( doinst ) - QWSServer::setKeyboardFilter ( this ); - } + ::closelog ( ); +} - virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) - { - bool kill = false; - - // Rotate cursor keys 180° - switch ( m_model ) { - case OMODEL_iPAQ_H31xx: - case OMODEL_iPAQ_H38xx: { - int newkeycode = keycode; - - switch ( keycode ) { - case Key_Left : newkeycode = Key_Right; break; - case Key_Right: newkeycode = Key_Left; break; - case Key_Up : newkeycode = Key_Down; break; - case Key_Down : newkeycode = Key_Up; break; - } - if ( newkeycode != keycode ) { - QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); - kill = true; - } - break; - } - default: break; - } - - // map Power Button short/long press to F34/F35 - switch ( m_model ) { - case OMODEL_iPAQ_H31xx: - case OMODEL_iPAQ_H36xx: - case OMODEL_iPAQ_H37xx: - case OMODEL_iPAQ_H38xx: { - if ( keycode == Key_SysReq ) { - if ( isPress ) { - m_power_timer = startTimer ( 500 ); - } - else if ( m_power_timer ) { - killTimer ( m_power_timer ); - m_power_timer = 0; - QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false ); - QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false ); - } - kill = true; - } - break; - } - default: break; - } - return kill; - } - virtual void timerEvent ( QTimerEvent * ) - { - killTimer ( m_power_timer ); - m_power_timer = 0; - QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false ); - QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false ); - } +class LoginScreenSaver : public QWSScreenSaver +{ +public: + LoginScreenSaver ( ) + { + m_lcd_status = true; + + m_backlight_bright = -1; + m_backlight_forcedoff = false; + + // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) + ODevice::inst ( ) -> setDisplayStatus ( true ); + } + void restore() + { + if ( !m_lcd_status ) // We must have turned it off + ODevice::inst ( ) -> setDisplayStatus ( true ); + + setBacklight ( -1 ); + } + bool save( int level ) + { + switch ( level ) { + case 0: + if ( backlight() > 1 ) + setBacklight( 1 ); // lowest non-off + return true; + break; + case 1: + setBacklight( 0 ); // off + return true; + break; + case 2: + // We're going to suspend the whole machine + if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { + QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); + return true; + } + break; + } + return false; + } private: - OModel m_model; - int m_power_timer; -}; +public: + void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) + { + int v [4]; + + v [ 0 ] = QMAX( 1000 * i1, 100 ); + v [ 1 ] = QMAX( 1000 * i2, 100 ); + v [ 2 ] = QMAX( 1000 * i3, 100 ); + v [ 3 ] = 0; + + if ( !i1 && !i2 && !i3 ) + QWSServer::setScreenSaverInterval ( 0 ); + else + QWSServer::setScreenSaverIntervals ( v ); + } + + int backlight ( ) + { + if ( m_backlight_bright == -1 ) + m_backlight_bright = 255; + + return m_backlight_bright; + } + + void setBacklight ( int bright ) + { + if ( bright == -3 ) { + // Forced on + m_backlight_forcedoff = false; + bright = -1; + } + if ( m_backlight_forcedoff && bright != -2 ) + return ; + if ( bright == -2 ) { + // Toggle between off and on + bright = m_backlight_bright ? 0 : -1; + m_backlight_forcedoff = !bright; + } + + m_backlight_bright = bright; + + bright = backlight ( ); + ODevice::inst ( ) -> setDisplayBrightness ( bright ); + + m_backlight_bright = bright; + } +private: + bool m_lcd_status; + + int m_backlight_bright; + bool m_backlight_forcedoff; +}; int login_main ( int argc, char **argv ) { QWSServer::setDesktopBackground( QImage() ); QPEApplication app ( argc, argv, QApplication::GuiServer ); - (void) new ModelKeyFilter ( ); - - { - QCopEnvelope e("QPE/System", "setBacklight(int)" ); - e << -3; // Forced on + app. setFont ( QFont ( "Helvetica", 10 )); + app. setStyle ( new QPEStyle ( )); + + ODevice::inst ( )-> setSoftSuspend ( true ); + + { + QCopEnvelope e("QPE/System", "setBacklight(int)" ); + e << -3; // Forced on } #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) if ( !QFile::exists ( "/etc/pointercal" )) { @@ -167,13 +201,24 @@ int login_main ( int argc, char **argv ) cal-> exec ( ); delete cal; } #endif - + + + LoginScreenSaver *saver = new LoginScreenSaver; + + saver-> setIntervals ( ); + QWSServer::setScreenSaver ( saver ); + + LoginWindowImpl *lw = new LoginWindowImpl ( ); app. setMainWidget ( lw ); lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( )); lw-> show ( ); - - return app. exec ( ); + + int rc = app. exec ( ); + + ODevice::inst ( )-> setSoftSuspend ( false ); + + return rc; } |