Compare commits

..

17 commits

Author SHA1 Message Date
ant
df11aae8c3 Revert "change colors for light theme"
This reverts commit 042af42400.
2026-02-05 10:08:37 +01:00
Antoine Vaure
87c6c244c4 change colors for light theme 2026-02-05 10:08:37 +01:00
Antoine Vaure
659b803a40 add keybinnds to scroll 2026-02-05 10:08:37 +01:00
Antoine Vaure
ccaedf3fe9 decrease default font size 2026-02-05 10:08:37 +01:00
ant
4194b515ee Enable alpha patch 2026-02-05 10:08:37 +01:00
ant
568f306b14 enable boxdraw 2026-02-05 10:08:37 +01:00
ant
bedf74d2ad Add a nix flake 2026-02-05 10:08:37 +01:00
ant
653e567b29 enable patches I want 2026-02-05 10:08:37 +01:00
ant
4d18a5e104 change keys to keyboard select and zoom 2026-02-05 10:08:37 +01:00
ant
38dcc0e866 change default colors 2026-02-05 10:08:37 +01:00
ant
d17eac914f Add darkman patch
a patch to choose between two color themes by executing a command
2026-02-05 10:08:37 +01:00
ant
81a9b451e9 font default to caskadia 2026-02-05 10:08:37 +01:00
Antoine Vaure
8ced61c5e3 config: increase scroll speed 2026-02-05 10:08:37 +01:00
ant
1252a3d79d fontfeature patch 2026-02-05 10:08:37 +01:00
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
veltza
490d2440da
sixel: fix hls-to-rgb and color count issues (#185)
This fixes the following sixel issues:

- The HLS to RGB color conversion is broken.
  Ref. d4ade1fe3c

- Not enough color registers have been allocated for 1024 colors.
  Ref. 97f93e8436
2026-01-15 11:11:04 +01:00
7 changed files with 145 additions and 21 deletions

View file

@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog: ### Changelog:
2026-01-08 - Added the xresources-xdefaults patch
2025-10-28 - Added the selectionbg-alpha patch 2025-10-28 - Added the selectionbg-alpha patch
2025-02-20 - Added the drag-n-drop and open-selected-text patches 2025-02-20 - Added the drag-n-drop and open-selected-text patches
@ -340,3 +342,6 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- [xresources](https://st.suckless.org/patches/xresources/) - [xresources](https://st.suckless.org/patches/xresources/)
- adds the ability to configure st via Xresources - adds the ability to configure st via Xresources
- during startup, st will read and apply the resources named in the resources[] array in config.h - during startup, st will read and apply the resources named in the resources[] array in config.h
- xresources-xdefaults
- allows .Xdefaults to be read as well in addition to the RESOURCE_MANAGER property on the root window

View file

@ -22,7 +22,8 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
switch (rtype) { switch (rtype) {
case STRING: case STRING:
*sdst = ret.addr; /* Note: this leaks memory */
*sdst = strdup(ret.addr);
break; break;
case INTEGER: case INTEGER:
*idst = strtoul(ret.addr, NULL, 10); *idst = strtoul(ret.addr, NULL, 10);
@ -34,6 +35,102 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
return 0; return 0;
} }
#if XRESOURCES_XDEFAULTS_PATCH
/* Returns an XrmDatabase that needs to be freed by the caller. */
static XrmDatabase
get_resources(Display *dpy)
{
/*******************************************************************/
/* Adapted from rxvt-unicode-9.31 rxvttoolkit.C get_resources() */
/*******************************************************************/
char *homedir = getenv("HOME");
char fname[1024];
char *displayResource, *xe;
XrmDatabase rdb1;
XrmDatabase database = XrmGetStringDatabase("");
/* For ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 */
/* 6. System wide per application default file. */
/* Add in $XAPPLRESDIR/St only; not bothering with XUSERFILESEARCHPATH */
if ((xe = getenv("XAPPLRESDIR")) || (xe = "/etc/X11/app-defaults"))
{
snprintf(fname, sizeof(fname), "%s/%s", xe, "St");
if ((rdb1 = XrmGetFileDatabase(fname)))
XrmMergeDatabases(rdb1, &database);
}
/* 5. User's per application default file. None. */
/* 4. User's defaults file. */
if (homedir)
{
snprintf(fname, sizeof(fname), "%s/.Xdefaults", homedir);
if ((rdb1 = XrmGetFileDatabase(fname)))
XrmMergeDatabases(rdb1, &database);
}
/* Get any Xserver Resources (xrdb). */
displayResource = XResourceManagerString(dpy);
if (displayResource)
{
if ((rdb1 = XrmGetStringDatabase(displayResource)))
XrmMergeDatabases(rdb1, &database);
}
/* Get screen specific resources. */
displayResource = XScreenResourceString(ScreenOfDisplay(dpy, DefaultScreen(dpy)));
if (displayResource)
{
if ((rdb1 = XrmGetStringDatabase(displayResource)))
XrmMergeDatabases(rdb1, &database);
XFree(displayResource);
}
/* 3. User's per host defaults file. */
/* Add in XENVIRONMENT file */
if ((xe = getenv("XENVIRONMENT")) && (rdb1 = XrmGetFileDatabase(xe)))
XrmMergeDatabases(rdb1, &database);
else if (homedir)
{
struct utsname un;
if (!uname(&un))
{
snprintf(fname, sizeof(fname), "%s/.Xdefaults-%s", homedir, un.nodename);
if ((rdb1 = XrmGetFileDatabase(fname)))
XrmMergeDatabases(rdb1, &database);
}
}
return database;
}
void
config_init(Display *dpy)
{
XrmDatabase db;
ResourcePref *p;
XrmInitialize();
db = get_resources(dpy);
for (p = resources; p < resources + LEN(resources); p++)
resource_load(db, p->name, p->type, p->dst);
XrmDestroyDatabase(db);
}
#else // !XRESOURCES_XDEFAULTS_PATCH
void void
config_init(Display *dpy) config_init(Display *dpy)
{ {
@ -42,14 +139,21 @@ config_init(Display *dpy)
ResourcePref *p; ResourcePref *p;
XrmInitialize(); XrmInitialize();
resm = XResourceManagerString(dpy); resm = XResourceManagerString(dpy);
if (!resm) if (!resm)
return; return;
db = XrmGetStringDatabase(resm); db = XrmGetStringDatabase(resm);
if (!db)
return;
for (p = resources; p < resources + LEN(resources); p++) for (p = resources; p < resources + LEN(resources); p++)
resource_load(db, p->name, p->type, p->dst); resource_load(db, p->name, p->type, p->dst);
XrmDestroyDatabase(db);
} }
#endif // XRESOURCES_XDEFAULTS_PATCH
#if XRESOURCES_RELOAD_PATCH #if XRESOURCES_RELOAD_PATCH
void void

View file

@ -1,4 +1,7 @@
#include <X11/Xresource.h> #include <X11/Xresource.h>
#if XRESOURCES_XDEFAULTS_PATCH
#include <sys/utsname.h>
#endif // XRESOURCES_XDEFAULTS_PATCH
/* Xresources preferences */ /* Xresources preferences */
enum resource_type { enum resource_type {

View file

@ -542,3 +542,10 @@
* Depends on the XRESOURCES_PATCH. * Depends on the XRESOURCES_PATCH.
*/ */
#define XRESOURCES_RELOAD_PATCH 0 #define XRESOURCES_RELOAD_PATCH 0
/* 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.
*/
#define XRESOURCES_XDEFAULTS_PATCH 0

View file

@ -100,9 +100,13 @@ set_default_color(sixel_image_t *image)
image->palette[n++] = SIXEL_RGB(i * 11, i * 11, i * 11); image->palette[n++] = SIXEL_RGB(i * 11, i * 11, i * 11);
} }
/* sixels rarely use more than 256 colors and if they do, they use a custom
* palette, so we don't need to initialize these colors */
/*
for (; n < DECSIXEL_PALETTE_MAX; n++) { for (; n < DECSIXEL_PALETTE_MAX; n++) {
image->palette[n] = SIXEL_RGB(255, 255, 255); image->palette[n] = SIXEL_RGB(255, 255, 255);
} }
*/
return (0); return (0);
} }
@ -610,11 +614,12 @@ sixel_parser_parse(sixel_state_t *st, const unsigned char *p, size_t len)
st->param = 0; st->param = 0;
if (st->nparams > 0) { if (st->nparams > 0) {
st->color_index = 1 + st->params[0]; /* offset 1(background color) added */ st->color_index = st->params[0];
if (st->color_index < 0) if (st->color_index < 0)
st->color_index = 0; st->color_index = 0;
else if (st->color_index >= DECSIXEL_PALETTE_MAX) else if (st->color_index >= DECSIXEL_PALETTE_MAX)
st->color_index = DECSIXEL_PALETTE_MAX - 1; st->color_index = DECSIXEL_PALETTE_MAX - 1;
st->color_index++; /* offset by 1 (background) */
} }
if (st->nparams > 4) { if (st->nparams > 4) {

View file

@ -14,7 +14,7 @@ typedef struct sixel_image_buffer {
sixel_color_no_t *data; sixel_color_no_t *data;
int width; int width;
int height; int height;
sixel_color_t palette[DECSIXEL_PALETTE_MAX]; sixel_color_t palette[DECSIXEL_PALETTE_MAX + 1];
sixel_color_no_t ncolors; sixel_color_no_t ncolors;
int palette_modified; int palette_modified;
int use_private_register; int use_private_register;

View file

@ -30,20 +30,18 @@
// sale, use or other dealings in this Software without prior written // sale, use or other dealings in this Software without prior written
// authorization. // authorization.
#define SIXEL_RGB(r, g, b) ((r) + ((g) << 8) + ((b) << 16) + (255 << 24)) #define SIXEL_RGB(r, g, b) ((255 << 24) + ((r) << 16) + ((g) << 8) + (b))
int int
hls_to_rgb(int hue, int lum, int sat) hls_to_rgb(int hue, int lum, int sat)
{ {
double hs = (hue + 240) % 360;
double hv = hs / 360.0;
double lv = lum / 100.0; double lv = lum / 100.0;
double sv = sat / 100.0; double sv = sat / 100.0;
double c, x, m, c2; double c, x, m, c2;
double r1, g1, b1; double r1, g1, b1;
int r, g, b; int r, g, b, hs;
int hpi;
hue = (hue + 240) % 360;
if (sat == 0) { if (sat == 0) {
r = g = b = lum * 255 / 100; r = g = b = lum * 255 / 100;
return SIXEL_RGB(r, g, b); return SIXEL_RGB(r, g, b);
@ -52,12 +50,14 @@ hls_to_rgb(int hue, int lum, int sat)
if ((c2 = ((2.0 * lv) - 1.0)) < 0.0) { if ((c2 = ((2.0 * lv) - 1.0)) < 0.0) {
c2 = -c2; c2 = -c2;
} }
if ((hs = (hue % 120) - 60) < 0) {
hs = -hs;
}
c = (1.0 - c2) * sv; c = (1.0 - c2) * sv;
hpi = (int) (hv * 6.0); x = ((60 - hs) / 60.0) * c;
x = (hpi & 1) ? c : 0.0;
m = lv - 0.5 * c; m = lv - 0.5 * c;
switch (hpi) { switch (hue / 60) {
case 0: case 0:
r1 = c; r1 = c;
g1 = x; g1 = x;
@ -92,24 +92,24 @@ hls_to_rgb(int hue, int lum, int sat)
return SIXEL_RGB(255, 255, 255); return SIXEL_RGB(255, 255, 255);
} }
r = (int) ((r1 + m) * 100.0 + 0.5); r = (int) ((r1 + m) * 255.0 + 0.5);
g = (int) ((g1 + m) * 100.0 + 0.5); g = (int) ((g1 + m) * 255.0 + 0.5);
b = (int) ((b1 + m) * 100.0 + 0.5); b = (int) ((b1 + m) * 255.0 + 0.5);
if (r < 0) { if (r < 0) {
r = 0; r = 0;
} else if (r > 100) { } else if (r > 255) {
r = 100; r = 255;
} }
if (g < 0) { if (g < 0) {
g = 0; g = 0;
} else if (g > 100) { } else if (g > 255) {
g = 100; g = 255;
} }
if (b < 0) { if (b < 0) {
b = 0; b = 0;
} else if (b > 100) { } else if (b > 255) {
b = 100; b = 255;
} }
return SIXEL_RGB(r * 255 / 100, g * 255 / 100, b * 255 / 100); return SIXEL_RGB(r, g, b);
} }