Drop Platform::{outputEnabled,outputDisabled} signals

Use Output::enabledChanged signal to determine if an output is enabled
or disabled.
This commit is contained in:
Vlad Zahorodnii 2022-07-30 15:34:13 +03:00
parent f956d701c4
commit ace5b58f7a
15 changed files with 11 additions and 99 deletions

View file

@ -110,8 +110,10 @@ void DrmBackend::createDpmsFilter()
void DrmBackend::turnOutputsOn() void DrmBackend::turnOutputsOn()
{ {
m_dpmsFilter.reset(); m_dpmsFilter.reset();
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) { for (Output *output : std::as_const(m_outputs)) {
(*it)->setDpmsMode(Output::DpmsMode::On); if (output->isEnabled()) {
output->setDpmsMode(Output::DpmsMode::On);
}
} }
} }
@ -121,8 +123,8 @@ void DrmBackend::checkOutputsAreOn()
// already disabled, all outputs are on // already disabled, all outputs are on
return; return;
} }
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) { for (Output *output : std::as_const(m_outputs)) {
if ((*it)->dpmsMode() != Output::DpmsMode::On) { if (output->isEnabled() && output->dpmsMode() != Output::DpmsMode::On) {
// dpms still disabled, need to keep the filter // dpms still disabled, need to keep the filter
return; return;
} }
@ -355,12 +357,7 @@ void DrmBackend::updateOutputs()
void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable) void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable)
{ {
if (m_enabledOutputs.contains(output) == enable) {
return;
}
if (enable) { if (enable) {
m_enabledOutputs << output;
Q_EMIT outputEnabled(output);
checkOutputsAreOn(); checkOutputsAreOn();
if (m_placeHolderOutput && !output->isNonDesktop()) { if (m_placeHolderOutput && !output->isNonDesktop()) {
qCDebug(KWIN_DRM) << "removing placeholder output"; qCDebug(KWIN_DRM) << "removing placeholder output";
@ -369,19 +366,17 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable)
m_placeholderFilter.reset(); m_placeholderFilter.reset();
} }
} else { } else {
int normalOutputsCount = std::count_if(m_enabledOutputs.begin(), m_enabledOutputs.end(), [](const auto output) { const int normalOutputsCount = std::count_if(m_outputs.constBegin(), m_outputs.constEnd(), [](const auto output) {
return !output->isNonDesktop(); return output->isEnabled() && !output->isNonDesktop();
}); });
if (normalOutputsCount == 1 && !output->isNonDesktop() && !kwinApp()->isTerminating()) { if (normalOutputsCount == 0 && !output->isNonDesktop() && !kwinApp()->isTerminating()) {
qCDebug(KWIN_DRM) << "adding placeholder output"; qCDebug(KWIN_DRM) << "adding placeholder output";
m_placeHolderOutput = primaryGpu()->createVirtualOutput({}, m_enabledOutputs.constFirst()->pixelSize(), 1, DrmVirtualOutput::Type::Placeholder); m_placeHolderOutput = primaryGpu()->createVirtualOutput({}, output->pixelSize(), 1, DrmVirtualOutput::Type::Placeholder);
// placeholder doesn't actually need to render anything // placeholder doesn't actually need to render anything
m_placeHolderOutput->renderLoop()->inhibit(); m_placeHolderOutput->renderLoop()->inhibit();
m_placeholderFilter = std::make_unique<PlaceholderInputEventFilter>(); m_placeholderFilter = std::make_unique<PlaceholderInputEventFilter>();
input()->prependInputEventFilter(m_placeholderFilter.get()); input()->prependInputEventFilter(m_placeholderFilter.get());
} }
m_enabledOutputs.removeOne(output);
Q_EMIT outputDisabled(output);
} }
} }

View file

@ -102,10 +102,7 @@ private:
std::unique_ptr<Udev> m_udev; std::unique_ptr<Udev> m_udev;
std::unique_ptr<UdevMonitor> m_udevMonitor; std::unique_ptr<UdevMonitor> m_udevMonitor;
Session *m_session; Session *m_session;
// all outputs, enabled and disabled
QVector<DrmAbstractOutput *> m_outputs; QVector<DrmAbstractOutput *> m_outputs;
// only enabled outputs
QVector<DrmAbstractOutput *> m_enabledOutputs;
DrmVirtualOutput *m_placeHolderOutput = nullptr; DrmVirtualOutput *m_placeHolderOutput = nullptr;
bool m_active = false; bool m_active = false;

View file

@ -91,7 +91,6 @@ void VirtualBackend::setVirtualOutputs(int count, QVector<QRect> geometries, QVe
Q_ASSERT(geometries.size() == 0 || geometries.size() == count); Q_ASSERT(geometries.size() == 0 || geometries.size() == count);
Q_ASSERT(scales.size() == 0 || scales.size() == count); Q_ASSERT(scales.size() == 0 || scales.size() == count);
const QVector<VirtualOutput *> disabled = m_outputsEnabled;
const QVector<VirtualOutput *> removed = m_outputs; const QVector<VirtualOutput *> removed = m_outputs;
int sumWidth = 0; int sumWidth = 0;
@ -112,11 +111,8 @@ void VirtualBackend::setVirtualOutputs(int count, QVector<QRect> geometries, QVe
vo->setEnabled(true); vo->setEnabled(true);
} }
for (VirtualOutput *output : disabled) {
output->setEnabled(false);
}
for (VirtualOutput *output : removed) { for (VirtualOutput *output : removed) {
output->setEnabled(false);
m_outputs.removeOne(output); m_outputs.removeOne(output);
Q_EMIT outputRemoved(output); Q_EMIT outputRemoved(output);
delete output; delete output;
@ -125,19 +121,6 @@ void VirtualBackend::setVirtualOutputs(int count, QVector<QRect> geometries, QVe
Q_EMIT screensQueried(); Q_EMIT screensQueried();
} }
void VirtualBackend::enableOutput(VirtualOutput *output, bool enable)
{
if (enable) {
Q_ASSERT(!m_outputsEnabled.contains(output));
m_outputsEnabled << output;
Q_EMIT outputEnabled(output);
} else {
Q_ASSERT(m_outputsEnabled.contains(output));
m_outputsEnabled.removeOne(output);
Q_EMIT outputDisabled(output);
}
}
void VirtualBackend::removeOutput(Output *output) void VirtualBackend::removeOutput(Output *output)
{ {
VirtualOutput *virtualOutput = static_cast<VirtualOutput *>(output); VirtualOutput *virtualOutput = static_cast<VirtualOutput *>(output);

View file

@ -53,8 +53,6 @@ public:
return QVector<CompositingType>{OpenGLCompositing, QPainterCompositing}; return QVector<CompositingType>{OpenGLCompositing, QPainterCompositing};
} }
void enableOutput(VirtualOutput *output, bool enable);
Q_INVOKABLE void removeOutput(Output *output); Q_INVOKABLE void removeOutput(Output *output);
Q_INVOKABLE QImage captureOutput(Output *output) const; Q_INVOKABLE QImage captureOutput(Output *output) const;
@ -63,7 +61,6 @@ Q_SIGNALS:
private: private:
QVector<VirtualOutput *> m_outputs; QVector<VirtualOutput *> m_outputs;
QVector<VirtualOutput *> m_outputsEnabled;
std::unique_ptr<QTemporaryDir> m_screenshotDir; std::unique_ptr<QTemporaryDir> m_screenshotDir;
}; };

View file

@ -66,9 +66,4 @@ void VirtualOutput::vblank(std::chrono::nanoseconds timestamp)
renderLoopPrivate->notifyFrameCompleted(timestamp); renderLoopPrivate->notifyFrameCompleted(timestamp);
} }
void VirtualOutput::updateEnablement(bool enable)
{
m_backend->enableOutput(this, enable);
}
} }

View file

@ -32,7 +32,6 @@ public:
void init(const QPoint &logicalPosition, const QSize &pixelSize); void init(const QPoint &logicalPosition, const QSize &pixelSize);
void setGeometry(const QRect &geo); void setGeometry(const QRect &geo);
void updateEnablement(bool enable) override;
private: private:
void vblank(std::chrono::nanoseconds timestamp); void vblank(std::chrono::nanoseconds timestamp);

View file

@ -71,15 +71,6 @@ void WaylandOutput::resize(const QSize &pixelSize)
Q_EMIT m_backend->screensQueried(); Q_EMIT m_backend->screensQueried();
} }
void WaylandOutput::updateEnablement(bool enable)
{
if (enable) {
Q_EMIT m_backend->outputEnabled(this);
} else {
Q_EMIT m_backend->outputDisabled(this);
}
}
void WaylandOutput::setDpmsMode(DpmsMode mode) void WaylandOutput::setDpmsMode(DpmsMode mode)
{ {
if (mode == DpmsMode::Off) { if (mode == DpmsMode::Off) {

View file

@ -64,7 +64,6 @@ public:
return m_surface; return m_surface;
} }
void updateEnablement(bool enable) override;
void setDpmsMode(DpmsMode mode) override; void setDpmsMode(DpmsMode mode) override;
Q_SIGNALS: Q_SIGNALS:

View file

@ -72,13 +72,4 @@ void X11Output::setMode(const QSize &size, uint32_t refreshRate)
} }
} }
void X11Output::updateEnablement(bool enabled)
{
if (enabled) {
Q_EMIT m_backend->outputEnabled(this);
} else {
Q_EMIT m_backend->outputDisabled(this);
}
}
} // namespace KWin } // namespace KWin

View file

@ -33,7 +33,6 @@ public:
explicit X11Output(X11StandalonePlatform *backend, QObject *parent = nullptr); explicit X11Output(X11StandalonePlatform *backend, QObject *parent = nullptr);
bool usesSoftwareCursor() const override; bool usesSoftwareCursor() const override;
void updateEnablement(bool enabled) override;
RenderLoop *renderLoop() const override; RenderLoop *renderLoop() const override;
void setRenderLoop(RenderLoop *loop); void setRenderLoop(RenderLoop *loop);

View file

@ -34,13 +34,4 @@ RenderLoop *X11PlaceholderOutput::renderLoop() const
return m_backend->renderLoop(); return m_backend->renderLoop();
} }
void X11PlaceholderOutput::updateEnablement(bool enabled)
{
if (enabled) {
Q_EMIT m_backend->outputEnabled(this);
} else {
Q_EMIT m_backend->outputDisabled(this);
}
}
} // namespace KWin } // namespace KWin

View file

@ -23,8 +23,6 @@ public:
RenderLoop *renderLoop() const override; RenderLoop *renderLoop() const override;
private: private:
void updateEnablement(bool enabled) override;
X11StandalonePlatform *m_backend; X11StandalonePlatform *m_backend;
}; };

View file

@ -194,13 +194,4 @@ bool X11WindowedOutput::usesSoftwareCursor() const
return false; return false;
} }
void X11WindowedOutput::updateEnablement(bool enabled)
{
if (enabled) {
Q_EMIT m_backend->outputEnabled(this);
} else {
Q_EMIT m_backend->outputDisabled(this);
}
}
} // namespace KWin } // namespace KWin

View file

@ -61,7 +61,6 @@ public:
QPointF mapFromGlobal(const QPointF &pos) const; QPointF mapFromGlobal(const QPointF &pos) const;
bool usesSoftwareCursor() const override; bool usesSoftwareCursor() const override;
void updateEnablement(bool enabled) override;
QRegion exposedArea() const; QRegion exposedArea() const;
void addExposedArea(const QRect &rect); void addExposedArea(const QRect &rect);

View file

@ -340,19 +340,6 @@ Q_SIGNALS:
* This signal is emitted when an output has been disconnected. * This signal is emitted when an output has been disconnected.
*/ */
void outputRemoved(Output *output); void outputRemoved(Output *output);
/**
* This signal is emitted when the @a output has become activated and it is ready for
* compositing.
*/
void outputEnabled(Output *output);
/**
* This signal is emitted when the @a output has been deactivated and it is no longer
* being composited. The outputDisabled() signal is guaranteed to be emitted before the
* output is removed.
*
* @see outputEnabled, outputRemoved
*/
void outputDisabled(Output *output);
protected: protected:
explicit Platform(QObject *parent = nullptr); explicit Platform(QObject *parent = nullptr);