diff --git a/composite.h b/composite.h --- a/composite.h +++ b/composite.h @@ -23,8 +23,6 @@ #define KWIN_COMPOSITE_H // KWin #include -// KDE -#include // Qt #include #include @@ -35,20 +33,9 @@ namespace KWin { class Client; +class CompositorSelectionOwner; class Scene; -class CompositorSelectionOwner : public KSelectionOwner -{ - Q_OBJECT -public: - CompositorSelectionOwner(const char *selection); -private: - friend class Compositor; - bool owning; -private Q_SLOTS: - void looseOwnership(); -}; - class KWIN_EXPORT Compositor : public QObject { Q_OBJECT public: @@ -216,7 +203,7 @@ SuspendReasons m_suspended; QBasicTimer compositeTimer; - CompositorSelectionOwner* cm_selection; + CompositorSelectionOwner *m_selectionOwner; QTimer m_releaseSelectionTimer; QList m_unusedSupportProperties; QTimer m_unusedSupportPropertyTimer; diff --git a/composite.cpp b/composite.cpp --- a/composite.cpp +++ b/composite.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include @@ -69,15 +69,26 @@ extern int currentRefreshRate(); -CompositorSelectionOwner::CompositorSelectionOwner(const char *selection) : KSelectionOwner(selection, connection(), rootWindow()), owning(false) +class CompositorSelectionOwner : public KSelectionOwner { - connect (this, SIGNAL(lostOwnership()), SLOT(looseOwnership())); -} - -void CompositorSelectionOwner::looseOwnership() -{ - owning = false; -} + Q_OBJECT +public: + CompositorSelectionOwner(const char *selection) + : KSelectionOwner(selection, connection(), rootWindow()) + , m_owning(false) + { + connect (this, &CompositorSelectionOwner::lostOwnership, + this, [this]() { m_owning = false; }); + } + bool owning() const { + return m_owning; + } + void setOwning(bool own) { + m_owning = own; + } +private: + bool m_owning; +}; KWIN_SINGLETON_FACTORY_VARIABLE(Compositor, s_compositor) @@ -87,7 +98,7 @@ Compositor::Compositor(QObject* workspace) : QObject(workspace) , m_suspended(options->isUseCompositing() ? NoReasonSuspend : UserSuspend) - , cm_selection(NULL) + , m_selectionOwner(NULL) , vBlankInterval(0) , fpsInterval(0) , m_xrrRefreshRate(0) @@ -133,8 +144,8 @@ ); connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed, this, [this] { - delete cm_selection; - cm_selection = nullptr; + delete m_selectionOwner; + m_selectionOwner = nullptr; } ); @@ -150,7 +161,7 @@ emit aboutToDestroy(); finish(); deleteUnusedSupportProperties(); - delete cm_selection; + delete m_selectionOwner; s_compositor = NULL; } @@ -249,9 +260,9 @@ delete m_scene; m_scene = NULL; m_starting = false; - if (cm_selection) { - cm_selection->owning = false; - cm_selection->release(); + if (m_selectionOwner) { + m_selectionOwner->setOwning(false); + m_selectionOwner->release(); } if (!supportedCompositors.contains(NoCompositing)) { qCCritical(KWIN_CORE) << "The used windowing system requires compositing"; @@ -280,28 +291,28 @@ void Compositor::claimCompositorSelection() { - if (!cm_selection) { + if (!m_selectionOwner) { char selection_name[ 100 ]; sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNumber()); - cm_selection = new CompositorSelectionOwner(selection_name); - connect(cm_selection, SIGNAL(lostOwnership()), SLOT(finish())); + m_selectionOwner = new CompositorSelectionOwner(selection_name); + connect(m_selectionOwner, &CompositorSelectionOwner::lostOwnership, this, &Compositor::finish); } - if (!cm_selection) // no X11 yet + if (!m_selectionOwner) // no X11 yet return; - if (!cm_selection->owning) { - cm_selection->claim(true); // force claiming - cm_selection->owning = true; + if (!m_selectionOwner->owning()) { + m_selectionOwner->claim(true); // force claiming + m_selectionOwner->setOwning(true); } } void Compositor::setupX11Support() { auto c = kwinApp()->x11Connection(); if (!c) { - delete cm_selection; - cm_selection = nullptr; + delete m_selectionOwner; + m_selectionOwner = nullptr; return; } claimCompositorSelection(); @@ -446,9 +457,9 @@ return; } qCDebug(KWIN_CORE) << "Releasing compositor selection"; - if (cm_selection) { - cm_selection->owning = false; - cm_selection->release(); + if (m_selectionOwner) { + m_selectionOwner->setOwning(false); + m_selectionOwner->release(); } } @@ -920,3 +931,6 @@ } } // namespace + +// included for CompositorSelectionOwner +#include "composite.moc" diff --git a/main.h b/main.h --- a/main.h +++ b/main.h @@ -25,8 +25,6 @@ #include #include -#include -#include #include // Qt #include diff --git a/main_x11.h b/main_x11.h --- a/main_x11.h +++ b/main_x11.h @@ -24,20 +24,7 @@ namespace KWin { -class KWinSelectionOwner - : public KSelectionOwner -{ - Q_OBJECT -public: - explicit KWinSelectionOwner(int screen); -protected: - virtual bool genericReply(xcb_atom_t target, xcb_atom_t property, xcb_window_t requestor); - virtual void replyTargets(xcb_atom_t property, xcb_window_t requestor); - virtual void getAtoms(); -private: - xcb_atom_t make_selection_atom(int screen); - static xcb_atom_t xa_version; -}; +class KWinSelectionOwner; class ApplicationX11 : public Application { diff --git a/main_x11.cpp b/main_x11.cpp --- a/main_x11.cpp +++ b/main_x11.cpp @@ -20,21 +20,22 @@ along with this program. If not, see . *********************************************************************/ #include "main_x11.h" + #include -// kwin + #include "platform.h" #include "sm.h" #include "workspace.h" #include "xcbutils.h" -// KDE #include #include #include #include #include +#include #include -// Qt + #include #include #include @@ -63,8 +64,6 @@ QApplication::exit(); } - - class AlternativeWMDialog : public QDialog { public: @@ -111,66 +110,64 @@ QComboBox* wmList; }; -//************************************ -// KWinSelectionOwner -//************************************ - -KWinSelectionOwner::KWinSelectionOwner(int screen_P) - : KSelectionOwner(make_selection_atom(screen_P), screen_P) +class KWinSelectionOwner : public KSelectionOwner { -} + Q_OBJECT +public: + explicit KWinSelectionOwner(int screen) + : KSelectionOwner(make_selection_atom(screen), screen) + { + } -xcb_atom_t KWinSelectionOwner::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)); - ScopedCPointer atom(xcb_intern_atom_reply( - connection(), - xcb_intern_atom_unchecked(connection(), false, screen.length(), screen.constData()), - nullptr)); - if (atom.isNull()) { - return XCB_ATOM_NONE; +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; } - return atom->atom; -} -void KWinSelectionOwner::getAtoms() -{ - KSelectionOwner::getAtoms(); - if (xa_version == XCB_ATOM_NONE) { - const QByteArray name(QByteArrayLiteral("VERSION")); + 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 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)); ScopedCPointer atom(xcb_intern_atom_reply( connection(), - xcb_intern_atom_unchecked(connection(), false, name.length(), name.constData()), + xcb_intern_atom_unchecked(connection(), false, screen.length(), screen.constData()), nullptr)); - if (!atom.isNull()) { - xa_version = atom->atom; + if (atom.isNull()) { + return XCB_ATOM_NONE; } + return atom->atom; } -} - -void KWinSelectionOwner::replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P) -{ - 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); -} - -bool KWinSelectionOwner::genericReply(xcb_atom_t target_P, xcb_atom_t property_P, xcb_window_t requestor_P) -{ - 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; -} - + static xcb_atom_t xa_version; +}; xcb_atom_t KWinSelectionOwner::xa_version = XCB_ATOM_NONE; //************************************ @@ -475,3 +472,5 @@ // listens for events and talks to it, so it needs to be created. return a.exec(); } + +#include "main_x11.moc" diff --git a/xwl/xwayland.cpp b/xwl/xwayland.cpp --- a/xwl/xwayland.cpp +++ b/xwl/xwayland.cpp @@ -26,6 +26,7 @@ #include "utils.h" #include +#include #include "xcbutils.h"