From 5a918d507ab08e35e50dfdb48dddc44f1d1c2dfb Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Fri, 14 Feb 2025 19:32:57 +0100 Subject: [PATCH] feat: add functionalities to bar This is the base of the bar I want to work with. It includes workspaces for Hyprland, a time/calendar widget, and quick settings including: - Toggles for wifi, bluetooth and idle inhibition (using matcha as a dependency) - Sliders for audio and brightness --- flake.lock | 21 +++++++++ flake.nix | 8 ++++ style.scss | 35 ++++++++++++-- widget/Bar.tsx | 114 +++++++++++++++++++++++++++++++++++++++++---- widget/Popover.tsx | 88 ---------------------------------- 5 files changed, 165 insertions(+), 101 deletions(-) delete mode 100644 widget/Popover.tsx diff --git a/flake.lock b/flake.lock index bd25a2b..fb750c4 100644 --- a/flake.lock +++ b/flake.lock @@ -42,6 +42,26 @@ "type": "github" } }, + "matcha": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1738448307, + "narHash": "sha256-jRmfa28gVEDyS7We881BJDpr6L1kla0AgpEWjZ04tZo=", + "ref": "refs/heads/main", + "rev": "90721110060e6b870839df847601d79f9a7a6461", + "revCount": 28, + "type": "git", + "url": "https://codeberg.org/QuincePie/matcha" + }, + "original": { + "type": "git", + "url": "https://codeberg.org/QuincePie/matcha" + } + }, "nixpkgs": { "locked": { "lastModified": 1739020877, @@ -61,6 +81,7 @@ "root": { "inputs": { "ags": "ags", + "matcha": "matcha", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 87d0bab..4fd569c 100644 --- a/flake.nix +++ b/flake.nix @@ -8,17 +8,24 @@ url = "github:aylur/ags"; inputs.nixpkgs.follows = "nixpkgs"; }; + + matcha = { + url = "git+https://codeberg.org/QuincePie/matcha"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self, nixpkgs, ags, + matcha, }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; astalPkgs = with ags.packages.${system}; [ battery + bluetooth hyprland mpris network @@ -47,6 +54,7 @@ extraPackages = astalPkgs; }) pkgs.brightnessctl + matcha.packages.${pkgs.system}.default ]; }; }; diff --git a/style.scss b/style.scss index 9171159..dc3fabd 100644 --- a/style.scss +++ b/style.scss @@ -34,6 +34,13 @@ $accent: #{"@accent_color"}; } } + .Time { + calendar { + label:selected { + background-color: $accent; + } + } + } .Battery label { margin-left: 0; } @@ -42,11 +49,29 @@ $accent: #{"@accent_color"}; image { -gtk-icon-size: 1.2em; } - - menubutton box { + .Audio, + .Wifi { margin-right: 0.5em; - &:last-child { - margin-right: 0; + } + + popover { + min-width: 350px; + + .Toggles { + margin: 0.5em 0; + button image { + -gtk-icon-size: 3em; + } + } + trough highlight { + background-color: $accent; + border-radius: 2em; + } + + slider { + min-height: 1.7em; + min-width: 1.7em; + margin: -0.2em; } } } @@ -59,6 +84,6 @@ $accent: #{"@accent_color"}; } popover { - margin-top: 0.5em; + margin-top: 0.8em; } } diff --git a/widget/Bar.tsx b/widget/Bar.tsx index b560406..85bf6f0 100644 --- a/widget/Bar.tsx +++ b/widget/Bar.tsx @@ -1,14 +1,18 @@ import { Astal, Gtk, Gdk } from "astal/gtk4"; -import { Variable, GLib, bind } from "astal"; +import { Variable, GLib, bind, execAsync, exec } from "astal"; import Battery from "gi://AstalBattery"; +import Bluetooth from "gi://AstalBluetooth"; import Wp from "gi://AstalWp"; import Network from "gi://AstalNetwork"; import Hyprland from "gi://AstalHyprland"; +import Brightness from "../service/brightness"; + +const network = Network.get_default(); +const wifi = bind(network, "wifi"); +const hypr = Hyprland.get_default(); +const bluetooth = Bluetooth.get_default(); function Wifi() { - const network = Network.get_default(); - const wifi = bind(network, "wifi"); - return ( {wifi.as( @@ -31,6 +35,42 @@ function Audio() { ); } +function AudioSlider() { + const speaker = Wp.get_default()?.audio.defaultSpeaker!; + + return ( + + + { + speaker.volume = value; + }} + value={bind(speaker, "volume")} + /> + + ); +} + +function BrightnessSlider() { + const brightness = Brightness.get_default(); + + return ( + + + { + brightness.screen = value; + }} + value={bind(brightness, "screen")} + /> + + ); +} + function BatteryLevel() { const bat = Battery.get_default(); @@ -62,6 +102,29 @@ function Time({ format = "%H:%M - %A %e." }) { ); } +function IdleInhibitor() { + const icon = Variable(getIcon()); + + function getIcon() { + const state = exec("matcha --status"); + const enabled = state.match(/on/g); + return enabled ? "my-caffeine-on-symbolic" : "my-caffeine-off-symbolic"; + } + + function toggle() { + exec("matcha --toggle"); + icon.set(getIcon()); + } + + return ( + +