Skip to content

Commit cfc96dd

Browse files
committed
feat(bar): add context menu for CustomButton right-click
- Show context menu instead of directly opening settings when no command is set - Context menu includes widget-settings option - Matches behavior of other bar widgets
1 parent b8a7c2f commit cfc96dd

4 files changed

Lines changed: 55 additions & 32 deletions

File tree

Modules/Bar/Widgets/CustomButton.qml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ import qs.Widgets
1212
Item {
1313
id: root
1414

15+
NPopupContextMenu {
16+
id: contextMenu
17+
18+
model: [
19+
{
20+
"label": I18n.tr("actions.widget-settings"),
21+
"action": "widget-settings",
22+
"icon": "settings"
23+
},
24+
]
25+
26+
onTriggered: action => {
27+
contextMenu.close();
28+
PanelService.closeContextMenu(screen);
29+
30+
if (action === "widget-settings") {
31+
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
32+
}
33+
}
34+
}
35+
1536
property ShellScreen screen
1637

1738
// Widget properties passed from Bar.qml for per-instance settings
@@ -425,21 +446,23 @@ Item {
425446
const text = parsed.text || "";
426447
const icon = parsed.icon || "";
427448
let tooltip = parsed.tooltip || "";
428-
449+
429450
// Support both "color" (legacy) and "iconColor"/"textColor" (new)
430451
const legacyColor = parsed.color || "";
431452
const iconColorKey = parsed.iconColor || "";
432453
const textColorKey = parsed.textColor || "";
433-
454+
434455
const validColors = ["primary", "secondary", "tertiary", "error", "none"];
435-
456+
436457
// Helper to resolve color: legacy > specific > none
437458
function resolveColor(legacy, specific) {
438-
if (legacy && validColors.includes(legacy)) return legacy;
439-
if (specific && validColors.includes(specific)) return specific;
459+
if (legacy && validColors.includes(legacy))
460+
return legacy;
461+
if (specific && validColors.includes(specific))
462+
return specific;
440463
return "";
441464
}
442-
465+
443466
const resolvedIconColor = resolveColor(legacyColor, iconColorKey);
444467
const resolvedTextColor = resolveColor(legacyColor, textColorKey);
445468

@@ -553,8 +576,8 @@ Item {
553576
if (rightClickExec) {
554577
Quickshell.execDetached(["sh", "-lc", rightClickExec]);
555578
Logger.i("CustomButton", `Executing command: ${rightClickExec}`);
556-
} else if (!rightClickUpdateText) {
557-
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
579+
} else {
580+
PanelService.showContextMenu(contextMenu, pill, screen);
558581
}
559582
if (!textStream && rightClickUpdateText) {
560583
runTextCommand();

Modules/Panels/Media/MediaPlayerPanel.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SmartPanel {
7474
id: playerContent
7575
anchors.fill: parent
7676

77-
property real contentPreferredHeight: mainLayout.implicitHeight + Style.margin2L;
77+
property real contentPreferredHeight: mainLayout.implicitHeight + Style.margin2L
7878

7979
property Component visualizerSource: {
8080
switch (root.visualizerType) {

Modules/Panels/Settings/Bar/WidgetSettings/CustomButtonSettings.qml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,29 @@ ColumnLayout {
122122
label: I18n.tr("bar.custom-button.icon-position-label")
123123
description: I18n.tr("bar.custom-button.icon-position-description")
124124
model: barIsVertical ? [
125-
{
126-
name: I18n.tr("bar.custom-button.icon-position-top"),
127-
key: "left"
128-
},
129-
{
130-
name: I18n.tr("bar.custom-button.icon-position-bottom"),
131-
key: "right"
132-
}
133-
] : [
134-
{
135-
name: I18n.tr("bar.custom-button.icon-position-left"),
136-
key: "left"
137-
},
138-
{
139-
name: I18n.tr("bar.custom-button.icon-position-right"),
140-
key: "right"
141-
}
142-
]
125+
{
126+
name: I18n.tr("bar.custom-button.icon-position-top"),
127+
key: "left"
128+
},
129+
{
130+
name: I18n.tr("bar.custom-button.icon-position-bottom"),
131+
key: "right"
132+
}
133+
] : [
134+
{
135+
name: I18n.tr("bar.custom-button.icon-position-left"),
136+
key: "left"
137+
},
138+
{
139+
name: I18n.tr("bar.custom-button.icon-position-right"),
140+
key: "right"
141+
}
142+
]
143143
currentKey: valueIconPosition
144144
onSelected: key => {
145-
valueIconPosition = key;
146-
saveSettings();
147-
}
145+
valueIconPosition = key;
146+
saveSettings();
147+
}
148148
defaultValue: widgetMetadata.iconPosition
149149
}
150150

Services/UI/BarWidgetRegistry.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Singleton {
126126
"customIconPath": "",
127127
"colorizeDistroLogo": false,
128128
"colorizeSystemIcon": "none",
129-
"colorizeSystemText": "none",
129+
"colorizeSystemText": "none",
130130
"enableColorization": false
131131
},
132132
"CustomButton": {
@@ -190,7 +190,7 @@ Singleton {
190190
"icon": "rocket",
191191
"customIconPath": "",
192192
"colorizeSystemIcon": "none",
193-
"colorizeSystemText": "none",
193+
"colorizeSystemText": "none",
194194
"enableColorization": false,
195195
"iconColor": "none"
196196
},

0 commit comments

Comments
 (0)