devdraw: fix handling of compose key on OS X

This implementation is simpler to understand.  It
removes conflicts with other modifiers and with
the virtual buttons.  Pressing alt during a
sequence now cancels it correctly.

R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5507049
This commit is contained in:
David Jeannot 2012-01-16 17:08:31 -05:00 committed by Russ Cox
parent a995f469b3
commit 73b0f029e1
2 changed files with 15 additions and 12 deletions

View file

@ -98,7 +98,6 @@ struct
struct struct
{ {
NSCursor *bigarrow; NSCursor *bigarrow;
int kalting;
int kbuttons; int kbuttons;
int mbuttons; int mbuttons;
NSPoint mpos; NSPoint mpos;
@ -593,6 +592,7 @@ interpretdeadkey(NSEvent *e)
static void static void
getkeyboard(NSEvent *e) getkeyboard(NSEvent *e)
{ {
static int omod;
NSString *s; NSString *s;
char c; char c;
int k, m; int k, m;
@ -602,8 +602,6 @@ getkeyboard(NSEvent *e)
switch([e type]){ switch([e type]){
case NSKeyDown: case NSKeyDown:
in.kalting = 0;
s = [e characters]; s = [e characters];
c = [s UTF8String][0]; c = [s UTF8String][0];
@ -635,15 +633,14 @@ getkeyboard(NSEvent *e)
in.kbuttons |= 4; in.kbuttons |= 4;
sendmouse(); sendmouse();
}else }else
if(m & NSAlternateKeyMask){ if(m&NSAlternateKeyMask && (omod&NSAlternateKeyMask)==0)
in.kalting = 1;
keystroke(Kalt); keystroke(Kalt);
}
break; break;
default: default:
panic("getkey: unexpected event type"); panic("getkey: unexpected event type");
} }
omod = m;
} }
/* /*
@ -715,12 +712,8 @@ getmouse(NSEvent *e)
if(b == 1){ if(b == 1){
m = [e modifierFlags]; m = [e modifierFlags];
if(m & NSAlternateKeyMask){ if(m & NSAlternateKeyMask){
abortcompose();
b = 2; b = 2;
// Take the ALT away from the keyboard handler.
if(in.kalting){
in.kalting = 0;
keystroke(Kalt);
}
}else }else
if(m & NSCommandKeyMask) if(m & NSCommandKeyMask)
b = 4; b = 4;

View file

@ -358,15 +358,25 @@ kputc(int c)
zunlock(); zunlock();
} }
static int alting;
void
abortcompose(void)
{
if(alting)
keystroke(Kalt);
}
void void
keystroke(int c) keystroke(int c)
{ {
static Rune k[10]; static Rune k[10];
static int alting, nk; static int nk;
int i; int i;
if(c == Kalt){ if(c == Kalt){
alting = !alting; alting = !alting;
nk = 0;
return; return;
} }
if(!alting){ if(!alting){