2 * Copyright (c) 2009, Wei Mingzhi <whistler@openoffice.org>.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses>.
21 static Atom wmprotocols, wmdelwindow;
24 wmprotocols = XInternAtom(g.Disp, "WM_PROTOCOLS", 0);
25 wmdelwindow = XInternAtom(g.Disp, "WM_DELETE_WINDOW", 0);
27 XkbSetDetectableAutoRepeat(g.Disp, 1, NULL);
29 g.PadState[0].KeyStatus = 0xFFFF;
30 g.PadState[1].KeyStatus = 0xFFFF;
33 void DestroyKeyboard() {
34 XkbSetDetectableAutoRepeat(g.Disp, 0, NULL);
37 void CheckKeyboard() {
40 XClientMessageEvent *xce;
43 while (XPending(g.Disp)) {
44 XNextEvent(g.Disp, &evt);
47 Key = XLookupKeysym((XKeyEvent *)&evt, 0);
49 for (i = 0; i < 2; i++) {
50 for (j = 0; j < DKEY_TOTAL; j++) {
51 if (g.cfg.PadDef[i].KeyDef[j].Key == Key) {
53 g.PadState[i].KeyStatus &= ~(1 << j);
57 if (!found && !AnalogKeyPressed(Key)) {
63 Key = XLookupKeysym((XKeyEvent *)&evt, 0);
65 for (i = 0; i < 2; i++) {
66 for (j = 0; j < DKEY_TOTAL; j++) {
67 if (g.cfg.PadDef[i].KeyDef[j].Key == Key) {
69 g.PadState[i].KeyStatus |= (1 << j);
73 if (!found && !AnalogKeyReleased(Key)) {
74 g.KeyLeftOver = ((long)Key | 0x40000000);
79 xce = (XClientMessageEvent *)&evt;
80 if (xce->message_type == wmprotocols && (Atom)xce->data.l[0] == wmdelwindow) {
81 // Fake an ESC key if user clicked the close button on window
82 g.KeyLeftOver = XK_Escape;