forked from Mirrors/openclonk
Use Qt's event loop instead of polling for events
This fixes slow input event handling execution on Linux. Additionally, it seems to fix some crashes with the menu bar.qteditor
parent
0767fd2616
commit
60671474a8
|
@ -537,31 +537,13 @@ bool C4ConsoleGUIState::CreateConsoleWindow(C4AbstractApp *app)
|
|||
HWND hWindow = reinterpret_cast<HWND>(window->winId());
|
||||
RestoreWindowPosition(hWindow, "Main", Config.GetSubkeyPath("Console"));
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void C4ConsoleGUIState::Execute(bool redraw_only)
|
||||
{
|
||||
// Avoid recursion in message processing; it's causing random crashes
|
||||
ExecRecursionCheck recursion_check;
|
||||
if (recursion_check.IsRecursion()) return;
|
||||
// Qt window message handling and object cleanup
|
||||
if (application)
|
||||
{
|
||||
if (redraw_only)
|
||||
{
|
||||
// process only non-critical events
|
||||
// redrawing only allowed during GameTick; prevent callbacks within a Qt event triggered by windows messaging
|
||||
if (::Application.IsInGameTick())
|
||||
application->processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
else
|
||||
{
|
||||
// process everything
|
||||
application->processEvents();
|
||||
application->sendPostedEvents(0, QEvent::DeferredDelete);
|
||||
}
|
||||
}
|
||||
// Nothing to do - Qt's event loop is handling everything.
|
||||
}
|
||||
|
||||
// Set action pressed/checked and enabled states
|
||||
|
|
|
@ -18,8 +18,31 @@
|
|||
#include "platform/C4App.h"
|
||||
#include "platform/C4Window.h"
|
||||
|
||||
#ifdef WITH_QT_EDITOR
|
||||
#include "game/C4Application.h"
|
||||
#include "editor/C4ConsoleQt.h"
|
||||
#endif
|
||||
|
||||
void C4AbstractApp::Run()
|
||||
{
|
||||
#ifdef WITH_QT_EDITOR
|
||||
if (Application.isEditor)
|
||||
{
|
||||
// Qt has its own event loop. Use a timer to call our own event handling whenever Qt is done
|
||||
// with its events (zero timeout). The alternative (calling Qt's event handling from
|
||||
// C4Console::Execute) is too slow, at least on Linux.
|
||||
QTimer timer;
|
||||
QObject::connect(&timer, &QTimer::timeout, [this]() {
|
||||
ScheduleProcs(0);
|
||||
if (fQuitMsgReceived)
|
||||
QApplication::quit();
|
||||
});
|
||||
timer.start();
|
||||
QApplication::exec();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Main message loop
|
||||
while (!fQuitMsgReceived)
|
||||
ScheduleProcs();
|
||||
|
|
Loading…
Reference in New Issue