2024-06-26 15:37:31 -07:00
|
|
|
From f53204bf14a0ac962d389467e9e915724639ad03 Mon Sep 17 00:00:00 2001
|
2015-03-14 17:09:36 -07:00
|
|
|
From: Sebastian Lackner <sebastian@fds-team.de>
|
|
|
|
Date: Sun, 15 Mar 2015 01:05:48 +0100
|
2020-07-07 15:59:50 -07:00
|
|
|
Subject: [PATCH] server: Fix handling of GetMessage after previous PeekMessage
|
|
|
|
call. (v3)
|
2015-03-14 17:09:36 -07:00
|
|
|
|
2015-04-10 13:53:14 -07:00
|
|
|
Changes in v2:
|
2017-02-01 14:43:28 -08:00
|
|
|
* accept_hardware_message should also reset ignore_post_msg.
|
|
|
|
|
|
|
|
Changes in v3:
|
|
|
|
* Fix remaining todo_wine.
|
2015-03-14 17:09:36 -07:00
|
|
|
---
|
2023-09-25 16:26:16 -07:00
|
|
|
dlls/user32/tests/msg.c | 32 ++++++++++++++++++--------
|
2020-07-07 15:59:50 -07:00
|
|
|
server/queue.c | 50 ++++++++++++++++++++++++++++++++++-------
|
2023-09-25 16:26:16 -07:00
|
|
|
2 files changed, 65 insertions(+), 17 deletions(-)
|
2015-03-14 17:09:36 -07:00
|
|
|
|
2015-03-16 20:35:13 -07:00
|
|
|
diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
|
2024-06-26 15:37:31 -07:00
|
|
|
index 398bb0a69ed..2aec627604c 100644
|
2015-03-16 20:35:13 -07:00
|
|
|
--- a/dlls/user32/tests/msg.c
|
|
|
|
+++ b/dlls/user32/tests/msg.c
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -14353,13 +14353,10 @@ static void test_PeekMessage3(void)
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
|
|
|
PostMessageA(hwnd, WM_USER, 0, 0);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, PM_NOREMOVE);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
|
|
|
ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
|
|
|
ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
2015-03-17 11:13:04 -07:00
|
|
|
ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret);
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -14369,10 +14366,8 @@ static void test_PeekMessage3(void)
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
|
|
|
PostMessageA(hwnd, WM_USER, 0, 0);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
|
|
|
ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
|
|
|
ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret);
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -14384,10 +14379,11 @@ static void test_PeekMessage3(void)
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
|
|
|
PostMessageA(hwnd, WM_USER, 0, 0);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
|
|
|
ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
2023-09-25 16:26:16 -07:00
|
|
|
+ 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);
|
2015-03-17 11:13:04 -07:00
|
|
|
ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret);
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -14415,14 +14411,32 @@ static void test_PeekMessage3(void)
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2015-03-16 20:35:13 -07:00
|
|
|
- todo_wine
|
2015-03-17 11:13:04 -07:00
|
|
|
ok(ret && msg.message == WM_TIMER, "msg.message = %u instead of WM_TIMER\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = GetMessageA(&msg, hwnd, 0, 0);
|
2017-02-01 14:43:28 -08:00
|
|
|
- todo_wine
|
|
|
|
ok(ret && msg.message == WM_USER + 1, "msg.message = %u instead of WM_USER + 1\n", msg.message);
|
2023-09-25 16:26:16 -07:00
|
|
|
ret = PeekMessageA(&msg, hwnd, 0, 0, 0);
|
2017-02-01 14:43:28 -08:00
|
|
|
ok(!ret, "expected PeekMessage to return FALSE, got %u\n", ret);
|
|
|
|
|
2015-08-18 00:40:34 -07:00
|
|
|
+ /* 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);
|
2017-02-01 14:43:28 -08:00
|
|
|
+ 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);
|
2015-08-18 00:40:34 -07:00
|
|
|
+ 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);
|
2017-02-01 14:43:28 -08:00
|
|
|
+ ok(ret && msg.message == WM_USER + 1, "msg.message = %u instead of WM_USER + 1\n", msg.message);
|
2015-08-18 00:40:34 -07:00
|
|
|
+ ret = PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE);
|
|
|
|
+ ok(ret && msg.message == WM_USER, "msg.message = %u instead of WM_USER\n", msg.message);
|
2017-02-01 14:43:28 -08:00
|
|
|
+ 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. */
|
2015-08-18 00:40:34 -07:00
|
|
|
|
2015-03-14 17:09:36 -07:00
|
|
|
diff --git a/server/queue.c b/server/queue.c
|
2024-06-26 15:37:31 -07:00
|
|
|
index 53306f46793..3cf1a20926d 100644
|
2015-03-14 17:09:36 -07:00
|
|
|
--- a/server/queue.c
|
|
|
|
+++ b/server/queue.c
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -147,6 +147,7 @@ struct msg_queue
|
2015-03-14 17:09:36 -07:00
|
|
|
timeout_t last_get_msg; /* time of last get message call */
|
2021-04-02 18:15:01 -07:00
|
|
|
int keystate_lock; /* owns an input keystate lock */
|
2024-06-26 15:37:31 -07:00
|
|
|
const queue_shm_t *shared; /* queue in session shared memory */
|
2015-03-14 17:09:36 -07:00
|
|
|
+ unsigned int ignore_post_msg; /* ignore post messages newer than this unique id */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hotkey
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -317,6 +318,7 @@ static struct msg_queue *create_msg_queue( struct thread *thread, struct thread_
|
2015-03-14 17:09:36 -07:00
|
|
|
queue->hooks = NULL;
|
|
|
|
queue->last_get_msg = current_time;
|
2021-04-02 18:15:01 -07:00
|
|
|
queue->keystate_lock = 0;
|
2015-03-14 17:09:36 -07:00
|
|
|
+ queue->ignore_post_msg = 0;
|
|
|
|
list_init( &queue->send_result );
|
|
|
|
list_init( &queue->callback_result );
|
|
|
|
list_init( &queue->pending_timers );
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -712,13 +714,21 @@ static inline struct msg_queue *get_current_queue(void)
|
2015-03-14 17:09:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
+}
|
|
|
|
+
|
2023-06-07 16:21:24 -07:00
|
|
|
/* 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 )
|
2015-03-14 17:09:36 -07:00
|
|
|
{
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -1029,7 +1039,7 @@ static int match_window( user_handle_t win, user_handle_t msg_win )
|
2017-02-01 14:43:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 )
|
|
|
|
{
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -1040,6 +1050,7 @@ static int get_posted_message( struct msg_queue *queue, user_handle_t win,
|
2015-03-14 17:09:36 -07:00
|
|
|
{
|
|
|
|
if (!match_window( win, msg->win )) continue;
|
|
|
|
if (!check_msg_filter( msg->msg, first, last )) continue;
|
2017-02-01 14:43:28 -08:00
|
|
|
+ if (ignore_msg && (int)(msg->unique_id - ignore_msg) >= 0) continue;
|
2015-03-14 17:09:36 -07:00
|
|
|
goto found; /* found one */
|
|
|
|
}
|
|
|
|
return 0;
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -1654,6 +1665,7 @@ found:
|
2015-03-14 17:09:36 -07:00
|
|
|
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;
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -2624,7 +2636,7 @@ static int get_hardware_message( struct thread *thread, unsigned int hw_id, user
|
2015-03-14 17:09:36 -07:00
|
|
|
}
|
2022-01-12 17:59:06 -08:00
|
|
|
|
2015-03-14 17:09:36 -07:00
|
|
|
/* 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;
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -2731,6 +2743,7 @@ void post_message( user_handle_t win, unsigned int message, lparam_t wparam, lpa
|
2015-03-14 17:09:36 -07:00
|
|
|
msg->result = NULL;
|
|
|
|
msg->data = NULL;
|
|
|
|
msg->data_size = 0;
|
|
|
|
+ msg->unique_id = get_unique_post_id();
|
|
|
|
|
2015-04-27 14:02:33 -07:00
|
|
|
get_message_defaults( thread->queue, &msg->x, &msg->y, &msg->time );
|
|
|
|
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -3025,6 +3038,7 @@ DECL_HANDLER(send_message)
|
2015-03-14 17:09:36 -07:00
|
|
|
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)
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -3151,12 +3165,12 @@ DECL_HANDLER(get_message)
|
2017-02-01 14:43:28 -08:00
|
|
|
|
|
|
|
/* 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 */
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -3167,7 +3181,7 @@ DECL_HANDLER(get_message)
|
2015-03-14 17:09:36 -07:00
|
|
|
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;
|
|
|
|
|
2024-03-21 17:29:09 -07:00
|
|
|
/* now check for WM_PAINT */
|
|
|
|
if ((filter & QS_PAINT) &&
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -3180,7 +3194,7 @@ DECL_HANDLER(get_message)
|
2015-03-14 17:09:36 -07:00
|
|
|
reply->wparam = 0;
|
|
|
|
reply->lparam = 0;
|
2015-04-27 14:02:33 -07:00
|
|
|
get_message_defaults( queue, &reply->x, &reply->y, &reply->time );
|
2015-03-14 17:09:36 -07:00
|
|
|
- return;
|
|
|
|
+ goto found_msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now check for timer */
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -3196,13 +3210,30 @@ DECL_HANDLER(get_message)
|
2015-04-27 14:02:33 -07:00
|
|
|
get_message_defaults( queue, &reply->x, &reply->y, &reply->time );
|
2015-03-14 17:09:36 -07:00
|
|
|
if (!(req->flags & PM_NOYIELD) && current->process->idle_event)
|
|
|
|
set_event( current->process->idle_event );
|
|
|
|
- return;
|
|
|
|
+ goto found_msg;
|
|
|
|
}
|
|
|
|
|
2017-02-01 14:43:28 -08:00
|
|
|
+ /* 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;
|
|
|
|
+
|
2015-03-14 17:09:36 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-26 15:37:31 -07:00
|
|
|
@@ -3220,7 +3251,10 @@ DECL_HANDLER(reply_message)
|
2015-04-10 13:53:14 -07:00
|
|
|
DECL_HANDLER(accept_hardware_message)
|
|
|
|
{
|
|
|
|
if (current->queue)
|
|
|
|
+ {
|
2020-07-07 15:59:50 -07:00
|
|
|
release_hardware_message( current->queue, req->hw_id );
|
|
|
|
+ current->queue->ignore_post_msg = 0;
|
2015-04-10 13:53:14 -07:00
|
|
|
+ }
|
|
|
|
else
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
}
|
2015-03-14 17:09:36 -07:00
|
|
|
--
|
2023-12-13 15:05:14 -08:00
|
|
|
2.43.0
|
2015-03-14 17:09:36 -07:00
|
|
|
|