Commit b01cfb85 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

wayland: Merge WaylandOutputDeviceV2 and OutputDeviceV2Interface

parent b0423c32
Pipeline #221470 passed with stage
in 19 minutes and 58 seconds
......@@ -146,7 +146,6 @@ target_sources(kwin PRIVATE
was_user_interaction_x11_filter.cpp
wayland_server.cpp
waylandoutput.cpp
waylandoutputdevicev2.cpp
waylandshellintegration.cpp
waylandwindow.cpp
window.cpp
......
......@@ -140,19 +140,6 @@ bool Platform::applyOutputChanges(const OutputConfiguration &config)
return true;
}
Output *Platform::findOutput(const QUuid &uuid) const
{
const auto outs = outputs();
auto it = std::find_if(outs.constBegin(), outs.constEnd(),
[uuid](Output *output) {
return output->uuid() == uuid;
});
if (it != outs.constEnd()) {
return *it;
}
return nullptr;
}
Output *Platform::findOutput(const QString &name) const
{
const auto candidates = outputs();
......
......@@ -287,7 +287,6 @@ public:
}
virtual Outputs outputs() const = 0;
Output *findOutput(const QUuid &uuid) const;
Output *findOutput(const QString &name) const;
/**
......
This diff is collapsed.
......@@ -41,103 +41,39 @@ class OutputDeviceModeV2InterfacePrivate;
class KWIN_EXPORT OutputDeviceV2Interface : public QObject
{
Q_OBJECT
public:
enum class SubPixel {
Unknown,
None,
HorizontalRGB,
HorizontalBGR,
VerticalRGB,
VerticalBGR,
};
Q_ENUM(SubPixel)
enum class Transform {
Normal,
Rotated90,
Rotated180,
Rotated270,
Flipped,
Flipped90,
Flipped180,
Flipped270,
};
Q_ENUM(Transform)
enum class Capability {
Overscan = 0x1,
Vrr = 0x2,
RgbRange = 0x4,
};
Q_ENUM(Capability)
Q_DECLARE_FLAGS(Capabilities, Capability)
enum class VrrPolicy {
Never = 0,
Always = 1,
Automatic = 2
};
Q_ENUM(VrrPolicy)
enum class RgbRange {
Automatic = 0,
Full = 1,
Limited = 2,
};
Q_ENUM(RgbRange)
public:
explicit OutputDeviceV2Interface(Display *display, KWin::Output *handle, QObject *parent = nullptr);
~OutputDeviceV2Interface() override;
void remove();
KWin::Output *handle() const;
QSize physicalSize() const;
QPoint globalPosition() const;
QString manufacturer() const;
QString model() const;
QString serialNumber() const;
QString eisaId() const;
QString name() const;
QSize pixelSize() const;
int refreshRate() const;
QList<KWaylandServer::OutputDeviceModeV2Interface *> modes() const;
qreal scale() const;
SubPixel subPixel() const;
Transform transform() const;
QByteArray edid() const;
bool enabled() const;
QUuid uuid() const;
Capabilities capabilities() const;
uint32_t overscan() const;
VrrPolicy vrrPolicy() const;
RgbRange rgbRange() const;
void setPhysicalSize(const QSize &size);
void setGlobalPosition(const QPoint &pos);
void setManufacturer(const QString &manufacturer);
void setModel(const QString &model);
void setSerialNumber(const QString &serialNumber);
void setEisaId(const QString &eisaId);
void setName(const QString &name);
void setScale(qreal scale);
void setSubPixel(SubPixel subPixel);
void setTransform(Transform transform);
void setModes(const QList<KWaylandServer::OutputDeviceModeV2Interface *> &modes, KWaylandServer::OutputDeviceModeV2Interface *currentMode);
void setCurrentMode(KWaylandServer::OutputDeviceModeV2Interface *mode);
void setEdid(const QByteArray &edid);
void setEnabled(bool enabled);
void setUuid(const QUuid &uuid);
void setCapabilities(Capabilities cap);
void setOverscan(uint32_t overscan);
void setVrrPolicy(VrrPolicy policy);
void setRgbRange(RgbRange rgbRange);
wl_resource *resource() const;
static OutputDeviceV2Interface *get(wl_resource *native);
private:
void updatePhysicalSize();
void updateGlobalPosition();
void updateManufacturer();
void updateModel();
void updateSerialNumber();
void updateEisaId();
void updateName();
void updateScale();
void updateSubPixel();
void updateTransform();
void updateModes();
void updateCurrentMode();
void updateEdid();
void updateEnabled();
void updateUuid();
void updateCapabilities();
void updateOverscan();
void updateVrrPolicy();
void updateRgbRange();
void updateGeometry();
std::unique_ptr<OutputDeviceV2InterfacePrivate> d;
};
......@@ -151,20 +87,12 @@ private:
class KWIN_EXPORT OutputDeviceModeV2Interface : public QObject
{
Q_OBJECT
public:
enum class ModeFlag {
Preferred = 0x1,
};
Q_ENUM(ModeFlag)
Q_DECLARE_FLAGS(ModeFlags, ModeFlag)
OutputDeviceModeV2Interface(std::weak_ptr<KWin::OutputMode> handle, const QSize &size, int refreshRate, ModeFlags flags, QObject *parent = nullptr);
public:
OutputDeviceModeV2Interface(std::shared_ptr<KWin::OutputMode> handle, QObject *parent = nullptr);
~OutputDeviceModeV2Interface() override;
std::weak_ptr<KWin::OutputMode> handle() const;
QSize size() const;
int refreshRate() const;
OutputDeviceModeV2Interface::ModeFlags flags() const;
static OutputDeviceModeV2Interface *get(wl_resource *native);
......@@ -174,7 +102,3 @@ private:
};
}
Q_DECLARE_METATYPE(KWaylandServer::OutputDeviceModeV2Interface::ModeFlag)
Q_DECLARE_METATYPE(KWaylandServer::OutputDeviceV2Interface::SubPixel)
Q_DECLARE_METATYPE(KWaylandServer::OutputDeviceV2Interface::Transform)
......@@ -229,7 +229,7 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_apply(Resource
if (kwinApp()->platform()->applyOutputChanges(config)) {
if (primaryOutput.has_value() || !kwinApp()->platform()->primaryOutput()->isEnabled()) {
auto requestedPrimaryOutput = kwinApp()->platform()->findOutput((*primaryOutput)->uuid());
auto requestedPrimaryOutput = (*primaryOutput)->handle();
if (requestedPrimaryOutput && requestedPrimaryOutput->isEnabled()) {
kwinApp()->platform()->setPrimaryOutput(requestedPrimaryOutput);
} else {
......
......@@ -38,6 +38,7 @@
#include "wayland/keystate_interface.h"
#include "wayland/linuxdmabufv1clientbuffer.h"
#include "wayland/output_interface.h"
#include "wayland/outputdevice_v2_interface.h"
#include "wayland/outputmanagement_v2_interface.h"
#include "wayland/plasmashell_interface.h"
#include "wayland/plasmavirtualdesktop_interface.h"
......@@ -60,7 +61,6 @@
#include "wayland/xdgoutput_v1_interface.h"
#include "wayland/xdgshell_interface.h"
#include "waylandoutput.h"
#include "waylandoutputdevicev2.h"
#include "workspace.h"
#include "x11window.h"
#include "xdgactivationv1.h"
......@@ -274,14 +274,14 @@ void WaylandServer::registerXdgGenericWindow(Window *window)
void WaylandServer::handleOutputAdded(Output *output)
{
if (!output->isPlaceholder() && !output->isNonDesktop()) {
m_waylandOutputDevices.insert(output, new WaylandOutputDevice(output));
m_waylandOutputDevices.insert(output, new KWaylandServer::OutputDeviceV2Interface(m_display, output));
}
}
void WaylandServer::handleOutputRemoved(Output *output)
{
if (!output->isPlaceholder() && !output->isNonDesktop()) {
delete m_waylandOutputDevices.take(output);
if (auto outputDevice = m_waylandOutputDevices.take(output)) {
outputDevice->remove();
}
}
......
......@@ -39,6 +39,7 @@ class PlasmaWindowActivationFeedbackInterface;
class PlasmaVirtualDesktopManagementInterface;
class PlasmaWindowManagementInterface;
class PrimaryOutputV1Interface;
class OutputDeviceV2Interface;
class OutputManagementV2Interface;
class XdgForeignV2Interface;
class XdgOutputManagerV1Interface;
......@@ -60,7 +61,6 @@ class XdgPopupWindow;
class XdgSurfaceWindow;
class XdgToplevelWindow;
class WaylandOutput;
class WaylandOutputDevice;
class KWIN_EXPORT WaylandServer : public QObject
{
......@@ -294,7 +294,7 @@ private:
QList<Window *> m_windows;
InitializationFlags m_initFlags;
QHash<Output *, WaylandOutput *> m_waylandOutputs;
QHash<Output *, WaylandOutputDevice *> m_waylandOutputDevices;
QHash<Output *, KWaylandServer::OutputDeviceV2Interface *> m_waylandOutputDevices;
KWIN_SINGLETON(WaylandServer)
};
......
/*
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(), output))
{
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;
OutputDeviceModeV2Interface *currentMode = nullptr;
const auto modes = output->modes();
deviceModes.reserve(modes.size());
for (const std::shared_ptr<OutputMode> &mode : modes) {
OutputDeviceModeV2Interface::ModeFlags flags;
if (mode->flags() & OutputMode::Flag::Preferred) {
flags |= OutputDeviceModeV2Interface::ModeFlag::Preferred;
}
OutputDeviceModeV2Interface *deviceMode = new OutputDeviceModeV2Interface(mode, mode->size(), mode->refreshRate(), flags);
deviceModes << deviceMode;
if (output->currentMode() == mode) {
currentMode = deviceMode;
}
}
m_outputDeviceV2->setModes(deviceModes, currentMode);
}
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()
{
const auto modes = m_outputDeviceV2->modes();
for (KWaylandServer::OutputDeviceModeV2Interface *mode : modes) {
if (mode->handle().lock() == m_platformOutput->currentMode()) {
m_outputDeviceV2->setCurrentMode(mode);
break;
}
}
}
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
/*
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
*/
#pragma once
#include "output.h"
#include "wayland/outputdevice_v2_interface.h"
#include "wayland/utils.h"
namespace KWin
{
class WaylandOutputDevice : public QObject
{
Q_OBJECT
public:
explicit WaylandOutputDevice(Output *output, QObject *parent = nullptr);
private Q_SLOTS:
void handleGeometryChanged();
void handleScaleChanged();
void handleEnabledChanged();
void handleTransformChanged();
void handleCurrentModeChanged();
void handleCapabilitiesChanged();
void handleOverscanChanged();
void handleVrrPolicyChanged();
void handleModesChanged();
void handleRgbRangeChanged();
private:
void updateModes(Output *output);
Output *m_platformOutput;
KWaylandServer::ScopedGlobalPointer<KWaylandServer::OutputDeviceV2Interface> m_outputDeviceV2;
};
} // namespace KWin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment