GNU bug report logs - #51404
Support system dark mode on Windows 10

Previous Next

Package: emacs;

Reported by: Vince Salvino <salvino <at> coderedcorp.com>

Date: Tue, 26 Oct 2021 06:58:02 UTC

Severity: wishlist

Full log


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

From: Vince Salvino <salvino <at> coderedcorp.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: "51404 <at> debbugs.gnu.org" <51404 <at> debbugs.gnu.org>
Subject: RE: Support system dark mode on Windows 10
Date: Sat, 29 Jan 2022 20:27:48 +0000
[Message part 1 (text/plain, inline)]
Thanks for the review. Attached is the revised patch, minus one thing specifically:

> I see where you add windows to the list, but I don't see where you remove deleted windows from the list.  Does that mean the list will always grow indefinitely through an Emacs session, even if windows are deleted?

I also had this concern but found it a bit sticky. I can't quite find a way to know if a HWND is destroyed. Windows seems to keep the HWNDs in memory, and even reuses them if a window is destroyed and new one is created. The win32 API seems to be designed around this behavior as calling functions with a HWND that is destroyed or that is not owned by the program will not have any adverse effects.

I experimented with WM_EMACS_DESTROYWINDOW but that seems to only be triggered on the titlebar destroy, not the other "windows" such as scrollbars, menu, etc.

To answer your question, yes the current implementation will grow indefinitely. Practically speaking the memory overhead is quite small though - as a marathon emacs session creating and destroying thousands of frames repeatedly might add up to few kilobytes memory overhead on supported Win 10 systems (each entry is 16 bytes). It's definitely sloppy programming, but I will have to continue to learn more about win32 to figure out the solution, given enough free time in the future.

A few items of note:
* https://stackoverflow.com/questions/2344233/validate-hwnd-using-win32-api
* I'm still digging through the code to figure out if emacs has a parent/child relationship for HWNDs, in which case this might be relevant (especially EnumChildWindows to loop through children and purge them from the list): https://docs.microsoft.com/en-us/windows/win32/winmsg/using-windows


Vince Salvino
[0002-Support-MS-Windows-light-dark-mode-theme-change-duri.patch (application/octet-stream, attachment)]

This bug report was last modified 2 years and 279 days ago.

Previous Next


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