From 9e7d1f4db0d757c11e9539e8e53defcb5b23ef5d Mon Sep 17 00:00:00 2001 From: foglar Date: Sat, 25 Jan 2025 18:36:08 +0100 Subject: [PATCH] cleanup, hyprland and hyprlock --- nixos/home/desktop/hyprland/hyprland.nix | 17 +- nixos/home/desktop/hyprland/hyprlock.nix | 331 +++++++++++++++++- .../system/settings/default-applications.nix | 8 +- 3 files changed, 335 insertions(+), 21 deletions(-) diff --git a/nixos/home/desktop/hyprland/hyprland.nix b/nixos/home/desktop/hyprland/hyprland.nix index 2297e23..799cc47 100644 --- a/nixos/home/desktop/hyprland/hyprland.nix +++ b/nixos/home/desktop/hyprland/hyprland.nix @@ -29,13 +29,15 @@ }; # XDG Portals configuration - xdg.portal.enable = true; - xdg.portal.config = { - common = { - default = ["hyprland"]; + xdg.portal = { + enable = true; + config = { + common = { + default = ["hyprland"]; + }; }; + extraPortals = [pkgs.xdg-desktop-portal-hyprland]; }; - xdg.portal.extraPortals = [pkgs.xdg-desktop-portal-hyprland]; # Services for the Hyprland module services.network-manager-applet.enable = true; @@ -325,7 +327,7 @@ "opacity 0.80 0.80,class:^(qt6ct)$" "opacity 0.80 0.80,class:^(kvantummanager)$" "opacity 0.80 0.70,class:^(org.pulseaudio.pavucontrol)$" - "opacity 0.80 0.70,class:^(blueman-manager)$" + "opacity 0.80 0.70,class:^(.blueman-manager-wrapped)$" "opacity 0.80 0.70,class:^(nm-applet)$" "opacity 0.80 0.70,class:^(nm-connection-editor)$" "opacity 0.80 0.70,class:^(org.kde.polkit-kde-authentication-agent-1)$" @@ -371,7 +373,7 @@ "float,class:^(nwg-look)$" "float,class:^(org.kde.ark)$" "float,class:^(org.pulseaudio.pavucontrol)$" - "float,class:^(blueman-manager)$" + "float,class:^(.blueman-manager-wrapped)$" "float,class:^(nm-applet)$" "float,class:^(nm-connection-editor)$" "float,class:^(org.kde.polkit-kde-authentication-agent-1)$" @@ -403,6 +405,7 @@ "workspace special,title:^(Spotify)$" "float,class:^(post_processing_gui.py)$" "float,title:^(Picture-in-Picture)$" + "pin,title:^(Picture-in-Picture)$" "move 1280 680,title:^(Picture-in-Picture)$" "float,title:^(KDE Connect)$" diff --git a/nixos/home/desktop/hyprland/hyprlock.nix b/nixos/home/desktop/hyprland/hyprlock.nix index 38e646c..e04f3f9 100644 --- a/nixos/home/desktop/hyprland/hyprlock.nix +++ b/nixos/home/desktop/hyprland/hyprlock.nix @@ -1,6 +1,7 @@ { lib, config, + pkgs, ... }: { options = { @@ -8,6 +9,160 @@ }; config = lib.mkIf config.desktop.hyprland.hyprlock.enable { + home.packages = with pkgs; [ + (writeShellScriptBin "battery-hyprlock" + '' + # Get the current battery percentage + battery_percentage=$(${pkgs.toybox}/bin/cat /sys/class/power_supply/BAT1/capacity) + + # Get the battery status (Charging or Discharging) + battery_status=$(${pkgs.toybox}/bin/cat /sys/class/power_supply/BAT1/status) + + # Define the battery icons for each 10% segment + battery_icons=("󰂃" "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰁹") + + # Define the charging icon + charging_icon="󰂄" + + # Calculate the index for the icon array + # Ensure the index is within bounds (0 to 9) for battery percentages 0 to 100 + icon_index=$((battery_percentage / 10)) + + # If the battery is 100%, use the last icon (index 9) + if [ "$battery_percentage" -eq 100 ]; then + icon_index=9 + fi + + # Get the corresponding icon + battery_icon=''${battery_icons[$icon_index]} + + # Check if the battery is charging + if [ "$battery_status" = "Charging" ]; then + battery_icon="$charging_icon" + fi + + # Output the battery percentage and icon + echo "$battery_percentage% $battery_icon" + '') + + (writeShellScriptBin "playerctl-hyprlock" + '' + if [ $# -eq 0 ]; then + echo "Usage: $0 --title | --artist | --album | --source | --source-symbol" + exit 1 + fi + + # Function to get metadata using playerctl + get_metadata() { + key=$1 + playerctl metadata --player=%any,chromium,firefox --format "{{ $key }}" 2>/dev/null + } + + # Check for arguments + + # Function to determine the source and return an icon and text + get_source_info_symbol() { + trackid=$(get_metadata "mpris:trackid") + if [[ "$trackid" == *"firefox"* ]]; then + echo -e "󰈹" + elif [[ "$trackid" == *"spotify"* ]]; then + echo -e "" + elif [[ "$trackid" == *"chromium"* ]]; then + echo -e "" + else + echo "" + fi + } + + get_source_info() { + trackid=$(get_metadata "mpris:trackid") + if [[ "$trackid" == *"firefox"* ]]; then + echo -e "Firefox" + elif [[ "$trackid" == *"spotify"* ]]; then + echo -e "Spotify" + elif [[ "$trackid" == *"chromium"* ]]; then + echo -e "Chrome" + else + echo "" + fi + } + + # Function to truncate text with ellipsis if necessary + truncate_with_ellipsis() { + text=$1 + max_length=$2 + if [ ''${#text} -gt $max_length ]; then + echo "''${text:0:$((max_length - 3))}..." + else + echo "$text" + fi + } + + # Parse the argument + case "$1" in + --title) + title=$(get_metadata "xesam:title") + if [ -z "$title" ]; then + echo "" + else + truncate_with_ellipsis "$title" 28 # Limit the output to 50 characters + fi + ;; + --artist) + artist=$(get_metadata "xesam:artist") + if [ -z "$artist" ]; then + echo "" + else + truncate_with_ellipsis "$artist" 28 # Limit the output to 50 characters + fi + ;; + --status-symbol) + status=$(playerctl status 2>/dev/null) + if [[ $status == "Playing" ]]; then + echo "󰎆" + elif [[ $status == "Paused" ]]; then + echo "󰏥" + else + echo "" + fi + ;; + --status) + status=$(playerctl status 2>/dev/null) + if [[ $status == "Playing" ]]; then + echo "Playing Now" + elif [[ $status == "Paused" ]]; then + echo "Paused" + else + echo "" + fi + ;; + --album) + album=$(playerctl metadata --player=%any,chromium,firefox --format "{{ xesam:album }}" 2>/dev/null) + if [[ -n $album ]]; then + echo "$album" + else + status=$(playerctl status 2>/dev/null) + if [[ -n $status ]]; then + echo "Not album" + else + truncate_with_ellipsis "$album" 28 # Limit the output to 50 characters + fi + fi + ;; + --source-symbol) + get_source_info_symbol + ;; + --source) + get_source_info + ;; + *) + echo "Invalid option: $1" + echo "Usage: $0 --title | --artist | --album | --source | --source-symbol" + exit 1 + ;; + esac'') + ]; + programs.hyprlock = { enable = true; @@ -71,17 +226,173 @@ valign = "center"; }; - label = { - monitor = ""; - text = "$TIME $LAYOUT[!, cz, ru]"; - color = "$text"; - font_size = 40; - #font_family = "Monaspace Xenon"; + label = [ + { + monitor = ""; + text = "$TIME"; + color = "$text"; + font_size = 40; + #font_family = "Monaspace Xenon"; - position = "0, 80"; - halign = "center"; - valign = "center"; - }; + position = "0, 80"; + halign = "center"; + valign = "center"; + } + # Battery percentage + { + monitor = ""; + text = "cmd[update:1000] echo $(battery-hyprlock)"; + + color = "$accent"; + font_size = 12; + + position = "-37, 29"; + halign = "right"; + valign = "bottom"; + zindex = 5; + } + { + # PLAYER TITTLE + monitor = ""; + text = "cmd[update:1000] echo $(playerctl-hyprlock --title)"; + + color = "$fg0"; + font_size = 14; + font_family = "$font-text"; + + position = "0, -400"; + halign = "center"; + valign = "center"; + zindex = 5; + } + + # PLAYER ARTIST + { + monitor = ""; + text = "cmd[update:1000] echo $(playerctl-hyprlock --artist)"; + + color = "$fg0"; + font_size = 11; + font_family = "$font-text"; + + position = "0, -420"; + halign = "center"; + valign = "center"; + zindex = 5; + } + + # PLAYER ALBUM + { + monitor = ""; + text = "cmd[update:1000] echo $(playerctl-hyprlock --album)"; + + color = "$fg0"; + font_size = 11; + font_family = "$font-text0"; + + position = "0, -445"; + halign = "center"; + valign = "center"; + zindex = 5; + } + + # PLAYER STATUS SYMBOL + { + monitor = ""; + text = "cmd[update:1000] echo (playerctl-hyprlock --status-symbol)"; + + color = "$fg0"; + font_size = 16; + font_family = "$font-symbol"; + + position = "700, -370"; + halign = "left"; + valign = "center"; + zindex = 5; + } + + # PLAYER STATUS + { + monitor = ""; + text = "cmd[update:1000] echo $(playerctl-hyprlock --status)"; + + color = "$fg0"; + font_size = 10; + font_family = "$font-text"; + + position = "720, -370"; + halign = "left"; + valign = "center"; + zindex = 5; + } + + # PLAYER SOURCE SYMBOL + { + monitor = ""; + text = "cmd[update:1000] echo $(playerctl-hyprlock --source-symbol)"; + + color = "rgba(255, 255, 255, 0.6)"; + font_size = 16; + font_family = "$font-symbol"; + + position = "-720, -370"; + halign = "right"; + valign = "center"; + zindex = 5; + } + + # PLAYER SOURCE + { + monitor = ""; + text = "cmd[update:1000] echo $(playerctl-hyprlock --source)"; + + color = "rgba(255, 255, 255, 0.6)"; + font_size = 10; + font_family = "$font-text"; + + position = "-740, -370"; + halign = "right"; + valign = "center"; + zindex = 5; + } + ]; + + shape = [ + { + monitor = ""; + size = "90, 40"; + + shadow_passes = "$text-shadow-pass"; + shadow_boost = "$text-shadow-boost"; + + color = "$shape-col0"; + rounding = "$shape-rd"; + border_size = ""; + border_color = ""; + + position = "-20, 20"; + halign = "right"; + valign = "bottom"; + zindex = 1; + } + { + monitor = ""; + size = "550, 120"; + + shadow_passes = "$text-shadow-pass"; + shadow_boost = "$text-shadow-boost"; + + color = "$shape-col1"; + rounding = "$rounding"; + border_size = ""; + border_color = ""; + + position = "0, 70"; + halign = "center"; + valign = "bottom"; + zindex = 1; + } + ]; }; }; }; diff --git a/nixos/system/settings/default-applications.nix b/nixos/system/settings/default-applications.nix index 6879b07..59b25cf 100644 --- a/nixos/system/settings/default-applications.nix +++ b/nixos/system/settings/default-applications.nix @@ -22,9 +22,6 @@ FLAKE = "/home/${userSettings.username}/.dotfiles"; }; - # Default applications configuration - xdg.mime.enable = true; - xdg.da.browser = if userSettings.browser == "qutebrowser" then "org.qutebrowser.qutebrowser" @@ -35,7 +32,9 @@ else "firefox" ); - xdg.mime.defaultApplications = { + xdg.mime = { + enable = true; + defaultApplications = { "text/html" = "${config.xdg.da.browser}.desktop"; "x-scheme-handler/http" = "${config.xdg.da.browser}.desktop"; "x-scheme-handler/https" = "${config.xdg.da.browser}.desktop"; @@ -50,6 +49,7 @@ "inode/directory" = "org.gnome.Nautilus.desktop"; "video/mp4" = "mpv.desktop"; }; + }; programs.zsh.enable = if userSettings.shell == "zsh"