1 /* This file is part of the KDE libraries
3 Copyright (c) 2001 Martin R. Jones <mjones@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.
20 #include "kscreensaver.h"
21 #include "kscreensaver_vroot.h"
23 #include <config-workspace.h>
33 #include <QSocketNotifier>
38 #include <kcmdlineargs.h>
39 #include <kapplication.h>
41 #include <kaboutdata.h>
43 #include <QtGui/QX11Info>
45 static void crashHandler( int )
48 signal (SIGABRT
, SIG_DFL
);
55 static int termPipe
[2];
57 static void termHandler( int )
59 write( termPipe
[1], "", 1 );
64 //----------------------------------------------------------------------------
66 class DemoWindow
: public QWidget
69 DemoWindow() : QWidget()
71 setFixedSize(600, 420);
75 virtual bool eventFilter( QObject
*, QEvent
*e
)
77 if (e
->type() == QEvent::KeyPress
) {
78 keyPressEvent( (QKeyEvent
*)e
);
84 virtual void keyPressEvent(QKeyEvent
*e
)
86 if (e
->text() == QLatin1String("q"))
92 virtual void closeEvent( QCloseEvent
* )
99 //----------------------------------------------------------------------------
100 #if defined(Q_WS_QWS) || defined(Q_WS_MACX)
104 int kScreenSaverMain( int argc
, char** argv
, KScreenSaverInterface
& screenSaverInterface
)
106 KLocale::setMainCatalog("libkscreensaver");
107 KCmdLineArgs::init(argc
, argv
, screenSaverInterface
.aboutData());
110 KCmdLineOptions options
;
112 options
.add("setup", ki18n("Setup screen saver"));
114 options
.add("window-id wid", ki18n("Run in the specified XWindow"));
116 options
.add("root", ki18n("Run in the root XWindow"));
118 options
.add("demo", ki18n("Start screen saver in demo mode"), "default");
120 KCmdLineArgs::addCmdLineOptions(options
);
127 sa
.sa_handler
= termHandler
;
128 sigemptyset(&sa
.sa_mask
);
130 sigaction(SIGTERM
, &sa
, 0);
131 QSocketNotifier
*sn
= new QSocketNotifier(termPipe
[0], QSocketNotifier::Read
, &app
);
132 QObject::connect(sn
, SIGNAL(activated(int)), &app
, SLOT(quit()));
135 KCrash::setCrashHandler( crashHandler
);
136 KGlobal::locale()->insertCatalog("klock");
137 KGlobal::locale()->insertCatalog("kscreensaver");
139 DemoWindow
*demoWidget
= 0;
141 KScreenSaver
*target
;
143 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
145 if (args
->isSet("setup"))
147 QDialog
*dlg
= screenSaverInterface
.setup();
154 if (args
->isSet("window-id"))
156 saveWin
= args
->getOption("window-id").toInt();
159 #ifdef Q_WS_X11 //FIXME
160 if (args
->isSet("root"))
163 saveWin
= RootWindow(QX11Info::display(), inf
.screen());
167 if (args
->isSet("demo"))
174 demoWidget
= new DemoWindow();
175 demoWidget
->setAttribute(Qt::WA_NoSystemBackground
);
176 demoWidget
->setAttribute(Qt::WA_PaintOnScreen
);
179 saveWin
= demoWidget
->winId();
182 target
= screenSaverInterface
.create( saveWin
);
187 target
->installEventFilter( demoWidget
);