Introduction
Introduction Statistics Contact Development Disclaimer Help
treworked event system. - surf - customized build of surf, the suckless webkit …
git clone git://src.adamsgaard.dk/surf
Log
Files
Refs
README
LICENSE
---
commit 4427474779e21ac3b306ea26b92b7608b7da4331
parent 5df6c8d6c5ef19e3e70630ba804271666aa84e1e
Author: Enno Boland (Gottox) <[email protected]>
Date: Sat, 6 Jun 2009 20:26:04 +0200
reworked event system.
Diffstat:
M surf.c | 147 ++++++++++++++++++++---------…
1 file changed, 95 insertions(+), 52 deletions(-)
---
diff --git a/surf.c b/surf.c
t@@ -33,26 +33,71 @@ gboolean ignore_once = FALSE;
extern char *optarg;
extern int optind;
-static Client *newclient();
-static void die(char *str);
-static void setup(void);
static void cleanup(void);
-static void updatetitle(Client *c);
-static void destroywin(GtkWidget* w, gpointer d);
-static gboolean keypress(GtkWidget* w, GdkEventKey *ev, gpointer d);
-static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gcha…
-static void progresschange(WebKitWebView *view, gint p, gpointer d);
-static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
-static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, gpo…
-static void destroyclient(Client *c);
-static WebKitWebView *newwindow(WebKitWebView *v, WebKitWebFrame *f, gpointer…
static gboolean decidewindow(WebKitWebView *view, WebKitWebFrame *f,
WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
WebKitWebPolicyDecision *p, gpointer d);
+static void destroyclient(Client *c);
+static void destroywin(GtkWidget* w, gpointer d);
+static void die(char *str);
static gboolean download(WebKitWebView *view, GObject *o, gpointer d);
-static void loaduri(const Client *c, const gchar *uri);
+static gchar *geturi(Client *c);
+static void hidesearch(Client *c);
+static void hideurl(Client *c);
+static gboolean keypress(GtkWidget* w, GdkEventKey *ev, gpointer d);
+static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, gpo…
+static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
static void loadfile(const Client *c, const gchar *f);
-GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer data);
+static void loaduri(const Client *c, const gchar *uri);
+static Client *newclient();
+static WebKitWebView *newwindow(WebKitWebView *v, WebKitWebFrame *f, gpointer…
+static void progresschange(WebKitWebView *view, gint p, gpointer d);
+static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d…
+static void setup(void);
+static void showsearch(Client *c);
+static void showurl(Client *c);
+static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gcha…
+static void updatetitle(Client *c);
+
+
+gchar *
+geturi(Client *c) {
+ gchar *uri;
+
+ if(!(uri = (gchar *)webkit_web_view_get_uri(c->view)))
+ uri = g_strdup("about:blank");
+ return uri;
+}
+
+void
+showurl(Client *c) {
+ gchar *uri;
+
+ hidesearch(c);
+ uri = geturi(c);
+ gtk_entry_set_text(GTK_ENTRY(c->urlbar), uri);
+ gtk_widget_show(c->urlbar);
+ gtk_widget_grab_focus(c->urlbar);
+}
+
+void
+hideurl(Client *c) {
+ gtk_widget_hide(c->urlbar);
+ gtk_widget_grab_focus(GTK_WIDGET(c->view));
+}
+
+void
+showsearch(Client *c) {
+ hideurl(c);
+ gtk_widget_show(c->searchbar);
+ gtk_widget_grab_focus(c->searchbar);
+}
+
+void
+hidesearch(Client *c) {
+ gtk_widget_hide(c->searchbar);
+ gtk_widget_grab_focus(GTK_WIDGET(c->view));
+}
void
cleanup(void) {
t@@ -77,7 +122,6 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
XFree(buf);
return GDK_FILTER_REMOVE;
}
- ignore_once = FALSE;
}
return GDK_FILTER_CONTINUE;
}
t@@ -153,8 +197,7 @@ loadcommit(WebKitWebView *view, WebKitWebFrame *f, gpointe…
Client *c = (Client *)d;
gchar *uri;
- if(!(uri = (gchar *)webkit_web_view_get_uri(view)))
- uri = "(null)";
+ uri = geturi(c);
ignore_once = TRUE;
XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), urlpr…
XA_STRING, 8, PropModeReplace, (unsigned char *)uri,
t@@ -220,10 +263,42 @@ destroyclient(Client *c) {
gboolean
keypress(GtkWidget* w, GdkEventKey *ev, gpointer d) {
Client *c = (Client *)d;
- gchar *uri;
if(ev->type != GDK_KEY_PRESS)
return FALSE;
+ if(GTK_WIDGET_HAS_FOCUS(c->searchbar)) {
+ switch(ev->keyval) {
+ case GDK_Escape:
+ hidesearch(c);
+ return TRUE;
+ case GDK_Return:
+ webkit_web_view_search_text(c->view,
+ gtk_entry_get_text(GTK_ENTRY(c->search…
+ FALSE,
+ !(ev->state & GDK_SHIFT_MASK),
+ TRUE);
+ return TRUE;
+ case GDK_Left:
+ case GDK_Right:
+ case GDK_r:
+ return FALSE;
+ }
+ }
+ else if(GTK_WIDGET_HAS_FOCUS(c->urlbar)) {
+ switch(ev->keyval) {
+ case GDK_Escape:
+ hideurl(c);
+ return TRUE;
+ case GDK_Return:
+ loaduri(c, gtk_entry_get_text(GTK_ENTRY(c->urlbar)));
+ hideurl(c);
+ return TRUE;
+ case GDK_Left:
+ case GDK_Right:
+ case GDK_r:
+ return FALSE;
+ }
+ }
if(ev->state == GDK_CONTROL_MASK || ev->state == (GDK_CONTROL_MASK | G…
switch(ev->keyval) {
case GDK_r:
t@@ -236,17 +311,10 @@ keypress(GtkWidget* w, GdkEventKey *ev, gpointer d) {
case GDK_b:
return TRUE;
case GDK_g:
- gtk_widget_hide(c->searchbar);
- if(!(uri = (gchar *)webkit_web_view_get_uri(c->view)))
- uri = "(null)";
- gtk_entry_set_text(GTK_ENTRY(c->urlbar), uri);
- gtk_widget_show(c->urlbar);
- gtk_widget_grab_focus(c->urlbar);
+ showurl(c);
return TRUE;
case GDK_slash:
- gtk_widget_hide(c->urlbar);
- gtk_widget_show(c->searchbar);
- gtk_widget_grab_focus(c->searchbar);
+ showsearch(c);
return TRUE;
case GDK_Left:
webkit_web_view_go_back(c->view);
t@@ -256,31 +324,6 @@ keypress(GtkWidget* w, GdkEventKey *ev, gpointer d) {
return TRUE;
}
}
- else {
- switch(ev->keyval) {
- case GDK_Escape:
- if(!GTK_WIDGET_HAS_FOCUS(c->searchbar) && !GTK_WIDGET_…
- return FALSE;
- gtk_widget_hide(c->urlbar);
- gtk_widget_hide(c->searchbar);
- gtk_widget_grab_focus(GTK_WIDGET(c->view));
- return TRUE;
- case GDK_Return:
- if(GTK_WIDGET_HAS_FOCUS(c->urlbar)) {
- loaduri(c, gtk_entry_get_text(GTK_ENTRY(c->url…
- gtk_widget_hide(c->urlbar);
- gtk_widget_grab_focus(GTK_WIDGET(c->view));
- return TRUE;
- }
- else if(GTK_WIDGET_HAS_FOCUS(c->searchbar)) {
- webkit_web_view_search_text(c->view,
- gtk_entry_get_text(GTK_ENTRY(c…
- FALSE,
- !(ev->state & GDK_SHIFT_MASK),
- TRUE);
- }
- }
- }
return FALSE;
}
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.