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
This commit is contained in:
nia 2020-10-12 11:07:23 +00:00
parent ce6d7dcd35
commit ad94c89804
5 changed files with 169 additions and 19 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.157 2020/09/23 15:30:36 nia Exp $
# $NetBSD: mi,v 1.158 2020/10/12 11:07:23 nia Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -1263,6 +1263,7 @@
./usr/X11R7/libexec base-x11-root xorg
./usr/X11R7/libexec/chooser xbase-chooser-bin xorg
./usr/X11R7/libexec/ctwm_app_menu xbase-ctwm-bin xorg
./usr/X11R7/libexec/ctwm_font_size xbase-ctwm-bin xorg
./usr/X11R7/man base-x11-root xorg
./usr/X11R7/man/cat1 base-x11-root xorg
./usr/X11R7/man/cat1/appres.0 xbase-appres-catman .cat,xorg

View File

@ -1,5 +1,5 @@
#
# $NetBSD: system.ctwmrc,v 1.7 2020/10/11 10:12:53 nia Exp $
# $NetBSD: system.ctwmrc,v 1.8 2020/10/12 11:07:24 nia Exp $
#
# ctwmrc by nia
#
@ -26,19 +26,79 @@ UseThreeDBorders
#UseThreeDMenus
UseThreeDTitles
ThreeDBorderWidth 3
esyscmd(`printf "define(fontsize, %d)\n" "$(/usr/X11R7/libexec/ctwm_font_size)"')
# TODO: we can use syscmd() in combination with xdpyinfo to detect
# HiDPI screens and set appropiate fonts.
#
# need some good scaled bitmap fonts imported - terminus or spleen
# would be good candidates
MenuFont "-misc-fixed-medium-r-*-*-14-*-*-*-*-*-*-*"
TitleFont "-misc-fixed-bold-r-*-*-18-*-*-*-*-*-*-*"
IconManagerFont "-misc-fixed-medium-r-*-*-14-*-*-*-*-*-*-*"
IconFont "-misc-fixed-bold-r-*-*-18-*-*-*-*-*-*-*"
ResizeFont "-misc-fixed-medium-r-*-*-18-*-*-*-*-*-*-*"
WorkSpaceFont "-misc-fixed-medium-r-*-*-14-*-*-*-*-*-*-*"
ifelse(fontsize, `64', `
TitleFont "-*-spleen-*-*-*-*-64-*-*-*-*-*-*-*"
MenuFont "-*-spleen-*-*-*-*-64-*-*-*-*-*-*-*"
IconManagerFont "-*-spleen-*-*-*-*-64-*-*-*-*-*-*-*"
IconFont "-*-spleen-*-*-*-*-64-*-*-*-*-*-*-*"
ResizeFont "-*-spleen-*-*-*-*-64-*-*-*-*-*-*-*"
WorkSpaceFont "-*-spleen-*-*-*-*-32-*-*-*-*-*-*-*"
WorkSpaceManagerGeometry "240x960-4-4" 1
IconManagerGeometry "800x-1-1+0" 1
ThreeDBorderWidth 12
BorderWidth 12
define(setsizes, `yes')
')
ifelse(fontsize, `32', `
TitleFont "-*-spleen-*-*-*-*-32-*-*-*-*-*-*-*"
MenuFont "-*-spleen-*-*-*-*-32-*-*-*-*-*-*-*"
IconManagerFont "-*-spleen-*-*-*-*-32-*-*-*-*-*-*-*"
IconFont "-*-spleen-*-*-*-*-32-*-*-*-*-*-*-*"
ResizeFont "-*-spleen-*-*-*-*-32-*-*-*-*-*-*-*"
WorkSpaceFont "-*-spleen-*-*-*-*-24-*-*-*-*-*-*-*"
WorkSpaceManagerGeometry "120x480-4-4" 1
IconManagerGeometry "400x-1-1+0" 1
ThreeDBorderWidth 6
BorderWidth 6
define(setsizes, `yes')
')
ifelse(fontsize, `24', `
TitleFont "-*-spleen-*-*-*-*-24-*-*-*-*-*-*-*"
MenuFont "-*-spleen-*-*-*-*-24-*-*-*-*-*-*-*"
IconManagerFont "-*-spleen-*-*-*-*-24-*-*-*-*-*-*-*"
IconFont "-*-spleen-*-*-*-*-24-*-*-*-*-*-*-*"
ResizeFont "-*-spleen-*-*-*-*-24-*-*-*-*-*-*-*"
WorkSpaceFont "-*-spleen-*-*-*-*-16-*-*-*-*-*-*-*"
WorkSpaceManagerGeometry "90x360-4-4" 1
IconManagerGeometry "300x-1-1+0" 1
ThreeDBorderWidth 4
BorderWidth 4
define(setsizes, `yes')
')
ifelse(fontsize, `12', `
TitleFont "-*-spleen-*-*-*-*-12-*-*-*-*-*-*-*"
MenuFont "-*-spleen-*-*-*-*-12-*-*-*-*-*-*-*"
IconManagerFont "-*-spleen-*-*-*-*-12-*-*-*-*-*-*-*"
IconFont "-*-spleen-*-*-*-*-12-*-*-*-*-*-*-*"
ResizeFont "-*-spleen-*-*-*-*-12-*-*-*-*-*-*-*"
WorkSpaceFont "-*-spleen-*-*-*-*-8-*-*-*-*-*-*-*"
WorkSpaceManagerGeometry "45x180-4-4" 1
IconManagerGeometry "150x-1-1+0" 1
ThreeDBorderWidth 1
BorderWidth 1
define(setsizes, `yes')
')
# Fallback in case a valid font size was not returned.
# "Default case" is 16px.
ifdef(`setsizes', `', `
TitleFont "-*-spleen-*-*-*-*-16-*-*-*-*-*-*-*"
MenuFont "-*-spleen-*-*-*-*-16-*-*-*-*-*-*-*"
IconManagerFont "-*-spleen-*-*-*-*-16-*-*-*-*-*-*-*"
IconFont "-*-spleen-*-*-*-*-16-*-*-*-*-*-*-*"
ResizeFont "-*-spleen-*-*-*-*-16-*-*-*-*-*-*-*"
WorkSpaceFont "-*-spleen-*-*-*-*-12-*-*-*-*-*-*-*"
WorkSpaceManagerGeometry "60x240-4-4" 1
IconManagerGeometry "200x-1-1+0" 1
ThreeDBorderWidth 3
BorderWidth 3
')
RestartPreviousState
@ -110,14 +170,12 @@ LeftTitleButton ":xpm:dot" = f.menu "titleops"
RightTitleButton ":xpm:resize" = f.resize
RightTitleButton ":xpm:cross" = f.delete
BorderWidth 4
BorderShadowDepth 2
BorderResizeCursors
MaxIconTitleWidth 120
NoIconManagerFocus
IconManagerShadowDepth 1
IconManagerGeometry "200x-1-1+0" 1
IconifyByUnmapping
ReallyMoveInWorkspaceManager
@ -129,7 +187,6 @@ ReverseCurrentWorkspace
StartInMapState
WMgrHorizButtonIndent 0
WMgrVertButtonIndent 0
WorkSpaceManagerGeometry "60x240-4-4" 1
WorkSpaces
{

View File

@ -1,8 +1,9 @@
# $NetBSD: Makefile,v 1.1 2020/09/23 15:30:36 nia Exp $
# $NetBSD: Makefile,v 1.2 2020/10/12 11:07:24 nia Exp $
.include <bsd.own.mk>
SCRIPTS= ctwm_app_menu
SCRIPTS= ctwm_font_size
SCRIPTSDIR= ${X11ROOTDIR}/libexec

View File

@ -1,5 +1,33 @@
#!/bin/sh
# $NetBSD: ctwm_app_menu,v 1.1 2020/09/23 15:30:36 nia Exp $
# $NetBSD: ctwm_app_menu,v 1.2 2020/10/12 11:07:24 nia Exp $
#
# 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.
#
OFS=$IFS
IFS='
'

View File

@ -0,0 +1,63 @@
#!/bin/sh
# $NetBSD: ctwm_font_size,v 1.1 2020/10/12 11:07:24 nia Exp $
#
# 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