diff --git a/bridge.cpp b/bridge.cpp index 3cc7c1be71..670063e227 100644 --- a/bridge.cpp +++ b/bridge.cpp @@ -217,7 +217,7 @@ void Bridge::grabXServer(bool grab) bool Bridge::compositingActive() const { if (c->workspace()->compositor()) { - return c->workspace()->compositor()->compositingActive(); + return c->workspace()->compositor()->isActive(); } return false; } diff --git a/client.cpp b/client.cpp index 1128d12a90..e6347d04c7 100644 --- a/client.cpp +++ b/client.cpp @@ -613,7 +613,7 @@ void Client::resizeDecorationPixmaps() XFreePixmap(display(), decorationPixmapTop.handle()); } - if (workspace()->compositor() && workspace()->compositor()->compositingActive() && effects->compositingType() == OpenGLCompositing) { + if (workspace()->compositor() && workspace()->compositor()->isActive() && effects->compositingType() == OpenGLCompositing) { decorationPixmapTop = QPixmap(tr.size()); m_responsibleForDecoPixmap = false; } else { @@ -632,7 +632,7 @@ void Client::resizeDecorationPixmaps() XFreePixmap(display(), decorationPixmapBottom.handle()); } - if (workspace()->compositor() && workspace()->compositor()->compositingActive() && effects->compositingType() == OpenGLCompositing) { + if (workspace()->compositor() && workspace()->compositor()->isActive() && effects->compositingType() == OpenGLCompositing) { decorationPixmapBottom = QPixmap(br.size()); m_responsibleForDecoPixmap = false; } else { @@ -651,7 +651,7 @@ void Client::resizeDecorationPixmaps() XFreePixmap(display(), decorationPixmapLeft.handle()); } - if (workspace()->compositor() && workspace()->compositor()->compositingActive() && effects->compositingType() == OpenGLCompositing) { + if (workspace()->compositor() && workspace()->compositor()->isActive() && effects->compositingType() == OpenGLCompositing) { decorationPixmapLeft = QPixmap(lr.size()); m_responsibleForDecoPixmap = false; } else { @@ -670,7 +670,7 @@ void Client::resizeDecorationPixmaps() XFreePixmap(display(), decorationPixmapRight.handle()); } - if (workspace()->compositor() && workspace()->compositor()->compositingActive() && effects->compositingType() == OpenGLCompositing) { + if (workspace()->compositor() && workspace()->compositor()->isActive() && effects->compositingType() == OpenGLCompositing) { decorationPixmapRight = QPixmap(rr.size()); m_responsibleForDecoPixmap = false; } else { diff --git a/composite.cpp b/composite.cpp index ccf7ad4de7..83218b9277 100644 --- a/composite.cpp +++ b/composite.cpp @@ -85,37 +85,37 @@ extern int currentRefreshRate(); Compositor::Compositor(QObject* workspace) : QObject(workspace) - , compositingSuspended(!options->isUseCompositing()) - , compositingBlocked(false) + , m_suspended(!options->isUseCompositing()) + , m_blocked(false) , m_xrrRefreshRate(0) , m_scene(NULL) { connect(&unredirectTimer, SIGNAL(timeout()), SLOT(delayedCheckUnredirect())); - connect(&compositeResetTimer, SIGNAL(timeout()), SLOT(resetCompositing())); + connect(&compositeResetTimer, SIGNAL(timeout()), SLOT(restart())); connect(workspace, SIGNAL(configChanged()), SLOT(slotConfigChanged())); connect(workspace, SIGNAL(reinitializeCompositing()), SLOT(slotReinitialize())); connect(&mousePollingTimer, SIGNAL(timeout()), SLOT(performMousePoll())); unredirectTimer.setSingleShot(true); compositeResetTimer.setSingleShot(true); nextPaintReference.invalidate(); // Initialize the timer - // delay the call to setupCompositing by one event cycle + // delay the call to setup by one event cycle // The ctor of this class is invoked from the Workspace ctor, that means before // Workspace is completely constructed, so calling Workspace::self() would result // in undefined behavior. This is fixed by using a delayed invocation. - QMetaObject::invokeMethod(this, "setupCompositing", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "setup", Qt::QueuedConnection); } Compositor::~Compositor() { - finishCompositing(); + finish(); } -void Compositor::setupCompositing() +void Compositor::setup() { if (hasScene()) return; - if (compositingSuspended) { + if (m_suspended) { kDebug(1212) << "Compositing is suspended"; return; } else if (!CompositingPrefs::compositingPossible()) { @@ -235,11 +235,11 @@ void Compositor::checkCompositeTimer() setCompositeTimer(); } -void Compositor::finishCompositing() +void Compositor::finish() { if (!hasScene()) return; - m_finishingCompositing = true; + m_finishing = true; delete cm_selection; foreach (Client * c, Workspace::self()->clientList()) m_scene->windowClosed(c, NULL); @@ -277,13 +277,13 @@ void Compositor::finishCompositing() // discard all Deleted windows (#152914) while (!Workspace::self()->deletedList().isEmpty()) Workspace::self()->deletedList().first()->discard(Allowed); - m_finishingCompositing = false; + m_finishing = false; } // OpenGL self-check failed, fallback to XRender void Compositor::fallbackToXRenderCompositing() { - finishCompositing(); + finish(); KConfigGroup config(KGlobal::config(), "Compositing"); config.writeEntry("Backend", "XRender"); config.writeEntry("GraphicsSystem", "native"); @@ -293,7 +293,7 @@ void Compositor::fallbackToXRenderCompositing() return; } else { options->setCompositingMode(XRenderCompositing); - setupCompositing(); + setup(); } } @@ -305,36 +305,36 @@ void Compositor::lostCMSelection() void Compositor::slotConfigChanged() { - if (!compositingSuspended) { - setupCompositing(); + if (!m_suspended) { + setup(); if (effects) // setupCompositing() may fail effects->reconfigure(); addRepaintFull(); } else - finishCompositing(); + finish(); } void Compositor::slotReinitialize() { // Restart compositing - finishCompositing(); + finish(); // resume compositing if suspended - compositingSuspended = false; + m_suspended = false; options->setCompositingInitialized(false); - setupCompositing(); + setup(); } // for the shortcut void Compositor::slotToggleCompositing() { - suspendCompositing(!compositingSuspended); + suspendResume(!m_suspended); } // for the dbus call void Compositor::toggleCompositing() { slotToggleCompositing(); - if (compositingSuspended) { + if (m_suspended) { // when disabled show a shortcut how the user can get back compositing QString shortcut, message; if (KAction* action = qobject_cast(Workspace::self()->actionCollection()->action("Suspend Compositing"))) @@ -359,13 +359,13 @@ void Compositor::updateCompositeBlocking(Client *c) { if (c) { // if c == 0 we just check if we can resume if (c->isBlockingCompositing()) { - if (!compositingBlocked) // do NOT attempt to call suspendCompositing(true); from within the eventchain! + if (!m_blocked) // do NOT attempt to call suspend(true); from within the eventchain! QMetaObject::invokeMethod(this, "slotToggleCompositing", Qt::QueuedConnection); - compositingBlocked = true; + m_blocked = true; } } - else if (compositingBlocked) { // lost a client and we're blocked - can we resume? - // NOTICE do NOT check for "compositingSuspended" or "!compositing()" + else if (m_blocked) { // lost a client and we're blocked - can we resume? + // NOTICE do NOT check for "m_Suspended" or "!compositing()" // only "resume" if it was really disabled for a block bool resume = true; for (ClientList::ConstIterator it = Workspace::self()->clientList().constBegin(); it != Workspace::self()->clientList().constEnd(); ++it) { @@ -374,32 +374,27 @@ void Compositor::updateCompositeBlocking(Client *c) break; } } - if (resume) { // do NOT attempt to call suspendCompositing(false); from within the eventchain! - compositingBlocked = false; - if (compositingSuspended) + if (resume) { // do NOT attempt to call suspend(false); from within the eventchain! + m_blocked = false; + if (m_suspended) QMetaObject::invokeMethod(this, "slotToggleCompositing", Qt::QueuedConnection); } } } -void Compositor::suspendCompositing() +void Compositor::suspendResume(bool suspend) { - suspendCompositing(true); + m_suspended = suspend; + finish(); + setup(); // will do nothing if suspended + emit compositingToggled(!m_suspended); } -void Compositor::suspendCompositing(bool suspend) -{ - compositingSuspended = suspend; - finishCompositing(); - setupCompositing(); // will do nothing if suspended - emit compositingToggled(!compositingSuspended); -} - -void Compositor::resetCompositing() +void Compositor::restart() { if (hasScene()) { - finishCompositing(); - QTimer::singleShot(0, this, SLOT(setupCompositing())); + finish(); + QTimer::singleShot(0, this, SLOT(setup())); } } @@ -564,9 +559,9 @@ void Compositor::stopMousePolling() mousePollingTimer.stop(); } -bool Compositor::compositingActive() +bool Compositor::isActive() { - return !m_finishingCompositing && hasScene(); + return !m_finishing && hasScene(); } // force is needed when the list of windows changes (e.g. a window goes away) diff --git a/composite.h b/composite.h index 31b22425a8..f899436a56 100644 --- a/composite.h +++ b/composite.h @@ -42,20 +42,28 @@ public: void addRepaint(const QRegion& r); void addRepaint(int x, int y, int w, int h); void checkUnredirect(bool force = false); + /** + * Called from the D-Bus interface. Does the same as slotToggleCompositing with the + * addition to show a notification on how to revert the compositing state. + **/ void toggleCompositing(); void updateCompositeBlocking(Client* c = NULL); // Mouse polling void startMousePolling(); void stopMousePolling(); - bool compositingActive(); - int xrrRefreshRate() { + /** + * 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); // returns the _estimated_ delay to the next screen update // good for having a rough idea to calculate transformations, bad to rely on. // might happen few ms earlier, might be an entire frame to short. This is NOT deterministic. - int nextFrameDelay() { + int nextFrameDelay() const { return m_nextFrameDelay; } bool hasScene() const { @@ -85,10 +93,14 @@ public: public Q_SLOTS: void addRepaintFull(); + /** + * 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 + **/ void slotToggleCompositing(); - void suspendCompositing(); - void suspendCompositing(bool suspend); - void resetCompositing(); Q_SIGNALS: void compositingToggled(bool active); @@ -98,12 +110,17 @@ protected: void timerEvent(QTimerEvent *te); private Q_SLOTS: - void setupCompositing(); + void setup(); /** * Called from setupCompositing() when the CompositingPrefs are ready. **/ void slotCompositingOptionsInitialized(); - void finishCompositing(); + void finish(); + /** + * Restarts the Compositor if running. + * That is the Compositor will be stopped and started again. + **/ + void restart(); void fallbackToXRenderCompositing(); void lostCMSelection(); void performCompositing(); @@ -113,10 +130,24 @@ private Q_SLOTS: void slotReinitialize(); private: + /** + * Suspends or Resumes the Compositor. + * That is stops the Scene in case of @p suspend and restores otherwise. + * @param suspend If @c true suspends the Compositor, if @c false starts the Compositor. + * TODO: split in two methods: suspend and resume + **/ + void suspendResume(bool suspend = true); void setCompositeTimer(); bool windowRepaintsPending() const; - bool compositingSuspended, compositingBlocked; + /** + * Whether the Compositor is currently suspended. + **/ + bool m_suspended; + /** + * Whether the Compositor is currently blocked by at least one Client requesting full resources. + **/ + bool m_blocked; QBasicTimer compositeTimer; KSelectionOwner* cm_selection; uint vBlankInterval, fpsInterval; @@ -128,7 +159,7 @@ private: QTimer unredirectTimer; bool forceUnredirectCheck; QTimer compositeResetTimer; // for compressing composite resets - bool m_finishingCompositing; // finishCompositing() sets this variable while shutting down + bool m_finishing; // finish() sets this variable while shutting down int m_timeSinceLastVBlank, m_nextFrameDelay; Scene *m_scene; }; diff --git a/workspace.cpp b/workspace.cpp index 4a69ef5aae..c0781c41cc 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -911,7 +911,7 @@ bool Workspace::waitForCompositingSetup() slotReconfigure(); } if (m_compositor) { - return m_compositor->compositingActive(); + return m_compositor->isActive(); } return false; } @@ -2278,7 +2278,7 @@ void Workspace::slotCompositingToggled() bool Workspace::compositingActive() { if (m_compositor) { - return m_compositor->compositingActive(); + return m_compositor->isActive(); } return false; }