From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Marchionna Newsgroups: gmane.emacs.bugs Subject: bug#8680: emacs 24.0 OS X keypad patch Date: Thu, 7 Jul 2011 07:55:32 -0700 Message-ID: <5B72ABEF-9A02-4663-A109-A115BF88081C@pacbell.net> References: <625A3C9C-ACF2-42A0-B4E8-8ABDDA060131@pacbell.net> <82F88237-57F3-49B4-9EBB-DE0358BDEA53@pacbell.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1310054996 18317 80.91.229.12 (7 Jul 2011 16:09:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jul 2011 16:09:56 +0000 (UTC) Cc: 8680@debbugs.gnu.org To: Adrian Robert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 07 18:09:46 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qer97-0003IB-8n for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Jul 2011 18:09:45 +0200 Original-Received: from localhost ([::1]:49966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qer96-0005QM-43 for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Jul 2011 12:09:44 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:53717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qepzq-0002MM-7b for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2011 10:56:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qepzo-0001F9-0q for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2011 10:56:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qepzn-0001Ez-CT for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2011 10:56:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Qepzm-00072o-84; Thu, 07 Jul 2011 10:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Marchionna Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Jul 2011 14:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8680 X-GNU-PR-Package: emacs,ns X-GNU-PR-Keywords: Original-Received: via spool by 8680-submit@debbugs.gnu.org id=B8680.131005054427054 (code B ref 8680); Thu, 07 Jul 2011 14:56:02 +0000 Original-Received: (at 8680) by debbugs.gnu.org; 7 Jul 2011 14:55:44 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QepzU-00072I-4K for submit@debbugs.gnu.org; Thu, 07 Jul 2011 10:55:44 -0400 Original-Received: from nm1-vm0.access.bullet.mail.mud.yahoo.com ([66.94.236.27]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QepzR-000725-Hc for 8680@debbugs.gnu.org; Thu, 07 Jul 2011 10:55:42 -0400 Original-Received: from [66.94.237.194] by nm1.access.bullet.mail.mud.yahoo.com with NNFMP; 07 Jul 2011 14:55:35 -0000 Original-Received: from [66.94.237.102] by tm5.access.bullet.mail.mud.yahoo.com with NNFMP; 07 Jul 2011 14:55:35 -0000 Original-Received: from [127.0.0.1] by omp1007.access.mail.mud.yahoo.com with NNFMP; 07 Jul 2011 14:55:35 -0000 X-Yahoo-Newman-Id: 699888.88667.bm@omp1007.access.mail.mud.yahoo.com Original-Received: (qmail 84598 invoked from network); 7 Jul 2011 14:55:35 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=pacbell.net; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=HtDPdGXn8on9jwZsHcve2lkEiGmUmWdOklTeeALaHKagbTsN/avYKM4ngsHMwYlBAauihSH4yd/ggqZKDIv86/Oji1eeVDKsAnjTMUEdrmraCys+cIFxRj9Z+KdVEw5mA+pF/BP+owrl4aaG3ZTqQ7dp2u6u7+6WGsCnZevCHwk= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pacbell.net; s=s1024; t=1310050535; bh=X/iNLSBZua7/Yh6WaaOHoCpnCo9AUSDmxDXljzcNQyA=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=SOycCorq+4MUgV+8h3gcRxgCE1hHUpSgKhqnjAYmi5A3KYfWRtkRANT4MrhKekEa5rL8/M6VKqNxPgYcN86v1EYzZIu0bZhiEYGnXBze7h+rig1E59WD0IGBvjFeLDkMPIHFhsl6DbJ49HbduGMlbQfXdK4Fn087/lAQS6ix5qw= Original-Received: from morbo.el-rayo-x.foo (tralfaz@216.101.161.154 with plain) by smtp109.sbc.mail.bf1.yahoo.com with SMTP; 07 Jul 2011 07:55:34 -0700 PDT X-Yahoo-SMTP: uVslrc.swBAsbr9qUoHctqw_w91g6l3qy9ZsMsYbaY4- X-YMail-OSG: zqPFjrwVM1kKrH_efzxzI8hnwBOn6eU7MeeOWOO7gIQFI_z LKvA.V6v8euowTO7bWGA2ySMMFeEAdsEOOEfEa_Cmp3EjnoKR1M_sIRj6KQC P8ZJAuqCEips9YNUG5xI8IWLnsauLYSvykDR_V96SwTT8AK9TD1Fm_5i_YsP LSdxCjLUcSYhEcO21elLp4TC_xyMm_05HziHCHtb1DnvftTziU6QMfAtf4qf mo49WwMGGPxW9Jzhyn_Lb_SvEBOvXzcm7s12k4APpDSXI6so_Alp5q1h7xdY ILXPSqM0REGCZjkRRCynjJsJ9iCHn52ngZQOZOvz5LhqsaATL3MqZUFpo5k9 wMewWQ6Q8N.ILNq55iwxrrbGsdzHJ6pesjf8NiyHVQfi4CXJ7ZsmVZw.O9vC tUWRGcoX.oUdQNv63pq5_rYf9Mf5G9GNeoDnoxQqVWz7WXOKwflvKbv8rKBk VsuG0T6DR56p3lFVsu.My2WxyEpTe06cff_OhYpoRzc.Z24V0_PdEsdntJQU 4NSeKoSb7k0o- X-Yahoo-Newman-Property: ymail-3 In-Reply-To: X-Mailer: Apple Mail (2.1084) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 07 Jul 2011 10:56:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:48169 Archived-At: The reason for split between non-keypad keys and keypad keys, was that = the code generated by the following code produced coincident values that = produced non-unique results. code =3D ([[theEvent charactersIgnoringModifiers] length] =3D=3D = 0) ? 0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: = 0]; Using the first character of key event would not distinguish a "=3D" on = the main keyboard from a "=3D" on the keypad. Using the [theEvent = keyCode] in the older ns_convert_key function would mean verifying and = possibly altering all the translation values in the older table. It may be the case that this change does not properly toggle between = numeric keypad, and movement keypad, but on newer mac keyboards the = num-lock key is actually a "Clear" key, and Num-Lock behavior is = synthesized. Not sure what the best solution for making the "Clear" key = behave like a physical Num-Lock key is, but this change does allow key = event from the keypad to at least be mapped to something. Michael Marchionna On Jul 6, 2011, at 8:04 PM, Adrian Robert wrote: > The code looks reasonable, but could the author explain why [theEvent = keyCode] needs to be used in the keypad conversion instead of code? The = code would be more understandable if ns_convert_kaypad() and = ns_convert_key() used the same argument. Also this patch should be = tested for correct behavior wrt this issue: >=20 > = http://www.cocoabuilder.com/archive/cocoa/73306-workaround-for-broken-numl= ock-support.html#73306 >=20 >=20 > thanks, > Adrian >=20 >=20 > On 2011/07/04, at 13:42, Stefan Monnier wrote: >=20 >> reassign 8680 emacs,ns >> tags 8680 +patch >> thanks >>=20 >> Could someone familiar with the MacOSX code take a look at this >> bug report? >>=20 >>=20 >> Stefan >>=20 >>=20 >>>>>>> "Michael" =3D=3D Michael Marchionna = writes: >>=20 >>> Adding keypad keycodes to the existing translation table leads to = some keys >>> being wrongly interpreted as keypad keys. To avoid that, this patch >>> uses a separate translation table exclusively for keys that >>> generate a NSNumericPadKeyMask. >>=20 >>=20 >>> diff --git a/src/nsterm.m b/src/nsterm.m >>> index 91f0cbb..d537ee3 100644 >>> --- a/src/nsterm.m >>> +++ b/src/nsterm.m >>> @@ -87,6 +87,7 @@ static unsigned convert_ns_to_X_keysym[] =3D >>> NSBeginFunctionKey, 0x58, >>> NSSelectFunctionKey, 0x60, >>> NSPrintFunctionKey, 0x61, >>> + NSClearLineFunctionKey, 0x0B, >>> NSExecuteFunctionKey, 0x62, >>> NSInsertFunctionKey, 0x63, >>> NSUndoFunctionKey, 0x65, >>> @@ -134,6 +135,35 @@ static unsigned convert_ns_to_X_keysym[] =3D >>> 0x1B, 0x1B /* escape */ >>> }; >>=20 >>> +static unsigned convert_nskeypad_to_X_keysym[] =3D >>> +{ >>> + /* Arrow keys are both function and keypad keys */ >>> + NSLeftArrowFunctionKey, 0x51, >>> + NSUpArrowFunctionKey, 0x52, >>> + NSRightArrowFunctionKey, 0x53, >>> + NSDownArrowFunctionKey, 0x54, >>> + >>> + 0x41, 0xAE, /* KP_Decimal */ >>> + 0x43, 0xAA, /* KP_Multiply */ >>> + 0x45, 0xAB, /* KP_Add */ >>> + 0x4B, 0xAF, /* KP_Divide */ >>> + 0x4E, 0xAD, /* KP_Subtract */ >>> + 0x51, 0xBD, /* KP_Equal */ >>> + 0x52, 0xB0, /* KP_0 */ >>> + 0x53, 0xB1, /* KP_1 */ >>> + 0x54, 0xB2, /* KP_2 */ >>> + 0x55, 0xB3, /* KP_3 */ >>> + 0x56, 0xB4, /* KP_4 */ >>> + 0x57, 0xB5, /* KP_5 */ >>> + 0x58, 0xB6, /* KP_6 */ >>> + 0x59, 0xB7, /* KP_7 */ >>> + 0x5B, 0xB8, /* KP_8 */ >>> + 0x5C, 0xB9, /* KP_9 */ >>> + >>> + // The enter key is on the keypad but modifier isnt set >>> + NSEnterCharacter, 0x8D >>> +}; >>> + >>=20 >>> static Lisp_Object Qmodifier_value; >>> Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper, Qnone; >>> @@ -1924,13 +1954,33 @@ ns_convert_key (unsigned code) >>> unsigned keysym; >>> /* An array would be faster, but less easy to read. */ >>> for (keysym =3D 0; keysym < last_keysym; keysym +=3D 2) >>> - if (code =3D=3D convert_ns_to_X_keysym[keysym]) >>> - return 0xFF00 | convert_ns_to_X_keysym[keysym+1]; >>> + =20 >>> + if (code =3D=3D convert_ns_to_X_keysym[keysym]) { >>> + return 0xFF00 | convert_ns_to_X_keysym[keysym+1]; >>> + } >>> return 0; >>> /* if decide to use keyCode and Carbon table, use this line: >>> return code > 0xff ? 0 : 0xFF00 | = ns_keycode_to_xkeysym_table[code]; */ >>> } >>=20 >>> +static unsigned >>> +ns_convert_keypad (unsigned code) >>> +/* = --------------------------------------------------------------------------= >>> + Internal call used by NSView-keyDown. >>> + = --------------------------------------------------------------------------= */ >>> +{ >>> + const unsigned last_keysym =3D (sizeof = (convert_nskeypad_to_X_keysym) >>> + / sizeof = (convert_nskeypad_to_X_keysym[0])); >>> + unsigned keysym; >>> + /* An array would be faster, but less easy to read. */ >>> + for (keysym =3D 0; keysym < last_keysym; keysym +=3D 2) { >>> + if (code =3D=3D convert_nskeypad_to_X_keysym[keysym]) { >>> + return 0xFF00 | convert_nskeypad_to_X_keysym[keysym+1]; >>> + } >>> + } >>> + return 0; >>> +} >>> + >>=20 >>> char * >>> x_get_keysym_name (int keysym) >>> @@ -4503,10 +4553,10 @@ ns_term_shutdown (int sig) >>> Mouse_HLInfo *hlinfo =3D MOUSE_HL_INFO (emacsframe); >>> int code; >>> unsigned fnKeysym =3D 0; >>> - int flags; >>> static NSMutableArray *nsEvArray; >>> static BOOL firstTime =3D YES; >>> int left_is_none; >>> + unsigned int flags =3D [theEvent modifierFlags]; >>=20 >>> NSTRACE (keyDown); >>=20 >>> @@ -4550,9 +4600,13 @@ ns_term_shutdown (int sig) >>> code =3D ([[theEvent charactersIgnoringModifiers] length] =3D=3D = 0) ? >>> 0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: = 0]; >>> /* (Carbon way: [theEvent keyCode]) */ >>> + =20 >>=20 >>> /* is it a "function key"? */ >>> - fnKeysym =3D ns_convert_key (code); >>> + if (code < 0x00ff && (flags & NSNumericPadKeyMask) ) >>> + fnKeysym =3D ns_convert_keypad([theEvent keyCode]); >>> + else >>> + fnKeysym =3D ns_convert_key(code); >>> if (fnKeysym) >>> { >>> /* COUNTERHACK: map 'Delete' on upper-right main KB to = 'Backspace', >>> @@ -4565,7 +4619,6 @@ ns_term_shutdown (int sig) >>=20 >>> /* are there modifiers? */ >> emacs_event-> modifiers =3D 0; >>> - flags =3D [theEvent modifierFlags]; >>=20 >>> if (flags & NSHelpKeyMask) >> emacs_event-> modifiers |=3D hyper_modifier; >=20