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>.
23 #include <X11/Xutil.h>
24 #include <X11/keysym.h>
25 #include <X11/XKBlib.h>
28 #include "plugin_lib.h"
31 uint16_t xkey, psxkey;
33 { XK_Left, DKEY_LEFT },
34 { XK_Right, DKEY_RIGHT },
36 { XK_Down, DKEY_DOWN },
38 { XK_s, DKEY_SQUARE },
39 { XK_x, DKEY_CIRCLE },
40 { XK_d, DKEY_TRIANGLE },
45 { XK_c, DKEY_SELECT },
49 static Atom wmprotocols, wmdelwindow;
50 static int initialized;
52 static void InitKeyboard(void) {
53 Display *disp = (Display *)gpuDisp;
55 fprintf(stderr, "xkb: null display\n");
59 wmprotocols = XInternAtom(disp, "WM_PROTOCOLS", 0);
60 wmdelwindow = XInternAtom(disp, "WM_DELETE_WINDOW", 0);
62 XkbSetDetectableAutoRepeat(disp, 1, NULL);
65 static void DestroyKeyboard(void) {
66 Display *disp = (Display *)gpuDisp;
68 XkbSetDetectableAutoRepeat(disp, 0, NULL);
71 int x11_update_keys(void) {
74 XClientMessageEvent *xce;
76 static int keystate_x11;
77 int psxkey, leave = 0;
78 Display *disp = (Display *)gpuDisp;
88 while (XPending(disp)) {
89 XNextEvent(disp, &evt);
93 Key = XLookupKeysym((XKeyEvent *)&evt, 0);
94 //printf("%s %x\n", evt.type == KeyPress ? "press" : "rel ", Key);
96 for (i = 0; i < ARRAY_SIZE(keymap); i++) {
97 if (keymap[i].xkey == Key) {
98 psxkey = keymap[i].psxkey;
104 if (evt.type == KeyPress)
105 keystate_x11 |= 1 << psxkey;
107 keystate_x11 &= ~(1 << psxkey);
109 if (evt.type == KeyPress && Key == XK_Escape)
114 xce = (XClientMessageEvent *)&evt;
115 if (xce->message_type == wmprotocols && (Atom)xce->data.l[0] == wmdelwindow)