Revert "Don't sleep in the event thread"

This commit is contained in:
Ryan Houdek 2014-09-05 00:50:40 -05:00
parent a9a6270982
commit 30fef298bb
2 changed files with 71 additions and 63 deletions

View File

@ -57,15 +57,19 @@ void cX11Window::XEventThread()
while (win) while (win)
{ {
XEvent event; XEvent event;
XNextEvent(dpy, &event); for (int num_events = XPending(dpy); num_events > 0; num_events--)
switch (event.type)
{ {
case ConfigureNotify: XNextEvent(dpy, &event);
XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height); switch (event.type)
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height); {
break; case ConfigureNotify:
default: XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height);
break; GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
break;
default:
break;
}
} }
Common::SleepCurrentThread(20);
} }
} }

View File

@ -199,69 +199,72 @@ class PlatformX11 : public Platform
{ {
XEvent event; XEvent event;
KeySym key; KeySym key;
XNextEvent(dpy, &event); for (int num_events = XPending(dpy); num_events > 0; num_events--)
switch (event.type)
{ {
case KeyPress: XNextEvent(dpy, &event);
key = XLookupKeysym((XKeyEvent*)&event, 0); switch (event.type)
if (key == XK_Escape)
{ {
if (Core::GetState() == Core::CORE_RUN) case KeyPress:
key = XLookupKeysym((XKeyEvent*)&event, 0);
if (key == XK_Escape)
{ {
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) if (Core::GetState() == Core::CORE_RUN)
XUndefineCursor(dpy, win); {
Core::SetState(Core::CORE_PAUSE); if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XUndefineCursor(dpy, win);
Core::SetState(Core::CORE_PAUSE);
}
else
{
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XDefineCursor(dpy, win, blankCursor);
Core::SetState(Core::CORE_RUN);
}
} }
else else if ((key == XK_Return) && (event.xkey.state & Mod1Mask))
{ {
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) fullscreen = !fullscreen;
XDefineCursor(dpy, win, blankCursor); X11Utils::ToggleFullscreen(dpy, win);
Core::SetState(Core::CORE_RUN);
}
}
else if ((key == XK_Return) && (event.xkey.state & Mod1Mask))
{
fullscreen = !fullscreen;
X11Utils::ToggleFullscreen(dpy, win);
#if defined(HAVE_XRANDR) && HAVE_XRANDR #if defined(HAVE_XRANDR) && HAVE_XRANDR
XRRConfig->ToggleDisplayMode(fullscreen); XRRConfig->ToggleDisplayMode(fullscreen);
#endif #endif
}
else if (key >= XK_F1 && key <= XK_F8)
{
int slot_number = key - XK_F1 + 1;
if (event.xkey.state & ShiftMask)
State::Save(slot_number);
else
State::Load(slot_number);
}
else if (key == XK_F9)
Core::SaveScreenShot();
else if (key == XK_F11)
State::LoadLastSaved();
else if (key == XK_F12)
{
if (event.xkey.state & ShiftMask)
State::UndoLoadState();
else
State::UndoSaveState();
}
break;
case FocusIn:
rendererHasFocus = true;
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
Core::GetState() != Core::CORE_PAUSE)
XDefineCursor(dpy, win, blankCursor);
break;
case FocusOut:
rendererHasFocus = false;
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XUndefineCursor(dpy, win);
break;
case ClientMessage:
if ((unsigned long) event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False))
running = false;
break;
} }
else if (key >= XK_F1 && key <= XK_F8)
{
int slot_number = key - XK_F1 + 1;
if (event.xkey.state & ShiftMask)
State::Save(slot_number);
else
State::Load(slot_number);
}
else if (key == XK_F9)
Core::SaveScreenShot();
else if (key == XK_F11)
State::LoadLastSaved();
else if (key == XK_F12)
{
if (event.xkey.state & ShiftMask)
State::UndoLoadState();
else
State::UndoSaveState();
}
break;
case FocusIn:
rendererHasFocus = true;
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
Core::GetState() != Core::CORE_PAUSE)
XDefineCursor(dpy, win, blankCursor);
break;
case FocusOut:
rendererHasFocus = false;
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XUndefineCursor(dpy, win);
break;
case ClientMessage:
if ((unsigned long) event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False))
running = false;
break;
} }
if (!fullscreen) if (!fullscreen)
{ {
@ -274,6 +277,7 @@ class PlatformX11 : public Platform
(unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight,
&borderDummy, &depthDummy); &borderDummy, &depthDummy);
} }
usleep(100000);
} }
} }