rules: add window rule to force tearing on or off

This allows the user to override which presentation mode individual apps request
This commit is contained in:
Xaver Hugl 2024-07-06 15:37:35 +02:00
parent 1dab5fb328
commit 5316cf8d50
7 changed files with 68 additions and 38 deletions

View file

@ -329,7 +329,7 @@ void WaylandCompositor::composite(RenderLoop *renderLoop)
const bool wantsAdaptiveSync = activeWindow && activeWindow->isOnOutput(output) && 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 && activeWindow->wantsTearing(activeFullscreenItem->presentationHint() == PresentationModeHint::Async);
if (vrr) {
frame->setPresentationMode(tearing ? PresentationMode::AdaptiveAsync : PresentationMode::AdaptiveSync);
} else {

View file

@ -724,6 +724,11 @@ void RulesModel::populateRuleList()
RulePolicy::ForceRule, RuleItem::Boolean,
i18n("Adaptive Sync"), i18n("Appearance & Fixes"),
QIcon::fromTheme("monitor-symbolic")));
addRule(new RuleItem(QLatin1String("tearing"),
RulePolicy::ForceRule, RuleItem::Boolean,
i18n("Allow Tearing"), i18n("Appearance & Fixes"),
QIcon::fromTheme("monitor-symbolic")));
}
const QHash<QString, QString> RulesModel::x11PropertyHash()

View file

@ -76,6 +76,7 @@ Rules::Rules()
, disableglobalshortcutsrule(UnusedForceRule)
, desktopfilerule(UnusedSetRule)
, adaptivesyncrule(UnusedForceRule)
, tearingrule(UnusedForceRule)
{
}
@ -160,6 +161,7 @@ void Rules::readFromSettings(const RuleSettings *settings)
READ_SET_RULE(desktopfile);
READ_FORCE_RULE(layer, );
READ_FORCE_RULE(adaptivesync, );
READ_FORCE_RULE(tearing, );
}
#undef READ_MATCH_STRING
@ -255,43 +257,44 @@ void Rules::write(RuleSettings *settings) const
// returns true if it doesn't affect anything
bool Rules::isEmpty() const
{
return (placementrule == UnusedForceRule
&& positionrule == UnusedSetRule
&& sizerule == UnusedSetRule
&& minsizerule == UnusedForceRule
&& maxsizerule == UnusedForceRule
&& opacityactiverule == UnusedForceRule
&& opacityinactiverule == UnusedForceRule
&& ignoregeometryrule == UnusedSetRule
&& desktopsrule == UnusedSetRule
&& screenrule == UnusedSetRule
&& activityrule == UnusedSetRule
&& maximizevertrule == UnusedSetRule
&& maximizehorizrule == UnusedSetRule
&& minimizerule == UnusedSetRule
&& shaderule == UnusedSetRule
&& skiptaskbarrule == UnusedSetRule
&& skippagerrule == UnusedSetRule
&& skipswitcherrule == UnusedSetRule
&& aboverule == UnusedSetRule
&& belowrule == UnusedSetRule
&& fullscreenrule == UnusedSetRule
&& noborderrule == UnusedSetRule
&& decocolorrule == UnusedForceRule
&& blockcompositingrule == UnusedForceRule
&& fsplevelrule == UnusedForceRule
&& fpplevelrule == UnusedForceRule
&& acceptfocusrule == UnusedForceRule
&& closeablerule == UnusedForceRule
&& autogrouprule == UnusedForceRule
&& autogroupfgrule == UnusedForceRule
&& autogroupidrule == UnusedForceRule
&& strictgeometryrule == UnusedForceRule
&& shortcutrule == UnusedSetRule
&& disableglobalshortcutsrule == UnusedForceRule
&& desktopfilerule == UnusedSetRule
&& layerrule == UnusedForceRule
&& adaptivesyncrule == UnusedForceRule);
return placementrule == UnusedForceRule
&& positionrule == UnusedSetRule
&& sizerule == UnusedSetRule
&& minsizerule == UnusedForceRule
&& maxsizerule == UnusedForceRule
&& opacityactiverule == UnusedForceRule
&& opacityinactiverule == UnusedForceRule
&& ignoregeometryrule == UnusedSetRule
&& desktopsrule == UnusedSetRule
&& screenrule == UnusedSetRule
&& activityrule == UnusedSetRule
&& maximizevertrule == UnusedSetRule
&& maximizehorizrule == UnusedSetRule
&& minimizerule == UnusedSetRule
&& shaderule == UnusedSetRule
&& skiptaskbarrule == UnusedSetRule
&& skippagerrule == UnusedSetRule
&& skipswitcherrule == UnusedSetRule
&& aboverule == UnusedSetRule
&& belowrule == UnusedSetRule
&& fullscreenrule == UnusedSetRule
&& noborderrule == UnusedSetRule
&& decocolorrule == UnusedForceRule
&& blockcompositingrule == UnusedForceRule
&& fsplevelrule == UnusedForceRule
&& fpplevelrule == UnusedForceRule
&& acceptfocusrule == UnusedForceRule
&& closeablerule == UnusedForceRule
&& autogrouprule == UnusedForceRule
&& autogroupfgrule == UnusedForceRule
&& autogroupidrule == UnusedForceRule
&& strictgeometryrule == UnusedForceRule
&& shortcutrule == UnusedSetRule
&& disableglobalshortcutsrule == UnusedForceRule
&& desktopfilerule == UnusedSetRule
&& layerrule == UnusedForceRule
&& adaptivesyncrule == UnusedForceRule
&& tearingrule == UnusedForceRule;
}
Rules::ForceRule Rules::convertForceRule(int v)
@ -686,6 +689,7 @@ APPLY_RULE(shortcut, Shortcut, QString)
APPLY_FORCE_RULE(disableglobalshortcuts, DisableGlobalShortcuts, bool)
APPLY_RULE(desktopfile, DesktopFile, QString)
APPLY_FORCE_RULE(adaptivesync, AdaptiveSync, bool)
APPLY_FORCE_RULE(tearing, Tearing, bool)
#undef APPLY_RULE
#undef APPLY_FORCE_RULE
@ -745,6 +749,7 @@ bool Rules::discardUsed(bool withdrawn)
DISCARD_USED_SET_RULE(desktopfile);
DISCARD_USED_FORCE_RULE(layer);
DISCARD_USED_FORCE_RULE(adaptivesync);
DISCARD_USED_FORCE_RULE(tearing);
return changed;
}
@ -893,6 +898,7 @@ CHECK_FORCE_RULE(DisableGlobalShortcuts, bool)
CHECK_RULE(DesktopFile, QString)
CHECK_FORCE_RULE(Layer, Layer)
CHECK_FORCE_RULE(AdaptiveSync, bool)
CHECK_FORCE_RULE(Tearing, bool)
#undef CHECK_RULE
#undef CHECK_FORCE_RULE

View file

@ -78,6 +78,7 @@ public:
QString checkDesktopFile(QString desktopFile, bool init = false) const;
Layer checkLayer(Layer layer) const;
bool checkAdaptiveSync(bool adaptivesync) const;
bool checkTearing(bool requestsTearing) const;
private:
MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const;
@ -189,6 +190,7 @@ public:
bool applyDesktopFile(QString &desktopFile, bool init) const;
bool applyLayer(enum Layer &layer) const;
bool applyAdaptiveSync(bool &adaptivesync) const;
bool applyTearing(bool &tearing) const;
private:
#endif
@ -295,6 +297,8 @@ private:
SetRule desktopfilerule;
bool adaptivesync;
ForceRule adaptivesyncrule;
bool tearing;
ForceRule tearingrule;
friend QDebug &operator<<(QDebug &stream, const Rules *);
};

View file

@ -450,5 +450,14 @@
<label>AdaptiveSync rule type</label>
<default code="true">Rules::UnusedForceRule</default>
</entry>
<entry name="tearing" type="Bool">
<label>Allow Tearing</label>
<default>true</default>
</entry>
<entry name="tearingrule" type="Int">
<label>Tearing rule type</label>
<default code="true">Rules::UnusedForceRule</default>
</entry>
</group>
</kcfg>

View file

@ -4032,6 +4032,11 @@ bool Window::wantsAdaptiveSync() const
return rules()->checkAdaptiveSync(isFullScreen());
}
bool Window::wantsTearing(bool tearingRequested) const
{
return rules()->checkTearing(tearingRequested);
}
/**
* Returns @c true if the Window can be minimized; otherwise @c false.
*

View file

@ -1004,6 +1004,7 @@ public:
virtual void setFullScreen(bool set);
bool wantsAdaptiveSync() const;
bool wantsTearing(bool tearingRequested) const;
QRectF geometryRestore() const;
void setGeometryRestore(const QRectF &rect);