1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

plugins: ipc visibility conditions

This commit is contained in:
bbedward
2026-01-06 13:22:36 -05:00
parent 1b5abca83a
commit c45eb2cccf
2 changed files with 186 additions and 1 deletions

View File

@@ -787,7 +787,16 @@ Item {
const widgets = BarWidgetService.getRegisteredWidgetIds();
if (widgets.length === 0)
return "No widgets registered";
return widgets.join("\n");
const lines = [];
for (const widgetId of widgets) {
const widget = BarWidgetService.getWidgetOnFocusedScreen(widgetId);
let state = "";
if (widget?.effectiveVisible !== undefined)
state = widget.effectiveVisible ? " [visible]" : " [hidden]";
lines.push(widgetId + state);
}
return lines.join("\n");
}
function status(widgetId: string): string {
@@ -806,6 +815,76 @@ Item {
return "hidden";
}
function reveal(widgetId: string): string {
if (!widgetId)
return "ERROR: No widget ID specified";
if (!BarWidgetService.hasWidget(widgetId))
return `WIDGET_NOT_FOUND: ${widgetId}`;
const widget = BarWidgetService.getWidgetOnFocusedScreen(widgetId);
if (!widget)
return `WIDGET_NOT_AVAILABLE: ${widgetId}`;
if (typeof widget.setVisibilityOverride === "function") {
widget.setVisibilityOverride(true);
return `WIDGET_REVEAL_SUCCESS: ${widgetId}`;
}
return `WIDGET_REVEAL_NOT_SUPPORTED: ${widgetId}`;
}
function hide(widgetId: string): string {
if (!widgetId)
return "ERROR: No widget ID specified";
if (!BarWidgetService.hasWidget(widgetId))
return `WIDGET_NOT_FOUND: ${widgetId}`;
const widget = BarWidgetService.getWidgetOnFocusedScreen(widgetId);
if (!widget)
return `WIDGET_NOT_AVAILABLE: ${widgetId}`;
if (typeof widget.setVisibilityOverride === "function") {
widget.setVisibilityOverride(false);
return `WIDGET_HIDE_SUCCESS: ${widgetId}`;
}
return `WIDGET_HIDE_NOT_SUPPORTED: ${widgetId}`;
}
function reset(widgetId: string): string {
if (!widgetId)
return "ERROR: No widget ID specified";
if (!BarWidgetService.hasWidget(widgetId))
return `WIDGET_NOT_FOUND: ${widgetId}`;
const widget = BarWidgetService.getWidgetOnFocusedScreen(widgetId);
if (!widget)
return `WIDGET_NOT_AVAILABLE: ${widgetId}`;
if (typeof widget.clearVisibilityOverride === "function") {
widget.clearVisibilityOverride();
return `WIDGET_RESET_SUCCESS: ${widgetId}`;
}
return `WIDGET_RESET_NOT_SUPPORTED: ${widgetId}`;
}
function visibility(widgetId: string): string {
if (!widgetId)
return "ERROR: No widget ID specified";
if (!BarWidgetService.hasWidget(widgetId))
return `WIDGET_NOT_FOUND: ${widgetId}`;
const widget = BarWidgetService.getWidgetOnFocusedScreen(widgetId);
if (!widget)
return `WIDGET_NOT_AVAILABLE: ${widgetId}`;
if (widget.effectiveVisible !== undefined)
return widget.effectiveVisible ? "visible" : "hidden";
return "unknown";
}
target: "widget"
}

View File

@@ -1,4 +1,5 @@
import QtQuick
import Quickshell.Io
import qs.Common
Item {
@@ -16,6 +17,20 @@ Item {
property string pluginId: ""
property var pluginService: null
property string visibilityCommand: ""
property int visibilityInterval: 0
property bool conditionVisible: true
property bool _visibilityOverride: false
property bool _visibilityOverrideValue: true
readonly property bool effectiveVisible: {
if (_visibilityOverride)
return _visibilityOverrideValue;
if (!visibilityCommand)
return true;
return conditionVisible;
}
property Component horizontalBarPill: null
property Component verticalBarPill: null
property Component popoutContent: null
@@ -49,6 +64,8 @@ Item {
Component.onCompleted: {
loadPluginData();
if (visibilityCommand)
Qt.callLater(checkVisibility);
}
onPluginServiceChanged: {
@@ -78,6 +95,57 @@ Item {
variants = pluginService.getPluginVariants(pluginId);
}
function checkVisibility() {
if (!visibilityCommand) {
conditionVisible = true;
return;
}
visibilityProcess.running = true;
}
function setVisibilityOverride(visible) {
_visibilityOverride = true;
_visibilityOverrideValue = visible;
}
function clearVisibilityOverride() {
_visibilityOverride = false;
if (visibilityCommand)
checkVisibility();
}
onVisibilityCommandChanged: {
if (visibilityCommand)
Qt.callLater(checkVisibility);
else
conditionVisible = true;
}
onVisibilityIntervalChanged: {
if (visibilityInterval > 0 && visibilityCommand) {
visibilityTimer.restart();
} else {
visibilityTimer.stop();
}
}
Timer {
id: visibilityTimer
interval: root.visibilityInterval * 1000
repeat: true
running: root.visibilityInterval > 0 && root.visibilityCommand !== ""
onTriggered: root.checkVisibility()
}
Process {
id: visibilityProcess
command: ["sh", "-c", root.visibilityCommand]
running: false
onExited: (exitCode, exitStatus) => {
root.conditionVisible = (exitCode === 0);
}
}
function createVariant(variantName, variantConfig) {
if (!pluginService || !pluginId) {
return null;
@@ -105,6 +173,7 @@ Item {
BasePill {
id: horizontalPill
visible: !isVertical && hasHorizontalPill
opacity: root.effectiveVisible ? 1 : 0
axis: root.axis
section: root.section
popoutTarget: hasPopout ? pluginPopout : null
@@ -114,6 +183,24 @@ Item {
barSpacing: root.barSpacing
barConfig: root.barConfig
content: root.horizontalBarPill
states: State {
name: "hidden"
when: !root.effectiveVisible
PropertyChanges {
target: horizontalPill
width: 0
}
}
transitions: Transition {
NumberAnimation {
properties: "width,opacity"
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
onClicked: {
if (pillClickAction) {
if (pillClickAction.length === 0) {
@@ -145,6 +232,7 @@ Item {
BasePill {
id: verticalPill
visible: isVertical && hasVerticalPill
opacity: root.effectiveVisible ? 1 : 0
axis: root.axis
section: root.section
popoutTarget: hasPopout ? pluginPopout : null
@@ -155,6 +243,24 @@ Item {
barConfig: root.barConfig
content: root.verticalBarPill
isVerticalOrientation: true
states: State {
name: "hidden"
when: !root.effectiveVisible
PropertyChanges {
target: verticalPill
height: 0
}
}
transitions: Transition {
NumberAnimation {
properties: "height,opacity"
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
onClicked: {
if (pillClickAction) {
if (pillClickAction.length === 0) {