From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vince Salvino Newsgroups: gmane.emacs.bugs Subject: bug#51404: Support system dark mode on Windows 10 Date: Tue, 26 Oct 2021 16:49:34 +0000 Message-ID: References: <834k93zxyo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16845"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "51404@debbugs.gnu.org" <51404@debbugs.gnu.org> To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 26 19:06:34 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 1mfPuE-00048a-1r for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 19:06:34 +0200 Original-Received: from localhost ([::1]:36694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfPuD-0006SE-0r for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 13:06:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfPti-0006N6-VC for bug-gnu-emacs@gnu.org; Tue, 26 Oct 2021 13:06:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfPti-0006tD-IN for bug-gnu-emacs@gnu.org; Tue, 26 Oct 2021 13:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mfPti-0005n7-7Q for bug-gnu-emacs@gnu.org; Tue, 26 Oct 2021 13:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vince Salvino Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Oct 2021 17:06:02 +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.163526791722176 (code B ref 51404); Tue, 26 Oct 2021 17:06:02 +0000 Original-Received: (at 51404) by debbugs.gnu.org; 26 Oct 2021 17:05:17 +0000 Original-Received: from localhost ([127.0.0.1]:47435 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfPsy-0005lW-R1 for submit@debbugs.gnu.org; Tue, 26 Oct 2021 13:05:17 -0400 Original-Received: from mail-dm6nam08on2041.outbound.protection.outlook.com ([40.107.102.41]:13920 helo=NAM04-DM6-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfPdt-0005Kg-VU for 51404@debbugs.gnu.org; Tue, 26 Oct 2021 12:49:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ARfMhP2ujAlxLeiF5gmfVsLiqUPZ3IRbszVojuZOg6psbcs/lru3RR1oapP1soEuw7v0N4TgrljsaRqnloT3ggcEc7PV+u/a2ZYa7268f/1JFHP6htU6F9o/V5dGE9DVJlUBF8Pu3eqBXFbdITomtDKxXX9X32mk1B9mm/YY6uGO1Tv9wcicqJBTw4dAGFlsGQXHDRV98lph32fnLhVGTsdleuDBf4pu43USa7f8Jct2r4JqiifKQJJ06Aujrs+CFbA0Wf6YMrcI8Yl/D4F34nH4NGq9IMPuzIFEqkay/quSRs+NEbngwbQsidiH/gjqzcL/IkeywyGGHdj6jd8a/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AYXuFW0vy6XRyeBPxGgcnaQuDvZtR9pRZXWQx+l04SM=; b=QIiI2pFHuWU+U4L9o7h17MYoRTHYot6K363HYuXgGyPJhpKihrSu1/l8Lp6Vxya8p1Sh7bS8AuGU7TUAe3WZ+sCyac20NMdnYHZyIT4wWq+nF+3FmVPtAacVcqxR39X1g1QqPMcQ+9iN2V6RMpBSOAwFWZP/6EcxzWNblj3Rgofuy6eR1CiAPMfz9SNLsCuUG/kpfF9fzR8jHPVjrqf4ei8lkmM/hdJ6nVtRMKp3uoFw5WB2ieDBh1skWYDCPbQe6MpB5hKmRaQf/7DmrwQAv93lmpH9VHMhOuAnhRdQe8UdwflqDfrsNDRMZzo+82MG/dmJqTGeiIb8XviTf+1xqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=coderedcorp.com; dmarc=pass action=none header.from=coderedcorp.com; dkim=pass header.d=coderedcorp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coderedcorp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AYXuFW0vy6XRyeBPxGgcnaQuDvZtR9pRZXWQx+l04SM=; b=dW3Rpdr4fr/e6vGI10UZeETCvEJG/zbiqfvZx6G8u2i03CaAqLiiVDvM7m6mWIrHDfjziIpw07qEgs1pm/rispqiu7PbGTjOygWU4XXMLQklOso/qcp+WKPp/aMog2ZIt+B/xgSzCuIaC3fK7LlPErt9Sg0SOBqCcCNsaoRv5Mw= Original-Received: from CH2PR12MB4231.namprd12.prod.outlook.com (2603:10b6:610:7d::24) by CH2PR12MB4277.namprd12.prod.outlook.com (2603:10b6:610:ae::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Tue, 26 Oct 2021 16:49:34 +0000 Original-Received: from CH2PR12MB4231.namprd12.prod.outlook.com ([fe80::55e4:7d22:a6df:970b]) by CH2PR12MB4231.namprd12.prod.outlook.com ([fe80::55e4:7d22:a6df:970b%5]) with mapi id 15.20.4649.014; Tue, 26 Oct 2021 16:49:34 +0000 Thread-Topic: bug#51404: Support system dark mode on Windows 10 Thread-Index: AdfKJC1fFkosmLKeRpu5RIGxKoA2egATeE0VAAVMuSA= In-Reply-To: <834k93zxyo.fsf@gnu.org> Accept-Language: en-US Content-Language: en-US authentication-results: gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=coderedcorp.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 52a00520-19ae-489e-b947-08d998a09719 x-ms-traffictypediagnostic: CH2PR12MB4277: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6fLlBM1im0I5N3X4nwESMtxcTKX7gQy2nmLyzn7BltFiCccrVkEEd4ydWVzKgXZCTLkFU6xqPgVS1OfUz28AL8zI6RwSvO+eIXGxGP8WEeTjg1BcHi/cYqjmpdhN0MCRcRMXzJoo95m9hS/lCVi98ywprf4ky2tWNUzLRFUmFOdVrhf88V00iL7kwEqwLedQd2StlOZBWU+vBeqjGaD7k3Kl0wbhtJCq341NhRkEqT2GBOF1gmOFJ3pdn2Z8aP3hfjcCmbwEwPD5mF0yEs+ChDigDhbtTqJ/cp/w4Jnz7KnErTDKz8lb/veBCSBPanoU1dsOWimB6LzraZphKn3ArWlF+BxNIIsCexYGfgFaetEHtLlBAKDRbZz/oshV4odz8MyYSQP90grmdPNNhQMeVpf+sWD3E1goy+blqvR1woVThKXnY/TZYlWysIbNCOqNDoWcArJPtQGzLAS9mdKqXEg5EoY1D8l/zBmdPlPjeR+4fGAa+kF73l1k/uiH+nLI9j6N7eWA6Q0T4csiX6flW7SWnXjmb9NGScMgwLlfwsy1S+JYk+3dApfI1t0m8h+n+pTzaGvleiPTUyBof5uewzEK459NwzPmEDJSLBiFhR+HEC0jQ4lw+V+EZyiy53/CBGynKQTZEp3uHWGnt8sD6xT+yyPxaLLEVz2cfswlExZAbyZ32ywl7YmPqIhEzvQXGFgoP32FEBen/04GmDn3JTfMvJMD/MekaAh7m5392dWxJMaEbBzfwHlaxDkRq 2lhehCUb3yabtR0FG/l44VJVXS+yNpCybWIxHlNw4qJTS0= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4231.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39830400003)(346002)(376002)(366004)(136003)(6916009)(966005)(8676002)(508600001)(186003)(9686003)(76116006)(4326008)(6506007)(7696005)(8936002)(2906002)(86362001)(52536014)(33656002)(71200400001)(53546011)(64756008)(66446008)(66476007)(66946007)(316002)(66556008)(83380400001)(26005)(38070700005)(38100700002)(5660300002)(122000001)(55016002)(45080400002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 0JEyKUfL7Buxk1KyiFhoI0DWIsxKmR2nME75aQen89/VD1vqFgz4Si0t3DvTKbqah/mjRvhk+MYcLIJbUMug1cmW1CC8esDpuk/kgUjcaaxOhLSHJKhnDIX8SMB7cZo5YFf4hc7HmD1n/0v1sBQCwW1lMrdh1Tk1CparuDnGTiPk8J7Dk4PNOk2iOEsc+ZZWfCMCpCBlWqLIVnN4AAy2nVo6ilTuUkTL7YiZxJua4PSDPdAJMuusPKhJXIHEIt834la547KxdEdMJVWzb/KjwGaPKmJfbUNy8yyG8QC50/IA/1wnBlHO6yXdukoWRqW0nwOso6mM0sH1y+JGO77BSg1UUotAsr3PeorgLFmW293ZzE5S7aVW3fGd2JguBgcCOxKTZ6dYJfreTHoyBGNOT0Gx7KoPI/84nAUIFGPe1b1gZ4FSXumlWLwgNu9DoQ+MENpqhRk1+Ql1rl35xNVKJNZzD13Tm3HzC2qyecuCIR0K4bh7c1+RFjbsy8lI0BNIFql0IpuBECVKfhvkjjbZlso0uOcO06RdemZhTs5/k8os45pn5BLkqaaCog/kzYIY7J2gG8+rkzfNnFCLusT8OyooyHdYlN8i0ZSbkj6mv5+SbH4DPc7YAGo344YB3z1xk+OkUMbgB5OXEgrM798el6IoHkuL7jYN4G4IaI6QAMwQq1ZWV9uM5jR2kZOiplD/DUZ/yYTknIcscUQZlRf4rcOArK2yA6yEqIgyAeisz85Ezuy19cPQCBNLbn 0gCFOkPXC7AU3BLCuiIu+LNi6XJpa2TJkq3vpS6bBxa4IWKNN9v6XqkzVq56oLLgnnDNpH1QzE/BSHC2PhXQKMoPiipFg9vopO X-OriginatorOrg: coderedcorp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4231.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52a00520-19ae-489e-b947-08d998a09719 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Oct 2021 16:49:34.6263 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9c94adb1-2ce8-484f-be82-c9b5127d4cb1 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: hk3hw3GXrcyL1JF4+twOadVbUdGufr/JoppG3A+0Ebktb4ju+tDo8Wl6AMTrp10Vpk10fTdncX+YzgjKC29m1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4277 X-Mailman-Approved-At: Tue, 26 Oct 2021 13:05:15 -0400 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:218392 Archived-At: > > +#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 ex= periment with other apps. Given that this is not so much a preference, as an undocumented magic strin= g in Win32, I think anyone who wants to play with this is going to require = knowledge of C and gdb to experiment, to risk causing erratic and unknown b= ehavior. So I would be inclined to keep it in C. > > +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE #define=20 > > +DWMWA_USE_IMMERSIVE_DARK_MODE 20 > Why not use 19 and 20, depending on the Windows build number, and thus ex= pand the applicability of the feature? I can add support for 19, but do not have the ability to test it on those s= pecific Win10 builds to confirm if it actually works as expected. If someon= e is able to test on a version of Windows 10 older than 2004, then I will i= nclude. Erring on the side of stability for now. > +/* Applies the Windows system theme (light or dark) to a window=20 > +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 optio= n. We cannot assume that every Emacs user will automatically want to follo= w the system theme. I agree this would be a "nice to have", but the current functionality is in= -line with behavior on other systems (GTK, macOS, etc. i.e. the application= has no say in window decorations which are controlled by the window manage= r). If we did add an elisp setting it should default to the registry value = at runtime. I also have no idea how to create an elisp setting and read it = in C. Examples or contributions to this patch would be helpful. > > + /* 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 SetW= indowTheme? I know that such a situation shouldn't normally happen, but wh= at if it does? If we need both calls, the second call should be conditione= d by SetWindowTheme_fn as well. There is no harm in calling one without the other. SetWindowTheme sets thin= gs like scrollbars. DwmSetWindowAttribute specifically sets the titlebar. M= y original proof-of-concept only had DwmSetWindowAttribute and worked fine. I will make the other requested changes, i.e. registry helper, style guide,= and NEWS; and submit an updated patch. Vince Salvino -----Original Message----- From: Eli Zaretskii =20 Sent: Tuesday, October 26, 2021 10:02 AM To: Vince Salvino Cc: 51404@debbugs.gnu.org Subject: Re: bug#51404: Support system dark mode on Windows 10 > From: Vince Salvino > Date: Tue, 26 Oct 2021 04:46:27 +0000 >=20 > Attached is the patch. Additional info available here:=20 > https://github.com/vsalvino/emacs Thanks. I have some comments and questions below, but in any case these ch= anges 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 f= orm 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=20 > +w32_query_registry (const char *root, const char *key, LPDWORD=20 > +lpdwtype) I'd prefer that you simply add an extra argument to the existing w32_get_re= source, 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 sp= ecific application for a theme sounds un-Emacsy. People could want to expe= riment with other apps. > +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE #define=20 > +DWMWA_USE_IMMERSIVE_DARK_MODE 20 Why not use 19 and 20, depending on the Windows build number, and thus expa= nd the applicability of the feature? > +/* Applies the Windows system theme (light or dark) to a window=20 > +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 SetWin= dowTheme? 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 preferab= ly also described in the "MS-Windows" Appendix in the Emacs manual. Thanks again for working on this.