From 64bdd8316ca10dd8bd474abb1fe7377dfd678762 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sun, 15 Mar 2015 01:05:48 +0100 Subject: [PATCH] server: Fix handling of GetMessage after previous PeekMessage call. (v3) Changes in v2: * accept_hardware_message should also reset ignore_post_msg. Changes in v3: * Fix remaining todo_wine. --- dlls/user32/tests/msg.c | 32 ++++++++++++++++++-------- server/queue.c | 50 ++++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c index 8b89d92cbf1..e7f133899ed 100644 --- a/dlls/user32/tests/msg.c +++ b/dlls/user32/tests/msg.c @@ -14012,13 +14012,10 @@ static void test_PeekMessage3(void) ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); PostMessageA(hwnd, WM_USER, 0, 0); ret = PeekMessageA(&msg, hwnd, 0, 0, PM_NOREMOVE); - todo_wine ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); ret = GetMessageA(&msg, hwnd, 0, 0); - todo_wine ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); ret = GetMessageA(&msg, hwnd, 0, 0); - todo_wine ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message); ret = PeekMessageA(&msg, hwnd, 0, 0, 0); ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret); @@ -14028,10 +14025,8 @@ static void test_PeekMessage3(void) ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); PostMessageA(hwnd, WM_USER, 0, 0); ret = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); - todo_wine ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); ret = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); - todo_wine ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message); ret = PeekMessageA(&msg, hwnd, 0, 0, 0); ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret); @@ -14043,10 +14038,11 @@ static void test_PeekMessage3(void) ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); PostMessageA(hwnd, WM_USER, 0, 0); ret = GetMessageA(&msg, hwnd, 0, 0); - todo_wine ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); ret = GetMessageA(&msg, hwnd, 0, 0); - todo_wine + ret = GetMessageA(&msg, NULL, 0, 0); + ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); + ret = GetMessageA(&msg, NULL, 0, 0); ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message); ret = PeekMessageA(&msg, hwnd, 0, 0, 0); ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret); @@ -14074,14 +14070,32 @@ static void test_PeekMessage3(void) ret = GetMessageA(&msg, hwnd, 0, 0); ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message); ret = GetMessageA(&msg, hwnd, 0, 0); - todo_wine ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); ret = GetMessageA(&msg, hwnd, 0, 0); - todo_wine ok(ret && msg.message == WM_USER + 1, "msg.message = %u instead of WM_USER + 1\n", msg.message); ret = PeekMessageA(&msg, hwnd, 0, 0, 0); ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret); + /* Newer messages are still returned when specifying a message range. */ + + SetTimer(hwnd, 1, 0, NULL); + while (!PeekMessageA(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE)); + ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); + PostMessageA(hwnd, WM_USER + 1, 0, 0); + PostMessageA(hwnd, WM_USER, 0, 0); + ret = PeekMessageA(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); + ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message); + ret = PeekMessageA(&msg, NULL, WM_USER, WM_USER + 1, PM_NOREMOVE); + ok(ret && msg.message == WM_USER + 1, "msg.message = %u instead of WM_USER + 1\n", msg.message); + ret = PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE); + ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message); + ret = PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE); + ok(ret && msg.message == WM_USER + 1, "msg.message = %u instead of WM_USER + 1\n", msg.message); + ret = PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE); + ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message); + ret = PeekMessageA(&msg, NULL, 0, 0, 0); + ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret); + /* Also works for posted messages, but the situation is a bit different, * because both messages are in the same queue. */ diff --git a/server/queue.c b/server/queue.c index fcc946ff0cb..348fdac3214 100644 --- a/server/queue.c +++ b/server/queue.c @@ -142,6 +142,7 @@ struct msg_queue struct hook_table *hooks; /* hook table */ timeout_t last_get_msg; /* time of last get message call */ int keystate_lock; /* owns an input keystate lock */ + unsigned int ignore_post_msg; /* ignore post messages newer than this unique id */ }; struct hotkey @@ -310,6 +311,7 @@ static struct msg_queue *create_msg_queue( struct thread *thread, struct thread_ queue->hooks = NULL; queue->last_get_msg = current_time; queue->keystate_lock = 0; + queue->ignore_post_msg = 0; list_init( &queue->send_result ); list_init( &queue->callback_result ); list_init( &queue->pending_timers ); @@ -634,13 +636,21 @@ static inline struct msg_queue *get_current_queue(void) } /* get a (pseudo-)unique id to tag hardware messages */ -static inline unsigned int get_unique_id(void) +static inline unsigned int get_unique_hw_id(void) { static unsigned int id; if (!++id) id = 1; /* avoid an id of 0 */ return id; } +/* get unique increasing id to tag post messages */ +static inline unsigned int get_unique_post_id(void) +{ + static unsigned int id; + if (!++id) id = 1; + return id; +} + /* try to merge a WM_MOUSEMOVE message with the last in the list; return 1 if successful */ static int merge_mousemove( struct thread_input *input, const struct message *msg ) { @@ -951,7 +961,7 @@ static int match_window( user_handle_t win, user_handle_t msg_win ) } /* retrieve a posted message */ -static int get_posted_message( struct msg_queue *queue, user_handle_t win, +static int get_posted_message( struct msg_queue *queue, unsigned int ignore_msg, user_handle_t win, unsigned int first, unsigned int last, unsigned int flags, struct get_message_reply *reply ) { @@ -962,6 +972,7 @@ static int get_posted_message( struct msg_queue *queue, user_handle_t win, { if (!match_window( win, msg->win )) continue; if (!check_msg_filter( msg->msg, first, last )) continue; + if (ignore_msg && (int)(msg->unique_id - ignore_msg) >= 0) continue; goto found; /* found one */ } return 0; @@ -1576,6 +1587,7 @@ found: msg->msg = WM_HOTKEY; msg->wparam = hotkey->id; msg->lparam = ((hotkey->vkey & 0xffff) << 16) | modifiers; + msg->unique_id = get_unique_post_id(); free( msg->data ); msg->data = NULL; @@ -2267,7 +2279,7 @@ static int get_hardware_message( struct thread *thread, unsigned int hw_id, user } /* now we can return it */ - if (!msg->unique_id) msg->unique_id = get_unique_id(); + if (!msg->unique_id) msg->unique_id = get_unique_hw_id(); reply->type = MSG_HARDWARE; reply->win = win; reply->msg = msg_code; @@ -2373,6 +2385,7 @@ void post_message( user_handle_t win, unsigned int message, lparam_t wparam, lpa msg->result = NULL; msg->data = NULL; msg->data_size = 0; + msg->unique_id = get_unique_post_id(); get_message_defaults( thread->queue, &msg->x, &msg->y, &msg->time ); @@ -2617,6 +2630,7 @@ DECL_HANDLER(send_message) set_queue_bits( recv_queue, QS_SENDMESSAGE ); break; case MSG_POSTED: + msg->unique_id = get_unique_post_id(); list_add_tail( &recv_queue->msg_list[POST_MESSAGE], &msg->entry ); set_queue_bits( recv_queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); if (msg->msg == WM_HOTKEY) @@ -2735,12 +2749,12 @@ DECL_HANDLER(get_message) /* then check for posted messages */ if ((filter & QS_POSTMESSAGE) && - get_posted_message( queue, get_win, req->get_first, req->get_last, req->flags, reply )) + get_posted_message( queue, queue->ignore_post_msg, get_win, req->get_first, req->get_last, req->flags, reply )) return; if ((filter & QS_HOTKEY) && queue->hotkey_count && req->get_first <= WM_HOTKEY && req->get_last >= WM_HOTKEY && - get_posted_message( queue, get_win, WM_HOTKEY, WM_HOTKEY, req->flags, reply )) + get_posted_message( queue, queue->ignore_post_msg, get_win, WM_HOTKEY, WM_HOTKEY, req->flags, reply )) return; /* only check for quit messages if not posted messages pending */ @@ -2751,7 +2765,7 @@ DECL_HANDLER(get_message) if ((filter & QS_INPUT) && filter_contains_hw_range( req->get_first, req->get_last ) && get_hardware_message( current, req->hw_id, get_win, req->get_first, req->get_last, req->flags, reply )) - return; + goto found_msg; /* now check for WM_PAINT */ if ((filter & QS_PAINT) && @@ -2764,7 +2778,7 @@ DECL_HANDLER(get_message) reply->wparam = 0; reply->lparam = 0; get_message_defaults( queue, &reply->x, &reply->y, &reply->time ); - return; + goto found_msg; } /* now check for timer */ @@ -2780,13 +2794,30 @@ DECL_HANDLER(get_message) get_message_defaults( queue, &reply->x, &reply->y, &reply->time ); if (!(req->flags & PM_NOYIELD) && current->process->idle_event) set_event( current->process->idle_event ); - return; + goto found_msg; } + /* if we previously skipped posted messages then check again */ + if (queue->ignore_post_msg && (filter & QS_POSTMESSAGE) && + get_posted_message( queue, 0, get_win, req->get_first, req->get_last, req->flags, reply )) + return; + + if (queue->ignore_post_msg && (filter & QS_HOTKEY) && queue->hotkey_count && + req->get_first <= WM_HOTKEY && req->get_last >= WM_HOTKEY && + get_posted_message( queue, 0, get_win, WM_HOTKEY, WM_HOTKEY, req->flags, reply )) + return; + if (get_win == -1 && current->process->idle_event) set_event( current->process->idle_event ); queue->wake_mask = req->wake_mask; queue->changed_mask = req->changed_mask; set_error( STATUS_PENDING ); /* FIXME */ + return; + +found_msg: + if (req->flags & PM_REMOVE) + queue->ignore_post_msg = 0; + else if (!queue->ignore_post_msg) + queue->ignore_post_msg = get_unique_post_id(); } @@ -2804,7 +2835,10 @@ DECL_HANDLER(reply_message) DECL_HANDLER(accept_hardware_message) { if (current->queue) + { release_hardware_message( current->queue, req->hw_id ); + current->queue->ignore_post_msg = 0; + } else set_error( STATUS_ACCESS_DENIED ); } -- 2.40.1