From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#44973: Add a macOS global hotkey function Date: Wed, 30 Dec 2020 11:01:09 +0000 Message-ID: References: <874kkw9gmq.fsf@gnus.org> <87lfdrhj4e.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37005"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 44973@debbugs.gnu.org, Lars Ingebrigtsen To: j@mremus.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 30 12:02:23 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 1kuZFE-0009UC-LC for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 12:02:20 +0100 Original-Received: from localhost ([::1]:38480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuZFD-0000fg-Lg for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 06:02:19 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuZEw-0000da-Ry for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 06:02:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kuZEw-00012z-1O for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 06:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kuZEv-0006si-UW for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 06:02:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Dec 2020 11:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44973 X-GNU-PR-Package: emacs Original-Received: via spool by 44973-submit@debbugs.gnu.org id=B44973.160932608224374 (code B ref 44973); Wed, 30 Dec 2020 11:02:01 +0000 Original-Received: (at 44973) by debbugs.gnu.org; 30 Dec 2020 11:01:22 +0000 Original-Received: from localhost ([127.0.0.1]:41986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuZEH-0006Kk-Sj for submit@debbugs.gnu.org; Wed, 30 Dec 2020 06:01:22 -0500 Original-Received: from outbound.soverin.net ([116.202.65.218]:37561) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuZEF-0006DC-5i for 44973@debbugs.gnu.org; Wed, 30 Dec 2020 06:01:20 -0500 Original-Received: from smtp.soverin.net (unknown [10.10.3.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 461056008F; Wed, 30 Dec 2020 11:01:12 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.142]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1609326071; bh=F6tzm8I1E+JhFz0OtbEfGjbRkTeK6a/7JdfbuoB0VAE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GVjaEkqv+fPUEpVWHKV1fH/YEt4SwioeD6PgpvpxaXtoH5DDTEydH5DXqcFP5VtgO c2EHuHFV+w748R742q2QtaggwoQHGKS0WPTgUrS1aUcQP2dJVTKTVx7coM+1iYrHXQ neCArSZYxiffN08D24ijfoHxkdhU5q6XC9QoGympl1Ue4YccYcBAzQq0MsYlycXoGI VS1NGICE99OEQnB8qS2z75RJj0MB4E6ScmDw01I+mdQ9YAKeVKDRg+Sm54eZPvQgNT R42eSMfdJDeCqJoGIdDKbp/6P0uV4cPG9/hN3QL+tTQ/wRitzRIfI3NwaDc6dBVjtd mU1pug3PsGW6g== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 86F66202952A37; Wed, 30 Dec 2020 11:01:09 +0000 (GMT) Mail-Followup-To: Alan Third , j@mremus.net, Lars Ingebrigtsen , 44973@debbugs.gnu.org Content-Disposition: inline In-Reply-To: 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:197018 Archived-At: On Tue, Dec 29, 2020 at 08:10:00PM -0800, j@mremus.net wrote: > Here is the patch to bind a global hotkey in mac. As long as Emacs is set as > "trusted" in macOS preferences, the user can bind a two-key hotkey of the > form [modifier-key] or a single-key modifier [function key], for example > (mac-bind-global-hotkey [f1] 'tetris). Binding a three-key > combo is left to a future patch. Hi, thanks for this. I'll leave it up to Lars and Eli whether this gets to go in, but I've got a few comments: +;; Copyright (C) 1993-1994, 2005-2020 Free Software Foundation, Inc. Since this is a new file I'm pretty sure we just specify 2020 for copyright. +const char *const lispy_to_mac_function_keys[] = + { + "up", "down", "left", "right", /* NSUpArrowfunctionKey 0xF700 */ + "f1", "f2", "f3", "f4", "f5", /* NSF1FunctionKey 0xF704 */ + "f6", "f7", "f8", "f9", "f10", I take it's not possible to use the existing keyboard IO stuff for this? Like convert_ns_to_X_keysym? +mac_parse_and_add_hotkey (Lisp_Object key, Lisp_Object lispfn, int hook) ^^^ We don't use mac_ in the NS port, we use ns_. I realise this code is mac specific, but I'd rather not add a new function name prefix, not least because it's possible it will interfere with the Mac port's code, but also we may want to extend this functionality to GNUstep in the future (although that seems unlikely right now). It also means it's easy to see all the lisp functions that relate to the NS port by doing something like M-x ns-. If you're copying functionality from the Mac port feel free to set up an alias, but please use ns for the function names. + || ((lisp_modifiers & ctrl_modifier) + && EQ (ns_command_modifier, Qcontrol)) + ) ^^^ I don't think we leave closing parens hanging like that, just stick it on the end of the previous line, please. doc: /* Bind KEY combination as a global hotkey, and run HOOK upon +invokation. This function assigns a hotkey that will run an elisp function ^^^^^^^^^^ invocation +mac_bind_key (NSEventModifierFlags modifier, unsigned vkey, You might want to call this something like ns_bind_global_hotkey so it's clearer what it does, and a short descriptive comment wouldn't go amiss. + hotkey_ids = [[NSMutableArray alloc] initWithCapacity: 1]; You're allocing this array, but not releasing it anywhere. + if (trusted) { ^^^ Opening brace should be on a new line. This function (mac_bind_key) needs this fix in a few places. + if([[event.charactersIgnoringModifiers capitalizedString] ^^^ Missing space. We could also do with some documentation. One thing I'm unsure about is that we allow users to map the left and right modifier keys separately but I think your code only allows for matching with left key settings. Is that intentional? It would seem unlikely that macOS would let us map global hotkeys to the left and right keys separately, so I understand if it's not possible. -- Alan Third