unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
@ 2024-01-28  2:08 Rahul M. Juliato
  2024-01-28  2:40 ` Stefan Kangas
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Rahul M. Juliato @ 2024-01-28  2:08 UTC (permalink / raw)
  To: 68766


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





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-28  2:08 bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar Rahul M. Juliato
@ 2024-01-28  2:40 ` Stefan Kangas
  2024-01-28  6:42   ` Eli Zaretskii
  2024-01-28  6:38 ` Eli Zaretskii
  2024-01-30 19:57 ` Rahul M. Juliato
  2 siblings, 1 reply; 12+ messages in thread
From: Stefan Kangas @ 2024-01-28  2:40 UTC (permalink / raw)
  To: Rahul M. Juliato, 68766

Hi Rahul,

"Rahul M. Juliato" <rahuljuliato@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?





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-28  2:08 bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar Rahul M. Juliato
  2024-01-28  2:40 ` Stefan Kangas
@ 2024-01-28  6:38 ` Eli Zaretskii
  2024-01-29 22:34   ` Stefan Kangas
  2024-01-30 19:57 ` Rahul M. Juliato
  2 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-01-28  6:38 UTC (permalink / raw)
  To: Rahul M. Juliato; +Cc: 68766

> From: "Rahul M. Juliato" <rahuljuliato@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-28  2:40 ` Stefan Kangas
@ 2024-01-28  6:42   ` Eli Zaretskii
  2024-01-30 19:52     ` Rahul M. Juliato
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-01-28  6:42 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: rahuljuliato, 68766

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Sat, 27 Jan 2024 18:40:03 -0800
> 
> Hi Rahul,
> 
> "Rahul M. Juliato" <rahuljuliato@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-28  6:38 ` Eli Zaretskii
@ 2024-01-29 22:34   ` Stefan Kangas
  2024-01-30  7:37     ` Visuwesh
  2024-01-30 11:57     ` Rudolf Schlatte
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Kangas @ 2024-01-29 22:34 UTC (permalink / raw)
  To: Eli Zaretskii, Rahul M. Juliato; +Cc: 68766

Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-29 22:34   ` Stefan Kangas
@ 2024-01-30  7:37     ` Visuwesh
  2024-01-30 11:57     ` Rudolf Schlatte
  1 sibling, 0 replies; 12+ messages in thread
From: Visuwesh @ 2024-01-30  7:37 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, Rahul M. Juliato, 68766

[திங்கள் ஜனவரி 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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-29 22:34   ` Stefan Kangas
  2024-01-30  7:37     ` Visuwesh
@ 2024-01-30 11:57     ` Rudolf Schlatte
  2024-01-30 13:15       ` Eli Zaretskii
  1 sibling, 1 reply; 12+ messages in thread
From: Rudolf Schlatte @ 2024-01-30 11:57 UTC (permalink / raw)
  To: 68766

Stefan Kangas <stefankangas@gmail.com> writes:

> Eli Zaretskii <eliz@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)))))






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-30 11:57     ` Rudolf Schlatte
@ 2024-01-30 13:15       ` Eli Zaretskii
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2024-01-30 13:15 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: 68766

> From: Rudolf Schlatte <rudi@constantly.at>
> Date: Tue, 30 Jan 2024 12:57:45 +0100
> 
> Stefan Kangas <stefankangas@gmail.com> writes:
> 
> > Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-28  6:42   ` Eli Zaretskii
@ 2024-01-30 19:52     ` Rahul M. Juliato
  0 siblings, 0 replies; 12+ messages in thread
From: Rahul M. Juliato @ 2024-01-30 19:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 68766






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-28  2:08 bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar Rahul M. Juliato
  2024-01-28  2:40 ` Stefan Kangas
  2024-01-28  6:38 ` Eli Zaretskii
@ 2024-01-30 19:57 ` Rahul M. Juliato
  2024-02-03  9:57   ` Eli Zaretskii
  2 siblings, 1 reply; 12+ messages in thread
From: Rahul M. Juliato @ 2024-01-30 19:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 68766

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





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-01-30 19:57 ` Rahul M. Juliato
@ 2024-02-03  9:57   ` Eli Zaretskii
  2024-02-19  1:15     ` Rahul M. Juliato
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-02-03  9:57 UTC (permalink / raw)
  To: Rahul M. Juliato; +Cc: 68766

> From: "Rahul M. Juliato" <rahuljuliato@gmail.com>
> Cc: 68766@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.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar
  2024-02-03  9:57   ` Eli Zaretskii
@ 2024-02-19  1:15     ` Rahul M. Juliato
  0 siblings, 0 replies; 12+ messages in thread
From: Rahul M. Juliato @ 2024-02-19  1:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Rahul M. Juliato, 68766


I am sorry, I haven't figured out a way to make it from the C code yet.






^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-02-19  1:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-28  2:08 bug#68766: 29.2; Windows dark/light mode changes does not reflect on Emacs Title bar/Scrollbar Rahul M. Juliato
2024-01-28  2:40 ` Stefan Kangas
2024-01-28  6:42   ` Eli Zaretskii
2024-01-30 19:52     ` Rahul M. Juliato
2024-01-28  6:38 ` Eli Zaretskii
2024-01-29 22:34   ` Stefan Kangas
2024-01-30  7:37     ` Visuwesh
2024-01-30 11:57     ` Rudolf Schlatte
2024-01-30 13:15       ` Eli Zaretskii
2024-01-30 19:57 ` Rahul M. Juliato
2024-02-03  9:57   ` Eli Zaretskii
2024-02-19  1:15     ` Rahul M. Juliato

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).