2021-04-04 14:11:13 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "waylandoutput.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
WaylandOutput::WaylandOutput(Output *output, QObject *parent)
|
2021-04-04 14:11:13 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, m_platformOutput(output)
|
2021-05-02 15:45:50 +00:00
|
|
|
, m_waylandOutput(new KWaylandServer::OutputInterface(waylandServer()->display()))
|
2021-11-30 17:10:54 +00:00
|
|
|
, m_xdgOutputV1(waylandServer()->xdgOutputManagerV1()->createXdgOutput(m_waylandOutput.data(), m_waylandOutput.data()))
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
|
|
|
const QRect geometry = m_platformOutput->geometry();
|
|
|
|
|
2022-05-17 13:33:03 +00:00
|
|
|
m_waylandOutput->setTransform(output->transform());
|
2021-04-04 14:11:13 +00:00
|
|
|
m_waylandOutput->setManufacturer(output->manufacturer());
|
|
|
|
m_waylandOutput->setModel(output->model());
|
|
|
|
m_waylandOutput->setPhysicalSize(output->physicalSize());
|
2022-05-17 13:33:03 +00:00
|
|
|
m_waylandOutput->setDpmsMode(output->dpmsMode());
|
2022-04-14 12:33:28 +00:00
|
|
|
m_waylandOutput->setDpmsSupported(output->capabilities() & Output::Capability::Dpms);
|
2021-04-04 14:11:13 +00:00
|
|
|
m_waylandOutput->setGlobalPosition(geometry.topLeft());
|
|
|
|
m_waylandOutput->setScale(std::ceil(output->scale()));
|
2022-05-18 22:59:39 +00:00
|
|
|
m_waylandOutput->setMode(output->modeSize(), output->refreshRate());
|
2022-05-17 13:33:03 +00:00
|
|
|
m_waylandOutput->setSubPixel(output->subPixel());
|
2021-04-04 14:11:13 +00:00
|
|
|
|
|
|
|
m_xdgOutputV1->setName(output->name());
|
|
|
|
m_xdgOutputV1->setDescription(output->description());
|
|
|
|
m_xdgOutputV1->setLogicalPosition(geometry.topLeft());
|
|
|
|
m_xdgOutputV1->setLogicalSize(geometry.size());
|
|
|
|
|
|
|
|
m_waylandOutput->done();
|
|
|
|
m_xdgOutputV1->done();
|
|
|
|
|
|
|
|
// The dpms functionality is not part of the wl_output interface, but org_kde_kwin_dpms.
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::dpmsModeChanged,
|
2021-04-04 14:11:13 +00:00
|
|
|
this, &WaylandOutput::handleDpmsModeChanged);
|
2021-05-02 15:45:50 +00:00
|
|
|
connect(m_waylandOutput.data(), &KWaylandServer::OutputInterface::dpmsModeRequested,
|
2021-04-04 14:11:13 +00:00
|
|
|
this, &WaylandOutput::handleDpmsModeRequested);
|
|
|
|
|
|
|
|
// The timer is used to compress output updates so the wayland clients are not spammed.
|
|
|
|
m_updateTimer.setSingleShot(true);
|
|
|
|
connect(&m_updateTimer, &QTimer::timeout, this, &WaylandOutput::update);
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::currentModeChanged, this, &WaylandOutput::scheduleUpdate);
|
|
|
|
connect(output, &Output::geometryChanged, this, &WaylandOutput::scheduleUpdate);
|
|
|
|
connect(output, &Output::transformChanged, this, &WaylandOutput::scheduleUpdate);
|
|
|
|
connect(output, &Output::scaleChanged, this, &WaylandOutput::scheduleUpdate);
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KWaylandServer::OutputInterface *WaylandOutput::waylandOutput() const
|
|
|
|
{
|
2021-05-02 15:45:50 +00:00
|
|
|
return m_waylandOutput.data();
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandOutput::scheduleUpdate()
|
|
|
|
{
|
|
|
|
m_updateTimer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandOutput::update()
|
|
|
|
{
|
|
|
|
const QRect geometry = m_platformOutput->geometry();
|
|
|
|
|
|
|
|
m_waylandOutput->setGlobalPosition(geometry.topLeft());
|
|
|
|
m_waylandOutput->setScale(std::ceil(m_platformOutput->scale()));
|
2022-05-17 13:33:03 +00:00
|
|
|
m_waylandOutput->setTransform(m_platformOutput->transform());
|
2022-05-18 22:59:39 +00:00
|
|
|
m_waylandOutput->setMode(m_platformOutput->modeSize(), m_platformOutput->refreshRate());
|
2021-04-04 14:11:13 +00:00
|
|
|
|
|
|
|
m_xdgOutputV1->setLogicalPosition(geometry.topLeft());
|
|
|
|
m_xdgOutputV1->setLogicalSize(geometry.size());
|
|
|
|
|
|
|
|
m_waylandOutput->done();
|
|
|
|
m_xdgOutputV1->done();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandOutput::handleDpmsModeChanged()
|
|
|
|
{
|
2022-05-17 13:33:03 +00:00
|
|
|
m_waylandOutput->setDpmsMode(m_platformOutput->dpmsMode());
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 13:33:03 +00:00
|
|
|
void WaylandOutput::handleDpmsModeRequested(KWin::Output::DpmsMode dpmsMode)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-05-17 13:33:03 +00:00
|
|
|
m_platformOutput->setDpmsMode(dpmsMode);
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|