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,53 +401,74 @@ 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);
for (i = 0; i < NUMCONTROLS; i++) { key = XLookupKeysym((XKeyEvent*)&E, 0);
if (key == pad[_numPAD].keyForControl[i]) {
KeyStatus[i] = true;
break;
}
}
break;
case KeyRelease: if((key >= XK_F1 && key <= XK_F9) ||
key = XLookupKeysym((XKeyEvent*)&E, 0); 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)); 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] = false; KeyStatus[i] = true;
break; break;
} }
} }
break;
case FocusIn:
XAutoRepeatOff(GXdsp);
break;
case FocusOut: break;
XAutoRepeatOn(GXdsp);
break; case KeyRelease:
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));
for (i = 0; i < NUMCONTROLS; i++) {
if (key == pad[_numPAD].keyForControl[i]) {
KeyStatus[i] = false;
break;
}
}
break;
case FocusIn:
XAutoRepeatOff(GXdsp);
break;
case FocusOut:
XAutoRepeatOn(GXdsp);
break;
default:
break;
} }
} }

View File

@ -440,7 +440,7 @@ bool OpenGL_MakeCurrent()
// Fetch video info. // Fetch video info.
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) { if (!videoInfo) {
// TODO: Display an error message. // TODO: Display an error message.
SDL_Quit(); SDL_Quit();
return false; return false;
@ -511,58 +511,60 @@ 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_R)
ShiftPressed = false;
else if(key == XK_Control_L || key == XK_Control_R)
ControlPressed = false;
else
XPutBackEvent(GLWin.dpy, &event);
} }
if(key == XK_Shift_L || key == XK_Shift_L)
ShiftPressed = false;
if(key == XK_Control_L || key == XK_Control_L)
ControlPressed = false;
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 {
ShiftPressed = true; if(key == XK_Shift_L || key == XK_Shift_R)
if(key == XK_Control_L || key == XK_Control_L) ShiftPressed = true;
ControlPressed = true; else if(key == XK_Control_L || key == XK_Control_R)
XPutBackEvent(GLWin.dpy, &event); ControlPressed = true;
else
XPutBackEvent(GLWin.dpy, &event);
}
break; break;
case ButtonPress: case ButtonPress:
case ButtonRelease: case ButtonRelease:
XPutBackEvent(GLWin.dpy, &event); XPutBackEvent(GLWin.dpy, &event);
break; break;
case ConfigureNotify: case ConfigureNotify:
Window winDummy; Window winDummy;
unsigned int borderDummy; unsigned int borderDummy;
XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y, XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
&GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth); &GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth);
nBackbufferWidth = GLWin.width; nBackbufferWidth = GLWin.width;
nBackbufferHeight = GLWin.height; nBackbufferHeight = GLWin.height;
break; break;
case ClientMessage: //TODO: We aren't reading this correctly, It could be anything, highest change is that it's a close event though case ClientMessage: //TODO: We aren't reading this correctly, It could be anything, highest change is that it's a close event though
Video_Shutdown(); // Calling from here since returning false does nothing Video_Shutdown(); // Calling from here since returning false does nothing
return; return;
break; break;
default: default:
//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