mirror of
https://github.com/mpv-player/mpv
synced 2025-01-01 12:22:22 +00:00
w32_common: quit event loop on destroy
When embedding, if the parent window is destroyed, it will cause mpv's window to be destroyed as well. Since WM_USER wakeups are sent to the window, destroying the window will prevent wakeups and cause uninit to hang. Fix this by quitting the event loop on WM_DESTROY. Events should only be processed for the lifetime of the window, from CreateWindowEx to WM_DESTROY. After the event loop is finished, mp_dispatch_queue_process can handle any remaining requests.
This commit is contained in:
parent
c2592be4f0
commit
f23827d557
@ -66,6 +66,9 @@ struct vo_w32_state {
|
|||||||
int prev_x;
|
int prev_x;
|
||||||
int prev_y;
|
int prev_y;
|
||||||
|
|
||||||
|
// Has the window seen a WM_DESTROY? If so, don't call DestroyWindow again.
|
||||||
|
bool destroyed;
|
||||||
|
|
||||||
// whether the window position and size were intialized
|
// whether the window position and size were intialized
|
||||||
bool window_bounds_initialized;
|
bool window_bounds_initialized;
|
||||||
|
|
||||||
@ -573,7 +576,11 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
// Don't actually allow it to destroy the window, or whatever else it
|
// Don't actually allow it to destroy the window, or whatever else it
|
||||||
// is that will make us lose WM_USER wakeups.
|
// is that will make us lose WM_USER wakeups.
|
||||||
mp_input_put_key(w32->input_ctx, MP_KEY_CLOSE_WIN);
|
mp_input_put_key(w32->input_ctx, MP_KEY_CLOSE_WIN);
|
||||||
return 1;
|
return 0;
|
||||||
|
case WM_DESTROY:
|
||||||
|
w32->destroyed = true;
|
||||||
|
PostQuitMessage(0);
|
||||||
|
return 0;
|
||||||
case WM_SYSCOMMAND:
|
case WM_SYSCOMMAND:
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
case SC_SCREENSAVE:
|
case SC_SCREENSAVE:
|
||||||
@ -1047,10 +1054,6 @@ static void *gui_thread(void *ptr)
|
|||||||
|
|
||||||
mp_dispatch_set_wakeup_fn(w32->dispatch, wakeup_gui_thread, w32);
|
mp_dispatch_set_wakeup_fn(w32->dispatch, wakeup_gui_thread, w32);
|
||||||
|
|
||||||
// Microsoft-recommended way to create a message queue.
|
|
||||||
// Needed so that initial WM_USER wakeups are not lost.
|
|
||||||
PeekMessage(&(MSG){0}, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
done:
|
done:
|
||||||
|
|
||||||
@ -1212,7 +1215,9 @@ static void do_terminate(void *ptr)
|
|||||||
{
|
{
|
||||||
struct vo_w32_state *w32 = ptr;
|
struct vo_w32_state *w32 = ptr;
|
||||||
w32->terminate = true;
|
w32->terminate = true;
|
||||||
PostQuitMessage(0);
|
|
||||||
|
if (!w32->destroyed)
|
||||||
|
DestroyWindow(w32->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vo_w32_uninit(struct vo *vo)
|
void vo_w32_uninit(struct vo *vo)
|
||||||
|
Loading…
Reference in New Issue
Block a user