X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=0d7037ad09a1436f02a0694160c93c688058690c;hb=566b452b46a171a4426256cdb02704ae8351a2b3;hp=dd9c3063987e373ac9d29756de334b41ab53f79b;hpb=2223e9ed2264cf1203865b7a0548e0724c89e527;p=surf.git diff --git a/surf.c b/surf.c index dd9c306..0d7037a 100644 --- a/surf.c +++ b/surf.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ union Arg { typedef struct Client { GtkWidget *win, *scroll, *vbox, *pane; + Window xid; WebKitWebView *view; WebKitWebInspector *inspector; char *title, *linkhover; @@ -99,7 +101,7 @@ typedef struct { static Display *dpy; static Atom atoms[AtomLast]; static Client *clients = NULL; -static GdkNativeWindow embed = 0; +static Window embed = 0; static gboolean showxid = FALSE; static char winid[64]; static gboolean usingproxy = 0; @@ -273,6 +275,7 @@ buildfile(const char *path) g_free(dname); fpath = g_build_filename(bpath, bname, NULL); + g_free(bpath); g_free(bname); if (!(f = fopen(fpath, "a"))) @@ -624,9 +627,9 @@ getatom(Client *c, int a) unsigned long ldummy; unsigned char *p = NULL; - XGetWindowProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), - atoms[a], 0L, BUFSIZ, False, XA_STRING, - &adummy, &idummy, &ldummy, &ldummy, &p); + XGetWindowProperty(dpy, c->xid, + atoms[a], 0L, BUFSIZ, False, XA_STRING, + &adummy, &idummy, &ldummy, &ldummy, &p); if (p) strncpy(buf, (char *)p, LENGTH(buf)-1); else @@ -803,7 +806,7 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) } setatom(c, AtomUri, uri); - if (enablestyles) + if (enablestyle) setstyle(c, getstyle(uri)); break; case WEBKIT_LOAD_FINISHED: @@ -869,6 +872,7 @@ newclient(void) WebKitWebFrame *frame; GdkGeometry hints = { 1, 1 }; GdkScreen *screen; + GdkWindow *gwin; gdouble dpi; char *ua; @@ -910,10 +914,10 @@ newclient(void) addaccelgroup(c); /* Pane */ - c->pane = gtk_vpaned_new(); + c->pane = gtk_paned_new(GTK_ORIENTATION_VERTICAL); /* VBox */ - c->vbox = gtk_vbox_new(FALSE, 0); + c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_paned_pack1(GTK_PANED(c->pane), c->vbox, TRUE, TRUE); /* Webview */ @@ -993,10 +997,12 @@ newclient(void) gtk_widget_show(c->scroll); gtk_widget_show(GTK_WIDGET(c->view)); gtk_widget_show(c->win); + gwin = gtk_widget_get_window(GTK_WIDGET(c->win)); + c->xid = gdk_x11_window_get_xid(gwin); gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, - GDK_HINT_MIN_SIZE); - gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); - gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); + GDK_HINT_MIN_SIZE); + gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK); + gdk_window_add_filter(gwin, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); runscript(frame); @@ -1021,7 +1027,7 @@ newclient(void) "default-font-size", defaultfontsize, NULL); g_object_set(G_OBJECT(settings), "resizable-text-areas", 1, NULL); - if (enablestyles) + if (enablestyle) setstyle(c, getstyle("about:blank")); /* @@ -1030,7 +1036,7 @@ newclient(void) * It is equivalent to firefox's "layout.css.devPixelsPerPx" setting. */ if (zoomto96dpi) { - screen = gdk_window_get_screen(GTK_WIDGET(c->win)->window); + screen = gdk_window_get_screen(gwin); dpi = gdk_screen_get_resolution(screen); if (dpi != -1) { g_object_set(G_OBJECT(settings), @@ -1068,8 +1074,7 @@ newclient(void) if (showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); - printf("%u\n", - (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); + printf("%lu\n", c->xid); fflush(NULL); if (fclose(stdout) != 0) { die("Error closing stdout"); @@ -1149,15 +1154,13 @@ menuactivate(GtkMenuItem *item, Client *c) * context-menu-action-12 stop */ - GtkAction *a = NULL; - const char *name, *uri; + const gchar *name, *uri; GtkClipboard *prisel, *clpbrd; - a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(item)); - if (a == NULL) + name = gtk_actionable_get_action_name(GTK_ACTIONABLE(item)); + if (name == NULL) return; - name = gtk_action_get_name(a); if (!g_strcmp0(name, "context-menu-action-3")) { prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); gtk_clipboard_set_text(prisel, c->linkhover, -1); @@ -1280,9 +1283,9 @@ void setatom(Client *c, int a, const char *v) { XSync(dpy, False); - XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), - atoms[a], XA_STRING, 8, PropModeReplace, - (unsigned char *)v, strlen(v) + 1); + XChangeProperty(dpy, c->xid, + atoms[a], XA_STRING, 8, PropModeReplace, + (unsigned char *)v, strlen(v) + 1); } void @@ -1299,7 +1302,7 @@ setup(void) sigchld(0); gtk_init(NULL, NULL); - dpy = GDK_DISPLAY(); + dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); /* atoms */ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); @@ -1534,8 +1537,8 @@ togglescrollbars(Client *c, const Arg *arg) void togglestyle(Client *c, const Arg *arg) { - enablestyles = !enablestyles; - setstyle(c, enablestyles ? getstyle(geturi(c)) : ""); + enablestyle = !enablestyle; + setstyle(c, enablestyle ? getstyle(geturi(c)) : ""); updatetitle(c); } @@ -1566,7 +1569,7 @@ gettogglestat(Client *c) g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL); togglestat[p++] = value? 'V': 'v'; - togglestat[p++] = enablestyles ? 'M': 'm'; + togglestat[p++] = enablestyle ? 'M': 'm'; togglestat[p] = '\0'; } @@ -1617,8 +1620,7 @@ updatetitle(Client *c) void updatewinid(Client *c) { - snprintf(winid, LENGTH(winid), "%u", - (int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); + snprintf(winid, LENGTH(winid), "%lu", c->xid); } void @@ -1709,10 +1711,10 @@ main(int argc, char *argv[]) kioskmode = 1; break; case 'm': - enablestyles = 0; + enablestyle = 0; break; case 'M': - enablestyles = 1; + enablestyle = 1; break; case 'n': enableinspector = 0;