GNU bug report logs - #68766
29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar

Previous Next

Package: emacs;

Reported by: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>

Date: Sun, 28 Jan 2024 02:10:02 UTC

Severity: normal

Found in version 29.2

To reply to this bug, email your comments to 68766 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Sun, 28 Jan 2024 02:10:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Rahul M. Juliato" <rahuljuliato <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 28 Jan 2024 02:10:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.2; Windows dark/light mode changes does not reflect on Emacs
 Title bar/Scrollbar
Date: Sat, 27 Jan 2024 23:08:45 -0300
Hello there!

I'm the maintainer of ~auto-dark~ for Emacs. Which is an utility package
aimed to change Emacs theme when the OS changes it's dark/light mode
settings (more here: https://github.com/LionyxML/auto-dark-emacs).

Currently I've been contacted by a Windows user that reported me a
strange behaviour on Emacs 29 with Windows 10/11.

In order to reproduce this behaviour:

1.) Download Emacs from the nearest mirror:

https://mirror.us-midwest-1.nexcess.net/gnu/emacs/windows/emacs-29/emacs-29.1_2.zip

Unzip it and run ~runemacs.exe~.

2.) Prepare a Powershell Script to Toggle between modes during test

Create a file named ~ToggleDarkMode.ps1~ with the following content:

#+BEGIN_SRC ps1
$k = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"
$v = (Get-ItemProperty -Path $k).SystemUsesLightTheme -bxor 1

Set-ItemProperty -Path $k -Name "SystemUsesLightTheme" -Value $v
Set-ItemProperty -Path $k -Name "AppsUseLightTheme" -Value $v
#+END_SRC

Open PowerShell as system administrator

Cd into where you created ~ToggleDarkMode.ps1~ and execute it with:

#+BEGIN_SRC shell
powershell.exe -noprofile -executionpolicy bypass -file .\ToggleDarkMode.ps1
#+END_SRC

Executing this will toggle your Windows looks between dark/light modes.

3.) As shown here in this pictures sequence

~https://imgur.com/a/zSSx2tk~

(If you guys have any Libre imgur alternative, please let me know!)


3.1) We open Emacs + calculator + notepad

The only package I have installed is ~auto-dark-mode~, responsible for
changing Emacs theme.

As the testing Windows machine was on Dark Mode when Emacs opened, both
title bar and scrollbar remains as "dark".


3.2) We now run the toggle script (2) again.

All Windows apps be come "light", auto-dark changes the theme to a light
one, but both the title bar and scrollbar remains "dark".


3.3) I now close Emacs and reopen it

Auto-dark changes the theme to "light" and both the title bar and
scrollbar becomes "light".


3.2) We now run the toggle script (2) again.

All windows apps change to "dark", auto-dark puts Emacs theme to dark,
but both title bar and scrollbar remains "light".


And you might continue with this and the results is always the same.


The problem:

It seems Emacs only sets it's title bar and scrollbar colors during
initialization, not during run time.

I do not know if this is "by design" or "a bug", hence my bug-report.

I'd also like to mention that ~auto-dark~ has a hook after changing to
both light/dark modes that could be used to run some extra elisp code if
needed.

Is it possible to change the system title bar/scrollbar colors or "theme"
from inside Emacs with Elisp?

Could we write some Powershell script and call it from Emacs using
~auto-dark~ hooks?


Thanks,

Rahul M. Juliato




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Sun, 28 Jan 2024 02:41:02 GMT) Full text and rfc822 format available.

Message #8 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>, 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not reflect
 on Emacs Title bar/Scrollbar
Date: Sat, 27 Jan 2024 18:40:03 -0800
Hi Rahul,

"Rahul M. Juliato" <rahuljuliato <at> gmail.com> writes:

> I'm the maintainer of ~auto-dark~ for Emacs. Which is an utility package
> aimed to change Emacs theme when the OS changes it's dark/light mode
> settings (more here: https://github.com/LionyxML/auto-dark-emacs).

Nifty mode.

Unrelated to your bug, but I was actually thinking about this the other
day, and I think we should have support for this available in Emacs
out-of-the-box.  Users these days expect such functionality to be
available.

Perhaps we could add auto-dark-mode, or some version of it, to Emacs?

Eli, WDYT?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Sun, 28 Jan 2024 06:39:01 GMT) Full text and rfc822 format available.

Message #11 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
Cc: 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2;
 Windows dark/light mode changes does not reflect on Emacs Title
 bar/Scrollbar
Date: Sun, 28 Jan 2024 08:38:20 +0200
> From: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
> Date: Sat, 27 Jan 2024 23:08:45 -0300
> 
> It seems Emacs only sets it's title bar and scrollbar colors during
> initialization, not during run time.

More accurately, the dark/light theme is examined and affected when
Emacs creates a frame.  So in the scenario you described, any frames
created _after_ running the script should obey the new dark/light
setting, but the frames which existed at the time of the change will
retain their appearance.

> I do not know if this is "by design" or "a bug", hence my bug-report.

It's "by design", in the sense that this is how the Dark theme support
is implemented in Emacs.  If someone submits changes to react to theme
change immediately for all the frames, we can consider that for
inclusion.

> I'd also like to mention that ~auto-dark~ has a hook after changing to
> both light/dark modes that could be used to run some extra elisp code if
> needed.
> 
> Is it possible to change the system title bar/scrollbar colors or "theme"
> from inside Emacs with Elisp?

No, it is not currently possible.  The code which determines the
dark/light mode of a frame runs at frame creation time, so exposing it
to Lisp would not be useful.  The development version (what will be
Emacs 30 in due time) has a user option to opt out of following the
system-wide Dark mode, but that option is only useful if set in the
init file.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Sun, 28 Jan 2024 06:43:01 GMT) Full text and rfc822 format available.

Message #14 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: rahuljuliato <at> gmail.com, 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2;
 Windows dark/light mode changes does not reflect on Emacs Title
 bar/Scrollbar
Date: Sun, 28 Jan 2024 08:42:21 +0200
> From: Stefan Kangas <stefankangas <at> gmail.com>
> Date: Sat, 27 Jan 2024 18:40:03 -0800
> 
> Hi Rahul,
> 
> "Rahul M. Juliato" <rahuljuliato <at> gmail.com> writes:
> 
> > I'm the maintainer of ~auto-dark~ for Emacs. Which is an utility package
> > aimed to change Emacs theme when the OS changes it's dark/light mode
> > settings (more here: https://github.com/LionyxML/auto-dark-emacs).
> 
> Nifty mode.
> 
> Unrelated to your bug, but I was actually thinking about this the other
> day, and I think we should have support for this available in Emacs
> out-of-the-box.  Users these days expect such functionality to be
> available.
> 
> Perhaps we could add auto-dark-mode, or some version of it, to Emacs?

We already have, sort of, since Emacs 29.  See my other response in
this thread.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Mon, 29 Jan 2024 22:36:01 GMT) Full text and rfc822 format available.

Message #17 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
Cc: 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not reflect
 on Emacs Title bar/Scrollbar
Date: Mon, 29 Jan 2024 17:34:54 -0500
Eli Zaretskii <eliz <at> gnu.org> writes:

> It's "by design", in the sense that this is how the Dark theme support
> is implemented in Emacs.  If someone submits changes to react to theme
> change immediately for all the frames, we can consider that for
> inclusion.

I think that would be a useful feature, indeed.

AFAIU, the point of light/dark mode for many users is that they want to
use different settings depending on the time of day.  This needs the
Emacs frame to react to it when the time switches (as most programs in
desktop environments like Gnome, or even macOS, do).

For example, Emacs on macOS already reacts automatically to light/dark
mode settings.  I believe this is provided by the toolkit itself,
without any changes in Emacs (or I missed them going in).

---

On a side note, I still don't think we have support for changing the
theme as well, do we?  This is the feature that auto-dark-mode provides.
In addition to changing the toolbar settings, I'd propose the new user
options `theme-dark' and `theme-light' indicating themes to switch to
when the desktop environment tells us that it's time.

This would be possible if the above new feature could also expose these
events to Lisp somehow.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Tue, 30 Jan 2024 07:38:02 GMT) Full text and rfc822 format available.

Message #20 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, "Rahul M. Juliato" <rahuljuliato <at> gmail.com>,
 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not
 reflect on Emacs Title bar/Scrollbar
Date: Tue, 30 Jan 2024 13:07:32 +0530
[திங்கள் ஜனவரி 29, 2024] Stefan Kangas wrote:

> On a side note, I still don't think we have support for changing the
> theme as well, do we?  This is the feature that auto-dark-mode provides.
> In addition to changing the toolbar settings, I'd propose the new user
> options `theme-dark' and `theme-light' indicating themes to switch to
> when the desktop environment tells us that it's time.

I wish we could reuse the frame-background-mode facility [1].  But
currently AFAIK, none of the themes exploit the 'background' face
display characteristic [2] to set the colours for light and dark
backgrounds in the same theme.  Perhaps some work can be done in this
direction?

1. There's even a commented out dark-mode command in frame.el.
2. (info "(elisp) Defining Faces") and the example definition therein.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Tue, 30 Jan 2024 11:59:02 GMT) Full text and rfc822 format available.

Message #23 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rudolf Schlatte <rudi <at> constantly.at>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#68766: 29.2;
 Windows dark/light mode changes does not reflect on Emacs Title
 bar/Scrollbar
Date: Tue, 30 Jan 2024 12:57:45 +0100
Stefan Kangas <stefankangas <at> gmail.com> writes:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>> It's "by design", in the sense that this is how the Dark theme support
>> is implemented in Emacs.  If someone submits changes to react to theme
>> change immediately for all the frames, we can consider that for
>> inclusion.
>
> I think that would be a useful feature, indeed.
>
> AFAIU, the point of light/dark mode for many users is that they want to
> use different settings depending on the time of day.  This needs the
> Emacs frame to react to it when the time switches (as most programs in
> desktop environments like Gnome, or even macOS, do).

This is what I have in my init file, conditionalized on (eq
window-system 'mac).  It's not the nicest API, but maybe serves as an
inspiration for a better-designed, more general hook.

(add-hook 'mac-effective-appearance-change-hook
             #'(lambda () (pcase (plist-get (mac-application-state) :appearance)
                            ("NSAppearanceNameDarkAqua" (load-theme 'ef-night t))
                            ("NSAppearanceNameAqua" (load-theme 'ef-frost t)))))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Tue, 30 Jan 2024 13:17:02 GMT) Full text and rfc822 format available.

Message #26 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Rudolf Schlatte <rudi <at> constantly.at>
Cc: 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2;
 Windows dark/light mode changes does not reflect on Emacs Title
 bar/Scrollbar
Date: Tue, 30 Jan 2024 15:15:04 +0200
> From: Rudolf Schlatte <rudi <at> constantly.at>
> Date: Tue, 30 Jan 2024 12:57:45 +0100
> 
> Stefan Kangas <stefankangas <at> gmail.com> writes:
> 
> > Eli Zaretskii <eliz <at> gnu.org> writes:
> >
> >> It's "by design", in the sense that this is how the Dark theme support
> >> is implemented in Emacs.  If someone submits changes to react to theme
> >> change immediately for all the frames, we can consider that for
> >> inclusion.
> >
> > I think that would be a useful feature, indeed.
> >
> > AFAIU, the point of light/dark mode for many users is that they want to
> > use different settings depending on the time of day.  This needs the
> > Emacs frame to react to it when the time switches (as most programs in
> > desktop environments like Gnome, or even macOS, do).
> 
> This is what I have in my init file, conditionalized on (eq
> window-system 'mac).  It's not the nicest API, but maybe serves as an
> inspiration for a better-designed, more general hook.
> 
> (add-hook 'mac-effective-appearance-change-hook
>              #'(lambda () (pcase (plist-get (mac-application-state) :appearance)
>                             ("NSAppearanceNameDarkAqua" (load-theme 'ef-night t))
>                             ("NSAppearanceNameAqua" (load-theme 'ef-frost t)))))

Thanks, but the original report was about MS-Windows, not macOS.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Tue, 30 Jan 2024 19:54:02 GMT) Full text and rfc822 format available.

Message #29 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not
 reflect on Emacs Title bar/Scrollbar
Date: Tue, 30 Jan 2024 16:52:16 -0300



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Tue, 30 Jan 2024 19:58:02 GMT) Full text and rfc822 format available.

Message #32 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not
 reflect on Emacs Title bar/Scrollbar
Date: Tue, 30 Jan 2024 16:57:26 -0300
Hello there again!


Regarding the side discussion Stefan and Eli were commenting on (and if I am
polluting this thread, please tell me where we can take this conversation).


I'd be more than happy if `auto-dark-mode` or some version
of it gets added to Emacs or some other more "official" package archive than
MELPA. I am also happy to help on any other matter I can contribute.


Just to be clear of what the package does:

- User sets a variable with "dark-mode" theme name;

- The same for "light-mode"

- Starts the minor mode either manually or on boot (auto-dark-mode)

- Emacs changes between these themes whenever system changes its dark/light
  mode internal state

- Also works with Doom Emacs and Spacemacs


Systems supported by the detection mechanism:

- macos: using `emacs-plus` (faster detection method) or any other emacs build
         falling back to osascript (a little slower detection method)

- gnu/linux: trough dbus with Gnome or gnome modules installed booting another
             WM, such as Sway or i3

- android: using `Termux`

- windows: through powershell or winreg


I am currently working on:

- nil themes: if the user wants to keep the original Emacs appearance,
              and/or set both themes to nil, and use only the detection
              mechanism with auto-dark post detection hooks to do
              something else. (Done, committed it today).

- macos:      emacs-mac build trough a faster detection method since someone
              pointed me there's a similar function to execute applescript
              than i've used for `emacs-plus` build.

- docs:       I plan to work shortly on a walk-trough install guide, some
              development tips and a FAQ


If you'd like to keep auto-dark as is today, I think we could add another
detection mechanism option such as *emacs-internal-auto-dark*, that may be fed
by some internally calculated status into a global elisp variable in which we
could use some event/or polling function to keep track of it during the
execution of the minor-mode.
    

The tricky part here would be assuring that all graphical toolkits in
all OSes can feed the OS system status to Emacs. On either Linux and macOS it
seems to be "automatically done"; Windows, as the bug originally described might
be harder.


Also the source code can be found here: https://github.com/LionyxML/auto-dark-emacs


Thank you for the opportunity to share it with you and discuss this matter.


Rahul M. Juliato




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Sat, 03 Feb 2024 09:58:01 GMT) Full text and rfc822 format available.

Message #35 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
Cc: 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not
 reflect on Emacs Title bar/Scrollbar
Date: Sat, 03 Feb 2024 11:57:00 +0200
> From: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
> Cc: 68766 <at> debbugs.gnu.org
> Date: Tue, 30 Jan 2024 16:57:26 -0300
> 
> Hello there again!
> 
> 
> Regarding the side discussion Stefan and Eli were commenting on (and if I am
> polluting this thread, please tell me where we can take this conversation).
> 
> 
> I'd be more than happy if `auto-dark-mode` or some version
> of it gets added to Emacs or some other more "official" package archive than
> MELPA. I am also happy to help on any other matter I can contribute.
> 
> 
> Just to be clear of what the package does:
> 
> - User sets a variable with "dark-mode" theme name;
> 
> - The same for "light-mode"
> 
> - Starts the minor mode either manually or on boot (auto-dark-mode)
> 
> - Emacs changes between these themes whenever system changes its dark/light
>   mode internal state
> 
> - Also works with Doom Emacs and Spacemacs
> 
> 
> Systems supported by the detection mechanism:
> 
> - macos: using `emacs-plus` (faster detection method) or any other emacs build
>          falling back to osascript (a little slower detection method)
> 
> - gnu/linux: trough dbus with Gnome or gnome modules installed booting another
>              WM, such as Sway or i3
> 
> - android: using `Termux`
> 
> - windows: through powershell or winreg

Regarding the Windows solution: aren't there better alternatives than
using Powershell or Registry?  I'd prefer doing this programmatically
in C using some suitable APIs, if possible.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68766; Package emacs. (Mon, 19 Feb 2024 01:18:01 GMT) Full text and rfc822 format available.

Message #38 received at 68766 <at> debbugs.gnu.org (full text, mbox):

From: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: "Rahul M. Juliato" <rahuljuliato <at> gmail.com>, 68766 <at> debbugs.gnu.org
Subject: Re: bug#68766: 29.2; Windows dark/light mode changes does not
 reflect on Emacs Title bar/Scrollbar
Date: Sun, 18 Feb 2024 22:15:30 -0300
I am sorry, I haven't figured out a way to make it from the C code yet.





This bug report was last modified 75 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.