]> Skullheadx's Git Forge - surf.git/commitdiff
Improve non-ASCII character search handling
authorQuentin Rameau <quinq@fifth.space>
Mon, 19 Jul 2021 19:23:32 +0000 (21:23 +0200)
committerQuentin Rameau <quinq@fifth.space>
Mon, 19 Jul 2021 20:27:50 +0000 (22:27 +0200)
Before, the XA_STRING would only let use ASCII characters properly.
Now UTF-8 characters should be handled correctly.

config.def.h
surf.c

index 3a417f01c96f86dfb11a863cbb171ffa018f618c..1355ba3d44d6e2217c31c8353a9b4fef8371add7 100644 (file)
@@ -68,10 +68,10 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
 #define SETPROP(r, s, p) { \
         .v = (const char *[]){ "/bin/sh", "-c", \
              "prop=\"$(printf '%b' \"$(xprop -id $1 "r" " \
-             "| sed -e 's/^"r"(STRING) = \"\\(.*\\)\"/\\1/' " \
+             "| sed -e 's/^"r"(UTF8_STRING) = \"\\(.*\\)\"/\\1/' " \
              "      -e 's/\\\\\\(.\\)/\\1/g')\" " \
              "| dmenu -p '"p"' -w $1)\" " \
-             "&& xprop -id $1 -f "s" 8s -set "s" \"$prop\"", \
+             "&& xprop -id $1 -f "s" 8u -set "s" \"$prop\"", \
              "surf-setprop", winid, NULL \
         } \
 }
diff --git a/surf.c b/surf.c
index c25def77e2a78cec29e4ad8cb90552e89ed4909d..03d824228b1ea01340eaf982cec50155a0b40436 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -37,7 +37,7 @@
 #define LENGTH(x)               (sizeof(x) / sizeof(x[0]))
 #define CLEANMASK(mask)         (mask & (MODKEY|GDK_SHIFT_MASK))
 
-enum { AtomFind, AtomGo, AtomUri, AtomLast };
+enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast };
 
 enum {
        OnDoc   = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
@@ -339,6 +339,7 @@ setup(void)
        atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
        atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
        atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
+       atoms[AtomUTF8] = XInternAtom(dpy, "UTF8_STRING", False);
 
        gtk_init(NULL, NULL);
 
@@ -608,7 +609,7 @@ void
 setatom(Client *c, int a, const char *v)
 {
        XChangeProperty(dpy, c->xid,
-                       atoms[a], XA_STRING, 8, PropModeReplace,
+                       atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
                        (unsigned char *)v, strlen(v) + 1);
        XSync(dpy, False);
 }
@@ -623,7 +624,8 @@ getatom(Client *c, int a)
        unsigned char *p = NULL;
 
        XSync(dpy, False);
-       XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
+       XGetWindowProperty(dpy, c->xid,
+                          atoms[a], 0L, BUFSIZ, False, atoms[AtomUTF8],
                           &adummy, &idummy, &ldummy, &ldummy, &p);
        if (p)
                strncpy(buf, (char *)p, LENGTH(buf) - 1);