Hi, I made a patch for surf today for integrating dmenu as a bookmark menu. You just have to make a file called "bookmarks" in the ~/.surf/ directory contening urls (one url per line).
The keyboard shortcut is Ctrl + m. NOTE: i'm a beginner in C, so you can report me everything i can do to improve the patch and made it sucking less! Hope you enjoy it. -- Julien Pecqueur (JPEC) Site: http://julienpecqueur.com Email: [email protected] PGP: B1AA2389 (GNUPG) IRC: jpec (irc.freenode.net - #archlinux-fr) Powered by Archlinux - Keep it simple stupid !
diff -r 7786b245532f surf.c
--- a/surf.c Fri Jun 12 13:41:09 2009 +0100
+++ b/surf.c Wed Aug 26 21:55:25 2009 +0200
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <webkit/webkit.h>
#include <glib/gstdio.h>
+#include <glib/gfileutils.h>
#define LENGTH(x) (sizeof x / sizeof x[0])
@@ -35,6 +36,8 @@
gboolean ignore_once = FALSE;
extern char *optarg;
extern int optind;
+gchar *bookmarks;
+static gchar *DMENU = "/usr/bin/dmenu -fn -*-*-medium-*-*-*-14-*-*-*-*-*-*-*";
static void cleanup(void);
static void destroyclient(Client *c);
@@ -51,6 +54,7 @@
static void loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c);
static void loadfile(Client *c, const gchar *f);
static void loaduri(Client *c, const gchar *uri);
+static void loadbookmark(Client *c);
static Client *newclient();
static WebKitWebView *newwindow(WebKitWebView *v, WebKitWebFrame *f, Client
*c);
static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
@@ -214,6 +218,9 @@
case GDK_g:
showurl(c);
return TRUE;
+ case GDK_m:
+ loadbookmark(c);
+ return TRUE;
case GDK_slash:
showsearch(c);
return TRUE;
@@ -320,6 +327,40 @@
g_free(u);
}
+void
+loadbookmark(Client *c) {
+ gchar *bookmarks_list, *dmenu_out, *title, *command;
+ if (g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
+ {
+ /* Read bookmarks file */
+ title = g_strdup("Loading bookmarks...");
+ updatetitle(c, title);
+ if (g_file_get_contents(bookmarks, &bookmarks_list, NULL, NULL))
+ {
+ /* Call dmenu */
+ command = g_strconcat("/bin/sh -c 'cat ", bookmarks, " | ", DMENU,
"'", NULL);
+ if(g_spawn_command_line_sync(command, &dmenu_out, NULL, NULL, NULL))
+ {
+ loaduri(c, dmenu_out);
+ }
+ else
+ {
+ printf("Error: please check if dmenu is correctly installed.");
+ return;
+ }
+ }
+ }
+ else
+ {
+ printf("I can't find the bookmarks file: %s\n", bookmarks);
+ return;
+ }
+ g_free(bookmarks_list);
+ g_free(dmenu_out);
+ g_free(command);
+ g_free(title);
+}
+
Client *
newclient(void) {
Client *c;
@@ -550,6 +591,10 @@
filename = g_build_filename(home, ".surf", "cookies", NULL);
cookiejar = soup_cookie_jar_text_new(filename, FALSE);
soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+
+ /* bookmarks file */
+ bookmarks = g_build_filename(home, ".surf", "bookmarks", NULL);
+
gtk_main();
cleanup();
pgpKRk7s96zPX.pgp
Description: PGP signature
