From: Rémi Bernon <rbernon@codeweavers.com> --- server/window.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/server/window.c b/server/window.c index 28e95a675b7..958d3977162 100644 --- a/server/window.c +++ b/server/window.c @@ -396,6 +396,18 @@ static void set_window_monitor_dpi( struct window *win ) SHARED_WRITE_END; } +/* attach or detach the parent window thread input if necessary */ +static void attach_parent_thread( struct window *win, bool attach ) +{ + struct thread *thread = win->thread, *parent; + + if (is_toplevel( win ) || !(parent = win->parent->thread) || parent == thread) return; + + /* if parent belongs to a different thread and the window isn't top-level, attach / detach the two threads */ + if (attach) attach_thread_input( thread->queue, parent->queue ); + else detach_thread_input( thread->queue, win->desktop ); +} + /* change the parent of a window (or unlink the window if the new parent is NULL) */ static int set_parent_window( struct window *win, struct window *parent ) { @@ -413,8 +425,10 @@ static int set_parent_window( struct window *win, struct window *parent ) if (parent) { + attach_parent_thread( win, false ); if (win->parent) release_object( win->parent ); win->parent = (struct window *)grab_object( parent ); + attach_parent_thread( win, true ); link_window( win, WINPTR_TOP ); if (is_desktop_window( parent )) set_window_monitor_dpi( win ); @@ -425,11 +439,6 @@ static int set_parent_window( struct window *win, struct window *parent ) } SHARED_WRITE_END; - /* if parent belongs to a different thread and the window isn't */ - /* top-level, attach the two threads */ - if (parent->thread && parent->thread != win->thread && !is_desktop_window(parent)) - attach_thread_input( win->thread->queue, parent->thread->queue ); - if (win->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD)) update_pixel_format_flags( win ); } @@ -698,9 +707,8 @@ static struct window *create_window( struct window *parent, struct window *owner /* make sure that the thread has a message queue */ if (!current->queue && !init_thread_queue( current )) goto failed; - /* if parent belongs to a different thread and the window isn't top-level, attach the two threads */ - if (parent && parent->thread && parent->thread != current && !is_desktop_window( parent )) - attach_thread_input( current->queue, parent->thread->queue ); + /* attach the parent thread if necessary */ + attach_parent_thread( win, true ); /* put it on parent unlinked list */ if (parent) list_add_head( &parent->unlinked, &win->entry ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11670