I've updated this for dmenu-style completion and you can now add the current
url to the urls file.
On Fri, Sep 18, 2009 at 08:52:04PM +0100, Anselm R Garbe wrote:
> Why not using dmenu for that? Just an idea though...
>
> On Sep 18, 2009 8:34 PM, "Rory Rory" <[email protected]> wrote:
>
> Here is the actual patch. Sorry, I sent the wrong file the first time.
>
> On 9/18/09, Rory Rory <[email protected]> wrote: > Sorry, the patch I
> sent is broken. If you ...
> --
> Rory
diff -r 561d9db3aae4 surf.c
--- a/surf.c Thu Sep 17 13:03:58 2009 +0200
+++ b/surf.c Wed Sep 23 13:47:38 2009 +0100
@@ -28,6 +28,8 @@
typedef struct Client {
GtkWidget *win, *scroll, *vbox, *urlbar, *searchbar, *indicator;
+ GtkEntryCompletion *urlcomplete;
+ GtkListStore *completeliststore;
WebKitWebView *view;
WebKitDownload *download;
gchar *title;
@@ -81,6 +83,7 @@
static gboolean initdownload(WebKitWebView *view, WebKitDownload *o, Client *c);
static gchar *geturi(Client *c);
static void hidesearch(Client *c, const Arg *arg);
+static void bkmarkurl(Client *c, const Arg *arg);
static void hideurl(Client *c, const Arg *arg);
static gboolean keypress(GtkWidget* w, GdkEventKey *ev, Client *c);
static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, Client *c);
@@ -348,6 +351,15 @@
g_free(uri);
}
+void bkmarkurl(Client *c, const Arg *arg) {
+ FILE *f;
+ gchar *currurl;
+ currurl = geturi(c);
+ f = g_fopen(g_strconcat(workdir,"/urls.txt",NULL),"a");
+ fprintf(f,"%s\n",currurl);
+ fclose(f);
+}
+
void
loaduri(Client *c, const Arg *arg) {
gchar *u;
@@ -369,6 +381,20 @@
webkit_web_view_go_back_or_forward(c->view, steps);
}
+gboolean
+matchfunc(GtkEntryCompletion *completion,const gchar *key,GtkTreeIter *iter,Client *c)
+{
+ gchar *matchval;
+ gtk_tree_model_get(GTK_TREE_MODEL(c->completeliststore),iter,0,&matchval,-1);
+ if (g_strrstr(matchval,key) != NULL)
+ {
+ return TRUE;
+ }
+ else
+ return FALSE;
+ g_free(matchval);
+}
+
Client *
newclient(void) {
Client *c;
@@ -414,6 +440,33 @@
gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
g_signal_connect(G_OBJECT(c->urlbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
+ /* completeliststore */
+ c->completeliststore = gtk_list_store_new(1,G_TYPE_STRING);
+ GtkTreeIter iter;
+ int len = 0;
+ char buf[1024];
+ FILE* urlf;
+
+ if (( urlf = g_fopen(g_strconcat(workdir,"/urls.txt",NULL),"r")))
+ {
+ while (fgets(buf,sizeof buf,urlf))
+ {
+ len = strlen(buf);
+ if (buf[len - 1] == '\n')
+ buf[len - 1] = 0;
+ gtk_list_store_append(c->completeliststore,&iter);
+ gtk_list_store_set(c->completeliststore,&iter,0,buf,-1);
+ }
+ }
+ fclose(urlf);
+
+ /* urlcomplete */
+ c->urlcomplete = gtk_entry_completion_new();
+ gtk_entry_completion_set_model(GTK_ENTRY_COMPLETION(c->urlcomplete),GTK_TREE_MODEL(c->completeliststore));
+ gtk_entry_completion_set_text_column(GTK_ENTRY_COMPLETION(c->urlcomplete),0);
+ gtk_entry_completion_set_match_func(c->urlcomplete,(GtkEntryCompletionMatchFunc)matchfunc,c,g_free);
+ gtk_entry_set_completion(GTK_ENTRY(c->urlbar),GTK_ENTRY_COMPLETION(c->urlcomplete));
+
/* searchbar */
c->searchbar = gtk_entry_new();
gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
@@ -433,6 +486,10 @@
gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
+ /* Hints */
+ GdkGeometry hints = {1,1};
+ gtk_window_set_geometry_hints(GTK_WINDOW(c->win),NULL,&hints,GDK_HINT_MIN_SIZE);
+
/* Setup */
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);