summaryrefslogtreecommitdiff
path: root/noctalia/.config/plugins/privacy-indicator/BarWidget.qml
blob: bdebd418a549c3bd4ac904794396ee996ee574f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import qs.Commons
import qs.Services.UI
import qs.Widgets

Item {
  id: root

  property var pluginApi: null

  property ShellScreen screen
  property string widgetId: ""
  property string section: ""
  property int sectionWidgetIndex: -1
  property int sectionWidgetsCount: 0

  // Bar positioning properties
  readonly property string screenName: screen ? screen.name : ""
  readonly property string barPosition: Settings.getBarPositionForScreen(screenName)
  readonly property bool isVertical: barPosition === "left" || barPosition === "right"
  readonly property real barHeight: Style.getBarHeightForScreen(screenName)
  readonly property real capsuleHeight: Style.getCapsuleHeightForScreen(screenName)
  readonly property real barFontSize: Style.getBarFontSizeForScreen(screenName)

  // Access main instance for state
  readonly property var mainInstance: pluginApi?.mainInstance
  
  property bool micActive: mainInstance ? mainInstance.micActive : false
  property bool camActive: mainInstance ? mainInstance.camActive : false
  property bool scrActive: mainInstance ? mainInstance.scrActive : false
  property var micApps: mainInstance ? mainInstance.micApps : []
  property var camApps: mainInstance ? mainInstance.camApps : []
  property var scrApps: mainInstance ? mainInstance.scrApps : []

  property var cfg: pluginApi?.pluginSettings || ({})
  property var defaults: pluginApi?.manifest?.metadata?.defaultSettings || ({})

  property bool hideInactive: cfg.hideInactive ?? defaults.hideInactive ?? false
  property bool enableToast: cfg.enableToast ?? defaults.enableToast ?? true
  property bool removeMargins: cfg.removeMargins ?? defaults.removeMargins ?? false
  property int iconSpacing: cfg.iconSpacing ?? defaults.iconSpacing ?? 4
  property string activeColorKey: cfg.activeColor ?? defaults.activeColor ?? "primary"
  property string inactiveColorKey: cfg.inactiveColor ?? defaults.inactiveColor ?? "none"

  readonly property color activeColor: Color.resolveColorKey(activeColorKey)
  readonly property color inactiveColor: inactiveColorKey === "none" ? Qt.alpha(Color.mOnSurfaceVariant, 0.3) : Color.resolveColorKey(inactiveColorKey)
  readonly property color micColor: micActive ? activeColor : inactiveColor
  readonly property color camColor: camActive ? activeColor : inactiveColor
  readonly property color scrColor: scrActive ? activeColor : inactiveColor

  readonly property bool isVisible: !hideInactive || micActive || camActive || scrActive

  property real margins: removeMargins ? 0 : Style.marginM * 2

  readonly property real contentWidth: isVertical ? Style.capsuleHeight : Math.round(layout.implicitWidth + margins)
  readonly property real contentHeight: isVertical ? Math.round(layout.implicitHeight + margins) : Style.capsuleHeight

  implicitWidth: contentWidth
  implicitHeight: contentHeight

  Layout.alignment: Qt.AlignVCenter
  visible: root.isVisible
  opacity: root.isVisible ? 1.0 : 0.0

  function buildTooltip() {
    var parts = [];

    if (micActive && micApps.length > 0) {
      parts.push("Mic: " + micApps.join(", "));
    }

    if (camActive && camApps.length > 0) {
      parts.push("Cam: " + camApps.join(", "));
    }

    if (scrActive && scrApps.length > 0) {
      parts.push("Screen sharing: " + scrApps.join(", "));
    }

    return parts.length > 0 ? parts.join("\n") : "";
  }

  Rectangle {
    id: visualCapsule
    x: Style.pixelAlignCenter(parent.width, width)
    y: Style.pixelAlignCenter(parent.height, height)
    width: root.contentWidth
    height: root.contentHeight
    radius: Style.radiusM
    color: Style.capsuleColor
    border.color: Style.capsuleBorderColor
    border.width: Style.capsuleBorderWidth

    Item {
      id: layout

      anchors.verticalCenter: parent.verticalCenter
      anchors.horizontalCenter: parent.horizontalCenter

      implicitWidth: iconsLayout.implicitWidth
      implicitHeight: iconsLayout.implicitHeight

      GridLayout {
        id: iconsLayout

        columns: root.isVertical ? 1 : 3
        rows: root.isVertical ? 3 : 1

        rowSpacing: root.iconSpacing
        columnSpacing: root.iconSpacing

        NIcon {
          visible: micActive || !root.hideInactive
          icon: micActive ? "microphone" : "microphone-off"
          color: root.micColor
        }
        NIcon {
          visible: camActive || !root.hideInactive
          icon: camActive ? "camera" : "camera-off"
          color: root.camColor
        }
        NIcon {
          visible: scrActive || !root.hideInactive
          icon: scrActive ? "screen-share" : "screen-share-off"
          color: root.scrColor
        }
      }
    }
  }

  NPopupContextMenu {
    id: contextMenu

    model: [
      {
        "label": pluginApi?.tr("menu.settings"),
        "action": "settings",
        "icon": "settings"
      },
    ]

    onTriggered: function (action) {
      contextMenu.close();
      PanelService.closeContextMenu(screen);
      if (action === "settings") {
        BarService.openPluginSettings(root.screen, pluginApi.manifest);
      }
    }
  }

  MouseArea {
    anchors.fill: parent
    acceptedButtons: Qt.RightButton | Qt.LeftButton
    hoverEnabled: true

    onClicked: function (mouse) {
      if (mouse.button === Qt.RightButton) {
        PanelService.showContextMenu(contextMenu, root, screen);
      } else if (mouse.button === Qt.LeftButton) {
        if (pluginApi) pluginApi.openPanel(root.screen, root);
      }
    }

    onEntered: {
      var tooltipText = buildTooltip();
      if (tooltipText) {
        TooltipService.show(root, tooltipText, BarService.getTooltipDirection());
      }
    }
    onExited: TooltipService.hide()
  }
}