summaryrefslogtreecommitdiff
path: root/common/modules/window_managers/scripts.nix
diff options
context:
space:
mode:
Diffstat (limited to 'common/modules/window_managers/scripts.nix')
-rw-r--r--common/modules/window_managers/scripts.nix387
1 files changed, 386 insertions, 1 deletions
diff --git a/common/modules/window_managers/scripts.nix b/common/modules/window_managers/scripts.nix
index 1d854ae..4a93928 100644
--- a/common/modules/window_managers/scripts.nix
+++ b/common/modules/window_managers/scripts.nix
@@ -1,6 +1,6 @@
{ pkgs, config }:
-{
+rec {
terminal = pkgs.writeShellScript "terminal" ''
TERM="${config.beeMods.terminal.default}"
SESSION="_main"
@@ -20,4 +20,389 @@
fi
fi
'';
+ dotfiles = pkgs.writeShellScriptBin "dotfiles" ''
+ case "$1" in
+ cd)
+ cd "$HOME/.config/beeSystems"
+ ;;
+ edit)
+ "$EDITOR" "$HOME/.config/beeSystems"
+ ;;
+ flake)
+ case "$2" in
+ update)
+ (
+ cd "$HOME/.config/beeSystems" || exit 1
+ nix flake update
+ )
+ ;;
+ esac
+ ;;
+ esac
+ '';
+ update_gtk_theme = pkgs.writeShellScript "update_gtk_theme" ''
+ if [ "$1" = "dark" ]; then
+ dconf write /org/gnome/desktop/interface/color-scheme "'prefer-light'"
+ else
+ dconf write /org/gnome/desktop/interface/color-scheme "'prefer-dark'"
+ fi
+
+ dconf write /org/gnome/desktop/interface/color-scheme "'prefer-$1'"
+ systemctl --user restart xdg-desktop-portal-gtk
+ '';
+ volume = pkgs.writeShellScript "volume" ''
+ TAG="audio-volume"
+ case $1 in
+ up) wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ ;;
+ down) wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- ;;
+ toggle) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
+ esac
+
+ status=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
+ vol=$(awk '{print int($2 * 100)}' <<< "$status")
+
+ case "$status" in
+ *MUTED*)
+ dunstify -a "Volume" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ "Volume: Muted"
+ ;;
+ *)
+ dunstify -a "Volume" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ -h int:value:"$vol" \
+ "Volume: $vol%"
+ ;;
+ esac
+ '';
+ micToggle = pkgs.writeShellScript "micToggle" ''
+ TAG="audio-mic"
+
+ wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
+
+ status=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)
+
+ if [[ "$status" == *MUTED* ]]; then
+ dunstify -a "Microphone" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ "Microphone: Muted"
+ else
+ dunstify -a "Microphone" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ "Microphone: On"
+ fi
+ '';
+ brightness = pkgs.writeShellScript "brightness" ''
+ TAG="screen-brightness"
+
+ case "$1" in
+ up) brightnessctl set +5% > /dev/null ;;
+ down) brightnessctl set 5%- > /dev/null ;;
+ esac
+
+ current=$(brightnessctl -m | cut -d, -f4 | tr -d '%')
+
+ dunstify -a "Brightness" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ -h int:value:"$current" \
+ "Brightness: $current%"
+ '';
+ screenshot = pkgs.writeShellScript "screenshot" ''
+ case $1 in
+ full)
+ ${pkgs.grim}/bin/grim - | wl-copy
+ ;;
+ selection)
+ GEOM=$(${pkgs.slurp}/bin/slurp) || exit
+ ${pkgs.grim}/bin/grim -g "$GEOM" - | wl-copy
+ ;;
+ window)
+ ${pkgs.grim}/bin/grim -g "$(mmsg -x | awk '
+ / x / {x=$3}
+ / y / {y=$3}
+ / width / {w=$3}
+ / height / {h=$3}
+ END {print x "," y " " w "x" h}
+ ')" - | wl-copy
+ ;;
+ esac
+ '';
+ dostuff = pkgs.writeShellScript "dostuff" ''
+ exec 2>/dev/null
+ : "''${CONFIG_FILE:=$HOME/.config/beestuff/conf}"
+ : "''${WALL_DIR:=$HOME/Pictures/Wallpapers}"
+ : "''${THUMB_DIR:=$HOME/.cache/beestuff/thumbnails}"
+
+ init_settings() {
+ [ -f "$CONFIG_FILE" ] && return 0
+
+ local config_dir
+ config_dir=$(dirname -- "$CONFIG_FILE")
+
+ mkdir -p -- "$config_dir"
+
+ cat > "$CONFIG_FILE" <<EOF
+ theme=dark
+ nightlight=off
+ wallpaper=$WALL_DIR/default.jpg
+ color_type=scheme-tonal-spot
+ EOF
+ }
+
+ get_val() {
+ grep "^$1=" "$CONFIG_FILE" | cut -d= -f2-
+ }
+
+ set_val() {
+ sed -i "s|^$1=.*|$1=$2|" "$CONFIG_FILE"
+ }
+
+ set_layout() {
+ mmsg dispatch setlayout,"$1"
+ }
+
+ hash_path() {
+ printf '%s' "$1" | md5sum | cut -d' ' -f1
+ }
+
+ ensure_thumb() {
+ local img="$1"
+ local hash thumb candidate
+
+ hash=$(hash_path "$img")
+ thumb="$THUMB_DIR/$hash.jpg"
+
+ [ -f "$thumb" ] && {
+ printf '%s' "$thumb"
+ return 0
+ }
+
+ mkdir -p -- "$THUMB_DIR"
+
+ if command -v magick >/dev/null 2>&1; then
+ magick "$img" \
+ -resize 400x300^ \
+ -gravity center \
+ -extent 400x300 \
+ "$thumb"
+
+ elif command -v convert >/dev/null 2>&1; then
+ convert "$img" \
+ -resize 400x300^ \
+ -gravity center \
+ -extent 400x300 \
+ "$thumb"
+
+ elif command -v ffmpeg >/dev/null 2>&1; then
+ ffmpeg -hide_banner -loglevel error \
+ -i "$img" \
+ -vf "scale=400:300:force_original_aspect_ratio=cover,crop=400:300" \
+ -frames:v 1 \
+ "$thumb"
+
+ else
+ printf '%s' "$img"
+ return 0
+ fi
+
+ [ -f "$thumb" ] || thumb="$img"
+
+ printf '%s' "$thumb"
+ }
+
+ list_walls() {
+ local wall
+
+ for wall in "$WALL_DIR"/*.{jpg,jpeg,png,webp}; do
+ [ -f "$wall" ] || continue
+
+ printf '%s\0icon\x1f%s\n' \
+ "''${wall##*/}" \
+ "$(ensure_thumb "$wall")"
+ done
+ }
+
+ apply_all() {
+ local theme=$(get_val "theme")
+ local wall=$(get_val "wallpaper")
+ local color_type=$(get_val "color_type")
+ local mode_flag="dark"
+
+ mode_flag="dark"
+ [ "$theme" = "light" ] && mode_flag="light"
+
+ matugen image "$wall" \
+ -r lanczos3 \
+ --continue-on-error \
+ -m "$mode_flag" \
+ -t "$color_type" \
+ --source-color-index 0
+
+
+ "${update_gtk_theme}" "$mode_flag"
+
+ if [ -z "$WAYLAND_DISPLAY" ] && [ -n "$DISPLAY" ]; then
+ xrdb -merge "$HOME/.Xresources"
+ fi
+
+ local seq_file="$HOME/.local/share/bee/sequences"
+ [ -f "$seq_file" ] && sh "$seq_file"
+ }
+
+ cmd_wall() {
+ local selected full_path
+
+ selected=$(
+ list_walls |
+ rofi -dmenu -i -p "Wallpaper" \
+ -show-icons \
+ -theme-str 'element { orientation: vertical; padding: 15px; }' \
+ -theme-str 'element-icon { size: 10em; horizontal-align: 0.5; }' \
+ -theme-str 'listview { columns: 4; lines: 2; }' \
+ -theme-str 'window { width: 50%; }'
+ )
+
+ [ -n "$selected" ] || return 0
+
+ full_path="$WALL_DIR/$selected"
+ set_val "wallpaper" "$full_path"
+
+ if [ -n "$WAYLAND_DISPLAY" ]; then
+ if command -v awww >/dev/null 2>&1; then
+ awww img "$full_path" \
+ --transition-type grow \
+ --transition-fps 120 \
+ --transition-step 60 \
+ --transition-duration 1.5
+ else
+ pkill swaybg
+ swaybg -i "$full_path" -m fill &
+ fi
+ else
+ feh --no-fehbg --bg-fill "$full_path"
+ fi
+
+ apply_all
+ }
+
+ clr_type() {
+ local schemes selection
+
+ schemes=(
+ "scheme-tonal-spot"
+ "scheme-content"
+ "scheme-expressive"
+ "scheme-fidelity"
+ "scheme-fruit-salad"
+ "scheme-monochrome"
+ "scheme-neutral"
+ "scheme-rainbow"
+ "scheme-vibrant"
+ )
+
+ selection=$(
+ printf '%s\n' "''${schemes[@]}" |
+ rofi -dmenu -i -p "Colorscheme Types"
+ )
+
+ [ -n "$selection" ] || return 0
+
+ set_val "color_type" "$selection"
+ apply_all
+ }
+
+ cmd_layout() {
+ local layouts selection
+
+ layouts=(
+ tile
+ monocle
+ scroller
+ fair
+ dwindle
+ grid
+ deck
+ center_tile
+ right_tile
+ vertical_scroller
+ vertical_tile
+ vertical_grid
+ vertical_fair
+ vertical_deck
+ )
+
+ selection=$(
+ printf '%s\n' "''${layouts[@]}" |
+ rofi -dmenu -i -p "Layout"
+ )
+
+ [ -n "$selection" ] || return 0
+
+ set_layout "$selection"
+ }
+
+ cmd_settings() {
+ local theme nl ct choice
+
+ theme=$(get_val "theme")
+ nl=$(get_val "nightlight")
+ ct=$(get_val "color_type")
+
+ choice=$(
+ printf '%s\n' \
+ "Mode: $theme" \
+ "Night Light: $nl" \
+ "Wallpaper" \
+ "Colorscheme Type: $ct" \
+ "Layouts" |
+ rofi -dmenu -p "Settings" -i
+ )
+
+ case "$choice" in
+ "Mode: "*)
+ if [ "$theme" = "dark" ]; then
+ set_val "theme" "light"
+ else
+ set_val "theme" "dark"
+ fi
+ apply_all
+ ;;
+
+ "Night Light: "*)
+ if [ "$nl" = "on" ]; then
+ set_val "nightlight" "off"
+ pkill wlsunset
+ else
+ set_val "nightlight" "on"
+ exec wlsunset -T 4500
+ fi
+ ;;
+
+ "Wallpaper")
+ cmd_wall
+ ;;
+
+ "Colorscheme Type:"*)
+ clr_type
+ ;;
+
+ "Layouts")
+ cmd_layout
+ ;;
+ esac
+ }
+
+ init_settings
+
+ case "$1" in
+ wall) cmd_wall ;;
+ settings) cmd_settings ;;
+ layout) cmd_layout ;;
+ apply) apply_all ;;
+ *)
+ printf '%s\n' "Usage: bee {wall|settings|layout|apply}"
+ ;;
+ esac
+ '';
+
}