X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=d6d644df44ba1744fe2ec6df71a8bc8fd3d7b35f;hb=bb1fc4195f4fa3be5625d0f663e537a22ccf1877;hp=7f859f91808944ca66c7c368fc3ac81ca239ff3f;hpb=04d46d1791f1ff3b82a665fbc5b574f4e2a70c97;p=surf.git diff --git a/surf.c b/surf.c index 7f859f9..d6d644d 100644 --- a/surf.c +++ b/surf.c @@ -120,6 +120,7 @@ static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d, static void decidenavigation(WebKitPolicyDecision *d, Client *c); static void decidenewwindow(WebKitPolicyDecision *d, Client *c); static void decideresource(WebKitPolicyDecision *d, Client *c); +static void closeview(WebKitWebView *v, Client *c); static void destroyclient(Client *c); static void destroywin(GtkWidget* w, Client *c); static void die(const char *errstr, ...); @@ -160,6 +161,7 @@ static Client *newclient(Client *c); static WebKitWebView *newview(Client *c, WebKitWebView *rv); static void showview(WebKitWebView *v, Client *c); static void newwindow(Client *c, const Arg *arg, gboolean noembed); +static GtkWidget *createwindow(Client *c); static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); static void print(Client *c, const Arg *arg); static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, @@ -551,10 +553,9 @@ destroyclient(Client *c) Client *p; webkit_web_view_stop_loading(c->view); - gtk_widget_destroy(GTK_WIDGET(c->view)); - gtk_widget_destroy(c->scroll); - gtk_widget_destroy(c->vbox); + /* Not needed, has already been called gtk_widget_destroy(c->win); + */ for (p = clients; p && p->next != c; p = p->next) ; @@ -563,14 +564,20 @@ destroyclient(Client *c) else clients = c->next; free(c); - if (clients == NULL) - gtk_main_quit(); +} + +void +closeview(WebKitWebView *v, Client *c) +{ + gtk_widget_destroy(c->win); } void destroywin(GtkWidget* w, Client *c) { destroyclient(c); + if (clients == NULL) + gtk_main_quit(); } void @@ -998,6 +1005,8 @@ newview(Client *c, WebKitWebView *rv) g_signal_connect(G_OBJECT(v), "button-release-event", G_CALLBACK(buttonreleased), c); + g_signal_connect(G_OBJECT(v), "close", + G_CALLBACK(closeview), c); return v; } @@ -1009,33 +1018,7 @@ showview(WebKitWebView *v, Client *c) GdkRGBA bgcolor = { 0 }; GdkWindow *gwin; - /* Window */ - if (embed) { - c->win = gtk_plug_new(embed); - } else { - c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - /* TA: 20091214: Despite what the GNOME docs say, the ICCCM - * is always correct, so we should still call this function. - * But when doing so, we *must* differentiate between a - * WM_CLASS and a resource on the window. By convention, the - * window class (WM_CLASS) is capped, while the resource is in - * lowercase. Both these values come as a pair. - */ - gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "Surf"); - - /* TA: 20091214: And set the role here as well -- so that - * sessions can pick this up. - */ - gtk_window_set_role(GTK_WINDOW(c->win), "Surf"); - } - gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600); - g_signal_connect(G_OBJECT(c->win), - "destroy", - G_CALLBACK(destroywin), c); - g_signal_connect(G_OBJECT(c->win), - "leave_notify_event", - G_CALLBACK(titlechangeleave), c); + c->win = createwindow(c); if (!kioskmode) addaccelgroup(c); @@ -1120,6 +1103,41 @@ newwindow(Client *c, const Arg *arg, gboolean noembed) spawn(NULL, &a); } +GtkWidget * +createwindow(Client *c) +{ + GtkWidget *w; + + if (embed) { + w = gtk_plug_new(embed); + } else { + w = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + /* TA: 20091214: Despite what the GNOME docs say, the ICCCM + * is always correct, so we should still call this function. + * But when doing so, we *must* differentiate between a + * WM_CLASS and a resource on the window. By convention, the + * window class (WM_CLASS) is capped, while the resource is in + * lowercase. Both these values come as a pair. + */ + gtk_window_set_wmclass(GTK_WINDOW(w), "surf", "Surf"); + + /* TA: 20091214: And set the role here as well -- so that + * sessions can pick this up. + */ + gtk_window_set_role(GTK_WINDOW(w), "Surf"); + + gtk_window_set_default_size(GTK_WINDOW(w), 800, 600); + } + + g_signal_connect(G_OBJECT(w), "destroy", + G_CALLBACK(destroywin), c); + g_signal_connect(G_OBJECT(w), "leave_notify_event", + G_CALLBACK(titlechangeleave), c); + + return w; +} + void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {