8e7a8c5a11
AbstractOutput is not so Abstract and it's common to avoid the word "Abstract" in class names as it doesn't contribute any new information. It also significantly reduces the line width in some places.
169 lines
6.2 KiB
C++
169 lines
6.2 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
SPDX-FileCopyrightText: 2021 Méven Car <meven.car@enioka.com>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "waylandoutputdevicev2.h"
|
|
#include "wayland_server.h"
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
static KWaylandServer::OutputDeviceV2Interface::Transform kwinTransformToOutputDeviceTransform(Output::Transform transform)
|
|
{
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::Transform>(transform);
|
|
}
|
|
|
|
static KWaylandServer::OutputDeviceV2Interface::SubPixel kwinSubPixelToOutputDeviceSubPixel(Output::SubPixel subPixel)
|
|
{
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::SubPixel>(subPixel);
|
|
}
|
|
|
|
static KWaylandServer::OutputDeviceV2Interface::Capabilities kwinCapabilitiesToOutputDeviceCapabilities(Output::Capabilities caps)
|
|
{
|
|
KWaylandServer::OutputDeviceV2Interface::Capabilities ret;
|
|
if (caps & Output::Capability::Overscan) {
|
|
ret |= KWaylandServer::OutputDeviceV2Interface::Capability::Overscan;
|
|
}
|
|
if (caps & Output::Capability::Vrr) {
|
|
ret |= KWaylandServer::OutputDeviceV2Interface::Capability::Vrr;
|
|
}
|
|
if (caps & Output::Capability::RgbRange) {
|
|
ret |= KWaylandServer::OutputDeviceV2Interface::Capability::RgbRange;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static KWaylandServer::OutputDeviceV2Interface::VrrPolicy kwinVrrPolicyToOutputDeviceVrrPolicy(RenderLoop::VrrPolicy policy)
|
|
{
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::VrrPolicy>(policy);
|
|
}
|
|
|
|
static KWaylandServer::OutputDeviceV2Interface::RgbRange kwinRgbRangeToOutputDeviceRgbRange(Output::RgbRange range)
|
|
{
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::RgbRange>(range);
|
|
}
|
|
|
|
WaylandOutputDevice::WaylandOutputDevice(Output *output, QObject *parent)
|
|
: QObject(parent)
|
|
, m_platformOutput(output)
|
|
, m_outputDeviceV2(new KWaylandServer::OutputDeviceV2Interface(waylandServer()->display()))
|
|
{
|
|
m_outputDeviceV2->setManufacturer(output->manufacturer());
|
|
m_outputDeviceV2->setEdid(output->edid());
|
|
m_outputDeviceV2->setUuid(output->uuid());
|
|
m_outputDeviceV2->setModel(output->model());
|
|
m_outputDeviceV2->setPhysicalSize(output->physicalSize());
|
|
m_outputDeviceV2->setGlobalPosition(output->geometry().topLeft());
|
|
m_outputDeviceV2->setScale(output->scale());
|
|
m_outputDeviceV2->setTransform(kwinTransformToOutputDeviceTransform(output->transform()));
|
|
m_outputDeviceV2->setEisaId(output->eisaId());
|
|
m_outputDeviceV2->setSerialNumber(output->serialNumber());
|
|
m_outputDeviceV2->setSubPixel(kwinSubPixelToOutputDeviceSubPixel(output->subPixel()));
|
|
m_outputDeviceV2->setOverscan(output->overscan());
|
|
m_outputDeviceV2->setCapabilities(kwinCapabilitiesToOutputDeviceCapabilities(output->capabilities()));
|
|
m_outputDeviceV2->setVrrPolicy(kwinVrrPolicyToOutputDeviceVrrPolicy(output->vrrPolicy()));
|
|
m_outputDeviceV2->setRgbRange(kwinRgbRangeToOutputDeviceRgbRange(output->rgbRange()));
|
|
m_outputDeviceV2->setName(output->name());
|
|
|
|
updateModes(output);
|
|
|
|
connect(output, &Output::geometryChanged,
|
|
this, &WaylandOutputDevice::handleGeometryChanged);
|
|
connect(output, &Output::scaleChanged,
|
|
this, &WaylandOutputDevice::handleScaleChanged);
|
|
connect(output, &Output::enabledChanged,
|
|
this, &WaylandOutputDevice::handleEnabledChanged);
|
|
connect(output, &Output::transformChanged,
|
|
this, &WaylandOutputDevice::handleTransformChanged);
|
|
connect(output, &Output::currentModeChanged,
|
|
this, &WaylandOutputDevice::handleCurrentModeChanged);
|
|
connect(output, &Output::capabilitiesChanged,
|
|
this, &WaylandOutputDevice::handleCapabilitiesChanged);
|
|
connect(output, &Output::overscanChanged,
|
|
this, &WaylandOutputDevice::handleOverscanChanged);
|
|
connect(output, &Output::vrrPolicyChanged,
|
|
this, &WaylandOutputDevice::handleVrrPolicyChanged);
|
|
connect(output, &Output::modesChanged,
|
|
this, &WaylandOutputDevice::handleModesChanged);
|
|
connect(output, &Output::rgbRangeChanged,
|
|
this, &WaylandOutputDevice::handleRgbRangeChanged);
|
|
}
|
|
|
|
void WaylandOutputDevice::updateModes(Output *output)
|
|
{
|
|
QList<OutputDeviceModeV2Interface *> deviceModes;
|
|
|
|
const auto modes = output->modes();
|
|
deviceModes.reserve(modes.size());
|
|
for (const Output::Mode &mode : modes) {
|
|
OutputDeviceModeV2Interface::ModeFlags flags;
|
|
|
|
if (mode.flags & Output::ModeFlag::Current) {
|
|
flags |= OutputDeviceModeV2Interface::ModeFlag::Current;
|
|
}
|
|
if (mode.flags & Output::ModeFlag::Preferred) {
|
|
flags |= OutputDeviceModeV2Interface::ModeFlag::Preferred;
|
|
}
|
|
|
|
OutputDeviceModeV2Interface *deviceMode = new OutputDeviceModeV2Interface(mode.size, mode.refreshRate, flags);
|
|
deviceModes << deviceMode;
|
|
}
|
|
m_outputDeviceV2->setModes(deviceModes);
|
|
}
|
|
|
|
void WaylandOutputDevice::handleModesChanged()
|
|
{
|
|
updateModes(m_platformOutput);
|
|
}
|
|
|
|
void WaylandOutputDevice::handleGeometryChanged()
|
|
{
|
|
m_outputDeviceV2->setGlobalPosition(m_platformOutput->geometry().topLeft());
|
|
}
|
|
|
|
void WaylandOutputDevice::handleScaleChanged()
|
|
{
|
|
m_outputDeviceV2->setScale(m_platformOutput->scale());
|
|
}
|
|
|
|
void WaylandOutputDevice::handleEnabledChanged()
|
|
{
|
|
m_outputDeviceV2->setEnabled(m_platformOutput->isEnabled());
|
|
}
|
|
|
|
void WaylandOutputDevice::handleTransformChanged()
|
|
{
|
|
m_outputDeviceV2->setTransform(kwinTransformToOutputDeviceTransform(m_platformOutput->transform()));
|
|
}
|
|
|
|
void WaylandOutputDevice::handleCurrentModeChanged()
|
|
{
|
|
m_outputDeviceV2->setCurrentMode(m_platformOutput->modeSize(), m_platformOutput->refreshRate());
|
|
}
|
|
|
|
void WaylandOutputDevice::handleCapabilitiesChanged()
|
|
{
|
|
m_outputDeviceV2->setCapabilities(kwinCapabilitiesToOutputDeviceCapabilities(m_platformOutput->capabilities()));
|
|
}
|
|
|
|
void WaylandOutputDevice::handleOverscanChanged()
|
|
{
|
|
m_outputDeviceV2->setOverscan(m_platformOutput->overscan());
|
|
}
|
|
|
|
void WaylandOutputDevice::handleVrrPolicyChanged()
|
|
{
|
|
m_outputDeviceV2->setVrrPolicy(kwinVrrPolicyToOutputDeviceVrrPolicy(m_platformOutput->vrrPolicy()));
|
|
}
|
|
|
|
void WaylandOutputDevice::handleRgbRangeChanged()
|
|
{
|
|
m_outputDeviceV2->setRgbRange(kwinRgbRangeToOutputDeviceRgbRange(m_platformOutput->rgbRange()));
|
|
}
|
|
|
|
} // namespace KWin
|