-rw-r--r-- | core/opie-login/main.cpp | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp new file mode 100644 index 0000000..9d52b75 --- a/dev/null +++ b/core/opie-login/main.cpp | |||
@@ -0,0 +1,178 @@ | |||
1 | #include <sys/time.h> | ||
2 | #include <sys/resource.h> | ||
3 | #include <unistd.h> | ||
4 | #include <syslog.h> | ||
5 | #include <sys/types.h> | ||
6 | #include <sys/wait.h> | ||
7 | #include <stdio.h> | ||
8 | |||
9 | #include <qpe/qpeapplication.h> | ||
10 | #include <qpe/qcopenvelope_qws.h> | ||
11 | |||
12 | #include <opie/odevice.h> | ||
13 | |||
14 | #include <qwindowsystem_qws.h> | ||
15 | #include <qfile.h> | ||
16 | |||
17 | #include "loginwindowimpl.h" | ||
18 | #include "calibrate.h" | ||
19 | |||
20 | int login_main ( int argc, char **argv ); | ||
21 | |||
22 | |||
23 | int main ( int argc, char **argv ) | ||
24 | { | ||
25 | if ( geteuid ( ) != 0 ) { | ||
26 | fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | ||
27 | return 1; | ||
28 | } | ||
29 | |||
30 | //struct rlimit rl; | ||
31 | //getrlimit ( RLIMIT_NOFILE, &rl ); | ||
32 | |||
33 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | ||
34 | // close ( i ); | ||
35 | |||
36 | setpgid ( 0, 0 ); | ||
37 | setsid ( ); | ||
38 | |||
39 | openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); | ||
40 | |||
41 | while ( true ) { | ||
42 | pid_t child = fork ( ); | ||
43 | |||
44 | if ( child < 0 ) { | ||
45 | syslog ( LOG_ERR, "Could not fork process" ); | ||
46 | break; | ||
47 | |||
48 | } | ||
49 | else if ( child > 0 ) { | ||
50 | int status = 0; | ||
51 | |||
52 | while ( waitpid ( child, &status, 0 ) < 0 ) { } | ||
53 | } | ||
54 | else { | ||
55 | exit ( login_main ( argc, argv )); | ||
56 | } | ||
57 | } | ||
58 | closelog ( ); | ||
59 | } | ||
60 | |||
61 | |||
62 | class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter | ||
63 | { | ||
64 | public: | ||
65 | ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" ) | ||
66 | { | ||
67 | bool doinst = false; | ||
68 | |||
69 | m_model = ODevice::inst ( )-> model ( ); | ||
70 | m_power_timer = 0; | ||
71 | |||
72 | switch ( m_model ) { | ||
73 | case OMODEL_iPAQ_H31xx: | ||
74 | case OMODEL_iPAQ_H36xx: | ||
75 | case OMODEL_iPAQ_H37xx: | ||
76 | case OMODEL_iPAQ_H38xx: doinst = true; | ||
77 | break; | ||
78 | default : break; | ||
79 | } | ||
80 | if ( doinst ) | ||
81 | QWSServer::setKeyboardFilter ( this ); | ||
82 | } | ||
83 | |||
84 | virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | ||
85 | { | ||
86 | bool kill = false; | ||
87 | |||
88 | // Rotate cursor keys 180° | ||
89 | switch ( m_model ) { | ||
90 | case OMODEL_iPAQ_H31xx: | ||
91 | case OMODEL_iPAQ_H38xx: { | ||
92 | int newkeycode = keycode; | ||
93 | |||
94 | switch ( keycode ) { | ||
95 | case Key_Left : newkeycode = Key_Right; break; | ||
96 | case Key_Right: newkeycode = Key_Left; break; | ||
97 | case Key_Up : newkeycode = Key_Down; break; | ||
98 | case Key_Down : newkeycode = Key_Up; break; | ||
99 | } | ||
100 | if ( newkeycode != keycode ) { | ||
101 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | ||
102 | kill = true; | ||
103 | } | ||
104 | break; | ||
105 | } | ||
106 | default: break; | ||
107 | } | ||
108 | |||
109 | // map Power Button short/long press to F34/F35 | ||
110 | switch ( m_model ) { | ||
111 | case OMODEL_iPAQ_H31xx: | ||
112 | case OMODEL_iPAQ_H36xx: | ||
113 | case OMODEL_iPAQ_H37xx: | ||
114 | case OMODEL_iPAQ_H38xx: { | ||
115 | if ( keycode == Key_SysReq ) { | ||
116 | if ( isPress ) { | ||
117 | m_power_timer = startTimer ( 500 ); | ||
118 | } | ||
119 | else if ( m_power_timer ) { | ||
120 | killTimer ( m_power_timer ); | ||
121 | m_power_timer = 0; | ||
122 | QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false ); | ||
123 | QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false ); | ||
124 | } | ||
125 | kill = true; | ||
126 | } | ||
127 | break; | ||
128 | } | ||
129 | default: break; | ||
130 | } | ||
131 | return kill; | ||
132 | } | ||
133 | |||
134 | virtual void timerEvent ( QTimerEvent * ) | ||
135 | { | ||
136 | killTimer ( m_power_timer ); | ||
137 | m_power_timer = 0; | ||
138 | QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false ); | ||
139 | QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false ); | ||
140 | } | ||
141 | |||
142 | private: | ||
143 | OModel m_model; | ||
144 | int m_power_timer; | ||
145 | }; | ||
146 | |||
147 | |||
148 | |||
149 | |||
150 | int login_main ( int argc, char **argv ) | ||
151 | { | ||
152 | QWSServer::setDesktopBackground( QImage() ); | ||
153 | QPEApplication app ( argc, argv, QApplication::GuiServer ); | ||
154 | |||
155 | (void) new ModelKeyFilter ( ); | ||
156 | |||
157 | { | ||
158 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | ||
159 | e << -3; // Forced on | ||
160 | } | ||
161 | |||
162 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | ||
163 | if ( !QFile::exists ( "/etc/pointercal" )) { | ||
164 | // Make sure calibration widget starts on top. | ||
165 | Calibrate *cal = new Calibrate; | ||
166 | cal-> exec ( ); | ||
167 | delete cal; | ||
168 | } | ||
169 | #endif | ||
170 | |||
171 | LoginWindowImpl *lw = new LoginWindowImpl ( ); | ||
172 | app. setMainWidget ( lw ); | ||
173 | lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( )); | ||
174 | lw-> show ( ); | ||
175 | |||
176 | return app. exec ( ); | ||
177 | } | ||
178 | |||