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>
40
#include <kapplication.h>
42
#include <kaboutdata.h>
44
#include <QtGui/QX11Info>
46
static void crashHandler( int )
49
signal (SIGABRT, SIG_DFL);
56
static int termPipe[2];
58
static void termHandler( int )
60
write( termPipe[1], "", 1 );
65
//----------------------------------------------------------------------------
67
class DemoWindow : public QWidget
70
DemoWindow() : QWidget()
72
setFixedSize(600, 420);
76
virtual bool eventFilter( QObject *, QEvent *e )
78
if (e->type() == QEvent::KeyPress) {
79
keyPressEvent( (QKeyEvent *)e );
81
} else if( e->type() == QEvent::Close ) {
82
// In demo mode, screensaver's QWidget does create()
83
// with winId of the DemoWidget, which results in two QWidget's
84
// sharing the same winId and Qt delivering events only to one of them.
90
virtual void keyPressEvent(QKeyEvent *e)
92
if (e->text() == QLatin1String("q"))
98
virtual void closeEvent( QCloseEvent * )
105
//----------------------------------------------------------------------------
106
#if defined(Q_WS_QWS) || defined(Q_WS_MACX)
113
static int (*oldXErrorHandler)(Display *, XErrorEvent *);
115
static int xErrorHandler(Display *dpy, XErrorEvent *err)
118
kFatal() << "Got X error after loss of parent process. Terminating.";
119
return oldXErrorHandler(dpy, err);
125
int kScreenSaverMain( int argc, char** argv, KScreenSaverInterface& screenSaverInterface )
127
KLocale::setMainCatalog("libkscreensaver");
128
KCmdLineArgs::init(argc, argv, screenSaverInterface.aboutData());
131
KCmdLineOptions options;
133
options.add("setup", ki18n("Setup screen saver"));
135
options.add("window-id wid", ki18n("Run in the specified XWindow"));
137
options.add("root", ki18n("Run in the root XWindow"));
139
options.add("demo", ki18n("Start screen saver in demo mode"), "default");
141
KCmdLineArgs::addCmdLineOptions(options);
145
// Set a useful default icon.
146
app.setWindowIcon(KIcon("preferences-desktop-screensaver"));
151
sa.sa_handler = termHandler;
152
sigemptyset(&sa.sa_mask);
154
sigaction(SIGTERM, &sa, 0);
155
QSocketNotifier *sn = new QSocketNotifier(termPipe[0], QSocketNotifier::Read, &app);
156
QObject::connect(sn, SIGNAL(activated(int)), &app, SLOT(quit()));
160
oldXErrorHandler = XSetErrorHandler(xErrorHandler);
162
KCrash::setCrashHandler( crashHandler );
163
KGlobal::locale()->insertCatalog("klock");
164
KGlobal::locale()->insertCatalog("kscreensaver");
166
DemoWindow *demoWidget = 0;
168
KScreenSaver *target;
170
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
172
if (args->isSet("setup"))
174
QDialog *dlg = screenSaverInterface.setup();
181
if (args->isSet("window-id"))
183
saveWin = args->getOption("window-id").toInt();
186
#ifdef Q_WS_X11 //FIXME
187
if (args->isSet("root"))
190
saveWin = RootWindow(QX11Info::display(), inf.screen());
194
if (args->isSet("demo"))
201
demoWidget = new DemoWindow();
202
demoWidget->setAttribute(Qt::WA_NoSystemBackground);
203
demoWidget->setAttribute(Qt::WA_PaintOnScreen);
206
saveWin = demoWidget->winId();
209
target = screenSaverInterface.create( saveWin );
210
target->setAttribute(Qt::WA_PaintOnScreen);
215
target->installEventFilter( demoWidget );