2014-08-12 07:08:48 +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>
|
|
|
|
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "main_x11.h"
|
2019-06-22 10:40:12 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
#include <config-kwin.h>
|
2019-06-22 10:40:12 +00:00
|
|
|
|
2016-04-08 08:11:27 +00:00
|
|
|
#include "platform.h"
|
2014-08-12 07:08:48 +00:00
|
|
|
#include "sm.h"
|
2016-02-17 08:26:38 +00:00
|
|
|
#include "workspace.h"
|
2014-08-12 07:08:48 +00:00
|
|
|
#include "xcbutils.h"
|
|
|
|
|
2016-05-06 14:28:29 +00:00
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KCrash>
|
2014-08-12 07:08:48 +00:00
|
|
|
#include <KLocalizedString>
|
2016-04-08 08:11:27 +00:00
|
|
|
#include <KPluginLoader>
|
|
|
|
#include <KPluginMetaData>
|
2019-06-22 10:40:12 +00:00
|
|
|
#include <KSelectionOwner>
|
2017-11-01 15:45:05 +00:00
|
|
|
#include <KQuickAddons/QtQuickSettings>
|
2019-06-22 10:40:12 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
#include <qplatformdefs.h>
|
2016-05-06 14:28:29 +00:00
|
|
|
#include <QComboBox>
|
2014-08-12 07:08:48 +00:00
|
|
|
#include <QCommandLineParser>
|
2016-05-06 14:28:29 +00:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
[platforms/X11] Disable VSync for QtQuick Windows
Summary:
QtQuick windows created by KWin currently use the default swap interval
of 1, meaning buffer swaps will block until vblank. However, this
results in a problematic interaction on hybrid graphics systems running
the proprietary NVIDIA driver. VSync on such setups relies on a system
called "PRIME synchronization", where the xf86-video-modesetting driver
controlling the display will signal the NVIDIA driver when vblank has
occurred. The issue is that it will only do so if there has been damage
to the screen.
So, when KWin creates a QtQuick window, compositing will stop waiting on
the window to render, therefore no damage to the screen will occur. But
this means that no vblank notifications will be delivered to the NVIDIA
driver, so the glXSwapBuffers call by the QtQuick window will block
perpetually. The end result is a freeze of the desktop.
To get around this, we can simply disable vsync for QtQuick windows by
setting the swap interval for the default QSurfaceFormat to 0. Since
they are redirected, this shouldn't cause any tearing.
BUG: 406180
FIXED-IN: 5.16.2
Test Plan:
Using the proprietary NVIDIA driver on a hybrid graphics system, with
PRIME synchronization enabled (see
https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/),
perform any action causing a QtQuick window to be created by KWin, for
example, triggering the application switcher dialogue with alt + tab.
Ensure the desktop does not temporarily freeze.
Note, this required a Qt build that includes commit
https://code.qt.io/cgit/qt/qtbase.git/commit/?id=0c1831178540462da31fd7a4b6d2e446bc84498b
resolving a bug that prevented the changing the swap interval.
Reviewers: #kwin, davidedmundson, zzag
Reviewed By: #kwin, davidedmundson, zzag
Subscribers: zzag, romangg, alexeymin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21808
2019-06-19 14:56:42 +00:00
|
|
|
#include <QSurfaceFormat>
|
2016-05-06 14:28:29 +00:00
|
|
|
#include <QVBoxLayout>
|
2016-11-11 08:59:46 +00:00
|
|
|
#include <QX11Info>
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
// system
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif // HAVE_UNISTD_H
|
2016-04-08 08:11:27 +00:00
|
|
|
#include <iostream>
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2016-05-06 14:28:29 +00:00
|
|
|
Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core", QtCriticalMsg)
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static void sighandler(int)
|
|
|
|
{
|
|
|
|
QApplication::exit();
|
|
|
|
}
|
|
|
|
|
2016-05-06 14:28:29 +00:00
|
|
|
class AlternativeWMDialog : public QDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AlternativeWMDialog()
|
|
|
|
: QDialog() {
|
|
|
|
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 QComboBox(mainWidget);
|
|
|
|
wmList->setEditable(true);
|
|
|
|
layout->addWidget(wmList);
|
|
|
|
|
|
|
|
addWM(QStringLiteral("metacity"));
|
|
|
|
addWM(QStringLiteral("openbox"));
|
|
|
|
addWM(QStringLiteral("fvwm2"));
|
|
|
|
addWM(QStringLiteral(KWIN_INTERNAL_NAME_X11));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
void addWM(const QString& wm) {
|
|
|
|
// TODO: Check if WM is installed
|
|
|
|
if (!QStandardPaths::findExecutable(wm).isEmpty())
|
|
|
|
wmList->addItem(wm);
|
|
|
|
}
|
|
|
|
QString selectedWM() const {
|
|
|
|
return wmList->currentText();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QComboBox* wmList;
|
|
|
|
};
|
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
class KWinSelectionOwner : public KSelectionOwner
|
2014-08-12 07:08:48 +00:00
|
|
|
{
|
2019-06-22 10:40:12 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit KWinSelectionOwner(int screen)
|
|
|
|
: KSelectionOwner(make_selection_atom(screen), screen)
|
|
|
|
{
|
|
|
|
}
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
private:
|
|
|
|
bool genericReply(xcb_atom_t target_P, xcb_atom_t property_P, xcb_window_t requestor_P) override {
|
|
|
|
if (target_P == xa_version) {
|
|
|
|
int32_t version[] = { 2, 0 };
|
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, requestor_P,
|
|
|
|
property_P, XCB_ATOM_INTEGER, 32, 2, version);
|
|
|
|
} else
|
|
|
|
return KSelectionOwner::genericReply(target_P, property_P, requestor_P);
|
|
|
|
return true;
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
void replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P) override {
|
|
|
|
KSelectionOwner::replyTargets(property_P, requestor_P);
|
|
|
|
xcb_atom_t atoms[ 1 ] = { xa_version };
|
|
|
|
// PropModeAppend !
|
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_APPEND, requestor_P,
|
|
|
|
property_P, XCB_ATOM_ATOM, 32, 1, atoms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAtoms() override {
|
|
|
|
KSelectionOwner::getAtoms();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_atom_t make_selection_atom(int screen_P) {
|
|
|
|
if (screen_P < 0)
|
|
|
|
screen_P = QX11Info::appScreen();
|
|
|
|
QByteArray screen(QByteArrayLiteral("WM_S"));
|
|
|
|
screen.append(QByteArray::number(screen_P));
|
2014-08-12 07:08:48 +00:00
|
|
|
ScopedCPointer<xcb_intern_atom_reply_t> atom(xcb_intern_atom_reply(
|
|
|
|
connection(),
|
2019-06-22 10:40:12 +00:00
|
|
|
xcb_intern_atom_unchecked(connection(), false, screen.length(), screen.constData()),
|
2014-08-12 07:08:48 +00:00
|
|
|
nullptr));
|
2019-06-22 10:40:12 +00:00
|
|
|
if (atom.isNull()) {
|
|
|
|
return XCB_ATOM_NONE;
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
return atom->atom;
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
static xcb_atom_t xa_version;
|
|
|
|
};
|
2014-08-12 07:08:48 +00:00
|
|
|
xcb_atom_t KWinSelectionOwner::xa_version = XCB_ATOM_NONE;
|
|
|
|
|
|
|
|
//************************************
|
|
|
|
// ApplicationX11
|
|
|
|
//************************************
|
|
|
|
|
|
|
|
ApplicationX11::ApplicationX11(int &argc, char **argv)
|
|
|
|
: Application(OperationModeX11, argc, argv)
|
|
|
|
, owner()
|
|
|
|
, m_replace(false)
|
|
|
|
{
|
2015-02-20 08:33:36 +00:00
|
|
|
setX11Connection(QX11Info::connection());
|
|
|
|
setX11RootWindow(QX11Info::appRootWindow());
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationX11::~ApplicationX11()
|
|
|
|
{
|
2019-01-06 16:05:10 +00:00
|
|
|
setTerminating();
|
2015-11-10 07:52:40 +00:00
|
|
|
destroyCompositor();
|
2014-08-12 07:08:48 +00:00
|
|
|
destroyWorkspace();
|
|
|
|
if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) // If there was no --replace (no new WM)
|
|
|
|
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationX11::setReplace(bool replace)
|
|
|
|
{
|
|
|
|
m_replace = replace;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationX11::lostSelection()
|
|
|
|
{
|
|
|
|
sendPostedEvents();
|
2015-11-10 07:52:40 +00:00
|
|
|
destroyCompositor();
|
2014-08-12 07:08:48 +00:00
|
|
|
destroyWorkspace();
|
|
|
|
// Remove windowmanager privileges
|
|
|
|
Xcb::selectInput(rootWindow(), XCB_EVENT_MASK_PROPERTY_CHANGE);
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationX11::performStartup()
|
|
|
|
{
|
2016-05-06 14:28:29 +00:00
|
|
|
crashChecking();
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
if (Application::x11ScreenNumber() == -1) {
|
|
|
|
Application::setX11ScreenNumber(QX11Info::appScreen());
|
|
|
|
}
|
|
|
|
|
2015-05-01 14:55:15 +00:00
|
|
|
// QSessionManager for some reason triggers a very early commitDataRequest
|
|
|
|
// and updates the key - before we create the workspace and load the session
|
|
|
|
// data -> store and pass to the workspace constructor
|
|
|
|
m_originalSessionKey = sessionKey();
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
owner.reset(new KWinSelectionOwner(Application::x11ScreenNumber()));
|
|
|
|
connect(owner.data(), &KSelectionOwner::failedToClaimOwnership, []{
|
|
|
|
fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").toLocal8Bit().constData(), stderr);
|
|
|
|
::exit(1);
|
|
|
|
});
|
|
|
|
connect(owner.data(), SIGNAL(lostOwnership()), SLOT(lostSelection()));
|
|
|
|
connect(owner.data(), &KSelectionOwner::claimedOwnership, [this]{
|
|
|
|
setupEventFilters();
|
|
|
|
// first load options - done internally by a different thread
|
|
|
|
createOptions();
|
|
|
|
|
|
|
|
// Check whether another windowmanager is running
|
|
|
|
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);
|
2015-12-16 15:30:06 +00:00
|
|
|
if (!wasCrash()) // if this is a crash-restart, DrKonqi may have stopped the process w/o killing the connection
|
|
|
|
::exit(1);
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 13:53:03 +00:00
|
|
|
createInput();
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2016-04-08 08:11:27 +00:00
|
|
|
connect(platform(), &Platform::screensQueried, this,
|
|
|
|
[this] {
|
|
|
|
createWorkspace();
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2016-04-08 08:11:27 +00:00
|
|
|
Xcb::sync(); // Trigger possible errors, there's still a chance to abort
|
|
|
|
|
|
|
|
notifyKSplash();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(platform(), &Platform::initFailed, this,
|
|
|
|
[] () {
|
|
|
|
std::cerr << "FATAL ERROR: backend failed to initialize, exiting now" << std::endl;
|
|
|
|
::exit(1);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
platform()->init();
|
2014-08-12 07:08:48 +00:00
|
|
|
});
|
|
|
|
// we need to do an XSync here, otherwise the QPA might crash us later on
|
|
|
|
Xcb::sync();
|
2015-12-16 15:30:06 +00:00
|
|
|
owner->claim(m_replace || wasCrash(), true);
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
createAtoms();
|
|
|
|
}
|
|
|
|
|
2016-02-17 08:26:38 +00:00
|
|
|
bool ApplicationX11::notify(QObject* o, QEvent* e)
|
|
|
|
{
|
|
|
|
if (Workspace::self()->workspaceEvent(e))
|
|
|
|
return true;
|
|
|
|
return QApplication::notify(o, e);
|
|
|
|
}
|
|
|
|
|
2016-05-06 14:28:29 +00:00
|
|
|
void ApplicationX11::setupCrashHandler()
|
|
|
|
{
|
|
|
|
KCrash::setEmergencySaveFunction(ApplicationX11::crashHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationX11::crashChecking()
|
|
|
|
{
|
|
|
|
setupCrashHandler();
|
|
|
|
if (crashes >= 4) {
|
|
|
|
// Something has gone seriously wrong
|
|
|
|
AlternativeWMDialog dialog;
|
|
|
|
QString cmd = QStringLiteral(KWIN_INTERNAL_NAME_X11);
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
cmd = dialog.selectedWM();
|
|
|
|
else
|
|
|
|
::exit(1);
|
|
|
|
if (cmd.length() > 500) {
|
|
|
|
qCDebug(KWIN_CORE) << "Command is too long, truncating";
|
|
|
|
cmd = cmd.left(500);
|
|
|
|
}
|
|
|
|
qCDebug(KWIN_CORE) << "Starting" << cmd << "and exiting";
|
|
|
|
char buf[1024];
|
2019-07-10 13:04:52 +00:00
|
|
|
sprintf(buf, "%s &", cmd.toLatin1().data());
|
2016-05-06 14:28:29 +00:00
|
|
|
system(buf);
|
|
|
|
::exit(1);
|
|
|
|
}
|
|
|
|
if (crashes >= 2) {
|
|
|
|
// Disable compositing if we have had too many crashes
|
|
|
|
qCDebug(KWIN_CORE) << "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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationX11::crashHandler(int signal)
|
|
|
|
{
|
|
|
|
crashes++;
|
|
|
|
|
|
|
|
fprintf(stderr, "Application::crashHandler() called with signal %d; recent crashes: %d\n", signal, crashes);
|
|
|
|
char cmd[1024];
|
|
|
|
sprintf(cmd, "%s --crashes %d &",
|
|
|
|
QFile::encodeName(QCoreApplication::applicationFilePath()).constData(), crashes);
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
system(cmd);
|
|
|
|
}
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
KWIN_EXPORT int kdemain(int argc, char * argv[])
|
|
|
|
{
|
|
|
|
KWin::Application::setupMalloc();
|
|
|
|
KWin::Application::setupLocalizedString();
|
|
|
|
|
|
|
|
int primaryScreen = 0;
|
|
|
|
xcb_connection_t *c = xcb_connect(nullptr, &primaryScreen);
|
|
|
|
if (!c || xcb_connection_has_error(c)) {
|
|
|
|
fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n",
|
|
|
|
argv[0], qgetenv("DISPLAY").constData());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int number_of_screens = xcb_setup_roots_length(xcb_get_setup(c));
|
2015-01-23 08:54:03 +00:00
|
|
|
xcb_disconnect(c);
|
|
|
|
c = nullptr;
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
// multi head
|
|
|
|
auto isMultiHead = []() -> bool {
|
|
|
|
QByteArray multiHead = qgetenv("KDE_MULTIHEAD");
|
|
|
|
if (!multiHead.isEmpty()) {
|
|
|
|
return (multiHead.toLower() == "true");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (number_of_screens != 1 && isMultiHead()) {
|
|
|
|
KWin::Application::setX11MultiHead(true);
|
|
|
|
KWin::Application::setX11ScreenNumber(primaryScreen);
|
|
|
|
int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head
|
|
|
|
QByteArray display_name = qgetenv("DISPLAY");
|
|
|
|
|
|
|
|
if ((pos = display_name.lastIndexOf('.')) != -1)
|
|
|
|
display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s"
|
|
|
|
|
|
|
|
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::Application::x11ScreenNumber() && fork() == 0) {
|
|
|
|
KWin::Application::setX11ScreenNumber(i);
|
2015-01-23 08:48:55 +00:00
|
|
|
QByteArray dBusSuffix = qgetenv("KWIN_DBUS_SERVICE_SUFFIX");
|
|
|
|
if (!dBusSuffix.isNull()) {
|
|
|
|
dBusSuffix.append(".");
|
|
|
|
}
|
|
|
|
dBusSuffix.append(QByteArrayLiteral("head-")).append(QByteArray::number(i));
|
|
|
|
qputenv("KWIN_DBUS_SERVICE_SUFFIX", dBusSuffix);
|
2014-08-12 07:08:48 +00:00
|
|
|
// Break here because we are the child process, we don't
|
|
|
|
// want to fork() anymore
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// In the next statement, display_name shouldn't contain a screen
|
|
|
|
// number. If it had it, it was removed at the "pos" check
|
2019-09-18 08:33:18 +00:00
|
|
|
const QString envir = QStringLiteral("DISPLAY=%1.%2")
|
|
|
|
.arg(display_name.data())
|
|
|
|
.arg(KWin::Application::x11ScreenNumber());
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2019-07-10 13:04:52 +00:00
|
|
|
if (putenv(strdup(envir.toLatin1().constData()))) {
|
2014-08-12 07:08:48 +00:00
|
|
|
fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]);
|
|
|
|
perror("putenv()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-11-18 09:02:04 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
// Disable the glib event loop integration, since it seems to be responsible
|
|
|
|
// for several bug reports about high CPU usage (bug #239963)
|
|
|
|
setenv("QT_NO_GLIB", "1", true);
|
|
|
|
|
|
|
|
// enforce xcb plugin, unfortunately command line switch has precedence
|
|
|
|
setenv("QT_QPA_PLATFORM", "xcb", true);
|
|
|
|
|
2015-04-17 16:13:39 +00:00
|
|
|
qunsetenv("QT_DEVICE_PIXEL_RATIO");
|
2019-04-04 01:03:26 +00:00
|
|
|
qunsetenv("QT_SCALE_FACTOR");
|
2016-01-26 17:01:40 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
|
2015-04-17 16:13:39 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
KWin::ApplicationX11 a(argc, argv);
|
|
|
|
a.setupTranslator();
|
|
|
|
|
|
|
|
KWin::Application::createAboutData();
|
2017-11-01 15:45:05 +00:00
|
|
|
KQuickAddons::QtQuickSettings::init();
|
2014-08-12 07:08:48 +00:00
|
|
|
|
[platforms/X11] Disable VSync for QtQuick Windows
Summary:
QtQuick windows created by KWin currently use the default swap interval
of 1, meaning buffer swaps will block until vblank. However, this
results in a problematic interaction on hybrid graphics systems running
the proprietary NVIDIA driver. VSync on such setups relies on a system
called "PRIME synchronization", where the xf86-video-modesetting driver
controlling the display will signal the NVIDIA driver when vblank has
occurred. The issue is that it will only do so if there has been damage
to the screen.
So, when KWin creates a QtQuick window, compositing will stop waiting on
the window to render, therefore no damage to the screen will occur. But
this means that no vblank notifications will be delivered to the NVIDIA
driver, so the glXSwapBuffers call by the QtQuick window will block
perpetually. The end result is a freeze of the desktop.
To get around this, we can simply disable vsync for QtQuick windows by
setting the swap interval for the default QSurfaceFormat to 0. Since
they are redirected, this shouldn't cause any tearing.
BUG: 406180
FIXED-IN: 5.16.2
Test Plan:
Using the proprietary NVIDIA driver on a hybrid graphics system, with
PRIME synchronization enabled (see
https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/),
perform any action causing a QtQuick window to be created by KWin, for
example, triggering the application switcher dialogue with alt + tab.
Ensure the desktop does not temporarily freeze.
Note, this required a Qt build that includes commit
https://code.qt.io/cgit/qt/qtbase.git/commit/?id=0c1831178540462da31fd7a4b6d2e446bc84498b
resolving a bug that prevented the changing the swap interval.
Reviewers: #kwin, davidedmundson, zzag
Reviewed By: #kwin, davidedmundson, zzag
Subscribers: zzag, romangg, alexeymin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21808
2019-06-19 14:56:42 +00:00
|
|
|
// disables vsync for any QtQuick windows we create (BUG 406180)
|
|
|
|
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
|
|
|
format.setSwapInterval(0);
|
|
|
|
QSurfaceFormat::setDefaultFormat(format);
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
QCommandLineOption replaceOption(QStringLiteral("replace"), i18n("Replace already-running ICCCM2.0-compliant window manager"));
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
a.setupCommandLine(&parser);
|
|
|
|
parser.addOption(replaceOption);
|
2015-11-24 08:01:46 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
|
|
|
QCommandLineOption noActivitiesOption(QStringLiteral("no-kactivities"),
|
|
|
|
i18n("Disable KActivities integration."));
|
|
|
|
parser.addOption(noActivitiesOption);
|
|
|
|
#endif
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
parser.process(a);
|
|
|
|
a.processCommandLine(&parser);
|
|
|
|
a.setReplace(parser.isSet(replaceOption));
|
2015-11-24 08:01:46 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
|
|
|
if (parser.isSet(noActivitiesOption)) {
|
|
|
|
a.setUseKActivities(false);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-12 07:08:48 +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);
|
|
|
|
}
|
2016-11-11 08:59:46 +00:00
|
|
|
if (!QX11Info::display()) {
|
2014-08-12 07:08:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-04-08 08:11:27 +00:00
|
|
|
// find and load the X11 platform plugin
|
|
|
|
const auto plugins = KPluginLoader::findPluginsById(QStringLiteral("org.kde.kwin.platforms"),
|
|
|
|
QStringLiteral("KWinX11Platform"));
|
|
|
|
if (plugins.isEmpty()) {
|
|
|
|
std::cerr << "FATAL ERROR: KWin could not find the KWinX11Platform plugin" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
a.initPlatform(plugins.first());
|
|
|
|
if (!a.platform()) {
|
|
|
|
std::cerr << "FATAL ERROR: could not instantiate the platform plugin" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
a.start();
|
|
|
|
|
|
|
|
KWin::SessionSaveDoneHelper helper;
|
2015-06-12 01:11:14 +00:00
|
|
|
Q_UNUSED(helper); // The sessionsavedonehelper opens a side channel to the smserver,
|
|
|
|
// listens for events and talks to it, so it needs to be created.
|
2014-08-12 07:08:48 +00:00
|
|
|
return a.exec();
|
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
|
|
|
|
#include "main_x11.moc"
|