Skip to content

Commit

Permalink
feat: support adaptive sync
Browse files Browse the repository at this point in the history
Add a switch to toggle the mode. It is visible only when the Disman backend
supports adaptive sync.
  • Loading branch information
romangg committed Apr 6, 2023
1 parent 58f4f3d commit f579f7e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
1 change: 1 addition & 0 deletions kcm/config_handler.cpp
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions kcm/kcm.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions kcm/kcm.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
31 changes: 29 additions & 2 deletions kcm/output_model.cpp
Expand Up @@ -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()) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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)) {
Expand All @@ -192,6 +197,12 @@ bool OutputModel::setData(const QModelIndex& index, const QVariant& value, int r
}
break;
}
case AdaptiveSyncRole:
if (value.canConvert<bool>()) {
return set_adaptive_sync(index.row(), value.value<bool>());
}
break;
}
return false;
}

Expand All @@ -217,6 +228,8 @@ QHash<int, QByteArray> OutputModel::roleNames() const
roles[ReplicationSourceModelRole] = "replicationSourceModel";
roles[ReplicationSourceIndexRole] = "replicationSourceIndex";
roles[ReplicasModelRole] = "replicasModel";
roles[AdaptiveSyncToggleSupportRole] = "adaptiveSyncToggleSupport";
roles[AdaptiveSyncRole] = "adaptiveSync";
return roles;
}

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion kcm/output_model.h
Expand Up @@ -49,7 +49,9 @@ class OutputModel : public QAbstractListModel
RefreshRatesRole,
ReplicationSourceModelRole,
ReplicationSourceIndexRole,
ReplicasModelRole
ReplicasModelRole,
AdaptiveSyncToggleSupportRole,
AdaptiveSyncRole,
};

explicit OutputModel(ConfigHandler* configHandler);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions kcm/package/contents/ui/OutputPanel.qml
Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions kcm/po/kcm_kdisplay.pot
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 ""
Expand Down

0 comments on commit f579f7e

Please sign in to comment.