diff --git a/composite.h b/composite.h --- a/composite.h +++ b/composite.h @@ -18,87 +18,61 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ +#pragma once -#ifndef KWIN_COMPOSITE_H -#define KWIN_COMPOSITE_H -// KWin #include -// Qt + #include #include #include #include #include -namespace KWin { - +namespace KWin +{ class Client; class CompositorSelectionOwner; class Scene; -class KWIN_EXPORT Compositor : public QObject { +class KWIN_EXPORT Compositor : public QObject +{ Q_OBJECT public: - enum SuspendReason { NoReasonSuspend = 0, UserSuspend = 1<<0, BlockRuleSuspend = 1<<1, ScriptSuspend = 1<<2, AllReasonSuspend = 0xff }; + enum SuspendReason { + NoReasonSuspend = 0, + UserSuspend = 1 << 0, + BlockRuleSuspend = 1 << 1, + ScriptSuspend = 1 << 2, + AllReasonSuspend = 0xff + }; Q_DECLARE_FLAGS(SuspendReasons, SuspendReason) - ~Compositor(); + + ~Compositor() override; + // when adding repaints caused by a window, you probably want to use // either Toplevel::addRepaint() or Toplevel::addWorkspaceRepaint() void addRepaint(const QRect& r); void addRepaint(const QRegion& r); void addRepaint(int x, int y, int w, int h); - /** - * Whether the Compositor is active. That is a Scene is present and the Compositor is - * not shutting down itself. - **/ - bool isActive(); - int xrrRefreshRate() const { - return m_xrrRefreshRate; - } - void setCompositeResetTimer(int msecs); - - bool hasScene() const { - return m_scene != NULL; - } + void addRepaintFull(); /** - * Checks whether @p w is the Scene's overlay window. - **/ - bool checkForOverlayWindow(WId w) const; - /** - * @returns Whether the Scene's Overlay X Window is visible. + * Schedules a new repaint if no repaint is currently scheduled. **/ - bool isOverlayWindowVisible() const; - - Scene *scene() { - return m_scene; - } + void scheduleRepaint(); /** - * @brief Checks whether the Compositor has already been created by the Workspace. - * - * This method can be used to check whether self will return the Compositor instance or @c null. - * - * @return bool @c true if the Compositor has been created, @c false otherwise + * Notifies the compositor that SwapBuffers() is about to be called. + * Rendering of the next frame will be deferred until bufferSwapComplete() + * is called. **/ - static bool isCreated() { - return s_compositor != NULL; - } + void aboutToSwapBuffers(); + /** - * @brief Static check to test whether the Compositor is available and active. - * - * @return bool @c true if there is a Compositor and it is active, @c false otherwise + * Notifies the compositor that a pending buffer swap has completed. **/ - static bool compositing() { - return s_compositor != NULL && s_compositor->isActive(); - } - - // for delayed supportproperty management of effects - void keepSupportProperty(xcb_atom_t atom); - void removeSupportProperty(xcb_atom_t atom); + void bufferSwapComplete(); -public Q_SLOTS: - void addRepaintFull(); /** * @brief Suspends the Compositor if it is currently active. * @@ -109,7 +83,8 @@ * @see resume * @see isActive **/ - void suspend(Compositor::SuspendReason reason); + Q_INVOKABLE void suspend(Compositor::SuspendReason reason); + /** * @brief Resumes the Compositor if it is currently suspended. * @@ -127,38 +102,73 @@ * @see isCompositingPossible * @see isOpenGLBroken **/ - void resume(Compositor::SuspendReason reason); + Q_INVOKABLE void resume(Compositor::SuspendReason reason); + /** - * Actual slot to perform the toggling compositing. - * That is if the Compositor is suspended it will be resumed and if the Compositor is active - * it will be suspended. - * Invoked primarily by the keybinding. - * TODO: make private slot + * Toggles compositing, that is if the Compositor is suspended it will be resumed + * and if the Compositor is active it will be suspended. + * Invoked by keybinding (shortcut default: Shift + Alt + F12). **/ - void slotToggleCompositing(); + void toggleCompositing(); + /** * Re-initializes the Compositor completely. * Connected to the D-Bus signal org.kde.KWin /KWin reinitCompositing **/ void slotReinitialize(); + /** - * Schedules a new repaint if no repaint is currently scheduled. + * Whether the Compositor is active. That is a Scene is present and the Compositor is + * not shutting down itself. **/ - void scheduleRepaint(); - void updateCompositeBlocking(); - void updateCompositeBlocking(KWin::Client* c); + bool isActive(); + int xrrRefreshRate() const { + return m_xrrRefreshRate; + } + void setCompositeResetTimer(int msecs); + + bool hasScene() const { + return m_scene != NULL; + } /** - * Notifies the compositor that SwapBuffers() is about to be called. - * Rendering of the next frame will be deferred until bufferSwapComplete() - * is called. + * Checks whether @p w is the Scene's overlay window. **/ - void aboutToSwapBuffers(); + bool checkForOverlayWindow(WId w) const; + /** + * @returns Whether the Scene's Overlay X Window is visible. + **/ + bool isOverlayWindowVisible() const; + + Scene *scene() { + return m_scene; + } /** - * Notifies the compositor that a pending buffer swap has completed. + * @brief Checks whether the Compositor has already been created by the Workspace. + * + * This method can be used to check whether self will return the Compositor instance or @c null. + * + * @return bool @c true if the Compositor has been created, @c false otherwise **/ - void bufferSwapComplete(); + static bool isCreated() { + return s_compositor != NULL; + } + /** + * @brief Static check to test whether the Compositor is available and active. + * + * @return bool @c true if there is a Compositor and it is active, @c false otherwise + **/ + static bool compositing() { + return s_compositor != NULL && s_compositor->isActive(); + } + + void updateCompositeBlocking(); + void updateClientCompositeBlocking(KWin::Client* c); + + // for delayed supportproperty management of effects + void keepSupportProperty(xcb_atom_t atom); + void removeSupportProperty(xcb_atom_t atom); Q_SIGNALS: void compositingToggled(bool active); @@ -168,35 +178,38 @@ void bufferSwapCompleted(); protected: - void timerEvent(QTimerEvent *te); + void timerEvent(QTimerEvent *te) override; -private Q_SLOTS: - void setup(); +private: + Q_INVOKABLE void setup(); /** - * Called from setupCompositing() when the CompositingPrefs are ready. + * Called from setup() when the CompositingPrefs are ready. **/ void slotCompositingOptionsInitialized(); void finish(); /** * Restarts the Compositor if running. * That is the Compositor will be stopped and started again. **/ void restart(); - void performCompositing(); - void slotConfigChanged(); - void releaseCompositorSelection(); - void deleteUnusedSupportProperties(); -private: void claimCompositorSelection(); - void setCompositeTimer(); - bool windowRepaintsPending() const; + /** * Continues the startup after Scene And Workspace are created **/ void startupWithWorkspace(); void setupX11Support(); + void setCompositeTimer(); + void performCompositing(); + bool windowRepaintsPending() const; + + void releaseCompositorSelection(); + void deleteUnusedSupportProperties(); + + void slotConfigChanged(); + /** * Whether the Compositor is currently suspended, 8 bits encoding the reason **/ @@ -215,14 +228,16 @@ bool m_finishing; // finish() sets this variable while shutting down bool m_starting; // start() sets this variable while starting qint64 m_timeSinceLastVBlank; + Scene *m_scene; + bool m_bufferSwapPending; bool m_composeAtSwapCompletion; + int m_framesToTestForSafety = 3; QElapsedTimer m_monotonicClock; KWIN_SINGLETON_VARIABLE(Compositor, s_compositor) }; -} -# endif // KWIN_COMPOSITE_H +} diff --git a/composite.cpp b/composite.cpp --- a/composite.cpp +++ b/composite.cpp @@ -110,7 +110,7 @@ , m_composeAtSwapCompletion(false) { qRegisterMetaType("Compositor::SuspendReason"); - connect(&compositeResetTimer, SIGNAL(timeout()), SLOT(restart())); + connect(&compositeResetTimer, &QTimer::timeout, this, &Compositor::restart); connect(options, &Options::configChanged, this, &Compositor::slotConfigChanged); compositeResetTimer.setSingleShot(true); m_monotonicClock.start(); @@ -120,11 +120,11 @@ m_releaseSelectionTimer.setSingleShot(true); m_releaseSelectionTimer.setInterval(compositorLostMessageDelay); - connect(&m_releaseSelectionTimer, SIGNAL(timeout()), SLOT(releaseCompositorSelection())); + connect(&m_releaseSelectionTimer, &QTimer::timeout, this, &Compositor::releaseCompositorSelection); m_unusedSupportPropertyTimer.setInterval(compositorLostMessageDelay); m_unusedSupportPropertyTimer.setSingleShot(true); - connect(&m_unusedSupportPropertyTimer, SIGNAL(timeout()), SLOT(deleteUnusedSupportProperties())); + connect(&m_unusedSupportPropertyTimer, &QTimer::timeout, this, &Compositor::deleteUnusedSupportProperties); // delay the call to setup by one event cycle // The ctor of this class is invoked from the Workspace ctor, that means before @@ -340,7 +340,7 @@ scheduleRepaint(); kwinApp()->platform()->createEffectsHandler(this, m_scene); // sets also the 'effects' pointer connect(Workspace::self(), &Workspace::deletedRemoved, m_scene, &Scene::removeToplevel); - connect(effects, SIGNAL(screenGeometryChanged(QSize)), SLOT(addRepaintFull())); + connect(effects, &EffectsHandler::screenGeometryChanged, this, &Compositor::addRepaintFull); addRepaintFull(); foreach (Client * c, Workspace::self()->clientList()) { c->setupCompositing(); @@ -523,7 +523,7 @@ } // for the shortcut -void Compositor::slotToggleCompositing() +void Compositor::toggleCompositing() { if (kwinApp()->platform()->requiresCompositing()) { // we are not allowed to turn on/off compositing @@ -538,10 +538,10 @@ void Compositor::updateCompositeBlocking() { - updateCompositeBlocking(NULL); + updateClientCompositeBlocking(NULL); } -void Compositor::updateCompositeBlocking(Client *c) +void Compositor::updateClientCompositeBlocking(Client *c) { if (kwinApp()->platform()->requiresCompositing()) { return; @@ -597,7 +597,7 @@ { if (hasScene()) { finish(); - QTimer::singleShot(0, this, SLOT(setup())); + QTimer::singleShot(0, this, &Compositor::setup); } } diff --git a/dbusinterface.h b/dbusinterface.h --- a/dbusinterface.h +++ b/dbusinterface.h @@ -165,6 +165,12 @@ * @see isOpenGLBroken **/ void resume(); + /** + * @brief Used by Compositing KCM after settings change. + * + * On signal Compositor reloads settings and restarts. + */ + void reinitialize(); Q_SIGNALS: void compositingToggled(bool active); diff --git a/dbusinterface.cpp b/dbusinterface.cpp --- a/dbusinterface.cpp +++ b/dbusinterface.cpp @@ -257,7 +257,7 @@ QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject(QStringLiteral("/Compositor"), this); dbus.connect(QString(), QStringLiteral("/Compositor"), QStringLiteral("org.kde.kwin.Compositing"), - QStringLiteral("reinit"), m_compositor, SLOT(slotReinitialize())); + QStringLiteral("reinit"), this, SLOT(reinitialize())); } QString CompositorDBusInterface::compositingNotPossibleReason() const @@ -317,6 +317,11 @@ m_compositor->suspend(Compositor::ScriptSuspend); } +void CompositorDBusInterface::reinitialize() +{ + m_compositor->slotReinitialize(); +} + QStringList CompositorDBusInterface::supportedOpenGLPlatformInterfaces() const { QStringList interfaces; diff --git a/kwinbindings.cpp b/kwinbindings.cpp --- a/kwinbindings.cpp +++ b/kwinbindings.cpp @@ -159,7 +159,7 @@ DEF(I18N_NOOP("Switch to Previous Screen"), 0, slotSwitchToPrevScreen); DEF(I18N_NOOP("Kill Window"), Qt::CTRL + Qt::ALT + Qt::Key_Escape, slotKillWindow); -DEF6(I18N_NOOP("Suspend Compositing"), Qt::SHIFT + Qt::ALT + Qt::Key_F12, Compositor::self(), Compositor::slotToggleCompositing); +DEF6(I18N_NOOP("Suspend Compositing"), Qt::SHIFT + Qt::ALT + Qt::Key_F12, Compositor::self(), Compositor::toggleCompositing); DEF6(I18N_NOOP("Invert Screen Colors"), 0, kwinApp()->platform(), Platform::invertScreen); #undef DEF diff --git a/workspace.cpp b/workspace.cpp --- a/workspace.cpp +++ b/workspace.cpp @@ -586,7 +586,7 @@ StackingUpdatesBlocker blocker(this); Client* c = new Client(); setupClientConnections(c); - connect(c, SIGNAL(blockingCompositingChanged(KWin::Client*)), m_compositor, SLOT(updateCompositeBlocking(KWin::Client*))); + connect(c, &Client::blockingCompositingChanged, m_compositor, &Compositor::updateClientCompositeBlocking); connect(c, SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)), ScreenEdges::self(), SIGNAL(checkBlocking())); if (!c->manage(w, is_mapped)) { Client::deleteClient(c); @@ -605,7 +605,7 @@ Unmanaged::deleteUnmanaged(c); return NULL; } - connect(c, SIGNAL(needsRepaint()), m_compositor, SLOT(scheduleRepaint())); + connect(c, &Unmanaged::needsRepaint, m_compositor, &Compositor::scheduleRepaint); addUnmanaged(c); emit unmanagedAdded(c); return c; @@ -737,7 +737,7 @@ stacking_order.append(c); } markXStackingOrderAsDirty(); - connect(c, SIGNAL(needsRepaint()), m_compositor, SLOT(scheduleRepaint())); + connect(c, &Deleted::needsRepaint, m_compositor, &Compositor::scheduleRepaint); } void Workspace::removeDeleted(Deleted* c)