Add Adaptive Sync window rule

This commit is contained in:
Pedro Nishiyama 2024-02-11 00:15:21 -03:00 committed by Vlad Zahorodnii
parent b02190bf23
commit a0d437163d
7 changed files with 35 additions and 2 deletions

View file

@ -165,7 +165,8 @@ void Compositor::composite(RenderLoop *renderLoop)
SurfaceItem *const activeFullscreenItem = activeWindow && activeWindow->isFullScreen() ? activeWindow->surfaceItem() : nullptr; SurfaceItem *const activeFullscreenItem = activeWindow && activeWindow->isFullScreen() ? activeWindow->surfaceItem() : nullptr;
frame->setContentType(activeWindow && activeFullscreenItem ? activeFullscreenItem->contentType() : ContentType::None); frame->setContentType(activeWindow && activeFullscreenItem ? activeFullscreenItem->contentType() : ContentType::None);
const bool vrr = (output->capabilities() & Output::Capability::Vrr) && (output->vrrPolicy() == VrrPolicy::Always || (output->vrrPolicy() == VrrPolicy::Automatic && activeFullscreenItem)); const bool wantsAdaptiveSync = activeWindow && activeWindow->wantsAdaptiveSync();
const bool vrr = (output->capabilities() & Output::Capability::Vrr) && (output->vrrPolicy() == VrrPolicy::Always || (output->vrrPolicy() == VrrPolicy::Automatic && wantsAdaptiveSync));
const bool tearing = (output->capabilities() & Output::Capability::Tearing) && options->allowTearing() && activeFullscreenItem && activeFullscreenItem->presentationHint() == PresentationModeHint::Async; const bool tearing = (output->capabilities() & Output::Capability::Tearing) && options->allowTearing() && activeFullscreenItem && activeFullscreenItem->presentationHint() == PresentationModeHint::Async;
if (vrr) { if (vrr) {
frame->setPresentationMode(tearing ? PresentationMode::AdaptiveAsync : PresentationMode::AdaptiveSync); frame->setPresentationMode(tearing ? PresentationMode::AdaptiveAsync : PresentationMode::AdaptiveSync);

View file

@ -719,6 +719,11 @@ void RulesModel::populateRuleList()
i18n("Layer"), i18n("Appearance & Fixes"), i18n("Layer"), i18n("Appearance & Fixes"),
QIcon::fromTheme("view-sort"))); QIcon::fromTheme("view-sort")));
layer->setOptionsData(layerModelData()); layer->setOptionsData(layerModelData());
addRule(new RuleItem(QLatin1String("adaptivesync"),
RulePolicy::ForceRule, RuleItem::Boolean,
i18n("Adaptive Sync"), i18n("Appearance & Fixes"),
QIcon::fromTheme("monitor-symbolic")));
} }
const QHash<QString, QString> RulesModel::x11PropertyHash() const QHash<QString, QString> RulesModel::x11PropertyHash()

View file

@ -75,6 +75,7 @@ Rules::Rules()
, shortcutrule(UnusedSetRule) , shortcutrule(UnusedSetRule)
, disableglobalshortcutsrule(UnusedForceRule) , disableglobalshortcutsrule(UnusedForceRule)
, desktopfilerule(UnusedSetRule) , desktopfilerule(UnusedSetRule)
, adaptivesyncrule(UnusedForceRule)
{ {
} }
@ -157,6 +158,7 @@ void Rules::readFromSettings(const RuleSettings *settings)
READ_FORCE_RULE(disableglobalshortcuts, ); READ_FORCE_RULE(disableglobalshortcuts, );
READ_SET_RULE(desktopfile); READ_SET_RULE(desktopfile);
READ_FORCE_RULE(layer, ); READ_FORCE_RULE(layer, );
READ_FORCE_RULE(adaptivesync, );
} }
#undef READ_MATCH_STRING #undef READ_MATCH_STRING
@ -235,6 +237,7 @@ void Rules::write(RuleSettings *settings) const
WRITE_FORCE_RULE(disableglobalshortcuts, Disableglobalshortcuts, ); WRITE_FORCE_RULE(disableglobalshortcuts, Disableglobalshortcuts, );
WRITE_SET_RULE(desktopfile, Desktopfile, ); WRITE_SET_RULE(desktopfile, Desktopfile, );
WRITE_FORCE_RULE(layer, Layer, ); WRITE_FORCE_RULE(layer, Layer, );
WRITE_FORCE_RULE(adaptivesync, Adaptivesync, );
} }
#undef WRITE_MATCH_STRING #undef WRITE_MATCH_STRING
@ -279,7 +282,8 @@ bool Rules::isEmpty() const
&& shortcutrule == UnusedSetRule && shortcutrule == UnusedSetRule
&& disableglobalshortcutsrule == UnusedForceRule && disableglobalshortcutsrule == UnusedForceRule
&& desktopfilerule == UnusedSetRule && desktopfilerule == UnusedSetRule
&& layerrule == UnusedForceRule); && layerrule == UnusedForceRule
&& adaptivesyncrule == UnusedForceRule);
} }
Rules::ForceRule Rules::convertForceRule(int v) Rules::ForceRule Rules::convertForceRule(int v)
@ -637,6 +641,7 @@ APPLY_FORCE_RULE(strictgeometry, StrictGeometry, bool)
APPLY_RULE(shortcut, Shortcut, QString) APPLY_RULE(shortcut, Shortcut, QString)
APPLY_FORCE_RULE(disableglobalshortcuts, DisableGlobalShortcuts, bool) APPLY_FORCE_RULE(disableglobalshortcuts, DisableGlobalShortcuts, bool)
APPLY_RULE(desktopfile, DesktopFile, QString) APPLY_RULE(desktopfile, DesktopFile, QString)
APPLY_FORCE_RULE(adaptivesync, AdaptiveSync, bool)
#undef APPLY_RULE #undef APPLY_RULE
#undef APPLY_FORCE_RULE #undef APPLY_FORCE_RULE
@ -695,6 +700,7 @@ bool Rules::discardUsed(bool withdrawn)
DISCARD_USED_FORCE_RULE(disableglobalshortcuts); DISCARD_USED_FORCE_RULE(disableglobalshortcuts);
DISCARD_USED_SET_RULE(desktopfile); DISCARD_USED_SET_RULE(desktopfile);
DISCARD_USED_FORCE_RULE(layer); DISCARD_USED_FORCE_RULE(layer);
DISCARD_USED_FORCE_RULE(adaptivesync);
return changed; return changed;
} }
@ -842,6 +848,7 @@ CHECK_RULE(Shortcut, QString)
CHECK_FORCE_RULE(DisableGlobalShortcuts, bool) CHECK_FORCE_RULE(DisableGlobalShortcuts, bool)
CHECK_RULE(DesktopFile, QString) CHECK_RULE(DesktopFile, QString)
CHECK_FORCE_RULE(Layer, Layer) CHECK_FORCE_RULE(Layer, Layer)
CHECK_FORCE_RULE(AdaptiveSync, bool)
#undef CHECK_RULE #undef CHECK_RULE
#undef CHECK_FORCE_RULE #undef CHECK_FORCE_RULE

View file

@ -77,6 +77,7 @@ public:
bool checkDisableGlobalShortcuts(bool disable) const; bool checkDisableGlobalShortcuts(bool disable) const;
QString checkDesktopFile(QString desktopFile, bool init = false) const; QString checkDesktopFile(QString desktopFile, bool init = false) const;
Layer checkLayer(Layer layer) const; Layer checkLayer(Layer layer) const;
bool checkAdaptiveSync(bool adaptivesync) const;
private: private:
MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const; MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const;
@ -185,6 +186,7 @@ public:
bool applyDisableGlobalShortcuts(bool &disable) const; bool applyDisableGlobalShortcuts(bool &disable) const;
bool applyDesktopFile(QString &desktopFile, bool init) const; bool applyDesktopFile(QString &desktopFile, bool init) const;
bool applyLayer(enum Layer &layer) const; bool applyLayer(enum Layer &layer) const;
bool applyAdaptiveSync(bool &adaptivesync) const;
private: private:
#endif #endif
@ -288,6 +290,8 @@ private:
ForceRule disableglobalshortcutsrule; ForceRule disableglobalshortcutsrule;
QString desktopfile; QString desktopfile;
SetRule desktopfilerule; SetRule desktopfilerule;
bool adaptivesync;
ForceRule adaptivesyncrule;
friend QDebug &operator<<(QDebug &stream, const Rules *); friend QDebug &operator<<(QDebug &stream, const Rules *);
}; };

View file

@ -441,5 +441,14 @@
<label>Layer rule type</label> <label>Layer rule type</label>
<default code="true">Rules::UnusedForceRule</default> <default code="true">Rules::UnusedForceRule</default>
</entry> </entry>
<entry name="adaptivesync" type="Bool">
<label>AdaptiveSync</label>
<default>true</default>
</entry>
<entry name="adaptivesyncrule" type="Int">
<label>AdaptiveSync rule type</label>
<default code="true">Rules::UnusedForceRule</default>
</entry>
</group> </group>
</kcfg> </kcfg>

View file

@ -3954,6 +3954,11 @@ void Window::setFullScreen(bool set)
qCWarning(KWIN_CORE, "%s doesn't support setting fullscreen state", metaObject()->className()); qCWarning(KWIN_CORE, "%s doesn't support setting fullscreen state", metaObject()->className());
} }
bool Window::wantsAdaptiveSync() const
{
return rules()->checkAdaptiveSync(isFullScreen());
}
/** /**
* Returns @c true if the Window can be minimized; otherwise @c false. * Returns @c true if the Window can be minimized; otherwise @c false.
* *

View file

@ -1000,6 +1000,8 @@ public:
virtual bool isRequestedFullScreen() const; virtual bool isRequestedFullScreen() const;
virtual void setFullScreen(bool set); virtual void setFullScreen(bool set);
bool wantsAdaptiveSync() const;
QRectF geometryRestore() const; QRectF geometryRestore() const;
virtual bool isMaximizable() const; virtual bool isMaximizable() const;
virtual MaximizeMode maximizeMode() const; virtual MaximizeMode maximizeMode() const;