1 /* This file is part of the KDE project
2 Copyright (C) 1999 David Faure
3 Copyright (c) 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 "krunner_interface.h"
41 bool MyApp::x11EventFilter( XEvent
*ev
)
43 if (ev
->type
== XKeyPress
|| ev
->type
== ButtonPress
)
45 else if (ev
->type
== MotionNotify
) {
46 time_t tick
= time( 0 );
47 if (tick
!= lastTick
) {
52 return KApplication::x11EventFilter( ev
);
56 // -----------------------------------------------------------------------------
58 int main( int argc
, char **argv
)
60 KCmdLineArgs::init( argc
, argv
, "krunner_lock", "krunner", ki18n("KRunner Locker"), "2.0" , ki18n("Session Locker for KRunner"));
62 KCmdLineOptions options
;
63 options
.add("forcelock", ki18n("Force session locking"));
64 options
.add("dontlock", ki18n("Only start screensaver"));
65 options
.add("blank", ki18n("Only use the blank screensaver"));
66 KCmdLineArgs::addCmdLineOptions( options
);
67 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
69 putenv(strdup("SESSION_MANAGER="));
71 //KApplication::disableAutoDcopRegistration();
73 int kdesktop_screen_number
= 0;
74 int starting_screen
= 0;
77 int parent_connection
= 0; // socket to the parent saver
78 QList
<int> child_sockets
;
80 if (KGlobalSettings::isMultiHead())
82 Display
*dpy
= XOpenDisplay(NULL
);
85 "%s: FATAL ERROR: couldn't open display '%s'\n",
86 argv
[0], XDisplayName(NULL
));
90 int number_of_screens
= ScreenCount(dpy
);
91 starting_screen
= kdesktop_screen_number
= DefaultScreen(dpy
);
93 QByteArray display_name
= XDisplayString(dpy
);
95 kDebug() << "screen " << number_of_screens
<< " " << kdesktop_screen_number
<< " " << display_name
<< " " << starting_screen
<< endl
;
98 if ((pos
= display_name
.lastIndexOf('.')) != -1)
99 display_name
.remove(pos
, 10);
102 if (number_of_screens
!= 1) {
103 for (int i
= 0; i
< number_of_screens
; i
++) {
104 if (i
!= starting_screen
) {
112 kdesktop_screen_number
= i
;
113 parent_connection
= fd
[0];
114 // break here because we are the child process, we don't
115 // want to fork() anymore
118 child_sockets
.append(fd
[1]);
123 env
.sprintf("DISPLAY=%s.%d", display_name
.data(),
124 kdesktop_screen_number
);
125 kDebug() << "env " << env
<< endl
;
127 if (putenv(strdup(env
.toLatin1().data()))) {
129 "%s: WARNING: unable to set DISPLAY environment variable\n",
137 kDebug() << "app " << kdesktop_screen_number
<< " " << starting_screen
<< " " << child
<< " " << child_sockets
.count() << " " << parent_connection
<< endl
;
138 app
.disableSessionManagement();
139 KGlobal::locale()->insertCatalog("libworkspace");
141 LockProcess
process(child
, args
->isSet( "blank" ));
143 process
.setChildren(child_sockets
);
145 process
.setParent(parent_connection
);
149 if( !child
&& args
->isSet( "forcelock" ))
154 else if( child
|| args
->isSet( "dontlock" ))
155 rt
= process
.dontLock();
157 rt
= process
.defaultSave();
163 org::freedesktop::ScreenSaver
runner("org.freedesktop.ScreenSaver", "/ScreenSaver", QDBusConnection::sessionBus());
164 runner
.saverLockReady();