aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/Wlogout.sh
blob: 7659008ed77edc278b69e65451f16acf6cacfd1e (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
#!/bin/bash
# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
# wlogout (Power, Screen Lock, Suspend, etc)

# Parameters for screen resolutions
declare -A resolutions=(
    [2160]=450
    [1600]=450
    [1440]=450
    [1080]=350
    [720]=175
)

# Check if wlogout is already running, if so, kill it
if pgrep -x "wlogout" > /dev/null; then
    pkill -x "wlogout"
    exit 0
fi

# Detect the current monitor's native resolution and scale
monitor_info=$(hyprctl -j monitors | jq -r '.[] | select(.focused==true)')
# extract some info
resolution=$(echo "$monitor_info" | jq -r '.height')
width=$(echo "$monitor_info" | jq -r '.width')
hypr_scale=$(echo "$monitor_info" | jq -r '.scale')

# If hypr_scale >= 1.25 or resolution can't be detected, run wlogout with -b 3 
if [[ -z "$resolution" || ! "$resolution" =~ ^[0-9]+$ || -z "$hypr_scale" || $(awk "BEGIN {exit !($hypr_scale >= 1.25)}") -eq 1 ]]; then
    echo "Hypr_scale is greater than or equal to 1.25 or resolution could not be detected, running wlogout with -b 3"
    wlogout --protocol layer-shell -b 3 -T 100 -B 100 &
    exit 0
fi

# Determine the appropriate resolution range and calculate T and B values
if ((resolution >= 2160)); then
    res_key=2160
elif ((resolution >= 1600)); then
    res_key=1600
elif ((resolution >= 1440)); then
    res_key=1440
elif ((resolution >= 1080)); then
    res_key=1080
else
    res_key=720
fi

# Calculate T and B values based on selected resolution and scale
T_val=$(awk "BEGIN {printf \"%.0f\", ${resolutions[$res_key]} * $res_key * $hypr_scale / $resolution}")
B_val=$(awk "BEGIN {printf \"%.0f\", ${resolutions[$res_key]} * $res_key * $hypr_scale / $resolution}")

# Output the resolution setting for debugging purposes
echo "Setting parameters for resolution >= $res_key"

# Run wlogout with -b 6 and calculated T/B values
wlogout --protocol layer-shell -b 6 -T $T_val -B $B_val &
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage