1 /* This file is part of the KDE project
2 Copyright (C) 1999 David Faure
3 Copyright 2003 Oswald Buddenhagen <ossi@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "lockprocess.h"
23 #include "kscreensaversettings.h"
25 #include <kcmdlineargs.h>
29 #include <kglobalsettings.h>
30 #include <QtDBus/QtDBus>
31 #include "kscreensaver_interface.h"
42 bool MyApp::x11EventFilter( XEvent
*ev
)
44 if (ev
->type
== XKeyPress
|| ev
->type
== ButtonPress
)
46 else if (ev
->type
== MotionNotify
) {
47 time_t tick
= time( 0 );
48 if (tick
!= lastTick
) {
53 return KApplication::x11EventFilter( ev
);
57 // -----------------------------------------------------------------------------
59 int main( int argc
, char **argv
)
61 KCmdLineArgs::init(argc
, argv
, "kscreenlocker", "krunner", ki18n("KDE Screen Locker"),
62 "2.0" , ki18n("Session Locker for KDE Workspace"));
64 KCmdLineOptions options
;
65 options
.add("forcelock", ki18n("Force session locking"));
66 options
.add("dontlock", ki18n("Only start screen saver"));
67 options
.add("blank", ki18n("Only use the blank screen saver"));
68 options
.add("plasmasetup", ki18n("start with plasma unlocked for configuring"));
69 KCmdLineArgs::addCmdLineOptions( options
);
70 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
72 putenv(strdup("SESSION_MANAGER="));
74 //KApplication::disableAutoDcopRegistration();
76 int kdesktop_screen_number
= 0;
77 int starting_screen
= 0;
80 int parent_connection
= 0; // socket to the parent saver
81 QList
<int> child_sockets
;
83 if (KGlobalSettings::isMultiHead())
85 Display
*dpy
= XOpenDisplay(NULL
);
88 "%s: FATAL ERROR: could not open display '%s'\n",
89 argv
[0], XDisplayName(NULL
));
93 int number_of_screens
= ScreenCount(dpy
);
94 starting_screen
= kdesktop_screen_number
= DefaultScreen(dpy
);
96 QByteArray display_name
= XDisplayString(dpy
);
98 kDebug() << "screen " << number_of_screens
<< " " << kdesktop_screen_number
<< " " << display_name
<< " " << starting_screen
;
101 if ((pos
= display_name
.lastIndexOf('.')) != -1)
102 display_name
.remove(pos
, 10);
105 if (number_of_screens
!= 1) {
106 for (int i
= 0; i
< number_of_screens
; i
++) {
107 if (i
!= starting_screen
) {
115 kdesktop_screen_number
= i
;
116 parent_connection
= fd
[0];
117 // break here because we are the child process, we don't
118 // want to fork() anymore
121 child_sockets
.append(fd
[1]);
126 env
.sprintf("DISPLAY=%s.%d", display_name
.data(),
127 kdesktop_screen_number
);
128 kDebug() << "env " << env
;
130 if (putenv(strdup(env
.toLatin1().data()))) {
132 "%s: WARNING: unable to set DISPLAY environment variable\n",
140 kDebug() << "app " << kdesktop_screen_number
<< " " << starting_screen
<< " " << child
<< " " << child_sockets
.count() << " " << parent_connection
;
141 app
.disableSessionManagement();
142 KGlobal::locale()->insertCatalog("libkworkspace");
144 LockProcess
process(child
, args
->isSet("blank"));
146 process
.setChildren(child_sockets
);
148 process
.setParent(parent_connection
);
152 if (!child
&& (args
->isSet("forcelock"))) {
156 else if( child
|| args
->isSet( "dontlock" ))
157 rt
= process
.dontLock();
158 else if (args
->isSet("plasmasetup")) {
159 rt
= process
.startSetup();
162 rt
= process
.defaultSave();
168 org::kde::screensaver
kscreensaver("org.kde.screensaver", "/ScreenSaver", QDBusConnection::sessionBus());
169 kscreensaver
.saverLockReady();