]> git.armaanb.net Git - st.git/blobdiff - x.c
fix: correctly encode mouse buttons >= 8 in X10 and SGR mode
[st.git] / x.c
diff --git a/x.c b/x.c
index cbbd11f0c407dadb615f8ba10ce46a92e9312c7f..8bf998e1dedb7ad592a03b985db2e606f9523ec9 100644 (file)
--- 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;
@@ -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) {
@@ -1186,6 +1188,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);
@@ -1526,8 +1529,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
        /* draw the new one */
        if (IS_SET(MODE_FOCUSED)) {
                switch (win.cursor) {
-               case 7: /* st extension: snowman (U+2603) */
-                       g.u = 0x2603;
+               case 7: /* st extension */
+                       g.u = 0x2603; /* snowman (U+2603) */
+                       /* FALLTHROUGH */
                case 0: /* Blinking Block */
                case 1: /* Blinking Block (Default) */
                case 2: /* Steady Block */
@@ -1578,6 +1582,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)
 {
@@ -1689,8 +1706,7 @@ xsetmode(int set, unsigned int flags)
 int
 xsetcursor(int cursor)
 {
-       DEFAULT(cursor, 1);
-       if (!BETWEEN(cursor, 0, 6))
+       if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
                return 1;
        win.cursor = cursor;
        return 0;
@@ -1927,7 +1943,7 @@ run(void)
                 * triggers drawing, we first wait a bit to ensure we got
                 * everything, and if nothing new arrives - we draw.
                 * We start with trying to wait minlatency ms. If more content
-                * arrives sooner, we retry with shorter and shorter preiods,
+                * arrives sooner, we retry with shorter and shorter periods,
                 * and eventually draw even without idle after maxlatency ms.
                 * Typically this results in low latency while interacting,
                 * maximum latency intervals during `cat huge.txt`, and perfect
@@ -1982,7 +1998,7 @@ main(int argc, char *argv[])
 {
        xw.l = xw.t = 0;
        xw.isfixed = False;
-       win.cursor = cursorshape;
+       xsetcursor(cursorshape);
 
        ARGBEGIN {
        case 'a':