* [PATCH]: lisp function for gtk-application-prefer-dark-theme [not found] <87d35r9ek5.fsf@antono.info> @ 2012-05-30 14:14 ` Antono Vasiljev 2019-06-27 15:22 ` bug#11590: " Lars Ingebrigtsen 0 siblings, 1 reply; 4+ messages in thread From: Antono Vasiljev @ 2012-05-30 14:14 UTC (permalink / raw) To: Antono Vasiljev; +Cc: bug-gnu-emacs, emacs-devel [-- Attachment #1: Type: text/plain, Size: 455 bytes --] Antono Vasiljev <self@antono.info> writes: > Hello, > > I would like to be able setup emacs to use dark GTK theme variant[0]. > > GTK apps usually provide such possibliity via GSettings property > gtk-application-prefer-dark-theme[1]. I wonder how can it be binded to > elisp function (best file for such function). Replying to myself with initial patch implementing application-prefer-dark-theme ARG See it in action: https://vimeo.com/43078091 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: application-prefer-dark-theme implementation --] [-- Type: text/x-diff, Size: 2886 bytes --] From 7679c96fb785bc682b086f08482411311d12f84a Mon Sep 17 00:00:00 2001 From: Antono Vasiljev <self@antono.info> Date: Wed, 30 May 2012 16:56:42 +0300 Subject: [PATCH] Implemented lisp function application-prefer-dark-theme * src/xsettings.c: GtkSetting and function definition * src/xsettings.h: EXFUN macro for application-prefer-dark-theme --- src/xsettings.c | 32 ++++++++++++++++++++++++++++++++ src/xsettings.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/xsettings.c b/src/xsettings.c index 69ef22f..d8c01c7 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -201,6 +201,7 @@ struct xsettings /* The single GSettings instance, or NULL if not connected to GSettings. */ static GSettings *gsettings_client; +static GtkSettings *gtk_settings; /* Callback called when something changed in GSettings. */ @@ -824,6 +825,8 @@ init_gsettings (void) g_signal_connect (G_OBJECT (gsettings_client), "changed", G_CALLBACK (something_changed_gsettingsCB), NULL); + gtk_settings = gtk_settings_get_default (); + val = g_settings_get_value (gsettings_client, GSETTINGS_TOOL_BAR_STYLE); if (val) { @@ -1004,6 +1007,30 @@ known style. Otherwise return image. */) return Qimage; } +DEFUN ("application-prefer-dark-theme", + Fapplication_prefer_dark_theme, + Sapplication_prefer_dark_theme, + 0, 1, 0, + doc: /* Set dark theme variant for application if supported by +GUI toolkit and ARG is not nil. */) + (Lisp_Object arg) +{ + gboolean result = FALSE; + +#ifdef HAVE_GSETTINGS + if (NILP (arg) || (NUMBERP(arg) && (XINT(arg) < 0))) { + result = FALSE; + } else { + result = TRUE; + } + + g_object_set (G_OBJECT (gtk_settings), + "gtk-application-prefer-dark-theme", result, NULL); +#endif + + return result ? Fmake_symbol (build_string ("t")) : Qnil; +} + void syms_of_xsettings (void) { @@ -1012,6 +1039,7 @@ syms_of_xsettings (void) first_dpyinfo = NULL; #ifdef HAVE_GSETTINGS gsettings_client = NULL; + gtk_settings = NULL; #endif #ifdef HAVE_GCONF gconf_client = NULL; @@ -1041,6 +1069,10 @@ If this variable is nil, Emacs ignores system font changes. */); #endif #endif +#ifdef HAVE_GSETTINGS + defsubr (&Sapplication_prefer_dark_theme); +#endif + current_tool_bar_style = Qnil; DEFSYM (Qtool_bar_style, "tool-bar-style"); defsubr (&Stool_bar_get_system_style); diff --git a/src/xsettings.h b/src/xsettings.h index d6b0c09..83b5cfc 100644 --- a/src/xsettings.h +++ b/src/xsettings.h @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #define XSETTINGS_H EXFUN (Ftool_bar_get_system_style, 0); +EXFUN (Fapplication_prefer_dark_theme, 1); extern void xsettings_initialize (struct x_display_info *dpyinfo); extern void xft_settings_event (struct x_display_info *dpyinfo, -- 1.7.9.5 [-- Attachment #3: Type: text/plain, Size: 62 bytes --] -- http://shelr.tv - plain text screencasts for unix ninjas ^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#11590: [PATCH]: lisp function for gtk-application-prefer-dark-theme 2012-05-30 14:14 ` [PATCH]: lisp function for gtk-application-prefer-dark-theme Antono Vasiljev @ 2019-06-27 15:22 ` Lars Ingebrigtsen 2019-11-23 14:39 ` Lars Ingebrigtsen 0 siblings, 1 reply; 4+ messages in thread From: Lars Ingebrigtsen @ 2019-06-27 15:22 UTC (permalink / raw) To: Antono Vasiljev; +Cc: 11590 Antono Vasiljev <self@antono.info> writes: >> GTK apps usually provide such possibliity via GSettings property >> gtk-application-prefer-dark-theme[1]. I wonder how can it be binded to >> elisp function (best file for such function). [...] > +DEFUN ("application-prefer-dark-theme", > + Fapplication_prefer_dark_theme, > + Sapplication_prefer_dark_theme, > + 0, 1, 0, > + doc: /* Set dark theme variant for application if supported by > +GUI toolkit and ARG is not nil. */) [...] > + g_object_set (G_OBJECT (gtk_settings), > + "gtk-application-prefer-dark-theme", result, NULL); Dark mode is very trendy now, so it would be nice if Emacs had support for telling gtk about that. But I wonder -- would it make sense to expose setting gtk_settings stuff more generally to the Emacs Lisp work? And then just have a (gtk-settings "gtk-application-prefer-dark-theme") call or something... -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#11590: [PATCH]: lisp function for gtk-application-prefer-dark-theme 2019-06-27 15:22 ` bug#11590: " Lars Ingebrigtsen @ 2019-11-23 14:39 ` Lars Ingebrigtsen 2020-10-15 15:03 ` Lars Ingebrigtsen 0 siblings, 1 reply; 4+ messages in thread From: Lars Ingebrigtsen @ 2019-11-23 14:39 UTC (permalink / raw) To: Antono Vasiljev; +Cc: 11590 Lars Ingebrigtsen <larsi@gnus.org> writes: > Dark mode is very trendy now, so it would be nice if Emacs had support > for telling gtk about that. But I wonder -- would it make sense to > expose setting gtk_settings stuff more generally to the Emacs Lisp work? > And then just have a (gtk-settings "gtk-application-prefer-dark-theme") > call or something... A complication here is that some settings are boolean and others aren't, so it's not that trivial, perhaps. Anyway, I tried to redo the patch, but when I try it on my Debian laptop (with Gnome, as far as I know), nothing happens, which is disappointing. Is anything more needed to get dark themes working? diff --git a/src/xsettings.c b/src/xsettings.c index c23a5dc72c..bcdc0a12cb 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -1024,6 +1024,36 @@ DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style, return Qimage; } +DEFUN ("set-toolkit-dark-theme", + Fset_toolkit_dark_theme, + Sset_toolkit_dark_theme, + 0, 1, 0, + doc: /* Alter the toolkit \"dark theme\" setting. +If ARG is a positive number, switch the dark theme on; otherwise, switch +it off. + +If the GUI toolkit used does not support altering the dark theme, an +error will be signalled. */) + (Lisp_Object arg) +{ +#ifdef HAVE_GSETTINGS + gboolean dark = FALSE; + GtkSettings *settings = gtk_settings_get_for_screen + (gdk_display_get_default_screen + (gdk_display_get_default ())); + + if (NUMBERP (arg) && XFLOATINT (arg) > 0) + dark = TRUE; + + g_object_set (G_OBJECT (settings), + "gtk-application-prefer-dark-theme", dark, NULL); + + return Qnil; +#else + user_error ("The toolkit doesn't support altering \"dark theme\" settings"); +#endif +} + void syms_of_xsettings (void) { @@ -1066,6 +1096,10 @@ syms_of_xsettings (void) #endif #endif +#ifdef HAVE_GSETTINGS + defsubr (&Sset_toolkit_dark_theme); +#endif + current_tool_bar_style = Qnil; DEFSYM (Qtool_bar_style, "tool-bar-style"); defsubr (&Stool_bar_get_system_style); -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#11590: [PATCH]: lisp function for gtk-application-prefer-dark-theme 2019-11-23 14:39 ` Lars Ingebrigtsen @ 2020-10-15 15:03 ` Lars Ingebrigtsen 0 siblings, 0 replies; 4+ messages in thread From: Lars Ingebrigtsen @ 2020-10-15 15:03 UTC (permalink / raw) To: Antono Vasiljev; +Cc: 11590 Lars Ingebrigtsen <larsi@gnus.org> writes: > Anyway, I tried to redo the patch, but when I try it on my Debian laptop > (with Gnome, as far as I know), nothing happens, which is disappointing. > > Is anything more needed to get dark themes working? Actually, I had it kinda backwards here, and this patch doesn't seem to be needed (any more): Emacs switches to dark mode (for the Gtk stuff line menus and toolbars) fine now, as far as I can see. And being able to notify Gtk about this from Emacs (instead of the other way around) probably doesn't make sense anyway? So I'm closing this bug report. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-15 15:03 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <87d35r9ek5.fsf@antono.info> 2012-05-30 14:14 ` [PATCH]: lisp function for gtk-application-prefer-dark-theme Antono Vasiljev 2019-06-27 15:22 ` bug#11590: " Lars Ingebrigtsen 2019-11-23 14:39 ` Lars Ingebrigtsen 2020-10-15 15:03 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).