From ab380782c3e5d09d4eeb7e9268399b1b5092fe6d Mon Sep 17 00:00:00 2001 From: marc Date: Sun, 8 Dec 2024 19:03:42 +0100 Subject: [PATCH] Added brightness notifications --- config/doom/config.el | 2 +- config/grapheio/scripts/brightness.sh | 72 +++++++++++++++++++++++++++ config/shell/sh/002-aliases.sh | 2 +- modules/desktop/grapheio.nix | 14 +++++- modules/shell/zsh.nix | 5 -- modules/system/brightness.nix | 23 --------- 6 files changed, 87 insertions(+), 31 deletions(-) create mode 100755 config/grapheio/scripts/brightness.sh diff --git a/config/doom/config.el b/config/doom/config.el index 13aa164..09df1ea 100644 --- a/config/doom/config.el +++ b/config/doom/config.el @@ -11,7 +11,7 @@ ;; Fonts (setq doom-font (font-spec :family "Iosevka Nerd Font" :size 15)) -(setq doom-unicode-font (font-spec :family "Iosevka Nerd Font" :size 15)) +(setq doom-symbol-font (font-spec :family "Iosevka Nerd Font" :size 15)) ;; Themeing ;; (use-package base16-theme diff --git a/config/grapheio/scripts/brightness.sh b/config/grapheio/scripts/brightness.sh new file mode 100755 index 0000000..a3e21c5 --- /dev/null +++ b/config/grapheio/scripts/brightness.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# Dependencies: +# - amixer +# - pactl +# - jq +# - libnotify + +ACTION=$1 + +get_brightness() { + brightnessctl | \ + grep "Current brightness" | \ + sed -e 's/^\s\+Current brightness: [0-9]\+ (\([0-9]\+\)%).*$/\1/' +} + +get_kb_brightness() { + brightnessctl -d platform::kbd_backlight | \ + grep "Current brightness" | \ + sed -e 's/^\s\+Current brightness: [0-9]\+ (\([0-9]\+\)%).*$/\1/' +} + +notify() { + notify-send "$1" "$2" -e -t 1500 -h string:x-canonical-private-synchronous:brightness +} + +set_brightness() { + # Set the brightness + TARGET=$1 + brightnessctl set $TARGET > /dev/null + + # Send a notification + BRIGHTNESS=$(get_brightness) + ACTION=$([[ ${TARGET:0:1} == "+" ]] && echo "Brightness Up" || echo "Brightness Down") + + BRIGHTNESS_ICON="󰃠" + + TITLE=$(echo "$BRIGHTNESS_ICON $ACTION") + BODY=$(echo "$BRIGHTNESS%") + notify "$TITLE" "$BODY" +} + +set_kb_brightness() { + # Set the brightness + TARGET=$1 + brightnessctl -d platform::kbd_backlight set $TARGET > /dev/null + + # Send a notification + BRIGHTNESS=$(get_kb_brightness) + ACTION=$([[ ${TARGET:0:1} == "+" ]] && echo "Keyboard brightness Up" || echo "Keyboard brightness Down") + + BRIGHTNESS_ICON="󰃠" + + TITLE=$(echo "$BRIGHTNESS_ICON $ACTION") + BODY=$(echo "$BRIGHTNESS%") + notify "$TITLE" "$BODY" +} + + +case $ACTION in + set) + set_brightness $2 + ;; + kb_set) + set_kb_brightness $2 + ;; + *) + echo "Unknown action" + exit 1 + ;; +esac + diff --git a/config/shell/sh/002-aliases.sh b/config/shell/sh/002-aliases.sh index 54aad01..1284176 100644 --- a/config/shell/sh/002-aliases.sh +++ b/config/shell/sh/002-aliases.sh @@ -1,5 +1,5 @@ [[ -x "$(command -v eza)" ]] && { - alias ll="eza --group-directories-first --color=auto --git -la" + alias ll="eza --group-directories-first --color=auto --icons=auto --git -la" } || { alias ll="ls -alh --color=always --group-directories-first" } diff --git a/modules/desktop/grapheio.nix b/modules/desktop/grapheio.nix index 409d8da..9275a85 100644 --- a/modules/desktop/grapheio.nix +++ b/modules/desktop/grapheio.nix @@ -65,12 +65,24 @@ in ", XF86AudioNext, exec, playerctl next" ", XF86AudioPrev, exec, playerctl previous" ", XF86AudioStop, exec, playerctl stop" + + # Keyboard brightness control + "${hyprCfg.mod}, XF86MonBrightnessUp, exec, brightnessctl -d platform::kbd_backlight set +1" + "${hyprCfg.mod}, XF86MonBrightnessDown, exec, brightnessctl -d platform::kbd_backlight set -1" ]; binde = [ - # Pulse Audio controls (volume) + # Pulse Audio controls (keep button pressed) ", XF86AudioRaiseVolume, exec, $HOME/.config/grapheio/scripts/volume.sh set +5%" ", XF86AudioLowerVolume, exec, $HOME/.config/grapheio/scripts/volume.sh set -5%" + + # Brightness control (keep button pressed) + ", XF86MonBrightnessUp, exec, $HOME/.config/grapheio/scripts/brightness.sh set +5%" + ", XF86MonBrightnessDown, exec, $HOME/.config/grapheio/scripts/brightness.sh set 5%-" + + # Keyboard brightness control (keep button pressed) + "${hyprCfg.mod}, XF86MonBrightnessUp, exec, $HOME/.config/grapheio/scripts/brightness.sh kb_set +1" + "${hyprCfg.mod}, XF86MonBrightnessDown, exec, $HOME/.config/grapheio/scripts/brightness.sh kb_set 1-" ]; }; diff --git a/modules/shell/zsh.nix b/modules/shell/zsh.nix index f1f0540..04ccb2a 100644 --- a/modules/shell/zsh.nix +++ b/modules/shell/zsh.nix @@ -14,11 +14,6 @@ in zsh-powerlevel10k ]; - # fonts.packages = with pkgs; [ - # iosevka - # (nerdfonts.override { fonts = [ "Iosevka" ]; }) - # ]; - programs.zsh.enable = true; hm.programs.zsh = { enable = true; diff --git a/modules/system/brightness.nix b/modules/system/brightness.nix index dac1e7b..005edd4 100644 --- a/modules/system/brightness.nix +++ b/modules/system/brightness.nix @@ -15,28 +15,5 @@ in environment.systemPackages = with pkgs; [ brightnessctl ]; - - # - Hyprland keybindings --------------------- - hm.wayland.windowManager.hyprland.settings = lib.mkIf hyprCfg.enable { - bind = [ - # Brightness control - ", XF86MonBrightnessUp, exec, brightnessctl set +5%" - ", XF86MonBrightnessDown, exec, brightnessctl set -5%" - - # Keyboard brightness control - "${hyprCfg.mod}, XF86MonBrightnessUp, exec, brightnessctl -d platform::kbd_backlight set +1" - "${hyprCfg.mod}, XF86MonBrightnessDown, exec, brightnessctl -d platform::kbd_backlight set -1" - ]; - - binde = [ - # Brightness control (keep button pressed) - ", XF86MonBrightnessUp, exec, brightnessctl set +5%" - ", XF86MonBrightnessDown, exec, brightnessctl set 5%-" - - # Keyboard brightness control (keep button pressed) - "${hyprCfg.mod}, XF86MonBrightnessUp, exec, brightnessctl -d platform::kbd_backlight set +1" - "${hyprCfg.mod}, XF86MonBrightnessDown, exec, brightnessctl -d platform::kbd_backlight set 1-" - ]; - }; }; }