2021-07-21 10:11:21 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
static KWaylandServer::OutputDeviceV2Interface::Transform kwinTransformToOutputDeviceTransform(Output::Transform transform)
|
2021-07-21 10:11:21 +00:00
|
|
|
{
|
|
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::Transform>(transform);
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
static KWaylandServer::OutputDeviceV2Interface::SubPixel kwinSubPixelToOutputDeviceSubPixel(Output::SubPixel subPixel)
|
2021-07-21 10:11:21 +00:00
|
|
|
{
|
|
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::SubPixel>(subPixel);
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
static KWaylandServer::OutputDeviceV2Interface::Capabilities kwinCapabilitiesToOutputDeviceCapabilities(Output::Capabilities caps)
|
2021-07-21 10:11:21 +00:00
|
|
|
{
|
|
|
|
KWaylandServer::OutputDeviceV2Interface::Capabilities ret;
|
2022-04-14 12:33:28 +00:00
|
|
|
if (caps & Output::Capability::Overscan) {
|
2021-07-21 10:11:21 +00:00
|
|
|
ret |= KWaylandServer::OutputDeviceV2Interface::Capability::Overscan;
|
|
|
|
}
|
2022-04-14 12:33:28 +00:00
|
|
|
if (caps & Output::Capability::Vrr) {
|
2021-07-21 10:11:21 +00:00
|
|
|
ret |= KWaylandServer::OutputDeviceV2Interface::Capability::Vrr;
|
|
|
|
}
|
2022-04-14 12:33:28 +00:00
|
|
|
if (caps & Output::Capability::RgbRange) {
|
2021-08-31 14:59:06 +00:00
|
|
|
ret |= KWaylandServer::OutputDeviceV2Interface::Capability::RgbRange;
|
|
|
|
}
|
2021-07-21 10:11:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static KWaylandServer::OutputDeviceV2Interface::VrrPolicy kwinVrrPolicyToOutputDeviceVrrPolicy(RenderLoop::VrrPolicy policy)
|
|
|
|
{
|
|
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::VrrPolicy>(policy);
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
static KWaylandServer::OutputDeviceV2Interface::RgbRange kwinRgbRangeToOutputDeviceRgbRange(Output::RgbRange range)
|
2021-08-31 14:59:06 +00:00
|
|
|
{
|
|
|
|
return static_cast<KWaylandServer::OutputDeviceV2Interface::RgbRange>(range);
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
WaylandOutputDevice::WaylandOutputDevice(Output *output, QObject *parent)
|
2021-07-21 10:11:21 +00:00
|
|
|
: 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()));
|
2021-08-31 14:59:06 +00:00
|
|
|
m_outputDeviceV2->setRgbRange(kwinRgbRangeToOutputDeviceRgbRange(output->rgbRange()));
|
2021-10-25 00:05:23 +00:00
|
|
|
m_outputDeviceV2->setName(output->name());
|
2021-07-21 10:11:21 +00:00
|
|
|
|
|
|
|
updateModes(output);
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::geometryChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleGeometryChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::scaleChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleScaleChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::enabledChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleEnabledChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::transformChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleTransformChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::currentModeChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleCurrentModeChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::capabilitiesChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleCapabilitiesChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::overscanChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleOverscanChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::vrrPolicyChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleVrrPolicyChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::modesChanged,
|
2021-07-21 10:11:21 +00:00
|
|
|
this, &WaylandOutputDevice::handleModesChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::rgbRangeChanged,
|
2021-08-31 14:59:06 +00:00
|
|
|
this, &WaylandOutputDevice::handleRgbRangeChanged);
|
2021-07-21 10:11:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandOutputDevice::updateModes(Output *output)
|
2021-07-21 10:11:21 +00:00
|
|
|
{
|
|
|
|
QList<OutputDeviceModeV2Interface *> deviceModes;
|
|
|
|
|
|
|
|
const auto modes = output->modes();
|
|
|
|
deviceModes.reserve(modes.size());
|
2022-05-17 10:36:34 +00:00
|
|
|
for (const std::shared_ptr<OutputMode> &mode : modes) {
|
2021-07-21 10:11:21 +00:00
|
|
|
OutputDeviceModeV2Interface::ModeFlags flags;
|
|
|
|
|
2022-04-19 11:46:15 +00:00
|
|
|
if (output->currentMode() == mode) {
|
2021-07-21 10:11:21 +00:00
|
|
|
flags |= OutputDeviceModeV2Interface::ModeFlag::Current;
|
|
|
|
}
|
2022-04-19 11:46:15 +00:00
|
|
|
if (mode->flags() & OutputMode::Flag::Preferred) {
|
2021-07-21 10:11:21 +00:00
|
|
|
flags |= OutputDeviceModeV2Interface::ModeFlag::Preferred;
|
|
|
|
}
|
|
|
|
|
2022-04-19 11:46:15 +00:00
|
|
|
OutputDeviceModeV2Interface *deviceMode = new OutputDeviceModeV2Interface(mode->size(), mode->refreshRate(), flags);
|
2021-07-21 10:11:21 +00:00
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2021-08-31 14:59:06 +00:00
|
|
|
void WaylandOutputDevice::handleRgbRangeChanged()
|
|
|
|
{
|
|
|
|
m_outputDeviceV2->setRgbRange(kwinRgbRangeToOutputDeviceRgbRange(m_platformOutput->rgbRange()));
|
|
|
|
}
|
|
|
|
|
2021-07-21 10:11:21 +00:00
|
|
|
} // namespace KWin
|