2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-05-13 17:47:20 +00:00
|
|
|
#include "main.h"
|
2013-07-23 04:45:06 +00:00
|
|
|
#include <QTextStream>
|
2007-05-13 17:47:20 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//#define QT_CLEAN_NAMESPACE
|
|
|
|
#include <ksharedconfig.h>
|
|
|
|
|
2013-07-23 04:45:06 +00:00
|
|
|
#include <kdeversion.h>
|
2007-04-30 09:51:12 +00:00
|
|
|
#include <kglobal.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <kcmdlineargs.h>
|
2013-07-23 04:44:15 +00:00
|
|
|
#include <k4aboutdata.h>
|
2007-09-27 14:53:52 +00:00
|
|
|
#include <kcrash.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <QX11Info>
|
|
|
|
#include <stdio.h>
|
2008-02-24 11:41:55 +00:00
|
|
|
#include <kxerrorhandler.h>
|
2008-06-16 08:36:35 +00:00
|
|
|
#include <kdefakes.h>
|
2013-07-23 04:45:06 +00:00
|
|
|
#include <fixx11h.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2010-09-21 14:31:40 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QEvent>
|
2011-07-10 08:48:25 +00:00
|
|
|
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <kdialog.h>
|
2007-09-27 17:06:10 +00:00
|
|
|
#include <kstandarddirs.h>
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <kdebug.h>
|
2009-10-30 08:10:35 +00:00
|
|
|
#include <kde_file.h>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <QLabel>
|
2009-10-30 08:10:35 +00:00
|
|
|
#include <KComboBox>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <QVBoxLayout>
|
2012-12-14 18:41:13 +00:00
|
|
|
#include <KGlobalSettings>
|
2012-03-30 07:54:18 +00:00
|
|
|
|
|
|
|
#include "config-workspace.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif // HAVE_UNISTD_H
|
|
|
|
|
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif // HAVE_MALLOC_H
|
2007-09-27 16:22:29 +00:00
|
|
|
|
2010-06-11 14:26:41 +00:00
|
|
|
#include <ksmserver_interface.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "atoms.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "sm.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "effects.h"
|
2013-04-30 07:15:29 +00:00
|
|
|
#include "workspace.h"
|
2013-01-22 12:17:07 +00:00
|
|
|
#include "xcbutils.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define INT8 _X11INT8
|
|
|
|
#define INT32 _X11INT32
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#undef INT8
|
|
|
|
#undef INT32
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
Options* options;
|
|
|
|
|
|
|
|
Atoms* atoms;
|
|
|
|
|
|
|
|
int screen_number = -1;
|
2011-05-08 18:39:27 +00:00
|
|
|
bool is_multihead = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-02-09 14:51:11 +00:00
|
|
|
bool initting = false;
|
2008-12-18 15:01:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether to run Xlib in synchronous mode and print backtraces for X errors.
|
|
|
|
* Note that you most probably need to configure cmake with "-D__KDE_HAVE_GCC_VISIBILITY=0"
|
|
|
|
* and -rdynamic in CXXFLAGS for kBacktrace() to work.
|
|
|
|
*/
|
2007-11-02 15:01:40 +00:00
|
|
|
static bool kwin_sync = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-04-30 07:15:29 +00:00
|
|
|
//************************************
|
|
|
|
// KWinSelectionOwner
|
|
|
|
//************************************
|
|
|
|
|
|
|
|
KWinSelectionOwner::KWinSelectionOwner(int screen_P)
|
|
|
|
: KSelectionOwner(make_selection_atom(screen_P), screen_P)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Atom KWinSelectionOwner::make_selection_atom(int screen_P)
|
|
|
|
{
|
|
|
|
if (screen_P < 0)
|
|
|
|
screen_P = DefaultScreen(display());
|
|
|
|
char tmp[ 30 ];
|
|
|
|
sprintf(tmp, "WM_S%d", screen_P);
|
|
|
|
return XInternAtom(display(), tmp, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinSelectionOwner::getAtoms()
|
|
|
|
{
|
|
|
|
KSelectionOwner::getAtoms();
|
|
|
|
if (xa_version == None) {
|
|
|
|
Atom atoms[ 1 ];
|
|
|
|
const char* const names[] =
|
|
|
|
{ "VERSION" };
|
|
|
|
XInternAtoms(display(), const_cast< char** >(names), 1, False, atoms);
|
|
|
|
xa_version = atoms[ 0 ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 04:43:09 +00:00
|
|
|
void KWinSelectionOwner::replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P)
|
2013-04-30 07:15:29 +00:00
|
|
|
{
|
|
|
|
KSelectionOwner::replyTargets(property_P, requestor_P);
|
|
|
|
Atom atoms[ 1 ] = { xa_version };
|
|
|
|
// PropModeAppend !
|
|
|
|
XChangeProperty(display(), requestor_P, property_P, XA_ATOM, 32, PropModeAppend,
|
|
|
|
reinterpret_cast< unsigned char* >(atoms), 1);
|
|
|
|
}
|
|
|
|
|
2013-07-23 04:43:09 +00:00
|
|
|
bool KWinSelectionOwner::genericReply(xcb_atom_t target_P, xcb_atom_t property_P, xcb_window_t requestor_P)
|
2013-04-30 07:15:29 +00:00
|
|
|
{
|
|
|
|
if (target_P == xa_version) {
|
|
|
|
long version[] = { 2, 0 };
|
|
|
|
XChangeProperty(display(), requestor_P, property_P, XA_INTEGER, 32,
|
|
|
|
PropModeReplace, reinterpret_cast< unsigned char* >(&version), 2);
|
|
|
|
} else
|
|
|
|
return KSelectionOwner::genericReply(target_P, property_P, requestor_P);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Atom KWinSelectionOwner::xa_version = None;
|
|
|
|
|
2007-09-27 16:22:29 +00:00
|
|
|
class AlternativeWMDialog : public KDialog
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
|
|
|
AlternativeWMDialog()
|
|
|
|
: KDialog() {
|
|
|
|
setButtons(KDialog::Ok | KDialog::Cancel);
|
|
|
|
|
|
|
|
QWidget* mainWidget = new QWidget(this);
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(mainWidget);
|
|
|
|
QString text = i18n(
|
|
|
|
"KWin is unstable.\n"
|
|
|
|
"It seems to have crashed several times in a row.\n"
|
|
|
|
"You can select another window manager to run:");
|
|
|
|
QLabel* textLabel = new QLabel(text, mainWidget);
|
|
|
|
layout->addWidget(textLabel);
|
|
|
|
wmList = new KComboBox(mainWidget);
|
|
|
|
wmList->setEditable(true);
|
|
|
|
layout->addWidget(wmList);
|
|
|
|
|
2013-07-23 05:02:52 +00:00
|
|
|
addWM(QStringLiteral("metacity"));
|
|
|
|
addWM(QStringLiteral("openbox"));
|
|
|
|
addWM(QStringLiteral("fvwm2"));
|
|
|
|
addWM(QStringLiteral(KWIN_NAME));
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
setMainWidget(mainWidget);
|
|
|
|
|
|
|
|
raise();
|
|
|
|
centerOnScreen(this);
|
|
|
|
}
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void addWM(const QString& wm) {
|
|
|
|
// TODO: Check if WM is installed
|
|
|
|
if (!KStandardDirs::findExe(wm).isEmpty())
|
|
|
|
wmList->addItem(wm);
|
|
|
|
}
|
|
|
|
QString selectedWM() const {
|
|
|
|
return wmList->currentText();
|
|
|
|
}
|
2007-09-27 16:22:29 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
|
|
|
KComboBox* wmList;
|
2007-09-27 16:22:29 +00:00
|
|
|
};
|
|
|
|
|
2007-09-27 14:53:52 +00:00
|
|
|
int Application::crashes = 0;
|
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
Application::Application()
|
|
|
|
: KApplication()
|
2011-01-30 14:34:42 +00:00
|
|
|
, owner(screen_number)
|
2013-07-26 05:52:56 +00:00
|
|
|
, m_eventFilter(new XcbEventFilter())
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (KCmdLineArgs::parsedArgs("qt")->isSet("sync")) {
|
2008-12-18 15:01:25 +00:00
|
|
|
kwin_sync = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
XSynchronize(display(), True);
|
|
|
|
kDebug(1212) << "Running KWin in sync mode";
|
|
|
|
}
|
|
|
|
setQuitOnLastWindowClosed(false);
|
2007-04-29 17:35:43 +00:00
|
|
|
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
|
|
|
KSharedConfig::Ptr config = KGlobal::config();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!config->isImmutable() && args->isSet("lock")) {
|
2009-10-05 06:59:10 +00:00
|
|
|
// TODO: This shouldn't be necessary
|
2008-12-18 15:01:25 +00:00
|
|
|
//config->setReadOnly( true );
|
2007-04-29 17:35:43 +00:00
|
|
|
config->reparseConfiguration();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (screen_number == -1)
|
2013-07-31 05:24:13 +00:00
|
|
|
screen_number = QX11Info::appScreen();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-23 05:27:40 +00:00
|
|
|
connect(&owner, &KSelectionOwner::failedToClaimOwnership, []{
|
2013-07-23 05:02:52 +00:00
|
|
|
fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").toLocal8Bit().constData(), stderr);
|
2011-01-30 14:34:42 +00:00
|
|
|
::exit(1);
|
2013-07-23 05:27:40 +00:00
|
|
|
});
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(&owner, SIGNAL(lostOwnership()), SLOT(lostSelection()));
|
2013-07-31 05:24:13 +00:00
|
|
|
connect(&owner, &KSelectionOwner::claimedOwnership, [this, args, config]{
|
|
|
|
KCrash::setEmergencySaveFunction(Application::crashHandler);
|
|
|
|
crashes = args->getOption("crashes").toInt();
|
|
|
|
if (crashes >= 4) {
|
|
|
|
// Something has gone seriously wrong
|
|
|
|
AlternativeWMDialog dialog;
|
|
|
|
QString cmd = QStringLiteral(KWIN_NAME);
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
cmd = dialog.selectedWM();
|
|
|
|
else
|
|
|
|
::exit(1);
|
|
|
|
if (cmd.length() > 500) {
|
|
|
|
kDebug(1212) << "Command is too long, truncating";
|
|
|
|
cmd = cmd.left(500);
|
|
|
|
}
|
|
|
|
kDebug(1212) << "Starting" << cmd << "and exiting";
|
|
|
|
char buf[1024];
|
|
|
|
sprintf(buf, "%s &", cmd.toAscii().data());
|
|
|
|
system(buf);
|
2011-01-30 14:34:42 +00:00
|
|
|
::exit(1);
|
2008-12-18 15:01:25 +00:00
|
|
|
}
|
2013-07-31 05:24:13 +00:00
|
|
|
if (crashes >= 2) {
|
|
|
|
// Disable compositing if we have had too many crashes
|
|
|
|
kDebug(1212) << "Too many crashes recently, disabling compositing";
|
|
|
|
KConfigGroup compgroup(config, "Compositing");
|
|
|
|
compgroup.writeEntry("Enabled", false);
|
|
|
|
}
|
|
|
|
// Reset crashes count if we stay up for more that 15 seconds
|
|
|
|
QTimer::singleShot(15 * 1000, this, SLOT(resetCrashesCount()));
|
2007-09-27 14:53:52 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
initting = true; // Startup...
|
|
|
|
installNativeEventFilter(m_eventFilter.data());
|
|
|
|
// first load options - done internally by a different thread
|
|
|
|
options = new Options;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
// Check whether another windowmanager is running
|
|
|
|
XSelectInput(display(), rootWindow(), SubstructureRedirectMask);
|
2013-07-31 05:27:12 +00:00
|
|
|
Xcb::sync(); // Trigger error now
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
atoms = new Atoms;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
// initting = false; // TODO
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
// This tries to detect compositing options and can use GLX. GLX problems
|
|
|
|
// (X errors) shouldn't cause kwin to abort, so this is out of the
|
|
|
|
// critical startup section where x errors cause kwin to abort.
|
2007-10-03 15:25:38 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
// create workspace.
|
|
|
|
(void) new Workspace(isSessionRestored());
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:27:12 +00:00
|
|
|
Xcb::sync(); // Trigger possible errors, there's still a chance to abort
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
initting = false; // Startup done, we are up and running now.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
XEvent e;
|
|
|
|
e.xclient.type = ClientMessage;
|
|
|
|
e.xclient.message_type = XInternAtom(display(), "_KDE_SPLASH_PROGRESS", False);
|
|
|
|
e.xclient.display = display();
|
|
|
|
e.xclient.window = rootWindow();
|
|
|
|
e.xclient.format = 8;
|
|
|
|
strcpy(e.xclient.data.b, "wm");
|
|
|
|
XSendEvent(display(), rootWindow(), False, SubstructureNotifyMask, &e);
|
|
|
|
});
|
|
|
|
owner.claim(args->isSet("replace"), true);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Application::~Application()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
delete Workspace::self();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (owner.ownerWindow() != None) // If there was no --replace (no new WM)
|
|
|
|
XSetInputFocus(display(), PointerRoot, RevertToPointerRoot, xTime());
|
2007-04-29 17:35:43 +00:00
|
|
|
delete options;
|
|
|
|
delete effects;
|
|
|
|
delete atoms;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Application::lostSelection()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-05-09 16:10:49 +00:00
|
|
|
sendPostedEvents();
|
2007-04-29 17:35:43 +00:00
|
|
|
delete Workspace::self();
|
2008-12-18 15:01:25 +00:00
|
|
|
// Remove windowmanager privileges
|
2011-01-30 14:34:42 +00:00
|
|
|
XSelectInput(display(), rootWindow(), PropertyChangeMask);
|
2007-04-29 17:35:43 +00:00
|
|
|
quit();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Application::notify(QObject* o, QEvent* e)
|
|
|
|
{
|
|
|
|
if (Workspace::self()->workspaceEvent(e))
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
return KApplication::notify(o, e);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static void sighandler(int)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
QApplication::exit();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Application::crashHandler(int signal)
|
|
|
|
{
|
2007-09-27 14:53:52 +00:00
|
|
|
crashes++;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
fprintf(stderr, "Application::crashHandler() called with signal %d; recent crashes: %d\n", signal, crashes);
|
2007-09-27 14:53:52 +00:00
|
|
|
char cmd[1024];
|
2011-01-30 14:34:42 +00:00
|
|
|
sprintf(cmd, "%s --crashes %d &",
|
|
|
|
QFile::encodeName(QCoreApplication::applicationFilePath()).constData(), crashes);
|
2007-09-27 14:53:52 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
sleep(1);
|
|
|
|
system(cmd);
|
|
|
|
}
|
2007-09-27 14:53:52 +00:00
|
|
|
|
|
|
|
void Application::resetCrashesCount()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-09-27 14:53:52 +00:00
|
|
|
crashes = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-09-27 14:53:52 +00:00
|
|
|
|
2013-07-26 05:52:56 +00:00
|
|
|
bool XcbEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long int *result)
|
|
|
|
{
|
|
|
|
Q_UNUSED(result)
|
|
|
|
if (!Workspace::self()) {
|
|
|
|
// Workspace not yet created
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (eventType != "xcb_generic_event_t") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Workspace::self()->workspaceEvent(static_cast<xcb_generic_event_t *>(message));
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
2008-07-28 13:46:16 +00:00
|
|
|
static const char version[] = KDE_VERSION_STRING;
|
2011-01-30 14:34:42 +00:00
|
|
|
static const char description[] = I18N_NOOP("KDE window manager");
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
extern "C"
|
2011-01-30 14:34:42 +00:00
|
|
|
KDE_EXPORT int kdemain(int argc, char * argv[])
|
|
|
|
{
|
2012-03-30 07:54:18 +00:00
|
|
|
#ifdef M_TRIM_THRESHOLD
|
|
|
|
// Prevent fragmentation of the heap by malloc (glibc).
|
|
|
|
//
|
|
|
|
// The default threshold is 128*1024, which can result in a large memory usage
|
|
|
|
// due to fragmentation especially if we use the raster graphicssystem. On the
|
|
|
|
// otherside if the threshold is too low, free() starts to permanently ask the kernel
|
|
|
|
// about shrinking the heap.
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
const int pagesize = sysconf(_SC_PAGESIZE);
|
|
|
|
#else
|
|
|
|
const int pagesize = 4*1024;
|
|
|
|
#endif // HAVE_UNISTD_H
|
|
|
|
mallopt(M_TRIM_THRESHOLD, 5*pagesize);
|
|
|
|
#endif // M_TRIM_THRESHOLD
|
2011-05-21 12:32:30 +00:00
|
|
|
|
2011-05-08 18:39:27 +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);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-05-08 18:39:27 +00:00
|
|
|
int number_of_screens = ScreenCount(dpy);
|
|
|
|
|
|
|
|
// multi head
|
2012-12-14 18:41:13 +00:00
|
|
|
if (number_of_screens != 1 && KGlobalSettings::isMultiHead()) {
|
2011-05-08 18:39:27 +00:00
|
|
|
KWin::is_multihead = true;
|
|
|
|
KWin::screen_number = DefaultScreen(dpy);
|
|
|
|
int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head
|
|
|
|
QByteArray display_name = XDisplayString(dpy);
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
dpy = 0;
|
|
|
|
|
|
|
|
if ((pos = display_name.lastIndexOf('.')) != -1)
|
|
|
|
display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s"
|
|
|
|
|
|
|
|
QString envir;
|
|
|
|
for (int i = 0; i < number_of_screens; i++) {
|
|
|
|
// If execution doesn't pass by here, then kwin
|
|
|
|
// acts exactly as previously
|
|
|
|
if (i != KWin::screen_number && fork() == 0) {
|
|
|
|
KWin::screen_number = i;
|
|
|
|
// Break here because we are the child process, we don't
|
|
|
|
// want to fork() anymore
|
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-08 18:39:27 +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
|
|
|
|
envir.sprintf("DISPLAY=%s.%d", display_name.data(), KWin::screen_number);
|
|
|
|
|
2013-07-23 04:44:15 +00:00
|
|
|
if (putenv(strdup(envir.toAscii().constData()))) {
|
2011-05-08 18:39:27 +00:00
|
|
|
fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]);
|
|
|
|
perror("putenv()");
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-07-23 04:44:15 +00:00
|
|
|
K4AboutData aboutData(
|
|
|
|
QByteArray(KWIN_NAME), // The program name used internally
|
|
|
|
QByteArray(), // The message catalog name. If null, program name is used instead
|
2011-01-30 14:34:42 +00:00
|
|
|
ki18n("KWin"), // A displayable program name string
|
2013-07-23 04:44:15 +00:00
|
|
|
QByteArray(version), // The program version string
|
2011-01-30 14:34:42 +00:00
|
|
|
ki18n(description), // Short description of what the app does
|
2013-07-23 04:44:15 +00:00
|
|
|
K4AboutData::License_GPL, // The license this code is released under
|
2011-01-30 14:34:42 +00:00
|
|
|
ki18n("(c) 1999-2008, The KDE Developers")); // Copyright Statement
|
|
|
|
aboutData.addAuthor(ki18n("Matthias Ettrich"), KLocalizedString(), "ettrich@kde.org");
|
|
|
|
aboutData.addAuthor(ki18n("Cristian Tibirna"), KLocalizedString(), "tibirna@kde.org");
|
|
|
|
aboutData.addAuthor(ki18n("Daniel M. Duley"), KLocalizedString(), "mosfet@kde.org");
|
|
|
|
aboutData.addAuthor(ki18n("Luboš Luňák"), KLocalizedString(), "l.lunak@kde.org");
|
2013-03-12 12:17:53 +00:00
|
|
|
aboutData.addAuthor(ki18n("Martin Gräßlin"), ki18n("Maintainer"), "mgraesslin@kde.org");
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KCmdLineArgs::init(argc, argv, &aboutData);
|
2007-07-02 08:49:20 +00:00
|
|
|
|
|
|
|
KCmdLineOptions args;
|
2011-01-30 14:34:42 +00:00
|
|
|
args.add("lock", ki18n("Disable configuration options"));
|
|
|
|
args.add("replace", ki18n("Replace already-running ICCCM2.0-compliant window manager"));
|
|
|
|
args.add("crashes <n>", ki18n("Indicate that KWin has recently crashed n times"));
|
|
|
|
KCmdLineArgs::addCmdLineOptions(args);
|
|
|
|
|
|
|
|
if (KDE_signal(SIGTERM, KWin::sighandler) == SIG_IGN)
|
|
|
|
KDE_signal(SIGTERM, SIG_IGN);
|
|
|
|
if (KDE_signal(SIGINT, KWin::sighandler) == SIG_IGN)
|
|
|
|
KDE_signal(SIGINT, SIG_IGN);
|
|
|
|
if (KDE_signal(SIGHUP, KWin::sighandler) == SIG_IGN)
|
|
|
|
KDE_signal(SIGHUP, SIG_IGN);
|
2008-12-18 15:01:25 +00:00
|
|
|
|
2010-06-13 20:22:50 +00:00
|
|
|
// Disable the glib event loop integration, since it seems to be responsible
|
|
|
|
// for several bug reports about high CPU usage (bug #239963)
|
2011-01-30 14:34:42 +00:00
|
|
|
setenv("QT_NO_GLIB", "1", true);
|
2010-06-13 20:22:50 +00:00
|
|
|
|
2013-07-23 05:02:52 +00:00
|
|
|
org::kde::KSMServerInterface ksmserver(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QDBusConnection::sessionBus());
|
|
|
|
ksmserver.suspendStartup(QStringLiteral(KWIN_NAME));
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::Application a;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-07-23 05:02:52 +00:00
|
|
|
ksmserver.resumeStartup(QStringLiteral(KWIN_NAME));
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::SessionManager weAreIndeed;
|
|
|
|
KWin::SessionSaveDoneHelper helper;
|
2013-07-22 14:18:47 +00:00
|
|
|
#warning insertCatalog needs porting
|
|
|
|
#if KWIN_QT5_PORTING
|
2011-01-30 14:34:42 +00:00
|
|
|
KGlobal::locale()->insertCatalog("kwin_effects");
|
2013-02-28 08:52:00 +00:00
|
|
|
KGlobal::locale()->insertCatalog("kwin_scripts");
|
|
|
|
KGlobal::locale()->insertCatalog("kwin_scripting");
|
2013-07-22 14:18:47 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-02-10 02:53:33 +00:00
|
|
|
// Announce when KWIN_DIRECT_GL is set for above HACK
|
2011-01-30 14:34:42 +00:00
|
|
|
if (qstrcmp(qgetenv("KWIN_DIRECT_GL"), "1") == 0)
|
|
|
|
kDebug(1212) << "KWIN_DIRECT_GL set, not forcing LIBGL_ALWAYS_INDIRECT=1";
|
2010-02-10 02:53:33 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
fcntl(XConnectionNumber(KWin::display()), F_SETFD, 1);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QString appname;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (KWin::screen_number == 0)
|
2013-07-23 05:02:52 +00:00
|
|
|
appname = QStringLiteral("org.kde.kwin");
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
appname.sprintf("org.kde.kwin-screen-%d", KWin::screen_number);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-12-18 15:01:25 +00:00
|
|
|
QDBusConnection::sessionBus().interface()->registerService(
|
2011-01-30 14:34:42 +00:00
|
|
|
appname, QDBusConnectionInterface::DontQueueService);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-09-21 14:31:40 +00:00
|
|
|
KCmdLineArgs* sargs = KCmdLineArgs::parsedArgs();
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
return a.exec();
|
2010-05-31 21:24:40 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "main.moc"
|