2019-06-13 09:36:07 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright 2019 Roman Gilg <subdiff@gmail.com>
|
2020-03-23 23:04:06 +00:00
|
|
|
Copyright 2020 David Edmundson <davidedmundson@kde.org>
|
2019-06-13 09:36:07 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "abstract_wayland_output.h"
|
2020-01-02 14:55:03 +00:00
|
|
|
|
|
|
|
#include "screens.h"
|
2019-06-13 09:36:07 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
|
|
|
|
// KWayland
|
|
|
|
#include <KWayland/Server/display.h>
|
|
|
|
#include <KWayland/Server/outputchangeset.h>
|
|
|
|
#include <KWayland/Server/xdgoutput_interface.h>
|
|
|
|
// KF5
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
AbstractWaylandOutput::AbstractWaylandOutput(QObject *parent)
|
|
|
|
: AbstractOutput(parent)
|
|
|
|
{
|
2020-03-23 23:04:06 +00:00
|
|
|
m_waylandOutput = waylandServer()->display()->createOutput(this);
|
|
|
|
m_waylandOutputDevice = waylandServer()->display()->createOutputDevice(this);
|
|
|
|
m_xdgOutput = waylandServer()->xdgOutputManager()->createXdgOutput(m_waylandOutput, this);
|
|
|
|
|
|
|
|
connect(m_waylandOutput, &KWayland::Server::OutputInterface::dpmsModeRequested, this,
|
|
|
|
[this] (KWayland::Server::OutputInterface::DpmsMode mode) {
|
|
|
|
updateDpms(mode);
|
|
|
|
});
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractWaylandOutput::~AbstractWaylandOutput()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AbstractWaylandOutput::name() const
|
|
|
|
{
|
2019-08-28 20:58:21 +00:00
|
|
|
return QStringLiteral("%1 %2").arg(m_waylandOutputDevice->manufacturer()).arg(
|
|
|
|
m_waylandOutputDevice->model());
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 18:54:37 +00:00
|
|
|
QByteArray AbstractWaylandOutput::uuid() const
|
|
|
|
{
|
|
|
|
return m_waylandOutputDevice->uuid();
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
QRect AbstractWaylandOutput::geometry() const
|
|
|
|
{
|
2019-08-27 14:19:47 +00:00
|
|
|
return QRect(globalPos(), pixelSize() / scale());
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize AbstractWaylandOutput::physicalSize() const
|
|
|
|
{
|
2019-08-27 14:52:39 +00:00
|
|
|
return orientateSize(m_waylandOutputDevice->physicalSize());
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AbstractWaylandOutput::refreshRate() const
|
|
|
|
{
|
2019-08-28 20:58:21 +00:00
|
|
|
return m_waylandOutputDevice->refreshRate();
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 12:41:16 +00:00
|
|
|
QPoint AbstractWaylandOutput::globalPos() const
|
|
|
|
{
|
|
|
|
return m_waylandOutputDevice->globalPosition();
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
void AbstractWaylandOutput::setGlobalPos(const QPoint &pos)
|
|
|
|
{
|
2019-08-27 11:07:11 +00:00
|
|
|
m_waylandOutputDevice->setGlobalPosition(pos);
|
|
|
|
|
2020-03-23 23:04:06 +00:00
|
|
|
m_waylandOutput->setGlobalPosition(pos);
|
|
|
|
m_xdgOutput->setLogicalPosition(pos);
|
|
|
|
m_xdgOutput->done();
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:05 +00:00
|
|
|
QSize AbstractWaylandOutput::modeSize() const
|
|
|
|
{
|
|
|
|
return m_waylandOutputDevice->pixelSize();
|
|
|
|
}
|
|
|
|
|
2019-08-27 14:19:47 +00:00
|
|
|
QSize AbstractWaylandOutput::pixelSize() const
|
|
|
|
{
|
|
|
|
return orientateSize(m_waylandOutputDevice->pixelSize());
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:41:16 +00:00
|
|
|
qreal AbstractWaylandOutput::scale() const
|
|
|
|
{
|
|
|
|
return m_waylandOutputDevice->scaleF();
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
void AbstractWaylandOutput::setScale(qreal scale)
|
|
|
|
{
|
2019-08-27 11:07:11 +00:00
|
|
|
m_waylandOutputDevice->setScaleF(scale);
|
|
|
|
|
2020-03-23 23:04:06 +00:00
|
|
|
// this is the scale that clients will ideally use for their buffers
|
|
|
|
// this has to be an int which is fine
|
2019-06-13 09:36:07 +00:00
|
|
|
|
2020-03-23 23:04:06 +00:00
|
|
|
// I don't know whether we want to round or ceil
|
|
|
|
// or maybe even set this to 3 when we're scaling to 1.5
|
|
|
|
// don't treat this like it's chosen deliberately
|
|
|
|
m_waylandOutput->setScale(std::ceil(scale));
|
|
|
|
m_xdgOutput->setLogicalSize(pixelSize() / scale);
|
|
|
|
m_xdgOutput->done();
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 10:42:30 +00:00
|
|
|
using DeviceInterface = KWayland::Server::OutputDeviceInterface;
|
|
|
|
|
|
|
|
KWayland::Server::OutputInterface::Transform toOutputTransform(DeviceInterface::Transform transform)
|
|
|
|
{
|
|
|
|
using Transform = DeviceInterface::Transform;
|
|
|
|
using OutputTransform = KWayland::Server::OutputInterface::Transform;
|
|
|
|
|
|
|
|
switch (transform) {
|
|
|
|
case Transform::Rotated90:
|
|
|
|
return OutputTransform::Rotated90;
|
|
|
|
case Transform::Rotated180:
|
|
|
|
return OutputTransform::Rotated180;
|
|
|
|
case Transform::Rotated270:
|
|
|
|
return OutputTransform::Rotated270;
|
|
|
|
case Transform::Flipped:
|
|
|
|
return OutputTransform::Flipped;
|
|
|
|
case Transform::Flipped90:
|
|
|
|
return OutputTransform::Flipped90;
|
|
|
|
case Transform::Flipped180:
|
|
|
|
return OutputTransform::Flipped180;
|
|
|
|
case Transform::Flipped270:
|
|
|
|
return OutputTransform::Flipped270;
|
|
|
|
default:
|
|
|
|
return OutputTransform::Normal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractWaylandOutput::setTransform(DeviceInterface::Transform transform)
|
|
|
|
{
|
|
|
|
m_waylandOutputDevice->setTransform(transform);
|
|
|
|
|
2020-03-23 23:04:06 +00:00
|
|
|
m_waylandOutput->setTransform(toOutputTransform(transform));
|
|
|
|
m_xdgOutput->setLogicalSize(pixelSize() / scale());
|
|
|
|
m_xdgOutput->done();
|
2019-11-24 10:42:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 22:53:17 +00:00
|
|
|
inline
|
|
|
|
AbstractWaylandOutput::Transform toTransform(DeviceInterface::Transform deviceTransform)
|
|
|
|
{
|
|
|
|
return static_cast<AbstractWaylandOutput::Transform>(deviceTransform);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
DeviceInterface::Transform toDeviceTransform(AbstractWaylandOutput::Transform transform)
|
|
|
|
{
|
|
|
|
return static_cast<DeviceInterface::Transform>(transform);
|
|
|
|
}
|
|
|
|
|
2019-08-28 18:54:37 +00:00
|
|
|
void AbstractWaylandOutput::applyChanges(const KWayland::Server::OutputChangeSet *changeSet)
|
2019-06-13 09:36:07 +00:00
|
|
|
{
|
2019-08-28 18:54:37 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Apply changes to the Wayland output.";
|
2019-08-25 12:22:12 +00:00
|
|
|
bool emitModeChanged = false;
|
2020-01-02 14:55:03 +00:00
|
|
|
bool overallSizeCheckNeeded = false;
|
2019-06-13 09:36:07 +00:00
|
|
|
|
2019-08-28 18:54:37 +00:00
|
|
|
// Enablement changes are handled by platform.
|
|
|
|
if (changeSet->modeChanged()) {
|
|
|
|
qCDebug(KWIN_CORE) << "Setting new mode:" << changeSet->mode();
|
|
|
|
m_waylandOutputDevice->setCurrentMode(changeSet->mode());
|
|
|
|
updateMode(changeSet->mode());
|
2019-08-25 12:22:12 +00:00
|
|
|
emitModeChanged = true;
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
2019-08-28 18:54:37 +00:00
|
|
|
if (changeSet->transformChanged()) {
|
|
|
|
qCDebug(KWIN_CORE) << "Server setting transform: " << (int)(changeSet->transform());
|
2019-11-24 10:42:30 +00:00
|
|
|
setTransform(changeSet->transform());
|
2020-01-02 14:55:07 +00:00
|
|
|
updateTransform(toTransform(changeSet->transform()));
|
2019-08-25 12:22:12 +00:00
|
|
|
emitModeChanged = true;
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
2019-08-28 18:54:37 +00:00
|
|
|
if (changeSet->positionChanged()) {
|
|
|
|
qCDebug(KWIN_CORE) << "Server setting position: " << changeSet->position();
|
|
|
|
setGlobalPos(changeSet->position());
|
2019-06-13 09:36:07 +00:00
|
|
|
// may just work already!
|
2020-01-02 14:55:03 +00:00
|
|
|
overallSizeCheckNeeded = true;
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
2019-08-28 18:54:37 +00:00
|
|
|
if (changeSet->scaleChanged()) {
|
2020-03-15 19:59:29 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Setting scale:" << changeSet->scaleF();
|
2019-08-28 18:54:37 +00:00
|
|
|
setScale(changeSet->scaleF());
|
2019-08-25 12:22:12 +00:00
|
|
|
emitModeChanged = true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:03 +00:00
|
|
|
overallSizeCheckNeeded |= emitModeChanged;
|
|
|
|
if (overallSizeCheckNeeded) {
|
|
|
|
emit screens()->changed();
|
|
|
|
}
|
|
|
|
|
2019-08-25 12:22:12 +00:00
|
|
|
if (emitModeChanged) {
|
|
|
|
emit modeChanged();
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 18:54:37 +00:00
|
|
|
bool AbstractWaylandOutput::isEnabled() const
|
|
|
|
{
|
|
|
|
return m_waylandOutputDevice->enabled() == DeviceInterface::Enablement::Enabled;
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
void AbstractWaylandOutput::setEnabled(bool enable)
|
|
|
|
{
|
|
|
|
if (enable == isEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-31 08:27:04 +00:00
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
if (enable) {
|
2020-03-23 23:04:06 +00:00
|
|
|
m_waylandOutputDevice->setEnabled(DeviceInterface::Enablement::Enabled);
|
|
|
|
m_waylandOutput->create();
|
2019-08-31 08:27:04 +00:00
|
|
|
updateEnablement(true);
|
2019-06-13 09:36:07 +00:00
|
|
|
} else {
|
2020-03-23 23:04:06 +00:00
|
|
|
m_waylandOutputDevice->setEnabled(DeviceInterface::Enablement::Disabled);
|
|
|
|
m_waylandOutput->destroy();
|
2019-08-31 08:27:04 +00:00
|
|
|
// xdg-output is destroyed in KWayland on wl_output going away.
|
|
|
|
updateEnablement(false);
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractWaylandOutput::setWaylandMode(const QSize &size, int refreshRate)
|
|
|
|
{
|
|
|
|
m_waylandOutput->setCurrentMode(size, refreshRate);
|
2019-08-28 18:54:37 +00:00
|
|
|
m_xdgOutput->setLogicalSize(pixelSize() / scale());
|
|
|
|
m_xdgOutput->done();
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 18:54:37 +00:00
|
|
|
void AbstractWaylandOutput::initInterfaces(const QString &model, const QString &manufacturer,
|
|
|
|
const QByteArray &uuid, const QSize &physicalSize,
|
|
|
|
const QVector<DeviceInterface::Mode> &modes)
|
2019-06-13 09:36:07 +00:00
|
|
|
{
|
|
|
|
m_waylandOutputDevice->setUuid(uuid);
|
|
|
|
|
|
|
|
if (!manufacturer.isEmpty()) {
|
|
|
|
m_waylandOutputDevice->setManufacturer(manufacturer);
|
|
|
|
} else {
|
|
|
|
m_waylandOutputDevice->setManufacturer(i18n("unknown"));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_waylandOutputDevice->setModel(model);
|
2019-08-27 14:52:39 +00:00
|
|
|
m_waylandOutputDevice->setPhysicalSize(physicalSize);
|
2019-06-13 09:36:07 +00:00
|
|
|
|
2020-03-23 23:04:06 +00:00
|
|
|
m_waylandOutput->setManufacturer(m_waylandOutputDevice->manufacturer());
|
|
|
|
m_waylandOutput->setModel(m_waylandOutputDevice->model());
|
|
|
|
m_waylandOutput->setPhysicalSize(m_waylandOutputDevice->physicalSize());
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
int i = 0;
|
|
|
|
for (auto mode : modes) {
|
|
|
|
qCDebug(KWIN_CORE).nospace() << "Adding mode " << ++i << ": " << mode.size << " [" << mode.refreshRate << "]";
|
|
|
|
m_waylandOutputDevice->addMode(mode);
|
2020-03-23 23:04:06 +00:00
|
|
|
|
|
|
|
KWayland::Server::OutputInterface::ModeFlags flags;
|
|
|
|
if (mode.flags & DeviceInterface::ModeFlag::Current) {
|
|
|
|
flags |= KWayland::Server::OutputInterface::ModeFlag::Current;
|
|
|
|
}
|
|
|
|
if (mode.flags & DeviceInterface::ModeFlag::Preferred) {
|
|
|
|
flags |= KWayland::Server::OutputInterface::ModeFlag::Preferred;
|
|
|
|
}
|
|
|
|
m_waylandOutput->addMode(mode.size, flags, mode.refreshRate);
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
2019-08-28 18:54:37 +00:00
|
|
|
|
2020-03-23 23:04:06 +00:00
|
|
|
// start off enabled
|
|
|
|
m_waylandOutput->create();
|
2020-03-24 16:13:05 +00:00
|
|
|
m_waylandOutputDevice->create();
|
2020-03-23 23:04:06 +00:00
|
|
|
m_xdgOutput->setLogicalSize(pixelSize() / scale());
|
|
|
|
m_xdgOutput->done();
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize AbstractWaylandOutput::orientateSize(const QSize &size) const
|
|
|
|
{
|
2019-11-24 10:42:30 +00:00
|
|
|
using Transform = DeviceInterface::Transform;
|
|
|
|
const Transform transform = m_waylandOutputDevice->transform();
|
|
|
|
if (transform == Transform::Rotated90 || transform == Transform::Rotated270 ||
|
|
|
|
transform == Transform::Flipped90 || transform == Transform::Flipped270) {
|
2019-06-13 09:36:07 +00:00
|
|
|
return size.transposed();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-11-26 22:53:17 +00:00
|
|
|
void AbstractWaylandOutput::setTransform(Transform transform)
|
2019-11-24 15:51:59 +00:00
|
|
|
{
|
2019-11-26 22:53:17 +00:00
|
|
|
const auto deviceTransform = toDeviceTransform(transform);
|
|
|
|
if (deviceTransform == m_waylandOutputDevice->transform()) {
|
2019-11-24 15:51:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-26 22:53:17 +00:00
|
|
|
setTransform(deviceTransform);
|
2019-11-24 15:51:59 +00:00
|
|
|
emit modeChanged();
|
|
|
|
}
|
|
|
|
|
2019-11-26 22:53:17 +00:00
|
|
|
AbstractWaylandOutput::Transform AbstractWaylandOutput::transform() const
|
2019-11-24 11:26:18 +00:00
|
|
|
{
|
2019-11-26 22:53:17 +00:00
|
|
|
return static_cast<Transform>(m_waylandOutputDevice->transform());
|
2019-11-24 11:26:18 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|