initial commit
This commit is contained in:
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# What is KDE Display Profiles?
|
||||||
|
A simple tool that can save and load display profiles using kscreen-doctor to save your displays resolution, refresh rate,
|
||||||
|
positional layout, scaling, rotation, enabled state and cloning state
|
||||||
|
|
||||||
15
apply.sh
Executable file
15
apply.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Make sure a config file was provided
|
||||||
|
if [ $# -lt 1 ]; then
|
||||||
|
echo "Usage: $0 <config file>"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Attempt to parse the config file
|
||||||
|
INPUT_FILE=$1
|
||||||
|
echo "Parsing config info from $INPUT_FILE..."
|
||||||
|
|
||||||
|
TEST=$(jq '.outputs[]' $INPUT_FILE)
|
||||||
|
|
||||||
|
echo $TEST[0]
|
||||||
97
load-display-profile.sh
Executable file
97
load-display-profile.sh
Executable file
@@ -0,0 +1,97 @@
|
|||||||
|
#!/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 + restore
|
||||||
|
#######################
|
||||||
|
|
||||||
|
# Extract outputs list
|
||||||
|
outputs=$(jq -c '.outputs[]' "$PROFILE")
|
||||||
|
|
||||||
|
# 1. Restore enabled/disabled + basic properties
|
||||||
|
while IFS= read -r out; do
|
||||||
|
id=$(echo "$out" | jq -r '.id')
|
||||||
|
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
|
||||||
|
if [[ "$enabled" == "true" ]]; then
|
||||||
|
kscreen-doctor "output.$id.enable"
|
||||||
|
else
|
||||||
|
kscreen-doctor "output.$id.disable"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Mode (Resolution + refresh)
|
||||||
|
kscreen-doctor "output.$id.mode.$mode"
|
||||||
|
|
||||||
|
# Position
|
||||||
|
kscreen-doctor "output.$id.position.$posx,$posy"
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# 2. 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."
|
||||||
108
load-display-profile2.sh
Executable file
108
load-display-profile2.sh
Executable file
@@ -0,0 +1,108 @@
|
|||||||
|
#!/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."
|
||||||
1297
profiles/desktop-only.json
Normal file
1297
profiles/desktop-only.json
Normal file
File diff suppressed because it is too large
Load Diff
1297
profiles/desktop-tv.json
Normal file
1297
profiles/desktop-tv.json
Normal file
File diff suppressed because it is too large
Load Diff
1297
profiles/desktop.json
Normal file
1297
profiles/desktop.json
Normal file
File diff suppressed because it is too large
Load Diff
1297
profiles/desktop2.json
Normal file
1297
profiles/desktop2.json
Normal file
File diff suppressed because it is too large
Load Diff
1297
profiles/tv.json
Normal file
1297
profiles/tv.json
Normal file
File diff suppressed because it is too large
Load Diff
10
save-display-profile.sh
Executable file
10
save-display-profile.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check for correct usage
|
||||||
|
if [ $# -lt 1 ]; then
|
||||||
|
echo "Usage: $0 <config name>"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
OUTPUT_CONFIG_NAME=$1
|
||||||
|
kscreen-doctor --json > $OUTPUT_CONFIG_NAME
|
||||||
Reference in New Issue
Block a user