bigendian again
[pcsx_rearmed.git] / maemo / maemo_xkb.c
CommitLineData
a76fd953
PI
1/*
2 * Copyright (c) 2009, Wei Mingzhi <whistler@openoffice.org>.
3 * All Rights Reserved.
4 *
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.
9 *
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.
14 *
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>.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <stdint.h>
22#include <X11/Xlib.h>
23#include <X11/Xutil.h>
24#include <X11/keysym.h>
25#include <X11/XKBlib.h>
26
27#include "../frontend/main.h"
28#include "../frontend/plugin_lib.h"
29
30static Atom wmprotocols, wmdelwindow;
31static int initialized;
32
33
34
35static void InitKeyboard(void) {
36 Display *disp = (Display *)gpuDisp;
37 if (disp){
38 wmprotocols = XInternAtom(disp, "WM_PROTOCOLS", 0);
39 wmdelwindow = XInternAtom(disp, "WM_DELETE_WINDOW", 0);
40 XkbSetDetectableAutoRepeat(disp, 1, NULL);
41 }
42}
43
44static void DestroyKeyboard(void) {
45 Display *disp = (Display *)gpuDisp;
46 if (disp)
47 XkbSetDetectableAutoRepeat(disp, 0, NULL);
48}
49#include "maemo_common.h"
50
51int maemo_x11_update_keys() {
52
53 XEvent evt;
54 XClientMessageEvent *xce;
55 int leave = 0;
56 Display *disp = (Display *)gpuDisp;
57
58 if (!disp)
59 return 0;
60
61 if (!initialized) {
62 initialized++;
63 InitKeyboard();
64 }
65
66 while (XPending(disp)>0) {
67 XNextEvent(disp, &evt);
68 switch (evt.type) {
69 case KeyPress:
70 case KeyRelease:
71 key_press_event(evt.xkey.keycode, evt.type==KeyPress ? 1 : (evt.type==KeyRelease ? 2 : 0) );
72 break;
73
74 case ClientMessage:
75 xce = (XClientMessageEvent *)&evt;
76 if (xce->message_type == wmprotocols && (Atom)xce->data.l[0] == wmdelwindow)
77 leave = 1;
78 break;
79 }
80 }
81
82 if (leave) {
83 DestroyKeyboard();
84 exit(1);
85 }
86
87 return 0;
88}