mirror of
https://github.com/gnustep/libs-back.git
synced 2025-05-31 01:11:00 +00:00
final fixes after feedback from Kazunobu Kuriyama on previous commit - lookup keysym properly when key combinations are pressed in process_key_event; also, improve interpretation of modifier state on keymapnotify events (processEvent:)
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@20129 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b907de6f9c
commit
765884244c
1 changed files with 36 additions and 51 deletions
|
@ -127,42 +127,28 @@ static void initialize_keyboard (void);
|
||||||
|
|
||||||
static void set_up_num_lock (void);
|
static void set_up_num_lock (void);
|
||||||
|
|
||||||
// checks if given keycode is set in bit vector
|
// checks whether a GNUstep modifier (key_sym) is pressed when we're only able
|
||||||
static inline int check_key (XEvent *xEvent, KeyCode key_code)
|
// to check whether X keycodes are pressed in xEvent->xkeymap;
|
||||||
{
|
|
||||||
return (key_code == 0) ?
|
|
||||||
0 : (xEvent->xkeymap.key_vector[key_code / 8] & (1 << (key_code % 8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// checks whether a GNUstep modifier is pressed when we're only able to check
|
|
||||||
// whether X keycodes are pressed
|
|
||||||
static int check_modifier (XEvent *xEvent, KeySym key_sym,
|
static int check_modifier (XEvent *xEvent, KeySym key_sym,
|
||||||
XModifierKeymap *modmap)
|
XModifierKeymap *modmap)
|
||||||
{
|
{
|
||||||
int m;
|
char *key_vector;
|
||||||
int c;
|
int by,bi;
|
||||||
KeyCode key_code;
|
|
||||||
|
|
||||||
// if key_sym is a modifier, check each of its keycodes
|
// implementation fails if key_sym is only accessible by a multi-key
|
||||||
for (m=0; m<8; m++)
|
// combination, however this is not expected for GNUstep modifier keys;
|
||||||
{
|
// to fix implementation, would need to first determine modifier state by
|
||||||
key_code = modmap->modifiermap[m * modmap->max_keypermod];
|
// a first-pass scann of the full key vector, then use the state in place
|
||||||
if ((key_code != 0)
|
// of "0" below in XKeycodeToKeysym
|
||||||
&& XKeycodeToKeysym(xEvent->xkeymap.display, key_code, 0) == key_sym)
|
key_vector = xEvent->xkeymap.key_vector;
|
||||||
{
|
for (by=0; by<32; by++) {
|
||||||
for (c=0; c<modmap->max_keypermod; c++)
|
for (bi=0; bi<8; bi++) {
|
||||||
{
|
if ((key_vector[by] & (1 << bi)) &&
|
||||||
if (check_key(xEvent,
|
(XKeycodeToKeysym(xEvent->xkeymap.display,by*8+bi,0)==key_sym))
|
||||||
modmap->modifiermap[m * modmap->max_keypermod + c]))
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
return 0; // no dice
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wasn't a modifier; just check the first keycode for this keysym,
|
return 0;
|
||||||
// which ignores other possibilities but that's the best we can do
|
|
||||||
// w/o XtKeysymToKeycodeList
|
|
||||||
return check_key(xEvent, XKeysymToKeycode(xEvent->xkeymap.display, key_sym));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation XGServer (EventOps)
|
@implementation XGServer (EventOps)
|
||||||
|
@ -1554,10 +1540,30 @@ process_key_event (XEvent* xEvent, XGServer* context, NSEventType eventType)
|
||||||
if (_is_keyboard_initialized == NO)
|
if (_is_keyboard_initialized == NO)
|
||||||
initialize_keyboard ();
|
initialize_keyboard ();
|
||||||
|
|
||||||
|
/* Process location */
|
||||||
|
window = [XGServer _windowWithTag: [[NSApp keyWindow] windowNumber]];
|
||||||
|
eventLocation.x = xEvent->xbutton.x;
|
||||||
|
if (window)
|
||||||
|
{
|
||||||
|
eventLocation.y = window->siz_hints.height - xEvent->xbutton.y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventLocation.y = xEvent->xbutton.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process characters */
|
||||||
|
keys = [context->inputServer lookupStringForEvent: (XKeyEvent *)xEvent
|
||||||
|
window: window
|
||||||
|
keysym: &keysym];
|
||||||
|
|
||||||
|
/* Process keycode */
|
||||||
|
keyCode = ((XKeyEvent *)xEvent)->keycode;
|
||||||
|
//ximKeyCode = XKeysymToKeycode([XGServer currentXDisplay],keysym);
|
||||||
|
|
||||||
/* Process NSFlagsChanged events. We can't use a switch because we
|
/* Process NSFlagsChanged events. We can't use a switch because we
|
||||||
are not comparing to constants. Make sure keyCode is not 0 since
|
are not comparing to constants. Make sure keyCode is not 0 since
|
||||||
XIM events can potentially return 0 keyCodes. */
|
XIM events can potentially return 0 keyCodes. */
|
||||||
keysym = XLookupKeysym((XKeyEvent *)xEvent, 0);
|
|
||||||
if (keysym != NoSymbol)
|
if (keysym != NoSymbol)
|
||||||
{
|
{
|
||||||
if (keysym == _control_keysyms[0])
|
if (keysym == _control_keysyms[0])
|
||||||
|
@ -1613,27 +1619,6 @@ process_key_event (XEvent* xEvent, XGServer* context, NSEventType eventType)
|
||||||
/* Process modifiers */
|
/* Process modifiers */
|
||||||
eventFlags = process_modifier_flags (xEvent->xkey.state);
|
eventFlags = process_modifier_flags (xEvent->xkey.state);
|
||||||
|
|
||||||
/* Process location */
|
|
||||||
window = [XGServer _windowWithTag: [[NSApp keyWindow] windowNumber]];
|
|
||||||
eventLocation.x = xEvent->xbutton.x;
|
|
||||||
if (window)
|
|
||||||
{
|
|
||||||
eventLocation.y = window->siz_hints.height - xEvent->xbutton.y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eventLocation.y = xEvent->xbutton.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Process characters */
|
|
||||||
keys = [context->inputServer lookupStringForEvent: (XKeyEvent *)xEvent
|
|
||||||
window: window
|
|
||||||
keysym: &keysym];
|
|
||||||
|
|
||||||
/* Process keycode */
|
|
||||||
keyCode = ((XKeyEvent *)xEvent)->keycode;
|
|
||||||
//ximKeyCode = XKeysymToKeycode([XGServer currentXDisplay],keysym);
|
|
||||||
|
|
||||||
/* Add NSNumericPadKeyMask if the key is in the KeyPad */
|
/* Add NSNumericPadKeyMask if the key is in the KeyPad */
|
||||||
if (IsKeypadKey (keysym))
|
if (IsKeypadKey (keysym))
|
||||||
eventFlags = eventFlags | NSNumericPadKeyMask;
|
eventFlags = eventFlags | NSNumericPadKeyMask;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue