Skip to content

Commit f579f7e

Browse files
committed
feat: support adaptive sync
Add a switch to toggle the mode. It is visible only when the Disman backend supports adaptive sync.
1 parent 58f4f3d commit f579f7e

File tree

7 files changed

+70
-8
lines changed

7 files changed

+70
-8
lines changed

kcm/config_handler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ void ConfigHandler::checkNeedsSave()
111111
|| output->position() != initialOutput->position()
112112
|| output->scale() != initialOutput->scale()
113113
|| output->rotation() != initialOutput->rotation()
114+
|| output->adaptive_sync() != initialOutput->adaptive_sync()
114115
|| output->replication_source() != initialOutput->replication_source()
115116
|| output->retention() != initialOutput->retention()
116117
|| output->auto_resolution() != initialOutput->auto_resolution()

kcm/kcm.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void KCMKDisplay::configReady(ConfigOperation* op)
7979
m_config->setConfig(config);
8080
setBackendReady(true);
8181
Q_EMIT perOutputScalingChanged();
82+
Q_EMIT supports_adaptive_sync_changed();
8283
Q_EMIT primaryOutputSupportedChanged();
8384
Q_EMIT outputReplicationSupportedChanged();
8485
Q_EMIT tabletModeAvailableChanged();
@@ -127,6 +128,10 @@ void KCMKDisplay::doSave(bool force)
127128
<< (perOutputScaling() ? QString::number(output->scale())
128129
: QStringLiteral("global"))
129130
<< "\n"
131+
<< " Adapt Sync:" << output->adaptive_sync()
132+
<< (output->adaptive_sync_toggle_support() ? "(no toggle support)"
133+
: ("supports toggle"))
134+
<< "\n"
130135
<< " Replicates:"
131136
<< (output->replication_source() == 0 ? "no" : "yes");
132137
}
@@ -218,6 +223,14 @@ bool KCMKDisplay::perOutputScaling() const
218223
return m_config->config()->supported_features().testFlag(Config::Feature::PerOutputScaling);
219224
}
220225

226+
bool KCMKDisplay::supports_adaptive_sync() const
227+
{
228+
if (!m_config || !m_config->config()) {
229+
return false;
230+
}
231+
return m_config->config()->supported_features().testFlag(Config::Feature::AdaptiveSync);
232+
}
233+
221234
bool KCMKDisplay::primaryOutputSupported() const
222235
{
223236
if (!m_config || !m_config->config()) {
@@ -294,6 +307,7 @@ void KCMKDisplay::load()
294307

295308
m_config.reset(new ConfigHandler(this));
296309
Q_EMIT perOutputScalingChanged();
310+
Q_EMIT supports_adaptive_sync_changed();
297311
connect(
298312
m_config.get(), &ConfigHandler::outputModelChanged, this, &KCMKDisplay::outputModelChanged);
299313
connect(m_config.get(), &ConfigHandler::outputConnect, this, [this](bool connected) {

kcm/kcm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class KCMKDisplay : public KQuickAddons::ConfigModule
3636
Q_PROPERTY(bool backendReady READ backendReady NOTIFY backendReadyChanged)
3737
Q_PROPERTY(bool screenNormalized READ screenNormalized NOTIFY screenNormalizedChanged)
3838
Q_PROPERTY(bool perOutputScaling READ perOutputScaling NOTIFY perOutputScalingChanged)
39+
Q_PROPERTY(bool adaptiveSyncSupported READ supports_adaptive_sync NOTIFY
40+
supports_adaptive_sync_changed)
3941
Q_PROPERTY(bool primaryOutputSupported READ primaryOutputSupported NOTIFY
4042
primaryOutputSupportedChanged)
4143
Q_PROPERTY(bool outputReplicationSupported READ outputReplicationSupported NOTIFY
@@ -70,6 +72,7 @@ class KCMKDisplay : public KQuickAddons::ConfigModule
7072

7173
bool perOutputScaling() const;
7274
bool primaryOutputSupported() const;
75+
bool supports_adaptive_sync() const;
7376
bool outputReplicationSupported() const;
7477

7578
qreal globalScale() const;
@@ -92,6 +95,7 @@ class KCMKDisplay : public KQuickAddons::ConfigModule
9295
void changed();
9396
void screenNormalizedChanged();
9497
void perOutputScalingChanged();
98+
void supports_adaptive_sync_changed();
9599
void primaryOutputSupportedChanged();
96100
void outputReplicationSupportedChanged();
97101
void globalScaleChanged();

kcm/output_model.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ QVariant OutputModel::data(const QModelIndex& index, int role) const
8383
return replicationSourceIndex(index.row());
8484
case ReplicasModelRole:
8585
return replicasModel(output);
86-
case RefreshRatesRole:
86+
case RefreshRatesRole: {
8787
QVariantList ret;
8888
for (auto rate : refreshRates(output)) {
8989
if (output->auto_refresh_rate()) {
@@ -99,6 +99,11 @@ QVariant OutputModel::data(const QModelIndex& index, int role) const
9999
}
100100
return ret;
101101
}
102+
case AdaptiveSyncToggleSupportRole:
103+
return output->adaptive_sync_toggle_support();
104+
case AdaptiveSyncRole:
105+
return output->adaptive_sync();
106+
}
102107
return QVariant();
103108
}
104109

@@ -181,7 +186,7 @@ bool OutputModel::setData(const QModelIndex& index, const QVariant& value, int r
181186
return setReplicationSourceIndex(index.row(), value.toInt() - 1);
182187
}
183188
break;
184-
case ScaleRole:
189+
case ScaleRole: {
185190
bool ok;
186191
const qreal scale = value.toReal(&ok);
187192
if (ok && !qFuzzyCompare(output.ptr->scale(), scale)) {
@@ -192,6 +197,12 @@ bool OutputModel::setData(const QModelIndex& index, const QVariant& value, int r
192197
}
193198
break;
194199
}
200+
case AdaptiveSyncRole:
201+
if (value.canConvert<bool>()) {
202+
return set_adaptive_sync(index.row(), value.value<bool>());
203+
}
204+
break;
205+
}
195206
return false;
196207
}
197208

@@ -217,6 +228,8 @@ QHash<int, QByteArray> OutputModel::roleNames() const
217228
roles[ReplicationSourceModelRole] = "replicationSourceModel";
218229
roles[ReplicationSourceIndexRole] = "replicationSourceIndex";
219230
roles[ReplicasModelRole] = "replicasModel";
231+
roles[AdaptiveSyncToggleSupportRole] = "adaptiveSyncToggleSupport";
232+
roles[AdaptiveSyncRole] = "adaptiveSync";
220233
return roles;
221234
}
222235

@@ -442,6 +455,20 @@ bool OutputModel::setRotation(int outputIndex, Disman::Output::Rotation rotation
442455
return true;
443456
}
444457

458+
bool OutputModel::set_adaptive_sync(int outputIndex, bool value)
459+
{
460+
Output& output = m_outputs[outputIndex];
461+
462+
if (output.ptr->adaptive_sync() == value) {
463+
return false;
464+
}
465+
output.ptr->set_adaptive_sync(value);
466+
467+
auto index = createIndex(outputIndex, 0);
468+
Q_EMIT dataChanged(index, index, {AdaptiveSyncRole});
469+
return true;
470+
}
471+
445472
int OutputModel::resolutionIndex(const Disman::OutputPtr& output) const
446473
{
447474
const QSize currentResolution = output->auto_mode()->size();

kcm/output_model.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class OutputModel : public QAbstractListModel
4949
RefreshRatesRole,
5050
ReplicationSourceModelRole,
5151
ReplicationSourceIndexRole,
52-
ReplicasModelRole
52+
ReplicasModelRole,
53+
AdaptiveSyncToggleSupportRole,
54+
AdaptiveSyncRole,
5355
};
5456

5557
explicit OutputModel(ConfigHandler* configHandler);
@@ -129,6 +131,7 @@ class OutputModel : public QAbstractListModel
129131
bool setResolution(int outputIndex, int resIndex);
130132
bool setRefreshRate(int outputIndex, int refIndex);
131133
bool setRotation(int outputIndex, Disman::Output::Rotation rotation);
134+
bool set_adaptive_sync(int outputIndex, bool value);
132135

133136
bool setAutoResolution(int outputIndex, bool value);
134137
bool setAutoRefreshRate(int outputIndex, bool value);

kcm/package/contents/ui/OutputPanel.qml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ Kirigami.FormLayout {
150150
currentIndex: element.refreshRateIndex
151151
onActivated: element.refreshRateIndex = currentIndex
152152
}
153+
154+
Controls.Switch {
155+
text: i18n("Adaptive Sync")
156+
visible: kcm.adaptiveSyncSupported
157+
enabled: element.adaptiveSyncToggleSupport
158+
checked: element.adaptiveSync
159+
onToggled: element.adaptiveSync = checked
160+
}
153161
}
154162

155163
Controls.ComboBox {

kcm/po/kcm_kdisplay.pot

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2022-05-01 13:44-0500\n"
11+
"POT-Creation-Date: 2023-03-31 00:13+0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -44,19 +44,19 @@ msgctxt "Refresh rate in Hz (rounded to 3 digits)"
4444
msgid "%1 Hz"
4545
msgstr ""
4646

47-
#: kcm/output_model.cpp:501
47+
#: kcm/output_model.cpp:528
4848
#, kde-format
4949
msgctxt "Width x height (aspect ratio)"
5050
msgid "%1x%2 (%3:%4)"
5151
msgstr ""
5252

53-
#: kcm/output_model.cpp:563
53+
#: kcm/output_model.cpp:590
5454
#, kde-format
5555
msgctxt "Displayed when no replication source is selected."
5656
msgid "None"
5757
msgstr ""
5858

59-
#: kcm/output_model.cpp:570
59+
#: kcm/output_model.cpp:597
6060
#, kde-format
6161
msgid "Replicated by other display"
6262
msgstr ""
@@ -116,7 +116,12 @@ msgstr ""
116116
msgid "Refresh rate:"
117117
msgstr ""
118118

119-
#: kcm/package/contents/ui/OutputPanel.qml:156
119+
#: kcm/package/contents/ui/OutputPanel.qml:155
120+
#, kde-format
121+
msgid "Adaptive Sync"
122+
msgstr ""
123+
124+
#: kcm/package/contents/ui/OutputPanel.qml:164
120125
#, kde-format
121126
msgid "Replica of:"
122127
msgstr ""

0 commit comments

Comments
 (0)