Ticket #2505: pearpc-x11-kbd.diff

File pearpc-x11-kbd.diff, 6.3 KB (added by shadow@…, 20 years ago)

x11 keyboard fix for pearpc

  • src/system/ui/x11/sysx11.cc

    RCS file: /cvsroot/pearpc/pearpc/src/system/ui/x11/sysx11.cc,v
    retrieving revision 1.17
    diff -u -r1.17 sysx11.cc
     
    44 *
    55 *      Copyright (C) 1999-2002 Stefan Weyergraf
    66 *      Copyright (C) 1999-2004 Sebastian Biallas (sb@biallas.net)
     7 *      Portions Copyright (C) 2004 Apple Computer, Inc.
    78 *
    89 *      This program is free software; you can redistribute it and/or modify
    910 *      it under the terms of the GNU General Public License version 2 as
     
    4243Display *       gX11Display = NULL;
    4344Window          gX11Window;
    4445
    45 static uint8 x11_key_to_adb_key[256] = {
    46         // 0    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    47         0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x35,0x12,0x13,0x14,0x15,0x17,0x16,
    48         0x1a,0x1c,0x19,0x1d,0x1b,0x18,0x33,0x30,0x0c,0x0d,0x0e,0x0f,0x11,0x10,0x20,0x22,
    49         0x1f,0x23,0x21,0x1e,0x24,0x36,0x00,0x01,0x02,0x03,0x05,0x04,0x26,0x28,0x25,0x29,
    50         0x27,0x32,0x38,0x2a,0x06,0x07,0x08,0x09,0x0b,0x2d,0x2e,0x2b,0x2f,0x2c,0x38,0x43,
    51         0x37,0x31,0xff,0x7a,0x78,0x63,0x76,0x60,0x61,0x62,0x64,0x65,0x6d,0x47,0xff,0x59,
    52         0x5b,0x5c,0x4e,0x56,0x57,0x58,0x45,0x53,0x54,0x55,0x52,0x41,0xff,0xff,0x0a,0x67,
    53         0x6f,0x73,0x3e,0x74,0x3b,0xff,0x3c,0x77,0x3d,0x79,0x72,0x75,0x4c,0x36,0xff,0xff,
    54         0x4b,0x3a,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     46static uint8 x11_latin1_keysym_to_adb_key[256] = {
     47        // Latin 1   Upper Byte = 0x00
     48        // 0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
    5549        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
    5650        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     51        0x31,0xff,0xff,0xff,0xff,0xff,0xff,0x27,0xff,0xff,0xff,0xff,0x2b,0x1b,0x2f,0x2c,
     52        0x1d,0x12,0x13,0x14,0x15,0x17,0x16,0x1a,0x1c,0x19,0xff,0x29,0xff,0x18,0xff,0xff,
    5753        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     54        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x21,0x2a,0x1e,0xff,0xff,
     55        0x32,0x00,0x0b,0x08,0x02,0x0e,0x03,0x05,0x04,0x22,0x26,0x28,0x25,0x2e,0x2d,0x1f,
     56        0x23,0x0c,0x0f,0x01,0x11,0x20,0x09,0x0d,0x07,0x10,0x06,0xff,0xff,0xff,0xff,0xff,
    5857        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
    5958        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
    6059        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
    6160        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
    6261        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     62        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     63        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     64        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
     65};
     66
     67static uint8 x11_function_keysym_to_adb_key[256] = {
     68        // Upper byte = 0xff
     69        // 0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
     70        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x33,0x30,0xff,0xff,0xff,0x24,0xff,0xff,
     71        0xff,0xff,0xff,0x71,0x6b,0xff,0xff,0xff,0xff,0xff,0xff,0x35,0xff,0xff,0xff,0xff,
     72        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     73        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     74        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     75        0x73,0x3b,0x3e,0x3c,0x3d,0x74,0x79,0x77,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     76        0xff,0xff,0xff,0x72,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     77        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x47,
     78        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x4c,0xff,0xff,
     79        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     80        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x43,0x45,0xff,0x4e,0x41,0x4b,
     81        0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5b,0x5c,0xff,0xff,0xff,0xff,0x7a,0x78,
     82        0x63,0x76,0x60,0x61,0x62,0x64,0x65,0x6d,0x67,0x6f,0x69,0xff,0xff,0xff,0xff,0xff,
     83        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     84        0xff,0x38,0x38,0x36,0x36,0x39,0xff,0xff,0xff,0x37,0x37,0xff,0xff,0xff,0xff,0xff,
     85        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    6386};
    6487
    6588static void handleX11Event(const XEvent &event)
     
    7699                gDisplay->displayShow();
    77100                break;
    78101        case KeyRelease: {
    79                 char buffer[4];
    80102                SystemEvent ev;
    81                 XComposeStatus compose;
    82103                KeySym keysym;
    83104
    84                 ev.key.keycode = x11_key_to_adb_key[event.xkey.keycode];
     105                sys_lock_mutex(gX11Mutex);
     106                keysym = XLookupKeysym((XKeyEvent*)&event, 0);
     107                sys_unlock_mutex(gX11Mutex);
     108                if ((keysym & 0xff00) == 0xff00) {
     109                        ev.key.keycode = x11_function_keysym_to_adb_key[keysym & 0x00ff];
     110                } else if ((keysym & 0xff00) == 0x0000) {
     111                        ev.key.keycode = x11_latin1_keysym_to_adb_key[keysym & 0x00ff];
     112                } else {
     113                        ev.key.keycode = 0xff;
     114                }
     115
    85116                if ((ev.key.keycode & 0xff) == 0xff) break;
    86117                ev.type = sysevKey;
    87118                ev.key.pressed = false;
    88119
    89                 sys_lock_mutex(gX11Mutex);
    90                 XLookupString((XKeyEvent*)&event, buffer, sizeof buffer, &keysym, &compose);
    91                 sys_unlock_mutex(gX11Mutex);
    92                 ev.key.chr = buffer[0];
    93 
    94120                gKeyboard->handleEvent(ev);
    95121                break;
    96122        }
    97123        case KeyPress: {
    98                 char buffer[4];
    99                 XComposeStatus compose;
    100124                KeySym keysym;
    101 
    102125                SystemEvent ev;
    103                 ev.key.keycode = x11_key_to_adb_key[event.xkey.keycode];
    104                 if ((ev.key.keycode & 0xff) == 0xff) break;
    105                 ev.type = sysevKey;
    106                 ev.key.pressed = true;
    107                 ev.key.keycode = x11_key_to_adb_key[event.xkey.keycode];
    108126
    109127                sys_lock_mutex(gX11Mutex);
    110                 XLookupString((XKeyEvent*)&event, buffer, sizeof buffer, &keysym, &compose);
     128                keysym = XLookupKeysym((XKeyEvent*)&event, 0);
    111129                sys_unlock_mutex(gX11Mutex);
    112                 ev.key.chr = buffer[0];
     130                if ((keysym & 0xff00) == 0xff00) {
     131                        ev.key.keycode = x11_function_keysym_to_adb_key[keysym & 0x00ff];
     132                } else if ((keysym & 0xff00) == 0x0000) {
     133                        ev.key.keycode = x11_latin1_keysym_to_adb_key[keysym & 0x00ff];
     134                } else {
     135                        ev.key.keycode = 0xff;
     136                }
     137
     138                if ((ev.key.keycode & 0xff) == 0xff) break;
     139                ev.type = sysevKey;
     140                ev.key.pressed = true;
    113141
    114142                gKeyboard->handleEvent(ev);
    115143                break;