]> Sergey Matveev's repositories - st.git/commitdiff
My config master
authorSergey Matveev <stargrave@stargrave.org>
Sat, 23 May 2020 11:17:54 +0000 (14:17 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 14 Apr 2025 09:39:37 +0000 (12:39 +0300)
Makefile
config.def.h
list-emojis [new file with mode: 0755]
list-emojis.pl [new file with mode: 0755]
st.c
x.c

index 15db421c0e7b56e9196353ffc5b75f8ef1ba7194..2dd11d6d2ae9118f573c1d86b02268172d447b9c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ config.h:
        cp config.def.h config.h
 
 .c.o:
-       $(CC) $(STCFLAGS) -c $<
+       $(CC) -O3 $(STCFLAGS) -c $<
 
 st.o: config.h st.h win.h
 x.o: arg.h config.h st.h win.h
@@ -21,7 +21,7 @@ x.o: arg.h config.h st.h win.h
 $(OBJ): config.h config.mk
 
 st: $(OBJ)
-       $(CC) -o $@ $(OBJ) $(STLDFLAGS)
+       $(CC) -s -o $@ $(OBJ) $(STLDFLAGS)
 
 clean:
        rm -f st $(OBJ) st-$(VERSION).tar.gz
index a5672a307c6e9a8f4642ec6db02615c88a490037..e5375d2b56ed2279b301a9d8201c893a6ca4d052 100644 (file)
@@ -7,7 +7,7 @@
  *
  * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
  */
-static char *font = "Go Mono:size=14:antialias=true";
+static char *font = "Go Mono:size=15:antialias=true";
 static int borderpx = 0;
 
 /*
@@ -36,7 +36,7 @@ static float chscale = 1.0;
  *
  * More advanced example: L" `'\"()[]{}"
  */
-wchar_t *worddelimiters = L" ·→│»« ";
+wchar_t *worddelimiters = L" ·→│»« <>";
 
 /* selection timeouts (in milliseconds) */
 static unsigned int doubleclicktimeout = 300;
diff --git a/list-emojis b/list-emojis
new file mode 100755 (executable)
index 0000000..c2aace0
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh -e
+
+echo "static const uint32_t emojis[] = {";
+./list-emojis.pl <data/emoji-data.txt | grep -v 0x0000 | sort | uniq
+echo "};"
diff --git a/list-emojis.pl b/list-emojis.pl
new file mode 100755 (executable)
index 0000000..daad7e9
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+while (<>) {
+    next if /^#/ or /^$/;
+    my @range = split " ";
+    @range = split /\.\./, $range[0];
+    my $i = hex $range[0];
+    my $end = ($#range > 0) ? hex($range[1]) : $i;
+    for (; $i <= $end; $i++) {
+        printf "\t0x%06x,\n", $i;
+    };
+};
diff --git a/st.c b/st.c
index b9f66e71163f0707bb477f9fa5346f5dad27683d..db0fee4ca963c923f2c6b756b209a26feed0ffbc 100644 (file)
--- a/st.c
+++ b/st.c
@@ -4,11 +4,12 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <pwd.h>
+#include <signal.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <signal.h>
 #include <sys/ioctl.h>
 #include <sys/select.h>
 #include <sys/types.h>
@@ -339,10 +340,31 @@ utf8encodebyte(Rune u, size_t i)
        return utfbyte[i] | (u & ~utfmask[i]);
 }
 
+// ./list-emojis <libgrapheme/data/emoji-data.txt >emojis.c.in
+#include "emojis.c.in"
+
+static int
+uint32comparator(const void *a, const void *b)
+{
+    return *(uint32_t *)a - *(uint32_t *)b;
+}
+
+int
+isEmoji(const Rune u)
+{
+    const uint32_t want = (uint32_t)u;
+    return bsearch(
+        &want,
+        emojis,
+        (sizeof emojis)/sizeof(uint32_t),
+        sizeof(uint32_t),
+        uint32comparator) != NULL;
+}
+
 size_t
 utf8validate(Rune *u, size_t i)
 {
-       if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
+       if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF) || isEmoji(*u))
                *u = UTF_INVALID;
        for (i = 1; *u > utfmax[i]; ++i)
                ;
@@ -1132,6 +1154,7 @@ csiparse(void)
 {
        char *p = csiescseq.buf, *np;
        long int v;
+       int sep = ';'; /* colon or semi-colon, but not both */
 
        csiescseq.narg = 0;
        if (*p == '?') {
@@ -1149,7 +1172,9 @@ csiparse(void)
                        v = -1;
                csiescseq.arg[csiescseq.narg++] = v;
                p = np;
-               if (*p != ';' || csiescseq.narg == ESC_ARG_SIZ)
+               if (sep == ';' && *p == ':')
+                       sep = ':'; /* allow override to colon once */
+               if (*p != sep || csiescseq.narg == ESC_ARG_SIZ)
                        break;
                p++;
        }
@@ -1702,7 +1727,7 @@ csihandle(void)
                        }
                        break;
                case 1: /* above */
-                       if (term.c.y > 1)
+                       if (term.c.y > 0)
                                tclearregion(0, 0, term.col-1, term.c.y-1);
                        tclearregion(0, term.c.y, term.c.x, term.c.y);
                        break;
@@ -1798,7 +1823,11 @@ csihandle(void)
                tcursor(CURSOR_SAVE);
                break;
        case 'u': /* DECRC -- Restore cursor position (ANSI.SYS) */
-               tcursor(CURSOR_LOAD);
+               if (csiescseq.priv) {
+                       goto unknown;
+               } else {
+                       tcursor(CURSOR_LOAD);
+               }
                break;
        case ' ':
                switch (csiescseq.mode[1]) {
diff --git a/x.c b/x.c
index b85161f0811cfe7166752e0ff13d5b1655faaa1a..732ab225924f25d18cb671b516421b8487dcb374 100644 (file)
--- a/x.c
+++ b/x.c
@@ -1132,7 +1132,7 @@ xinit(int cols, int rows)
 {
        XGCValues gcvalues;
        Cursor cursor;
-       Window parent;
+       Window parent, root;
        pid_t thispid = getpid();
        XColor xmousefg, xmousebg;
 
@@ -1169,16 +1169,19 @@ xinit(int cols, int rows)
                | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
        xw.attrs.colormap = xw.cmap;
 
+       root = XRootWindow(xw.dpy, xw.scr);
        if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
-               parent = XRootWindow(xw.dpy, xw.scr);
-       xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
+               parent = root;
+       xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t,
                        win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
                        xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
                        | CWEventMask | CWColormap, &xw.attrs);
+       if (parent != root)
+               XReparentWindow(xw.dpy, xw.win, parent, xw.l, xw.t);
 
        memset(&gcvalues, 0, sizeof(gcvalues));
        gcvalues.graphics_exposures = False;
-       dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
+       dc.gc = XCreateGC(xw.dpy, xw.win, GCGraphicsExposures,
                        &gcvalues);
        xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
                        DefaultDepth(xw.dpy, xw.scr));
@@ -1197,24 +1200,6 @@ xinit(int cols, int rows)
                                               ximinstantiate, NULL);
        }
 
-       /* white cursor, black outline */
-       cursor = XCreateFontCursor(xw.dpy, mouseshape);
-       XDefineCursor(xw.dpy, xw.win, cursor);
-
-       if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
-               xmousefg.red   = 0xffff;
-               xmousefg.green = 0xffff;
-               xmousefg.blue  = 0xffff;
-       }
-
-       if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) {
-               xmousebg.red   = 0x0000;
-               xmousebg.green = 0x0000;
-               xmousebg.blue  = 0x0000;
-       }
-
-       XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
-
        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);