2000-03-24 22:23:02 +00:00
|
|
|
/*****************************************************************
|
2003-09-16 19:28:03 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2000-03-24 22:23:02 +00:00
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
2003-09-16 19:28:03 +00:00
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
2000-04-20 17:37:33 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
2000-04-20 17:37:33 +00:00
|
|
|
|
2000-07-29 07:59:24 +00:00
|
|
|
//#define QT_CLEAN_NAMESPACE
|
2003-10-14 16:06:54 +00:00
|
|
|
#include <kconfig.h>
|
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
#include "main.h"
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2007-01-02 21:02:22 +00:00
|
|
|
#include <kglobal.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <klocale.h>
|
1999-12-22 17:16:23 +00:00
|
|
|
#include <stdlib.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <kcmdlineargs.h>
|
|
|
|
#include <kaboutdata.h>
|
|
|
|
#include <unistd.h>
|
1999-08-19 23:26:42 +00:00
|
|
|
#include <signal.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <fcntl.h>
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <QX11Info>
|
|
|
|
#include <stdio.h>
|
2006-06-08 13:43:23 +00:00
|
|
|
#include <fixx11h.h>
|
2006-07-02 18:31:00 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2007-01-02 21:02:22 +00:00
|
|
|
#include "ksplash_interface.h"
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
#include "atoms.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "sm.h"
|
2006-07-06 19:02:14 +00:00
|
|
|
#include "utils.h"
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2000-07-30 16:15:17 +00:00
|
|
|
#define INT8 _X11INT8
|
|
|
|
#define INT32 _X11INT32
|
1999-08-19 23:26:42 +00:00
|
|
|
#include <X11/Xproto.h>
|
2000-07-30 16:15:17 +00:00
|
|
|
#undef INT8
|
|
|
|
#undef INT32
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
2001-02-20 01:20:38 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
Options* options;
|
2001-04-20 07:19:03 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
Atoms* atoms;
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
int screen_number = -1;
|
1999-11-28 21:41:15 +00:00
|
|
|
|
2006-02-19 01:33:48 +00:00
|
|
|
static bool initting = false;
|
2000-06-01 23:44:03 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
static
|
|
|
|
int x11ErrorHandler(Display *d, XErrorEvent *e)
|
|
|
|
{
|
1999-08-19 23:26:42 +00:00
|
|
|
char msg[80], req[80], number[80];
|
2006-02-19 01:33:48 +00:00
|
|
|
bool ignore_badwindow = true; //maybe temporary
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
if (initting &&
|
2003-09-16 19:28:03 +00:00
|
|
|
(
|
|
|
|
e->request_code == X_ChangeWindowAttributes
|
|
|
|
|| e->request_code == X_GrabKey
|
|
|
|
)
|
|
|
|
&& (e->error_code == BadAccess))
|
|
|
|
{
|
2005-09-24 12:26:22 +00:00
|
|
|
fputs(i18n("kwin: it looks like there's already a window manager running. kwin not started.\n").toLocal8Bit(), stderr);
|
2003-09-16 19:28:03 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
if (ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor))
|
2003-09-16 19:28:03 +00:00
|
|
|
return 0;
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
XGetErrorText(d, e->error_code, msg, sizeof(msg));
|
|
|
|
sprintf(number, "%d", e->request_code);
|
|
|
|
XGetErrorDatabaseText(d, "XRequest", number, "<unknown>", req, sizeof(req));
|
|
|
|
|
|
|
|
fprintf(stderr, "kwin: %s(0x%lx): %s\n", req, e->resourceid, msg);
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if (initting)
|
|
|
|
{
|
2005-09-24 12:26:22 +00:00
|
|
|
fputs(i18n("kwin: failure during initialization; aborting").toLocal8Bit(), stderr);
|
1999-08-19 23:26:42 +00:00
|
|
|
exit(1);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
return 0;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2000-06-23 16:26:44 +00:00
|
|
|
|
2000-01-12 15:08:42 +00:00
|
|
|
Application::Application( )
|
2003-09-16 19:28:03 +00:00
|
|
|
: KApplication( ), owner( screen_number )
|
|
|
|
{
|
2003-10-14 16:06:54 +00:00
|
|
|
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
2005-11-03 11:49:08 +00:00
|
|
|
KConfig *config = KGlobal::config();
|
|
|
|
if (!config->isImmutable() && args->isSet("lock"))
|
2003-10-14 16:06:54 +00:00
|
|
|
{
|
2005-11-03 11:49:08 +00:00
|
|
|
config->setReadOnly(true);
|
|
|
|
config->reparseConfiguration();
|
2003-10-14 16:06:54 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if (screen_number == -1)
|
2006-07-06 19:02:14 +00:00
|
|
|
screen_number = DefaultScreen(display());
|
2001-02-06 18:32:07 +00:00
|
|
|
|
2003-01-24 15:39:52 +00:00
|
|
|
if( !owner.claim( args->isSet( "replace" ), true ))
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-09-24 12:26:22 +00:00
|
|
|
fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").toLocal8Bit(), stderr);
|
2003-01-24 15:39:52 +00:00
|
|
|
::exit(1);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
connect( &owner, SIGNAL( lostOwnership()), SLOT( lostSelection()));
|
2004-05-31 16:18:34 +00:00
|
|
|
|
|
|
|
// if there was already kwin running, it saved its configuration after loosing the selection -> reread
|
2005-11-03 11:49:08 +00:00
|
|
|
config->reparseConfiguration();
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2006-02-19 01:33:48 +00:00
|
|
|
initting = true; // startup....
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
// install X11 error handler
|
|
|
|
XSetErrorHandler( x11ErrorHandler );
|
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
// check whether another windowmanager is running
|
2006-07-06 19:02:14 +00:00
|
|
|
XSelectInput(display(), rootWindow(), SubstructureRedirectMask );
|
2000-03-22 12:36:07 +00:00
|
|
|
syncX(); // trigger error now
|
2000-01-12 15:08:42 +00:00
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
options = new Options;
|
|
|
|
atoms = new Atoms;
|
2005-01-15 17:07:48 +00:00
|
|
|
|
2001-04-22 06:51:07 +00:00
|
|
|
// create workspace.
|
2006-07-10 18:34:57 +00:00
|
|
|
(void) new Workspace( isSessionRestored() );
|
2000-03-24 22:23:02 +00:00
|
|
|
|
2000-03-22 12:36:07 +00:00
|
|
|
syncX(); // trigger possible errors, there's still a chance to abort
|
2000-03-24 22:23:02 +00:00
|
|
|
|
2006-02-19 01:33:48 +00:00
|
|
|
initting = false; // startup done, we are up and running now.
|
2006-06-08 13:43:23 +00:00
|
|
|
|
2007-01-02 21:02:22 +00:00
|
|
|
org::kde::KSplash ksplash("org.kde.ksplash", "/KSplash", QDBusConnection::sessionBus());
|
|
|
|
ksplash.upAndRunning(QString( "wm started" ));
|
|
|
|
|
2004-09-20 12:35:27 +00:00
|
|
|
XEvent e;
|
|
|
|
e.xclient.type = ClientMessage;
|
2006-07-06 19:02:14 +00:00
|
|
|
e.xclient.message_type = XInternAtom( display(), "_KDE_SPLASH_PROGRESS", False );
|
|
|
|
e.xclient.display = display();
|
|
|
|
e.xclient.window = rootWindow();
|
2004-09-20 12:35:27 +00:00
|
|
|
e.xclient.format = 8;
|
|
|
|
strcpy( e.xclient.data.b, "wm started" );
|
2006-07-06 19:02:14 +00:00
|
|
|
XSendEvent( display(), rootWindow(), False, SubstructureNotifyMask, &e );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
Application::~Application()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
delete Workspace::self();
|
2004-05-24 13:14:31 +00:00
|
|
|
if( owner.ownerWindow() != None ) // if there was no --replace (no new WM)
|
2006-07-06 19:02:14 +00:00
|
|
|
XSetInputFocus( display(), PointerRoot, RevertToPointerRoot, xTime() );
|
2003-09-16 19:28:03 +00:00
|
|
|
delete options;
|
|
|
|
}
|
2000-02-12 00:25:21 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Application::lostSelection()
|
|
|
|
{
|
|
|
|
delete Workspace::self();
|
|
|
|
// remove windowmanager privileges
|
2006-07-06 19:02:14 +00:00
|
|
|
XSelectInput(display(), rootWindow(), PropertyChangeMask );
|
2003-09-16 19:28:03 +00:00
|
|
|
quit();
|
|
|
|
}
|
2002-02-28 22:11:43 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
bool Application::x11EventFilter( XEvent *e )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-02-28 22:11:43 +00:00
|
|
|
if ( Workspace::self()->workspaceEvent( e ) )
|
2006-02-19 01:33:48 +00:00
|
|
|
return true;
|
2003-01-24 15:39:52 +00:00
|
|
|
return KApplication::x11EventFilter( e );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2005-01-15 17:07:48 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
static void sighandler(int)
|
|
|
|
{
|
1999-08-19 23:26:42 +00:00
|
|
|
QApplication::exit();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2000-03-21 20:02:27 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
} // namespace
|
|
|
|
|
2004-08-04 12:39:34 +00:00
|
|
|
static const char version[] = "3.0";
|
2004-06-27 16:18:56 +00:00
|
|
|
static const char description[] = I18N_NOOP( "KDE window manager" );
|
2000-09-07 22:46:24 +00:00
|
|
|
|
2003-01-24 15:39:52 +00:00
|
|
|
static KCmdLineOptions args[] =
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2003-10-26 10:07:54 +00:00
|
|
|
{ "lock", I18N_NOOP("Disable configuration options"), 0 },
|
2004-06-23 11:48:38 +00:00
|
|
|
{ "replace", I18N_NOOP("Replace already-running ICCCM2.0-compliant window manager"), 0 },
|
2003-09-16 19:28:03 +00:00
|
|
|
KCmdLineLastOption
|
|
|
|
};
|
2003-01-24 15:39:52 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
extern "C"
|
2004-11-17 17:56:22 +00:00
|
|
|
KDE_EXPORT int kdemain( int argc, char * argv[] )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2001-02-06 18:32:07 +00:00
|
|
|
bool restored = false;
|
2003-09-16 19:28:03 +00:00
|
|
|
for (int arg = 1; arg < argc; arg++)
|
|
|
|
{
|
|
|
|
if (! qstrcmp(argv[arg], "-session"))
|
|
|
|
{
|
2001-02-06 18:32:07 +00:00
|
|
|
restored = true;
|
|
|
|
break;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2001-02-06 18:32:07 +00:00
|
|
|
}
|
2001-03-28 12:44:31 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if (! restored)
|
|
|
|
{
|
2001-02-06 18:32:07 +00:00
|
|
|
// we only do the multihead fork if we are not restored by the session
|
|
|
|
// manager, since the session manager will register multiple kwins,
|
|
|
|
// one for each screen...
|
2005-07-28 14:59:42 +00:00
|
|
|
QByteArray multiHead = getenv("KDE_MULTIHEAD");
|
2006-03-17 18:18:20 +00:00
|
|
|
if (multiHead.toLower() == "true")
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
Display* dpy = XOpenDisplay( NULL );
|
|
|
|
if ( !dpy )
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n",
|
|
|
|
argv[0], XDisplayName(NULL ) );
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int number_of_screens = ScreenCount( dpy );
|
|
|
|
KWinInternal::screen_number = DefaultScreen( dpy );
|
|
|
|
int pos; // temporarily needed to reconstruct DISPLAY var if multi-head
|
2005-07-28 14:59:42 +00:00
|
|
|
QByteArray display_name = XDisplayString( dpy );
|
2003-09-16 19:28:03 +00:00
|
|
|
XCloseDisplay( dpy );
|
|
|
|
dpy = 0;
|
|
|
|
|
2005-09-24 12:26:22 +00:00
|
|
|
if ((pos = display_name.lastIndexOf('.')) != -1 )
|
2003-09-16 19:28:03 +00:00
|
|
|
display_name.remove(pos,10); // 10 is enough to be sure we removed ".s"
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
QString envir;
|
2003-09-16 19:28:03 +00:00
|
|
|
if (number_of_screens != 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < number_of_screens; i++ )
|
|
|
|
{
|
2001-02-06 18:32:07 +00:00
|
|
|
// if execution doesn't pass by here, then kwin
|
|
|
|
// acts exactly as previously
|
2003-09-16 19:28:03 +00:00
|
|
|
if ( i != KWinInternal::screen_number && fork() == 0 )
|
|
|
|
{
|
|
|
|
KWinInternal::screen_number = i;
|
2001-02-06 18:32:07 +00:00
|
|
|
// break here because we are the child process, we don't
|
|
|
|
// want to fork() anymore
|
2003-09-16 19:28:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-02-06 18:32:07 +00:00
|
|
|
// in the next statement, display_name shouldn't contain a screen
|
|
|
|
// number. If it had it, it was removed at the "pos" check
|
2003-09-16 19:28:03 +00:00
|
|
|
envir.sprintf("DISPLAY=%s.%d", display_name.data(), KWinInternal::screen_number);
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
if (putenv( strdup(envir.toAscii())) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: WARNING: unable to set DISPLAY environment variable\n",
|
|
|
|
argv[0]);
|
|
|
|
perror("putenv()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-11 23:41:07 +00:00
|
|
|
|
2000-03-21 20:02:27 +00:00
|
|
|
KAboutData aboutData( "kwin", I18N_NOOP("KWin"),
|
2003-09-16 19:28:03 +00:00
|
|
|
version, description, KAboutData::License_GPL,
|
2005-08-08 12:03:15 +00:00
|
|
|
I18N_NOOP("(c) 1999-2005, The KDE Developers"));
|
2000-03-21 20:02:27 +00:00
|
|
|
aboutData.addAuthor("Matthias Ettrich",0, "ettrich@kde.org");
|
2002-04-08 12:58:27 +00:00
|
|
|
aboutData.addAuthor("Cristian Tibirna",0, "tibirna@kde.org");
|
2000-03-21 20:02:27 +00:00
|
|
|
aboutData.addAuthor("Daniel M. Duley",0, "mosfet@kde.org");
|
2004-11-15 14:57:37 +00:00
|
|
|
aboutData.addAuthor("Luboš Luňák", I18N_NOOP( "Maintainer" ), "l.lunak@kde.org");
|
2000-01-12 15:08:42 +00:00
|
|
|
|
|
|
|
KCmdLineArgs::init(argc, argv, &aboutData);
|
2003-01-24 15:39:52 +00:00
|
|
|
KCmdLineArgs::addCmdLineOptions( args );
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if (signal(SIGTERM, KWinInternal::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGTERM, SIG_IGN);
|
|
|
|
if (signal(SIGINT, KWinInternal::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
if (signal(SIGHUP, KWinInternal::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGHUP, SIG_IGN);
|
2006-06-08 13:43:23 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning D-BUS TODO
|
|
|
|
// KApplication::disableAutoDcopRegistration();
|
|
|
|
#endif
|
2003-09-16 19:28:03 +00:00
|
|
|
KWinInternal::Application a;
|
2007-01-02 21:02:22 +00:00
|
|
|
KWinInternal::SessionManager weAreIndeed;
|
2003-09-16 19:28:03 +00:00
|
|
|
KWinInternal::SessionSaveDoneHelper helper;
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2006-07-06 19:02:14 +00:00
|
|
|
fcntl(XConnectionNumber(KWinInternal::display()), F_SETFD, 1);
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
QString appname;
|
2003-09-16 19:28:03 +00:00
|
|
|
if (KWinInternal::screen_number == 0)
|
2007-01-02 21:02:22 +00:00
|
|
|
appname = "org.kde.kwin";
|
2001-02-06 18:32:07 +00:00
|
|
|
else
|
2007-01-02 21:02:22 +00:00
|
|
|
appname.sprintf("org.kde.kwin-screen-%d", KWinInternal::screen_number);
|
2001-02-06 18:32:07 +00:00
|
|
|
|
2006-08-21 20:18:49 +00:00
|
|
|
QDBusConnection::sessionBus().interface()->registerService( appname, QDBusConnectionInterface::DontQueueService );
|
2000-02-12 00:25:21 +00:00
|
|
|
|
2000-02-12 00:36:49 +00:00
|
|
|
return a.exec();
|
2003-01-24 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "main.moc"
|