A try to fix up input race between glinit and padsimple

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@705 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee
2008-09-26 11:37:09 +00:00
parent f69166d0c2
commit 7a402985ab
2 changed files with 131 additions and 108 deletions

View File

@ -401,37 +401,53 @@ void XInput_Read(int _numPAD, SPADStatus* _pPADStatus)
void X11_Read(int _numPAD, SPADStatus* _pPADStatus) void X11_Read(int _numPAD, SPADStatus* _pPADStatus)
{ {
// Do all the stuff we need to do once per frame here // Do all the stuff we need to do once per frame here
if (_numPAD != 0) if (_numPAD != 0) {
{
return; return;
} }
int i;
// This code is from Zerofrog's pcsx2 pad plugin // This code is from Zerofrog's pcsx2 pad plugin
XEvent E; XEvent E;
//int keyPress=0, keyRelease=0; //int keyPress=0, keyRelease=0;
KeySym key; KeySym key;
// keyboard input // keyboard input
while (XPending(GXdsp) > 0) { int num_events;
for (num_events = XPending(GXdsp);num_events > 0;num_events--) {
XNextEvent(GXdsp, &E); XNextEvent(GXdsp, &E);
switch (E.type) { switch (E.type) {
case KeyPress: case KeyPress:
//_KeyPress(pad, XLookupKeysym((XKeyEvent *)&E, 0)); break; //_KeyPress(pad, XLookupKeysym((XKeyEvent *)&E, 0)); break;
key = XLookupKeysym((XKeyEvent*)&E, 0); key = XLookupKeysym((XKeyEvent*)&E, 0);
if((key >= XK_F1 && key <= XK_F9) ||
key == XK_Shift_L || key == XK_Shift_R ||
key == XK_Control_L || key == XK_Control_R) {
XPutBackEvent(GXdsp, &E);
break;
}
int i;
for (i = 0; i < NUMCONTROLS; i++) { for (i = 0; i < NUMCONTROLS; i++) {
if (key == pad[_numPAD].keyForControl[i]) { if (key == pad[_numPAD].keyForControl[i]) {
KeyStatus[i] = true; KeyStatus[i] = true;
break; break;
} }
} }
break; break;
case KeyRelease: case KeyRelease:
key = XLookupKeysym((XKeyEvent*)&E, 0); key = XLookupKeysym((XKeyEvent*)&E, 0);
if((key >= XK_F1 && key <= XK_F9) ||
key == XK_Shift_L || key == XK_Shift_R ||
key == XK_Control_L || key == XK_Control_R) {
XPutBackEvent(GXdsp, &E);
break;
}
//_KeyRelease(pad, XLookupKeysym((XKeyEvent *)&E, 0)); //_KeyRelease(pad, XLookupKeysym((XKeyEvent *)&E, 0));
for (i = 0; i < NUMCONTROLS; i++) { for (i = 0; i < NUMCONTROLS; i++) {
if (key == pad[_numPAD].keyForControl[i]) { if (key == pad[_numPAD].keyForControl[i]) {
@ -439,8 +455,10 @@ void X11_Read(int _numPAD, SPADStatus* _pPADStatus)
break; break;
} }
} }
break; break;
case FocusIn: case FocusIn:
XAutoRepeatOff(GXdsp); XAutoRepeatOff(GXdsp);
break; break;
@ -448,6 +466,9 @@ void X11_Read(int _numPAD, SPADStatus* _pPADStatus)
case FocusOut: case FocusOut:
XAutoRepeatOn(GXdsp); XAutoRepeatOn(GXdsp);
break; break;
default:
break;
} }
} }

View File

@ -511,33 +511,36 @@ void OpenGL_Update()
static bool ShiftPressed = false; static bool ShiftPressed = false;
static bool ControlPressed = false; static bool ControlPressed = false;
static int FKeyPressed = -1; static int FKeyPressed = -1;
int num_events = XPending(GLWin.dpy); int num_events;
while (XPending(GLWin.dpy) > 0 && num_events != 0) { for (num_events = XPending(GLWin.dpy);num_events > 0;num_events--) {
XNextEvent(GLWin.dpy, &event); XNextEvent(GLWin.dpy, &event);
switch(event.type) switch(event.type) {
{
case KeyRelease: case KeyRelease:
key = XLookupKeysym((XKeyEvent*)&event, 0); key = XLookupKeysym((XKeyEvent*)&event, 0);
if(key >= XK_F1 && key <= XK_F9) if(key >= XK_F1 && key <= XK_F9) {
{
g_VideoInitialize.pKeyPress(FKeyPressed, ShiftPressed, ControlPressed); g_VideoInitialize.pKeyPress(FKeyPressed, ShiftPressed, ControlPressed);
FKeyPressed = -1; FKeyPressed = -1;
} } else {
if(key == XK_Shift_L || key == XK_Shift_L) if(key == XK_Shift_L || key == XK_Shift_R)
ShiftPressed = false; ShiftPressed = false;
if(key == XK_Control_L || key == XK_Control_L) else if(key == XK_Control_L || key == XK_Control_R)
ControlPressed = false; ControlPressed = false;
else
XPutBackEvent(GLWin.dpy, &event); XPutBackEvent(GLWin.dpy, &event);
}
break; break;
case KeyPress: case KeyPress:
key = XLookupKeysym((XKeyEvent*)&event, 0); key = XLookupKeysym((XKeyEvent*)&event, 0);
if(key >= XK_F1 && key <= XK_F9) if(key >= XK_F1 && key <= XK_F9)
FKeyPressed = key - 0xff4e; FKeyPressed = key - 0xff4e;
if(key == XK_Shift_L || key == XK_Shift_L) else {
if(key == XK_Shift_L || key == XK_Shift_R)
ShiftPressed = true; ShiftPressed = true;
if(key == XK_Control_L || key == XK_Control_L) else if(key == XK_Control_L || key == XK_Control_R)
ControlPressed = true; ControlPressed = true;
else
XPutBackEvent(GLWin.dpy, &event); XPutBackEvent(GLWin.dpy, &event);
}
break; break;
case ButtonPress: case ButtonPress:
case ButtonRelease: case ButtonRelease:
@ -559,10 +562,9 @@ void OpenGL_Update()
//TODO: Should we put the event back if we don't handle it? //TODO: Should we put the event back if we don't handle it?
// I think we handle all the needed ones, the rest shouldn't matter // I think we handle all the needed ones, the rest shouldn't matter
// But to be safe, let's but them back anyway // But to be safe, let's but them back anyway
XPutBackEvent(GLWin.dpy, &event); //XPutBackEvent(GLWin.dpy, &event);
break; break;
} }
num_events--;
} }
return; return;
#endif #endif