making changes to get back lost progress from yesterday

This commit is contained in:
Dawson Matthews
2025-12-04 06:52:15 -07:00
parent 84d746859c
commit 9e990cf58d
2 changed files with 67 additions and 49 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
profiles/*.json

View File

@@ -25,58 +25,73 @@ if ! command -v kscreen-doctor &>/dev/null; then
exit 1 exit 1
fi fi
#######################
# Parse JSON + restore
#######################
# Extract outputs list # Extract outputs list
enabled_outputs=$(jq -c '.outputs[] | select(.enabled=="true")' "$PROFILE")
echo "enabled:"
echo $enabled_outputs
disabled_outputs=$(jq -c '.outputs[] | select(.enabled=="false")' "$PROFILE")
echo "disabled:"
echo $dis
outputs=$(jq -c '.outputs[]' "$PROFILE") outputs=$(jq -c '.outputs[]' "$PROFILE")
# 1. Restore enabled/disabled + basic properties # Restore enabled/disabled starting with the enabled monitors
while IFS= read -r out; do # Starting with a disabled monitor might not work if it was
id=$(echo "$out" | jq -r '.id') # previously the only enabled monitor
enabled=$(echo "$out" | jq -r '.enabled')
posx=$(echo "$out" | jq -r '.pos.x')
posy=$(echo "$out" | jq -r '.pos.y')
rotation=$(echo "$out" | jq -r '.rotation')
scale=$(echo "$out" | jq -r '.scale')
mode=$(echo "$out" | jq -r '.currentModeId')
priority=$(echo "$out" | jq -r '.priority')
# Enable/disable function enable_outputs {
if [[ "$enabled" == "true" ]]; then local outputs=$1
kscreen-doctor "output.$id.enable" while IFS= read -r out; do
else id=$(echo "$out" | jq -r '.id')
kscreen-doctor "output.$id.disable" name=$(echo "$out" | jq -r '.name')
continue enabled=$(echo "$out" | jq -r '.enabled')
fi
# Mode (Resolution + refresh) # Enable/disable
kscreen-doctor "output.$id.mode.$mode" if [[ "$enabled" == "true" ]]; then
kscreen-doctor "output.$name.enable"
else
kscreen-doctor "output.$name.disable"
fi
done <<< "$outputs"
}
# Position function load_profile_to_outputs {
kscreen-doctor "output.$id.position.$posx,$posy" local outputs=$1
while IFS= read -r out; do
id=$(echo "$out" | jq -r '.id')
name=$(echo "$out" | jq -r '.name')
posx=$(echo "$out" | jq -r '.pos.x')
posy=$(echo "$out" | jq -r '.pos.y')
rotation=$(echo "$out" | jq -r '.rotation')
scale=$(echo "$out" | jq -r '.scale')
mode=$(echo "$out" | jq -r '.currentModeId')
priority=$(echo "$out" | jq -r '.priority')
# Scale # Mode (Resolution + refresh)
kscreen-doctor "output.$id.scale.$scale" kscreen-doctor "output.$id.mode.$mode"
# Rotation (map from JSON names to kscreen-doctor options) # Position
case "$rotation" in kscreen-doctor "output.$id.position.$posx,$posy"
"1") kscreen-doctor "output.$id.rotation.normal" ;;
"2") kscreen-doctor "output.$id.rotation.left" ;;
"4") kscreen-doctor "output.$id.rotation.inverted" ;;
"8") kscreen-doctor "output.$id.rotation.right" ;;
esac
# Primary / Not Primary # Scale
echo $priority kscreen-doctor "output.$id.scale.$scale"
if [ $priority -eq 1 ]; then
kscreen-doctor "output.$id.primary"
fi
# Rotation (map from JSON names to kscreen-doctor options)
case "$rotation" in
"1") kscreen-doctor "output.$id.rotation.normal" ;;
"2") kscreen-doctor "output.$id.rotation.left" ;;
"4") kscreen-doctor "output.$id.rotation.inverted" ;;
"8") kscreen-doctor "output.$id.rotation.right" ;;
esac
done <<< "$outputs" # Primary / Not Primary
echo $priority
if [ $priority -eq 1 ]; then
kscreen-doctor "output.$id.primary"
fi
done <<< "$outputs"
`
}
######################### #########################
@@ -85,13 +100,15 @@ done <<< "$outputs"
clone_groups=$(jq -c '.clones[]?' "$PROFILE") clone_groups=$(jq -c '.clones[]?' "$PROFILE")
while IFS= read -r clone; do function restore_clone_groups {
primary=$(echo "$clone" | jq -r '.[0]') while IFS= read -r clone; do
others=$(echo "$clone" | jq -r '.[]' | tail -n +2) primary=$(echo "$clone" | jq -r '.[0]')
others=$(echo "$clone" | jq -r '.[]' | tail -n +2)
for o in $others; do for o in $others; do
kscreen-doctor "output.$o.clone.$primary" kscreen-doctor "output.$o.clone.$primary"
done done
done <<< "$clone_groups" done <<< "$clone_groups"
}
echo "Display configuration restored." echo "Display configuration restored."