X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=surf.c;h=cd0a13c261f580125a00866fbf29a7a7a31e7f2a;hp=938785991f1688f5f3f1244f8d8ec962dd32696a;hb=37e43501d80710533f3ec0bd61ee84916c8524a4;hpb=7ca9421a69956c27b010cc9fc6162df7fa9699cf diff --git a/surf.c b/surf.c index 9387859..cd0a13c 100644 --- a/surf.c +++ b/surf.c @@ -58,6 +58,7 @@ enum { }; typedef enum { + AcceleratedCanvas, CaretBrowsing, CookiePolicies, DiskCache, @@ -70,11 +71,13 @@ typedef enum { JavaScript, KioskMode, LoadImages, + MediaManualPlay, Plugins, PreferredLanguages, RunInFullscreen, ScrollBars, ShowIndicators, + SiteQuirks, SpellChecking, SpellLanguages, StrictSSL, @@ -142,8 +145,11 @@ static void usage(void); static void die(const char *errstr, ...); static void setup(void); static void sigchld(int unused); +static void sighup(int unused); static char *buildfile(const char *path); static char *buildpath(const char *path); +static const char *getuserhomedir(const char *user); +static const char *getcurrentuserhomedir(void); static Client *newclient(Client *c); static void loaduri(Client *c, const Arg *a); static const char *geturi(Client *c); @@ -168,8 +174,8 @@ static void destroyclient(Client *c); static void cleanup(void); /* GTK/WebKit */ -static GdkDevice *getkbdevice(void); static WebKitWebView *newview(Client *c, WebKitWebView *rv); +static void initwebextensions(WebKitWebContext *wc, Client *c); static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c); static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c); @@ -257,13 +263,18 @@ die(const char *errstr, ...) void setup(void) { + GdkDisplay *gdpy; int i, j; /* clean up any zombies immediately */ sigchld(0); + if (signal(SIGHUP, sighup) == SIG_ERR) + die("Can't install SIGHUP handler"); + gtk_init(NULL, NULL); - dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + gdpy = gdk_display_get_default(); + dpy = GDK_DISPLAY_XDISPLAY(gdpy); curconfig = defconfig; @@ -277,7 +288,7 @@ setup(void) scriptfile = buildfile(scriptfile); cachedir = buildpath(cachedir); - gdkkb = getkbdevice(); + gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy)); if (!stylefile) { styledir = buildpath(styledir); @@ -325,6 +336,16 @@ sigchld(int unused) ; } +void +sighup(int unused) +{ + Arg a = { .b = 0 }; + Client *c; + + for (c = clients; c; c = c->next) + reload(c, &a); +} + char * buildfile(const char *path) { @@ -350,29 +371,59 @@ buildfile(const char *path) return fpath; } +static const char* +getuserhomedir(const char *user) +{ + struct passwd *pw = getpwnam(user); + + if (!pw) + die("Can't get user %s login information.\n", user); + + return pw->pw_dir; +} + +static const char* +getcurrentuserhomedir(void) +{ + const char *homedir; + const char *user; + struct passwd *pw; + + homedir = getenv("HOME"); + if (homedir) + return homedir; + + user = getenv("USER"); + if (user) + return getuserhomedir(user); + + pw = getpwuid(getuid()); + if (!pw) + die("Can't get current user home directory\n"); + + return pw->pw_dir; +} + char * buildpath(const char *path) { - struct passwd *pw; char *apath, *name, *p, *fpath; + const char *homedir; if (path[0] == '~') { if (path[1] == '/' || path[1] == '\0') { p = (char *)&path[1]; - pw = getpwuid(getuid()); + homedir = getcurrentuserhomedir(); } else { if ((p = strchr(path, '/'))) name = g_strndup(&path[1], --p - path); else name = g_strdup(&path[1]); - if (!(pw = getpwnam(name))) { - die("Can't get user %s home directory: %s.\n", - name, path); - } + homedir = getuserhomedir(name); g_free(name); } - apath = g_build_filename(pw->pw_dir, p, NULL); + apath = g_build_filename(homedir, p, NULL); } else { apath = g_strdup(path); } @@ -415,7 +466,10 @@ loaduri(Client *c, const Arg *a) if (g_strcmp0(uri, "") == 0) return; - if (g_strrstr(uri, "://") || g_str_has_prefix(uri, "about:")) { + if (g_str_has_prefix(uri, "http://") || + g_str_has_prefix(uri, "https://") || + g_str_has_prefix(uri, "file://") || + g_str_has_prefix(uri, "about:")) { url = g_strdup(uri); } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) { url = g_strdup_printf("file://%s", path); @@ -575,6 +629,9 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) WebKitSettings *s = webkit_web_view_get_settings(c->view); switch (p) { + case AcceleratedCanvas: + webkit_settings_set_enable_accelerated_2d_canvas(s, a->b); + break; case CaretBrowsing: webkit_settings_set_enable_caret_browsing(s, a->b); refresh = 0; @@ -619,6 +676,9 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) case LoadImages: webkit_settings_set_auto_load_images(s, a->b); break; + case MediaManualPlay: + webkit_settings_set_media_playback_requires_user_gesture(s, a->b); + break; case Plugins: webkit_settings_set_enable_plugins(s, a->b); break; @@ -636,6 +696,9 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) return; /* do not update */ case ShowIndicators: break; + case SiteQuirks: + webkit_settings_set_enable_site_specific_quirks(s, a->b); + break; case SpellChecking: webkit_web_context_set_spell_checking_enabled( webkit_web_view_get_context(c->view), a->b); @@ -840,22 +903,6 @@ cleanup(void) g_free(cachedir); } -static GdkDevice * -getkbdevice(void) -{ - GList *l, *gdl = gdk_device_manager_list_devices( - gdk_display_get_device_manager(gdk_display_get_default()), - GDK_DEVICE_TYPE_MASTER); - GdkDevice *gd = NULL; - - for (l = gdl; l != NULL; l = l->next) - if (gdk_device_get_source(l->data) == GDK_SOURCE_KEYBOARD) - gd = l->data; - - g_list_free(gdl); - return gd; -} - WebKitWebView * newview(Client *c, WebKitWebView *rv) { @@ -871,7 +918,7 @@ newview(Client *c, WebKitWebView *rv) } else { settings = webkit_settings_new_with_settings( "auto-load-images", curconfig[LoadImages].val.b, - "default-font-size", curconfig[FontSize].val.f, + "default-font-size", curconfig[FontSize].val.i, "enable-caret-browsing", curconfig[CaretBrowsing].val.b, "enable-developer-extras", curconfig[Inspector].val.b, "enable-dns-prefetching", curconfig[DNSPrefetch].val.b, @@ -880,6 +927,9 @@ newview(Client *c, WebKitWebView *rv) "enable-html5-local-storage", curconfig[DiskCache].val.b, "enable-javascript", curconfig[JavaScript].val.b, "enable-plugins", curconfig[Plugins].val.b, + "enable-accelerated-2d-canvas", curconfig[AcceleratedCanvas].val.b, + "enable-site-specific-quirks", curconfig[SiteQuirks].val.b, + "media-playback-requires-user-gesture", curconfig[MediaManualPlay].val.b, NULL); /* For mor interesting settings, have a look at * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */ @@ -931,6 +981,8 @@ newview(Client *c, WebKitWebView *rv) g_signal_connect(G_OBJECT(context), "download-started", G_CALLBACK(downloadstarted), c); + g_signal_connect(G_OBJECT(context), "initialize-web-extensions", + G_CALLBACK(initwebextensions), c); v = g_object_new(WEBKIT_TYPE_WEB_VIEW, "settings", settings, @@ -963,6 +1015,12 @@ newview(Client *c, WebKitWebView *rv) return v; } +void +initwebextensions(WebKitWebContext *wc, Client *c) +{ + webkit_web_context_set_web_extensions_directory(wc, WEBEXTDIR); +} + GtkWidget * createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c) {