#!/usr/bin/env bash set -e # Make sure a config file was provided if [ $# -lt 1 ]; then echo "Usage: $0 " 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."