Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.9 #153

Merged
merged 15 commits into from
Apr 30, 2023
Merged

0.9 #153

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FAQ
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,6 @@ fonts:

Please don't bother reporting this bug to st, but notify the upstream Xft
developers about fixing this bug.

As of 2022-09-05 this now seems to be finally fixed in libXft 2.3.5:
https://gitlab.freedesktop.org/xorg/lib/libxft/-/blob/libXft-2.3.5/NEWS
6 changes: 5 additions & 1 deletion config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static unsigned int borderless = 0;
/* allow infelicity between the weights: */
unsigned int max_bold_weight_infelicity = 20;

static unsigned int borderpx = 2;
static int borderpx = 2;

/*
* What program is execed by st depends of these precedence rules:
Expand Down Expand Up @@ -173,6 +173,8 @@ static const char *colorname[] = {
"#555555",
"gray90", /* default foreground colour */
"black", /* default background colour */
"gray90", /* foreground colour (reverse) */
"black", /* background colour (reverse) */
};


Expand All @@ -182,6 +184,8 @@ static const char *colorname[] = {
*/
unsigned int defaultfg = 258;
unsigned int defaultbg = 259;
unsigned int defaultfg_reverse = 260;
unsigned int defaultbg_reverse = 261;
unsigned int defaultcs = 256;
static unsigned int defaultrcs = 257;

Expand Down
3 changes: 2 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# st version
VERSION = 0.8.5
VERSION = 0.9

# Customize below to fit your system

Expand Down Expand Up @@ -30,6 +30,7 @@ STLDFLAGS = $(LIBS) $(LDFLAGS)
#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
# `$(PKG_CONFIG) --libs fontconfig` \
# `$(PKG_CONFIG) --libs freetype2`
#MANPREFIX = ${PREFIX}/man

# compiler and linker
# CC = c99
686 changes: 686 additions & 0 deletions icon.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions readme.org
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
- [[https://st.suckless.org/patches/spoiler/][spoiler]]
- [[https://st.suckless.org/patches/vertcenter/][vertcenter]]
- [[https://st.suckless.org/patches/undercurl/][undercurl]]
- [[https://st.suckless.org/patches/netwmicon/][netwmicon]]

*** Not supported patches

- [[https://st.suckless.org/patches/hidecursor/][hidecursor]]: use unclutter or an external program to hide your cursor
- [[https://st.suckless.org/patches/keyboard_select/][keyboard_select]]: use tmux

*** Packages

Expand Down
136 changes: 57 additions & 79 deletions st.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static void csihandle(void);
static void csiparse(void);
static void readcolonargs(char **, int, int[][CAR_PER_ARG]);
static void csireset(void);
static void osc_color_response(int, int, int);
static int eschandle(uchar);
static void strdump(void);
static void strhandle(void);
Expand Down Expand Up @@ -359,25 +360,10 @@ utf8validate(Rune *u, size_t i)
return i;
}

static const char base64_digits[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0,
63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, -1, 0, 0, 0, 0, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

char
base64dec_getc(const char **src)
{
while (**src && !isprint(**src))
while (**src && !isprint((unsigned char)**src))
(*src)++;
return **src ? *((*src)++) : '='; /* emulate padding if string ends */
}
Expand All @@ -387,6 +373,13 @@ base64dec(const char *src)
{
size_t in_len = strlen(src);
char *result, *dst;
static const char base64_digits[256] = {
[43] = 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0,
0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
};

if (in_len % 4)
in_len += 4 - (in_len % 4);
Expand Down Expand Up @@ -964,7 +957,7 @@ ttyresize(int tw, int th)
}

void
ttyhangup()
ttyhangup(void)
{
/* Send SIGHUP to shell */
kill(pid, SIGHUP);
Expand Down Expand Up @@ -1906,11 +1899,18 @@ csihandle(void)
case 'm': /* SGR -- Terminal attribute (color) */
tsetattr(csiescseq.arg, csiescseq.narg);
break;
case 'n': /* DSR – Device Status Report (cursor position) */
if (csiescseq.arg[0] == 6) {
case 'n': /* DSR -- Device Status Report */
switch (csiescseq.arg[0]) {
case 5: /* Status Report "OK" `0n` */
ttywrite("\033[0n", sizeof("\033[0n") - 1, 0);
break;
case 6: /* Report Cursor Position (CPR) "<row>;<column>R" */
len = snprintf(buf, sizeof(buf), "\033[%i;%iR",
term.c.y+1, term.c.x+1);
term.c.y+1, term.c.x+1);
ttywrite(buf, len, 0);
break;
default:
goto unknown;
}
break;
case 'r': /* DECSTBM -- Set Scrolling Region */
Expand Down Expand Up @@ -1973,46 +1973,40 @@ csireset(void)
}

void
osc4_color_response(int num)
osc_color_response(int num, int index, int is_osc4)
{
int n;
char buf[32];
unsigned char r, g, b;

if (xgetcolor(num, &r, &g, &b)) {
fprintf(stderr, "erresc: failed to fetch osc4 color %d\n", num);
if (xgetcolor(is_osc4 ? num : index, &r, &g, &b)) {
fprintf(stderr, "erresc: failed to fetch %s color %d\n",
is_osc4 ? "osc4" : "osc",
is_osc4 ? num : index);
return;
}

n = snprintf(buf, sizeof buf, "\033]4;%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
num, r, r, g, g, b, b);

ttywrite(buf, n, 1);
}

void
osc_color_response(int index, int num)
{
int n;
char buf[32];
unsigned char r, g, b;

if (xgetcolor(index, &r, &g, &b)) {
fprintf(stderr, "erresc: failed to fetch osc color %d\n", index);
return;
n = snprintf(buf, sizeof buf, "\033]%s%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
is_osc4 ? "4;" : "", num, r, r, g, g, b, b);
if (n < 0 || n >= sizeof(buf)) {
fprintf(stderr, "error: %s while printing %s response\n",
n < 0 ? "snprintf failed" : "truncation occurred",
is_osc4 ? "osc4" : "osc");
} else {
ttywrite(buf, n, 1);
}

n = snprintf(buf, sizeof buf, "\033]%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
num, r, r, g, g, b, b);

ttywrite(buf, n, 1);
}

void
strhandle(void)
{
char *p = NULL, *dec;
int j, narg, par;
const struct { int idx; char *str; } osc_table[] = {
{ defaultfg, "foreground" },
{ defaultbg, "background" },
{ defaultcs, "cursor" }
};

term.esc &= ~(ESC_STR_END|ESC_STR);
strparse();
Expand Down Expand Up @@ -2047,43 +2041,22 @@ strhandle(void)
}
return;
case 10:
if (narg < 2)
break;

p = strescseq.args[1];

if (!strcmp(p, "?"))
osc_color_response(defaultfg, 10);
else if (xsetcolorname(defaultfg, p))
fprintf(stderr, "erresc: invalid foreground color: %s\n", p);
else
tfulldirt();
return;
case 11:
if (narg < 2)
break;

p = strescseq.args[1];

if (!strcmp(p, "?"))
osc_color_response(defaultbg, 11);
else if (xsetcolorname(defaultbg, p))
fprintf(stderr, "erresc: invalid background color: %s\n", p);
else
tfulldirt();
return;
case 12:
if (narg < 2)
break;

p = strescseq.args[1];

if (!strcmp(p, "?"))
osc_color_response(defaultcs, 12);
else if (xsetcolorname(defaultcs, p))
fprintf(stderr, "erresc: invalid cursor color: %s\n", p);
else
if ((j = par - 10) < 0 || j >= LEN(osc_table))
break; /* shouldn't be possible */

if (!strcmp(p, "?")) {
osc_color_response(par, osc_table[j].idx, 0);
} else if (xsetcolorname(osc_table[j].idx, p)) {
fprintf(stderr, "erresc: invalid %s color: %s\n",
osc_table[j].str, p);
} else {
tfulldirt();
}
return;
case 4: /* color set */
if (narg < 3)
Expand All @@ -2093,11 +2066,13 @@ strhandle(void)
case 104: /* color reset */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;

if (p && !strcmp(p, "?"))
osc4_color_response(j);
else if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1)
if (p && !strcmp(p, "?")) {
osc_color_response(j, 0, 1);
} else if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1) {
xloadcols();
return; /* color reset without parameter */
}
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
j, p ? p : "(null)");
} else {
Expand Down Expand Up @@ -2630,6 +2605,9 @@ tputc(Rune u)
* they must not cause conflicts with sequences.
*/
if (control) {
/* in UTF-8 mode ignore handling C1 control characters */
if (IS_SET(MODE_UTF8) && ISCONTROLC1(u))
return;
tcontrolcode(u);
/*
* control codes are not shown ever
Expand Down
1 change: 1 addition & 0 deletions win.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void xdrawline(Line, int, int, int);
void xfinishdraw(void);
void xloadcols(void);
int xsetcolorname(int, const char *);
int xgetcolor(int, unsigned char *, unsigned char *, unsigned char *);
void xseticontitle(char *);
void xsettitle(char *);
int xsetcursor(int);
Expand Down
34 changes: 22 additions & 12 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

char *argv0;
#include "arg.h"
#include "icon.h"
#include "st.h"
#include "win.h"

Expand Down Expand Up @@ -107,7 +108,7 @@ typedef struct {
Window win;
Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmicon, netwmpid;
struct {
XIM xim;
XIC xic;
Expand Down Expand Up @@ -852,6 +853,9 @@ xloadcols(void)
if (alpha > 1.0)
alpha = alpha / 255.0;

dc.col[defaultbg_reverse] = dc.col[defaultfg];
dc.col[defaultfg_reverse] = dc.col[defaultbg];

dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);

if (disable_alpha_correction) {
Expand All @@ -871,6 +875,11 @@ xloadcols(void)
scaled_alpha << 24;
}

if (alpha != 0) {
dc.col[defaultbg_reverse] = dc.col[defaultfg];
dc.col[defaultfg_reverse] = dc.col[defaultbg];
}

loaded = 1;
}

Expand Down Expand Up @@ -1395,6 +1404,10 @@ xinit(int cols, int rows)
xw.netwmiconname = XInternAtom(xw.dpy, "_NET_WM_ICON_NAME", False);
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);

xw.netwmicon = XInternAtom(xw.dpy, "_NET_WM_ICON", False);
XChangeProperty(xw.dpy, xw.win, xw.netwmicon, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&icon, LEN(icon));

xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
Expand Down Expand Up @@ -2047,14 +2060,8 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
}

if (base.mode & ATTR_REVERSE) {
if (bg == fg) {
bg = &dc.col[defaultfg];
fg = &dc.col[defaultbg];
} else {
temp = fg;
fg = bg;
bg = temp;
}
bg = &dc.col[defaultbg_reverse];
fg = &dc.col[defaultfg_reverse];
neeasade marked this conversation as resolved.
Show resolved Hide resolved
}

if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
Expand Down Expand Up @@ -2476,7 +2483,7 @@ void
kpress(XEvent *ev)
{
XKeyEvent *e = &ev->xkey;
KeySym ksym;
KeySym ksym = NoSymbol;
char buf[64], *customkey;
int len;
Rune c;
Expand All @@ -2486,10 +2493,13 @@ kpress(XEvent *ev)
if (IS_SET(MODE_KBDLOCK))
return;

if (xw.ime.xic)
if (xw.ime.xic) {
len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
else
if (status == XBufferOverflow)
return;
} else {
len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
}
/* 1. shortcuts */
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) {
Expand Down