summaryrefslogtreecommitdiff
path: root/plugins/dfinput/xkb.c
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-10-25 14:21:02 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-10-25 14:21:02 +0000
commit7d0f136239c4dcee9f27adf9f7a8c262fcbfe95f (patch)
tree18b5c5292a39fcda65327e2dd32e44e70ef8e5ff /plugins/dfinput/xkb.c
parent5408345d8b1cde19a19ddf324d3439ead6e80709 (diff)
downloadpcsxr-7d0f136239c4dcee9f27adf9f7a8c262fcbfe95f.tar.gz
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@32889 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins/dfinput/xkb.c')
-rw-r--r--plugins/dfinput/xkb.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/plugins/dfinput/xkb.c b/plugins/dfinput/xkb.c
new file mode 100644
index 00000000..5706d230
--- /dev/null
+++ b/plugins/dfinput/xkb.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2009, Wei Mingzhi <whistler@openoffice.org>.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#include "pad.h"
+
+static Atom wmprotocols, wmdelwindow;
+
+void InitKeyboard() {
+ wmprotocols = XInternAtom(g.Disp, "WM_PROTOCOLS", 0);
+ wmdelwindow = XInternAtom(g.Disp, "WM_DELETE_WINDOW", 0);
+
+ XAutoRepeatOff(g.Disp);
+
+ g.PadState[0].KeyStatus = 0xFFFF;
+ g.PadState[1].KeyStatus = 0xFFFF;
+}
+
+void DestroyKeyboard() {
+ XAutoRepeatOn(g.Disp);
+}
+
+void CheckKeyboard() {
+ uint8_t i, j, found;
+ XEvent evt;
+ XClientMessageEvent *xce;
+ uint16_t Key;
+
+ while (XPending(g.Disp)) {
+ XNextEvent(g.Disp, &evt);
+ switch (evt.type) {
+ case KeyPress:
+ Key = XLookupKeysym((XKeyEvent *)&evt, 0);
+ found = 0;
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < DKEY_TOTAL; j++) {
+ if (g.cfg.PadDef[i].KeyDef[j].Key == Key) {
+ found = 1;
+ g.PadState[i].KeyStatus &= ~(1 << j);
+ }
+ }
+ }
+ if (!found) {
+ g.KeyLeftOver = Key;
+ }
+ return;
+
+ case KeyRelease:
+ Key = XLookupKeysym((XKeyEvent *)&evt, 0);
+ found = 0;
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < DKEY_TOTAL; j++) {
+ if (g.cfg.PadDef[i].KeyDef[j].Key == Key) {
+ found = 1;
+ g.PadState[i].KeyStatus |= (1 << j);
+ }
+ }
+ }
+ if (!found) {
+ g.KeyLeftOver = ((long)Key | 0x40000000);
+ }
+ break;
+
+ case ClientMessage:
+ xce = (XClientMessageEvent *)&evt;
+ if (xce->message_type == wmprotocols && (Atom)xce->data.l[0] == wmdelwindow) {
+ // Fake an ESC key if user clicked the close button on window
+ g.KeyLeftOver = XK_Escape;
+ return;
+ }
+ break;
+
+ case FocusOut:
+ XAutoRepeatOn(g.Disp);
+ break;
+
+ case FocusIn:
+ XAutoRepeatOff(g.Disp);
+ break;
+ }
+ }
+}
+