head	1.1;
access;
symbols
	netbsd-11-0-RC4:1.1
	netbsd-11-0-RC3:1.1
	netbsd-11-0-RC2:1.1
	netbsd-11-0-RC1:1.1
	perseant-exfatfs-base-20250801:1.1
	netbsd-11:1.1.0.10
	netbsd-11-base:1.1
	netbsd-10-1-RELEASE:1.1
	perseant-exfatfs-base-20240630:1.1
	perseant-exfatfs:1.1.0.8
	perseant-exfatfs-base:1.1
	netbsd-10-0-RELEASE:1.1
	netbsd-10-0-RC6:1.1
	netbsd-10-0-RC5:1.1
	netbsd-10-0-RC4:1.1
	netbsd-10-0-RC3:1.1
	netbsd-10-0-RC2:1.1
	netbsd-10-0-RC1:1.1
	netbsd-10:1.1.0.6
	netbsd-10-base:1.1
	cjep_sun2x-base1:1.1
	cjep_sun2x:1.1.0.4
	cjep_sun2x-base:1.1
	cjep_staticlib_x-base1:1.1
	cjep_staticlib_x:1.1.0.2
	cjep_staticlib_x-base:1.1;
locks; strict;
comment	@# @;


1.1
date	2020.10.12.11.07.24;	author nia;	state Exp;
branches;
next	;
commitid	KkU41ZuoYV9FvBrC;


desc
@@


1.1
log
@Automatic font scaling based on screen size in the default ctwm config.

Based on a shell script which gets the DPI from the X server, and if this
fails, attempts to guess based on resolution. Taking advantage of M4 macros
in the ctwmrc, we can also scale the workspace manager and window list.

The following sizes are supported: 6x12 (<800x600) 8x16 12x24 (4k and higher)
16x32 32x64

Also makes Spleen the default font in ctwm
@
text
@#!/bin/sh
#	$NetBSD$
#
# Copyright (c) 2020 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Nia Alarie.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

width=$(xwininfo -root | awk '/Width:/{ print $2; }')
height=$(xwininfo -root | awk '/Height:/{ print $2; }')
dpi=$(xdpyinfo | awk '/resolution:/{ split($2, res, "x"); print res[1]; }' | head -1)

# Attempt to select a reasonably sized font for the reported DPI.
#
# If the DPI is greater than 100, chances are it's specified and
# not just a default.
if [ "$dpi" -gt 100 ]; then
	for size in 16 24 32 64; do
		mm=$(printf '%d / (%d / 25)\n' "$size" "$dpi" | bc)
		if [ "$mm" -ge 3 ]; then
			printf '%d\n' "$size"
			exit 0
		fi
	done
fi

# In case the reported DPI is lower than the actual DPI, allow at least 2x2
# 80x24 xterms to be displayed in a grid.
if [ "$width" -gt 6088 -a "$height" -gt 3656 ]; then
	printf '64\n'
elif [ "$width" -gt 3048 -a "$height" -gt 1832 ]; then
	printf '32\n'
elif [ "$width" -gt 2248 -a "$height" -gt 1400 ]; then
	printf '24\n'
elif [ "$width" -gt 640 -a "$height" -gt 480 ]; then
	printf '16\n'
else
	# One 80x24 xterm with 16 pixel fonts does not fit into 640x480...
	printf '12\n'
fi
@
