A session creates Desktop, Documents, Downloads, Pictures, Music and Network (programs/dtlogin/config/0075.homefolders). The test's new home had none, so a program that writes "to the Desktop" fell back to the home directory and the screenshot check counted 0 before and 0 after while "Screenshot 2026-11-15 at 08.49.33.png" lay in $HOME (t0222, measured). With the folders, the same run says: 0 before, 1 after, "Screenshot 2026-11-15 at 08.51.30.png" (build/logs/mcde-keytest-2026-11-15f.txt).
201 lines
6.6 KiB
Bash
Executable File
201 lines
6.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# mcde-keytest.sh -- try MCDE's keyboard shortcuts on a private X display
|
|
#
|
|
# usage: tools/mcde-keytest.sh [OUT.txt]
|
|
#
|
|
# docs/reference/shortcuts.txt lists the keys; this sends them (tools/mcde-xkey.sh:
|
|
# plain keycodes, `xdotool key' adds Alt to F-keys on Xvfb) to
|
|
# a session of its own (Xvfb, ttsession, dtwm, dtbar, dtlaunch, from the
|
|
# development installation `make mcde-host MCDE_DIRS=install' made, build/
|
|
# mcde-root) and writes one line for each: key, what is expected, what the
|
|
# screen showed. A new home each run: the real ~/.dt is not touched.
|
|
#
|
|
# Xvfb has no Eject key and loses its keymap when the last client leaves
|
|
# (ext/src/mcde/AGENTS.md, Hazards): a dtwm and a bar stay up during the run.
|
|
#
|
|
# What is seen is the list of named windows that came or went (pop-ups have no
|
|
# name), and a screenshot after every key in build/mcde-keytest-shots, to look at.
|
|
|
|
set -u
|
|
|
|
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
|
R=$TOP/build/mcde-root
|
|
OUT=${1:-$TOP/build/mcde-keytest.txt}
|
|
[ -x "$R/dt/bin/dtwm" ] || { echo "no $R: make mcde-host MCDE_DIRS=install" >&2; exit 1; }
|
|
|
|
DISP=:92
|
|
SHOTS=$TOP/build/mcde-keytest-shots
|
|
rm -rf "$SHOTS"
|
|
mkdir -p "$SHOTS"
|
|
n=0
|
|
H=$TOP/build/mcde-keytest-home
|
|
rm -rf "$H"
|
|
mkdir -p "$H/.dt"
|
|
# A session's home has Desktop, Documents, Downloads, Pictures, Music and
|
|
# Network (programs/dtlogin/config/0075.homefolders): without them a program
|
|
# that writes "to the Desktop" falls back to the home directory and a test
|
|
# that looks on the Desktop sees nothing.
|
|
for d in Desktop Documents Downloads Pictures Music Network; do
|
|
mkdir -p "$H/$d"
|
|
done
|
|
|
|
Xvfb $DISP -screen 0 1280x800x24 -nolisten tcp > /dev/null 2>&1 &
|
|
xpid=$!
|
|
sleep 2
|
|
|
|
PATH=$R/dt/bin:$PATH
|
|
LD_LIBRARY_PATH=$R/dt/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
|
XFILESEARCHPATH=$R/dt/app-defaults/%L/%N:$R/dt/app-defaults/C/%N
|
|
DTDATABASESEARCHPATH=$R/dt/appconfig/types/%L,$R/dt/appconfig/types/C
|
|
export PATH LD_LIBRARY_PATH XFILESEARCHPATH DTDATABASESEARCHPATH
|
|
|
|
Session() {
|
|
env -i DISPLAY=$DISP HOME=$H PATH=$PATH LANG=C.UTF-8 \
|
|
LD_LIBRARY_PATH=$LD_LIBRARY_PATH XFILESEARCHPATH=$XFILESEARCHPATH \
|
|
DTDATABASESEARCHPATH=$DTDATABASESEARCHPATH "$@"
|
|
}
|
|
X() { DISPLAY=$DISP "$@"; }
|
|
|
|
LOG=$H/session.log
|
|
Session ttsession -s > $LOG 2>&1 &
|
|
tpid=$!
|
|
sleep 1
|
|
Session dtwm >> $LOG 2>&1 &
|
|
wpid=$!
|
|
sleep 2
|
|
Session dtbar >> $LOG 2>&1 &
|
|
bpid=$!
|
|
Session dtlaunch >> $LOG 2>&1 &
|
|
lpid=$!
|
|
sleep 2
|
|
|
|
pids="$lpid $bpid $wpid $tpid"
|
|
# every window of the display: id and name, mapped ones marked
|
|
snap() {
|
|
X xwininfo -root -tree 2>/dev/null |
|
|
sed -n 's/^ *\(0x[0-9a-f]*\) \("[^"]*"\).*[0-9]*x[0-9]*+[-0-9]*+[-0-9]*.*$/\1 \2/p' |
|
|
sort -u
|
|
}
|
|
mapped() {
|
|
X xdotool search --onlyvisible --name '.' 2>/dev/null | while read -r w; do
|
|
printf '%s %s\n' "$w" "$(X xdotool getwindowname "$w" 2>/dev/null)"
|
|
done | sort -u
|
|
}
|
|
|
|
: > "$OUT"
|
|
printf '%s\n' "MCDE keyboard shortcuts -- test of $(date +%Y-%m-%d), tools/mcde-keytest.sh" >> "$OUT"
|
|
printf '%s\n' "Xvfb $DISP, a private home, dtwm + dtbar + dtlaunch; tools/mcde-xkey.sh sends the keys." >> "$OUT"
|
|
printf '\n%-24s %-34s %s\n' KEY EXPECTED SEEN >> "$OUT"
|
|
|
|
# send_keys super+shift+q: the keys of the xdotool spelling, pressed in this order
|
|
send_keys() {
|
|
args=$(printf '%s' "$1" | tr '+' '\n' | sed -e 's/^super$/Super_L/' \
|
|
-e 's/^ctrl$/Control_L/' -e 's/^alt$/Alt_L/' -e 's/^shift$/Shift_L/' |
|
|
tr '\n' ' ')
|
|
# shellcheck disable=SC2086
|
|
X sh "$TOP/tools/mcde-xkey.sh" $args
|
|
}
|
|
|
|
# try KEYS EXPECTED [SETTLE]
|
|
# sends the keys; reports the visible windows that came or went, and whether
|
|
# the picture of the screen changed
|
|
try() {
|
|
keys=$1 expect=$2 settle=${3:-1}
|
|
mapped > $H/before
|
|
X import -window root $H/before.png
|
|
send_keys "$keys"
|
|
sleep "$settle"
|
|
mapped > $H/after
|
|
n=$((n + 1))
|
|
X import -window root "$SHOTS/$(printf %02d $n)-$(echo "$keys" | tr -c "A-Za-z0-9\n" _).png"
|
|
new=$(comm -13 $H/before $H/after | sed 's/^[^ ]* //' | tr '\n' ',' | sed 's/,$//')
|
|
gone=$(comm -23 $H/before $H/after | sed 's/^[^ ]* //' | tr '\n' ',' | sed 's/,$//')
|
|
seen=
|
|
[ -z "$new" ] || seen="new: $new"
|
|
[ -z "$gone" ] || seen="$seen${seen:+; }gone: $gone"
|
|
[ -n "$seen" ] || seen="no window came or went"
|
|
X import -window root $H/after.png
|
|
cmp -s $H/before.png $H/after.png || seen="$seen; screen changed"
|
|
printf '%-24s %-34s %s\n' "$keys" "$expect" "$seen" >> "$OUT"
|
|
}
|
|
# closewin: leave the display as it was between tests
|
|
cleanup_windows() {
|
|
send_keys Escape; sleep 1
|
|
}
|
|
|
|
try super+space "dtlaunch window opens"
|
|
cleanup_windows
|
|
try Escape "(the launcher is closed again)"
|
|
|
|
# two terminals to switch between
|
|
Session dtterm -title Term1 >> $LOG 2>&1 &
|
|
t1=$!
|
|
sleep 2
|
|
Session dtterm -title Term2 >> $LOG 2>&1 &
|
|
t2=$!
|
|
sleep 2
|
|
pids="$pids $t1 $t2"
|
|
|
|
# the pointer in a Terminal: focus follows it, the keys of dtterm need it
|
|
focus_term() {
|
|
w=$(X xdotool search --onlyvisible --name Terminal | head -1)
|
|
[ -z "$w" ] || X xdotool mousemove --window "$w" 60 60 click 1
|
|
sleep 1
|
|
}
|
|
|
|
try "super+grave" "the program's next window (focus)"
|
|
focus_term
|
|
try "super+n" "a new terminal window (dtterm focused)"
|
|
focus_term
|
|
try "super+comma" "the program's preferences"
|
|
cleanup_windows
|
|
focus_term
|
|
try "super+w" "close the window"
|
|
focus_term
|
|
try "super+h" "hide the program (windows leave)"
|
|
try "super+m" "minimize the window"
|
|
try "super+alt+d" "front panel hides or shows"
|
|
try "super+alt+d" "front panel back"
|
|
try "ctrl+Right" "next workspace"
|
|
try "ctrl+Left" "previous workspace"
|
|
try "super+Tab" "program switcher bar"
|
|
cleanup_windows
|
|
try "super+shift+q" "log-out question"
|
|
cleanup_windows
|
|
try "super+alt+Escape" "Force Quit dialog"
|
|
cleanup_windows
|
|
try "ctrl+F2" "the bar's menu bar gets the focus"
|
|
cleanup_windows
|
|
try "F9" "all windows as tiles"
|
|
cleanup_windows
|
|
try "F11" "windows off the screen"
|
|
try "F11" "windows back"
|
|
|
|
# the rest: focus a Terminal first (the pointer is in it)
|
|
focus_term
|
|
try "ctrl+Up" "all windows as tiles"
|
|
cleanup_windows
|
|
focus_term
|
|
try "super+ctrl+Left" "the window becomes the left half"
|
|
try "super+ctrl+BackSpace" "the window gets its place back"
|
|
try "super+shift+Tab" "the previous program (switcher)"
|
|
cleanup_windows
|
|
n_before=$(ls "$H/Desktop" 2> /dev/null | wc -l)
|
|
try "super+shift+3" "a screenshot file on the Desktop" 3
|
|
printf '%-24s %-34s %s\n' "(files on Desktop)" "one more than before" \
|
|
"$n_before before, $(ls "$H/Desktop" 2> /dev/null | wc -l) after: $(ls "$H/Desktop" 2> /dev/null | tr '\n' ' ')" >> "$OUT"
|
|
focus_term
|
|
try "super+alt+h" "hide the other programs"
|
|
try "super+alt+m" "minimize all windows of the program"
|
|
try "super+alt+w" "close all windows of the program"
|
|
|
|
printf '\n%s\n' "log of the session: $LOG" >> "$OUT"
|
|
|
|
for p in $pids; do kill "$p" 2> /dev/null; done
|
|
sleep 1
|
|
kill "$xpid" 2> /dev/null
|
|
wait 2> /dev/null
|
|
cat "$OUT"
|