irongit
hygoland/scripts/Wlogout.sh
57 lines2.5 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# wlogout (Power, Screen Lock, Suspend, etc)
4
5# Set variables for parameters. First numbers corresponts to Monitor Resolution
6# i.e 2160 means 2160p
7A_2160=600
8B_2160=600
9A_1600=400
10B_1600=400
11A_1440=400
12B_1440=400
13A_1080=200
14B_1080=200
15A_720=50
16B_720=50
17
18# Check if wlogout is already running
19if pgrep -x "wlogout" > /dev/null; then
20 pkill -x "wlogout"
21 exit 0
22fi
23
24# Detect monitor resolution and scaling factor
25resolution=$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .height / .scale' | awk -F'.' '{print $1}')
26hypr_scale=$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .scale')
27
28# Set parameters based on screen resolution and scaling factor
29if ((resolution >= 2160)); then
30 T_val=$(awk "BEGIN {printf \"%.0f\", $A_2160 * 2160 * $hypr_scale / $resolution}")
31 B_val=$(awk "BEGIN {printf \"%.0f\", $B_2160 * 2160 * $hypr_scale / $resolution}")
32 echo "Setting parameters for resolution >= 4k"
33 wlogout --protocol layer-shell -b 6 -T $T_val -B $B_val &
34elif ((resolution >= 1600 && resolution < 2160)); then
35 T_val=$(awk "BEGIN {printf \"%.0f\", $A_1600 * 1600 * $hypr_scale / $resolution}")
36 B_val=$(awk "BEGIN {printf \"%.0f\", $B_1600 * 1600 * $hypr_scale / $resolution}")
37 echo "Setting parameters for resolution >= 2.5k and < 4k"
38 wlogout --protocol layer-shell -b 6 -T $T_val -B $B_val &
39elif ((resolution >= 1440 && resolution < 1600)); then
40 T_val=$(awk "BEGIN {printf \"%.0f\", $A_1440 * 1440 * $hypr_scale / $resolution}")
41 B_val=$(awk "BEGIN {printf \"%.0f\", $B_1440 * 1440 * $hypr_scale / $resolution}")
42 echo "Setting parameters for resolution >= 2k and < 2.5k"
43 wlogout --protocol layer-shell -b 6 -T $T_val -B $B_val &
44elif ((resolution >= 1080 && resolution < 1440)); then
45 T_val=$(awk "BEGIN {printf \"%.0f\", $A_1080 * 1080 * $hypr_scale / $resolution}")
46 B_val=$(awk "BEGIN {printf \"%.0f\", $B_1080 * 1080 * $hypr_scale / $resolution}")
47 echo "Setting parameters for resolution >= 1080p and < 2k"
48 wlogout --protocol layer-shell -b 6 -T $T_val -B $B_val &
49elif ((resolution >= 720 && resolution < 1080)); then
50 T_val=$(awk "BEGIN {printf \"%.0f\", $A_720 * 720 * $hypr_scale / $resolution}")
51 B_val=$(awk "BEGIN {printf \"%.0f\", $B_720 * 720 * $hypr_scale / $resolution}")
52 echo "Setting parameters for resolution >= 720p and < 1080p"
53 wlogout --protocol layer-shell -b 3 -T $T_val -B $B_val &
54else
55 echo "Setting default parameters"
56 wlogout &
57fi