From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#27973: [PATCH] Add ability to change macOS WM theme (bug#27973) Date: Sun, 20 Aug 2017 14:42:01 +0100 Message-ID: <20170820134201.GA17481@breton.holly.idiocy.org> References: <838tinilci.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1503236599 11777 195.159.176.226 (20 Aug 2017 13:43:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 20 Aug 2017 13:43:19 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: james@jojojames.com, 27973@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 20 15:43:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djQVR-0002Uo-7Q for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Aug 2017 15:43:09 +0200 Original-Received: from localhost ([::1]:50654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djQVX-0002Ag-QT for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Aug 2017 09:43:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djQVO-00029M-EC for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 09:43:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djQVL-00081z-0J for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 09:43:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37511) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1djQVK-00081t-Sk for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 09:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1djQVK-0005Cz-Ch for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 09:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Aug 2017 13:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27973 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27973-submit@debbugs.gnu.org id=B27973.150323653319967 (code B ref 27973); Sun, 20 Aug 2017 13:43:02 +0000 Original-Received: (at 27973) by debbugs.gnu.org; 20 Aug 2017 13:42:13 +0000 Original-Received: from localhost ([127.0.0.1]:46192 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djQUW-0005By-PU for submit@debbugs.gnu.org; Sun, 20 Aug 2017 09:42:13 -0400 Original-Received: from mail-wr0-f169.google.com ([209.85.128.169]:33064) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djQUV-0005Bl-EY for 27973@debbugs.gnu.org; Sun, 20 Aug 2017 09:42:12 -0400 Original-Received: by mail-wr0-f169.google.com with SMTP id 30so5358172wrk.0 for <27973@debbugs.gnu.org>; Sun, 20 Aug 2017 06:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fjRaFxRjAa0JIm1/8BROuXgS2csWyFzkZiaSN1E/2Zo=; b=aDyyzTDipiuADMTdhC9wq8CcjImswm8jix8vVjJDIWEceJrrs/vXYmVR4WqUYh6buf 3a+1HVfHS6zG0jHSbayM5FryM7DteaIg+DtOQOeZt4SnZK/Vofth7HUXwsbhr6Ed71hJ pDem2oQV/42N1knzw9mO2s/M+68u+J9U/aIDz8n+FbyeiNzSvvEJQBH8AktOmLKO1LvI K1SsbCJHp9Kj7pFL3Oq5PEFYjom4yLEg8CtCOZPNZejQw/V760Z+83D0l8qKbwrq/2qM o78TX5mjkJwQPWiL6oTpUyAUWVdGmJ8zBik7kxE10q0fNP7zWO9cLYPdlTK5q9DGikmi kK9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=fjRaFxRjAa0JIm1/8BROuXgS2csWyFzkZiaSN1E/2Zo=; b=UzWSR985DU2M64W++uaLg6X4XD1nKNQ/pVcm7hyHxQ4cwr4woxf93Bae59dR0IHPyA Ciy8gdjMN33l7GCIIm0ECxg0sAGMgo3ta447JjpVgIyWSa9xvV/2+jXdyj2+Aq5E+fwY gaYh/9esWRkWNYKj6M9fBlzbvrgc1kATDRDXxv2+xf/cEl722EtFIMWzSzG5oGrQALml Rx+GX0is51fvBCRc1F2CMag5PJlcuQY9DNUs1NzovnlqSeMH2WtEDOvw/kCXwfdLsgYd UUEwlPreO+Wnz7MHsyeOdOLHOuP29Fk4KrOiSdwcfXyvEFt+koV4dmXMbNdxD381OByo kfew== X-Gm-Message-State: AHYfb5gbEVEWBBaD+K2zXYjR7y7bHWVi5k0XSbEAsQ5Qo8zxVLt5vg7s AXap/7Ps79E/fg== X-Received: by 10.223.164.157 with SMTP id g29mr9957605wrb.105.1503236525439; Sun, 20 Aug 2017 06:42:05 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-0595-da88-ef61-e9de.holly.idiocy.org. [2001:8b0:3f8:8129:595:da88:ef61:e9de]) by smtp.gmail.com with ESMTPSA id j137sm12260649wmd.0.2017.08.20.06.42.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Aug 2017 06:42:04 -0700 (PDT) Content-Disposition: inline In-Reply-To: <838tinilci.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135934 Archived-At: * src/frame.c (make_frame, frame_parms, syms_of_frame) [NS_IMPL_COCOA]: Add ns-appearance and ns-transparent-titlebar options. * src/frame.h (ns_appearance_type) [NS_IMPL_COCOA]: Add enum to represent NSAppearance options. (struct frame) [NS_IMPL_COCOA]: Add ns_appearance and ns_transparent_titlebar frame parameters. * src/nsfns.m (ns_frame_parm_handlers) [NS_IMPL_COCOA]: Add ns_set_appearance and ns_set_transparent_titlebar handlers. (Sx_create_frame): Handle ns-appearance and ns-transparent-titlebar frame parameters. (Qdark): Add new symbol for use with ns-appearance. * src/nsterm.h (ns_set_appearance, ns_set_transparent_titlebar) [NS_IMPL_COCOA]: Add prototypes. * src/nsterm.m (ns_set_appearance, ns_set_transparent_titlebar) [NS_IMPL_COCOA]: New functions. (initFrameFromEmacs) [NS_IMPL_COCOA]: Handle ns-appearance and ns-transparent-titlebar frame parameters. * doc/lispref/frames.texi (Window Management Parameters): Document ns-apperance and ns-transparent-titlebar. --- doc/lispref/frames.texi | 14 ++++++++++ src/frame.c | 12 +++++++++ src/frame.h | 18 +++++++++++++ src/nsfns.m | 17 +++++++++++++ src/nsterm.h | 7 +++++ src/nsterm.m | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+) diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index b430f7c6fa..1552d8f27e 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -2125,6 +2125,20 @@ Management Parameters application's window. (It is not certain this will be implemented; try it and see if it works.) @end ignore + +@vindex ns-appearance, a frame parameter +@item ns-appearance +Only available on macOS, if set to @code{dark} draw this frame's +window-system window using the `vibrant dark' theme, otherwise use the +system default. The `vibrant dark' theme can be used to set the +toolbar and scrollbars to a dark appearance when using an Emacs theme +with a dark background. + +@vindex ns-transparent-titlebar, a frame parameter +@item ns-transparent-titlebar +Only available on macOS, if non-@code{nil}, set the titlebar and +toolbar to be `transparent'. This effectively sets the background +color of both to match the Emacs background color. @end table diff --git a/src/frame.c b/src/frame.c index 1e5e4bbdb4..5099f75be4 100644 --- a/src/frame.c +++ b/src/frame.c @@ -834,6 +834,10 @@ make_frame (bool mini_p) #if ! defined (USE_GTK) && ! defined (HAVE_NS) f->last_tool_bar_item = -1; #endif +#ifdef NS_IMPL_COCOA + f->ns_appearance = ns_appearance_aqua; + f->ns_transparent_titlebar = false; +#endif #endif root_window = make_window (); @@ -3520,6 +3524,10 @@ static const struct frame_parm_table frame_parms[] = {"z-group", SYMBOL_INDEX (Qz_group)}, {"override-redirect", SYMBOL_INDEX (Qoverride_redirect)}, {"no-special-glyphs", SYMBOL_INDEX (Qno_special_glyphs)}, +#ifdef NS_IMPL_COCOA + {"ns-appearance", SYMBOL_INDEX (Qns_appearance)}, + {"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)}, +#endif }; #ifdef HAVE_WINDOW_SYSTEM @@ -5646,6 +5654,10 @@ syms_of_frame (void) #ifdef HAVE_NS DEFSYM (Qns_parse_geometry, "ns-parse-geometry"); #endif +#ifdef NS_IMPL_COCOA + DEFSYM (Qns_appearance, "ns-appearance"); + DEFSYM (Qns_transparent_titlebar, "ns-transparent-titlebar"); +#endif DEFSYM (Qalpha, "alpha"); DEFSYM (Qauto_lower, "auto-lower"); diff --git a/src/frame.h b/src/frame.h index 154dc9a3bb..4b7e448b54 100644 --- a/src/frame.h +++ b/src/frame.h @@ -65,6 +65,14 @@ enum internal_border_part INTERNAL_BORDER_BOTTOM_EDGE, INTERNAL_BORDER_BOTTOM_LEFT_CORNER, }; + +#ifdef NS_IMPL_COCOA +enum ns_appearance_type + { + ns_appearance_aqua, + ns_appearance_vibrant_dark + }; +#endif #endif /* HAVE_WINDOW_SYSTEM */ /* The structure representing a frame. */ @@ -563,6 +571,12 @@ struct frame /* All display backends seem to need these two pixel values. */ unsigned long background_pixel; unsigned long foreground_pixel; + +#ifdef NS_IMPL_COCOA + /* NSAppearance theme used on this frame. */ + enum ns_appearance_type ns_appearance; + bool_bf ns_transparent_titlebar; +#endif }; /* Most code should use these functions to set Lisp fields in struct frame. */ @@ -953,6 +967,10 @@ default_pixels_per_inch_y (void) #define FRAME_Z_GROUP_ABOVE_SUSPENDED(f) \ ((f)->z_group == z_group_above_suspended) #define FRAME_Z_GROUP_BELOW(f) ((f)->z_group == z_group_below) +#ifdef NS_IMPL_COCOA +#define FRAME_NS_APPEARANCE(f) ((f)->ns_appearance) +#define FRAME_NS_TRANSPARENT_TITLEBAR(f) ((f)->ns_transparent_titlebar) +#endif #else /* not HAVE_WINDOW_SYSTEM */ #define FRAME_UNDECORATED(f) ((void) (f), 0) #define FRAME_OVERRIDE_REDIRECT(f) ((void) (f), 0) diff --git a/src/nsfns.m b/src/nsfns.m index e19e4e2641..b00441eb79 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -985,6 +985,10 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side x_set_z_group, /* x_set_z_group */ 0, /* x_set_override_redirect */ x_set_no_special_glyphs, +#ifdef NS_IMPL_COCOA + ns_set_appearance, + ns_set_transparent_titlebar, +#endif }; @@ -1277,6 +1281,18 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side FRAME_UNDECORATED (f) = !NILP (tem) && !EQ (tem, Qunbound); store_frame_param (f, Qundecorated, FRAME_UNDECORATED (f) ? Qt : Qnil); +#ifdef NS_IMPL_COCOA + tem = x_get_arg (dpyinfo, parms, Qns_appearance, NULL, NULL, RES_TYPE_SYMBOL); + FRAME_NS_APPEARANCE (f) = EQ (tem, Qdark) + ? ns_appearance_vibrant_dark : ns_appearance_aqua; + store_frame_param (f, Qns_appearance, tem); + + tem = x_get_arg (dpyinfo, parms, Qns_transparent_titlebar, + NULL, NULL, RES_TYPE_BOOLEAN); + FRAME_NS_TRANSPARENT_TITLEBAR (f) = !NILP (tem) && !EQ (tem, Qunbound); + store_frame_param (f, Qns_transparent_titlebar, tem); +#endif + parent_frame = x_get_arg (dpyinfo, parms, Qparent_frame, NULL, NULL, RES_TYPE_SYMBOL); /* Accept parent-frame iff parent-id was not specified. */ @@ -3248,6 +3264,7 @@ - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename DEFSYM (Qfontsize, "fontsize"); DEFSYM (Qframe_title_format, "frame-title-format"); DEFSYM (Qicon_title_format, "icon-title-format"); + DEFSYM (Qdark, "dark"); DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist, doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames. diff --git a/src/nsterm.h b/src/nsterm.h index 0ac8043e26..65b7a0347a 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1210,6 +1210,13 @@ extern void x_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_value); extern void x_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value); +#ifdef NS_IMPL_COCOA +extern void ns_set_appearance (struct frame *f, Lisp_Object new_value, + Lisp_Object old_value); +extern void ns_set_transparent_titlebar (struct frame *f, + Lisp_Object new_value, + Lisp_Object old_value); +#endif extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timespec *timeout, sigset_t *sigmask); diff --git a/src/nsterm.m b/src/nsterm.m index 95092b29c8..22f8efd6b9 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -2036,6 +2036,58 @@ so some key presses (TAB) are swallowed by the system. */ error ("Invalid z-group specification"); } +#ifdef NS_IMPL_COCOA +void +ns_set_appearance (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 + EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); + NSWindow *window = [view window]; + + NSTRACE ("ns_set_appearance"); + +#ifndef NSAppKitVersionNumber10_9 +#define NSAppKitVersionNumber10_9 1265 +#endif + + if (NSAppKitVersionNumber < NSAppKitVersionNumber10_9) + return; + + if (EQ (new_value, Qdark)) + { + window.appearance = [NSAppearance + appearanceNamed: NSAppearanceNameVibrantDark]; + FRAME_NS_APPEARANCE (f) = ns_appearance_vibrant_dark; + } + else + { + window.appearance = [NSAppearance + appearanceNamed: NSAppearanceNameAqua]; + FRAME_NS_APPEARANCE (f) = ns_appearance_aqua; + } +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 */ +} + +void +ns_set_transparent_titlebar (struct frame *f, Lisp_Object new_value, + Lisp_Object old_value) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 + EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); + NSWindow *window = [view window]; + + NSTRACE ("ns_set_transparent_titlebar"); + + if ([window respondsToSelector: @selector(titlebarAppearsTransparent)] + && !EQ (new_value, old_value)) + { + window.titlebarAppearsTransparent = !NILP (new_value); + FRAME_NS_TRANSPARENT_TITLEBAR (f) = !NILP (new_value); + } +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 */ +} +#endif /* NS_IMPL_COCOA */ + static void ns_fullscreen_hook (struct frame *f) { @@ -7083,6 +7135,22 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f if (! FRAME_UNDECORATED (f)) [self createToolbar: f]; +#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 +#ifndef NSAppKitVersionNumber10_9 +#define NSAppKitVersionNumber10_9 1265 +#endif + + if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_9 + && FRAME_NS_APPEARANCE (f) != ns_appearance_aqua) + win.appearance = [NSAppearance + appearanceNamed: NSAppearanceNameVibrantDark]; +#endif + +#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 + if ([win respondsToSelector: @selector(titlebarAppearsTransparent)]) + win.titlebarAppearsTransparent = FRAME_NS_TRANSPARENT_TITLEBAR (f); +#endif + tem = f->icon_name; if (!NILP (tem)) [win setMiniwindowTitle: -- Documentation updated as requested. -- Alan Third