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);
key = XLookupKeysym((XKeyEvent*)&E, 0);
for (i = 0; i < NUMCONTROLS; i++) {
if (key == pad[_numPAD].keyForControl[i]) { if((key >= XK_F1 && key <= XK_F9) ||
KeyStatus[i] = true; key == XK_Shift_L || key == XK_Shift_R ||
break; key == XK_Control_L || key == XK_Control_R) {
} XPutBackEvent(GXdsp, &E);
} break;
break; }
case KeyRelease: int i;
key = XLookupKeysym((XKeyEvent*)&E, 0); for (i = 0; i < NUMCONTROLS; i++) {
if (key == pad[_numPAD].keyForControl[i]) {
//_KeyRelease(pad, XLookupKeysym((XKeyEvent *)&E, 0)); KeyStatus[i] = true;
for (i = 0; i < NUMCONTROLS; i++) { break;
if (key == pad[_numPAD].keyForControl[i]) { }
KeyStatus[i] = false; }
break;
}
} break;
break;
case KeyRelease:
case FocusIn:
XAutoRepeatOff(GXdsp); key = XLookupKeysym((XKeyEvent*)&E, 0);
break;
if((key >= XK_F1 && key <= XK_F9) ||
case FocusOut: key == XK_Shift_L || key == XK_Shift_R ||
XAutoRepeatOn(GXdsp); key == XK_Control_L || key == XK_Control_R) {
break; 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;
} }
} }
@ -479,7 +500,7 @@ void X11_Read(int _numPAD, SPADStatus* _pPADStatus)
_pPADStatus->button |= PAD_BUTTON_B; _pPADStatus->button |= PAD_BUTTON_B;
_pPADStatus->analogB = 255; _pPADStatus->analogB = 255;
} }
if (KeyStatus[CTL_X]){_pPADStatus->button |= PAD_BUTTON_X;} if (KeyStatus[CTL_X]){_pPADStatus->button |= PAD_BUTTON_X;}
if (KeyStatus[CTL_Y]){_pPADStatus->button |= PAD_BUTTON_Y;} if (KeyStatus[CTL_Y]){_pPADStatus->button |= PAD_BUTTON_Y;}
if (KeyStatus[CTL_Z]){_pPADStatus->button |= PAD_TRIGGER_Z;} if (KeyStatus[CTL_Z]){_pPADStatus->button |= PAD_TRIGGER_Z;}
@ -488,12 +509,12 @@ void X11_Read(int _numPAD, SPADStatus* _pPADStatus)
_pPADStatus->button |= PAD_TRIGGER_L; _pPADStatus->button |= PAD_TRIGGER_L;
_pPADStatus->triggerLeft = triggervalue; _pPADStatus->triggerLeft = triggervalue;
} }
if (KeyStatus[CTL_R]) { if (KeyStatus[CTL_R]) {
_pPADStatus->button |= PAD_TRIGGER_R; _pPADStatus->button |= PAD_TRIGGER_R;
_pPADStatus->triggerRight = triggervalue; _pPADStatus->triggerRight = triggervalue;
} }
if (KeyStatus[CTL_START]){_pPADStatus->button |= PAD_BUTTON_START;} if (KeyStatus[CTL_START]){_pPADStatus->button |= PAD_BUTTON_START;}
} }

View File

@ -427,8 +427,8 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
return true; return true;
} }
bool OpenGL_MakeCurrent() bool OpenGL_MakeCurrent()
{ {
#if USE_SDL #if USE_SDL
// Note: The reason for having the call to SDL_SetVideoMode in here instead // Note: The reason for having the call to SDL_SetVideoMode in here instead
// of in OpenGL_Create() is that "make current" is part of the video // of in OpenGL_Create() is that "make current" is part of the video
@ -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;
@ -504,68 +504,70 @@ void OpenGL_Update()
nBackbufferWidth = width; nBackbufferWidth = width;
nBackbufferHeight = height; nBackbufferHeight = height;
#else // GLX #else // GLX
// We just check all of our events here // We just check all of our events here
XEvent event; XEvent event;
KeySym key; KeySym key;
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);
{ FKeyPressed = -1;
g_VideoInitialize.pKeyPress(FKeyPressed, ShiftPressed, ControlPressed); } else {
FKeyPressed = -1; if(key == XK_Shift_L || key == XK_Shift_R)
} ShiftPressed = false;
if(key == XK_Shift_L || key == XK_Shift_L) else if(key == XK_Control_L || key == XK_Control_R)
ShiftPressed = false; ControlPressed = false;
if(key == XK_Control_L || key == XK_Control_L) else
ControlPressed = false; 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 {
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;
break; else
case ButtonPress: XPutBackEvent(GLWin.dpy, &event);
case ButtonRelease: }
XPutBackEvent(GLWin.dpy, &event); break;
break; case ButtonPress:
case ConfigureNotify: case ButtonRelease:
Window winDummy; XPutBackEvent(GLWin.dpy, &event);
unsigned int borderDummy; break;
XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y, case ConfigureNotify:
&GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth); Window winDummy;
nBackbufferWidth = GLWin.width; unsigned int borderDummy;
nBackbufferHeight = GLWin.height; XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
break; &GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth);
case ClientMessage: //TODO: We aren't reading this correctly, It could be anything, highest change is that it's a close event though nBackbufferWidth = GLWin.width;
Video_Shutdown(); // Calling from here since returning false does nothing nBackbufferHeight = GLWin.height;
return; 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
default: Video_Shutdown(); // Calling from here since returning false does nothing
//TODO: Should we put the event back if we don't handle it? return;
// I think we handle all the needed ones, the rest shouldn't matter break;
// But to be safe, let's but them back anyway default:
XPutBackEvent(GLWin.dpy, &event); //TODO: Should we put the event back if we don't handle it?
break; // I think we handle all the needed ones, the rest shouldn't matter
} // But to be safe, let's but them back anyway
num_events--; //XPutBackEvent(GLWin.dpy, &event);
} break;
return; }
#endif }
return;
#endif
float FactorW = 640.0f / (float)nBackbufferWidth; float FactorW = 640.0f / (float)nBackbufferWidth;
float FactorH = 480.0f / (float)nBackbufferHeight; float FactorH = 480.0f / (float)nBackbufferHeight;