aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/MonitorProfiles.sh
blob: 09467e76d9969582f71901adb23033c7e537a5e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# ==================================================
#  KoolDots (2026)
#  Project URL: https://github.com/LinuxBeginnings
#  License: GNU GPLv3
#  SPDX-License-Identifier: GPL-3.0-or-later
# ==================================================
# For applying Pre-configured Monitor Profiles

# Check if rofi is already running
if pidof rofi > /dev/null; then
  pkill rofi
fi

# Detect active Hyprland config mode (Lua entrypoint vs legacy .conf includes)
config_home="${XDG_CONFIG_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}}"
hypr_dir="$config_home/hypr"
lua_entry="$hypr_dir/hyprland.lua"
legacy_lua_entry="$config_home/hyprland.lua"
if [[ -n "$HYPR_CONFIG_MODE" ]]; then
    case "${HYPR_CONFIG_MODE,,}" in
        lua) hypr_config_mode="lua" ;;
        conf|hyprlang) hypr_config_mode="conf" ;;
        auto) hypr_config_mode="" ;;
        *) hypr_config_mode="" ;;
    esac
fi

if [[ -z "$hypr_config_mode" ]]; then
    if [[ -f "$lua_entry" || -f "$legacy_lua_entry" ]]; then
        hypr_config_mode="lua"
    else
        hypr_config_mode="conf"
    fi
fi

# Variables
iDIR="${XDG_CONFIG_HOME:-$HOME/.config}/swaync/images"
SCRIPTSDIR="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/scripts"
monitor_dir="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/Monitor_Profiles"
target_conf="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/monitors.conf"
target_lua_user="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/UserConfigs/monitors.lua"
target_lua_legacy="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/lua/monitors.lua"
rofi_theme="${XDG_CONFIG_HOME:-$HOME/.config}/rofi/config-Monitors.rasi"

if [[ "$hypr_config_mode" == "lua" ]]; then
    profile_ext="lua"
    target="$target_lua_user"
    msg="❗NOTE:❗ This will overwrite ${XDG_CONFIG_HOME:-$HOME/.config}/hypr/UserConfigs/monitors.lua"
else
    profile_ext="conf"
    target="$target_conf"
    msg="❗NOTE:❗ This will overwrite ${XDG_CONFIG_HOME:-$HOME/.config}/hypr/monitors.conf"
fi

# Define the list of files to ignore
ignore_files=(
  "README"
)

# list of Monitor Profiles, sorted alphabetically with numbers first
mon_profiles_list=$(find -L "$monitor_dir" -maxdepth 1 -type f -name "*.${profile_ext}" | sed 's/.*\///' | sed "s/\.${profile_ext}$//" | sort -V)

# Remove ignored files from the list
for ignored_file in "${ignore_files[@]}"; do
    mon_profiles_list=$(echo "$mon_profiles_list" | grep -v -E "^$ignored_file$")
done
if [[ -z "$mon_profiles_list" ]]; then
    notify-send -u low -i "$iDIR/ja.png" "Monitor Profiles" "No .${profile_ext} profiles found in $monitor_dir"
    exit 1
fi

# Rofi Menu
chosen_file=$(echo "$mon_profiles_list" | rofi -i -dmenu -config "$rofi_theme" -mesg "$msg")

if [[ -n "$chosen_file" ]]; then
    full_path="$monitor_dir/$chosen_file.$profile_ext"
    mkdir -p "$(dirname "$target")"
    cp "$full_path" "$target"
    if [[ "$hypr_config_mode" == "lua" && -f "$target_lua_legacy" ]]; then
        cp "$full_path" "$target_lua_legacy"
    fi
    
    notify-send -u low -i "$iDIR/ja.png" "$chosen_file" "Monitor Profile Loaded"
fi

sleep 1
"${SCRIPTSDIR}/RefreshNoWaybar.sh" &
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage