summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/BrightnessWidget.qml
blob: 7f9c1ad0c58b5a701ed31afa4c535e10ec4bc46d (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
import QtQuick
import Quickshell
import Quickshell.Widgets
import qs.Services

Item {
  height: parent.height
  width: brightnessIcon.width + 8
  anchors.verticalCenter: parent.verticalCenter

  WrapperMouseArea {
    id: widgetMouseArea

    anchors.fill: parent

    hoverEnabled: true

    property real sensitivity: (1 / 50) / 120
    onWheel: event => Brightness.currBrightness += event.angleDelta.y * sensitivity

    Item {
      anchors.fill: parent

      MaterialDesignIcon {
	id: brightnessIcon

	implicitSize: 14
	anchors.centerIn: parent

	icon: `brightness-${Math.min(7, Math.floor(Brightness.currBrightness * 7) + 1)}`
	color: "#555"
      }
    }
  }

  PopupWindow {
    id: tooltip

    property bool nextVisible: widgetMouseArea.containsMouse || tooltipMouseArea.containsMouse

    anchor {
      item: widgetMouseArea
      edges: Edges.Bottom | Edges.Left
    }
    visible: false

    onNextVisibleChanged: hangTimer.restart()

    Timer {
      id: hangTimer
      interval: 100
      onTriggered: tooltip.visible = tooltip.nextVisible
    }

    implicitWidth: widgetTooltipText.contentWidth + 16
    implicitHeight: widgetTooltipText.contentHeight + 16
    color: "black"

    WrapperMouseArea {
      id: tooltipMouseArea

      hoverEnabled: true
      enabled: true

      anchors.centerIn: parent

      Text {
	id: widgetTooltipText

	font.pointSize: 10
	font.family: "Fira Sans"
	color: "white"

	text: `${Math.round(Brightness.currBrightness * 100)}%`
      }
    }
  }
}