X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=surf.c;h=f227d4c9851b0a58b15c3ec661d5997573ce763e;hp=e8b2c3de891da70aed3a33690f44249c161841a0;hb=ba8617e4ee9ff35a45059930ef611cb85ed33af2;hpb=d9cecc89329dee3eb48bb6cc38d2bc38796c2e8b diff --git a/surf.c b/surf.c index e8b2c3d..f227d4c 100644 --- a/surf.c +++ b/surf.c @@ -107,7 +107,7 @@ static char *buildfile(const char *path); static char *buildpath(const char *path); static gboolean buttonreleased(GtkWidget *w, GdkEventKey *e, Client *c); static void cleanup(void); -static void clipboard(Client *c, const Arg *arg); +static void clipboard(Client *c, const Arg *a); static WebKitCookieAcceptPolicy cookiepolicy_get(void); static char cookiepolicy_set(const WebKitCookieAcceptPolicy p); @@ -127,7 +127,7 @@ static void die(const char *errstr, ...); static void evalscript(Client *c, const char *jsstr, ...); static void runscript(Client *c); static void find(Client *c, const Arg *arg); -static void fullscreen(Client *c, const Arg *arg); +static void togglefullscreen(Client *c, const Arg *a); static gboolean permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c); static const char *getatom(Client *c, int a); @@ -135,7 +135,7 @@ static void gettogglestat(Client *c); static void getpagestat(Client *c); static char *geturi(Client *c); static const gchar *getstyle(const char *uri); -static void setstyle(Client *c, const char *style); +static void setstyle(Client *c, const char *stylefile); static void handleplumb(Client *c, const gchar *uri); @@ -167,6 +167,7 @@ static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); static void print(Client *c, const Arg *arg); static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d); +static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c); static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c); static void linkopen(Client *c, const Arg *arg); static void linkopenembed(Client *c, const Arg *arg); @@ -180,7 +181,6 @@ static void sigchld(int unused); static void spawn(Client *c, const Arg *arg); static void stop(Client *c, const Arg *arg); static void titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c); -static void titlechangeleave(void *a, void *b, Client *c); static void toggle(Client *c, const Arg *arg); static void togglecookiepolicy(Client *c, const Arg *arg); static void togglegeolocation(Client *c, const Arg *arg); @@ -362,18 +362,16 @@ runscript(Client *c) } void -clipboard(Client *c, const Arg *arg) +clipboard(Client *c, const Arg *a) { - gboolean paste = *(gboolean *)arg; - - if (paste) { + if (a->b) { /* load clipboard uri */ gtk_clipboard_request_text(gtk_clipboard_get( GDK_SELECTION_PRIMARY), pasteuri, c); - } else { + } else { /* copy uri */ gtk_clipboard_set_text(gtk_clipboard_get( - GDK_SELECTION_PRIMARY), c->linkhover - ? c->linkhover : geturi(c), -1); + GDK_SELECTION_PRIMARY), c->targeturi + ? c->targeturi : geturi(c), -1); } } @@ -600,13 +598,13 @@ find(Client *c, const Arg *arg) } void -fullscreen(Client *c, const Arg *arg) +togglefullscreen(Client *c, const Arg *a) { + /* toggling value is handled in winevent() */ if (c->fullscreen) gtk_window_unfullscreen(GTK_WINDOW(c->win)); else gtk_window_fullscreen(GTK_WINDOW(c->win)); - c->fullscreen = !c->fullscreen; } gboolean @@ -672,11 +670,23 @@ getstyle(const char *uri) } void -setstyle(Client *c, const char *style) +setstyle(Client *c, const char *stylefile) { - WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); + gchar *style; + + if (!g_file_get_contents(stylefile, &style, NULL, NULL)) { + fprintf(stderr, "Could not read style file: %s\n", stylefile); + return; + } + + webkit_user_content_manager_add_style_sheet( + webkit_web_view_get_user_content_manager(c->view), + webkit_user_style_sheet_new(style, + WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, + WEBKIT_USER_STYLE_LEVEL_USER, + NULL, NULL)); - g_object_set(G_OBJECT(settings), "user-stylesheet-uri", style, NULL); + g_free(style); } void @@ -1037,7 +1047,7 @@ showview(WebKitWebView *v, Client *c) webkit_web_view_set_zoom_level(c->view, zoomlevel); if (runinfullscreen) - fullscreen(c, NULL); + togglefullscreen(c, NULL); setatom(c, AtomFind, ""); setatom(c, AtomUri, "about:blank"); @@ -1125,8 +1135,10 @@ createwindow(Client *c) g_signal_connect(G_OBJECT(w), "destroy", G_CALLBACK(destroywin), c); - g_signal_connect(G_OBJECT(w), "leave_notify_event", - G_CALLBACK(titlechangeleave), c); + g_signal_connect(G_OBJECT(w), "leave-notify-event", + G_CALLBACK(winevent), c); + g_signal_connect(G_OBJECT(w), "window-state-event", + G_CALLBACK(winevent), c); return w; } @@ -1331,11 +1343,26 @@ titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c) updatetitle(c); } -void -titlechangeleave(void *a, void *b, Client *c) +gboolean +winevent(GtkWidget *w, GdkEvent *e, Client *c) { - c->linkhover = NULL; - updatetitle(c); + switch (e->type) { + case GDK_LEAVE_NOTIFY: + c->targeturi = NULL; + updatetitle(c); + break; + case GDK_WINDOW_STATE: /* fallthrough */ + if (e->window_state.changed_mask == + GDK_WINDOW_STATE_FULLSCREEN) { + c->fullscreen = e->window_state.new_window_state & + GDK_WINDOW_STATE_FULLSCREEN; + break; + } + default: + return FALSE; + } + + return TRUE; } void