Commit graph

9 commits

Author SHA1 Message Date
step
9edb8d86fb
Add xresources-xdefaults patch (#195)
* Add xresources-xdefaults patch

This patch adds the ability to configure st via Xdefaults, in addition
to Xresources, like the rxvt-unicode terminal. At startup, st will read
and apply the system and user's local Xdefault files, the XServer's
Xresources, and the screen and per-host Xdefaults. This patch depends
on XRESOURCES_PATCH and is compatible with XRESOURCES_RELOAD_PATCH.

I used the following script to stress test this patch. You can also use
the script to demo what the patch does. To be simple, it only tests
the user's .Xdefaults and .Xresources files, without throwing in the
system and per-host files. The script cycles st's background through
red, green and blue indefinitely.

BACKUP YOUR ~/.Xdefaults and ~/.Xresources FILES BEFORE TESTING.

```sh

unset pid
if [ -n "$1" ]; then
	pid=$1
elif pid=$(pgrep -f ^valgrind) && [ -n "$pid" ]; then
	:
else
	pid=$(pgrep -n ^st$)
fi
if [ -z "$pid" -o "x$pid" = "x-h" -o "x$pid" = "x--help" ]; then
	echo "usage: $0 [pid]
	If pid is omitted valgrind's is used falling back to st's.
	---------------------------------------------------------------
	BACKUP YOUR ~/.Xdefaults and ~/.Xresources FILES BEFORE TESTING
	---------------------------------------------------------------"
	exit 0
fi
printf "Attaching pid=%d\n\t%s\n" "$pid" "$(ps -h -ocmd "$pid")" >&2

seconds=0.25 red='#800000' green='#008000' blue='#000080'
echo "St.background: $red" >> $HOME/.Xdefaults
while true; do
	sed -i "\$s/$red/$green/" $HOME/.Xdefaults
	kill -USR1 $pid
	sleep $seconds
	sed -i "\$s/$green/$red/" $HOME/.Xdefaults
	kill -USR1 $pid
	sleep $seconds

	echo "St.background: $blue" >> $HOME/.Xresources
	xrdb -load $HOME/.Xresources
	kill -USR1 $pid
	sleep $seconds
	sed -i '$d' $HOME/.Xresources
	xrdb -load $HOME/.Xresources
	kill -USR1 $pid
	sleep $seconds
done
```

* Minor refactoring and freeing / destroying the Xrm database with XrmDestroyDatabase

---------

Co-authored-by: Bakkeby <bakkeby@gmail.com>
2026-01-30 08:59:28 +01:00
Bakkeby
b8056cbf24 xresources: destroy Xrm database after resource load
st would hold on to a XrmDatabase reference for the lifetime of the
program due to how in resource_load the ret.addr of the database
would be referenced directly. This also meant that for every reload
st would be leaking another XrmDatabase reference.

This has been partially worked around by applying a strdup to make
a copy of the string in order to allow for the XrmDatabase to be
freed / destroyed. Consequently the char arrays / strings still
leak on reload.

We could pass *sdst to free beforehand, but that will only work if
that reference is guaranteed to be on the heap.
2026-01-29 21:28:16 +01:00
Bakkeby
9328548866 xresources: removing focus change ttywrite ref. #182 2025-08-03 22:19:37 +02:00
step
499b7fbc19
XRESOURCES_RELOAD_PATCH reload fonts + re-render (#84)
This patch 1) improves reloading X resources - by considering fonts in
a way nearly identical to function `zoomabs`' - and 2) re-renders st so
that changed colors and fonts can be seen.
2022-09-24 10:40:33 +02:00
Bakkeby
9e0e419781 xresources reload: should close the display after being finished with the connection (if not then it can cause "Maximum amount of clients reached" errors after some time) 2022-07-28 15:48:40 +02:00
bakkeby
3e41e252b1 Adding background image reload patch ref. pull request #62 2022-04-11 16:04:58 +02:00
bakkeby
0fade9158a xresources reload: minor style changes ref. #16 2021-05-07 09:27:05 +02:00
Loic Coyle
540a923fb9 Add XRESOURCES_RELOAD_PATCH 2021-04-24 00:30:14 +02:00
bakkeby
4bd0ed3327 Adding xresources patch 2019-09-16 14:21:09 +02:00