18 WindowHolder::WindowHolder(unique_ptr<BaseComposite>&& compositeWindow,
bool unregisterClass) noexcept :
38 int WindowHolder::runMainLoop(
const vector<uint32_t>& registeredHotkeyIds)
43 DWORD currentThreadId = GetCurrentThreadId();
45 while (code = GetMessageW(&message,
nullptr, NULL, NULL))
52 TranslateMessage(&message);
54 DispatchMessageW(&message);
56 if (message.message == WM_KEYDOWN)
58 instance.processHotkeys();
60 else if (message.message == custom_window_messages::runOnUIThreadFunctions)
62 (*
reinterpret_cast<std::function<
void()
>*>(message.wParam))();
65 if (currentThreadId == instance.uiThreadId)
67 unique_lock<recursive_mutex> runOnUIThreadLock(instance.runOnUIThreadMutex);
68 queue<function<void()>>& runOnUIFunctions = instance.runOnUIFunctions;
70 while (runOnUIFunctions.size())
72 function<void()>& currentFunction = runOnUIFunctions.front();
73 function<void()>* functionWrapper =
new function<void()>();
75 (*functionWrapper) = [currentFunction, functionWrapper]()
79 delete functionWrapper;
82 runOnUIFunctions.pop();
84 PostThreadMessageW(currentThreadId, custom_window_messages::runOnUIThreadFunctions,
reinterpret_cast<WPARAM
>(functionWrapper), NULL);
89 for (uint32_t hotkeyId : registeredHotkeyIds)
99 return static_cast<int>(message.wParam);