fix(scripts): port screen rotation to Lua config
Replace hyprctl keyword with hyprctl eval + hl.monitor/hl.device Lua API, and switch monitor/device parsing from fragile grep to hyprctl -j + jq. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>main
parent
f880191764
commit
ef4a0a483d
|
|
@ -6,17 +6,13 @@ direction="$1"
|
||||||
|
|
||||||
if [[ "$direction" != "cw" && "$direction" != "ccw" && "$direction" != "0" && "$direction" != "1" && "$direction" != "2" && "$direction" != "3" ]]; then
|
if [[ "$direction" != "cw" && "$direction" != "ccw" && "$direction" != "0" && "$direction" != "1" && "$direction" != "2" && "$direction" != "3" ]]; then
|
||||||
echo "Usage: $0 [cw|ccw] OR $0 [0|1|2|3]"
|
echo "Usage: $0 [cw|ccw] OR $0 [0|1|2|3]"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get current monitor name
|
monitors_json=$(hyprctl monitors -j)
|
||||||
curmon=$(hyprctl monitors | grep -B12 "focused: yes" | head -n1 | awk '{print $2}')
|
|
||||||
# curmon=$(hyprctl monitors | awk '/focused: yes/{getline; print $2}')
|
|
||||||
|
|
||||||
# Get current transform value
|
curmon=$(echo "$monitors_json" | jq -r '.[] | select(.focused) | .name')
|
||||||
# currot=$(hyprctl monitors | awk '/focused: yes/{for(i=0;i<15;i++){getline;if($1=="transform:"){print $2;break}}}')
|
currot=$(echo "$monitors_json" | jq -r '.[] | select(.focused) | .transform')
|
||||||
currot=$(hyprctl monitors | grep -B1 "focused: yes" | head -n1 | awk '{print $2}')
|
|
||||||
|
|
||||||
# Calculate new rotation
|
# Calculate new rotation
|
||||||
if [[ "$direction" == "cw" ]]; then
|
if [[ "$direction" == "cw" ]]; then
|
||||||
|
|
@ -25,29 +21,27 @@ if [[ "$direction" == "cw" ]]; then
|
||||||
else
|
else
|
||||||
newrot=$((currot + 1))
|
newrot=$((currot + 1))
|
||||||
fi
|
fi
|
||||||
else # ccw
|
elif [[ "$direction" == "ccw" ]]; then
|
||||||
if [[ "$currot" == "0" ]]; then
|
if [[ "$currot" == "0" ]]; then
|
||||||
newrot="3"
|
newrot="3"
|
||||||
else
|
else
|
||||||
newrot=$((currot - 1))
|
newrot=$((currot - 1))
|
||||||
fi
|
fi
|
||||||
fi
|
else
|
||||||
|
newrot="$direction"
|
||||||
if [[ "$direction" == "0" || "$direction" == "1" || "$direction" == "2" || "$direction" == "3" ]]; then
|
|
||||||
newrot="$direction"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Rotating monitor '$curmon' from $currot to $newrot ($direction)"
|
echo "Rotating monitor '$curmon' from $currot to $newrot ($direction)"
|
||||||
|
|
||||||
# Apply new rotation to monitor
|
# Apply new rotation to monitor (hyprctl keyword doesn't work with Lua config)
|
||||||
hyprctl keyword monitor "$curmon,preferred,auto,1,transform,$newrot"
|
hyprctl eval "hl.monitor({output='$curmon', transform=$newrot})"
|
||||||
|
|
||||||
# Detect touchscreen device name
|
# Detect touchscreen device name
|
||||||
touchdev=$(hyprctl devices | awk '/Touch Device/{getline; print $1}')
|
touchdev=$(hyprctl devices -j | jq -r '.touch[0].name // empty')
|
||||||
|
|
||||||
if [[ -n "$touchdev" ]]; then
|
if [[ -n "$touchdev" ]]; then
|
||||||
echo "Applying same rotation to touchscreen: $touchdev"
|
echo "Applying same rotation to touchscreen: $touchdev"
|
||||||
hyprctl keyword "device[$touchdev]:transform" "$newrot"
|
hyprctl eval "hl.device({name='$touchdev', transform=$newrot})"
|
||||||
else
|
else
|
||||||
echo "No touchscreen device detected."
|
echo "No touchscreen device detected."
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue