From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#44333: 27.1; macOS menu bar 2-clicks Date: Sun, 27 Dec 2020 18:14:25 +0100 Message-ID: References: <20201031150101.GN59267@breton.holly.idiocy.org> <6F053CD0-A164-490F-9D15-225D8782C633@acm.org> <20201101172843.GQ59267@breton.holly.idiocy.org> <40B4784A-74FF-4021-B51C-2E80801483BE@acm.org> <44D6C180-9C74-4B2D-BCB8-683FC4A84091@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_93100978-9868-4C2F-AACB-81DD67F47D30" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21297"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 44333@debbugs.gnu.org, Viktor Kharitonovich To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 27 18:15:11 2020 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 1ktZdO-0005Mx-SI for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 27 Dec 2020 18:15:11 +0100 Original-Received: from localhost ([::1]:41750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktZdN-0006bB-UD for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 27 Dec 2020 12:15:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktZdG-0006b5-OJ for bug-gnu-emacs@gnu.org; Sun, 27 Dec 2020 12:15:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ktZdG-0005Am-GR for bug-gnu-emacs@gnu.org; Sun, 27 Dec 2020 12:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ktZdG-0006XQ-An for bug-gnu-emacs@gnu.org; Sun, 27 Dec 2020 12:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 27 Dec 2020 17:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44333 X-GNU-PR-Package: emacs Original-Received: via spool by 44333-submit@debbugs.gnu.org id=B44333.160908927825085 (code B ref 44333); Sun, 27 Dec 2020 17:15:02 +0000 Original-Received: (at 44333) by debbugs.gnu.org; 27 Dec 2020 17:14:38 +0000 Original-Received: from localhost ([127.0.0.1]:33384 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ktZcr-0006WW-Fs for submit@debbugs.gnu.org; Sun, 27 Dec 2020 12:14:38 -0500 Original-Received: from mail1450c50.megamailservers.eu ([91.136.14.50]:37732 helo=mail265c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ktZcp-0006WH-E6 for 44333@debbugs.gnu.org; Sun, 27 Dec 2020 12:14:36 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1609089268; bh=sE3fObDJTYjob8VGjPgLqK/qPjoORp3dzWQieL/4N4g=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=CHm0wKn88IGfvv0lskvVnWjbgjqgtizhCFAaKwAncTbLNT2ELOOkejUaQirXTTqdU 2buIwnNP3q149ObLLA/vFluC0K5JcCn2WyTaIlQSRq9PSAyIR+x4k40QXXzyGOnx9E mVtTtrK7og1euOJnArWxNku7kEl6FDSi6cvcxq+w= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.comhem.se [188.150.171.71]) (authenticated bits=0) by mail265c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 0BRHEQEP029417; Sun, 27 Dec 2020 17:14:27 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.17) X-CTCH-RefID: str=0001.0A742F19.5FE8C0F4.0023, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=QoAgIm6d c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=M51BFTxLslgA:10 a=hIj89exaAAAA:8 a=anMcQ69C1EZOHEeKvVoA:9 a=QEXdDO2ut3YA:10 a=tpF0QAhZnqjl15_envsA:9 a=De_Ol2h6w80A:10 a=lS9wXHQM5UdnNJ4u63Ry:22 X-Origin-Country: SE 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:196805 Archived-At: --Apple-Mail=_93100978-9868-4C2F-AACB-81DD67F47D30 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 26 dec. 2020 kl. 22.52 skrev Alan Third : > It's actually almost possible to copy the Mac port code in verbatim, > the NS port's code is based on it after all, but I feel it may be > neater to use a custom view for the NSMenuItems. That would give us > complete control over the layout. We should, but because I was lazy and impatient, I wrote the attached = (terrible) hack just to see what right-justification would look like. The right margin is slightly ragged because I'm using plain spaces to = offset the key binding from the menu text, but I still think it's better = than what we have now. I tried using U+2009 THIN SPACE and even U+200A = HAIR SPACE instead but somehow the result became worse; no doubt a silly = mistake somewhere. I also removed the special hack for s- bindings because it broke the = nice alignment. If we want, we could translate modifiers into the = standard symbols (=E2=8C=98, =E2=8C=83, =E2=87=A7 and =E2=8C=A5) = depending on these are assigned, or just keep using the Emacs notation. = We could also translate into =E2=86=92 and so on. --Apple-Mail=_93100978-9868-4C2F-AACB-81DD67F47D30 Content-Disposition: attachment; filename=right-justify-keys.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="right-justify-keys.diff" Content-Transfer-Encoding: 7bit diff --git a/src/nsmenu.m b/src/nsmenu.m index b5d0821323..f985234643 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -498,9 +498,16 @@ - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr keyEq = [self parseKeyEquiv: wv->key]; #ifdef NS_IMPL_COCOA /* macOS mangles modifier strings longer than one character. */ - if (keyEquivModMask == 0) + if (1 || keyEquivModMask == 0) { - title = [title stringByAppendingFormat: @" (%@)", keyEq]; + if (wv->key) + { + const char *k = wv->key; + while (*k == ' ') k++; + title = [title stringByAppendingString: + [NSString stringWithUTF8String: k]]; + } + //title = [title stringByAppendingString: keyEq]; item = [self addItemWithTitle: (NSString *)title action: @selector (menuDown:) keyEquivalent: @""]; @@ -514,7 +521,7 @@ - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr #ifdef NS_IMPL_COCOA } #endif - [item setKeyEquivalentModifierMask: keyEquivModMask]; + //[item setKeyEquivalentModifierMask: keyEquivModMask]; [item setEnabled: wv->enabled]; @@ -556,14 +563,67 @@ - (void)fillWithWidgetValue: (void *)wvptr - (void)fillWithWidgetValue: (void *)wvptr { - widget_value *wv = (widget_value *)wvptr; + widget_value *first_wv = (widget_value *)wvptr; + NSFont *menuFont = [NSFont menuFontOfSize:0]; + NSDictionary *attributes = + [NSDictionary dictionaryWithObject:menuFont forKey:NSFontAttributeName]; + const char space_str[] = " "; + int space_bytes = sizeof space_str - 1; + NSSize spaceSize = [[NSString stringWithUTF8String: space_str] + sizeWithAttributes:attributes]; + CGFloat spaceWidth = spaceSize.width; + CGFloat maxNameWidth = 0; + CGFloat maxKeyWidth = 0; + + for (widget_value *wv = first_wv; wv != NULL; wv = wv->next) + if (!menu_separator_name_p (wv->name)) + { + NSString *name = [NSString stringWithUTF8String: wv->name]; + NSSize nameSize = [name sizeWithAttributes: attributes]; + CGFloat nameWidth = nameSize.width; + maxNameWidth = MAX(maxNameWidth, nameWidth); + if (wv->key) + { + const char *k = wv->key; + while (*k == ' ') k++; + NSString *key = [NSString stringWithUTF8String: k]; + NSSize keySize = [key sizeWithAttributes: attributes]; + CGFloat keyWidth = keySize.width; + maxKeyWidth = MAX(maxKeyWidth, keyWidth); + } + } /* clear existing contents */ [self removeAllItems]; /* add new contents */ - for (; wv != NULL; wv = wv->next) + for (widget_value *wv = first_wv; wv != NULL; wv = wv->next) { + if (wv->key && !menu_separator_name_p (wv->name)) + { + NSString *name = [NSString stringWithUTF8String: wv->name]; + NSSize nameSize = [name sizeWithAttributes: attributes]; + CGFloat nameWidth = nameSize.width; + const char *k = wv->key; + while (*k == ' ') k++; + NSString *key = [NSString stringWithUTF8String: k]; + NSSize keySize = [key sizeWithAttributes: attributes]; + CGFloat keyWidth = keySize.width; + CGFloat padWidth = (maxNameWidth - nameWidth) + + (maxKeyWidth - keyWidth); + int name_len = strlen (wv->name); + int extra_spaces = 7; + int pad_len = lround(padWidth / spaceWidth + extra_spaces); + Lisp_Object s = make_uninit_string (name_len + pad_len * space_bytes); + memcpy (SSDATA (s), wv->name, name_len); + if (space_bytes == 1) + memset (SDATA (s) + name_len, space_str[0], pad_len); + else + for (int i = 0; i < pad_len; i++) + memcpy (SDATA (s) + name_len + i * space_bytes, space_str, + space_bytes); + wv->name = SSDATA (s); + } NSMenuItem *item = [self addItemWithWidgetValue: wv]; if (wv->contents) --Apple-Mail=_93100978-9868-4C2F-AACB-81DD67F47D30--