From c7af7adda6cf23dcc7c996dc680dd4da3ff7aa9f Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 20 Jul 2022 11:05:00 +0300 Subject: [PATCH] x11: Hard-code 0 default screen The screen number matters only on multi-head setups. --- .../integration/xwaylandserver_crash_test.cpp | 1 - autotests/test_virtual_desktops.cpp | 3 -- src/composite.cpp | 4 +-- src/main.cpp | 14 -------- src/main.h | 10 ------ src/main_x11.cpp | 33 +++++-------------- src/netinfo.cpp | 3 +- src/utils/xcbutils.h | 12 ++----- src/xwayland/xwayland.cpp | 6 ++-- 9 files changed, 15 insertions(+), 71 deletions(-) diff --git a/autotests/integration/xwaylandserver_crash_test.cpp b/autotests/integration/xwaylandserver_crash_test.cpp index 9c8b654e29..99aa7f1332 100644 --- a/autotests/integration/xwaylandserver_crash_test.cpp +++ b/autotests/integration/xwaylandserver_crash_test.cpp @@ -129,7 +129,6 @@ void XwaylandServerCrashTest::testCrash() QCOMPARE(kwinApp()->x11Connection(), nullptr); QCOMPARE(kwinApp()->x11DefaultScreen(), nullptr); QCOMPARE(kwinApp()->x11RootWindow(), XCB_WINDOW_NONE); - QCOMPARE(kwinApp()->x11ScreenNumber(), -1); // Render a frame to ensure that the compositor doesn't crash. Compositor::self()->scene()->addRepaintFull(); diff --git a/autotests/test_virtual_desktops.cpp b/autotests/test_virtual_desktops.cpp index 05abf72193..d5a22acad2 100644 --- a/autotests/test_virtual_desktops.cpp +++ b/autotests/test_virtual_desktops.cpp @@ -17,8 +17,6 @@ namespace KWin { -int screen_number = 0; - InputRedirection *InputRedirection::s_self = nullptr; void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action) @@ -101,7 +99,6 @@ private: void TestVirtualDesktops::init() { VirtualDesktopManager::create(); - screen_number = 0; } void TestVirtualDesktops::cleanup() diff --git a/src/composite.cpp b/src/composite.cpp index c572c3b8f2..884a1b2d49 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -331,9 +331,7 @@ void Compositor::initializeX11() } if (!m_selectionOwner) { - char selection_name[100]; - sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNumber()); - m_selectionOwner = std::make_unique(selection_name); + m_selectionOwner = std::make_unique("_NET_WM_CM_S0"); connect(m_selectionOwner.get(), &CompositorSelectionOwner::lostOwnership, this, &Compositor::stop); } if (!m_selectionOwner->owning()) { diff --git a/src/main.cpp b/src/main.cpp index c98443bb5d..ac122548bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,23 +60,9 @@ namespace KWin { Options *options; - Atoms *atoms; - -int screen_number = -1; - int Application::crashes = 0; -void Application::setX11ScreenNumber(int screenNumber) -{ - screen_number = screenNumber; -} - -int Application::x11ScreenNumber() -{ - return screen_number; -} - Application::Application(Application::OperationMode mode, int &argc, char **argv) : QApplication(argc, argv) , m_eventFilter(new XcbEventFilter()) diff --git a/src/main.h b/src/main.h index 1d47d73d38..8a663f6c4c 100644 --- a/src/main.h +++ b/src/main.h @@ -58,7 +58,6 @@ class KWIN_EXPORT Application : public QApplication Q_PROPERTY(quint32 x11Time READ x11Time WRITE setX11Time) Q_PROPERTY(quint32 x11RootWindow READ x11RootWindow CONSTANT) Q_PROPERTY(void *x11Connection READ x11Connection NOTIFY x11ConnectionChanged) - Q_PROPERTY(int x11ScreenNumber READ x11ScreenNumber CONSTANT) Q_PROPERTY(KSharedConfigPtr config READ config WRITE setConfig) Q_PROPERTY(KSharedConfigPtr kxkbConfig READ kxkbConfig WRITE setKxkbConfig) public: @@ -149,15 +148,6 @@ public: */ static void createAboutData(); - /** - * @returns the X11 Screen number. If not applicable it's set to @c -1. - */ - static int x11ScreenNumber(); - /** - * Sets the X11 screen number of this KWin instance to @p screenNumber. - */ - static void setX11ScreenNumber(int screenNumber); - /** * @returns the X11 root window. */ diff --git a/src/main_x11.cpp b/src/main_x11.cpp index 5119a49fe0..e784bc9e68 100644 --- a/src/main_x11.cpp +++ b/src/main_x11.cpp @@ -108,8 +108,8 @@ class KWinSelectionOwner : public KSelectionOwner { Q_OBJECT public: - explicit KWinSelectionOwner(int screen) - : KSelectionOwner(make_selection_atom(screen), screen) + explicit KWinSelectionOwner() + : KSelectionOwner(make_selection_atom()) { } @@ -150,13 +150,9 @@ private: } } - xcb_atom_t make_selection_atom(int screen_P) + xcb_atom_t make_selection_atom() { - if (screen_P < 0) { - screen_P = QX11Info::appScreen(); - } - QByteArray screen(QByteArrayLiteral("WM_S")); - screen.append(QByteArray::number(screen_P)); + QByteArray screen(QByteArrayLiteral("WM_S0")); ScopedCPointer atom(xcb_intern_atom_reply( kwinApp()->x11Connection(), xcb_intern_atom_unchecked(kwinApp()->x11Connection(), false, screen.length(), screen.constData()), @@ -209,28 +205,15 @@ void ApplicationX11::lostSelection() quit(); } -static xcb_screen_t *findXcbScreen(xcb_connection_t *connection, int screen) -{ - for (xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(connection)); - it.rem; - --screen, xcb_screen_next(&it)) { - if (screen == 0) { - return it.data; - } - } - return nullptr; -} - void ApplicationX11::performStartup() { crashChecking(); - if (Application::x11ScreenNumber() == -1) { - Application::setX11ScreenNumber(QX11Info::appScreen()); - } - setX11DefaultScreen(findXcbScreen(x11Connection(), x11ScreenNumber())); + xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(x11Connection())).data; + Q_ASSERT(screen); + setX11DefaultScreen(screen); - owner.reset(new KWinSelectionOwner(Application::x11ScreenNumber())); + owner.reset(new KWinSelectionOwner()); 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); diff --git a/src/netinfo.cpp b/src/netinfo.cpp index eb009ef1fd..215f81af35 100644 --- a/src/netinfo.cpp +++ b/src/netinfo.cpp @@ -20,7 +20,6 @@ namespace KWin { -extern int screen_number; std::unique_ptr RootInfo::s_self; @@ -116,7 +115,7 @@ RootInfo *RootInfo::create() | NET::ActionChangeDesktop | NET::ActionClose; - s_self.reset(new RootInfo(supportWindow, "KWin", properties, types, states, properties2, actions, screen_number)); + s_self.reset(new RootInfo(supportWindow, "KWin", properties, types, states, properties2, actions)); return s_self.get(); } diff --git a/src/utils/xcbutils.h b/src/utils/xcbutils.h index 3708aa715b..8f66e35ea8 100644 --- a/src/utils/xcbutils.h +++ b/src/utils/xcbutils.h @@ -1976,15 +1976,9 @@ static inline int defaultDepth() if (depth != 0) { return depth; } - int screen = Application::x11ScreenNumber(); - for (xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(connection())); - it.rem; - --screen, xcb_screen_next(&it)) { - if (screen == 0) { - depth = it.data->root_depth; - break; - } - } + xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection())).data; + Q_ASSERT(screen); + depth = screen->root_depth; return depth; } diff --git a/src/xwayland/xwayland.cpp b/src/xwayland/xwayland.cpp index 2093abb398..677db123c1 100644 --- a/src/xwayland/xwayland.cpp +++ b/src/xwayland/xwayland.cpp @@ -261,7 +261,6 @@ bool Xwayland::createX11Connection() m_app->setX11Connection(connection); m_app->setX11DefaultScreen(screen); - m_app->setX11ScreenNumber(0); m_app->setX11RootWindow(screen->root); m_app->createAtoms(); @@ -269,8 +268,8 @@ bool Xwayland::createX11Connection() installSocketNotifier(); - // Note that it's very important to have valid x11RootWindow(), x11ScreenNumber(), and - // atoms when the rest of kwin is notified about the new X11 connection. + // Note that it's very important to have valid x11RootWindow(), and atoms when the + // rest of kwin is notified about the new X11 connection. Q_EMIT m_app->x11ConnectionChanged(); return true; @@ -292,7 +291,6 @@ void Xwayland::destroyX11Connection() m_app->setX11Connection(nullptr); m_app->setX11DefaultScreen(nullptr); - m_app->setX11ScreenNumber(-1); m_app->setX11RootWindow(XCB_WINDOW_NONE); Q_EMIT m_app->x11ConnectionChanged();