return fpath;
}
+static const char*
+get_user_homedir(const char *user) {
+ struct passwd *pw = getpwnam(user);
+ if (!pw) {
+ die("Can't get user `%s' home directory.\n", user);
+ }
+ return pw->pw_dir;
+}
+
+static const char*
+get_current_user_homedir() {
+ const char *homedir;
+ const char *user;
+ struct passwd *pw;
+
+ homedir = getenv("HOME");
+ if (homedir) {
+ return homedir;
+ }
+
+ user = getenv("USER");
+ if (user) {
+ return get_user_homedir(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;
if (path[0] == '~') {
+ const char *homedir;
if (path[1] == '/' || path[1] == '\0') {
p = (char *)&path[1];
- pw = getpwuid(getuid());
+ homedir = get_current_user_homedir();
} 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 = get_user_homedir(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);
}
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);
void
setparameter(Client *c, int refresh, ParamName p, const Arg *a)
{
+ GdkRGBA bgcolor = { 0 };
WebKitSettings *s = webkit_web_view_get_settings(c->view);
switch (p) {
break;
case DiskCache:
webkit_web_context_set_cache_model(
- webkit_web_view_get_context(c->view),
- curconfig[DiskCache].val.b ?
+ webkit_web_view_get_context(c->view), a->b ?
WEBKIT_CACHE_MODEL_WEB_BROWSER :
WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
- break;
+ return; /* do not update */
case DNSPrefetch:
- refresh = 0;
- break;
+ webkit_settings_set_enable_dns_prefetching(s, a->b);
+ return; /* do not update */
case FontSize:
- webkit_settings_set_default_font_size(
- webkit_web_view_get_settings(c->view),
- curconfig[FontSize].val.i);
- break;
+ webkit_settings_set_default_font_size(s, a->i);
+ return; /* do not update */
case FrameFlattening:
webkit_settings_set_enable_frame_flattening(s, a->b);
break;
case Geolocation:
+ refresh = 0;
break;
case HideBackground:
- return; /* do nothing */
+ if (a->b)
+ webkit_web_view_set_background_color(c->view, &bgcolor);
+ return; /* do not update */
case Inspector:
- return; /* do nothing */
+ webkit_settings_set_enable_developer_extras(s, a->b);
+ return; /* do not update */
case JavaScript:
webkit_settings_set_enable_javascript(s, a->b);
break;
evalscript(c, "document.documentElement.style.overflow = '%s'",
enablescrollbars ? "auto" : "hidden");
*/
- refresh = 0;
- break;
+ return; /* do not update */
case ShowIndicators:
- return; /* do nothing */
+ break;
case SpellChecking:
webkit_web_context_set_spell_checking_enabled(
- webkit_web_view_get_context(c->view),
- curconfig[SpellChecking].val.b);
- return; /* do nothing */
+ webkit_web_view_get_context(c->view), a->b);
+ return; /* do not update */
case SpellLanguages:
return; /* do nothing */
case StrictSSL:
webkit_web_context_set_tls_errors_policy(
- webkit_web_view_get_context(c->view),
- curconfig[StrictSSL].val.b ? WEBKIT_TLS_ERRORS_POLICY_FAIL :
+ webkit_web_view_get_context(c->view), a->b ?
+ WEBKIT_TLS_ERRORS_POLICY_FAIL :
WEBKIT_TLS_ERRORS_POLICY_IGNORE);
- return; /* do nothing */
+ return; /* do not update */
case Style:
- if (curconfig[Style].val.b)
+ if (a->b)
setstyle(c, getstyle(geturi(c)));
else
webkit_user_content_manager_remove_all_style_sheets(
refresh = 0;
break;
case ZoomLevel:
- return; /* do nothing */
+ webkit_web_view_set_zoom_level(c->view, a->f);
+ return; /* do not update */
default:
return; /* do nothing */
}
GdkWindow *gwin;
c->finder = webkit_web_view_get_find_controller(c->view);
- if (curconfig[Inspector].val.b)
- c->inspector = webkit_web_view_get_inspector(c->view);
+ c->inspector = webkit_web_view_get_inspector(c->view);
c->win = createwindow(c);
setatom(c, AtomUri, title);
c->title = title;
c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
+ seturiparameters(c, geturi(c));
break;
case WEBKIT_LOAD_REDIRECTED:
setatom(c, AtomUri, title);
c->title = title;
+ seturiparameters(c, geturi(c));
break;
case WEBKIT_LOAD_COMMITTED:
- setatom(c, AtomUri, title);
- c->title = title;
if (!webkit_web_view_get_tls_info(c->view, NULL,
&(c->tlsflags)))
c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
- setatom(c, AtomUri, geturi(c));
- seturiparameters(c, geturi(c));
break;
case WEBKIT_LOAD_FINISHED:
/* Disabled until we write some WebKitWebExtension for
GdkEvent *ev = gdk_event_new(GDK_KEY_PRESS);
gdk_event_set_device(ev, gdkkb);
-// gdk_event_set_screen(ev, gdk_screen_get_default());
ev->key.window = gtk_widget_get_window(GTK_WIDGET(c->win));
ev->key.state = GDK_CONTROL_MASK;
ev->key.time = GDK_CURRENT_TIME;
void
toggleinspector(Client *c, const Arg *a)
{
- if (curconfig[Inspector].val.b) {
- if (webkit_web_inspector_is_attached(c->inspector))
- webkit_web_inspector_close(c->inspector);
- else
- webkit_web_inspector_show(c->inspector);
- }
+ if (webkit_web_inspector_is_attached(c->inspector))
+ webkit_web_inspector_close(c->inspector);
+ else if (curconfig[Inspector].val.b)
+ webkit_web_inspector_show(c->inspector);
}
void