1/*
2 * Copyright (c) 2002-2003 by The XFree86 Project, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Except as contained in this notice, the name of the copyright holder(s)
23 * and author(s) shall not be used in advertising or otherwise to promote
24 * the sale, use or other dealings in this Software without prior written
25 * authorization from the copyright holder(s) and author(s).
26 */
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <xorg-server.h>
33#include "xf86.h"
34#include "xf86Xinput.h"
35#include "xf86OSKbd.h"
36#include "atKeynames.h"
37
38Bool
39ATScancode(InputInfoPtr pInfo, int *scanCode)
40{
41    KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
42
43    switch (pKbd->scanPrefix) {
44       case 0:
45          switch (*scanCode) {
46             case KEY_Prefix0:
47             case KEY_Prefix1:
48                  pKbd->scanPrefix = *scanCode;  /* special prefixes */
49                  return TRUE;
50          }
51          switch (*scanCode) {
52             case 0x59: *scanCode = KEY_0x59; break;
53             case 0x5a: *scanCode = KEY_0x5A; break;
54             case 0x5b: *scanCode = KEY_0x5B; break;
55             case 0x5c: *scanCode = KEY_KP_Equal; break; /* Keypad Equal */
56             case 0x5d: *scanCode = KEY_0x5D; break;
57             case 0x5e: *scanCode = KEY_0x5E; break;
58             case 0x5f: *scanCode = KEY_0x5F; break;
59             case 0x62: *scanCode = KEY_0x62; break;
60             case 0x63: *scanCode = KEY_0x63; break;
61             case 0x64: *scanCode = KEY_0x64; break;
62             case 0x65: *scanCode = KEY_0x65; break;
63             case 0x66: *scanCode = KEY_0x66; break;
64             case 0x67: *scanCode = KEY_0x67; break;
65             case 0x68: *scanCode = KEY_0x68; break;
66             case 0x69: *scanCode = KEY_0x69; break;
67             case 0x6a: *scanCode = KEY_0x6A; break;
68             case 0x6b: *scanCode = KEY_0x6B; break;
69             case 0x6c: *scanCode = KEY_0x6C; break;
70             case 0x6d: *scanCode = KEY_0x6D; break;
71             case 0x6e: *scanCode = KEY_0x6E; break;
72             case 0x6f: *scanCode = KEY_0x6F; break;
73             case 0x70: *scanCode = KEY_0x70; break;
74             case 0x71: *scanCode = KEY_0x71; break;
75             case 0x72: *scanCode = KEY_0x72; break;
76             case 0x73: *scanCode = KEY_0x73; break;
77             case 0x74: *scanCode = KEY_0x74; break;
78             case 0x75: *scanCode = KEY_0x75; break;
79             case 0x76: *scanCode = KEY_0x76; break;
80          }
81          break;
82       case KEY_Prefix0:
83          pKbd->scanPrefix = 0;
84          switch (*scanCode) {
85            case KEY_KP_7:        *scanCode = KEY_Home;      break;  /* curs home */
86            case KEY_KP_8:        *scanCode = KEY_Up;        break;  /* curs up */
87            case KEY_KP_9:        *scanCode = KEY_PgUp;      break;  /* curs pgup */
88            case KEY_KP_4:        *scanCode = KEY_Left;      break;  /* curs left */
89            case KEY_KP_5:        *scanCode = KEY_Begin;     break;  /* curs begin */
90            case KEY_KP_6:        *scanCode = KEY_Right;     break;  /* curs right */
91            case KEY_KP_1:        *scanCode = KEY_End;       break;  /* curs end */
92            case KEY_KP_2:        *scanCode = KEY_Down;      break;  /* curs down */
93            case KEY_KP_3:        *scanCode = KEY_PgDown;    break;  /* curs pgdown */
94            case KEY_KP_0:        *scanCode = KEY_Insert;    break;  /* curs insert */
95            case KEY_KP_Decimal:  *scanCode = KEY_Delete;    break;  /* curs delete */
96            case KEY_Enter:       *scanCode = KEY_KP_Enter;  break;  /* keypad enter */
97            case KEY_LCtrl:       *scanCode = KEY_RCtrl;     break;  /* right ctrl */
98            case KEY_KP_Multiply: *scanCode = KEY_Print;     break;  /* print */
99            case KEY_Slash:       *scanCode = KEY_KP_Divide; break;  /* keyp divide */
100            case KEY_Alt:         *scanCode = KEY_AltLang;   break;  /* right alt */
101            case KEY_ScrollLock:  *scanCode = KEY_Break;     break;  /* curs break */
102            case 0x5b:            *scanCode = KEY_LMeta;     break;
103            case 0x5c:            *scanCode = KEY_RMeta;     break;
104            case 0x5d:            *scanCode = KEY_Menu;      break;
105            case KEY_F3:          *scanCode = KEY_F13;       break;
106            case KEY_F4:          *scanCode = KEY_F14;       break;
107            case KEY_F5:          *scanCode = KEY_F15;       break;
108            case KEY_F6:          *scanCode = KEY_F16;       break;
109            case KEY_F7:          *scanCode = KEY_F17;       break;
110            case KEY_KP_Plus:     *scanCode = KEY_KP_DEC;    break;
111            /* Remap codes 0x09 and 0x11 to avoid overlap with the
112               Henkan and Muhenkan keys on Japanese pc106 or pc103
113               keyboards */
114            case 0x01:            *scanCode = KEY_R_0xF4;    break;
115            case 0x03:            *scanCode = KEY_R_0xF5;    break;
116            case 0x2A:
117            case 0x36:
118	         return TRUE;
119            default:
120                 LogMessageVerbSigSafe(X_INFO, 4, "Unreported Prefix0 scancode: 0x%x\n",
121                                       *scanCode);
122                 *scanCode += 0x78;
123          }
124       break;
125       case KEY_Prefix1:
126            pKbd->scanPrefix = (*scanCode == KEY_LCtrl) ? KEY_LCtrl : 0;
127            return TRUE;
128       case KEY_LCtrl:
129            pKbd->scanPrefix = 0;
130            if (*scanCode != KEY_NumLock)
131                return TRUE;
132            *scanCode = KEY_Pause;       /* pause */
133    }
134    return FALSE;
135}
136