#!/bin/sh
# Linux programs at a new display scale while the session runs (David
# 2026-10-05: "it'd be nice if we could do so while logged in without having
# to restart the session"): Settings > Display > Scale (sg-shell's
# scale_write, through sg-settingsctl display-scale) runs this after it
# writes LogPixels. GTK, Qt and the pointer follow at once (the XSETTINGS
# manager, sg-common.sh sg_linux_scale); Xft programs at their next start;
# the work area above the taskbar for Linux programs is the new taskbar's.
#   sg-display-scale PERCENT
SG_LIB="${SG_LIB:-/usr/lib/stained-glass}"
# shellcheck source=lib/sg-common.sh
. "$SG_LIB/sg-common.sh"
case "${1:-}" in ''|*[!0-9]*) echo "usage: sg-display-scale PERCENT" >&2; exit 2 ;; esac
if [ "$1" -lt 100 ] || [ "$1" -gt 500 ]; then echo "a scale is 100 to 500 percent" >&2; exit 2; fi
SG_SCALE=$1
export SG_SCALE
# the scale Linux programs were told before (the XSETTINGS manager's file)
_was=$(sg_linux_scale_now)
sg_linux_scale "$SG_SCALE"
# Qt takes the new scale but leaves its windows their old size in pixels,
# their contents cut off (GTK resizes its own): each Qt window is given the
# size that keeps its contents whole, as Windows resizes a program's window
# for a new scale
[ -n "$_was" ] && [ "$_was" != "$SG_SCALE" ] && sg_qt_windows_rescale "$_was" "$SG_SCALE"
if [ -n "${DISPLAY:-}" ] && [ "${SG_DISPLAY_PATH:-x11}" = x11 ]; then
    _size=$(sg_x_size)
    [ -n "$_size" ] && sg_x11_workarea "${_size%x*}" "${_size#*x}" >/dev/null 2>&1
fi
exit 0
