[hackers] [surf/surf-webkit2] Add dark mode toggle || Quentin Rameau

From: <git_AT_suckless.org>
Date: Sun, 10 Apr 2022 16:43:19 +0200 (CEST)

commit 1f5b8f3bd1f37d4d3dc45d21285f34ef4752dbaa
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Sun Apr 10 16:35:24 2022 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Sun Apr 10 16:35:24 2022 +0200

    Add dark mode toggle
    
    This sets dark gtk theme variant,
    which should make webkit2gtk use dark css variant
    from websites that provide it.

diff --git a/config.def.h b/config.def.h
index 1355ba3..93cfeeb 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -20,6 +20,7 @@ static Parameter defconfig[ParameterLast] = {
         [Certificate] = { { .i = 0 }, },
         [CaretBrowsing] = { { .i = 0 }, },
         [CookiePolicies] = { { .v = "_AT_Aa" }, },
+ [DarkMode] = { { .i = 0 }, },
         [DefaultCharset] = { { .v = "UTF-8" }, },
         [DiskCache] = { { .i = 1 }, },
         [DNSPrefetch] = { { .i = 0 }, },
_AT_@ -179,6 +180,7 @@ static Key keys[] = {
         { 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_m, toggle, { .i = Style } },
+ { MODKEY|GDK_SHIFT_MASK, GDK_KEY_d, toggle, { .i = DarkMode } },
 };
 
 /* button definitions */
diff --git a/surf.1 b/surf.1
index 496afb9..5d69a07 100644
--- a/surf.1
+++ b/surf.1
_AT_@ -208,6 +208,9 @@ Toggle scrollbars. This will reload the page.
 .B Ctrl\-Shift\-c
 Toggle caret browsing. This will reload the page.
 .TP
+.B Ctrl\-Shift\-d
+Toggle dark mode. This will reload the page.
+.TP
 .B Ctrl\-Shift\-i
 Toggle auto-loading of images. This will reload the page.
 .TP
diff --git a/surf.c b/surf.c
index 03d8242..3132249 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -56,6 +56,7 @@ typedef enum {
         CaretBrowsing,
         Certificate,
         CookiePolicies,
+ DarkMode,
         DiskCache,
         DefaultCharset,
         DNSPrefetch,
_AT_@ -259,6 +260,7 @@ char *argv0;
 static ParamName loadtransient[] = {
         Certificate,
         CookiePolicies,
+ DarkMode,
         DiskCache,
         DNSPrefetch,
         FileURLsCrossAccess,
_AT_@ -772,6 +774,10 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a)
                     cookiepolicy_get());
                 refresh = 0;
                 break;
+ case DarkMode:
+ g_object_set(gtk_settings_get_default(),
+ "gtk-application-prefer-dark-theme", a->i, NULL);
+ break;
         case DiskCache:
                 webkit_web_context_set_cache_model(
                     webkit_web_view_get_context(c->view), a->i ?
Received on Sun Apr 10 2022 - 16:43:19 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 10 2022 - 16:48:34 CEST