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.devel Subject: Detecting changes between dark and light mode on Mac OS Date: Tue, 9 Mar 2021 14:23:18 +0100 Message-ID: Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_3658199B-7B81-4BED-9795-0C0BCD8572A6" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7184"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 09 16:13:24 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lJe32-0001kO-HJ for ged-emacs-devel@m.gmane-mx.org; Tue, 09 Mar 2021 16:13:24 +0100 Original-Received: from localhost ([::1]:49102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJe31-0005k8-I7 for ged-emacs-devel@m.gmane-mx.org; Tue, 09 Mar 2021 10:13:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJcKg-0007rj-Jj for emacs-devel@gnu.org; Tue, 09 Mar 2021 08:23:30 -0500 Original-Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:54857) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJcKb-0001Bu-El for emacs-devel@gnu.org; Tue, 09 Mar 2021 08:23:29 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 5B53C2358 for ; Tue, 9 Mar 2021 08:23:22 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 09 Mar 2021 08:23:22 -0500 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=1lZ8Wi+sYDLJ0TjgOMobSOojox32V LjXVXi07jxvBuI=; b=LoFNWhXEYgqd06P+Uak3CTovweCvqLubtjApE1jTsfZEk L7zxIy/BIpP3FsJE+xYNMJqm42mISb4o5J3KF4vvB16lUnvltS8bgsDMKVw2BM+c Jj5+Qrimj7JOm5NTDcHhu2Cqq8FrSBLgWI1uPafTGOpBk7ANGOg+81YEToTiKtAZ N26wjIDFB4Ws4CKJpFQpStqVsFFfnJvdWgdPI65b6vlmrBRvpGNb12TwIKto3xeX Shoq9RBJrKN+zpm8ijRZb7ZJWoZIvtuwhNncKKvWJv54nih+cuehF/2n98DrdOzA XpjeFsB4wejZ+jGGHvsgUcC2xNZDjjOU4WzArG1pQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudduiedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhtggguffkfffvofesmhdtmherhh dtjeenucfhrhhomhepffgrphhhnhgvucfrrhgvshhtohhnqdfmvghnuggrlhcuoeguphhk sehnohhntggvfihorhgurdhorhhgqeenucggtffrrghtthgvrhhnpeeihefhgfekuefgle eifefgvdegleehfeehfffgteeugeekjefgheekgeelveegudenucfkphepleehrdeltddr vdefgedrudefleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpeguphhksehnohhntggvfihorhgurdhorhhg X-ME-Proxy: Original-Received: from [192.168.0.3] (ip5f5aea8b.dynamic.kabel-deutschland.de [95.90.234.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 448AD1080064 for ; Tue, 9 Mar 2021 08:23:21 -0500 (EST) X-Mailer: Apple Mail (2.3654.60.0.2.21) Received-SPF: none client-ip=64.147.123.19; envelope-from=dpk@nonceword.org; helo=wout3-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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 09 Mar 2021 10:03:38 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:266246 Archived-At: --Apple-Mail=_3658199B-7B81-4BED-9795-0C0BCD8572A6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello, I've attempted to implement support for detecting and responding to changes between system dark and light mode on Mac OS. This patch makes it so that the ns-appearance parameter of a frame is always bound =E2=80=94 if it isn't set by the user, it's set to 'dark or 'light depending on the operating system's default setting. It also listens for changes in the systemwide appearance, changes the ns-appearance on all frames when that happens, and runs a new hook, ns-dark-mode-change-hook. (It's still possible to set ns-appearance on a frame-by-frame basis, but such changes will be overridden the next time the systemwide appearance changes.) This enables users to automatically set Emacs to change their theme when the system changes from dark to light, for example. (Since Mac OS 10.15, there is a mode in the system which automatically changes to dark mode in the evening and light mode during the day; various third-party utilities existed to provide similar behaviour before 10.15. So this helps Emacs follow that automatic change, for example.) This is my first Emacs patch, and also the first time I've written Objective-C in probably ten years. So there are probably still gremlins lurking here and there, and I'd appreciate feedback! Many thanks Daphne Preston-Kendal --Apple-Mail=_3658199B-7B81-4BED-9795-0C0BCD8572A6 Content-Disposition: attachment; filename=0001-auto-detection-of-ns-appearance-and-an-ns-dark-mode-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-auto-detection-of-ns-appearance-and-an-ns-dark-mode-.patch" Content-Transfer-Encoding: quoted-printable =46rom=20813b66cff906bc39b7615b7ca71689da3388029c=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-detection=20of=20ns-appearance,=20and=20an=0A=20= ns-dark-mode-change-hook=0A=0A---=0A=20src/nsfns.m=20=20|=2010=20= +++++++++-=0A=20src/nsterm.m=20|=2050=20= +++++++++++++++++++++++++++++++++++++++++++++++++-=0A=202=20files=20= changed,=2058=20insertions(+),=202=20deletions(-)=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..e0632e347e=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,32=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=20Lisp_Object=20new_value=20=3D=20[[[self=20= effectiveAppearance]=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=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=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]=20= isEqualToString:NSAppearanceNameDarkAqua]=20?=20Qlight=20:=20Qdark;=20/*=20= this=20is=20backwards;=20i=20have=20no=20idea=20why=20*/=0A+=0A+=20=20= Lisp_Object=20tail,=20frame;=0A+=20=20FOR_EACH_FRAME=20(tail,=20frame)=0A= +=20=20=20=20{=0A+=20=20=20=20=20=20struct=20frame=20*f=20=3D=20XFRAME=20= (frame);=0A+=20=20=20=20=20=20EmacsView=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=20= ns_update_system_appearance=20(f,=20new_value);=0A+=20=20=20=20=20=20= ns_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=20run_hook=20= (Qns_dark_mode_changed_hook);=0A+#endif=0A+}=0A=20=0A=20/*=20Termination=20= sequences:=0A=20=20=20=20=20C-x=20C-c:=0A@@=20-9790,7=20+9833,7=20@@=20-=20= (CGContextRef)=20getContext=0A=20=20=20IOSurfaceRef=20surface=20=3D=20= NULL;=0A=20=0A=20=20=20NSTRACE=20("[EmacsSurface=20= getContextWithSize:]");=0A-=20=20NSTRACE_MSG=20(@"IOSurface=20count:=20= %lu",=20[cache=20count]=20+=20(lastSurface=20?=201=20:=200));=0A+=20=20= //=20NSTRACE_MSG=20(@"IOSurface=20count:=20%lu",=20[cache=20count]=20+=20= (lastSurface=20?=201=20:=200));=0A=20=0A=20=20=20for=20(id=20object=20in=20= cache)=0A=20=20=20=20=20{=0A@@=20-10199,6=20+10242,11=20@@=20Nil=20means=20= use=20fullscreen=20the=20old=20(<=2010.7)=20way.=20=20The=20old=20way=20= works=20better=20with=0A=20This=20variable=20is=20ignored=20on=20Mac=20= OS=20X=20<=2010.7=20and=20GNUstep.=20=20*/);=0A=20=20=20= ns_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=_3658199B-7B81-4BED-9795-0C0BCD8572A6--