wayland: Clean up current mode handling in kde-output-device-v2
Compare OutputModeV2 handles to find the current mode, this is more robust than testing mode properties such as size or refresh rate.
This commit is contained in:
parent
71dcb2738d
commit
65a2f88d24
3 changed files with 23 additions and 52 deletions
|
@ -176,18 +176,18 @@ int OutputDeviceV2Interface::refreshRate() const
|
|||
return d->currentMode->refreshRate();
|
||||
}
|
||||
|
||||
QList<OutputDeviceModeV2Interface *> OutputDeviceV2Interface::modes() const
|
||||
{
|
||||
return d->modes;
|
||||
}
|
||||
|
||||
void OutputDeviceV2Interface::setCurrentMode(OutputDeviceModeV2Interface *mode)
|
||||
{
|
||||
Q_ASSERT(d->modes.contains(mode));
|
||||
if (mode == d->currentMode) {
|
||||
return;
|
||||
}
|
||||
if (d->currentMode) {
|
||||
// another mode has the current flag - remove
|
||||
d->currentMode->setFlags(d->currentMode->flags() & ~uint(OutputDeviceModeV2Interface::ModeFlag::Current));
|
||||
}
|
||||
|
||||
mode->setFlags(mode->flags() | OutputDeviceModeV2Interface::ModeFlag::Current);
|
||||
d->currentMode = mode;
|
||||
|
||||
const auto clientResources = d->resourceMap();
|
||||
|
@ -199,18 +199,6 @@ void OutputDeviceV2Interface::setCurrentMode(OutputDeviceModeV2Interface *mode)
|
|||
d->updateGeometry();
|
||||
}
|
||||
|
||||
bool OutputDeviceV2Interface::setCurrentMode(const QSize &size, int refreshRate)
|
||||
{
|
||||
auto mode = std::find_if(d->modes.begin(), d->modes.end(), [size, refreshRate](OutputDeviceModeV2Interface *mode) {
|
||||
return mode->size() == size && mode->refreshRate() == refreshRate;
|
||||
});
|
||||
if (mode == d->modes.end()) {
|
||||
return false;
|
||||
}
|
||||
setCurrentMode(*mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t OutputDeviceV2InterfacePrivate::toTransform() const
|
||||
{
|
||||
switch (transform) {
|
||||
|
@ -488,7 +476,7 @@ OutputDeviceV2Interface::Transform OutputDeviceV2Interface::transform() const
|
|||
return d->transform;
|
||||
}
|
||||
|
||||
void OutputDeviceV2Interface::setModes(const QList<OutputDeviceModeV2Interface *> &modes)
|
||||
void OutputDeviceV2Interface::setModes(const QList<OutputDeviceModeV2Interface *> &modes, OutputDeviceModeV2Interface *currentMode)
|
||||
{
|
||||
if (modes.isEmpty()) {
|
||||
qCWarning(KWIN_CORE) << "Tried to set no modes for output";
|
||||
|
@ -499,25 +487,16 @@ void OutputDeviceV2Interface::setModes(const QList<OutputDeviceModeV2Interface *
|
|||
|
||||
const auto oldModes = d->modes;
|
||||
d->modes.clear();
|
||||
d->currentMode = nullptr;
|
||||
|
||||
for (OutputDeviceModeV2Interface *outputDeviceMode : modes) {
|
||||
d->modes << outputDeviceMode;
|
||||
outputDeviceMode->setParent(this);
|
||||
|
||||
for (auto resource : clientResources) {
|
||||
d->sendNewMode(resource, outputDeviceMode);
|
||||
}
|
||||
|
||||
if (outputDeviceMode->flags().testFlag(OutputDeviceModeV2Interface::ModeFlag::Current)) {
|
||||
d->currentMode = outputDeviceMode;
|
||||
}
|
||||
}
|
||||
|
||||
if (!d->currentMode) {
|
||||
d->currentMode = d->modes.at(0);
|
||||
}
|
||||
|
||||
d->currentMode = currentMode;
|
||||
for (auto resource : clientResources) {
|
||||
d->sendCurrentMode(resource);
|
||||
}
|
||||
|
@ -764,11 +743,6 @@ OutputDeviceModeV2Interface::ModeFlags OutputDeviceModeV2Interface::flags() cons
|
|||
return d->m_flags;
|
||||
}
|
||||
|
||||
void OutputDeviceModeV2Interface::setFlags(OutputDeviceModeV2Interface::ModeFlags flags)
|
||||
{
|
||||
d->m_flags = flags;
|
||||
}
|
||||
|
||||
void OutputDeviceModeV2InterfacePrivate::bindResource(wl_resource *resource)
|
||||
{
|
||||
send_size(resource, m_size.width(), m_size.height());
|
||||
|
|
|
@ -97,7 +97,7 @@ public:
|
|||
QString name() const;
|
||||
QSize pixelSize() const;
|
||||
int refreshRate() const;
|
||||
|
||||
QList<KWaylandServer::OutputDeviceModeV2Interface *> modes() const;
|
||||
qreal scale() const;
|
||||
SubPixel subPixel() const;
|
||||
Transform transform() const;
|
||||
|
@ -123,15 +123,8 @@ public:
|
|||
void setSubPixel(SubPixel subPixel);
|
||||
void setTransform(Transform transform);
|
||||
|
||||
void setModes(const QList<KWaylandServer::OutputDeviceModeV2Interface *> &modes);
|
||||
void setModes(const QList<KWaylandServer::OutputDeviceModeV2Interface *> &modes, KWaylandServer::OutputDeviceModeV2Interface *currentMode);
|
||||
void setCurrentMode(KWaylandServer::OutputDeviceModeV2Interface *mode);
|
||||
|
||||
/**
|
||||
* Makes the mode with the specified @a size and @a refreshRate current.
|
||||
* Returns @c false if no mode with the given attributes exists; otherwise returns @c true.
|
||||
*/
|
||||
bool setCurrentMode(const QSize &size, int refreshRate);
|
||||
|
||||
void setEdid(const QByteArray &edid);
|
||||
void setEnabled(bool enabled);
|
||||
void setUuid(const QUuid &uuid);
|
||||
|
@ -160,8 +153,7 @@ class KWIN_EXPORT OutputDeviceModeV2Interface : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
enum class ModeFlag {
|
||||
Current = 0x1,
|
||||
Preferred = 0x2,
|
||||
Preferred = 0x1,
|
||||
};
|
||||
Q_ENUM(ModeFlag)
|
||||
Q_DECLARE_FLAGS(ModeFlags, ModeFlag)
|
||||
|
@ -174,8 +166,6 @@ public:
|
|||
int refreshRate() const;
|
||||
OutputDeviceModeV2Interface::ModeFlags flags() const;
|
||||
|
||||
void setFlags(OutputDeviceModeV2Interface::ModeFlags newFlags);
|
||||
|
||||
static OutputDeviceModeV2Interface *get(wl_resource *native);
|
||||
|
||||
private:
|
||||
|
|
|
@ -97,23 +97,24 @@ WaylandOutputDevice::WaylandOutputDevice(Output *output, QObject *parent)
|
|||
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 (output->currentMode() == mode) {
|
||||
flags |= OutputDeviceModeV2Interface::ModeFlag::Current;
|
||||
}
|
||||
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);
|
||||
m_outputDeviceV2->setModes(deviceModes, currentMode);
|
||||
}
|
||||
|
||||
void WaylandOutputDevice::handleModesChanged()
|
||||
|
@ -143,7 +144,13 @@ void WaylandOutputDevice::handleTransformChanged()
|
|||
|
||||
void WaylandOutputDevice::handleCurrentModeChanged()
|
||||
{
|
||||
m_outputDeviceV2->setCurrentMode(m_platformOutput->modeSize(), m_platformOutput->refreshRate());
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue