[PATCH] Replace source view with inspector

From: Gregor Best <gbe_AT_ring0.de>
Date: Tue, 22 Jan 2013 21:41:38 +0100

Signed-off-by: Gregor Best <gbe_AT_ring0.de>
---
 config.def.h |  2 +-
 config.mk    |  2 +-
 surf.c       | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/config.def.h b/config.def.h
index 663e532..ddfafc3 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -68,7 +68,7 @@ static Key keys[] = {
 
     { 0,                    GDK_F11,    fullscreen, { 0 } },
     { 0,                    GDK_Escape, stop,       { 0 } },
-    { MODKEY,               GDK_o,      source,     { 0 } },
+    { MODKEY,               GDK_o,      inspector_show,     { 0 } },
 
     { MODKEY,               GDK_g,      spawn,      SETPROP("_SURF_URI", "_SURF_GO") },
     { MODKEY,               GDK_f,      spawn,      SETPROP("_SURF_FIND", "_SURF_FIND") },
diff --git a/config.mk b/config.mk
index ee05292..a6a9149 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -20,7 +20,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${GTKLIB} -lgthread-2.0 \
 
 # flags
 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE
-CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
+CFLAGS = -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS = -g ${LIBS}
 
 # Solaris
diff --git a/surf.c b/surf.c
index 899ab04..1800203 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -41,6 +41,8 @@ union Arg {
 typedef struct Client {
 	GtkWidget *win, *scroll, *vbox, *indicator;
 	WebKitWebView *view;
+	WebKitWebInspector *inspector;
+	gboolean is_inspector;
 	char *title, *linkhover;
 	const char *uri, *needle;
 	gint progress;
_AT_@ -139,7 +141,6 @@ static void scroll(GtkAdjustment *a, const Arg *arg);
 static void setatom(Client *c, int a, const char *v);
 static void setup(void);
 static void sigchld(int unused);
-static void source(Client *c, const Arg *arg);
 static void spawn(Client *c, const Arg *arg);
 static void eval(Client *c, const Arg *arg);
 static void stop(Client *c, const Arg *arg);
_AT_@ -153,6 +154,12 @@ static void usage(void);
 static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame,
 		JSContextRef js, JSObjectRef win, Client *c);
 static void zoom(Client *c, const Arg *arg);
+static void inspector_open(Client *c, const Arg *arg);
+
+static WebKitWebView *inspector_new(WebKitWebInspector *i, WebKitWebView *v, Client *c);
+static gboolean inspector_show(WebKitWebInspector *i, Client *c);
+static gboolean inspector_close(WebKitWebInspector *i, Client *c);
+static void inspector_finished(WebKitWebInspector *i, Client *c);
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
_AT_@ -711,6 +718,18 @@ newclient(void) {
 	g_object_set(G_OBJECT(settings), "enable-scripts", enablescripts, NULL);
 	g_object_set(G_OBJECT(settings), "enable-spatial-navigation",
 			spatialbrowsing, NULL);
+	g_object_set(G_OBJECT(settings), "enable-developer-extras", true, NULL);
+
+	c->inspector = WEBKIT_WEB_INSPECTOR(webkit_web_view_get_inspector(c->view));
+	g_signal_connect(G_OBJECT(c->inspector), "inspect-web-view",
+			G_CALLBACK(inspector_new), c);
+	g_signal_connect(G_OBJECT(c->inspector), "show-window",
+			G_CALLBACK(inspector_show), c);
+	g_signal_connect(G_OBJECT(c->inspector), "close-window",
+			G_CALLBACK(inspector_close), c);
+	g_signal_connect(G_OBJECT(c->inspector), "finished",
+			G_CALLBACK(inspector_finished), c);
+	c->is_inspector = false;
 
 	g_free(uri);
 
_AT_@ -953,16 +972,6 @@ sigchld(int unused) {
 }
 
 static void
-source(Client *c, const Arg *arg) {
-	Arg a = { .b = FALSE };
-	gboolean s;
-
-	s = webkit_web_view_get_view_source_mode(c->view);
-	webkit_web_view_set_view_source_mode(c->view, !s);
-	reload(c, &a);
-}
-
-static void
 spawn(Client *c, const Arg *arg) {
 	if(fork() == 0) {
 		if(dpy)
_AT_@ -1086,6 +1095,37 @@ zoom(Client *c, const Arg *arg) {
 	}
 }
 
+WebKitWebView*
+inspector_new(WebKitWebInspector *i, WebKitWebView *v, Client *c) {
+	Client *n = newclient();
+	n->is_inspector = true;
+	return n->view;
+}
+
+gboolean
+inspector_show(WebKitWebInspector *i, Client *c) {
+	gtk_widget_show(GTK_WIDGET(webkit_web_inspector_get_web_view(i)));
+	return true;
+}
+
+gboolean
+inspector_close(WebKitWebInspector *i, Client *c) {
+	gtk_widget_hide(GTK_WIDGET(webkit_web_inspector_get_web_view(i)));
+	return true;
+}
+
+void
+inspector_open(Client *c, const Arg *arg) {
+	if (c->is_inspector)
+		return;
+	webkit_web_inspector_show(c->inspector);
+}
+
+void
+inspector_finished(WebKitWebInspector *i, Client *c) {
+	g_free(c->inspector);
+}
+
 int
 main(int argc, char *argv[]) {
 	Arg arg;
-- 
1.8.0.1
--s2ZSL+KKDSLx8OML--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Jan 22 2013 - 21:48:04 CET