st

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c812c9f2ba6c81c14435cbb719368a18160e8877
parent c07885e9fac0a29f8a610394329052fb026207dc
Author: siduck <siduck@tutanota.com>
Date:   Wed,  6 Jul 2022 06:55:14 +0530

add netwmicon patch | bump to v0.8.5

Diffstat:
M.gitignore | 2++
MMakefile | 3+++
MREADME.md | 10----------
Mconfig.mk | 10+++++++---
Mst.c | 61++++++++++++++++++++++++++++++++++++++-----------------------
Mst.desktop | 1+
Mst.h | 9+++++----
Ast.png | 0
Mwin.h | 1+
Mx.c | 76+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
10 files changed, 122 insertions(+), 51 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,5 @@ config.h st *.o +*.rej +*.orig diff --git a/Makefile b/Makefile @@ -55,6 +55,8 @@ install: st chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1 tic -sx st.info @echo Please see the README file regarding the terminfo entry of st. + mkdir -p $(DESTDIR)$(ICONPREFIX) + [ -f $(ICONNAME) ] && cp -f $(ICONNAME) $(DESTDIR)$(ICONPREFIX) || : mkdir -p $(DESTDIR)$(PREFIX)/share/applications cp -f st.desktop $(DESTDIR)$(PREFIX)/share/applications @@ -64,5 +66,6 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/st-urlhandler rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 rm -f $(DESTDIR)$(PREFIX)/share/applications/st.desktop + rm -f $(DESTDIR)$(ICONPREFIX)/$(ICONNAME) .PHONY: all options clean dist install uninstall diff --git a/README.md b/README.md @@ -111,13 +111,3 @@ you can change all of these in config.h - [live-reload](https://github.com/nimaipatel/st) - [patch_column](https://github.com/nimaipatel/st/blob/all/patches/7672445bab01cb4e861651dc540566ac22e25812.diff) - -## Other St builds <br> - -1. Sixel St (sixel branch , with sixel graphics support) -2. St with vim-browse (vim-browse branch , navigate within like vim) -3. Awesomewm users might face a weird gaps issue (#23) so they need to use the anysize branch. - -- Use a different st build ( clone its branch) - -`example: git clone https://github.com/siduck/st --branch sixel` diff --git a/config.mk b/config.mk @@ -1,11 +1,13 @@ # st version -VERSION = 0.8.4 +VERSION = 0.8.5 # Customize below to fit your system # paths PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man +ICONPREFIX = $(PREFIX)/share/pixmaps +ICONNAME = st.png X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib @@ -14,16 +16,18 @@ PKG_CONFIG = pkg-config # includes and libs INCS = -I$(X11INC) \ + `$(PKG_CONFIG) --cflags glib-2.0` \ `$(PKG_CONFIG) --cflags fontconfig` \ `$(PKG_CONFIG) --cflags freetype2` \ `$(PKG_CONFIG) --cflags harfbuzz` -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \ +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lgd \ + `$(PKG_CONFIG) --libs glib-2.0` \ `$(PKG_CONFIG) --libs fontconfig` \ `$(PKG_CONFIG) --libs freetype2` \ `$(PKG_CONFIG) --libs harfbuzz` # flags -STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 +STCPPFLAGS = -DVERSION=\"$(VERSION)\" -DICON=\"$(ICONPREFIX)/$(ICONNAME)\" -D_XOPEN_SOURCE=600 STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS) STLDFLAGS = $(LIBS) $(LDFLAGS) diff --git a/st.c b/st.c @@ -203,18 +203,18 @@ static void tputc(Rune); static void treset(void); static void tscrollup(int, int, int); static void tscrolldown(int, 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); @@ -243,10 +243,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) @@ -286,12 +286,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 @@ -544,7 +546,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: @@ -617,7 +619,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; @@ -776,7 +778,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; @@ -809,14 +811,15 @@ ttynew(char *line, char *cmd, 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"); @@ -1289,9 +1292,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 */ @@ -1406,7 +1409,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; @@ -1456,7 +1459,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; @@ -1574,9 +1577,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) { @@ -1953,7 +1956,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]); @@ -2201,7 +2212,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]; @@ -2616,6 +2627,10 @@ check_control_code: if (width == 2) { gp->mode |= ATTR_WIDE; if (term.c.x+1 < term.col) { + if (gp[1].mode == ATTR_WIDE && term.c.x+2 < term.col) { + gp[2].u = ' '; + gp[2].mode &= ~ATTR_WDUMMY; + } gp[1].u = '\0'; gp[1].mode = ATTR_WDUMMY; } diff --git a/st.desktop b/st.desktop @@ -5,3 +5,4 @@ Comment=simple-terminal emulator for X Icon=utilities-terminal Exec=st Categories=System;TerminalEmulator +StartupWMClass=st-256color diff --git a/st.h b/st.h @@ -3,9 +3,10 @@ #include <stdint.h> #include <sys/types.h> +#include <gd.h> +#include <glib.h> + /* macros */ -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LEN(a) (sizeof(a) / sizeof(a)[0]) #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) @@ -112,7 +113,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); @@ -130,7 +131,7 @@ size_t utf8encode(Rune, char *); void *xmalloc(size_t); void *xrealloc(void *, size_t); -char *xstrdup(char *); +char *xstrdup(const char *); int isboxdraw(Rune); ushort boxdrawindex(const Glyph *); diff --git a/st.png b/st.png Binary files differ. diff --git 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 @@ -61,7 +61,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 *); @@ -90,6 +90,8 @@ typedef XftDraw *Draw; typedef XftColor Color; typedef XftGlyphFontSpec GlyphFontSpec; +typedef unsigned long int CARD32; + /* Purely graphic info */ typedef struct { int tw, th; /* tty width and height */ @@ -108,7 +110,7 @@ typedef struct { Window win; Drawable buf; GlyphFontSpec *specbuf; /* font spec buffer used for rendering */ - Atom xembed, wmdeletewin, netwmname, netwmpid; + Atom xembed, wmdeletewin, netwmname, netwmicon, netwmiconname, netwmpid; XIM xim; XIC xic; Draw draw; @@ -167,7 +169,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 int xloadsparefont(FcPattern *, int); static void xloadsparefonts(void); static void xunloadfont(Font *); @@ -412,6 +414,8 @@ mousereport(XEvent *e) } else { button -= Button1; if (button >= 3) + button += 128 - 7; + else if (button >= 3) button += 64 - 3; } if (e->xbutton.type == ButtonPress) { @@ -858,8 +862,8 @@ xclearwin(void) void xhints(void) { - XClassHint class = {opt_name ? opt_name : "st", - opt_class ? opt_class : "St"}; + XClassHint class = {opt_name ? opt_name : termname, + opt_class ? opt_class : termname}; XWMHints wm = {.flags = InputHint, .input = 1}; XSizeHints *sizeh; @@ -980,7 +984,7 @@ xloadfont(Font *f, FcPattern *pattern) } void -xloadfonts(char *fontstr, double fontsize) +xloadfonts(const char *fontstr, double fontsize) { FcPattern *pattern; double fontval; @@ -988,7 +992,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); @@ -1304,8 +1308,43 @@ 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); + /* use a png-image to set _NET_WM_ICON */ + FILE* file = fopen(ICON, "r"); + if (file) { + /* inititialize variables */ + const gdImagePtr icon_rgba = gdImageCreateFromPng(file); + fclose(file); + const int width = gdImageSX(icon_rgba); + const int height = gdImageSY(icon_rgba); + const int icon_n = width * height + 2; + CARD32 *icon_argb = g_new0(CARD32, icon_n); + /* set width and height of the icon */ + int i = 0; + icon_argb[i++] = width; + icon_argb[i++] = height; + /* RGBA -> ARGB */ + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + const int pixel_rgba = gdImageGetPixel(icon_rgba, x, y); + guint8* pixel_argb = (guint8*) &icon_argb[i++]; + pixel_argb[0] = gdImageBlue(icon_rgba, pixel_rgba); + pixel_argb[1] = gdImageGreen(icon_rgba, pixel_rgba); + pixel_argb[2] = gdImageRed(icon_rgba, pixel_rgba); + /* scale alpha from 0-127 to 0-255 */ + const int alpha = 127 - gdImageAlpha(icon_rgba, pixel_rgba); + pixel_argb[3] = alpha == 127 ? 255 : alpha * 2; + } + } + gdImageDestroy(icon_rgba); + /* set _NET_WM_ICON */ + xw.netwmicon = XInternAtom(xw.dpy, "_NET_WM_ICON", False); + XChangeProperty(xw.dpy, xw.win, xw.netwmicon, XA_CARDINAL, 32, + PropModeReplace, (uchar *)icon_argb, icon_n); + } + xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False); XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32, PropModeReplace, (uchar *)&thispid, 1); @@ -1712,13 +1751,28 @@ xsetenv(void) } void +xseticontitle(char *p) +{ + XTextProperty prop; + DEFAULT(p, opt_title); + + 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); +} + +void 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); @@ -2241,9 +2295,9 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) XrmValue ret; snprintf(fullname, sizeof(fullname), "%s.%s", - opt_name ? opt_name : "st", name); + opt_name ? opt_name : termname, name); snprintf(fullclass, sizeof(fullclass), "%s.%s", - opt_class ? opt_class : "St", name); + opt_class ? opt_class : termname, name); fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0'; XrmGetResource(db, fullname, fullclass, &type, &ret);