From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#51404: Support system dark mode on Windows 10 Date: Tue, 26 Oct 2021 17:01:51 +0300 Message-ID: <834k93zxyo.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7697"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 51404@debbugs.gnu.org To: Vince Salvino Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 26 16:03:23 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfN2u-0001aa-1n for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 16:03:20 +0200 Original-Received: from localhost ([::1]:42512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfN2r-0004wo-TD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 10:03:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfN2c-0004uD-1V for bug-gnu-emacs@gnu.org; Tue, 26 Oct 2021 10:03:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfN2b-0004Et-Pj for bug-gnu-emacs@gnu.org; Tue, 26 Oct 2021 10:03:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mfN2b-0000am-Me for bug-gnu-emacs@gnu.org; Tue, 26 Oct 2021 10:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Oct 2021 14:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51404 X-GNU-PR-Package: emacs Original-Received: via spool by 51404-submit@debbugs.gnu.org id=B51404.16352569252128 (code B ref 51404); Tue, 26 Oct 2021 14:03:01 +0000 Original-Received: (at 51404) by debbugs.gnu.org; 26 Oct 2021 14:02:05 +0000 Original-Received: from localhost ([127.0.0.1]:47264 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfN1h-0000YF-Ck for submit@debbugs.gnu.org; Tue, 26 Oct 2021 10:02:05 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46498) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfN1e-0000Xe-Qv for 51404@debbugs.gnu.org; Tue, 26 Oct 2021 10:02:04 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:56458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfN1Z-00041d-B0; Tue, 26 Oct 2021 10:01:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=kVF6zMs7kfohqr+6iaEj4wskRsw3OT99mgjgDtoQXwU=; b=fXwQbD4MeNc+ bHN32qHduzNpt7HrXHr78Llg+LYKjb684kBqLmV2LnE+TFtScz8qfLLGvYLx064NNfEPcP/WPkmHl LifHIdAjzXdZFYKgYim6GbwcX+c3zkVaANwClrHuB5Qh1sfwjE8xb1H5Mj39wdizL7CPOaK36fReS bsvYBzvt27aRugRMFN8UDt1yVPhzrxOLJEpFti9dWeJpQ2tRrRj/TzQvye6oYaTIdydonJJaQvoNj nR/JX4CGNu4HbFwOcdA0eaEx7hlpxtEkofI18kL/FcOkfzsspOMt2EyHLuqG7S3qhWe6qILUIHAkG JCu+1M5h+ofJODyP88aI7A==; Original-Received: from [87.69.77.57] (port=4088 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfN1Y-0002qc-Ch; Tue, 26 Oct 2021 10:01:57 -0400 In-Reply-To: (message from Vince Salvino on Tue, 26 Oct 2021 04:46:27 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:218383 Archived-At: > From: Vince Salvino > Date: Tue, 26 Oct 2021 04:46:27 +0000 > > Attached is the patch. Additional info available here: https://github.com/vsalvino/emacs Thanks. I have some comments and questions below, but in any case these changes are large enough to require copyright assignment from you. If you'd be willing to start the legal paperwork at this time, I will send you the form to fill with the appropriate instructions. > LPBYTE > w32_get_resource (const char *key, LPDWORD lpdwtype) > +{ > + return w32_query_registry(REG_ROOT, key, lpdwtype); > +} > + > +/* Enables reading any key/name from the Windows Registry */ > +LPBYTE > +w32_query_registry (const char *root, const char *key, LPDWORD lpdwtype) I'd prefer that you simply add an extra argument to the existing w32_get_resource, and adjust its single caller to pass REG_ROOT there. > +/* > + Internal/undocumented constants for Windows Dark mode. > + See: https://github.com/microsoft/WindowsAppSDK/issues/41 > +*/ Please follow our style for comments, both single-line and multi-line. > +#define DARK_MODE_APP_NAME L"DarkMode_Explorer" Can we make this exposed to Lisp, rather than hard-coded? Hard-coding a specific application for a theme sounds un-Emacsy. People could want to experiment with other apps. > +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE > +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 Why not use 19 and 20, depending on the Windows build number, and thus expand the applicability of the feature? > +/* Applies the Windows system theme (light or dark) to a window handle. */ > +static void > +w32_applytheme(HWND hwnd) > +{ > + if (w32_darkmode) { > + /* Set window theme to that of a built-in Windows app (Explorer) > + because it has dark scroll bars and other UI elements. */ Likewise here: it should be able to control this behavior by a user option. We cannot assume that every Emacs user will automatically want to follow the system theme. > + if(SetWindowTheme_fn) { > + SetWindowTheme_fn(hwnd, DARK_MODE_APP_NAME, NULL); > + } Please follow our style of using braces in C code. > + /* Set the titlebar to system dark mode. */ > + if (DwmSetWindowAttribute_fn) { > + DwmSetWindowAttribute_fn > + (hwnd, > + DWMWA_USE_IMMERSIVE_DARK_MODE, > + &w32_darkmode, > + sizeof(w32_darkmode)); > + } Does it make sense to call DwmSetWindowAttribute if we couldn't call SetWindowTheme? I know that such a situation shouldn't normally happen, but what if it does? If we need both calls, the second call should be conditioned by SetWindowTheme_fn as well. Last, but not least: this feature should be called out in NEWS and preferably also described in the "MS-Windows" Appendix in the Emacs manual. Thanks again for working on this.