Fix synchronization issue with atoms
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 2003b79..2d3a6f5 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -530,10 +530,10 @@ geturi(Client *c)
 void
 setatom(Client *c, int a, const char *v)
 {
-       XSync(dpy, False);
        XChangeProperty(dpy, c->xid,
                        atoms[a], XA_STRING, 8, PropModeReplace,
                        (unsigned char *)v, strlen(v) + 1);
+       XSync(dpy, False);
 }
 
 const char *
@@ -545,6 +545,7 @@ getatom(Client *c, int a)
        unsigned long ldummy;
        unsigned char *p = NULL;
 
+       XSync(dpy, False);
        XGetWindowProperty(dpy, c->xid, atoms[a], 0L, BUFSIZ, False, XA_STRING,
                           &adummy, &idummy, &ldummy, &ldummy, &p);
        if (p)
@@ -1375,23 +1376,23 @@ loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
 void
 loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
 {
-       const char *title = geturi(c);
+       const char *uri = geturi(c);
 
        switch (e) {
        case WEBKIT_LOAD_STARTED:
-               setatom(c, AtomUri, title);
-               c->title = title;
+               setatom(c, AtomUri, uri);
+               c->title = uri;
                c->https = c->insecure = 0;
-               seturiparameters(c, geturi(c));
+               seturiparameters(c, uri);
                if (c->errorpage)
                        c->errorpage = 0;
                else
                        g_clear_object(&c->failedcert);
                break;
        case WEBKIT_LOAD_REDIRECTED:
-               setatom(c, AtomUri, title);
-               c->title = title;
-               seturiparameters(c, geturi(c));
+               setatom(c, AtomUri, uri);
+               c->title = uri;
+               seturiparameters(c, uri);
                break;
        case WEBKIT_LOAD_COMMITTED:
                c->https = webkit_web_view_get_tls_info(c->view, &c->cert,