[2010-02-23 10:06] Sean Whitton <s...@silentflame.com>
> 
> [...] I am
> considering switching to surf.  I tried modifying config.h to remove the
> need to hit a modifier (control by default) before every command: it
> seems to me to make more sense to just be able to scroll with j and k
> without having to hold down another key.
> 
> But of course, as I quickly discovered, this doesn't work, as one then
> loses the ability to type j and k into text boxes, which is pretty dire.

I used surf for several weeks last year. I had the same problem, so I
hacked a mode interface like vi has. It is just a quick hack, it is
outdated, and I don't use it anymore, but maybe it helps.

See attached diff which is against:

changeset:   153:d841cfabc257
date:        Wed Oct 21 15:52:36 2009 +0200

The patch also removes function calls that were not provided by my
older webkit version. I'm sure you can figure out what the relevant
parts are.


meillo
diff -r d841cfabc257 surf.c
--- a/surf.c	Wed Oct 21 15:52:36 2009 +0200
+++ b/surf.c	Tue Feb 23 13:58:01 2010 +0100
@@ -65,7 +65,9 @@
 static char winid[64];
 static char *progname;
 static gboolean lockcookie = FALSE;
+static gboolean insert_mode = FALSE;
 
+static void insert(Client *c, const Arg *arg);
 static char *buildpath(const char *path);
 static void changecookie(SoupCookieJar *jar, SoupCookie *o, SoupCookie *n, gpointer p);
 static void cleanup(void);
@@ -94,7 +96,6 @@
 static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c);
 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
-static void print(Client *c, const Arg *arg);
 static void progresschange(WebKitWebView *v, gint p, Client *c);
 static void reloadcookies();
 static void reload(Client *c, const Arg *arg);
@@ -105,7 +106,6 @@
 static void spawn(Client *c, const Arg *arg);
 static void scroll(Client *c, const Arg *arg);
 static void find(Client *c, const Arg *arg);
-static void source(Client *c, const Arg *arg);
 static void stop(Client *c, const Arg *arg);
 static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
 static void usage(void);
@@ -232,7 +232,8 @@
 }
 
 gboolean
-decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c) {
+decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r,
+             WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c) {
 	Arg arg;
 
 	if(webkit_web_navigation_action_get_reason(n) == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
@@ -359,21 +360,59 @@
 			items[i].func(c, &(items[i].arg));
 }
 
+
+void
+insert(Client *c, const Arg *arg) {
+	insert_mode = TRUE;
+	update(clients);
+}
+
+
 gboolean
 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
 	guint i;
 	gboolean processed = FALSE;
 
 	updatewinid(c);
+
+	if (ev->type   != GDK_KEY_PRESS ||
+		ev->keyval == GDK_Return   ||
+		ev->keyval == GDK_Page_Up   ||
+		ev->keyval == GDK_Page_Down ||
+		ev->keyval == GDK_Up		||
+		ev->keyval == GDK_Down	  ||
+		ev->keyval == GDK_Left	  ||
+		ev->keyval == GDK_Right	 ||
+		ev->keyval == GDK_Shift_L   ||
+		ev->keyval == GDK_Shift_R)
+		return FALSE;
+
+	/* turn off insert mode */
+	if (insert_mode && (ev->keyval == GDK_Escape)) {
+		insert_mode = FALSE;
+		update(c);
+		return TRUE;
+	}
+	
+	if (insert_mode && ( ((ev->state & MODKEY) != MODKEY) || !MODKEY ) ) {
+		return FALSE;
+	}
+
+	if (ev->keyval == GDK_Escape) {
+		webkit_web_view_set_highlight_text_matches(c->view, FALSE);
+		//return TRUE;
+	}
+
 	for(i = 0; i < LENGTH(keys); i++) {
-		if(gdk_keyval_to_lower(ev->keyval) == keys[i].keyval
-				&& CLEANMASK(ev->state) == keys[i].mod
+		if(ev->keyval == keys[i].keyval
+				//&& CLEANMASK(ev->state) == keys[i].mod
 				&& keys[i].func) {
 			keys[i].func(c, &(keys[i].arg));
 			processed = TRUE;
 		}
 	}
-	return processed;
+	//return processed;
+	return TRUE;
 }
 
 void
@@ -407,6 +446,8 @@
 	u = g_strrstr(uri, "://") ? g_strdup(uri)
 		: g_strdup_printf("http://%s";, uri);
 	webkit_web_view_load_uri(c->view, u);
+	printf("uri %s\n", u);
+	fflush(stdout);
 	c->progress = 0;
 	c->title = copystr(&c->title, u);
 	g_free(u);
@@ -475,7 +516,7 @@
 
 	/* indicator */
 	c->indicator = gtk_drawing_area_new();
-	gtk_widget_set_size_request(c->indicator, 0, 2);
+	gtk_widget_set_size_request(c->indicator, 0, 5);
 	g_signal_connect (G_OBJECT (c->indicator), "expose_event",
 			G_CALLBACK (exposeindicator), c);
 
@@ -506,7 +547,7 @@
 	setatom(c, findprop, "");
 
 	c->download = NULL;
-	c->title = NULL;
+	c->title = copystr(&c->title, "<surf-"VERSION">");
 	c->next = clients;
 	clients = c;
 	if(showxid) {
@@ -514,6 +555,7 @@
 		printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
 		fflush(NULL);
 	}
+	update(c);
 	return c;
 }
 
@@ -580,11 +622,6 @@
 }
 
 void
-print(Client *c, const Arg *arg) {
-	webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
-}
-
-void
 progresschange(WebKitWebView *v, gint p, Client *c) {
 	c->progress = p;
 	update(c);
@@ -688,22 +725,15 @@
 }
 
 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);
-}
-
-void
 find(Client *c, const Arg *arg) {
 	const char *s;
 
 	s = getatom(c, findprop);
 	gboolean forward = *(gboolean *)arg;
+	webkit_web_view_unmark_text_matches(c->view);
 	webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE);
+	webkit_web_view_mark_text_matches(c->view, s, FALSE, 0);
+	webkit_web_view_set_highlight_text_matches(c->view, TRUE);
 }
 
 void
@@ -744,12 +774,10 @@
 update(Client *c) {
 	char *t;
 
-	if(c->progress != 100)
-		t = g_strdup_printf("%s [%i%%]", c->title, c->progress);
-	else if(c->linkhover)
+	if(c->linkhover)
 		t = g_strdup(c->linkhover);
 	else
-		t = g_strdup(c->title);
+		t = g_strdup_printf("%s%s", (insert_mode?"[INSERT] ":""), c->title);
 	drawindicator(c);
 	gtk_window_set_title(GTK_WINDOW(c->win), t);
 	g_free(t);
@@ -808,7 +836,7 @@
 			break;
 		}
 		else if(!strcmp(argv[i], "-v"))
-			die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
+			die("surf-"VERSION", (c) 2009 surf engineers, see LICENSE for details\n");
 		else
 			usage();
 	}

Reply via email to