From 28b4c822c5c0acec300fdf15c6e3ede9f5e2335d Mon Sep 17 00:00:00 2001 From: John Collis Date: Sun, 6 Sep 2020 17:53:41 +1200 Subject: [PATCH 1/7] ST: Add WM_ICON_NAME property support Also added _NET_WM_ICON_NAME. --- st.c | 9 +++++++++ win.h | 1 + x.c | 16 +++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/st.c b/st.c index 76b7e0d..ae7fa63 100644 --- a/st.c +++ b/st.c @@ -1844,6 +1844,7 @@ strhandle(void) { char *p = NULL, *dec; int j, narg, par; + static int winname = 0; term.esc &= ~(ESC_STR_END|ESC_STR); strparse(); @@ -1853,7 +1854,15 @@ strhandle(void) case ']': /* OSC -- Operating System Command */ switch (par) { case 0: + if (narg > 1) { + xsettitle(strescseq.args[1]); + xseticontitle(strescseq.args[1]); + } + return; case 1: + if (narg > 1) + xseticontitle(strescseq.args[1]); + return; case 2: if (narg > 1) xsettitle(strescseq.args[1]); diff --git a/win.h b/win.h index a6ef1b9..e6e4369 100644 --- a/win.h +++ b/win.h @@ -30,6 +30,7 @@ void xdrawline(Line, int, int, int); void xfinishdraw(void); void xloadcols(void); int xsetcolorname(int, const char *); +void xseticontitle(char *); void xsettitle(char *); int xsetcursor(int); void xsetmode(int, unsigned int); diff --git a/x.c b/x.c index 210f184..120e495 100644 --- a/x.c +++ b/x.c @@ -93,7 +93,7 @@ typedef struct { Window win; Drawable buf; GlyphFontSpec *specbuf; /* font spec buffer used for rendering */ - Atom xembed, wmdeletewin, netwmname, netwmpid; + Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid; struct { XIM xim; XIC xic; @@ -1186,6 +1186,7 @@ xinit(int cols, int rows) xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False); xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False); + xw.netwmiconname = XInternAtom(xw.dpy, "_NET_WM_ICON_NAME", False); XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1); xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False); @@ -1579,6 +1580,19 @@ xsetenv(void) setenv("WINDOWID", buf, 1); } +void +xseticontitle(char *p) +{ + XTextProperty prop; + DEFAULT(p, opt_title); + + Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, + &prop); + XSetWMIconName(xw.dpy, xw.win, &prop); + XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname); + XFree(prop.value); +} + void xsettitle(char *p) { From 4ef0cbd8b9371f37f7d02ef37b5378b879e6b8bf Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 18 Oct 2020 11:18:03 +0200 Subject: [PATCH 2/7] remove unused variable from previous patch --- st.c | 1 - 1 file changed, 1 deletion(-) diff --git a/st.c b/st.c index ae7fa63..abbbe4b 100644 --- a/st.c +++ b/st.c @@ -1844,7 +1844,6 @@ strhandle(void) { char *p = NULL, *dec; int j, narg, par; - static int winname = 0; term.esc &= ~(ESC_STR_END|ESC_STR); strparse(); From 9e68fdbcdb06dfa3d23fe3a7a7f7b59e40e1ea2f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 19 Mar 2021 11:54:36 +0100 Subject: [PATCH 3/7] fix: correctly encode mouse buttons >= 8 in X10 and SGR mode These are typically mapped in X11 to the side-buttons (backward/forwards) on the mouse. A comparison of the button numbers in SGR mode (first field): st old: 0 1 2 64 65 66 67 68 69 70 st new (it is the same as xterm now): 0 1 2 64 65 66 67 128 129 130 A script to test and reproduce it, first argument is "h" (on) or "l" (off): #!/bin/sh printf '\x1b[?1000%s\x1b[?1006%s' "$1" "$1" for n in 1 2 3 4 5 6 7 8 9 10; do printf 'button %d\n' "$n" xdotool click "$n" printf '\n\n' done --- x.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x.c b/x.c index 120e495..8bf998e 100644 --- a/x.c +++ b/x.c @@ -387,7 +387,9 @@ mousereport(XEvent *e) button = 3; } else { button -= Button1; - if (button >= 3) + if (button >= 7) + button += 128 - 7; + else if (button >= 3) button += 64 - 3; } if (e->xbutton.type == ButtonPress) { From 4536f46cfff50c66a115755def0155d8e246b02f Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 28 Mar 2021 21:16:59 +0200 Subject: [PATCH 4/7] Mild const-correctness improvements. Only touch a few things, the main focus is to improve code readability. --- st.c | 44 +++++++++++++++++++++++--------------------- st.h | 4 ++-- x.c | 6 +++--- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/st.c b/st.c index abbbe4b..ebdf360 100644 --- a/st.c +++ b/st.c @@ -186,18 +186,18 @@ static void tputc(Rune); static void treset(void); static void tscrollup(int, int); static void tscrolldown(int, int); -static void tsetattr(int *, int); -static void tsetchar(Rune, Glyph *, int, int); +static void tsetattr(const int *, int); +static void tsetchar(Rune, const Glyph *, int, int); static void tsetdirt(int, int); static void tsetscroll(int, int); static void tswapscreen(void); -static void tsetmode(int, int, int *, int); +static void tsetmode(int, int, const int *, int); static int twrite(const char *, int, int); static void tfulldirt(void); static void tcontrolcode(uchar ); static void tdectest(char ); static void tdefutf8(char); -static int32_t tdefcolor(int *, int *, int); +static int32_t tdefcolor(const int *, int *, int); static void tdeftran(char); static void tstrsequence(uchar); @@ -226,10 +226,10 @@ static int iofd = 1; static int cmdfd; static pid_t pid; -static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; -static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; -static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; -static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; +static const uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; +static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; +static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; +static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; ssize_t xwrite(int fd, const char *s, size_t len) @@ -269,12 +269,14 @@ xrealloc(void *p, size_t len) } char * -xstrdup(char *s) +xstrdup(const char *s) { - if ((s = strdup(s)) == NULL) + char *p; + + if ((p = strdup(s)) == NULL) die("strdup: %s\n", strerror(errno)); - return s; + return p; } size_t @@ -518,7 +520,7 @@ selsnap(int *x, int *y, int direction) { int newx, newy, xt, yt; int delim, prevdelim; - Glyph *gp, *prevgp; + const Glyph *gp, *prevgp; switch (sel.snap) { case SNAP_WORD: @@ -591,7 +593,7 @@ getsel(void) { char *str, *ptr; int y, bufsize, lastx, linelen; - Glyph *gp, *last; + const Glyph *gp, *last; if (sel.ob.x == -1) return NULL; @@ -758,7 +760,7 @@ stty(char **args) } int -ttynew(char *line, char *cmd, char *out, char **args) +ttynew(const char *line, char *cmd, const char *out, char **args) { int m, s; @@ -1186,9 +1188,9 @@ tmoveto(int x, int y) } void -tsetchar(Rune u, Glyph *attr, int x, int y) +tsetchar(Rune u, const Glyph *attr, int x, int y) { - static char *vt100_0[62] = { /* 0x41 - 0x7e */ + static const char *vt100_0[62] = { /* 0x41 - 0x7e */ "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ 0, 0, 0, 0, 0, 0, 0, 0, /* P - W */ @@ -1300,7 +1302,7 @@ tdeleteline(int n) } int32_t -tdefcolor(int *attr, int *npar, int l) +tdefcolor(const int *attr, int *npar, int l) { int32_t idx = -1; uint r, g, b; @@ -1350,7 +1352,7 @@ tdefcolor(int *attr, int *npar, int l) } void -tsetattr(int *attr, int l) +tsetattr(const int *attr, int l) { int i; int32_t idx; @@ -1468,9 +1470,9 @@ tsetscroll(int t, int b) } void -tsetmode(int priv, int set, int *args, int narg) +tsetmode(int priv, int set, const int *args, int narg) { - int alt, *lim; + int alt; const int *lim; for (lim = args + narg; args < lim; ++args) { if (priv) { @@ -2020,7 +2022,7 @@ void tdumpline(int n) { char buf[UTF_SIZ]; - Glyph *bp, *end; + const Glyph *bp, *end; bp = &term.line[n][0]; end = &bp[MIN(tlinelen(n), term.col) - 1]; diff --git a/st.h b/st.h index 3d351b6..fa2eddf 100644 --- a/st.h +++ b/st.h @@ -91,7 +91,7 @@ void tnew(int, int); void tresize(int, int); void tsetdirtattr(int); void ttyhangup(void); -int ttynew(char *, char *, char *, char **); +int ttynew(const char *, char *, const char *, char **); size_t ttyread(void); void ttyresize(int, int); void ttywrite(const char *, size_t, int); @@ -109,7 +109,7 @@ size_t utf8encode(Rune, char *); void *xmalloc(size_t); void *xrealloc(void *, size_t); -char *xstrdup(char *); +char *xstrdup(const char *); /* config.h globals */ extern char *utmp; diff --git a/x.c b/x.c index 8bf998e..7186040 100644 --- a/x.c +++ b/x.c @@ -156,7 +156,7 @@ static void xresize(int, int); static void xhints(void); static int xloadcolor(int, const char *, Color *); static int xloadfont(Font *, FcPattern *); -static void xloadfonts(char *, double); +static void xloadfonts(const char *, double); static void xunloadfont(Font *); static void xunloadfonts(void); static void xsetenv(void); @@ -952,7 +952,7 @@ xloadfont(Font *f, FcPattern *pattern) } void -xloadfonts(char *fontstr, double fontsize) +xloadfonts(const char *fontstr, double fontsize) { FcPattern *pattern; double fontval; @@ -960,7 +960,7 @@ xloadfonts(char *fontstr, double fontsize) if (fontstr[0] == '-') pattern = XftXlfdParse(fontstr, False, False); else - pattern = FcNameParse((FcChar8 *)fontstr); + pattern = FcNameParse((const FcChar8 *)fontstr); if (!pattern) die("can't open font %s\n", fontstr); From 2ec571a30c0c3b1a17f6b3631c80d573582f59a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20Kapri=C5=A1?= Date: Sun, 18 Jul 2021 00:14:00 +0200 Subject: [PATCH 5/7] Add 14th bit to XK_SWITCH_MOD bitmask The bits of uint signal in an XKeyEvent which concern the key group (keyboard layout) are bits 13 and 14, as documented here: https://www.x.org/releases/X11R7.7/doc/libX11/XKB/xkblib.html#Groups_and_Shift_Levels In the older version, only bit 13 was marked as part of XK_SWITCH_MOD, this causes issues for users who have more than two keymaps. the 14th bit is not in ignoremod, key sequences are not caught by match(), if they switch to a third or fourth keyboard. --- x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x.c b/x.c index 7186040..248d505 100644 --- a/x.c +++ b/x.c @@ -48,7 +48,7 @@ typedef struct { /* X modifiers */ #define XK_ANY_MOD UINT_MAX #define XK_NO_MOD 0 -#define XK_SWITCH_MOD (1<<13) +#define XK_SWITCH_MOD (1<<13|1<<14) /* function definitions used in config.h */ static void clipcopy(const Arg *); From 1d3142da968da7f6f61f1c1708f39ca233eda150 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 24 Aug 2021 06:25:05 +0900 Subject: [PATCH 6/7] fix a problem that the standard streams are unexpectedly closed In the current implementation, the slave PTY (assigned to the variable `s') is always closed after duplicating it to file descriptors of standard streams (0, 1, and 2). However, when the allocated slave PTY `s' is already one of 0, 1, or 2, this causes unexpected closing of a standard stream. The same problem occurs when the file descriptor of the master PTY (the variable `m') is one of 0, 1, or 2. In this patch, the original master PTY (m) is closed before it would be overwritten by duplicated slave PTYs. The original slave PTY (s) is closed only when it is not one of the stanrad streams. --- st.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/st.c b/st.c index ebdf360..a9338e1 100644 --- a/st.c +++ b/st.c @@ -793,14 +793,15 @@ ttynew(const char *line, char *cmd, const char *out, char **args) break; case 0: close(iofd); + close(m); setsid(); /* create a new process group */ dup2(s, 0); dup2(s, 1); dup2(s, 2); if (ioctl(s, TIOCSCTTY, NULL) < 0) die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); - close(s); - close(m); + if (s > 2) + close(s); #ifdef __OpenBSD__ if (pledge("stdio getpw proc exec", NULL) == -1) die("pledge\n"); From 2f6e597ed871cff91c627850d03152cae5f45779 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 24 Aug 2021 13:44:35 +0200 Subject: [PATCH 7/7] fix possible rare crash when Xutf8TextPropertyToTextList fails from the XmbTextListToTextProperty(3) man page: "If insufficient memory is available for the new value string, the functions return XNoMemory. If the current locale is not supported, the functions return XLocaleNotSupported. In both of these error cases, the functions do not set text_prop_return." Reported by Steffen Nurpmeso , thanks! --- x.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/x.c b/x.c index 248d505..89786b8 100644 --- a/x.c +++ b/x.c @@ -1588,8 +1588,9 @@ xseticontitle(char *p) XTextProperty prop; DEFAULT(p, opt_title); - Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, - &prop); + if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, + &prop) != Success) + return; XSetWMIconName(xw.dpy, xw.win, &prop); XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname); XFree(prop.value); @@ -1601,8 +1602,9 @@ xsettitle(char *p) XTextProperty prop; DEFAULT(p, opt_title); - Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, - &prop); + if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, + &prop) != Success) + return; XSetWMName(xw.dpy, xw.win, &prop); XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname); XFree(prop.value);