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"
|
2014-03-18 08:30:40 +00:00
|
|
|
#include <config-kwin.h>
|
2013-08-15 11:17:29 +00:00
|
|
|
// kwin
|
|
|
|
#include "atoms.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "sm.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "xcbutils.h"
|
|
|
|
|
|
|
|
// KDE
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KAboutData>
|
|
|
|
#include <KConfig>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KCrash>
|
|
|
|
#include <KLocalizedString>
|
2014-03-18 13:37:01 +00:00
|
|
|
#include <KSharedConfig>
|
2013-08-15 11:17:29 +00:00
|
|
|
// Qt
|
2013-08-28 12:10:51 +00:00
|
|
|
#include <qplatformdefs.h>
|
2013-09-02 11:14:39 +00:00
|
|
|
#include <QDebug>
|
2013-08-15 10:52:37 +00:00
|
|
|
#include <QComboBox>
|
2013-08-29 14:22:30 +00:00
|
|
|
#include <qcommandlineparser.h>
|
2013-08-15 10:52:37 +00:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <QLabel>
|
2013-08-15 10:52:37 +00:00
|
|
|
#include <QPushButton>
|
2013-10-25 11:00:50 +00:00
|
|
|
#include <QQuickWindow>
|
2013-08-15 11:17:29 +00:00
|
|
|
#include <QStandardPaths>
|
2007-09-27 16:22:29 +00:00
|
|
|
#include <QVBoxLayout>
|
2013-08-15 11:17:29 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
|
|
|
#include <QX11Info>
|
2013-09-10 11:18:55 +00:00
|
|
|
// TODO: remove once QX11Info provides the X screen
|
|
|
|
#include <X11/Xlib.h>
|
2012-03-30 07:54:18 +00:00
|
|
|
|
2013-08-15 11:17:29 +00:00
|
|
|
// system
|
2012-03-30 07:54:18 +00:00
|
|
|
#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
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
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
|
|
|
|
2013-04-30 07:15:29 +00:00
|
|
|
//************************************
|
|
|
|
// KWinSelectionOwner
|
|
|
|
//************************************
|
|
|
|
|
|
|
|
KWinSelectionOwner::KWinSelectionOwner(int screen_P)
|
|
|
|
: KSelectionOwner(make_selection_atom(screen_P), screen_P)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-28 11:52:21 +00:00
|
|
|
xcb_atom_t KWinSelectionOwner::make_selection_atom(int screen_P)
|
2013-04-30 07:15:29 +00:00
|
|
|
{
|
|
|
|
if (screen_P < 0)
|
2014-04-25 09:37:09 +00:00
|
|
|
screen_P = QX11Info::appScreen();
|
2013-08-28 13:50:46 +00:00
|
|
|
QByteArray screen(QByteArrayLiteral("WM_S"));
|
|
|
|
screen.append(QByteArray::number(screen_P));
|
|
|
|
ScopedCPointer<xcb_intern_atom_reply_t> atom(xcb_intern_atom_reply(
|
|
|
|
connection(),
|
|
|
|
xcb_intern_atom_unchecked(connection(), false, screen.length(), screen.constData()),
|
|
|
|
nullptr));
|
|
|
|
if (atom.isNull()) {
|
|
|
|
return XCB_ATOM_NONE;
|
|
|
|
}
|
|
|
|
return atom->atom;
|
2013-04-30 07:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinSelectionOwner::getAtoms()
|
|
|
|
{
|
|
|
|
KSelectionOwner::getAtoms();
|
2013-08-28 13:50:46 +00:00
|
|
|
if (xa_version == XCB_ATOM_NONE) {
|
|
|
|
const QByteArray name(QByteArrayLiteral("VERSION"));
|
|
|
|
ScopedCPointer<xcb_intern_atom_reply_t> atom(xcb_intern_atom_reply(
|
|
|
|
connection(),
|
|
|
|
xcb_intern_atom_unchecked(connection(), false, name.length(), name.constData()),
|
|
|
|
nullptr));
|
|
|
|
if (!atom.isNull()) {
|
|
|
|
xa_version = atom->atom;
|
|
|
|
}
|
2013-04-30 07:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2013-08-28 13:50:46 +00:00
|
|
|
xcb_atom_t atoms[ 1 ] = { xa_version };
|
2013-04-30 07:15:29 +00:00
|
|
|
// PropModeAppend !
|
2013-08-28 13:50:46 +00:00
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_APPEND, requestor_P,
|
|
|
|
property_P, XCB_ATOM_ATOM, 32, 1, atoms);
|
2013-04-30 07:15:29 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-08-28 13:50:46 +00:00
|
|
|
int32_t version[] = { 2, 0 };
|
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, requestor_P,
|
|
|
|
property_P, XCB_ATOM_INTEGER, 32, 2, version);
|
2013-04-30 07:15:29 +00:00
|
|
|
} else
|
|
|
|
return KSelectionOwner::genericReply(target_P, property_P, requestor_P);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-28 11:52:21 +00:00
|
|
|
xcb_atom_t KWinSelectionOwner::xa_version = XCB_ATOM_NONE;
|
2013-04-30 07:15:29 +00:00
|
|
|
|
2013-08-15 10:52:37 +00:00
|
|
|
class AlternativeWMDialog : public QDialog
|
2007-09-27 16:22:29 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
|
|
|
AlternativeWMDialog()
|
2013-08-15 10:52:37 +00:00
|
|
|
: QDialog() {
|
2011-01-30 14:34:42 +00:00
|
|
|
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);
|
2013-08-15 10:52:37 +00:00
|
|
|
wmList = new QComboBox(mainWidget);
|
2011-01-30 14:34:42 +00:00
|
|
|
wmList->setEditable(true);
|
|
|
|
layout->addWidget(wmList);
|
|
|
|
|
2013-07-23 05:02:52 +00:00
|
|
|
addWM(QStringLiteral("metacity"));
|
|
|
|
addWM(QStringLiteral("openbox"));
|
|
|
|
addWM(QStringLiteral("fvwm2"));
|
2014-06-10 10:05:54 +00:00
|
|
|
addWM(QStringLiteral(KWIN_INTERNAL_NAME_X11));
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-08-15 10:52:37 +00:00
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
|
|
|
mainLayout->addWidget(mainWidget);
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
|
|
|
buttons->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
mainLayout->addWidget(buttons);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
raise();
|
|
|
|
}
|
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
|
2013-08-03 20:30:42 +00:00
|
|
|
if (!QStandardPaths::findExecutable(wm).isEmpty())
|
2011-01-30 14:34:42 +00:00
|
|
|
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:
|
2013-08-15 10:52:37 +00:00
|
|
|
QComboBox* wmList;
|
2007-09-27 16:22:29 +00:00
|
|
|
};
|
|
|
|
|
2007-09-27 14:53:52 +00:00
|
|
|
int Application::crashes = 0;
|
|
|
|
|
2013-08-28 12:10:51 +00:00
|
|
|
Application::Application(int &argc, char **argv)
|
|
|
|
: QApplication(argc, argv)
|
2014-03-09 11:37:21 +00:00
|
|
|
, owner()
|
2013-07-26 05:52:56 +00:00
|
|
|
, m_eventFilter(new XcbEventFilter())
|
2013-08-28 12:10:51 +00:00
|
|
|
, m_replace(false)
|
|
|
|
, m_configLock(false)
|
2014-01-09 16:39:47 +00:00
|
|
|
, m_operationMode(OperationModeX11)
|
2013-08-28 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setConfigLock(bool lock)
|
|
|
|
{
|
|
|
|
m_configLock = lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setReplace(bool replace)
|
|
|
|
{
|
|
|
|
m_replace = replace;
|
|
|
|
}
|
|
|
|
|
2013-06-25 06:52:08 +00:00
|
|
|
Application::OperationMode Application::operationMode() const
|
|
|
|
{
|
|
|
|
return m_operationMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setOperationMode(OperationMode mode)
|
|
|
|
{
|
|
|
|
m_operationMode = mode;
|
|
|
|
}
|
|
|
|
|
2013-06-25 07:53:45 +00:00
|
|
|
bool Application::shouldUseWaylandForCompositing() const
|
|
|
|
{
|
|
|
|
return m_operationMode == OperationModeWaylandAndX11;
|
|
|
|
}
|
|
|
|
|
2013-06-25 08:39:13 +00:00
|
|
|
bool Application::requiresCompositing() const
|
|
|
|
{
|
|
|
|
return shouldUseWaylandForCompositing();
|
|
|
|
}
|
|
|
|
|
2013-08-28 12:10:51 +00:00
|
|
|
void Application::start()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
setQuitOnLastWindowClosed(false);
|
2013-08-28 12:10:51 +00:00
|
|
|
|
2013-09-04 14:10:36 +00:00
|
|
|
KSharedConfig::Ptr config = KSharedConfig::openConfig();
|
2013-08-28 12:10:51 +00:00
|
|
|
if (!config->isImmutable() && m_configLock) {
|
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
|
|
|
|
2014-03-09 11:37:21 +00:00
|
|
|
owner.reset(new KWinSelectionOwner(screen_number));
|
|
|
|
connect(owner.data(), &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
|
|
|
});
|
2014-03-09 11:37:21 +00:00
|
|
|
connect(owner.data(), SIGNAL(lostOwnership()), SLOT(lostSelection()));
|
|
|
|
connect(owner.data(), &KSelectionOwner::claimedOwnership, [this]{
|
2013-10-25 11:00:50 +00:00
|
|
|
// we want all QQuickWindows with an alpha buffer
|
|
|
|
QQuickWindow::setDefaultAlphaBuffer(true);
|
|
|
|
|
2013-07-31 05:24:13 +00:00
|
|
|
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
|
2013-08-19 08:52:22 +00:00
|
|
|
const uint32_t maskValues[] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT};
|
|
|
|
ScopedCPointer<xcb_generic_error_t> redirectCheck(xcb_request_check(connection(),
|
|
|
|
xcb_change_window_attributes_checked(connection(),
|
|
|
|
rootWindow(),
|
|
|
|
XCB_CW_EVENT_MASK,
|
|
|
|
maskValues)));
|
|
|
|
if (!redirectCheck.isNull()) {
|
|
|
|
fputs(i18n("kwin: another window manager is running (try using --replace)\n").toLocal8Bit().constData(), stderr);
|
|
|
|
::exit(1);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-09-10 11:18:55 +00:00
|
|
|
atoms->retrieveHelpers();
|
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-11-04 10:14:20 +00:00
|
|
|
// Tell KSplash that KWin has started
|
|
|
|
QDBusMessage ksplashProgressMessage = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KSplash"),
|
|
|
|
QStringLiteral("/KSplash"),
|
|
|
|
QStringLiteral("org.kde.KSplash"),
|
|
|
|
QStringLiteral("setStage"));
|
|
|
|
ksplashProgressMessage.setArguments(QList<QVariant>() << QStringLiteral("wm"));
|
|
|
|
QDBusConnection::sessionBus().asyncCall(ksplashProgressMessage);
|
2013-07-31 05:24:13 +00:00
|
|
|
});
|
2013-11-13 09:23:45 +00:00
|
|
|
crashChecking();
|
2013-08-02 06:29:15 +00:00
|
|
|
// we need to do an XSync here, otherwise the QPA might crash us later on
|
|
|
|
Xcb::sync();
|
2014-03-09 11:37:21 +00:00
|
|
|
owner->claim(m_replace, true);
|
2013-09-10 10:26:18 +00:00
|
|
|
|
2013-09-10 11:18:55 +00:00
|
|
|
atoms = new Atoms;
|
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();
|
2014-03-09 11:37:21 +00:00
|
|
|
if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) // If there was no --replace (no new WM)
|
2013-08-29 08:41:45 +00:00
|
|
|
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
|
2007-04-29 17:35:43 +00:00
|
|
|
delete options;
|
|
|
|
delete atoms;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-09-10 10:26:18 +00:00
|
|
|
void Application::crashChecking()
|
|
|
|
{
|
|
|
|
KCrash::setEmergencySaveFunction(Application::crashHandler);
|
|
|
|
if (crashes >= 4) {
|
|
|
|
// Something has gone seriously wrong
|
|
|
|
AlternativeWMDialog dialog;
|
2014-06-10 10:05:54 +00:00
|
|
|
QString cmd = QStringLiteral(KWIN_INTERNAL_NAME_X11);
|
2013-09-10 10:26:18 +00:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
cmd = dialog.selectedWM();
|
|
|
|
else
|
|
|
|
::exit(1);
|
|
|
|
if (cmd.length() > 500) {
|
|
|
|
qDebug() << "Command is too long, truncating";
|
|
|
|
cmd = cmd.left(500);
|
|
|
|
}
|
|
|
|
qDebug() << "Starting" << cmd << "and exiting";
|
|
|
|
char buf[1024];
|
|
|
|
sprintf(buf, "%s &", cmd.toAscii().data());
|
|
|
|
system(buf);
|
|
|
|
::exit(1);
|
|
|
|
}
|
|
|
|
if (crashes >= 2) {
|
|
|
|
// Disable compositing if we have had too many crashes
|
|
|
|
qDebug() << "Too many crashes recently, disabling compositing";
|
|
|
|
KConfigGroup compgroup(KSharedConfig::openConfig(), "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-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
|
2013-08-19 08:52:22 +00:00
|
|
|
Xcb::selectInput(rootWindow(), XCB_EVENT_MASK_PROPERTY_CHANGE);
|
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;
|
2013-08-28 12:10:51 +00:00
|
|
|
return QApplication::notify(o, e);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
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-08-28 12:10:51 +00:00
|
|
|
void Application::setCrashCount(int count)
|
|
|
|
{
|
|
|
|
crashes = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Application::wasCrash()
|
|
|
|
{
|
|
|
|
return crashes > 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2013-12-05 16:18:50 +00:00
|
|
|
static const char version[] = KWIN_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"
|
2013-12-06 07:37:16 +00:00
|
|
|
KWIN_EXPORT int kdemain(int argc, char * argv[])
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
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
|
|
|
|
2014-05-07 13:42:42 +00:00
|
|
|
const QByteArray loopName = qgetenv("QSG_RENDER_LOOP");
|
|
|
|
if (loopName.isEmpty()) {
|
|
|
|
setenv("QSG_RENDER_LOOP", "basic", 1);
|
|
|
|
}
|
|
|
|
|
2014-04-29 06:51:04 +00:00
|
|
|
KLocalizedString::setApplicationDomain("kwin");
|
2013-11-29 05:18:28 +00:00
|
|
|
QLoggingCategory::setFilterRules(QStringLiteral("aurorae.debug = true\n") +
|
|
|
|
QStringLiteral("kwineffects.debug = true"));
|
2013-11-25 13:55:58 +00:00
|
|
|
|
2013-08-29 10:24:23 +00:00
|
|
|
int primaryScreen = 0;
|
|
|
|
xcb_connection_t *c = xcb_connect(nullptr, &primaryScreen);
|
|
|
|
if (!c || xcb_connection_has_error(c)) {
|
2011-05-08 18:39:27 +00:00
|
|
|
fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n",
|
2013-08-29 10:24:23 +00:00
|
|
|
argv[0], qgetenv("DISPLAY").constData());
|
2011-05-08 18:39:27 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-08-29 10:24:23 +00:00
|
|
|
const int number_of_screens = xcb_setup_roots_length(xcb_get_setup(c));
|
2011-05-08 18:39:27 +00:00
|
|
|
|
|
|
|
// multi head
|
2013-08-29 09:32:20 +00:00
|
|
|
auto isMultiHead = []() -> bool {
|
|
|
|
QByteArray multiHead = qgetenv("KDE_MULTIHEAD");
|
|
|
|
if (!multiHead.isEmpty()) {
|
|
|
|
return (multiHead.toLower() == "true");
|
|
|
|
}
|
2013-09-26 05:54:51 +00:00
|
|
|
return true;
|
2013-08-29 09:32:20 +00:00
|
|
|
};
|
|
|
|
if (number_of_screens != 1 && isMultiHead()) {
|
2011-05-08 18:39:27 +00:00
|
|
|
KWin::is_multihead = true;
|
2013-08-29 10:24:23 +00:00
|
|
|
KWin::screen_number = primaryScreen;
|
2011-05-08 18:39:27 +00:00
|
|
|
int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head
|
2013-08-29 10:24:23 +00:00
|
|
|
QByteArray display_name = qgetenv("DISPLAY");
|
|
|
|
xcb_disconnect(c);
|
|
|
|
c = nullptr;
|
2011-05-08 18:39:27 +00:00
|
|
|
|
|
|
|
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-08-28 12:24:58 +00:00
|
|
|
if (signal(SIGTERM, KWin::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGTERM, SIG_IGN);
|
|
|
|
if (signal(SIGINT, KWin::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
if (signal(SIGHUP, KWin::sighandler) == SIG_IGN)
|
|
|
|
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
|
|
|
|
2014-03-09 11:37:21 +00:00
|
|
|
// enforce xcb plugin, unfortunately command line switch has precedence
|
|
|
|
setenv("QT_QPA_PLATFORM", "xcb", true);
|
|
|
|
|
2013-08-28 12:10:51 +00:00
|
|
|
KWin::Application a(argc, argv);
|
|
|
|
|
2014-06-04 13:59:03 +00:00
|
|
|
QTranslator qtTranslator;
|
|
|
|
qtTranslator.load("qt_" + QLocale::system().name(),
|
|
|
|
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
a.installTranslator(&qtTranslator);
|
|
|
|
|
2013-08-28 12:10:51 +00:00
|
|
|
KAboutData aboutData(QStringLiteral(KWIN_NAME), // The program name used internally
|
|
|
|
i18n("KWin"), // A displayable program name string
|
2013-12-05 16:18:50 +00:00
|
|
|
QStringLiteral(KWIN_VERSION_STRING), // The program version string
|
2013-08-28 12:10:51 +00:00
|
|
|
i18n(description), // Short description of what the app does
|
2014-05-14 02:49:33 +00:00
|
|
|
KAboutLicense::GPL, // The license this code is released under
|
2013-08-28 12:10:51 +00:00
|
|
|
i18n("(c) 1999-2013, The KDE Developers")); // Copyright Statement
|
|
|
|
|
|
|
|
aboutData.addAuthor(i18n("Matthias Ettrich"), QString(), QStringLiteral("ettrich@kde.org"));
|
|
|
|
aboutData.addAuthor(i18n("Cristian Tibirna"), QString(), QStringLiteral("tibirna@kde.org"));
|
|
|
|
aboutData.addAuthor(i18n("Daniel M. Duley"), QString(), QStringLiteral("mosfet@kde.org"));
|
|
|
|
aboutData.addAuthor(i18n("Luboš Luňák"), QString(), QStringLiteral("l.lunak@kde.org"));
|
|
|
|
aboutData.addAuthor(i18n("Martin Gräßlin"), i18n("Maintainer"), QStringLiteral("mgraesslin@kde.org"));
|
2014-05-27 07:33:34 +00:00
|
|
|
KAboutData::setApplicationData(aboutData);
|
2013-08-28 12:10:51 +00:00
|
|
|
|
|
|
|
QCommandLineOption lockOption(QStringLiteral("lock"), i18n("Disable configuration options"));
|
|
|
|
QCommandLineOption replaceOption(QStringLiteral("replace"), i18n("Replace already-running ICCCM2.0-compliant window manager"));
|
|
|
|
QCommandLineOption crashesOption(QStringLiteral("crashes"), i18n("Indicate that KWin has recently crashed n times"), QStringLiteral("n"));
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription(i18n("KDE window manager"));
|
|
|
|
parser.addVersionOption();
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addOption(lockOption);
|
|
|
|
parser.addOption(replaceOption);
|
|
|
|
parser.addOption(crashesOption);
|
2014-05-27 07:34:14 +00:00
|
|
|
aboutData.setupCommandLine(&parser);
|
2013-08-28 12:10:51 +00:00
|
|
|
|
|
|
|
parser.process(a);
|
2014-05-27 07:34:14 +00:00
|
|
|
aboutData.processCommandLine(&parser);
|
2013-08-28 12:10:51 +00:00
|
|
|
|
|
|
|
KWin::Application::setCrashCount(parser.value(crashesOption).toInt());
|
|
|
|
a.setConfigLock(parser.isSet(lockOption));
|
|
|
|
a.setReplace(parser.isSet(replaceOption));
|
|
|
|
|
2014-03-09 11:37:21 +00:00
|
|
|
// perform sanity checks
|
|
|
|
if (a.platformName().toLower() != QStringLiteral("xcb")) {
|
|
|
|
fprintf(stderr, "%s: FATAL ERROR expecting platform xcb but got platform %s\n",
|
|
|
|
argv[0], qPrintable(a.platformName()));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!KWin::display()) {
|
|
|
|
fprintf(stderr, "%s: FATAL ERROR KWin requires Xlib support in the xcb plugin. Do not configure Qt with -no-xcb-xlib\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-08-28 12:10:51 +00:00
|
|
|
a.start();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-09-06 13:22:16 +00:00
|
|
|
#warning SessionManager needs porting
|
|
|
|
#if KWIN_QT5_PORTING
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::SessionManager weAreIndeed;
|
2013-09-06 13:22:16 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::SessionSaveDoneHelper helper;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return a.exec();
|
2010-05-31 21:24:40 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "main.moc"
|