X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=surf.c;h=f227d4c9851b0a58b15c3ec661d5997573ce763e;hp=c84f0c5dbf40d7ecb1f557af665d4b25af5fc891;hb=ba8617e4ee9ff35a45059930ef611cb85ed33af2;hpb=d6794e0d75128dda9be6bd4769e2cd81a57192c7 diff --git a/surf.c b/surf.c index c84f0c5..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); @@ -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); @@ -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); } } @@ -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