feat(bar): add "hide on last display" option (#3816)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
This commit is contained in:
Tomé Carvalhoandcopilot-swe-agent[bot] authored and GitHub committed 2026-10-19 15:45:10 -04:00
1 parent bb3e3adaab
commit f43e3705b8
7 files changed
+64 -6

No files matched your search

+2
View File
@@ -32,6 +32,8 @@ function screenMatches(screen, preferences, screens, displayNameMode) {
}
function coversScreen(config, screen, screens, displayNameMode) {
if ((config?.hideOnLastDisplay ?? false) && screens.length === 1)
return false;
const preferences = config?.screenPreferences || ["all"];
return preferences.includes("all") || screenMatches(screen, preferences, screens, displayNameMode) || ((config?.showOnLastDisplay ?? false) && screens.length === 1);
}
+2 -1
View File
@@ -47,7 +47,8 @@ Column {
enabled: true,
position: freeEdge >= 0 ? freeEdge : (defaultBar.position ?? 0),
screenPreferences: ["all"],
showOnLastDisplay: true
showOnLastDisplay: true,
hideOnLastDisplay: false
});
delete newBar.island;
delete newBar.dot;
+19 -2
View File
@@ -32,8 +32,22 @@ Item {
}
function setBarShowOnLastDisplay(barId, value) {
SettingsData.updateBarConfig(barId, {
showOnLastDisplay: value
SettingsData.updateBarConfig(barId, value ? {
showOnLastDisplay: true,
hideOnLastDisplay: false
} : {
showOnLastDisplay: false
});
if (Quickshell.screens.length === 1)
bar.notifyHorizontalBarChange();
}
function setBarHideOnLastDisplay(barId, value) {
SettingsData.updateBarConfig(barId, value ? {
hideOnLastDisplay: true,
showOnLastDisplay: false
} : {
hideOnLastDisplay: false
});
if (Quickshell.screens.length === 1)
bar.notifyHorizontalBarChange();
@@ -223,8 +237,11 @@ Item {
allowEmpty: true
showLastDisplay: true
showOnLastDisplay: bar.selectedBarConfig?.showOnLastDisplay ?? true
allowHideOnLastDisplay: true
hideOnLastDisplay: bar.selectedBarConfig?.hideOnLastDisplay ?? false
preferencesHandler: prefs => dankBarTab.setBarScreenPreferences(bar.selectedBarId, prefs)
onLastDisplayToggled: checked => dankBarTab.setBarShowOnLastDisplay(bar.selectedBarId, checked)
onHideOnLastDisplayToggled: checked => dankBarTab.setBarHideOnLastDisplay(bar.selectedBarId, checked)
}
}
@@ -90,8 +90,11 @@ Item {
function setShowOnLastDisplay(componentId, enabled) {
if (componentId.startsWith("bar:")) {
const barId = componentId.substring(4);
SettingsData.updateBarConfig(barId, {
"showOnLastDisplay": enabled
SettingsData.updateBarConfig(barId, enabled ? {
"showOnLastDisplay": true,
"hideOnLastDisplay": false
} : {
"showOnLastDisplay": false
});
return;
}
@@ -101,6 +104,25 @@ Item {
SettingsData.set("showOnLastDisplay", newPrefs);
}
function getHideOnLastDisplay(componentId) {
if (!componentId.startsWith("bar:"))
return false;
const barId = componentId.substring(4);
return SettingsData.getBarConfig(barId)?.hideOnLastDisplay ?? false;
}
function setHideOnLastDisplay(componentId, enabled) {
if (!componentId.startsWith("bar:"))
return;
const barId = componentId.substring(4);
SettingsData.updateBarConfig(barId, enabled ? {
"hideOnLastDisplay": true,
"showOnLastDisplay": false
} : {
"hideOnLastDisplay": false
});
}
SettingsPage {
id: mainColumn
@@ -154,8 +176,11 @@ Item {
allowEmpty: true
showLastDisplay: ["notifications", "osd", "toast", "notepad"].includes(componentCard.modelData.id) || componentCard.modelData.id.startsWith("bar:")
showOnLastDisplay: root.getShowOnLastDisplay(componentCard.modelData.id)
allowHideOnLastDisplay: componentCard.modelData.id.startsWith("bar:")
hideOnLastDisplay: root.getHideOnLastDisplay(componentCard.modelData.id)
preferencesHandler: prefs => root.setScreenPreferences(componentCard.modelData.id, prefs)
onLastDisplayToggled: checked => root.setShowOnLastDisplay(componentCard.modelData.id, checked)
onHideOnLastDisplayToggled: checked => root.setHideOnLastDisplay(componentCard.modelData.id, checked)
}
SettingsToggleRow {
@@ -137,7 +137,7 @@ Item {
return false;
const prefs = c.screenPreferences || ["all"];
if (prefs.length > 0)
return true;
return !(c.hideOnLastDisplay ?? false) || Quickshell.screens.length !== 1;
return (c.showOnLastDisplay ?? true) && Quickshell.screens.length === 1;
}
@@ -12,11 +12,14 @@ Column {
property bool allowEmpty: false
property bool showLastDisplay: false
property bool showOnLastDisplay: false
property bool allowHideOnLastDisplay: false
property bool hideOnLastDisplay: false
readonly property bool localAllDisplays: !Array.isArray(displayPreferences) || displayPreferences.includes("all") || (emptyMeansAll && displayPreferences.length === 0)
// A callback, not a signal: Qt 6.12 hands signal array parameters over as a V4Sequence that fails Array.isArray.
property var preferencesHandler: null
signal lastDisplayToggled(bool checked)
signal hideOnLastDisplayToggled(bool checked)
width: parent?.width ?? 0
spacing: Theme.groupedListGap
@@ -46,6 +49,13 @@ Column {
onToggled: checked => root.lastDisplayToggled(checked)
}
SettingsToggleRow {
text: I18n.tr("Hide on last display", "bar display assignment option")
visible: root.allowHideOnLastDisplay
checked: root.hideOnLastDisplay
onToggled: checked => root.hideOnLastDisplayToggled(checked)
}
Repeater {
model: Quickshell.screens
@@ -49,6 +49,9 @@ test("absent, empty, explicit and fallback assignments remain distinct", () => {
assert.equal(covers({ screenPreferences: ["DP-2"] }), false);
assert.equal(covers({ screenPreferences: [], showOnLastDisplay: true }), count === 1);
assert.equal(covers({ screenPreferences: ["missing"], showOnLastDisplay: true }), count === 1);
assert.equal(covers({ hideOnLastDisplay: true }), count !== 1);
assert.equal(covers({ screenPreferences: ["DP-1"], hideOnLastDisplay: true }), count !== 1);
assert.equal(covers({ screenPreferences: [], showOnLastDisplay: true, hideOnLastDisplay: true }), false);
}
});