From ca84e7de34e1d7c1fdbb62614195b97ead689e50 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Tue, 12 Sep 2023 15:27:39 -0400
Subject: [PATCH] feat(ags): add slider box to quick settings

---
 config/ags/js/quick-settings/main.js        |  8 ++-
 config/ags/js/quick-settings/slider-box.js  | 75 +++++++++++++++++++++
 config/ags/scss/widgets/quick-settings.scss |  2 +
 config/ags/style.css                        |  2 +
 4 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/config/ags/js/quick-settings/main.js b/config/ags/js/quick-settings/main.js
index 344acfbe..c8d30b2f 100644
--- a/config/ags/js/quick-settings/main.js
+++ b/config/ags/js/quick-settings/main.js
@@ -1,13 +1,13 @@
 const { Window, CenterBox, Box, Label } = ags.Widget;
 
 import { ButtonGrid } from './button-grid.js';
-//import { SliderBox } from './slider-box';
+import { SliderBox } from './slider-box.js';
 //import { Player } from 
 
 export const QuickSettings = Window({
   name: 'quick-settings',
   layer: 'overlay',
-  //popup: true,
+  popup: true,
   anchor: 'top right',
   child: Box({
     className: 'qs-container',
@@ -22,11 +22,13 @@ export const QuickSettings = Window({
           Label({
             label: 'Control Center',
             className: 'title',
+            halign: 'start',
+            style: 'margin-left: 20px'
           }),
 
           ButtonGrid,
 
-          //SliderBox,
+          SliderBox,
 
         ],
       }),
diff --git a/config/ags/js/quick-settings/slider-box.js b/config/ags/js/quick-settings/slider-box.js
index e69de29b..ed4d6798 100644
--- a/config/ags/js/quick-settings/slider-box.js
+++ b/config/ags/js/quick-settings/slider-box.js
@@ -0,0 +1,75 @@
+const { Box, Slider, Label, Icon } = ags.Widget;
+const { Audio } = ags.Service;
+const { exec } = ags.Utils;
+
+const items = {
+  101: 'audio-volume-overamplified-symbolic',
+  67: 'audio-volume-high-symbolic',
+  34: 'audio-volume-medium-symbolic',
+  1: 'audio-volume-low-symbolic',
+  0: 'audio-volume-muted-symbolic',
+};
+
+export const SliderBox = Box({
+  className: 'slider-box',
+  vertical: true,
+  halign: 'center',
+  children: [
+
+    Box({
+      className: 'slider',
+      valign: 'start',
+      halign: 'center',
+      children: [
+        Icon({
+          size: 26,
+          className: 'slider-label',
+          connections: [[Audio, icon => {
+            if (Audio.speaker) {
+              if (Audio.speaker.isMuted) {
+                icon.icon = items[0];
+              }
+              else {
+                const vol = Audio.speaker.volume * 100;
+                for (const threshold of [-1, 0, 33, 66, 100]) {
+                  if (vol > threshold + 1) {
+                    icon.icon = items[threshold + 1];
+                  }
+                }
+              }
+            }
+          }, 'speaker-changed']],
+        }),
+
+        Slider({
+          value: `${exec('bash -c "$EWW_PATH/volume.sh vol"')}`,
+          onChange: 'bash -c "$EWW_PATH/volume.sh set {}"',
+          min: 0,
+          max: 100,
+          draw_value: false,
+        }),
+      ],
+    }),
+
+    Box({
+      className: 'slider',
+      valign: 'start',
+      halign: 'center',
+      children: [
+        Icon({
+          className: 'slider-label',
+          icon: 'display-brightness-symbolic',
+        }),
+
+        Slider({
+          value: `${exec('brightnessctl get') / 2.55}`,
+          onChange: "brightnessctl set {}%",
+          min: 0,
+          max: 100,
+          draw_value: false,
+        }),
+      ],
+    }),
+
+  ],
+});
diff --git a/config/ags/scss/widgets/quick-settings.scss b/config/ags/scss/widgets/quick-settings.scss
index f65f7bf0..8aaa047f 100644
--- a/config/ags/scss/widgets/quick-settings.scss
+++ b/config/ags/scss/widgets/quick-settings.scss
@@ -1,4 +1,6 @@
 .quick-settings {
+  margin-right: 5px;
+  margin-top: 8px;
   font-size: 30px;
   min-width: 500px;
   padding: 0px 0px 0px 0px;
diff --git a/config/ags/style.css b/config/ags/style.css
index 3b7223c3..4e79a27f 100644
--- a/config/ags/style.css
+++ b/config/ags/style.css
@@ -456,6 +456,8 @@ calendar:indeterminate {
   color: #262831; }
 
 .quick-settings {
+  margin-right: 5px;
+  margin-top: 8px;
   font-size: 30px;
   min-width: 500px;
   padding: 0px 0px 0px 0px;