Abstract output dpms handling
Summary: Move init and Wayland side changes of dpms modes into AbstractOutput. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, kwin Tags: #kwin Maniphest Tasks: T10016 Differential Revision: https://phabricator.kde.org/D16787
This commit is contained in:
parent
e2b1bcea1b
commit
27946199b6
5 changed files with 42 additions and 29 deletions
|
@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
// KWayland
|
||||
#include <KWayland/Server/display.h>
|
||||
#include <KWayland/Server/output_interface.h>
|
||||
#include <KWayland/Server/outputchangeset.h>
|
||||
#include <KWayland/Server/xdgoutput_interface.h>
|
||||
// KF5
|
||||
|
@ -169,10 +168,16 @@ void AbstractOutput::initWaylandOutput()
|
|||
m_waylandOutput = waylandServer()->display()->createOutput();
|
||||
createXdgOutput();
|
||||
|
||||
/*
|
||||
* add base wayland output data
|
||||
*/
|
||||
m_waylandOutput->setManufacturer(m_waylandOutputDevice->manufacturer());
|
||||
m_waylandOutput->setModel(m_waylandOutputDevice->model());
|
||||
m_waylandOutput->setPhysicalSize(rawPhysicalSize());
|
||||
|
||||
/*
|
||||
* add modes
|
||||
*/
|
||||
for(const auto &mode: m_waylandOutputDevice->modes()) {
|
||||
KWayland::Server::OutputInterface::ModeFlags flags;
|
||||
if (mode.flags & KWayland::Server::OutputDeviceInterface::ModeFlag::Current) {
|
||||
|
@ -184,6 +189,18 @@ void AbstractOutput::initWaylandOutput()
|
|||
m_waylandOutput->addMode(mode.size, flags, mode.refreshRate);
|
||||
}
|
||||
m_waylandOutput->create();
|
||||
|
||||
/*
|
||||
* set dpms
|
||||
*/
|
||||
m_waylandOutput->setDpmsSupported(m_supportsDpms);
|
||||
// set to last known mode
|
||||
m_waylandOutput->setDpmsMode(m_dpms);
|
||||
connect(m_waylandOutput.data(), &KWayland::Server::OutputInterface::dpmsModeRequested, this,
|
||||
[this] (KWayland::Server::OutputInterface::DpmsMode mode) {
|
||||
updateDpms(mode);
|
||||
}, Qt::QueuedConnection
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QSize>
|
||||
#include <QVector>
|
||||
|
||||
#include <KWayland/Server/output_interface.h>
|
||||
#include <KWayland/Server/outputdevice_interface.h>
|
||||
|
||||
namespace KWayland
|
||||
|
@ -139,6 +140,12 @@ protected:
|
|||
void setInternal(bool set) {
|
||||
m_internal = set;
|
||||
}
|
||||
void setDpmsSupported(bool set) {
|
||||
m_supportsDpms = set;
|
||||
}
|
||||
virtual void updateDpms(KWayland::Server::OutputInterface::DpmsMode mode) {
|
||||
Q_UNUSED(mode);
|
||||
}
|
||||
virtual void updateMode(int modeIndex) {
|
||||
Q_UNUSED(modeIndex);
|
||||
}
|
||||
|
@ -152,11 +159,14 @@ private:
|
|||
QPointer<KWayland::Server::XdgOutputInterface> m_xdgOutput;
|
||||
QPointer<KWayland::Server::OutputDeviceInterface> m_waylandOutputDevice;
|
||||
|
||||
KWayland::Server::OutputInterface::DpmsMode m_dpms = KWayland::Server::OutputInterface::DpmsMode::On;
|
||||
|
||||
QPoint m_globalPos;
|
||||
qreal m_scale = 1;
|
||||
QSize m_physicalSize;
|
||||
Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation;
|
||||
bool m_internal = false;
|
||||
bool m_supportsDpms = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ void DrmBackend::turnOutputsOn()
|
|||
{
|
||||
m_dpmsFilter.reset();
|
||||
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) {
|
||||
(*it)->setDpms(DrmOutput::DpmsMode::On);
|
||||
(*it)->updateDpms(KWayland::Server::OutputInterface::DpmsMode::On);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -192,11 +192,10 @@ void DrmOutput::setEnabled(bool enabled)
|
|||
return;
|
||||
}
|
||||
if (enabled) {
|
||||
setDpms(DpmsMode::On);
|
||||
updateDpms(KWayland::Server::OutputInterface::DpmsMode::On);
|
||||
initWaylandOutput();
|
||||
initDrmWaylandOutput();
|
||||
} else {
|
||||
setDpms(DpmsMode::Off);
|
||||
updateDpms(KWayland::Server::OutputInterface::DpmsMode::Off);
|
||||
delete waylandOutput().data();
|
||||
}
|
||||
waylandOutputDevice()->setEnabled(enabled ?
|
||||
|
@ -290,6 +289,7 @@ bool DrmOutput::init(drmModeConnector *connector)
|
|||
}
|
||||
|
||||
setInternal(connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP);
|
||||
setDpmsSupported(true);
|
||||
|
||||
if (internal()) {
|
||||
connect(kwinApp(), &Application::screensCreated, this,
|
||||
|
@ -329,21 +329,6 @@ void DrmOutput::initUuid()
|
|||
m_uuid = hash.result().toHex().left(10);
|
||||
}
|
||||
|
||||
void DrmOutput::initDrmWaylandOutput()
|
||||
{
|
||||
auto wlOutput = waylandOutput();
|
||||
// set dpms
|
||||
if (!m_dpms.isNull()) {
|
||||
wlOutput->setDpmsSupported(true);
|
||||
wlOutput->setDpmsMode(toWaylandDpmsMode(m_dpmsMode));
|
||||
connect(wlOutput.data(), &KWayland::Server::OutputInterface::dpmsModeRequested, this,
|
||||
[this] (KWayland::Server::OutputInterface::DpmsMode mode) {
|
||||
setDpms(fromWaylandDpmsMode(mode));
|
||||
}, Qt::QueuedConnection
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void DrmOutput::initOutputDevice(drmModeConnector *connector)
|
||||
{
|
||||
auto wlOutputDevice = waylandOutputDevice();
|
||||
|
@ -654,21 +639,23 @@ void DrmOutput::initDpms(drmModeConnector *connector)
|
|||
}
|
||||
}
|
||||
|
||||
void DrmOutput::setDpms(DrmOutput::DpmsMode mode)
|
||||
void DrmOutput::updateDpms(KWayland::Server::OutputInterface::DpmsMode mode)
|
||||
{
|
||||
if (m_dpms.isNull()) {
|
||||
return;
|
||||
}
|
||||
if (mode == m_dpmsModePending) {
|
||||
|
||||
const auto drmMode = fromWaylandDpmsMode(mode);
|
||||
if (drmMode == m_dpmsModePending) {
|
||||
qCDebug(KWIN_DRM) << "New DPMS mode equals old mode. DPMS unchanged.";
|
||||
return;
|
||||
}
|
||||
|
||||
m_dpmsModePending = mode;
|
||||
m_dpmsModePending = drmMode;
|
||||
|
||||
if (m_backend->atomicModeSetting()) {
|
||||
m_modesetRequested = true;
|
||||
if (mode == DpmsMode::On) {
|
||||
if (drmMode == DpmsMode::On) {
|
||||
if (m_pageFlipPending) {
|
||||
m_pageFlipPending = false;
|
||||
Compositor::self()->bufferSwapComplete();
|
||||
|
@ -681,12 +668,12 @@ void DrmOutput::setDpms(DrmOutput::DpmsMode mode)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (drmModeConnectorSetProperty(m_backend->fd(), m_conn->id(), m_dpms->prop_id, uint64_t(mode)) < 0) {
|
||||
if (drmModeConnectorSetProperty(m_backend->fd(), m_conn->id(), m_dpms->prop_id, uint64_t(drmMode)) < 0) {
|
||||
m_dpmsModePending = m_dpmsMode;
|
||||
qCWarning(KWIN_DRM) << "Setting DPMS failed";
|
||||
return;
|
||||
}
|
||||
if (mode == DpmsMode::On) {
|
||||
if (drmMode == DpmsMode::On) {
|
||||
dpmsOnHandler();
|
||||
} else {
|
||||
dpmsOffHandler();
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
|
||||
/**
|
||||
* Enable or disable the output.
|
||||
* This differs from setDpms as it also
|
||||
* This differs from updateDpms as it also
|
||||
* removes the wl_output
|
||||
* The default is on
|
||||
*/
|
||||
|
@ -83,7 +83,6 @@ public:
|
|||
Suspend = DRM_MODE_DPMS_SUSPEND,
|
||||
Off = DRM_MODE_DPMS_OFF
|
||||
};
|
||||
void setDpms(DpmsMode mode);
|
||||
bool isDpmsEnabled() const {
|
||||
// We care for current as well as pending mode in order to allow first present in AMS.
|
||||
return m_dpmsModePending == DpmsMode::On;
|
||||
|
@ -119,7 +118,6 @@ private:
|
|||
void initEdid(drmModeConnector *connector);
|
||||
void initDpms(drmModeConnector *connector);
|
||||
void initOutputDevice(drmModeConnector *connector);
|
||||
void initDrmWaylandOutput();
|
||||
|
||||
bool isCurrentMode(const drmModeModeInfo *mode) const;
|
||||
void initUuid();
|
||||
|
@ -130,6 +128,7 @@ private:
|
|||
void dpmsOffHandler();
|
||||
bool dpmsAtomicOff();
|
||||
bool atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable);
|
||||
void updateDpms(KWayland::Server::OutputInterface::DpmsMode mode) override;
|
||||
void updateMode(int modeIndex) override;
|
||||
void setWaylandMode();
|
||||
|
||||
|
|
Loading…
Reference in a new issue