all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Marchionna <tralfaz@pacbell.net>
To: Adrian Robert <adrian.b.robert@gmail.com>
Cc: 8680@debbugs.gnu.org
Subject: bug#8680: emacs 24.0 OS X keypad patch
Date: Thu, 7 Jul 2011 07:55:32 -0700	[thread overview]
Message-ID: <5B72ABEF-9A02-4663-A109-A115BF88081C@pacbell.net> (raw)
In-Reply-To: <A489D4C4-D353-4CD8-9D76-8868D5452214@gmail.com>

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 = ([[theEvent charactersIgnoringModifiers] length] == 0) ?
        0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: 0];

Using the first character of key event would not distinguish a "=" on the main keyboard from a "=" 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:
> 
> http://www.cocoabuilder.com/archive/cocoa/73306-workaround-for-broken-numlock-support.html#73306
> 
> 
> thanks,
> Adrian
> 
> 
> On 2011/07/04, at 13:42, Stefan Monnier wrote:
> 
>> reassign 8680 emacs,ns
>> tags 8680 +patch
>> thanks
>> 
>> Could someone familiar with the MacOSX code take a look at this
>> bug report?
>> 
>> 
>>       Stefan
>> 
>> 
>>>>>>> "Michael" == Michael Marchionna <tralfaz@pacbell.net> writes:
>> 
>>> 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.
>> 
>> 
>>> 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[] =
>>>  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[] =
>>>  0x1B,				0x1B   /* escape */
>>> };
>> 
>>> +static unsigned convert_nskeypad_to_X_keysym[] =
>>> +{
>>> +  /* 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
>>> +};
>>> +
>> 
>>> 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 = 0; keysym < last_keysym; keysym += 2)
>>> -    if (code == convert_ns_to_X_keysym[keysym])
>>> -      return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
>>> +      
>>> +      if (code == 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]; */
>>> }
>> 
>>> +static unsigned
>>> +ns_convert_keypad (unsigned code)
>>> +/* --------------------------------------------------------------------------
>>> +    Internal call used by NSView-keyDown.
>>> +   -------------------------------------------------------------------------- */
>>> +{
>>> +  const unsigned last_keysym = (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 = 0; keysym < last_keysym; keysym += 2) {
>>> +      if (code == convert_nskeypad_to_X_keysym[keysym]) {
>>> +        return 0xFF00 | convert_nskeypad_to_X_keysym[keysym+1];
>>> +      }
>>> +  }
>>> +  return 0;
>>> +}
>>> +
>> 
>>> char *
>>> x_get_keysym_name (int keysym)
>>> @@ -4503,10 +4553,10 @@ ns_term_shutdown (int sig)
>>>  Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (emacsframe);
>>>  int code;
>>>  unsigned fnKeysym = 0;
>>> -  int flags;
>>>  static NSMutableArray *nsEvArray;
>>>  static BOOL firstTime = YES;
>>>  int left_is_none;
>>> +  unsigned int flags = [theEvent modifierFlags];
>> 
>>>  NSTRACE (keyDown);
>> 
>>> @@ -4550,9 +4600,13 @@ ns_term_shutdown (int sig)
>>>      code = ([[theEvent charactersIgnoringModifiers] length] == 0) ?
>>>        0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: 0];
>>>      /* (Carbon way: [theEvent keyCode]) */
>>> +      
>> 
>>>      /* is it a "function key"? */
>>> -      fnKeysym = ns_convert_key (code);
>>> +      if (code < 0x00ff && (flags & NSNumericPadKeyMask) )
>>> +	fnKeysym = ns_convert_keypad([theEvent keyCode]);
>>> +      else
>>> +	fnKeysym = 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)
>> 
>>>      /* are there modifiers? */
>> emacs_event-> modifiers = 0;
>>> -      flags = [theEvent modifierFlags];
>> 
>>>      if (flags & NSHelpKeyMask)
>> emacs_event-> modifiers |= hyper_modifier;
> 






  reply	other threads:[~2011-07-07 14:55 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-17  5:07 bug#8680: Cocoa Emacs not mapping Clear key on aluminum keyboards Michael Marchionna
2011-05-17 17:34 ` bug#8680: nsterm.m does not distinguish key on the key pad Michael Marchionna
2012-11-04  3:34   ` Chong Yidong
2011-05-23 20:11 ` bug#8680: emacs 24.0 OS X keypad patch Michael Marchionna
2011-07-04 17:42   ` Stefan Monnier
2011-07-07  3:04     ` Adrian Robert
2011-07-07 14:55       ` Michael Marchionna [this message]
2013-12-10 22:13 ` bug#8680: Bug #8680 Andrew Stein
2013-12-10 22:40   ` bug#8680: Glenn Morris
2013-12-10 22:54     ` bug#8680: Andrew Stein
2013-12-11  4:53       ` bug#8680: Stefan Monnier
2013-12-12  0:48         ` bug#8680: Leo Liu
2013-12-13 21:50           ` bug#8680: releases Juri Linkov
2013-12-19  3:00             ` Leo Liu
2013-12-19 13:43               ` Stefan Monnier
2013-12-19 17:12                 ` Glenn Morris
2013-12-19 18:09                   ` The next releases Stefan Monnier
2013-12-19 21:22                     ` Stefan Monnier
2013-12-19 22:31                       ` Bastien
2013-12-20  2:12                         ` Stefan Monnier
2013-12-22  0:54                       ` Xue Fuqiao
2013-12-23  0:57                         ` Glenn Morris
2013-12-23  1:37                           ` Ted Zlatanov
2013-12-23  3:11                             ` Glenn Morris
2013-12-23  3:47                               ` Glenn Morris
2013-12-23 13:05                               ` Ted Zlatanov
2013-12-20  7:25                     ` Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5B72ABEF-9A02-4663-A109-A115BF88081C@pacbell.net \
    --to=tralfaz@pacbell.net \
    --cc=8680@debbugs.gnu.org \
    --cc=adrian.b.robert@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.