summaryrefslogtreecommitdiff
path: root/core/opie-login/main.cpp
Unidiff
Diffstat (limited to 'core/opie-login/main.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp257
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
@@ -3,177 +3,222 @@
3#include <unistd.h> 3#include <unistd.h>
4#include <syslog.h> 4#include <syslog.h>
5#include <sys/types.h> 5#include <sys/types.h>
6#include <sys/wait.h> 6#include <sys/wait.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <signal.h>
9 10
10#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
11#include <qpe/qcopenvelope_qws.h> 12#include <qpe/qcopenvelope_qws.h>
13#include <qpe/qpestyle.h>
14#include <qpe/power.h>
12 15
13#include <opie/odevice.h> 16#include <opie/odevice.h>
14 17
15#include <qwindowsystem_qws.h> 18#include <qwindowsystem_qws.h>
16#include <qfile.h> 19#include <qfile.h>
17 20
18#include "loginwindowimpl.h" 21#include "loginwindowimpl.h"
19#include "calibrate.h" 22#include "calibrate.h"
20 23
21int login_main ( int argc, char **argv ); 24int login_main ( int argc, char **argv );
25void sigusr1 ( int sig );
26void exit_closelog ( );
27
22 28
23 29
24int main ( int argc, char **argv ) 30int main ( int argc, char **argv )
25{ 31{
26 if ( geteuid ( ) != 0 ) { 32 if ( ::geteuid ( ) != 0 ) {
27 fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); 33 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
28 return 1; 34 return 1;
29 } 35 }
30 36
31 //struct rlimit rl; 37 //struct rlimit rl;
32 //getrlimit ( RLIMIT_NOFILE, &rl ); 38 //::getrlimit ( RLIMIT_NOFILE, &rl );
33 39
34 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 40 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
35 // close ( i ); 41 // ::close ( i );
42
43 ::setpgid ( 0, 0 );
44 ::setsid ( );
45
46 ::signal ( SIGUSR1, sigusr1 );
47
48 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
49 ::atexit ( exit_closelog );
36 50
37 setpgid ( 0, 0 );
38 setsid ( );
39
40 openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
41
42 while ( true ) { 51 while ( true ) {
43 pid_t child = fork ( ); 52 pid_t child = ::fork ( );
44 53
45 if ( child < 0 ) { 54 if ( child < 0 ) {
46 syslog ( LOG_ERR, "Could not fork process" ); 55 ::syslog ( LOG_ERR, "Could not fork process" );
47 break; 56 break;
48 57
49 } 58 }
50 else if ( child > 0 ) { 59 else if ( child > 0 ) {
51 int status = 0; 60 int status = 0;
52 61
53 while ( waitpid ( child, &status, 0 ) < 0 ) { } 62 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
54 } 63 }
55 else { 64 else {
56 exit ( login_main ( argc, argv )); 65 ::exit ( login_main ( argc, argv ));
57 } 66 }
58 } 67 }
59 closelog ( ); 68 return 0;
60} 69}
61 70
71void sigusr1 ( int /*sig*/ )
72{
73 ::exit ( 0 );
74}
62 75
63class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter 76void exit_closelog ( )
64{ 77{
65public: 78 ::closelog ( );
66 ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" ) 79}
67 {
68 bool doinst = false;
69
70 m_model = ODevice::inst ( )-> model ( );
71 m_power_timer = 0;
72
73 switch ( m_model ) {
74 case OMODEL_iPAQ_H31xx:
75 case OMODEL_iPAQ_H36xx:
76 case OMODEL_iPAQ_H37xx:
77 case OMODEL_iPAQ_H38xx: doinst = true;
78 break;
79 default : break;
80 }
81 if ( doinst )
82 QWSServer::setKeyboardFilter ( this );
83 }
84 80
85 virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
86 {
87 bool kill = false;
88
89 // Rotate cursor keys 180°
90 switch ( m_model ) {
91 case OMODEL_iPAQ_H31xx:
92 case OMODEL_iPAQ_H38xx: {
93 int newkeycode = keycode;
94
95 switch ( keycode ) {
96 case Key_Left : newkeycode = Key_Right; break;
97 case Key_Right: newkeycode = Key_Left; break;
98 case Key_Up : newkeycode = Key_Down; break;
99 case Key_Down : newkeycode = Key_Up; break;
100 }
101 if ( newkeycode != keycode ) {
102 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
103 kill = true;
104 }
105 break;
106 }
107 default: break;
108 }
109
110 // map Power Button short/long press to F34/F35
111 switch ( m_model ) {
112 case OMODEL_iPAQ_H31xx:
113 case OMODEL_iPAQ_H36xx:
114 case OMODEL_iPAQ_H37xx:
115 case OMODEL_iPAQ_H38xx: {
116 if ( keycode == Key_SysReq ) {
117 if ( isPress ) {
118 m_power_timer = startTimer ( 500 );
119 }
120 else if ( m_power_timer ) {
121 killTimer ( m_power_timer );
122 m_power_timer = 0;
123 QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false );
124 QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false );
125 }
126 kill = true;
127 }
128 break;
129 }
130 default: break;
131 }
132 return kill;
133 }
134 81
135 virtual void timerEvent ( QTimerEvent * ) 82class LoginScreenSaver : public QWSScreenSaver
136 { 83{
137 killTimer ( m_power_timer ); 84public:
138 m_power_timer = 0; 85 LoginScreenSaver ( )
139 QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false ); 86 {
140 QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false ); 87 m_lcd_status = true;
141 } 88
89 m_backlight_bright = -1;
90 m_backlight_forcedoff = false;
91
92 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
93 ODevice::inst ( ) -> setDisplayStatus ( true );
94 }
95 void restore()
96 {
97 if ( !m_lcd_status ) // We must have turned it off
98 ODevice::inst ( ) -> setDisplayStatus ( true );
99
100 setBacklight ( -1 );
101 }
102 bool save( int level )
103 {
104 switch ( level ) {
105 case 0:
106 if ( backlight() > 1 )
107 setBacklight( 1 ); // lowest non-off
108 return true;
109 break;
110 case 1:
111 setBacklight( 0 ); // off
112 return true;
113 break;
114 case 2:
115 // We're going to suspend the whole machine
116 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
117 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
118 return true;
119 }
120 break;
121 }
122 return false;
123 }
142 124
143private: 125private:
144 OModel m_model; 126public:
145 int m_power_timer; 127 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
146}; 128 {
129 int v [4];
130
131 v [ 0 ] = QMAX( 1000 * i1, 100 );
132 v [ 1 ] = QMAX( 1000 * i2, 100 );
133 v [ 2 ] = QMAX( 1000 * i3, 100 );
134 v [ 3 ] = 0;
135
136 if ( !i1 && !i2 && !i3 )
137 QWSServer::setScreenSaverInterval ( 0 );
138 else
139 QWSServer::setScreenSaverIntervals ( v );
140 }
141
142 int backlight ( )
143 {
144 if ( m_backlight_bright == -1 )
145 m_backlight_bright = 255;
146
147 return m_backlight_bright;
148 }
149
150 void setBacklight ( int bright )
151 {
152 if ( bright == -3 ) {
153 // Forced on
154 m_backlight_forcedoff = false;
155 bright = -1;
156 }
157 if ( m_backlight_forcedoff && bright != -2 )
158 return ;
159 if ( bright == -2 ) {
160 // Toggle between off and on
161 bright = m_backlight_bright ? 0 : -1;
162 m_backlight_forcedoff = !bright;
163 }
164
165 m_backlight_bright = bright;
166
167 bright = backlight ( );
168 ODevice::inst ( ) -> setDisplayBrightness ( bright );
169
170 m_backlight_bright = bright;
171 }
147 172
173private:
174 bool m_lcd_status;
175
176 int m_backlight_bright;
177 bool m_backlight_forcedoff;
178};
148 179
149 180
150 181
151int login_main ( int argc, char **argv ) 182int login_main ( int argc, char **argv )
152{ 183{
153 QWSServer::setDesktopBackground( QImage() ); 184 QWSServer::setDesktopBackground( QImage() );
154 QPEApplication app ( argc, argv, QApplication::GuiServer ); 185 QPEApplication app ( argc, argv, QApplication::GuiServer );
155 186
156 (void) new ModelKeyFilter ( ); 187 app. setFont ( QFont ( "Helvetica", 10 ));
157 188 app. setStyle ( new QPEStyle ( ));
158 { 189
159 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 190 ODevice::inst ( )-> setSoftSuspend ( true );
160 e << -3; // Forced on 191
192 {
193 QCopEnvelope e("QPE/System", "setBacklight(int)" );
194 e << -3; // Forced on
161 } 195 }
162 196
163#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 197#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
164 if ( !QFile::exists ( "/etc/pointercal" )) { 198 if ( !QFile::exists ( "/etc/pointercal" )) {
165 // Make sure calibration widget starts on top. 199 // Make sure calibration widget starts on top.
166 Calibrate *cal = new Calibrate; 200 Calibrate *cal = new Calibrate;
167 cal-> exec ( ); 201 cal-> exec ( );
168 delete cal; 202 delete cal;
169 } 203 }
170#endif 204#endif
171 205
206
207 LoginScreenSaver *saver = new LoginScreenSaver;
208
209 saver-> setIntervals ( );
210 QWSServer::setScreenSaver ( saver );
211
212
172 LoginWindowImpl *lw = new LoginWindowImpl ( ); 213 LoginWindowImpl *lw = new LoginWindowImpl ( );
173 app. setMainWidget ( lw ); 214 app. setMainWidget ( lw );
174 lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( )); 215 lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( ));
175 lw-> show ( ); 216 lw-> show ( );
176 217
177 return app. exec ( ); 218 int rc = app. exec ( );
219
220 ODevice::inst ( )-> setSoftSuspend ( false );
221
222 return rc;
178} 223}
179 224