From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daphne Preston-Kendal Newsgroups: gmane.emacs.bugs Subject: bug#47291: [PATCH] Auto-detect ns-appearance of frames and call a hook when it changes Date: Sun, 21 Mar 2021 11:48:10 +0100 Message-ID: <1B39376A-B108-41FD-87EE-52D68E8F7256@nonceword.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_00A35F14-D080-469E-85A2-0ADF277FA6D5" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27458"; mail-complaints-to="usenet@ciao.gmane.io" To: 47291@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 21 13:56:30 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 1lNxd7-00071M-4C for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Mar 2021 13:56:29 +0100 Original-Received: from localhost ([::1]:33712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNxd6-0000sO-6T for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Mar 2021 08:56:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNxcj-0000gG-M0 for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 08:56:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42189) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNxcg-0001rk-NK for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 08:56:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lNxcg-00006n-La for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 08:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daphne Preston-Kendal Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Mar 2021 12:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47291 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1616331356397 (code B ref -1); Sun, 21 Mar 2021 12:56:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Mar 2021 12:55:56 +0000 Original-Received: from localhost ([127.0.0.1]:53733 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNxca-00006J-7i for submit@debbugs.gnu.org; Sun, 21 Mar 2021 08:55:56 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:58190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNvd6-0003KG-FU for submit@debbugs.gnu.org; Sun, 21 Mar 2021 06:48:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNvd6-0004uR-4Y for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 06:48:20 -0400 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:43593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNvd4-00006c-4z for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 06:48:19 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 81D4C1572 for ; Sun, 21 Mar 2021 06:48:13 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 21 Mar 2021 06:48:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=3+2HWhM4uIUGLiIc3H1homl1wYkoU SShd2FO/dRekNs=; b=ZqJ//qGjFOEgJrb9pCU/9AtaDAzJGUEgiv3kft0jTkZHc mWStsejjZCa1q4EbcjqlVNXVrw2cQIRWxK/6rW+JM3Diw9CwGEnKpMATE1JH6AIl DUVQq4RtkJuvWpG/Ma+1fZSTANnoRj0pg5PwZqEBa/OtjLtP0Ox6Bw9UcvCn3g1H A4Ihn2qqKPINlEdIl1Zd1efBYS9ilckhp8j2OlwkHnEqrCfjR5xcgHPLz7i4NX1g /BHA9ElBni+I4LmJm6QGqfWKwMNN4Cj4ZLmC6J9d+50SfL5DcpOpXhGF4r13cdj8 eNcennJU7dMSfnXSlXsy+spUMC7zJNoaihY2KkDag== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudegvddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhtggguffkfffvofesmhdtmherhh dtjeenucfhrhhomhepffgrphhhnhgvucfrrhgvshhtohhnqdfmvghnuggrlhcuoeguphhk sehnohhntggvfihorhgurdhorhhgqeenucggtffrrghtthgvrhhnpeegveffteejgfdutd ffgfekkeejffehvdevkeejteelffetgefgteeghffhtddvheenucffohhmrghinhepghhn uhdrohhrghenucfkphepleehrdeltddrvdefgedrudefleenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeguphhksehnohhntggvfihorhgurdho rhhg X-ME-Proxy: Original-Received: from [192.168.0.3] (unknown [95.90.234.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 97C20240423 for ; Sun, 21 Mar 2021 06:48:12 -0400 (EDT) X-Mailer: Apple Mail (2.3654.60.0.2.21) Received-SPF: none client-ip=64.147.123.20; envelope-from=dpk@nonceword.org; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 21 Mar 2021 08:55:55 -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:202772 Archived-At: --Apple-Mail=_00A35F14-D080-469E-85A2-0ADF277FA6D5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 This is a slightly cleaned-up version of the patch I initially posted = for commentary on emacs-devel. The patch makes two closely related changes: when a new frame is created, the ns-appearance parameter (which was already in Emacs) is bound to 'light or 'dark depending on the system theme. (Previously, it could be set explicitly and Emacs would respect that change on a per-frame basis, but if it wasn't explicitly set it was unbound.) Secondly, it registers an event handler for changes to the system-wide theme, and when the system theme changes, it changes the ns-appearance parameter of all frames to match the new system theme, and runs a new hook, ns-dark-mode-changed-hook so that users can e.g. set a new Emacs theme to match the new system theme or whatever. The patch is against Emacs HEAD as of time of writing. (3cbf92323c) As mentioned on emacs-devel, this is my first Emacs patch and my first time programming Objective-C in a long while, so I=E2=80=99d definitely appreciate feedback! Daphne Preston-Kendal --Apple-Mail=_00A35F14-D080-469E-85A2-0ADF277FA6D5 Content-Disposition: attachment; filename=0001-Auto-detect-ns-appearance-of-frames-and-call-a-hook-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Auto-detect-ns-appearance-of-frames-and-call-a-hook-.patch" Content-Transfer-Encoding: quoted-printable =46rom=20f0fec3e277432d20a38c50685a84448e7cd5a536=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Daphne=20Preston-Kendal=20=0ADate:=20= Tue,=209=20Mar=202021=2013:05:13=20+0100=0ASubject:=20[PATCH]=20= Auto-detect=20ns-appearance=20of=20frames=20and=20call=20a=20hook=20when=20= it=0A=20changes.=0A=0A*=20src/nsfns.m=20(Fx_create_frame):=20= Automatically=20set=20the=20ns-appearance=0Aparamter=20of=20a=20frame=20= from=20the=20current=20system=20appearance=20on=20Mac=20OS.=0A*=20= src/nsterm.m:=20Register=20for=20system=20dark/light=20mode=20change=20= events=20on=0AMac=20OS,=20and=20update=20the=20ns-appearance=20parameter=20= of=20frames=20when=20the=0Asystem=20theme=20changes,=20calling=20a=20new=20= ns-dark-mode-changed-hook=20when=0Adone.=0A---=0A=20src/nsfns.m=20=20|=20= 10=20+++++++++-=0A=20src/nsterm.m=20|=2052=20= ++++++++++++++++++++++++++++++++++++++++++++++++++++=0A=202=20files=20= changed,=2061=20insertions(+),=201=20deletion(-)=0A=0Adiff=20--git=20= a/src/nsfns.m=20b/src/nsfns.m=0Aindex=205c4cc915e7..fc73725226=20100644=0A= ---=20a/src/nsfns.m=0A+++=20b/src/nsfns.m=0A@@=20-1284,7=20+1284,15=20@@=20= Turn=20the=20input=20menu=20(an=20NSMenu)=20into=20a=20lisp=20list=20for=20= tracking=20on=20lisp=20side.=0A=20=20=20else=20if=20(EQ=20(tem,=20= Qlight))=0A=20=20=20=20=20FRAME_NS_APPEARANCE=20(f)=20=3D=20= ns_appearance_aqua;=0A=20=20=20else=0A-=20=20=20=20FRAME_NS_APPEARANCE=20= (f)=20=3D=20ns_appearance_system_default;=0A+=20=20=20=20{=0A+=20=20=20=20= =20=20tem=20=3D=20[[[NSApp=20effectiveAppearance]=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20bestMatchFromAppearancesWithNames:@[=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= NSAppearanceNameAqua,=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20NSAppearanceNameDarkAqua=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20]=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20]=20= isEqualToString:NSAppearanceNameDarkAqua]=20?=20Qdark=20:=20Qlight;=0A+=20= =20=20=20=20=20FRAME_NS_APPEARANCE=20(f)=20=3D=20(tem=20=3D=3D=20Qdark=20= ?=20ns_appearance_vibrant_dark=20:=20ns_appearance_aqua);=0A+=20=20=20=20= }=0A=20=20=20store_frame_param=20(f,=20Qns_appearance,=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(!NILP=20(tem)=20&&=20= !EQ=20(tem,=20Qunbound))=20?=20tem=20:=20Qnil);=0A=20=0Adiff=20--git=20= a/src/nsterm.m=20b/src/nsterm.m=0Aindex=20bf175bbd18..2a0213dcb4=20= 100644=0A---=20a/src/nsterm.m=0A+++=20b/src/nsterm.m=0A@@=20-2207,6=20= +2207,14=20@@=20so=20some=20key=20presses=20(TAB)=20are=20swallowed=20by=20= the=20system.=20=20*/=0A=20#endif=20/*=20MAC_OS_X_VERSION_MAX_ALLOWED=20= >=3D=20101000=20*/=0A=20}=0A=20=0A+void=0A+ns_update_system_appearance=20= (struct=20frame=20*f,=20Lisp_Object=20new_value)=0A+{=0A+#if=20= MAC_OS_X_VERSION_MAX_ALLOWED=20>=3D=20101000=0A+=20=20store_frame_param=20= (f,=20Qns_appearance,=20new_value);=0A+#endif=20/*=20= MAC_OS_X_VERSION_MAX_ALLOWED=20>=3D=20101000=20*/=0A+}=0A+=0A=20void=0A=20= ns_set_transparent_titlebar=20(struct=20frame=20*f,=20Lisp_Object=20= new_value,=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20Lisp_Object=20old_value)=0A@@=20-5926,6=20= +5934,15=20@@=20-=20(void)applicationDidFinishLaunching:=20= (NSNotification=20*)notification=0A=20=09=20object:nil];=0A=20#endif=0A=20= =0A+#ifdef=20NS_IMPL_COCOA=0A+=20=20[[NSDistributedNotificationCenter=20= defaultCenter]=0A+=20=20=20=20addObserver:self=0A+=20=20=20=20=20=20=20= selector:@selector(darkModeDidChange:)=0A+=20=20=20=20=20=20=20=20=20=20=20= name:@"AppleInterfaceThemeChangedNotification"=0A+=20=20=20=20=20=20=20=20= =20object:nil=0A+=20=20=20];=0A+#endif=0A+=0A=20#ifdef=20NS_IMPL_COCOA=0A= =20=20=20/*=20Some=20functions/methods=20in=20CoreFoundation/Foundation=20= increase=20the=0A=20=20=20=20=20=20maximum=20number=20of=20open=20files=20= for=20the=20process=20in=20their=20first=20call.=0A@@=20-5964,6=20= +5981,36=20@@=20-=20(void)antialiasThresholdDidChange:(NSNotification=20= *)notification=0A=20#endif=0A=20}=0A=20=0A+-=20= (void)darkModeDidChange:(NSNotification=20*)notification=0A+{=0A+#ifdef=20= NS_IMPL_COCOA=0A+=20=20NSTRACE=20("[EmacsApp=20darkModeDidChange:]");=0A= +=0A+=20=20/*=20It=20appears=20that=20the=20= AppleInterfaceThemeChangedNotification=20is=0A+=20=20=20=20=20sent=20to=20= the=20app=20before=20the=20effectiveAppearance=20is=20set,=20so=0A+=20=20= =20=20=20if=20the=20effectiveAppearance=20matches=20the=20dark=20theme,=20= we=20assume=0A+=20=20=20=20=20the=20new=20theme=20is=20the=20light=20= theme,=20and=20vice-versa.=20*/=0A+=20=20Lisp_Object=20new_value=20=3D=20= [[[self=20effectiveAppearance]=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= bestMatchFromAppearancesWithNames:@[=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20NSAppearanceNameAqua,=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20NSAppearanceNameDarkAqua=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20]=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20]=20isEqualToString:NSAppearanceNameDarkAqua]=20= ?=20Qlight=20:=20Qdark;=0A+=0A+=20=20Lisp_Object=20tail,=20frame;=0A+=20=20= FOR_EACH_FRAME=20(tail,=20frame)=0A+=20=20=20=20{=0A+=20=20=20=20=20=20= struct=20frame=20*f=20=3D=20XFRAME=20(frame);=0A+=20=20=20=20=20=20= EmacsView=20*view=20=3D=20(EmacsView=20*)FRAME_NS_VIEW=20(f);=0A+=20=20=20= =20=20=20EmacsWindow=20*window=20=3D=20(EmacsWindow=20*)[view=20window];=0A= +=20=20=20=20=20=20ns_update_system_appearance=20(f,=20new_value);=0A+=20= =20=20=20=20=20ns_set_appearance=20(f,=20new_value,=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(new_value=20=3D=3D= =20Qdark=20?=20Qlight=20:=20Qdark));=0A+=20=20=20=20}=0A+=0A+=20=20= run_hook=20(Qns_dark_mode_changed_hook);=0A+#endif=0A+}=0A=20=0A=20/*=20= Termination=20sequences:=0A=20=20=20=20=20C-x=20C-c:=0A@@=20-10199,6=20= +10246,11=20@@=20Nil=20means=20use=20fullscreen=20the=20old=20(<=2010.7)=20= way.=20=20The=20old=20way=20works=20better=20with=0A=20This=20variable=20= is=20ignored=20on=20Mac=20OS=20X=20<=2010.7=20and=20GNUstep.=20=20*/);=0A= =20=20=20ns_use_srgb_colorspace=20=3D=20YES;=0A=20=0A+=20=20DEFSYM=20= (Qns_dark_mode_changed_hook,=20"ns-dark-mode-changed-hook");=0A+=0A+=20=20= DEFVAR_LISP=20("ns-dark-mode-changed-hook",=20= Vns_dark_mode_changed_hook,=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20doc:=20/*=20Hook=20run=20when=20the=20Mac=20OS=20system-wide=20UI=20= theme=20changes=20from=20dark=20to=20light=20or=20vice=20versa.=20*/);=0A= +=0A=20=20=20DEFVAR_BOOL=20("ns-use-mwheel-acceleration",=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20ns_use_mwheel_acceleration,=0A=20=20=20=20= =20=20doc:=20/*=20Non-nil=20means=20use=20macOS's=20standard=20mouse=20= wheel=20acceleration.=0A--=20=0A2.24.3=20(Apple=20Git-128)=0A=0A= --Apple-Mail=_00A35F14-D080-469E-85A2-0ADF277FA6D5 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_00A35F14-D080-469E-85A2-0ADF277FA6D5--