diff --git a/.scripts/change-colortheme.py b/.scripts/change-colortheme.py index 389111c..cc86a6a 100755 --- a/.scripts/change-colortheme.py +++ b/.scripts/change-colortheme.py @@ -40,6 +40,7 @@ import shutil import argparse from typing import Callable + FLAVOR_NAME_PLACEHOLDER = "" FLAVOR_HEX_PLACEHOLDER = "" @@ -105,6 +106,10 @@ def copy_template(src: Path, dist_dir: Path | None) -> Path: return dist +def hex2rgb(hex_color: str) -> tuple[int, int, int]: + return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4)) # type: ignore + + def _change_kvantum(_, flavor): os.system(f'kvantummanager --set catppuccin-mocha-{flavor}') # execute twice to ensure the theme is installed AND applied @@ -208,7 +213,7 @@ apply_theme_funcs: dict[str, Callable[[dict[str, str], str], None]] = { 'hypr': _change_hypr, 'rofi': _change_rofi, 'waybar': _change_waybar, - 'oh-myposh': _change_ohmyposh, + 'oh-my-posh': _change_ohmyposh, 'fastfetch': _change_fastfetch, 'mako': _change_mako, 'yazi': _change_yazi, @@ -229,9 +234,6 @@ def match_color(color: str, palette: dict[str, str]) -> str: color = color.lower().strip().removeprefix('#') - def hex2rgb(hex_color: str) -> tuple[int, int, int]: - return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4)) # type: ignore - # weigh by CCIR 601 luminosity fr, fg, fb = 0.299 / 255 / 255, 0.587 / 255 / 255, 0.114 / 255 / 255 lfr, lfg, lfb = 0.299 / 255, 0.587 / 255, 0.114 / 255 @@ -282,6 +284,39 @@ def match_color(color: str, palette: dict[str, str]) -> str: return closest_color +def pick_flavor(palette: dict[str, str]) -> str: + def is_interactive() -> bool: + return sys.stdin.isatty() and sys.stdout.isatty() + + def is_truecolor() -> bool: + colorterm = os.environ.get('COLORTERM', '') + term = os.environ.get('TERM', '') + + return ( + 'truecolor' in colorterm or + '24bit' in colorterm or + term.endswith('-256color') + ) + + if is_interactive(): + isTruecolor = is_truecolor() + print("Available flavors:") + for i, flavor in enumerate(palette.keys(), 1): + r, g, b = hex2rgb(palette[flavor]) + if isTruecolor: + print(f"\033[38;2;{r};{g};{b}m█ {i}. {flavor}: #{palette[flavor]}\033[0m") + else: + print(f"{i}. {flavor}") + while True: + choice = input("Pick a flavor by number: ") + if choice.isdigit() and 1 <= int(choice) <= len(palette): + return list(palette.keys())[int(choice) - 1] + print("Invalid choice. Try again.") + else: + print("No flavor specified.") + sys.exit(1) + + def main(): parser = argparse.ArgumentParser(description="Change color theme for various applications.") parser.add_argument('-i', '--image', type=str, help="Path to the image") @@ -313,8 +348,7 @@ def main(): flavor = match_color(color, palette) print(f"Extracted color: {flavor}") else: - import random - flavor = random.choice(list(palette.keys())) + flavor = pick_flavor(palette) return flavor def parse_apps() -> list[str]: diff --git a/.scripts/change-wallpaper.fish b/.scripts/change-wallpaper.fish deleted file mode 100755 index 96c259c..0000000 --- a/.scripts/change-wallpaper.fish +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/fish - -# if the path is given as an argument, use that -if test (count $argv) -eq 1 - set image $argv[1] -else - set image (zenity --file-selection --title="Open File" --file-filter="*.jpg *.jpeg *.png") -end - -if test -z "$image" - exit 1 -end -if not test -f "$image" - notify-send "Error" "Selected file does not exist." - exit 1 -end -if string match -q "* *" "$image" - notify-send "Error" "The path of selected file contains white spaces, please select a file without white spaces." - exit 1 -end - -hyprctl hyprpaper reload ,"$image" -echo "preload = $image" > ~/.config/hypr/hyprpaper.conf -echo "wallpaper = , $image" >> ~/.config/hypr/hyprpaper.conf - -notify-send "Wallpaper Changed" "$image" - -notify-send "Extracting colors from wallpaper" "This may take a few seconds..." -change-colortheme.py -i "$image" \ No newline at end of file diff --git a/.scripts/change-wallpaper.sh b/.scripts/change-wallpaper.sh new file mode 100755 index 0000000..238dfda --- /dev/null +++ b/.scripts/change-wallpaper.sh @@ -0,0 +1,23 @@ +#!/bin/env bash + +if [ -z "$1" ]; then + image=$(zenity --file-selection --title="Open File" --file-filter="*.jpg *.jpeg *.png *.webp *.bmp *.jfif *.tiff *.avif *.heic *.heif") +else + image="$1" +fi + +[ -z "$image" ] && exit 1 + +ext=${image##*.} +image_copied="$HOME/.config/hypr/wallpaper.$ext" + +cp -f "$image" "$image_copied" || exit 1 + +hyprctl hyprpaper reload ,"$image_copied" || exit 1 +echo "preload = $image_copied" >"$HOME/.config/hypr/hyprpaper.conf" +echo "wallpaper = , $image_copied" >>"$HOME/.config/hypr/hyprpaper.conf" + +notify-send "Wallpaper Changed" "$image" + +notify-send "Extracting colors from wallpaper" "This may take a few seconds..." +change-colortheme.py -i "$image_copied" || exit 1 diff --git a/.utils/set_display b/.utils/set_display new file mode 100644 index 0000000..9f39bc7 --- /dev/null +++ b/.utils/set_display @@ -0,0 +1,27 @@ +Intel_ID="$(lspci -d ::03xx | grep Intel | cut -f 1 -d ' ')" +NVIDIA_ID="$(lspci -d ::03xx | grep NVIDIA | cut -f 1 -d ' ')" + +for file in /dev/dri/by-path/*card; do + real_target=$(readlink -f "$file") + if [[ "$file" == *"$Intel_ID"* ]]; then + Intel_DRI_PATH="$real_target" + elif [[ "$file" == *"$NVIDIA_ID"* ]]; then + NVIDIA_DRI_PATH="$real_target" + fi +done + +if [ -n "$Intel_DRI_PATH" ]; then + export HYPR_DISPLAY_DEVICE=intel_backlight + # if [ -n "$NVIDIA_DRI_PATH" ]; then + # export HYPR_AQ_DRM_DEVICES="$NVIDIA_DRI_PATH:$Intel_DRI_PATH" + # else + # export HYPR_AQ_DRM_DEVICES="$Intel_DRI_PATH" + # fi +elif [ -n "$NVIDIA_DRI_PATH" ]; then + export HYPR_DISPLAY_DEVICE=nvidia_0 + # export HYPR_AQ_DRM_DEVICES="$NVIDIA_DRI_PATH" +else + export HYPR_DISPLAY_DEVICE + # export HYPR_AQ_DRM_DEVICES=/dev/dri/card0 +fi + diff --git a/eww/Lyrics/eww.scss b/eww/Lyrics/eww.scss index 54cd57b..be3d8cc 100644 --- a/eww/Lyrics/eww.scss +++ b/eww/Lyrics/eww.scss @@ -73,7 +73,7 @@ .offset-minus, .offset-minus-single { - color: $border; + color: $blue; } .offset-plus, diff --git a/fish/functions/__bass.py b/fish/functions/__bass.py index d56d880..b761e3f 100755 --- a/fish/functions/__bass.py +++ b/fish/functions/__bass.py @@ -1,18 +1,3 @@ -''' -Author: Uyanide pywang0608@foxmail.com -Date: 2025-06-14 20:23:25 -LastEditTime: 2025-08-03 01:15:54 -Description: -''' -""" -To be used with a companion fish function like this: - - function refish - set -l _x (python /tmp/bass.py source ~/.nvm/nvim.sh ';' nvm use iojs); source $_x; and rm -f $_x - end - -""" - from __future__ import print_function import json @@ -31,9 +16,10 @@ FISH_READONLY = [ ] IGNORED = [ - 'PS1', 'XPC_SERVICE_NAME' + 'PS1', 'XPC_SERVICE_NAME' ] + def ignored(name): if name == 'PWD': # this is read only, but has special handling return False @@ -46,16 +32,20 @@ def ignored(name): return True return False + def escape(string): # use json.dumps to reliably escape quotes and backslashes return json.dumps(string).replace(r'$', r'\$') + def escape_identifier(word): return escape(word.replace('?', '\\?')) + def comment(string): return '\n'.join(['# ' + line for line in string.split('\n')]) + def gen_script(): # Use the following instead of /usr/bin/env to read environment so we can # deal with multi-line environment variables (and other odd cases). @@ -66,7 +56,7 @@ def gen_script(): pipe_r, pipe_w = os.pipe() if sys.version_info >= (3, 4): - os.set_inheritable(pipe_w, True) + os.set_inheritable(pipe_w, True) command = 'eval $1 && ({}; alias) >&{}'.format( env_reader, pipe_w @@ -126,6 +116,7 @@ def gen_script(): return script + '\n' + alias + script_file = os.fdopen(3, 'w') if not sys.argv[1:]: @@ -138,7 +129,7 @@ except subprocess.CalledProcessError as e: sys.exit(e.returncode) except Exception: print('Bass internal error!', file=sys.stderr) - raise # traceback will output to stderr + raise # traceback will output to stderr except KeyboardInterrupt: signal.signal(signal.SIGINT, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGINT) diff --git a/hypr/.gitignore b/hypr/.gitignore index 4039784..2def4fe 100644 --- a/hypr/.gitignore +++ b/hypr/.gitignore @@ -1 +1,2 @@ -shaders \ No newline at end of file +shaders +wallpaper* \ No newline at end of file diff --git a/hypr/hyprland.conf b/hypr/hyprland.conf index 481952a..8bf1254 100755 --- a/hypr/hyprland.conf +++ b/hypr/hyprland.conf @@ -1,7 +1,3 @@ -# This file sources other files in `hyprland` and `custom` folders -# You wanna add your stuff in file in `custom` - -# Defaults source=~/.config/hypr/hyprland/env.conf source=~/.config/hypr/hyprland/execs.conf source=~/.config/hypr/hyprland/general.conf diff --git a/hypr/hyprland/env.conf b/hypr/hyprland/env.conf index eec1367..93fa60a 100755 --- a/hypr/hyprland/env.conf +++ b/hypr/hyprland/env.conf @@ -18,10 +18,11 @@ env = QT_STYLE_OVERRIDE, kvantum # ############ nvidia ############# env = LIBVA_DRIVER_NAME,nvidia +env = __GLX_VENDOR_LIBRARY_NAME,nvidia env = NVD_BACKEND,direct +# env = AQ_DRM_DEVICES,$HYPR_AQ_DRM_DEVICES # ############ others ############# env = XCURSOR_SIZE,24 env = HYPRCURSOR_SIZE,24 env = ELECTRON_OZONE_PLATFORM_HINT,auto -env = DISPLAY_DEVICE,intel_backlight # or nvidia_0 diff --git a/hypr/hyprland/general.conf b/hypr/hyprland/general.conf index eee378d..e04b85c 100755 --- a/hypr/hyprland/general.conf +++ b/hypr/hyprland/general.conf @@ -1,7 +1,7 @@ # MONITOR CONFIG monitor=,preferred,auto,1 -monitor=eDP-1,2560x1600@240,auto,1.25 # dGPU only -monitor=eDP-2,2560x1600@240,auto,1.25,bitdepth,10 # iGPU & dGPU hybrid +monitor=eDP-1,2560x1600@240,auto,1.25,bitdepth,10 +monitor=eDP-2,2560x1600@240,auto,1.25,bitdepth,10 # monitor=,addreserved, 0, 0, 0, 0 # Custom reserved area # HDMI port: mirror display. To see device name, use `hyprctl monitors` @@ -175,4 +175,4 @@ plugin { xwayland { force_zero_scaling = true -} \ No newline at end of file +} diff --git a/hypr/hyprpaper.conf b/hypr/hyprpaper.conf index 534fb81..0b3f9b4 100644 --- a/hypr/hyprpaper.conf +++ b/hypr/hyprpaper.conf @@ -1,2 +1,2 @@ -preload = /home/kolkas/.config/backgrounds/nanami.png -wallpaper = , /home/kolkas/.config/backgrounds/nanami.png +preload = /home/kolkas/.config/hypr/wallpaper.png +wallpaper = , /home/kolkas/.config/hypr/wallpaper.png diff --git a/waybar/config.jsonc b/waybar/config.jsonc index b1b7be4..2242384 100644 --- a/waybar/config.jsonc +++ b/waybar/config.jsonc @@ -73,7 +73,7 @@ "min-length": 20 }, "custom/publicip": { - "interval": 60, + "interval": 30, "return-type": "json", "format": " {text}", "tooltip-format": "{alt}", @@ -131,8 +131,8 @@ "format-alt-click": "click-right", //"format-icons": ["", ""], "format-icons": [""], - "on-scroll-down": "brightnessctl -d $DISPLAY_DEVICE set 5%-", - "on-scroll-up": "brightnessctl -d $DISPLAY_DEVICE set +5%", + "on-scroll-down": "brightnessctl -d $HYPR_DISPLAY_DEVICE set 5%-", + "on-scroll-up": "brightnessctl -d $HYPR_DISPLAY_DEVICE set +5%", "max-length": 6, "min-length": 6 }, diff --git a/waybar/modules/publicip.sh b/waybar/modules/publicip.sh index b0ad44c..7576638 100755 --- a/waybar/modules/publicip.sh +++ b/waybar/modules/publicip.sh @@ -25,6 +25,19 @@ time_log="$path/publicip.log" [ "$1" == "force" ] && rm -f "$cache_file" [ -f "$cache_file" ] && . "$cache_file" +# Try to check network connectivity before querying +if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then + # No network, return cached values if available + [ -z "$CACHED_IP" ] && CACHED_IP="N/A" + [ -z "$CACHED_CODE" ] && CACHED_CODE="N/A" + + jq -n --unbuffered --compact-output \ + --arg ip "$CACHED_IP" \ + --arg country "$CACHED_CODE" \ + '{alt: $ip, text: $country}' + exit 0 +fi + ip_current=$(curl -s -L -4 "$IP_QUERY_URL" | jq -r '.ip') [ -z "$ip_current" ] && exit 1