Simplify GUI event handling

This commit is contained in:
Robbert van der Helm
2020-03-19 21:35:23 +01:00
parent f1f7523248
commit 4ae1f03e4c
4 changed files with 38 additions and 30 deletions
+13 -21
View File
@@ -24,7 +24,7 @@ HWND Editor::open() {
}
void Editor::close() {
// RAII does the rest for us
// RAII will destroy the window for us
win32_handle = std::nullopt;
// TODO: Do we need to do something on the X11 side or does the host do
@@ -44,26 +44,6 @@ bool Editor::resize(const VstRect& new_size) {
return true;
}
// TODO: Below function shouldn't be needed
bool Editor::update() {
if (!win32_handle.has_value()) {
return false;
}
// TODO: Doing this manually should not be needed
UpdateWindow(win32_handle->get());
// TODO: This should also be done somewhere else
// Pump events since the Win32 API won't do it for us
MSG msg;
while (PeekMessage(&msg, win32_handle->get(), 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return true;
}
bool Editor::embed_into(const size_t parent_window_handle) {
if (!win32_handle.has_value()) {
return false;
@@ -101,6 +81,18 @@ bool Editor::embed_into(const size_t parent_window_handle) {
return true;
}
void Editor::handle_events() {
// Process any remaining events, otherwise we won't be able to interact with
// the window
if (win32_handle.has_value()) {
MSG msg;
while (PeekMessage(&msg, win32_handle->get(), 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
std::optional<size_t> Editor::get_x11_handle() {
if (!win32_handle.has_value()) {
return std::nullopt;