hyprlock/hyprlock.sh

79 lines
3.1 KiB
Bash
Raw Normal View History

2024-03-14 16:13:28 -04:00
#!/bin/bash
# Use "hyprctl -j monitors" to determine the parameters for the lock and unlock positions.
unlockedMonitorYPositions=(0 0 0)
lockedMonitorYPositions=(1080 1080 1080)
monitors=$(hyprctl -j monitors)
2024-03-14 20:07:16 -04:00
tailMonitorIndex=$(($(echo "$monitors" | jq length)-1))
monitorIndices=$(seq 0 $tailMonitorIndex)
2024-03-14 16:13:28 -04:00
if [ "$1" == "" ]; then
2024-03-14 17:32:10 -04:00
monitorUnlocked=0
2024-03-14 16:13:28 -04:00
for monitorIndex in $monitorIndices; do
monitor=$(echo "$monitors" | jq -c ".[$monitorIndex]")
unlockedMonitorYPosition=${unlockedMonitorYPositions[$monitorIndex]}
2024-03-14 17:32:10 -04:00
if [ $(echo "$monitor" | jq -j ".y") -eq $unlockedMonitorYPosition ]; then continue; fi
2024-03-14 16:13:28 -04:00
hyprctl keyword monitor $(echo "$monitor" | jq -j ".name"),$(echo "$monitor" | jq -j ".width")x$(echo "$monitor" | jq -j ".height")@$(echo "$monitor" | jq -j ".refreshRate"),$(echo "$monitor" | jq -j ".x")x$unlockedMonitorYPosition,$(echo "$monitor" | jq -j ".scale")
2024-03-14 17:32:10 -04:00
monitorUnlocked=1
2024-03-14 16:13:28 -04:00
echo Unlocked monitor $monitorIndex
2024-03-14 17:32:10 -04:00
done
if [ $monitorUnlocked -eq 1 ]; then exit; fi
for monitorIndex in $monitorIndices; do
monitor=$(echo "$monitors" | jq -c ".[$monitorIndex]")
if [ $(echo "$monitor" | jq -j ".focused") == "false" ]; then continue; fi
hyprctl keyword monitor $(echo "$monitor" | jq -j ".name"),$(echo "$monitor" | jq -j ".width")x$(echo "$monitor" | jq -j ".height")@$(echo "$monitor" | jq -j ".refreshRate"),$(echo "$monitor" | jq -j ".x")x${lockedMonitorYPositions[$monitorIndex]},$(echo "$monitor" | jq -j ".scale")
echo Locked monitor $monitorIndex
2024-03-14 16:13:28 -04:00
exit
done
elif [ "$1" == "status" ]; then
for monitorIndex in $monitorIndices; do
2024-03-14 17:32:10 -04:00
if [ $(echo "$monitors" | jq -j ".[$monitorIndex].y") -eq ${unlockedMonitorYPositions[$monitorIndex]} ];
2024-03-14 16:13:28 -04:00
then echo Monitor $monitorIndex: Unlocked
else echo Monitor $monitorIndex: Locked;
fi
done
exit
2024-03-14 18:21:03 -04:00
elif [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then
echo Usage:
echo -e "\thyprlock status"
echo -e "\thyprlock [monitor_id]"
exit
2024-03-14 16:13:28 -04:00
fi
2024-03-14 20:07:16 -04:00
if ! [[ $1 =~ ^[0-9]+$ ]]; then
echo "Error: Invalid parameter value was provided."
echo "[monitor_id] must be an integer."
exit 1
fi
if [ $1 -lt 0 ] || [ $tailMonitorIndex -lt $1 ]; then
echo "Error: The provided [monitor_id] is out of range."
echo "[monitor_id] must be an integer from 0 to $tailMonitorIndex."
exit 2
fi
2024-03-14 16:13:28 -04:00
monitor=$(echo "$monitors" | jq -c ".[$1]")
unlockedMonitorYPosition=${unlockedMonitorYPositions[$1]}
2024-03-14 17:32:10 -04:00
if [ $(echo "$monitor" | jq -j ".y") -eq $unlockedMonitorYPosition ]; then
2024-03-14 16:13:28 -04:00
hyprctl keyword monitor $(echo "$monitor" | jq -j ".name"),$(echo "$monitor" | jq -j ".width")x$(echo "$monitor" | jq -j ".height")@$(echo "$monitor" | jq -j ".refreshRate"),$(echo "$monitor" | jq -j ".x")x${lockedMonitorYPositions[$monitorIndex]},$(echo "$monitor" | jq -j ".scale")
echo Locked monitor $monitorIndex
exit
fi
hyprctl keyword monitor $(echo "$monitor" | jq -j ".name"),$(echo "$monitor" | jq -j ".width")x$(echo "$monitor" | jq -j ".height")@$(echo "$monitor" | jq -j ".refreshRate"),$(echo "$monitor" | jq -j ".x")x$unlockedMonitorYPosition,$(echo "$monitor" | jq -j ".scale")
2024-03-14 17:32:10 -04:00
echo Unlocked monitor $monitorIndex