From f579f7e08be36763df595971d31d83ae9f9e35d3 Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Thu, 30 Mar 2023 22:16:44 +0200 Subject: [PATCH] feat: support adaptive sync Add a switch to toggle the mode. It is visible only when the Disman backend supports adaptive sync. --- kcm/config_handler.cpp | 1 + kcm/kcm.cpp | 14 +++++++++++ kcm/kcm.h | 4 ++++ kcm/output_model.cpp | 31 +++++++++++++++++++++++-- kcm/output_model.h | 5 +++- kcm/package/contents/ui/OutputPanel.qml | 8 +++++++ kcm/po/kcm_kdisplay.pot | 15 ++++++++---- 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/kcm/config_handler.cpp b/kcm/config_handler.cpp index db249b0..e54d00a 100644 --- a/kcm/config_handler.cpp +++ b/kcm/config_handler.cpp @@ -111,6 +111,7 @@ void ConfigHandler::checkNeedsSave() || output->position() != initialOutput->position() || output->scale() != initialOutput->scale() || output->rotation() != initialOutput->rotation() + || output->adaptive_sync() != initialOutput->adaptive_sync() || output->replication_source() != initialOutput->replication_source() || output->retention() != initialOutput->retention() || output->auto_resolution() != initialOutput->auto_resolution() diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 70ff7dd..9b03177 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -79,6 +79,7 @@ void KCMKDisplay::configReady(ConfigOperation* op) m_config->setConfig(config); setBackendReady(true); Q_EMIT perOutputScalingChanged(); + Q_EMIT supports_adaptive_sync_changed(); Q_EMIT primaryOutputSupportedChanged(); Q_EMIT outputReplicationSupportedChanged(); Q_EMIT tabletModeAvailableChanged(); @@ -127,6 +128,10 @@ void KCMKDisplay::doSave(bool force) << (perOutputScaling() ? QString::number(output->scale()) : QStringLiteral("global")) << "\n" + << " Adapt Sync:" << output->adaptive_sync() + << (output->adaptive_sync_toggle_support() ? "(no toggle support)" + : ("supports toggle")) + << "\n" << " Replicates:" << (output->replication_source() == 0 ? "no" : "yes"); } @@ -218,6 +223,14 @@ bool KCMKDisplay::perOutputScaling() const return m_config->config()->supported_features().testFlag(Config::Feature::PerOutputScaling); } +bool KCMKDisplay::supports_adaptive_sync() const +{ + if (!m_config || !m_config->config()) { + return false; + } + return m_config->config()->supported_features().testFlag(Config::Feature::AdaptiveSync); +} + bool KCMKDisplay::primaryOutputSupported() const { if (!m_config || !m_config->config()) { @@ -294,6 +307,7 @@ void KCMKDisplay::load() m_config.reset(new ConfigHandler(this)); Q_EMIT perOutputScalingChanged(); + Q_EMIT supports_adaptive_sync_changed(); connect( m_config.get(), &ConfigHandler::outputModelChanged, this, &KCMKDisplay::outputModelChanged); connect(m_config.get(), &ConfigHandler::outputConnect, this, [this](bool connected) { diff --git a/kcm/kcm.h b/kcm/kcm.h index 08d5ad8..68c47d3 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -36,6 +36,8 @@ class KCMKDisplay : public KQuickAddons::ConfigModule Q_PROPERTY(bool backendReady READ backendReady NOTIFY backendReadyChanged) Q_PROPERTY(bool screenNormalized READ screenNormalized NOTIFY screenNormalizedChanged) Q_PROPERTY(bool perOutputScaling READ perOutputScaling NOTIFY perOutputScalingChanged) + Q_PROPERTY(bool adaptiveSyncSupported READ supports_adaptive_sync NOTIFY + supports_adaptive_sync_changed) Q_PROPERTY(bool primaryOutputSupported READ primaryOutputSupported NOTIFY primaryOutputSupportedChanged) Q_PROPERTY(bool outputReplicationSupported READ outputReplicationSupported NOTIFY @@ -70,6 +72,7 @@ class KCMKDisplay : public KQuickAddons::ConfigModule bool perOutputScaling() const; bool primaryOutputSupported() const; + bool supports_adaptive_sync() const; bool outputReplicationSupported() const; qreal globalScale() const; @@ -92,6 +95,7 @@ class KCMKDisplay : public KQuickAddons::ConfigModule void changed(); void screenNormalizedChanged(); void perOutputScalingChanged(); + void supports_adaptive_sync_changed(); void primaryOutputSupportedChanged(); void outputReplicationSupportedChanged(); void globalScaleChanged(); diff --git a/kcm/output_model.cpp b/kcm/output_model.cpp index 187b29c..7826cb1 100644 --- a/kcm/output_model.cpp +++ b/kcm/output_model.cpp @@ -83,7 +83,7 @@ QVariant OutputModel::data(const QModelIndex& index, int role) const return replicationSourceIndex(index.row()); case ReplicasModelRole: return replicasModel(output); - case RefreshRatesRole: + case RefreshRatesRole: { QVariantList ret; for (auto rate : refreshRates(output)) { if (output->auto_refresh_rate()) { @@ -99,6 +99,11 @@ QVariant OutputModel::data(const QModelIndex& index, int role) const } return ret; } + case AdaptiveSyncToggleSupportRole: + return output->adaptive_sync_toggle_support(); + case AdaptiveSyncRole: + return output->adaptive_sync(); + } return QVariant(); } @@ -181,7 +186,7 @@ bool OutputModel::setData(const QModelIndex& index, const QVariant& value, int r return setReplicationSourceIndex(index.row(), value.toInt() - 1); } break; - case ScaleRole: + case ScaleRole: { bool ok; const qreal scale = value.toReal(&ok); if (ok && !qFuzzyCompare(output.ptr->scale(), scale)) { @@ -192,6 +197,12 @@ bool OutputModel::setData(const QModelIndex& index, const QVariant& value, int r } break; } + case AdaptiveSyncRole: + if (value.canConvert()) { + return set_adaptive_sync(index.row(), value.value()); + } + break; + } return false; } @@ -217,6 +228,8 @@ QHash OutputModel::roleNames() const roles[ReplicationSourceModelRole] = "replicationSourceModel"; roles[ReplicationSourceIndexRole] = "replicationSourceIndex"; roles[ReplicasModelRole] = "replicasModel"; + roles[AdaptiveSyncToggleSupportRole] = "adaptiveSyncToggleSupport"; + roles[AdaptiveSyncRole] = "adaptiveSync"; return roles; } @@ -442,6 +455,20 @@ bool OutputModel::setRotation(int outputIndex, Disman::Output::Rotation rotation return true; } +bool OutputModel::set_adaptive_sync(int outputIndex, bool value) +{ + Output& output = m_outputs[outputIndex]; + + if (output.ptr->adaptive_sync() == value) { + return false; + } + output.ptr->set_adaptive_sync(value); + + auto index = createIndex(outputIndex, 0); + Q_EMIT dataChanged(index, index, {AdaptiveSyncRole}); + return true; +} + int OutputModel::resolutionIndex(const Disman::OutputPtr& output) const { const QSize currentResolution = output->auto_mode()->size(); diff --git a/kcm/output_model.h b/kcm/output_model.h index 6bb0b4c..8169ecd 100644 --- a/kcm/output_model.h +++ b/kcm/output_model.h @@ -49,7 +49,9 @@ class OutputModel : public QAbstractListModel RefreshRatesRole, ReplicationSourceModelRole, ReplicationSourceIndexRole, - ReplicasModelRole + ReplicasModelRole, + AdaptiveSyncToggleSupportRole, + AdaptiveSyncRole, }; explicit OutputModel(ConfigHandler* configHandler); @@ -129,6 +131,7 @@ class OutputModel : public QAbstractListModel bool setResolution(int outputIndex, int resIndex); bool setRefreshRate(int outputIndex, int refIndex); bool setRotation(int outputIndex, Disman::Output::Rotation rotation); + bool set_adaptive_sync(int outputIndex, bool value); bool setAutoResolution(int outputIndex, bool value); bool setAutoRefreshRate(int outputIndex, bool value); diff --git a/kcm/package/contents/ui/OutputPanel.qml b/kcm/package/contents/ui/OutputPanel.qml index b446735..67ae94f 100644 --- a/kcm/package/contents/ui/OutputPanel.qml +++ b/kcm/package/contents/ui/OutputPanel.qml @@ -150,6 +150,14 @@ Kirigami.FormLayout { currentIndex: element.refreshRateIndex onActivated: element.refreshRateIndex = currentIndex } + + Controls.Switch { + text: i18n("Adaptive Sync") + visible: kcm.adaptiveSyncSupported + enabled: element.adaptiveSyncToggleSupport + checked: element.adaptiveSync + onToggled: element.adaptiveSync = checked + } } Controls.ComboBox { diff --git a/kcm/po/kcm_kdisplay.pot b/kcm/po/kcm_kdisplay.pot index 3999662..cbc7349 100644 --- a/kcm/po/kcm_kdisplay.pot +++ b/kcm/po/kcm_kdisplay.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-05-01 13:44-0500\n" +"POT-Creation-Date: 2023-03-31 00:13+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -44,19 +44,19 @@ msgctxt "Refresh rate in Hz (rounded to 3 digits)" msgid "%1 Hz" msgstr "" -#: kcm/output_model.cpp:501 +#: kcm/output_model.cpp:528 #, kde-format msgctxt "Width x height (aspect ratio)" msgid "%1x%2 (%3:%4)" msgstr "" -#: kcm/output_model.cpp:563 +#: kcm/output_model.cpp:590 #, kde-format msgctxt "Displayed when no replication source is selected." msgid "None" msgstr "" -#: kcm/output_model.cpp:570 +#: kcm/output_model.cpp:597 #, kde-format msgid "Replicated by other display" msgstr "" @@ -116,7 +116,12 @@ msgstr "" msgid "Refresh rate:" msgstr "" -#: kcm/package/contents/ui/OutputPanel.qml:156 +#: kcm/package/contents/ui/OutputPanel.qml:155 +#, kde-format +msgid "Adaptive Sync" +msgstr "" + +#: kcm/package/contents/ui/OutputPanel.qml:164 #, kde-format msgid "Replica of:" msgstr ""