]> git.armaanb.net Git - chorizo.git/commitdiff
Add an input box to change the URL
authorPeter Hofmann <scm@uninformativ.de>
Sat, 14 Jun 2014 13:23:22 +0000 (15:23 +0200)
committerPeter Hofmann <scm@uninformativ.de>
Sat, 14 Jun 2014 13:23:22 +0000 (15:23 +0200)
README
zea.c

diff --git a/README b/README
index 662714caddbac9d11c2a9687ba5fc7693d2798a1..a758b050ed9240cb6701d61ea07260103dc08f27 100644 (file)
--- a/README
+++ b/README
@@ -8,13 +8,13 @@ page).
 Features:
 
        - A WebKit viewport
+       - An input box to change the current URL
        - Global content zoom
        - Pluggability into suckless' tabbed
        - Support for Flash and Java
 
 Planned features:
 
-       - An input box to change the current URL
        - vi-like shortcuts
        - Adblock
 
diff --git a/zea.c b/zea.c
index 311cad3e31c0e29fb72022a739a89a399d7ccf05..3000388af6106ce299637f1cf7d3c7ee81272cf5 100644 (file)
--- a/zea.c
+++ b/zea.c
@@ -3,6 +3,7 @@
 
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
+#include <gdk/gdkkeysyms.h>
 #include <webkit/webkit.h>
 
 
@@ -14,12 +15,14 @@ static gboolean zea_do_download(WebKitWebView *, WebKitDownload *, gpointer);
 static gboolean zea_download_request(WebKitWebView *, WebKitWebFrame *,
                                      WebKitNetworkRequest *, gchar *,
                                      WebKitWebPolicyDecision *, gpointer);
+static gboolean zea_location_key(GtkWidget *, GdkEvent *, gpointer);
 static void zea_new_client(const gchar *uri);
 static gboolean zea_new_client_request(WebKitWebView *, WebKitWebFrame *,
                                        WebKitNetworkRequest *,
                                        WebKitWebNavigationAction *,
                                        WebKitWebPolicyDecision *, gpointer);
 static void zea_title_changed(GObject *, GParamSpec *, gpointer);
+static gboolean zea_web_view_key(GtkWidget *, GdkEvent *, gpointer);
 
 
 static Window embed = 0;
@@ -30,6 +33,8 @@ static double global_zoom = 1.0;
 struct Client
 {
        GtkWidget *win;
+       GtkWidget *vbox;
+       GtkWidget *location;
        GtkWidget *scroll;
        GtkWidget *web_view;
 };
@@ -109,6 +114,27 @@ zea_download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
        return FALSE;
 }
 
+gboolean
+zea_location_key(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+       struct Client *c = (struct Client *)data;
+
+       (void)widget;
+
+       if (event->type == GDK_KEY_PRESS)
+       {
+               if (((GdkEventKey *)event)->keyval == GDK_KEY_Return)
+               {
+                       gtk_widget_grab_focus(c->web_view);
+                       webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view),
+                                                gtk_entry_get_text(GTK_ENTRY(c->location)));
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
 void
 zea_new_client(const gchar *uri)
 {
@@ -150,12 +176,24 @@ zea_new_client(const gchar *uri)
                         G_CALLBACK(zea_download_request), NULL);
        g_signal_connect(G_OBJECT(c->web_view), "download-requested",
                         G_CALLBACK(zea_do_download), NULL);
+       g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
+                        G_CALLBACK(zea_web_view_key), c);
 
        c->scroll = gtk_scrolled_window_new(NULL, NULL);
 
        gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
-       gtk_container_add(GTK_CONTAINER(c->win), c->scroll);
 
+       c->location = gtk_entry_new();
+       g_signal_connect(G_OBJECT(c->location), "key-press-event",
+                        G_CALLBACK(zea_location_key), c);
+
+       c->vbox = gtk_vbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(c->vbox), c->location, FALSE, FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
+
+       gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
+
+       gtk_widget_grab_focus(c->web_view);
        gtk_widget_show_all(c->win);
 
        webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), uri);
@@ -194,6 +232,28 @@ zea_title_changed(GObject *obj, GParamSpec *pspec, gpointer data)
        gtk_window_set_title(win, (t == NULL ? "zea" : t));
 }
 
+gboolean
+zea_web_view_key(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+       struct Client *c = (struct Client *)data;
+
+       (void)widget;
+
+       if (event->type == GDK_KEY_PRESS)
+       {
+               if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
+               {
+                       if (((GdkEventKey *)event)->keyval == GDK_KEY_l)
+                       {
+                               gtk_widget_grab_focus(c->location);
+                               return TRUE;
+                       }
+               }
+       }
+
+       return FALSE;
+}
+
 int
 main(int argc, char **argv)
 {