On Wed, Sep 9, 2009 at 5:05 AM, Enno Boland (Gottox)<got...@gmail.com> wrote: > You already can read surfs url by using xprop. This can be used to > write a bookmark managing system. I'm thinking about adding the first > patch but I'm not sure about the to others.
The difficulty with using xprop to read and write surf's URL is that even though I have the XID when the session starts, there's a risk that it changes. Links may open themselves in new windows, or the user might choose to do it with webkit's context menu. It seems uncomfortable to require the user of a bookmark managing system to do some manual step to indicate which window their action applies to, so I chose to let the window initiate the action, as in these patches, which resolves the ambiguity. My (barely considered) plan when loading a URL from bookmarks or history was to just start another instance of surf rather than interacting with an existing one, because of this multiple-window problem. (This also protects me against coredumps in webkit, in sort of a faux-Chrome way, but makes the various race conditions more problematic.) In any case, I don't think my ideas are the best ways to get this functionality - just the best ways I could think of so far. I've regenerated these patches after the last round of changes.
# HG changeset patch # User Ray Kohler <ataraxia...@gmail.com> # Date 1252501698 14400 # Node ID c63f78bf2dbba972846d04bc6298e9dc05c51943 # Parent 991d3036e5e2d98f6f47fae443335ee3cb2d03bf [mq]: config_file_locs diff -r 991d3036e5e2 -r c63f78bf2dbb config.def.h --- a/config.def.h Wed Sep 09 09:06:30 2009 -0400 +++ b/config.def.h Wed Sep 09 09:08:18 2009 -0400 @@ -1,6 +1,14 @@ /* modifier 0 means no modifier */ static gchar *progress = "#FF0000"; static gchar *progress_trust = "#00FF00"; + +/* persistent files and directories */ +/* this one is relative to home directory */ +static const char *surf_dir = ".surf"; +/* these are relative to surf_dir */ +static const char *download_dir = "dl"; +static const char *cookie_file = "cookies"; + #define MODKEY GDK_CONTROL_MASK static Key keys[] = { /* modifier keyval function arg Focus */ diff -r 991d3036e5e2 -r c63f78bf2dbb surf.c --- a/surf.c Wed Sep 09 09:06:30 2009 -0400 +++ b/surf.c Wed Sep 09 09:08:18 2009 -0400 @@ -225,7 +225,7 @@ c->download = o; home = g_get_home_dir(); filename = webkit_download_get_suggested_filename(o); - path = g_build_filename(home, ".surf", "dl", + path = g_build_filename(home, surf_dir, download_dir, filename, NULL); uri = g_strconcat("file://", path, NULL); webkit_download_set_destination_uri(c->download, uri); @@ -526,7 +526,7 @@ const gchar *filename, *home; home = g_get_home_dir(); - filename = g_build_filename(home, ".surf", "cookies", NULL); + filename = g_build_filename(home, surf_dir, cookie_file, NULL); } void @@ -670,12 +670,12 @@ /* make dirs */ home = g_get_home_dir(); - filename = g_build_filename(home, ".surf", "dl", NULL); + filename = g_build_filename(home, surf_dir, download_dir, NULL); g_mkdir_with_parents(filename, 0755); /* cookie persistance */ s = webkit_get_default_session(); - filename = g_build_filename(home, ".surf", "cookies.jar", NULL); + filename = g_build_filename(home, surf_dir, cookie_file, NULL); cookiejar = soup_cookie_jar_text_new(filename, FALSE); soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
# HG changeset patch # User Ray Kohler <ataraxia...@gmail.com> # Date 1252501758 14400 # Node ID 5e7b815f9127c27c1d06a86a889c080a9fabb3b3 # Parent c63f78bf2dbba972846d04bc6298e9dc05c51943 [mq]: write_bookmarks diff -r c63f78bf2dbb -r 5e7b815f9127 config.def.h --- a/config.def.h Wed Sep 09 09:08:18 2009 -0400 +++ b/config.def.h Wed Sep 09 09:09:18 2009 -0400 @@ -8,6 +8,7 @@ /* these are relative to surf_dir */ static const char *download_dir = "dl"; static const char *cookie_file = "cookies"; +static const char *bookmark_file = "bookmarks"; #define MODKEY GDK_CONTROL_MASK static Key keys[] = { @@ -28,6 +29,7 @@ { MODKEY, GDK_h, navigate, { .i = -1 }, BROWSER }, { 0, GDK_Escape, stop, { 0 }, BROWSER }, { MODKEY, GDK_o, source, { 0 }, BROWSER }, + { MODKEY, GDK_B, savebookmark, {0}, BROWSER }, { MODKEY, GDK_n, searchtext, { .b = TRUE }, BROWSER|SEARCHBAR }, { MODKEY, GDK_N, searchtext, { .b = FALSE }, BROWSER|SEARCHBAR }, { 0, GDK_Return, searchtext, { .b = TRUE }, SEARCHBAR }, diff -r c63f78bf2dbb -r 5e7b815f9127 surf.c --- a/surf.c Wed Sep 09 09:08:18 2009 -0400 +++ b/surf.c Wed Sep 09 09:09:18 2009 -0400 @@ -99,6 +99,7 @@ static void request(SoupSession *s, SoupMessage *m, Client *c); static void reload(Client *c, const Arg *arg); static void rereadcookies(); +static void savebookmark(Client *c, const Arg *arg); static void setcookie(char *name, char *val, char *dom, char *path, long exp); static void setup(); static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, @@ -530,6 +531,21 @@ } void +savebookmark(Client *c, const Arg *arg) { + const gchar *uri, *home, *bookmarkpath; + FILE *bookmarkfile; + + uri = geturi(c); + + home = g_get_home_dir(); + bookmarkpath = g_build_filename(home, surf_dir, bookmark_file, NULL); + + bookmarkfile = g_fopen(bookmarkpath, "a"); + fprintf(bookmarkfile, "%s\n", uri); + fclose(bookmarkfile); +} + +void setcookie(char *name, char *val, char *dom, char *path, long exp) { }
# HG changeset patch # User Ray Kohler <ataraxia...@gmail.com> # Date 1252459391 14400 # Node ID bfd6b9370ce3b013db5993c8a49fd47836b12286 # Parent 9bbedc5f48946677ea0a22446fbb8024dd79c3e5 [mq]: config_file_locs diff --git a/config.def.h b/config.def.h --- a/config.def.h +++ b/config.def.h @@ -1,6 +1,14 @@ /* modifier 0 means no modifier */ static gchar *progress = "#FF0000"; static gchar *progress_trust = "#00FF00"; + +/* persistent files and directories */ +/* this one is relative to home directory */ +static const char *surf_dir = ".surf"; +/* these are relative to surf_dir */ +static const char *download_dir = "dl"; +static const char *cookie_file = "cookies"; + #define MODKEY GDK_CONTROL_MASK static Key keys[] = { /* modifier keyval function arg Focus */ diff --git a/surf.c b/surf.c --- a/surf.c +++ b/surf.c @@ -224,7 +224,7 @@ c->download = o; home = g_get_home_dir(); filename = webkit_download_get_suggested_filename(o); - path = g_build_filename(home, ".surf", "dl", + path = g_build_filename(home, surf_dir, download_dir, filename, NULL); uri = g_strconcat("file://", path, NULL); webkit_download_set_destination_uri(c->download, uri); @@ -524,7 +524,7 @@ const gchar *filename, *home; home = g_get_home_dir(); - filename = g_build_filename(home, ".surf", "cookies", NULL); + filename = g_build_filename(home, surf_dir, cookie_file, NULL); } void @@ -658,14 +658,14 @@ /* make dirs */ home = g_get_home_dir(); - filename = g_build_filename(home, ".surf", NULL); + filename = g_build_filename(home, surf_dir, NULL); g_mkdir_with_parents(filename, 0711); - filename = g_build_filename(home, ".surf", "dl", NULL); + filename = g_build_filename(home, surf_dir, download_dir, NULL); g_mkdir_with_parents(filename, 0755); /* cookie persistance */ s = webkit_get_default_session(); - filename = g_build_filename(home, ".surf", "cookies.jar", NULL); + filename = g_build_filename(home, surf_dir, cookie_file, NULL); cookiejar = soup_cookie_jar_text_new(filename, FALSE); soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));