diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index fccdafcd..871ca931 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -133,11 +133,13 @@ }, "left-click": { "description": "Command to execute when the button is left-clicked.", - "label": "Left click" + "label": "Left click", + "update-text": "Update displayed text on left-click" }, "middle-click": { "description": "Command to execute when the button is middle-clicked.", - "label": "Middle click" + "label": "Middle click", + "update-text": "Update displayed text on middle-click" }, "parse-json": { "description": "Parse the command output as a JSON object to dynamically set text and icon.", @@ -149,7 +151,8 @@ }, "right-click": { "description": "Command to execute when the button is right-clicked.", - "label": "Right click" + "label": "Right click", + "update-text": "Update displayed text on right-click" }, "text-stream": { "description": "Streamed lines from the command will be displayed as text on the button.", diff --git a/Modules/Bar/Widgets/CustomButton.qml b/Modules/Bar/Widgets/CustomButton.qml index 3e67fb0c..7e03fdb1 100644 --- a/Modules/Bar/Widgets/CustomButton.qml +++ b/Modules/Bar/Widgets/CustomButton.qml @@ -34,8 +34,11 @@ Item { readonly property string customIcon: widgetSettings.icon || widgetMetadata.icon readonly property string leftClickExec: widgetSettings.leftClickExec || widgetMetadata.leftClickExec + readonly property bool leftClickUpdateText: widgetSettings.leftClickUpdateText ?? widgetMetadata.leftClickUpdateText readonly property string rightClickExec: widgetSettings.rightClickExec || widgetMetadata.rightClickExec + readonly property bool rightClickUpdateText: widgetSettings.rightClickUpdateText ?? widgetMetadata.rightClickUpdateText readonly property string middleClickExec: widgetSettings.middleClickExec || widgetMetadata.middleClickExec + readonly property bool middleClickUpdateText: widgetSettings.middleClickUpdateText ?? widgetMetadata.middleClickUpdateText readonly property string textCommand: widgetSettings.textCommand !== undefined ? widgetSettings.textCommand : (widgetMetadata.textCommand || "") readonly property bool textStream: widgetSettings.textStream !== undefined ? widgetSettings.textStream : (widgetMetadata.textStream || false) readonly property int textIntervalMs: widgetSettings.textIntervalMs !== undefined ? widgetSettings.textIntervalMs : (widgetMetadata.textIntervalMs || 3000) @@ -210,6 +213,7 @@ Item { if (leftClickExec) { Quickshell.execDetached(["sh", "-c", leftClickExec]) Logger.i("CustomButton", `Executing command: ${leftClickExec}`) + if (leftClickUpdateText) runTextCommand() } else if (!hasExec) { // No script was defined, open settings var settingsPanel = PanelService.getPanel("settingsPanel", screen) @@ -222,6 +226,7 @@ Item { if (rightClickExec) { Quickshell.execDetached(["sh", "-c", rightClickExec]) Logger.i("CustomButton", `Executing command: ${rightClickExec}`) + if (rightClickUpdateText) runTextCommand() } } @@ -229,6 +234,7 @@ Item { if (middleClickExec) { Quickshell.execDetached(["sh", "-c", middleClickExec]) Logger.i("CustomButton", `Executing command: ${middleClickExec}`) + if (middleClickUpdateText) runTextCommand() } } diff --git a/Modules/Panels/Settings/Bar/WidgetSettings/CustomButtonSettings.qml b/Modules/Panels/Settings/Bar/WidgetSettings/CustomButtonSettings.qml index 715e4ef9..4b51db86 100644 --- a/Modules/Panels/Settings/Bar/WidgetSettings/CustomButtonSettings.qml +++ b/Modules/Panels/Settings/Bar/WidgetSettings/CustomButtonSettings.qml @@ -21,8 +21,11 @@ ColumnLayout { var settings = Object.assign({}, widgetData || {}) settings.icon = valueIcon settings.leftClickExec = leftClickExecInput.text + settings.leftClickUpdateText = leftClickUpdateText.checked settings.rightClickExec = rightClickExecInput.text + settings.rightClickUpdateText = rightClickUpdateText.checked settings.middleClickExec = middleClickExecInput.text + settings.middleClickUpdateText = middleClickUpdateText.checked settings.textCommand = textCommandInput.text settings.textCollapse = textCollapseInput.text settings.textStream = valueTextStream @@ -61,31 +64,73 @@ ColumnLayout { } } - NTextInput { - id: leftClickExecInput - Layout.fillWidth: true - label: I18n.tr("bar.widget-settings.custom-button.left-click.label") - description: I18n.tr("bar.widget-settings.custom-button.left-click.description") - placeholderText: I18n.tr("placeholders.enter-command") - text: widgetData?.leftClickExec || widgetMetadata.leftClickExec + RowLayout { + spacing: Style.marginM + + NTextInput { + id: leftClickExecInput + Layout.fillWidth: true + label: I18n.tr("bar.widget-settings.custom-button.left-click.label") + description: I18n.tr("bar.widget-settings.custom-button.left-click.description") + placeholderText: I18n.tr("placeholders.enter-command") + text: widgetData?.leftClickExec || widgetMetadata.leftClickExec + } + + NToggle { + id: leftClickUpdateText + Layout.alignment: Qt.AlignRight | Qt.AlignBottom + Layout.bottomMargin: Style.marginS + onEntered: TooltipService.show(Screen, leftClickUpdateText, I18n.tr("bar.widget-settings.custom-button.left-click.update-text"), "auto") + onExited: TooltipService.hide() + checked: widgetData?.leftClickUpdateText ?? widgetMetadata.leftClickUpdateText + onToggled: isChecked => checked = isChecked + } } - NTextInput { - id: rightClickExecInput - Layout.fillWidth: true - label: I18n.tr("bar.widget-settings.custom-button.right-click.label") - description: I18n.tr("bar.widget-settings.custom-button.right-click.description") - placeholderText: I18n.tr("placeholders.enter-command") - text: widgetData?.rightClickExec || widgetMetadata.rightClickExec + RowLayout { + spacing: Style.marginM + + NTextInput { + id: rightClickExecInput + Layout.fillWidth: true + label: I18n.tr("bar.widget-settings.custom-button.right-click.label") + description: I18n.tr("bar.widget-settings.custom-button.right-click.description") + placeholderText: I18n.tr("placeholders.enter-command") + text: widgetData?.rightClickExec || widgetMetadata.rightClickExec + } + + NToggle { + id: rightClickUpdateText + Layout.alignment: Qt.AlignRight | Qt.AlignBottom + Layout.bottomMargin: Style.marginS + onEntered: TooltipService.show(Screen, rightClickUpdateText, I18n.tr("bar.widget-settings.custom-button.right-click.update-text"), "auto") + onExited: TooltipService.hide() + checked: widgetData?.rightClickUpdateText ?? widgetMetadata.rightClickUpdateText + onToggled: isChecked => checked = isChecked + } } - NTextInput { - id: middleClickExecInput - Layout.fillWidth: true - label: I18n.tr("bar.widget-settings.custom-button.middle-click.label") - description: I18n.tr("bar.widget-settings.custom-button.middle-click.description") - placeholderText: I18n.tr("placeholders.enter-command") - text: widgetData.middleClickExec || widgetMetadata.middleClickExec + RowLayout { + spacing: Style.marginM + + NTextInput { + id: middleClickExecInput + Layout.fillWidth: true + label: I18n.tr("bar.widget-settings.custom-button.middle-click.label") + description: I18n.tr("bar.widget-settings.custom-button.middle-click.description") + placeholderText: I18n.tr("placeholders.enter-command") + text: widgetData.middleClickExec || widgetMetadata.middleClickExec + } + + NToggle { + id: middleClickUpdateText + Layout.alignment: Qt.AlignRight | Qt.AlignBottom + Layout.bottomMargin: Style.marginS + onEntered: TooltipService.show(Screen, middleClickUpdateText, I18n.tr("bar.widget-settings.custom-button.middle-click.update-text"), "auto") + onExited: TooltipService.hide() + checked: widgetData?.middleClickUpdateText ?? widgetMetadata.middleClickUpdateText + onToggled: isChecked => checked = isChecked + } } NDivider { diff --git a/Services/UI/BarWidgetRegistry.qml b/Services/UI/BarWidgetRegistry.qml index a2b4f470..99995aa4 100644 --- a/Services/UI/BarWidgetRegistry.qml +++ b/Services/UI/BarWidgetRegistry.qml @@ -93,8 +93,11 @@ Singleton { "allowUserSettings": true, "icon": "heart", "leftClickExec": "", + "leftClickUpdateText": true, "rightClickExec": "", + "rightClickUpdateText": true, "middleClickExec": "", + "middleClickUpdateText": true, "textCommand": "", "textStream": false, "textIntervalMs": 3000, diff --git a/Widgets/NToggle.qml b/Widgets/NToggle.qml index 82c54711..abbe75fc 100644 --- a/Widgets/NToggle.qml +++ b/Widgets/NToggle.qml @@ -25,6 +25,7 @@ RowLayout { NLabel { label: root.label description: root.description + visible: root.label !== "" || root.description !== "" } Rectangle {