Add dark mode toggle

This sets dark gtk theme variant,
which should make webkit2gtk use dark css variant
from websites that provide it.
This commit is contained in:
Quentin Rameau 2022-04-10 16:35:24 +02:00
parent 11dca18a2d
commit 1f5b8f3bd1
3 changed files with 11 additions and 0 deletions

View File

@ -20,6 +20,7 @@ static Parameter defconfig[ParameterLast] = {
[Certificate] = { { .i = 0 }, }, [Certificate] = { { .i = 0 }, },
[CaretBrowsing] = { { .i = 0 }, }, [CaretBrowsing] = { { .i = 0 }, },
[CookiePolicies] = { { .v = "@Aa" }, }, [CookiePolicies] = { { .v = "@Aa" }, },
[DarkMode] = { { .i = 0 }, },
[DefaultCharset] = { { .v = "UTF-8" }, }, [DefaultCharset] = { { .v = "UTF-8" }, },
[DiskCache] = { { .i = 1 }, }, [DiskCache] = { { .i = 1 }, },
[DNSPrefetch] = { { .i = 0 }, }, [DNSPrefetch] = { { .i = 0 }, },
@ -179,6 +180,7 @@ static Key keys[] = {
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } },
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_d, toggle, { .i = DarkMode } },
}; };
/* button definitions */ /* button definitions */

3
surf.1
View File

@ -208,6 +208,9 @@ Toggle scrollbars. This will reload the page.
.B Ctrl\-Shift\-c .B Ctrl\-Shift\-c
Toggle caret browsing. This will reload the page. Toggle caret browsing. This will reload the page.
.TP .TP
.B Ctrl\-Shift\-d
Toggle dark mode. This will reload the page.
.TP
.B Ctrl\-Shift\-i .B Ctrl\-Shift\-i
Toggle auto-loading of images. This will reload the page. Toggle auto-loading of images. This will reload the page.
.TP .TP

6
surf.c
View File

@ -56,6 +56,7 @@ typedef enum {
CaretBrowsing, CaretBrowsing,
Certificate, Certificate,
CookiePolicies, CookiePolicies,
DarkMode,
DiskCache, DiskCache,
DefaultCharset, DefaultCharset,
DNSPrefetch, DNSPrefetch,
@ -259,6 +260,7 @@ char *argv0;
static ParamName loadtransient[] = { static ParamName loadtransient[] = {
Certificate, Certificate,
CookiePolicies, CookiePolicies,
DarkMode,
DiskCache, DiskCache,
DNSPrefetch, DNSPrefetch,
FileURLsCrossAccess, FileURLsCrossAccess,
@ -772,6 +774,10 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a)
cookiepolicy_get()); cookiepolicy_get());
refresh = 0; refresh = 0;
break; break;
case DarkMode:
g_object_set(gtk_settings_get_default(),
"gtk-application-prefer-dark-theme", a->i, NULL);
break;
case DiskCache: case DiskCache:
webkit_web_context_set_cache_model( webkit_web_context_set_cache_model(
webkit_web_view_get_context(c->view), a->i ? webkit_web_view_get_context(c->view), a->i ?