Compare commits
3 Commits
84d746859c
...
changing-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39d46fa9e1 | ||
|
|
4bbe14f8f2 | ||
|
|
9e990cf58d |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
profiles/*.json
|
||||||
@@ -25,59 +25,77 @@ 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 $disabled_outputs
|
||||||
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
|
enable_outputs $enabled_outputs
|
||||||
kscreen-doctor "output.$id.position.$posx,$posy"
|
enable_outputs $disabled_outputs
|
||||||
|
|
||||||
# Scale
|
function load_profile_to_outputs {
|
||||||
kscreen-doctor "output.$id.scale.$scale"
|
local outputs=$1
|
||||||
|
while IFS= read -r out; do
|
||||||
# Rotation (map from JSON names to kscreen-doctor options)
|
id=$(echo "$out" | jq -r '.id')
|
||||||
case "$rotation" in
|
name=$(echo "$out" | jq -r '.name')
|
||||||
"1") kscreen-doctor "output.$id.rotation.normal" ;;
|
posx=$(echo "$out" | jq -r '.pos.x')
|
||||||
"2") kscreen-doctor "output.$id.rotation.left" ;;
|
posy=$(echo "$out" | jq -r '.pos.y')
|
||||||
"4") kscreen-doctor "output.$id.rotation.inverted" ;;
|
rotation=$(echo "$out" | jq -r '.rotation')
|
||||||
"8") kscreen-doctor "output.$id.rotation.right" ;;
|
scale=$(echo "$out" | jq -r '.scale')
|
||||||
esac
|
mode=$(echo "$out" | jq -r '.currentModeId')
|
||||||
|
priority=$(echo "$out" | jq -r '.priority')
|
||||||
|
|
||||||
# Primary / Not Primary
|
# Mode (Resolution + refresh)
|
||||||
echo $priority
|
kscreen-doctor "output.$id.mode.$mode"
|
||||||
if [ $priority -eq 1 ]; then
|
|
||||||
kscreen-doctor "output.$id.primary"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Position
|
||||||
|
kscreen-doctor "output.$id.position.$posx,$posy"
|
||||||
|
|
||||||
done <<< "$outputs"
|
# Scale
|
||||||
|
kscreen-doctor "output.$id.scale.$scale"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Primary / Not Primary
|
||||||
|
echo $priority
|
||||||
|
if [ $priority -eq 1 ]; then
|
||||||
|
kscreen-doctor "output.$id.primary"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done <<< "$outputs"
|
||||||
|
}
|
||||||
|
|
||||||
|
load_profile_to_outputs $outputs
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# 2. Restore clone groups
|
# 2. Restore clone groups
|
||||||
@@ -85,13 +103,18 @@ 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]')
|
local clone_groups=$1
|
||||||
others=$(echo "$clone" | jq -r '.[]' | tail -n +2)
|
while IFS= read -r clone; do
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
restore_clone_groups $clone_groups
|
||||||
|
|
||||||
echo "Display configuration restored."
|
echo "Display configuration restored."
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Make sure a config file was provided
|
|
||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo "Usage: $0 <config file>"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
PROFILE=$1
|
|
||||||
|
|
||||||
if [[ ! -f "$PROFILE" ]]; then
|
|
||||||
echo "Profile file not found: $PROFILE" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v jq &>/dev/null; then
|
|
||||||
echo "jq not installed!" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v kscreen-doctor &>/dev/null; then
|
|
||||||
echo "kscreen-doctor not found!" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
#######################
|
|
||||||
# Parse JSON + ordering
|
|
||||||
#######################
|
|
||||||
|
|
||||||
# Extract output entries based on positions
|
|
||||||
origin_out=$(jq -c '.outputs[] | select(.pos.x == 0 and .pos.y == 0 and .enabled == true)' "$PROFILE")
|
|
||||||
non_origin_outs=$(jq -c '.outputs[] | select(.pos.x != 0 or .pos.y != 0 or .enable == false)' "$PROFILE")
|
|
||||||
|
|
||||||
#######################
|
|
||||||
# Function: Apply output
|
|
||||||
#######################
|
|
||||||
apply_output() {
|
|
||||||
local out="$1"
|
|
||||||
|
|
||||||
id=$(echo "$out" | jq -r '.id')
|
|
||||||
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')
|
|
||||||
enabled=$(echo "$out" | jq -r '.enabled')
|
|
||||||
|
|
||||||
# Enable/disable
|
|
||||||
if [[ "$enabled" == "true" ]]; then
|
|
||||||
kscreen-doctor "output.$id.enable"
|
|
||||||
else
|
|
||||||
kscreen-doctor "output.$id.disable"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Mode
|
|
||||||
kscreen-doctor "output.$id.mode.$mode"
|
|
||||||
|
|
||||||
# Position
|
|
||||||
kscreen-doctor "output.$id.position.$posx,$posy"
|
|
||||||
|
|
||||||
# Scale
|
|
||||||
kscreen-doctor "output.$id.scale.$scale"
|
|
||||||
|
|
||||||
# Rotation
|
|
||||||
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
|
|
||||||
|
|
||||||
# Primary
|
|
||||||
if [ "$priority" -eq 1 ]; then
|
|
||||||
kscreen-doctor "output.$id.primary"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ -n "$origin_out" ]]; then
|
|
||||||
apply_output "$origin_out"
|
|
||||||
fi
|
|
||||||
|
|
||||||
while IFS= read -r out; do
|
|
||||||
apply_output "$out"
|
|
||||||
done <<< "$non_origin_outs"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#########################
|
|
||||||
# 3. Restore clone groups
|
|
||||||
#########################
|
|
||||||
|
|
||||||
clone_groups=$(jq -c '.clones[]?' "$PROFILE")
|
|
||||||
|
|
||||||
while IFS= read -r clone; do
|
|
||||||
primary=$(echo "$clone" | jq -r '.[0]')
|
|
||||||
others=$(echo "$clone" | jq -r '.[]' | tail -n +2)
|
|
||||||
|
|
||||||
for o in $others; do
|
|
||||||
kscreen-doctor "output.$o.clone.$primary"
|
|
||||||
done
|
|
||||||
done <<< "$clone_groups"
|
|
||||||
|
|
||||||
echo "Display configuration restored."
|
|
||||||
Reference in New Issue
Block a user