Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side message queues |
| 3 | * |
| 4 | * Copyright (C) 2000 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | #include "wine/port.h" |
| 23 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 24 | #include <assert.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 29 | #include "ntstatus.h" |
| 30 | #define WIN32_NO_STATUS |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 31 | #include "windef.h" |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 32 | #include "winbase.h" |
| 33 | #include "wingdi.h" |
| 34 | #include "winuser.h" |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 35 | #include "winternl.h" |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 36 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 37 | #include "handle.h" |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 38 | #include "file.h" |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "process.h" |
| 41 | #include "request.h" |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 42 | #include "user.h" |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 43 | |
Alexandre Julliard | cf2f142 | 2005-03-14 17:17:09 +0000 | [diff] [blame] | 44 | #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE |
Alexandre Julliard | cb7aa87 | 2005-03-24 19:16:54 +0000 | [diff] [blame] | 45 | #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST)) |
Alexandre Julliard | cf2f142 | 2005-03-14 17:17:09 +0000 | [diff] [blame] | 46 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 47 | enum message_kind { SEND_MESSAGE, POST_MESSAGE }; |
| 48 | #define NB_MSG_KINDS (POST_MESSAGE+1) |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 49 | |
| 50 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 51 | struct message_result |
| 52 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 53 | struct list sender_entry; /* entry in sender list */ |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 54 | struct message *msg; /* message the result is for */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 55 | struct message_result *recv_next; /* next in receiver list */ |
| 56 | struct msg_queue *sender; /* sender queue */ |
| 57 | struct msg_queue *receiver; /* receiver queue */ |
| 58 | int replied; /* has it been replied to? */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 59 | unsigned int error; /* error code to pass back to sender */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 60 | lparam_t result; /* reply result */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 61 | struct message *callback_msg; /* message to queue for callback */ |
| 62 | void *data; /* message reply data */ |
| 63 | unsigned int data_size; /* size of message reply data */ |
| 64 | struct timeout_user *timeout; /* result timeout */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct message |
| 68 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 69 | struct list entry; /* entry in message list */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 70 | enum message_type type; /* message type */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 71 | user_handle_t win; /* window handle */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 72 | unsigned int msg; /* message code */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 73 | lparam_t wparam; /* parameters */ |
| 74 | lparam_t lparam; /* parameters */ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 75 | unsigned int time; /* message time */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 76 | void *data; /* message data for sent messages */ |
| 77 | unsigned int data_size; /* size of message data */ |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 78 | unsigned int unique_id; /* unique id for nested hw message waits */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 79 | struct message_result *result; /* result in sender queue */ |
| 80 | }; |
| 81 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 82 | struct timer |
| 83 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 84 | struct list entry; /* entry in timer list */ |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 85 | timeout_t when; /* next expiration */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 86 | unsigned int rate; /* timer rate in ms */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 87 | user_handle_t win; /* window handle */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 88 | unsigned int msg; /* message to post */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 89 | lparam_t id; /* timer id */ |
| 90 | lparam_t lparam; /* lparam for message */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 93 | struct thread_input |
| 94 | { |
| 95 | struct object obj; /* object header */ |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 96 | struct desktop *desktop; /* desktop that this thread input belongs to */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 97 | user_handle_t focus; /* focus window */ |
| 98 | user_handle_t capture; /* capture window */ |
| 99 | user_handle_t active; /* active window */ |
| 100 | user_handle_t menu_owner; /* current menu owner window */ |
| 101 | user_handle_t move_size; /* current moving/resizing window */ |
| 102 | user_handle_t caret; /* caret window */ |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 103 | rectangle_t caret_rect; /* caret rectangle */ |
| 104 | int caret_hide; /* caret hide count */ |
| 105 | int caret_state; /* caret on/off state */ |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 106 | user_handle_t cursor; /* current cursor */ |
| 107 | int cursor_count; /* cursor show count */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 108 | struct list msg_list; /* list of hardware messages */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 109 | unsigned char keystate[256]; /* state of each key */ |
| 110 | }; |
| 111 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 112 | struct msg_queue |
| 113 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 114 | struct object obj; /* object header */ |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 115 | struct fd *fd; /* optional file descriptor to poll */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 116 | unsigned int wake_bits; /* wakeup bits */ |
| 117 | unsigned int wake_mask; /* wakeup mask */ |
| 118 | unsigned int changed_bits; /* changed wakeup bits */ |
| 119 | unsigned int changed_mask; /* changed wakeup mask */ |
| 120 | int paint_count; /* pending paint messages count */ |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 121 | int quit_message; /* is there a pending quit message? */ |
| 122 | int exit_code; /* exit code of pending quit message */ |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 123 | int cursor_count; /* per-queue cursor show count */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 124 | struct list msg_list[NB_MSG_KINDS]; /* lists of messages */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 125 | struct list send_result; /* stack of sent messages waiting for result */ |
| 126 | struct list callback_result; /* list of callback messages waiting for result */ |
| 127 | struct message_result *recv_result; /* stack of received messages waiting for result */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 128 | struct list pending_timers; /* list of pending timers */ |
| 129 | struct list expired_timers; /* list of expired timers */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 130 | lparam_t next_timer_id; /* id for the next timer with a 0 window */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 131 | struct timeout_user *timeout; /* timeout for next timer to expire */ |
| 132 | struct thread_input *input; /* thread input descriptor */ |
| 133 | struct hook_table *hooks; /* hook table */ |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 134 | timeout_t last_get_msg; /* time of last get message call */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | static void msg_queue_dump( struct object *obj, int verbose ); |
| 138 | static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry ); |
| 139 | static void msg_queue_remove_queue( struct object *obj, struct wait_queue_entry *entry ); |
| 140 | static int msg_queue_signaled( struct object *obj, struct thread *thread ); |
| 141 | static int msg_queue_satisfied( struct object *obj, struct thread *thread ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 142 | static void msg_queue_destroy( struct object *obj ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 143 | static void msg_queue_poll_event( struct fd *fd, int event ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 144 | static void thread_input_dump( struct object *obj, int verbose ); |
| 145 | static void thread_input_destroy( struct object *obj ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 146 | static void timer_callback( void *private ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 147 | |
| 148 | static const struct object_ops msg_queue_ops = |
| 149 | { |
| 150 | sizeof(struct msg_queue), /* size */ |
| 151 | msg_queue_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 152 | no_get_type, /* get_type */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 153 | msg_queue_add_queue, /* add_queue */ |
| 154 | msg_queue_remove_queue, /* remove_queue */ |
| 155 | msg_queue_signaled, /* signaled */ |
| 156 | msg_queue_satisfied, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 157 | no_signal, /* signal */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 158 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 159 | no_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 160 | default_get_sd, /* get_sd */ |
| 161 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 162 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 163 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 164 | no_close_handle, /* close_handle */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 165 | msg_queue_destroy /* destroy */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 168 | static const struct fd_ops msg_queue_fd_ops = |
| 169 | { |
| 170 | NULL, /* get_poll_events */ |
| 171 | msg_queue_poll_event, /* poll_event */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 172 | NULL, /* flush */ |
| 173 | NULL, /* get_fd_type */ |
Alexandre Julliard | 6357143 | 2007-04-16 14:45:03 +0200 | [diff] [blame] | 174 | NULL, /* ioctl */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 175 | NULL, /* queue_async */ |
Alexandre Julliard | 72bff2e | 2007-04-10 17:07:27 +0200 | [diff] [blame] | 176 | NULL, /* reselect_async */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 177 | NULL /* cancel async */ |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 178 | }; |
| 179 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 180 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 181 | static const struct object_ops thread_input_ops = |
| 182 | { |
| 183 | sizeof(struct thread_input), /* size */ |
| 184 | thread_input_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 185 | no_get_type, /* get_type */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 186 | no_add_queue, /* add_queue */ |
| 187 | NULL, /* remove_queue */ |
| 188 | NULL, /* signaled */ |
| 189 | NULL, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 190 | no_signal, /* signal */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 191 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 192 | no_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 193 | default_get_sd, /* get_sd */ |
| 194 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 195 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 196 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 197 | no_close_handle, /* close_handle */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 198 | thread_input_destroy /* destroy */ |
| 199 | }; |
| 200 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 201 | /* pointer to input structure of foreground thread */ |
| 202 | static struct thread_input *foreground_input; |
Mike McCormack | abe70f7 | 2005-04-28 12:04:14 +0000 | [diff] [blame] | 203 | static unsigned int last_input_time; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 204 | |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 205 | static void free_message( struct message *msg ); |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 206 | |
| 207 | /* set the caret window in a given thread input */ |
| 208 | static void set_caret_window( struct thread_input *input, user_handle_t win ) |
| 209 | { |
Krzysztof Foltman | b850172 | 2005-02-18 20:02:55 +0000 | [diff] [blame] | 210 | if (!win || win != input->caret) |
| 211 | { |
| 212 | input->caret_rect.left = 0; |
| 213 | input->caret_rect.top = 0; |
| 214 | input->caret_rect.right = 0; |
| 215 | input->caret_rect.bottom = 0; |
| 216 | } |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 217 | input->caret = win; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 218 | input->caret_hide = 1; |
| 219 | input->caret_state = 0; |
| 220 | } |
| 221 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 222 | /* create a thread input object */ |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 223 | static struct thread_input *create_thread_input( struct thread *thread ) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 224 | { |
| 225 | struct thread_input *input; |
| 226 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 227 | if ((input = alloc_object( &thread_input_ops ))) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 228 | { |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 229 | input->focus = 0; |
| 230 | input->capture = 0; |
| 231 | input->active = 0; |
| 232 | input->menu_owner = 0; |
| 233 | input->move_size = 0; |
| 234 | input->cursor = 0; |
| 235 | input->cursor_count = 0; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 236 | list_init( &input->msg_list ); |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 237 | set_caret_window( input, 0 ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 238 | memset( input->keystate, 0, sizeof(input->keystate) ); |
Robert Shearman | d8058fb | 2006-04-07 11:15:19 +0100 | [diff] [blame] | 239 | |
| 240 | if (!(input->desktop = get_thread_desktop( thread, 0 /* FIXME: access rights */ ))) |
| 241 | { |
| 242 | release_object( input ); |
| 243 | return NULL; |
| 244 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 245 | } |
| 246 | return input; |
| 247 | } |
| 248 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 249 | /* create a message queue object */ |
| 250 | static struct msg_queue *create_msg_queue( struct thread *thread, struct thread_input *input ) |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 251 | { |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 252 | struct thread_input *new_input = NULL; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 253 | struct msg_queue *queue; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 254 | int i; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 255 | |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 256 | if (!input) |
| 257 | { |
| 258 | if (!(new_input = create_thread_input( thread ))) return NULL; |
| 259 | input = new_input; |
| 260 | } |
| 261 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 262 | if ((queue = alloc_object( &msg_queue_ops ))) |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 263 | { |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 264 | queue->fd = NULL; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 265 | queue->wake_bits = 0; |
| 266 | queue->wake_mask = 0; |
| 267 | queue->changed_bits = 0; |
| 268 | queue->changed_mask = 0; |
Alexandre Julliard | 4b0343d | 2001-06-20 22:55:31 +0000 | [diff] [blame] | 269 | queue->paint_count = 0; |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 270 | queue->quit_message = 0; |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 271 | queue->cursor_count = 0; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 272 | queue->recv_result = NULL; |
Dmitry Timoshkov | b4227d7 | 2007-11-13 20:41:01 +0800 | [diff] [blame] | 273 | queue->next_timer_id = 0x7fff; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 274 | queue->timeout = NULL; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 275 | queue->input = (struct thread_input *)grab_object( input ); |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 276 | queue->hooks = NULL; |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 277 | queue->last_get_msg = current_time; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 278 | list_init( &queue->send_result ); |
| 279 | list_init( &queue->callback_result ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 280 | list_init( &queue->pending_timers ); |
| 281 | list_init( &queue->expired_timers ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 282 | for (i = 0; i < NB_MSG_KINDS; i++) list_init( &queue->msg_list[i] ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 283 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 284 | thread->queue = queue; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 285 | } |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 286 | if (new_input) release_object( new_input ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 287 | return queue; |
| 288 | } |
| 289 | |
Alexandre Julliard | 31022d6 | 2002-08-16 23:30:41 +0000 | [diff] [blame] | 290 | /* free the message queue of a thread at thread exit */ |
| 291 | void free_msg_queue( struct thread *thread ) |
| 292 | { |
Alexandre Julliard | ca3ac8f | 2003-07-11 21:55:58 +0000 | [diff] [blame] | 293 | remove_thread_hooks( thread ); |
Alexandre Julliard | 31022d6 | 2002-08-16 23:30:41 +0000 | [diff] [blame] | 294 | if (!thread->queue) return; |
Alexandre Julliard | 31022d6 | 2002-08-16 23:30:41 +0000 | [diff] [blame] | 295 | release_object( thread->queue ); |
| 296 | thread->queue = NULL; |
| 297 | } |
| 298 | |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 299 | /* change the thread input data of a given thread */ |
| 300 | static int assign_thread_input( struct thread *thread, struct thread_input *new_input ) |
| 301 | { |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 302 | struct msg_queue *queue = thread->queue; |
| 303 | |
| 304 | if (!queue) |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 305 | { |
| 306 | thread->queue = create_msg_queue( thread, new_input ); |
| 307 | return thread->queue != NULL; |
| 308 | } |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 309 | if (queue->input) |
| 310 | { |
| 311 | queue->input->cursor_count -= queue->cursor_count; |
| 312 | release_object( queue->input ); |
| 313 | } |
| 314 | queue->input = (struct thread_input *)grab_object( new_input ); |
| 315 | new_input->cursor_count += queue->cursor_count; |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 316 | return 1; |
| 317 | } |
| 318 | |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 319 | /* get the hook table for a given thread */ |
| 320 | struct hook_table *get_queue_hooks( struct thread *thread ) |
| 321 | { |
| 322 | if (!thread->queue) return NULL; |
| 323 | return thread->queue->hooks; |
| 324 | } |
| 325 | |
| 326 | /* set the hook table for a given thread, allocating the queue if needed */ |
| 327 | void set_queue_hooks( struct thread *thread, struct hook_table *hooks ) |
| 328 | { |
| 329 | struct msg_queue *queue = thread->queue; |
Alexandre Julliard | d70a253 | 2005-04-26 14:31:33 +0000 | [diff] [blame] | 330 | if (!queue && !(queue = create_msg_queue( thread, NULL ))) return; |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 331 | if (queue->hooks) release_object( queue->hooks ); |
| 332 | queue->hooks = hooks; |
| 333 | } |
| 334 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 335 | /* check the queue status */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 336 | static inline int is_signaled( struct msg_queue *queue ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 337 | { |
| 338 | return ((queue->wake_bits & queue->wake_mask) || (queue->changed_bits & queue->changed_mask)); |
| 339 | } |
| 340 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 341 | /* set some queue bits */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 342 | static inline void set_queue_bits( struct msg_queue *queue, unsigned int bits ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 343 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 344 | queue->wake_bits |= bits; |
| 345 | queue->changed_bits |= bits; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 346 | if (is_signaled( queue )) wake_up( &queue->obj, 0 ); |
| 347 | } |
| 348 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 349 | /* clear some queue bits */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 350 | static inline void clear_queue_bits( struct msg_queue *queue, unsigned int bits ) |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 351 | { |
| 352 | queue->wake_bits &= ~bits; |
| 353 | queue->changed_bits &= ~bits; |
| 354 | } |
| 355 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 356 | /* check whether msg is a keyboard message */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 357 | static inline int is_keyboard_msg( struct message *msg ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 358 | { |
| 359 | return (msg->msg >= WM_KEYFIRST && msg->msg <= WM_KEYLAST); |
| 360 | } |
| 361 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 362 | /* check if message is matched by the filter */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 363 | static inline int check_msg_filter( unsigned int msg, unsigned int first, unsigned int last ) |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 364 | { |
| 365 | return (msg >= first && msg <= last); |
| 366 | } |
| 367 | |
Alexandre Julliard | cf2f142 | 2005-03-14 17:17:09 +0000 | [diff] [blame] | 368 | /* check whether a message filter contains at least one potential hardware message */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 369 | static inline int filter_contains_hw_range( unsigned int first, unsigned int last ) |
Alexandre Julliard | cf2f142 | 2005-03-14 17:17:09 +0000 | [diff] [blame] | 370 | { |
| 371 | /* hardware message ranges are (in numerical order): |
| 372 | * WM_NCMOUSEFIRST .. WM_NCMOUSELAST |
| 373 | * WM_KEYFIRST .. WM_KEYLAST |
| 374 | * WM_MOUSEFIRST .. WM_MOUSELAST |
| 375 | */ |
| 376 | if (last < WM_NCMOUSEFIRST) return 0; |
| 377 | if (first > WM_NCMOUSELAST && last < WM_KEYFIRST) return 0; |
| 378 | if (first > WM_KEYLAST && last < WM_MOUSEFIRST) return 0; |
| 379 | if (first > WM_MOUSELAST) return 0; |
| 380 | return 1; |
| 381 | } |
| 382 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 383 | /* get the QS_* bit corresponding to a given hardware message */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 384 | static inline int get_hardware_msg_bit( struct message *msg ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 385 | { |
| 386 | if (msg->msg == WM_MOUSEMOVE || msg->msg == WM_NCMOUSEMOVE) return QS_MOUSEMOVE; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 387 | if (is_keyboard_msg( msg )) return QS_KEY; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 388 | return QS_MOUSEBUTTON; |
| 389 | } |
| 390 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 391 | /* get the current thread queue, creating it if needed */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 392 | static inline struct msg_queue *get_current_queue(void) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 393 | { |
| 394 | struct msg_queue *queue = current->queue; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 395 | if (!queue) queue = create_msg_queue( current, NULL ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 396 | return queue; |
| 397 | } |
| 398 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 399 | /* get a (pseudo-)unique id to tag hardware messages */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 400 | static inline unsigned int get_unique_id(void) |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 401 | { |
| 402 | static unsigned int id; |
| 403 | if (!++id) id = 1; /* avoid an id of 0 */ |
| 404 | return id; |
| 405 | } |
| 406 | |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 407 | /* try to merge a message with the last in the list; return 1 if successful */ |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 408 | static int merge_message( struct thread_input *input, const struct message *msg ) |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 409 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 410 | struct message *prev; |
| 411 | struct list *ptr = list_tail( &input->msg_list ); |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 412 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 413 | if (!ptr) return 0; |
| 414 | prev = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 415 | if (prev->result) return 0; |
Alexandre Julliard | 942a70d | 2007-11-27 16:43:00 +0100 | [diff] [blame] | 416 | if (prev->win && msg->win && prev->win != msg->win) return 0; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 417 | if (prev->msg != msg->msg) return 0; |
| 418 | if (prev->type != msg->type) return 0; |
| 419 | /* now we can merge it */ |
| 420 | prev->wparam = msg->wparam; |
| 421 | prev->lparam = msg->lparam; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 422 | prev->time = msg->time; |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 423 | if (msg->type == MSG_HARDWARE && prev->data && msg->data) |
| 424 | { |
| 425 | struct hardware_msg_data *prev_data = prev->data; |
| 426 | struct hardware_msg_data *msg_data = msg->data; |
| 427 | prev_data->x = msg_data->x; |
| 428 | prev_data->y = msg_data->y; |
| 429 | prev_data->info = msg_data->info; |
| 430 | } |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 431 | return 1; |
| 432 | } |
| 433 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 434 | /* free a result structure */ |
| 435 | static void free_result( struct message_result *result ) |
| 436 | { |
| 437 | if (result->timeout) remove_timeout_user( result->timeout ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 438 | free( result->data ); |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 439 | if (result->callback_msg) free_message( result->callback_msg ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 440 | free( result ); |
| 441 | } |
| 442 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 443 | /* remove the result from the sender list it is on */ |
| 444 | static inline void remove_result_from_sender( struct message_result *result ) |
| 445 | { |
| 446 | assert( result->sender ); |
| 447 | |
| 448 | list_remove( &result->sender_entry ); |
| 449 | result->sender = NULL; |
| 450 | if (!result->receiver) free_result( result ); |
| 451 | } |
| 452 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 453 | /* store the message result in the appropriate structure */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 454 | static void store_message_result( struct message_result *res, lparam_t result, unsigned int error ) |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 455 | { |
| 456 | res->result = result; |
| 457 | res->error = error; |
| 458 | res->replied = 1; |
| 459 | if (res->timeout) |
| 460 | { |
| 461 | remove_timeout_user( res->timeout ); |
| 462 | res->timeout = NULL; |
| 463 | } |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 464 | if (res->sender) |
| 465 | { |
| 466 | if (res->callback_msg) |
| 467 | { |
| 468 | /* queue the callback message in the sender queue */ |
Alexandre Julliard | 29a3ce9 | 2006-10-04 16:29:45 +0200 | [diff] [blame] | 469 | struct callback_msg_data *data = res->callback_msg->data; |
| 470 | data->result = result; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 471 | list_add_tail( &res->sender->msg_list[SEND_MESSAGE], &res->callback_msg->entry ); |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 472 | set_queue_bits( res->sender, QS_SENDMESSAGE ); |
| 473 | res->callback_msg = NULL; |
| 474 | remove_result_from_sender( res ); |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | /* wake sender queue if waiting on this result */ |
| 479 | if (list_head(&res->sender->send_result) == &res->sender_entry) |
| 480 | set_queue_bits( res->sender, QS_SMRESULT ); |
| 481 | } |
| 482 | } |
| 483 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 486 | /* free a message when deleting a queue or window */ |
| 487 | static void free_message( struct message *msg ) |
| 488 | { |
| 489 | struct message_result *result = msg->result; |
| 490 | if (result) |
| 491 | { |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 492 | result->msg = NULL; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 493 | if (result->sender) |
| 494 | { |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 495 | result->receiver = NULL; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 496 | store_message_result( result, 0, STATUS_ACCESS_DENIED /*FIXME*/ ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 497 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 498 | else free_result( result ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 499 | } |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 500 | free( msg->data ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 501 | free( msg ); |
| 502 | } |
| 503 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 504 | /* remove (and free) a message from a message list */ |
| 505 | static void remove_queue_message( struct msg_queue *queue, struct message *msg, |
| 506 | enum message_kind kind ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 507 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 508 | list_remove( &msg->entry ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 509 | switch(kind) |
| 510 | { |
| 511 | case SEND_MESSAGE: |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 512 | if (list_empty( &queue->msg_list[kind] )) clear_queue_bits( queue, QS_SENDMESSAGE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 513 | break; |
| 514 | case POST_MESSAGE: |
Robert Shearman | 22bd7a3 | 2006-05-22 22:16:53 +0100 | [diff] [blame] | 515 | if (list_empty( &queue->msg_list[kind] ) && !queue->quit_message) |
| 516 | clear_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 517 | break; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 518 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 519 | free_message( msg ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 522 | /* message timed out without getting a reply */ |
| 523 | static void result_timeout( void *private ) |
| 524 | { |
| 525 | struct message_result *result = private; |
| 526 | |
| 527 | assert( !result->replied ); |
| 528 | |
| 529 | result->timeout = NULL; |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 530 | |
| 531 | if (result->msg) /* not received yet */ |
| 532 | { |
| 533 | struct message *msg = result->msg; |
| 534 | |
| 535 | result->msg = NULL; |
| 536 | msg->result = NULL; |
| 537 | remove_queue_message( result->receiver, msg, SEND_MESSAGE ); |
| 538 | result->receiver = NULL; |
| 539 | if (!result->sender) |
| 540 | { |
| 541 | free_result( result ); |
| 542 | return; |
| 543 | } |
| 544 | } |
| 545 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 546 | store_message_result( result, 0, STATUS_TIMEOUT ); |
| 547 | } |
| 548 | |
| 549 | /* allocate and fill a message result structure */ |
| 550 | static struct message_result *alloc_message_result( struct msg_queue *send_queue, |
| 551 | struct msg_queue *recv_queue, |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 552 | struct message *msg, timeout_t timeout ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 553 | { |
| 554 | struct message_result *result = mem_alloc( sizeof(*result) ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 555 | if (result) |
| 556 | { |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 557 | result->msg = msg; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 558 | result->sender = send_queue; |
| 559 | result->receiver = recv_queue; |
| 560 | result->replied = 0; |
| 561 | result->data = NULL; |
| 562 | result->data_size = 0; |
| 563 | result->timeout = NULL; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 564 | |
| 565 | if (msg->type == MSG_CALLBACK) |
| 566 | { |
| 567 | struct message *callback_msg = mem_alloc( sizeof(*callback_msg) ); |
Alexandre Julliard | 29a3ce9 | 2006-10-04 16:29:45 +0200 | [diff] [blame] | 568 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 569 | if (!callback_msg) |
| 570 | { |
| 571 | free( result ); |
| 572 | return NULL; |
| 573 | } |
| 574 | callback_msg->type = MSG_CALLBACK_RESULT; |
| 575 | callback_msg->win = msg->win; |
| 576 | callback_msg->msg = msg->msg; |
Alexandre Julliard | 29a3ce9 | 2006-10-04 16:29:45 +0200 | [diff] [blame] | 577 | callback_msg->wparam = 0; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 578 | callback_msg->lparam = 0; |
| 579 | callback_msg->time = get_tick_count(); |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 580 | callback_msg->result = NULL; |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 581 | /* steal the data from the original message */ |
| 582 | callback_msg->data = msg->data; |
| 583 | callback_msg->data_size = msg->data_size; |
| 584 | msg->data = NULL; |
| 585 | msg->data_size = 0; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 586 | |
| 587 | result->callback_msg = callback_msg; |
| 588 | list_add_head( &send_queue->callback_result, &result->sender_entry ); |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | result->callback_msg = NULL; |
| 593 | list_add_head( &send_queue->send_result, &result->sender_entry ); |
| 594 | } |
| 595 | |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 596 | if (timeout != TIMEOUT_INFINITE) |
| 597 | result->timeout = add_timeout_user( timeout, result_timeout, result ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 598 | } |
| 599 | return result; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* receive a message, removing it from the sent queue */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 603 | static void receive_message( struct msg_queue *queue, struct message *msg, |
| 604 | struct get_message_reply *reply ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 605 | { |
| 606 | struct message_result *result = msg->result; |
| 607 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 608 | reply->total = msg->data_size; |
| 609 | if (msg->data_size > get_reply_max_size()) |
| 610 | { |
| 611 | set_error( STATUS_BUFFER_OVERFLOW ); |
| 612 | return; |
| 613 | } |
| 614 | reply->type = msg->type; |
| 615 | reply->win = msg->win; |
| 616 | reply->msg = msg->msg; |
| 617 | reply->wparam = msg->wparam; |
| 618 | reply->lparam = msg->lparam; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 619 | reply->time = msg->time; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 620 | |
| 621 | if (msg->data) set_reply_data_ptr( msg->data, msg->data_size ); |
| 622 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 623 | list_remove( &msg->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 624 | /* put the result on the receiver result stack */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 625 | if (result) |
| 626 | { |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 627 | result->msg = NULL; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 628 | result->recv_next = queue->recv_result; |
| 629 | queue->recv_result = result; |
| 630 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 631 | free( msg ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 632 | if (list_empty( &queue->msg_list[SEND_MESSAGE] )) clear_queue_bits( queue, QS_SENDMESSAGE ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* set the result of the current received message */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 636 | static void reply_message( struct msg_queue *queue, lparam_t result, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 637 | unsigned int error, int remove, const void *data, data_size_t len ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 638 | { |
| 639 | struct message_result *res = queue->recv_result; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 640 | |
| 641 | if (remove) |
| 642 | { |
| 643 | queue->recv_result = res->recv_next; |
| 644 | res->receiver = NULL; |
| 645 | if (!res->sender) /* no one waiting for it */ |
| 646 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 647 | free_result( res ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 648 | return; |
| 649 | } |
| 650 | } |
| 651 | if (!res->replied) |
| 652 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 653 | if (len && (res->data = memdup( data, len ))) res->data_size = len; |
| 654 | store_message_result( res, result, error ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
Dmitry Timoshkov | acb0566 | 2009-06-11 21:49:31 +0900 | [diff] [blame] | 658 | static int match_window( user_handle_t win, user_handle_t msg_win ) |
| 659 | { |
| 660 | if (!win) return 1; |
Alexandre Julliard | 4d33d49 | 2010-03-03 13:18:33 +0100 | [diff] [blame] | 661 | if (win == -1 || win == 1) return !msg_win; |
Dmitry Timoshkov | acb0566 | 2009-06-11 21:49:31 +0900 | [diff] [blame] | 662 | if (msg_win == win) return 1; |
| 663 | return is_child_window( win, msg_win ); |
| 664 | } |
| 665 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 666 | /* retrieve a posted message */ |
| 667 | static int get_posted_message( struct msg_queue *queue, user_handle_t win, |
| 668 | unsigned int first, unsigned int last, unsigned int flags, |
| 669 | struct get_message_reply *reply ) |
| 670 | { |
| 671 | struct message *msg; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 672 | |
| 673 | /* check against the filters */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 674 | LIST_FOR_EACH_ENTRY( msg, &queue->msg_list[POST_MESSAGE], struct message, entry ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 675 | { |
Dmitry Timoshkov | acb0566 | 2009-06-11 21:49:31 +0900 | [diff] [blame] | 676 | if (!match_window( win, msg->win )) continue; |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 677 | if (!check_msg_filter( msg->msg, first, last )) continue; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 678 | goto found; /* found one */ |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 679 | } |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 680 | return 0; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 681 | |
| 682 | /* return it to the app */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 683 | found: |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 684 | reply->total = msg->data_size; |
| 685 | if (msg->data_size > get_reply_max_size()) |
| 686 | { |
| 687 | set_error( STATUS_BUFFER_OVERFLOW ); |
| 688 | return 1; |
| 689 | } |
| 690 | reply->type = msg->type; |
| 691 | reply->win = msg->win; |
| 692 | reply->msg = msg->msg; |
| 693 | reply->wparam = msg->wparam; |
| 694 | reply->lparam = msg->lparam; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 695 | reply->time = msg->time; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 696 | |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 697 | if (flags & PM_REMOVE) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 698 | { |
| 699 | if (msg->data) |
| 700 | { |
| 701 | set_reply_data_ptr( msg->data, msg->data_size ); |
| 702 | msg->data = NULL; |
| 703 | msg->data_size = 0; |
| 704 | } |
| 705 | remove_queue_message( queue, msg, POST_MESSAGE ); |
| 706 | } |
| 707 | else if (msg->data) set_reply_data( msg->data, msg->data_size ); |
| 708 | |
| 709 | return 1; |
| 710 | } |
| 711 | |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 712 | static int get_quit_message( struct msg_queue *queue, unsigned int flags, |
| 713 | struct get_message_reply *reply ) |
| 714 | { |
| 715 | if (queue->quit_message) |
| 716 | { |
| 717 | reply->total = 0; |
| 718 | reply->type = MSG_POSTED; |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 719 | reply->win = 0; |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 720 | reply->msg = WM_QUIT; |
| 721 | reply->wparam = queue->exit_code; |
| 722 | reply->lparam = 0; |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 723 | reply->time = get_tick_count(); |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 724 | |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 725 | if (flags & PM_REMOVE) |
Robert Shearman | 22bd7a3 | 2006-05-22 22:16:53 +0100 | [diff] [blame] | 726 | { |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 727 | queue->quit_message = 0; |
Robert Shearman | 22bd7a3 | 2006-05-22 22:16:53 +0100 | [diff] [blame] | 728 | if (list_empty( &queue->msg_list[POST_MESSAGE] )) |
| 729 | clear_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
| 730 | } |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 731 | return 1; |
| 732 | } |
| 733 | else |
| 734 | return 0; |
| 735 | } |
| 736 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 737 | /* empty a message list and free all the messages */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 738 | static void empty_msg_list( struct list *list ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 739 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 740 | struct list *ptr; |
| 741 | |
| 742 | while ((ptr = list_head( list )) != NULL) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 743 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 744 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
| 745 | list_remove( &msg->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 746 | free_message( msg ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
| 750 | /* cleanup all pending results when deleting a queue */ |
| 751 | static void cleanup_results( struct msg_queue *queue ) |
| 752 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 753 | struct list *entry; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 754 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 755 | while ((entry = list_head( &queue->send_result )) != NULL) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 756 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 757 | remove_result_from_sender( LIST_ENTRY( entry, struct message_result, sender_entry ) ); |
| 758 | } |
| 759 | |
| 760 | while ((entry = list_head( &queue->callback_result )) != NULL) |
| 761 | { |
| 762 | remove_result_from_sender( LIST_ENTRY( entry, struct message_result, sender_entry ) ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 765 | while (queue->recv_result) |
| 766 | reply_message( queue, 0, STATUS_ACCESS_DENIED /*FIXME*/, 1, NULL, 0 ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 769 | /* check if the thread owning the queue is hung (not checking for messages) */ |
| 770 | static int is_queue_hung( struct msg_queue *queue ) |
| 771 | { |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 772 | struct wait_queue_entry *entry; |
| 773 | |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 774 | if (current_time - queue->last_get_msg <= 5 * TICKS_PER_SEC) |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 775 | return 0; /* less than 5 seconds since last get message -> not hung */ |
| 776 | |
Alexandre Julliard | aa34768 | 2005-03-01 11:49:58 +0000 | [diff] [blame] | 777 | LIST_FOR_EACH_ENTRY( entry, &queue->obj.wait_queue, struct wait_queue_entry, entry ) |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 778 | { |
| 779 | if (entry->thread->queue == queue) |
| 780 | return 0; /* thread is waiting on queue -> not hung */ |
| 781 | } |
| 782 | return 1; |
| 783 | } |
| 784 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 785 | static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry ) |
| 786 | { |
| 787 | struct msg_queue *queue = (struct msg_queue *)obj; |
| 788 | struct process *process = entry->thread->process; |
| 789 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 790 | /* a thread can only wait on its own queue */ |
| 791 | if (entry->thread->queue != queue) |
| 792 | { |
| 793 | set_error( STATUS_ACCESS_DENIED ); |
| 794 | return 0; |
| 795 | } |
Alexandre Julliard | 92e704e | 2009-12-16 17:32:15 +0100 | [diff] [blame] | 796 | if (process->idle_event && !(queue->wake_mask & QS_SMRESULT)) set_event( process->idle_event ); |
Alexandre Julliard | 7d4e284 | 2009-12-16 17:25:01 +0100 | [diff] [blame] | 797 | |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 798 | if (queue->fd && list_empty( &obj->wait_queue )) /* first on the queue */ |
| 799 | set_fd_events( queue->fd, POLLIN ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 800 | add_queue( obj, entry ); |
| 801 | return 1; |
| 802 | } |
| 803 | |
| 804 | static void msg_queue_remove_queue(struct object *obj, struct wait_queue_entry *entry ) |
| 805 | { |
| 806 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 807 | |
| 808 | remove_queue( obj, entry ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 809 | if (queue->fd && list_empty( &obj->wait_queue )) /* last on the queue is gone */ |
| 810 | set_fd_events( queue->fd, 0 ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static void msg_queue_dump( struct object *obj, int verbose ) |
| 814 | { |
| 815 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 816 | fprintf( stderr, "Msg queue bits=%x mask=%x\n", |
| 817 | queue->wake_bits, queue->wake_mask ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static int msg_queue_signaled( struct object *obj, struct thread *thread ) |
| 821 | { |
| 822 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 823 | int ret = 0; |
| 824 | |
| 825 | if (queue->fd) |
| 826 | { |
| 827 | if ((ret = check_fd_events( queue->fd, POLLIN ))) |
| 828 | /* stop waiting on select() if we are signaled */ |
| 829 | set_fd_events( queue->fd, 0 ); |
| 830 | else if (!list_empty( &obj->wait_queue )) |
| 831 | /* restart waiting on poll() if we are no longer signaled */ |
| 832 | set_fd_events( queue->fd, POLLIN ); |
| 833 | } |
| 834 | return ret || is_signaled( queue ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | static int msg_queue_satisfied( struct object *obj, struct thread *thread ) |
| 838 | { |
| 839 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 840 | queue->wake_mask = 0; |
| 841 | queue->changed_mask = 0; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 842 | return 0; /* Not abandoned */ |
| 843 | } |
| 844 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 845 | static void msg_queue_destroy( struct object *obj ) |
| 846 | { |
| 847 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 848 | struct list *ptr; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 849 | int i; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 850 | |
| 851 | cleanup_results( queue ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 852 | for (i = 0; i < NB_MSG_KINDS; i++) empty_msg_list( &queue->msg_list[i] ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 853 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 854 | while ((ptr = list_head( &queue->pending_timers ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 855 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 856 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 857 | list_remove( &timer->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 858 | free( timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 859 | } |
| 860 | while ((ptr = list_head( &queue->expired_timers ))) |
| 861 | { |
| 862 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 863 | list_remove( &timer->entry ); |
| 864 | free( timer ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 865 | } |
| 866 | if (queue->timeout) remove_timeout_user( queue->timeout ); |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 867 | if (queue->input) |
| 868 | { |
| 869 | queue->input->cursor_count -= queue->cursor_count; |
| 870 | release_object( queue->input ); |
| 871 | } |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 872 | if (queue->hooks) release_object( queue->hooks ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 873 | if (queue->fd) release_object( queue->fd ); |
| 874 | } |
| 875 | |
| 876 | static void msg_queue_poll_event( struct fd *fd, int event ) |
| 877 | { |
| 878 | struct msg_queue *queue = get_fd_user( fd ); |
| 879 | assert( queue->obj.ops == &msg_queue_ops ); |
| 880 | |
| 881 | if (event & (POLLERR | POLLHUP)) set_fd_events( fd, -1 ); |
Alexandre Julliard | 2d69ba4 | 2009-06-02 22:14:40 +0200 | [diff] [blame] | 882 | else set_fd_events( queue->fd, 0 ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 883 | wake_up( &queue->obj, 0 ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 886 | static void thread_input_dump( struct object *obj, int verbose ) |
| 887 | { |
| 888 | struct thread_input *input = (struct thread_input *)obj; |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 889 | fprintf( stderr, "Thread input focus=%08x capture=%08x active=%08x\n", |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 890 | input->focus, input->capture, input->active ); |
| 891 | } |
| 892 | |
| 893 | static void thread_input_destroy( struct object *obj ) |
| 894 | { |
| 895 | struct thread_input *input = (struct thread_input *)obj; |
| 896 | |
| 897 | if (foreground_input == input) foreground_input = NULL; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 898 | empty_msg_list( &input->msg_list ); |
Robert Shearman | d8058fb | 2006-04-07 11:15:19 +0100 | [diff] [blame] | 899 | if (input->desktop) release_object( input->desktop ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /* fix the thread input data when a window is destroyed */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 903 | static inline void thread_input_cleanup_window( struct msg_queue *queue, user_handle_t window ) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 904 | { |
| 905 | struct thread_input *input = queue->input; |
| 906 | |
| 907 | if (window == input->focus) input->focus = 0; |
| 908 | if (window == input->capture) input->capture = 0; |
| 909 | if (window == input->active) input->active = 0; |
| 910 | if (window == input->menu_owner) input->menu_owner = 0; |
| 911 | if (window == input->move_size) input->move_size = 0; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 912 | if (window == input->caret) set_caret_window( input, 0 ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 915 | /* check if the specified window can be set in the input data of a given queue */ |
| 916 | static int check_queue_input_window( struct msg_queue *queue, user_handle_t window ) |
| 917 | { |
| 918 | struct thread *thread; |
| 919 | int ret = 0; |
| 920 | |
| 921 | if (!window) return 1; /* we can always clear the data */ |
| 922 | |
| 923 | if ((thread = get_window_thread( window ))) |
| 924 | { |
| 925 | ret = (queue->input == thread->queue->input); |
| 926 | if (!ret) set_error( STATUS_ACCESS_DENIED ); |
| 927 | release_object( thread ); |
| 928 | } |
| 929 | else set_error( STATUS_INVALID_HANDLE ); |
| 930 | |
| 931 | return ret; |
| 932 | } |
| 933 | |
Alexandre Julliard | d70a253 | 2005-04-26 14:31:33 +0000 | [diff] [blame] | 934 | /* make sure the specified thread has a queue */ |
| 935 | int init_thread_queue( struct thread *thread ) |
| 936 | { |
| 937 | if (thread->queue) return 1; |
| 938 | return (create_msg_queue( thread, NULL ) != NULL); |
| 939 | } |
| 940 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 941 | /* attach two thread input data structures */ |
| 942 | int attach_thread_input( struct thread *thread_from, struct thread *thread_to ) |
| 943 | { |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 944 | struct desktop *desktop; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 945 | struct thread_input *input; |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 946 | int ret; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 947 | |
| 948 | if (!thread_to->queue && !(thread_to->queue = create_msg_queue( thread_to, NULL ))) return 0; |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 949 | if (!(desktop = get_thread_desktop( thread_from, 0 ))) return 0; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 950 | input = (struct thread_input *)grab_object( thread_to->queue->input ); |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 951 | if (input->desktop != desktop) |
| 952 | { |
| 953 | set_error( STATUS_ACCESS_DENIED ); |
| 954 | release_object( input ); |
| 955 | release_object( desktop ); |
| 956 | return 0; |
| 957 | } |
| 958 | release_object( desktop ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 959 | |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 960 | ret = assign_thread_input( thread_from, input ); |
| 961 | if (ret) memset( input->keystate, 0, sizeof(input->keystate) ); |
| 962 | release_object( input ); |
| 963 | return ret; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | /* detach two thread input data structures */ |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 967 | void detach_thread_input( struct thread *thread_from ) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 968 | { |
| 969 | struct thread_input *input; |
| 970 | |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 971 | if ((input = create_thread_input( thread_from ))) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 972 | { |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 973 | assign_thread_input( thread_from, input ); |
| 974 | release_object( input ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 979 | /* set the next timer to expire */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 980 | static void set_next_timer( struct msg_queue *queue ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 981 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 982 | struct list *ptr; |
| 983 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 984 | if (queue->timeout) |
| 985 | { |
| 986 | remove_timeout_user( queue->timeout ); |
| 987 | queue->timeout = NULL; |
| 988 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 989 | if ((ptr = list_head( &queue->pending_timers ))) |
| 990 | { |
| 991 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 992 | queue->timeout = add_timeout_user( timer->when, timer_callback, queue ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 993 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 994 | /* set/clear QS_TIMER bit */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 995 | if (list_empty( &queue->expired_timers )) |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 996 | clear_queue_bits( queue, QS_TIMER ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 997 | else |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 998 | set_queue_bits( queue, QS_TIMER ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1001 | /* find a timer from its window and id */ |
| 1002 | static struct timer *find_timer( struct msg_queue *queue, user_handle_t win, |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 1003 | unsigned int msg, lparam_t id ) |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1004 | { |
| 1005 | struct list *ptr; |
| 1006 | |
| 1007 | /* we need to search both lists */ |
| 1008 | |
| 1009 | LIST_FOR_EACH( ptr, &queue->pending_timers ) |
| 1010 | { |
| 1011 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1012 | if (timer->win == win && timer->msg == msg && timer->id == id) return timer; |
| 1013 | } |
| 1014 | LIST_FOR_EACH( ptr, &queue->expired_timers ) |
| 1015 | { |
| 1016 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1017 | if (timer->win == win && timer->msg == msg && timer->id == id) return timer; |
| 1018 | } |
| 1019 | return NULL; |
| 1020 | } |
| 1021 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1022 | /* callback for the next timer expiration */ |
| 1023 | static void timer_callback( void *private ) |
| 1024 | { |
| 1025 | struct msg_queue *queue = private; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1026 | struct list *ptr; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1027 | |
| 1028 | queue->timeout = NULL; |
| 1029 | /* move on to the next timer */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1030 | ptr = list_head( &queue->pending_timers ); |
| 1031 | list_remove( ptr ); |
| 1032 | list_add_tail( &queue->expired_timers, ptr ); |
| 1033 | set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* link a timer at its rightful place in the queue list */ |
| 1037 | static void link_timer( struct msg_queue *queue, struct timer *timer ) |
| 1038 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1039 | struct list *ptr; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1040 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1041 | for (ptr = queue->pending_timers.next; ptr != &queue->pending_timers; ptr = ptr->next) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1042 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1043 | struct timer *t = LIST_ENTRY( ptr, struct timer, entry ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1044 | if (t->when >= timer->when) break; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1045 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1046 | list_add_before( ptr, &timer->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1049 | /* remove a timer from the queue timer list and free it */ |
| 1050 | static void free_timer( struct msg_queue *queue, struct timer *timer ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1051 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1052 | list_remove( &timer->entry ); |
| 1053 | free( timer ); |
| 1054 | set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /* restart an expired timer */ |
| 1058 | static void restart_timer( struct msg_queue *queue, struct timer *timer ) |
| 1059 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1060 | list_remove( &timer->entry ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1061 | while (timer->when <= current_time) timer->when += (timeout_t)timer->rate * 10000; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1062 | link_timer( queue, timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1063 | set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | /* find an expired timer matching the filtering parameters */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1067 | static struct timer *find_expired_timer( struct msg_queue *queue, user_handle_t win, |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1068 | unsigned int get_first, unsigned int get_last, |
| 1069 | int remove ) |
| 1070 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1071 | struct list *ptr; |
| 1072 | |
| 1073 | LIST_FOR_EACH( ptr, &queue->expired_timers ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1074 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1075 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1076 | if (win && timer->win != win) continue; |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1077 | if (check_msg_filter( timer->msg, get_first, get_last )) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1078 | { |
| 1079 | if (remove) restart_timer( queue, timer ); |
| 1080 | return timer; |
| 1081 | } |
| 1082 | } |
| 1083 | return NULL; |
| 1084 | } |
| 1085 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1086 | /* add a timer */ |
| 1087 | static struct timer *set_timer( struct msg_queue *queue, unsigned int rate ) |
| 1088 | { |
| 1089 | struct timer *timer = mem_alloc( sizeof(*timer) ); |
| 1090 | if (timer) |
| 1091 | { |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 1092 | timer->rate = max( rate, 1 ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1093 | timer->when = current_time + (timeout_t)timer->rate * 10000; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1094 | link_timer( queue, timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1095 | /* check if we replaced the next timer */ |
| 1096 | if (list_head( &queue->pending_timers ) == &timer->entry) set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1097 | } |
| 1098 | return timer; |
| 1099 | } |
| 1100 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1101 | /* change the input key state for a given key */ |
| 1102 | static void set_input_key_state( struct thread_input *input, unsigned char key, int down ) |
| 1103 | { |
| 1104 | if (down) |
| 1105 | { |
| 1106 | if (!(input->keystate[key] & 0x80)) input->keystate[key] ^= 0x01; |
| 1107 | input->keystate[key] |= 0x80; |
| 1108 | } |
| 1109 | else input->keystate[key] &= ~0x80; |
| 1110 | } |
| 1111 | |
| 1112 | /* update the input key state for a keyboard message */ |
| 1113 | static void update_input_key_state( struct thread_input *input, const struct message *msg ) |
| 1114 | { |
| 1115 | unsigned char key; |
Vitaliy Margolen | 9faf7e3 | 2008-04-01 23:13:45 -0600 | [diff] [blame] | 1116 | int down = 0; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1117 | |
| 1118 | switch (msg->msg) |
| 1119 | { |
| 1120 | case WM_LBUTTONDOWN: |
| 1121 | down = 1; |
| 1122 | /* fall through */ |
| 1123 | case WM_LBUTTONUP: |
| 1124 | set_input_key_state( input, VK_LBUTTON, down ); |
| 1125 | break; |
| 1126 | case WM_MBUTTONDOWN: |
| 1127 | down = 1; |
| 1128 | /* fall through */ |
| 1129 | case WM_MBUTTONUP: |
| 1130 | set_input_key_state( input, VK_MBUTTON, down ); |
| 1131 | break; |
| 1132 | case WM_RBUTTONDOWN: |
| 1133 | down = 1; |
| 1134 | /* fall through */ |
| 1135 | case WM_RBUTTONUP: |
| 1136 | set_input_key_state( input, VK_RBUTTON, down ); |
| 1137 | break; |
Alexandre Julliard | cb7aa87 | 2005-03-24 19:16:54 +0000 | [diff] [blame] | 1138 | case WM_XBUTTONDOWN: |
| 1139 | down = 1; |
| 1140 | /* fall through */ |
| 1141 | case WM_XBUTTONUP: |
| 1142 | if (msg->wparam == XBUTTON1) set_input_key_state( input, VK_XBUTTON1, down ); |
| 1143 | else if (msg->wparam == XBUTTON2) set_input_key_state( input, VK_XBUTTON2, down ); |
| 1144 | break; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1145 | case WM_KEYDOWN: |
| 1146 | case WM_SYSKEYDOWN: |
| 1147 | down = 1; |
| 1148 | /* fall through */ |
| 1149 | case WM_KEYUP: |
| 1150 | case WM_SYSKEYUP: |
| 1151 | key = (unsigned char)msg->wparam; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1152 | set_input_key_state( input, key, down ); |
| 1153 | switch(key) |
| 1154 | { |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1155 | case VK_LCONTROL: |
| 1156 | case VK_RCONTROL: |
Vitaliy Margolen | 9faf7e3 | 2008-04-01 23:13:45 -0600 | [diff] [blame] | 1157 | down = (input->keystate[VK_LCONTROL] | input->keystate[VK_RCONTROL]) & 0x80; |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1158 | set_input_key_state( input, VK_CONTROL, down ); |
| 1159 | break; |
| 1160 | case VK_LMENU: |
| 1161 | case VK_RMENU: |
Vitaliy Margolen | 9faf7e3 | 2008-04-01 23:13:45 -0600 | [diff] [blame] | 1162 | down = (input->keystate[VK_LMENU] | input->keystate[VK_RMENU]) & 0x80; |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1163 | set_input_key_state( input, VK_MENU, down ); |
| 1164 | break; |
| 1165 | case VK_LSHIFT: |
| 1166 | case VK_RSHIFT: |
Vitaliy Margolen | 9faf7e3 | 2008-04-01 23:13:45 -0600 | [diff] [blame] | 1167 | down = (input->keystate[VK_LSHIFT] | input->keystate[VK_RSHIFT]) & 0x80; |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1168 | set_input_key_state( input, VK_SHIFT, down ); |
| 1169 | break; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1170 | } |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1175 | /* release the hardware message currently being processed by the given thread */ |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1176 | static void release_hardware_message( struct msg_queue *queue, unsigned int hw_id, |
| 1177 | int remove, user_handle_t new_win ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1178 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1179 | struct thread_input *input = queue->input; |
| 1180 | struct message *msg; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1181 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1182 | LIST_FOR_EACH_ENTRY( msg, &input->msg_list, struct message, entry ) |
| 1183 | { |
| 1184 | if (msg->unique_id == hw_id) break; |
| 1185 | } |
| 1186 | if (&msg->entry == &input->msg_list) return; /* not found */ |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1187 | |
| 1188 | /* clear the queue bit for that message */ |
| 1189 | if (remove || new_win) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1190 | { |
| 1191 | struct message *other; |
| 1192 | int clr_bit; |
| 1193 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1194 | clr_bit = get_hardware_msg_bit( msg ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1195 | LIST_FOR_EACH_ENTRY( other, &input->msg_list, struct message, entry ) |
| 1196 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1197 | if (other != msg && get_hardware_msg_bit( other ) == clr_bit) |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1198 | { |
| 1199 | clr_bit = 0; |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1203 | if (clr_bit) clear_queue_bits( queue, clr_bit ); |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | if (new_win) /* set the new window */ |
| 1207 | { |
| 1208 | struct thread *owner = get_window_thread( new_win ); |
| 1209 | if (owner) |
| 1210 | { |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1211 | msg->win = new_win; |
| 1212 | if (owner->queue->input != input) |
Alexandre Julliard | 90b48e9 | 2005-05-13 14:00:19 +0000 | [diff] [blame] | 1213 | { |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1214 | list_remove( &msg->entry ); |
| 1215 | if (msg->msg == WM_MOUSEMOVE && merge_message( owner->queue->input, msg )) |
| 1216 | { |
| 1217 | free_message( msg ); |
| 1218 | release_object( owner ); |
| 1219 | return; |
| 1220 | } |
| 1221 | list_add_tail( &owner->queue->input->msg_list, &msg->entry ); |
Alexandre Julliard | 90b48e9 | 2005-05-13 14:00:19 +0000 | [diff] [blame] | 1222 | } |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1223 | set_queue_bits( owner->queue, get_hardware_msg_bit( msg )); |
| 1224 | remove = 0; |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1225 | release_object( owner ); |
| 1226 | } |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1227 | } |
Alexandre Julliard | 90b48e9 | 2005-05-13 14:00:19 +0000 | [diff] [blame] | 1228 | if (remove) |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1229 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1230 | update_input_key_state( input, msg ); |
| 1231 | list_remove( &msg->entry ); |
| 1232 | free_message( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1233 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /* find the window that should receive a given hardware message */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1237 | static user_handle_t find_hardware_message_window( struct thread_input *input, struct message *msg, |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1238 | struct hardware_msg_data *data, unsigned int *msg_code ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1239 | { |
| 1240 | user_handle_t win = 0; |
| 1241 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1242 | *msg_code = msg->msg; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1243 | if (is_keyboard_msg( msg )) |
| 1244 | { |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1245 | if (input && !(win = input->focus)) |
| 1246 | { |
| 1247 | win = input->active; |
| 1248 | if (*msg_code < WM_SYSKEYDOWN) *msg_code += WM_SYSKEYDOWN - WM_KEYDOWN; |
| 1249 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1250 | } |
| 1251 | else /* mouse message */ |
| 1252 | { |
| 1253 | if (!input || !(win = input->capture)) |
| 1254 | { |
Dmitry Timoshkov | 93a4e1e | 2004-10-27 21:55:00 +0000 | [diff] [blame] | 1255 | if (!(win = msg->win) || !is_window_visible( win )) |
Alexandre Julliard | 3f31a10 | 2005-08-16 19:58:12 +0000 | [diff] [blame] | 1256 | { |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1257 | if (input) win = window_from_point( input->desktop, data->x, data->y ); |
Alexandre Julliard | 3f31a10 | 2005-08-16 19:58:12 +0000 | [diff] [blame] | 1258 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | return win; |
| 1262 | } |
| 1263 | |
| 1264 | /* queue a hardware message into a given thread input */ |
Alexandre Julliard | cd28e2b | 2010-04-20 20:51:45 +0200 | [diff] [blame] | 1265 | static void queue_hardware_message( struct thread_input *input, struct message *msg, |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1266 | struct hardware_msg_data *data ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1267 | { |
| 1268 | user_handle_t win; |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1269 | struct thread *thread; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1270 | unsigned int msg_code; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1271 | |
Mike McCormack | abe70f7 | 2005-04-28 12:04:14 +0000 | [diff] [blame] | 1272 | last_input_time = get_tick_count(); |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1273 | win = find_hardware_message_window( input, msg, data, &msg_code ); |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1274 | if (!win || !(thread = get_window_thread(win))) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1275 | { |
Alexandre Julliard | 5d282dc | 2006-02-14 10:43:15 +0100 | [diff] [blame] | 1276 | if (input) update_input_key_state( input, msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1277 | free( msg ); |
| 1278 | return; |
| 1279 | } |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1280 | input = thread->queue->input; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1281 | |
| 1282 | if (msg->msg == WM_MOUSEMOVE && merge_message( input, msg )) free( msg ); |
| 1283 | else |
| 1284 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1285 | msg->unique_id = 0; /* will be set once we return it to the app */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1286 | list_add_tail( &input->msg_list, &msg->entry ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1287 | set_queue_bits( thread->queue, get_hardware_msg_bit(msg) ); |
| 1288 | } |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1289 | release_object( thread ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1292 | /* check message filter for a hardware message */ |
| 1293 | static int check_hw_message_filter( user_handle_t win, unsigned int msg_code, |
| 1294 | user_handle_t filter_win, unsigned int first, unsigned int last ) |
| 1295 | { |
| 1296 | if (msg_code >= WM_KEYFIRST && msg_code <= WM_KEYLAST) |
| 1297 | { |
| 1298 | /* we can only test the window for a keyboard message since the |
| 1299 | * dest window for a mouse message depends on hittest */ |
| 1300 | if (filter_win && win != filter_win && !is_child_window( filter_win, win )) |
| 1301 | return 0; |
| 1302 | /* the message code is final for a keyboard message, we can simply check it */ |
| 1303 | return check_msg_filter( msg_code, first, last ); |
| 1304 | } |
| 1305 | else /* mouse message */ |
| 1306 | { |
| 1307 | /* we need to check all possible values that the message can have in the end */ |
| 1308 | |
| 1309 | if (check_msg_filter( msg_code, first, last )) return 1; |
| 1310 | if (msg_code == WM_MOUSEWHEEL) return 0; /* no other possible value for this one */ |
| 1311 | |
| 1312 | /* all other messages can become non-client messages */ |
| 1313 | if (check_msg_filter( msg_code + (WM_NCMOUSEFIRST - WM_MOUSEFIRST), first, last )) return 1; |
| 1314 | |
| 1315 | /* clicks can become double-clicks or non-client double-clicks */ |
| 1316 | if (msg_code == WM_LBUTTONDOWN || msg_code == WM_MBUTTONDOWN || |
| 1317 | msg_code == WM_RBUTTONDOWN || msg_code == WM_XBUTTONDOWN) |
| 1318 | { |
| 1319 | if (check_msg_filter( msg_code + (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN), first, last )) return 1; |
| 1320 | if (check_msg_filter( msg_code + (WM_NCLBUTTONDBLCLK - WM_LBUTTONDOWN), first, last )) return 1; |
| 1321 | } |
| 1322 | return 0; |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1327 | /* find a hardware message for the given queue */ |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 1328 | static int get_hardware_message( struct thread *thread, unsigned int hw_id, user_handle_t filter_win, |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1329 | unsigned int first, unsigned int last, struct get_message_reply *reply ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1330 | { |
| 1331 | struct thread_input *input = thread->queue->input; |
| 1332 | struct thread *win_thread; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1333 | struct list *ptr; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1334 | user_handle_t win; |
| 1335 | int clear_bits, got_one = 0; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1336 | unsigned int msg_code; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1337 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1338 | ptr = list_head( &input->msg_list ); |
| 1339 | if (hw_id) |
| 1340 | { |
| 1341 | while (ptr) |
| 1342 | { |
| 1343 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
| 1344 | if (msg->unique_id == hw_id) break; |
| 1345 | ptr = list_next( &input->msg_list, ptr ); |
| 1346 | } |
| 1347 | if (!ptr) ptr = list_head( &input->msg_list ); |
| 1348 | else ptr = list_next( &input->msg_list, ptr ); /* start from the next one */ |
| 1349 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1350 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1351 | if (ptr == list_head( &input->msg_list )) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1352 | clear_bits = QS_KEY | QS_MOUSEMOVE | QS_MOUSEBUTTON; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1353 | else |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1354 | clear_bits = 0; /* don't clear bits if we don't go through the whole list */ |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1355 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1356 | while (ptr) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1357 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1358 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1359 | struct hardware_msg_data *data = msg->data; |
| 1360 | |
Alexandre Julliard | 55d449e | 2005-05-14 11:08:05 +0000 | [diff] [blame] | 1361 | ptr = list_next( &input->msg_list, ptr ); |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1362 | win = find_hardware_message_window( input, msg, data, &msg_code ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1363 | if (!win || !(win_thread = get_window_thread( win ))) |
| 1364 | { |
| 1365 | /* no window at all, remove it */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1366 | update_input_key_state( input, msg ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1367 | list_remove( &msg->entry ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1368 | free_message( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1369 | continue; |
| 1370 | } |
| 1371 | if (win_thread != thread) |
| 1372 | { |
Alexandre Julliard | 55d449e | 2005-05-14 11:08:05 +0000 | [diff] [blame] | 1373 | if (win_thread->queue->input == input) |
| 1374 | { |
| 1375 | /* wake the other thread */ |
| 1376 | set_queue_bits( win_thread->queue, get_hardware_msg_bit(msg) ); |
| 1377 | got_one = 1; |
| 1378 | } |
| 1379 | else |
| 1380 | { |
| 1381 | /* for another thread input, drop it */ |
| 1382 | update_input_key_state( input, msg ); |
| 1383 | list_remove( &msg->entry ); |
| 1384 | free_message( msg ); |
| 1385 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1386 | release_object( win_thread ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1387 | continue; |
| 1388 | } |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1389 | release_object( win_thread ); |
| 1390 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1391 | /* if we already got a message for another thread, or if it doesn't |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1392 | * match the filter we skip it */ |
| 1393 | if (got_one || !check_hw_message_filter( win, msg_code, filter_win, first, last )) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1394 | { |
| 1395 | clear_bits &= ~get_hardware_msg_bit( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1396 | continue; |
| 1397 | } |
| 1398 | /* now we can return it */ |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1399 | if (!msg->unique_id) msg->unique_id = get_unique_id(); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1400 | reply->type = MSG_HARDWARE; |
| 1401 | reply->win = win; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1402 | reply->msg = msg_code; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1403 | reply->wparam = msg->wparam; |
| 1404 | reply->lparam = msg->lparam; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1405 | reply->time = msg->time; |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1406 | |
| 1407 | data->hw_id = msg->unique_id; |
| 1408 | set_reply_data( msg->data, msg->data_size ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1409 | return 1; |
| 1410 | } |
| 1411 | /* nothing found, clear the hardware queue bits */ |
| 1412 | clear_queue_bits( thread->queue, clear_bits ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1413 | return 0; |
| 1414 | } |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 1415 | |
| 1416 | /* increment (or decrement if 'incr' is negative) the queue paint count */ |
| 1417 | void inc_queue_paint_count( struct thread *thread, int incr ) |
| 1418 | { |
| 1419 | struct msg_queue *queue = thread->queue; |
| 1420 | |
| 1421 | assert( queue ); |
| 1422 | |
| 1423 | if ((queue->paint_count += incr) < 0) queue->paint_count = 0; |
| 1424 | |
| 1425 | if (queue->paint_count) |
| 1426 | set_queue_bits( queue, QS_PAINT ); |
| 1427 | else |
| 1428 | clear_queue_bits( queue, QS_PAINT ); |
| 1429 | } |
| 1430 | |
| 1431 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1432 | /* remove all messages and timers belonging to a certain window */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1433 | void queue_cleanup_window( struct thread *thread, user_handle_t win ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1434 | { |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1435 | struct msg_queue *queue = thread->queue; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1436 | struct list *ptr; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1437 | int i; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1438 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1439 | if (!queue) return; |
| 1440 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1441 | /* remove timers */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1442 | |
| 1443 | ptr = list_head( &queue->pending_timers ); |
| 1444 | while (ptr) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1445 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1446 | struct list *next = list_next( &queue->pending_timers, ptr ); |
| 1447 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1448 | if (timer->win == win) free_timer( queue, timer ); |
| 1449 | ptr = next; |
| 1450 | } |
| 1451 | ptr = list_head( &queue->expired_timers ); |
| 1452 | while (ptr) |
| 1453 | { |
| 1454 | struct list *next = list_next( &queue->expired_timers, ptr ); |
| 1455 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1456 | if (timer->win == win) free_timer( queue, timer ); |
| 1457 | ptr = next; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1460 | /* remove messages */ |
| 1461 | for (i = 0; i < NB_MSG_KINDS; i++) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1462 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1463 | struct list *ptr, *next; |
| 1464 | |
| 1465 | LIST_FOR_EACH_SAFE( ptr, next, &queue->msg_list[i] ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1466 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1467 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1468 | if (msg->win == win) remove_queue_message( queue, msg, i ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1469 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1470 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1471 | |
| 1472 | thread_input_cleanup_window( queue, win ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1475 | /* post a message to a window; used by socket handling */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 1476 | void post_message( user_handle_t win, unsigned int message, lparam_t wparam, lparam_t lparam ) |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1477 | { |
| 1478 | struct message *msg; |
| 1479 | struct thread *thread = get_window_thread( win ); |
| 1480 | |
| 1481 | if (!thread) return; |
| 1482 | |
| 1483 | if (thread->queue && (msg = mem_alloc( sizeof(*msg) ))) |
| 1484 | { |
| 1485 | msg->type = MSG_POSTED; |
| 1486 | msg->win = get_user_full_handle( win ); |
| 1487 | msg->msg = message; |
| 1488 | msg->wparam = wparam; |
| 1489 | msg->lparam = lparam; |
| 1490 | msg->time = get_tick_count(); |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1491 | msg->result = NULL; |
| 1492 | msg->data = NULL; |
| 1493 | msg->data_size = 0; |
| 1494 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1495 | list_add_tail( &thread->queue->msg_list[POST_MESSAGE], &msg->entry ); |
Alexandre Julliard | 80b997a | 2005-11-14 15:17:09 +0000 | [diff] [blame] | 1496 | set_queue_bits( thread->queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1497 | } |
| 1498 | release_object( thread ); |
| 1499 | } |
| 1500 | |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1501 | /* post a win event */ |
| 1502 | void post_win_event( struct thread *thread, unsigned int event, |
| 1503 | user_handle_t win, unsigned int object_id, |
Alexandre Julliard | cc55fd3 | 2008-12-29 17:35:35 +0100 | [diff] [blame] | 1504 | unsigned int child_id, client_ptr_t hook_proc, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1505 | const WCHAR *module, data_size_t module_size, |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1506 | user_handle_t hook) |
| 1507 | { |
| 1508 | struct message *msg; |
| 1509 | |
| 1510 | if (thread->queue && (msg = mem_alloc( sizeof(*msg) ))) |
| 1511 | { |
Alexandre Julliard | 59dc456 | 2006-10-04 16:04:53 +0200 | [diff] [blame] | 1512 | struct winevent_msg_data *data; |
| 1513 | |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1514 | msg->type = MSG_WINEVENT; |
| 1515 | msg->win = get_user_full_handle( win ); |
| 1516 | msg->msg = event; |
| 1517 | msg->wparam = object_id; |
| 1518 | msg->lparam = child_id; |
| 1519 | msg->time = get_tick_count(); |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1520 | msg->result = NULL; |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1521 | |
Alexandre Julliard | 59dc456 | 2006-10-04 16:04:53 +0200 | [diff] [blame] | 1522 | if ((data = malloc( sizeof(*data) + module_size ))) |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1523 | { |
Alexandre Julliard | 59dc456 | 2006-10-04 16:04:53 +0200 | [diff] [blame] | 1524 | data->hook = hook; |
| 1525 | data->tid = get_thread_id( current ); |
| 1526 | data->hook_proc = hook_proc; |
| 1527 | memcpy( data + 1, module, module_size ); |
| 1528 | |
| 1529 | msg->data = data; |
| 1530 | msg->data_size = sizeof(*data) + module_size; |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1531 | |
| 1532 | if (debug_level > 1) |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 1533 | fprintf( stderr, "post_win_event: tid %04x event %04x win %08x object_id %d child_id %d\n", |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1534 | get_thread_id(thread), event, win, object_id, child_id ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1535 | list_add_tail( &thread->queue->msg_list[SEND_MESSAGE], &msg->entry ); |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1536 | set_queue_bits( thread->queue, QS_SENDMESSAGE ); |
| 1537 | } |
| 1538 | else |
| 1539 | free( msg ); |
| 1540 | } |
| 1541 | } |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1542 | |
Dmitry Timoshkov | e735e19 | 2007-12-28 10:59:13 +0800 | [diff] [blame] | 1543 | |
| 1544 | /* check if the thread owning the window is hung */ |
| 1545 | DECL_HANDLER(is_window_hung) |
| 1546 | { |
| 1547 | struct thread *thread; |
| 1548 | |
| 1549 | thread = get_window_thread( req->win ); |
| 1550 | if (thread) |
| 1551 | { |
| 1552 | reply->is_hung = is_queue_hung( thread->queue ); |
| 1553 | release_object( thread ); |
| 1554 | } |
| 1555 | else reply->is_hung = 0; |
| 1556 | } |
| 1557 | |
| 1558 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1559 | /* get the message queue of the current thread */ |
| 1560 | DECL_HANDLER(get_msg_queue) |
| 1561 | { |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1562 | struct msg_queue *queue = get_current_queue(); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1563 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1564 | reply->handle = 0; |
| 1565 | if (queue) reply->handle = alloc_handle( current->process, queue, SYNCHRONIZE, 0 ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1568 | |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 1569 | /* set the file descriptor associated to the current thread queue */ |
| 1570 | DECL_HANDLER(set_queue_fd) |
| 1571 | { |
| 1572 | struct msg_queue *queue = get_current_queue(); |
| 1573 | struct file *file; |
| 1574 | int unix_fd; |
| 1575 | |
| 1576 | if (queue->fd) /* fd can only be set once */ |
| 1577 | { |
| 1578 | set_error( STATUS_ACCESS_DENIED ); |
| 1579 | return; |
| 1580 | } |
| 1581 | if (!(file = get_file_obj( current->process, req->handle, SYNCHRONIZE ))) return; |
| 1582 | |
| 1583 | if ((unix_fd = get_file_unix_fd( file )) != -1) |
| 1584 | { |
| 1585 | if ((unix_fd = dup( unix_fd )) != -1) |
Alexandre Julliard | f85437c | 2007-04-10 22:25:07 +0200 | [diff] [blame] | 1586 | queue->fd = create_anonymous_fd( &msg_queue_fd_ops, unix_fd, &queue->obj, 0 ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 1587 | else |
| 1588 | file_set_error(); |
| 1589 | } |
| 1590 | release_object( file ); |
| 1591 | } |
| 1592 | |
| 1593 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1594 | /* set the current message queue wakeup mask */ |
| 1595 | DECL_HANDLER(set_queue_mask) |
| 1596 | { |
| 1597 | struct msg_queue *queue = get_current_queue(); |
| 1598 | |
| 1599 | if (queue) |
| 1600 | { |
| 1601 | queue->wake_mask = req->wake_mask; |
| 1602 | queue->changed_mask = req->changed_mask; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1603 | reply->wake_bits = queue->wake_bits; |
| 1604 | reply->changed_bits = queue->changed_bits; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1605 | if (is_signaled( queue )) |
| 1606 | { |
| 1607 | /* if skip wait is set, do what would have been done in the subsequent wait */ |
| 1608 | if (req->skip_wait) msg_queue_satisfied( &queue->obj, current ); |
| 1609 | else wake_up( &queue->obj, 0 ); |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | /* get the current message queue status */ |
| 1616 | DECL_HANDLER(get_queue_status) |
| 1617 | { |
| 1618 | struct msg_queue *queue = current->queue; |
| 1619 | if (queue) |
| 1620 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1621 | reply->wake_bits = queue->wake_bits; |
| 1622 | reply->changed_bits = queue->changed_bits; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1623 | if (req->clear) queue->changed_bits = 0; |
| 1624 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1625 | else reply->wake_bits = reply->changed_bits = 0; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | /* send a message to a thread queue */ |
| 1630 | DECL_HANDLER(send_message) |
| 1631 | { |
| 1632 | struct message *msg; |
| 1633 | struct msg_queue *send_queue = get_current_queue(); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1634 | struct msg_queue *recv_queue = NULL; |
| 1635 | struct thread *thread = NULL; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1636 | |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1637 | if (!(thread = get_thread_from_id( req->id ))) return; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1638 | |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1639 | if (!(recv_queue = thread->queue)) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1640 | { |
| 1641 | set_error( STATUS_INVALID_PARAMETER ); |
| 1642 | release_object( thread ); |
| 1643 | return; |
| 1644 | } |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1645 | if ((req->flags & SEND_MSG_ABORT_IF_HUNG) && is_queue_hung(recv_queue)) |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 1646 | { |
| 1647 | set_error( STATUS_TIMEOUT ); |
| 1648 | release_object( thread ); |
| 1649 | return; |
| 1650 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1651 | |
| 1652 | if ((msg = mem_alloc( sizeof(*msg) ))) |
| 1653 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1654 | msg->type = req->type; |
Alexandre Julliard | bc878ef | 2001-09-12 17:09:24 +0000 | [diff] [blame] | 1655 | msg->win = get_user_full_handle( req->win ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1656 | msg->msg = req->msg; |
| 1657 | msg->wparam = req->wparam; |
| 1658 | msg->lparam = req->lparam; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1659 | msg->time = get_tick_count(); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1660 | msg->result = NULL; |
| 1661 | msg->data = NULL; |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 1662 | msg->data_size = get_req_data_size(); |
| 1663 | |
| 1664 | if (msg->data_size && !(msg->data = memdup( get_req_data(), msg->data_size ))) |
| 1665 | { |
| 1666 | free( msg ); |
| 1667 | release_object( thread ); |
| 1668 | return; |
| 1669 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1670 | |
| 1671 | switch(msg->type) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1672 | { |
Eric Pouech | 0faceb0 | 2002-01-18 19:22:55 +0000 | [diff] [blame] | 1673 | case MSG_OTHER_PROCESS: |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1674 | case MSG_ASCII: |
| 1675 | case MSG_UNICODE: |
| 1676 | case MSG_CALLBACK: |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 1677 | if (!(msg->result = alloc_message_result( send_queue, recv_queue, msg, req->timeout ))) |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 1678 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 1679 | free_message( msg ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1680 | break; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 1681 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1682 | /* fall through */ |
| 1683 | case MSG_NOTIFY: |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1684 | list_add_tail( &recv_queue->msg_list[SEND_MESSAGE], &msg->entry ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1685 | set_queue_bits( recv_queue, QS_SENDMESSAGE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1686 | break; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1687 | case MSG_POSTED: |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1688 | list_add_tail( &recv_queue->msg_list[POST_MESSAGE], &msg->entry ); |
Alexandre Julliard | 80b997a | 2005-11-14 15:17:09 +0000 | [diff] [blame] | 1689 | set_queue_bits( recv_queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1690 | break; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1691 | case MSG_HARDWARE: /* should use send_hardware_message instead */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 1692 | case MSG_CALLBACK_RESULT: /* cannot send this one */ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1693 | default: |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1694 | set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1695 | free( msg ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1696 | break; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1697 | } |
| 1698 | } |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1699 | release_object( thread ); |
| 1700 | } |
| 1701 | |
| 1702 | /* send a hardware message to a thread queue */ |
| 1703 | DECL_HANDLER(send_hardware_message) |
| 1704 | { |
| 1705 | struct message *msg; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1706 | struct thread *thread = NULL; |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1707 | struct hardware_msg_data *data; |
Alexandre Julliard | cd28e2b | 2010-04-20 20:51:45 +0200 | [diff] [blame] | 1708 | struct thread_input *input = foreground_input; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1709 | |
| 1710 | if (req->id) |
| 1711 | { |
| 1712 | if (!(thread = get_thread_from_id( req->id ))) return; |
Alexandre Julliard | cd28e2b | 2010-04-20 20:51:45 +0200 | [diff] [blame] | 1713 | if (!thread->queue) |
| 1714 | { |
| 1715 | set_error( STATUS_INVALID_PARAMETER ); |
| 1716 | release_object( thread ); |
| 1717 | return; |
| 1718 | } |
| 1719 | input = thread->queue->input; |
Alexandre Julliard | 5ee89aa | 2010-05-12 13:48:00 +0200 | [diff] [blame] | 1720 | reply->cursor = input->cursor; |
| 1721 | reply->count = input->cursor_count; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1722 | } |
| 1723 | |
Alexandre Julliard | 5ee89aa | 2010-05-12 13:48:00 +0200 | [diff] [blame] | 1724 | if (!req->msg || !(data = mem_alloc( sizeof(*data) ))) |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1725 | { |
Marcus Meissner | 3b86f46 | 2009-01-28 23:58:38 +0100 | [diff] [blame] | 1726 | if (thread) release_object( thread ); |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1727 | return; |
| 1728 | } |
Alexandre Julliard | 8c8c665 | 2008-12-31 15:14:29 +0100 | [diff] [blame] | 1729 | memset( data, 0, sizeof(*data) ); |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1730 | data->x = req->x; |
| 1731 | data->y = req->y; |
| 1732 | data->info = req->info; |
| 1733 | |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1734 | if ((msg = mem_alloc( sizeof(*msg) ))) |
| 1735 | { |
| 1736 | msg->type = MSG_HARDWARE; |
| 1737 | msg->win = get_user_full_handle( req->win ); |
| 1738 | msg->msg = req->msg; |
| 1739 | msg->wparam = req->wparam; |
| 1740 | msg->lparam = req->lparam; |
| 1741 | msg->time = req->time; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1742 | msg->result = NULL; |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1743 | msg->data = data; |
| 1744 | msg->data_size = sizeof(*data); |
Alexandre Julliard | cd28e2b | 2010-04-20 20:51:45 +0200 | [diff] [blame] | 1745 | queue_hardware_message( input, msg, data ); |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 1746 | } |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1747 | else free( data ); |
| 1748 | |
Alexandre Julliard | 5ee89aa | 2010-05-12 13:48:00 +0200 | [diff] [blame] | 1749 | if (thread) release_object( thread ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 1752 | /* post a quit message to the current queue */ |
| 1753 | DECL_HANDLER(post_quit_message) |
| 1754 | { |
| 1755 | struct msg_queue *queue = get_current_queue(); |
| 1756 | |
| 1757 | if (!queue) |
| 1758 | return; |
| 1759 | |
| 1760 | queue->quit_message = 1; |
| 1761 | queue->exit_code = req->exit_code; |
| 1762 | set_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
| 1763 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1764 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1765 | /* get a message from the current queue */ |
| 1766 | DECL_HANDLER(get_message) |
| 1767 | { |
| 1768 | struct timer *timer; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1769 | struct list *ptr; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1770 | struct msg_queue *queue = get_current_queue(); |
Alexandre Julliard | bc878ef | 2001-09-12 17:09:24 +0000 | [diff] [blame] | 1771 | user_handle_t get_win = get_user_full_handle( req->get_win ); |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1772 | unsigned int filter = req->flags >> 16; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1773 | |
Alexandre Julliard | 6334235 | 2005-05-11 13:03:15 +0000 | [diff] [blame] | 1774 | reply->active_hooks = get_active_hooks(); |
| 1775 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1776 | if (!queue) return; |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 1777 | queue->last_get_msg = current_time; |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1778 | if (!filter) filter = QS_ALLINPUT; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1779 | |
| 1780 | /* first check for sent messages */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1781 | if ((ptr = list_head( &queue->msg_list[SEND_MESSAGE] ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1782 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1783 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1784 | receive_message( queue, msg, reply ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1785 | return; |
| 1786 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1787 | |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 1788 | /* clear changed bits so we can wait on them if we don't find a message */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1789 | if (filter & QS_POSTMESSAGE) |
| 1790 | { |
| 1791 | queue->changed_bits &= ~(QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER); |
| 1792 | if (req->get_first == 0 && req->get_last == ~0U) queue->changed_bits &= ~QS_ALLPOSTMESSAGE; |
| 1793 | } |
| 1794 | if (filter & QS_INPUT) queue->changed_bits &= ~QS_INPUT; |
| 1795 | if (filter & QS_PAINT) queue->changed_bits &= ~QS_PAINT; |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 1796 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1797 | /* then check for posted messages */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1798 | if ((filter & QS_POSTMESSAGE) && |
| 1799 | get_posted_message( queue, get_win, req->get_first, req->get_last, req->flags, reply )) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1800 | return; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1801 | |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 1802 | /* only check for quit messages if not posted messages pending. |
| 1803 | * note: the quit message isn't filtered */ |
| 1804 | if (get_quit_message( queue, req->flags, reply )) |
| 1805 | return; |
| 1806 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1807 | /* then check for any raw hardware message */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1808 | if ((filter & QS_INPUT) && |
| 1809 | filter_contains_hw_range( req->get_first, req->get_last ) && |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1810 | get_hardware_message( current, req->hw_id, get_win, req->get_first, req->get_last, reply )) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1811 | return; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1812 | |
| 1813 | /* now check for WM_PAINT */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1814 | if ((filter & QS_PAINT) && |
| 1815 | queue->paint_count && |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1816 | check_msg_filter( WM_PAINT, req->get_first, req->get_last ) && |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1817 | (reply->win = find_window_to_repaint( get_win, current ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1818 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1819 | reply->type = MSG_POSTED; |
| 1820 | reply->msg = WM_PAINT; |
| 1821 | reply->wparam = 0; |
| 1822 | reply->lparam = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1823 | reply->time = get_tick_count(); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1824 | return; |
| 1825 | } |
| 1826 | |
| 1827 | /* now check for timer */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 1828 | if ((filter & QS_TIMER) && |
| 1829 | (timer = find_expired_timer( queue, get_win, req->get_first, |
| 1830 | req->get_last, (req->flags & PM_REMOVE) ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1831 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1832 | reply->type = MSG_POSTED; |
| 1833 | reply->win = timer->win; |
| 1834 | reply->msg = timer->msg; |
| 1835 | reply->wparam = timer->id; |
| 1836 | reply->lparam = timer->lparam; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1837 | reply->time = get_tick_count(); |
Alexandre Julliard | 7265e89 | 2009-12-16 18:18:07 +0100 | [diff] [blame] | 1838 | if (!(req->flags & PM_NOYIELD) && current->process->idle_event) |
| 1839 | set_event( current->process->idle_event ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1840 | return; |
| 1841 | } |
| 1842 | |
Alexandre Julliard | b0760fc | 2010-03-03 13:19:13 +0100 | [diff] [blame] | 1843 | if (get_win == -1 && current->process->idle_event) set_event( current->process->idle_event ); |
Alexandre Julliard | 2896540 | 2007-08-29 18:13:13 +0200 | [diff] [blame] | 1844 | queue->wake_mask = req->wake_mask; |
| 1845 | queue->changed_mask = req->changed_mask; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1846 | set_error( STATUS_PENDING ); /* FIXME */ |
| 1847 | } |
| 1848 | |
| 1849 | |
| 1850 | /* reply to a sent message */ |
| 1851 | DECL_HANDLER(reply_message) |
| 1852 | { |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1853 | if (!current->queue) set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | b1095da | 2003-03-19 00:12:17 +0000 | [diff] [blame] | 1854 | else if (current->queue->recv_result) |
| 1855 | reply_message( current->queue, req->result, 0, req->remove, |
| 1856 | get_req_data(), get_req_data_size() ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1860 | /* accept the current hardware message */ |
| 1861 | DECL_HANDLER(accept_hardware_message) |
| 1862 | { |
| 1863 | if (current->queue) |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1864 | release_hardware_message( current->queue, req->hw_id, req->remove, req->new_win ); |
| 1865 | else |
| 1866 | set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1870 | /* retrieve the reply for the last message sent */ |
| 1871 | DECL_HANDLER(get_message_reply) |
| 1872 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 1873 | struct message_result *result; |
| 1874 | struct list *entry; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1875 | struct msg_queue *queue = current->queue; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1876 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1877 | if (queue) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1878 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1879 | set_error( STATUS_PENDING ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1880 | reply->result = 0; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1881 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 1882 | if (!(entry = list_head( &queue->send_result ))) return; /* no reply ready */ |
| 1883 | |
| 1884 | result = LIST_ENTRY( entry, struct message_result, sender_entry ); |
| 1885 | if (result->replied || req->cancel) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1886 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1887 | if (result->replied) |
| 1888 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1889 | reply->result = result->result; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1890 | set_error( result->error ); |
| 1891 | if (result->data) |
| 1892 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1893 | data_size_t data_len = min( result->data_size, get_reply_max_size() ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1894 | set_reply_data_ptr( result->data, data_len ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1895 | result->data = NULL; |
| 1896 | result->data_size = 0; |
| 1897 | } |
| 1898 | } |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 1899 | remove_result_from_sender( result ); |
| 1900 | |
| 1901 | entry = list_head( &queue->send_result ); |
| 1902 | if (!entry) clear_queue_bits( queue, QS_SMRESULT ); |
| 1903 | else |
| 1904 | { |
| 1905 | result = LIST_ENTRY( entry, struct message_result, sender_entry ); |
| 1906 | if (!result->replied) clear_queue_bits( queue, QS_SMRESULT ); |
| 1907 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1908 | } |
| 1909 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1910 | else set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1914 | /* set a window timer */ |
| 1915 | DECL_HANDLER(set_win_timer) |
| 1916 | { |
| 1917 | struct timer *timer; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1918 | struct msg_queue *queue; |
| 1919 | struct thread *thread = NULL; |
| 1920 | user_handle_t win = 0; |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 1921 | lparam_t id = req->id; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1922 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1923 | if (req->win) |
| 1924 | { |
| 1925 | if (!(win = get_user_full_handle( req->win )) || !(thread = get_window_thread( win ))) |
| 1926 | { |
| 1927 | set_error( STATUS_INVALID_HANDLE ); |
| 1928 | return; |
| 1929 | } |
| 1930 | if (thread->process != current->process) |
| 1931 | { |
| 1932 | release_object( thread ); |
| 1933 | set_error( STATUS_ACCESS_DENIED ); |
| 1934 | return; |
| 1935 | } |
| 1936 | queue = thread->queue; |
| 1937 | /* remove it if it existed already */ |
| 1938 | if ((timer = find_timer( queue, win, req->msg, id ))) free_timer( queue, timer ); |
| 1939 | } |
| 1940 | else |
| 1941 | { |
| 1942 | queue = get_current_queue(); |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 1943 | /* look for a timer with this id */ |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 1944 | if (id && (timer = find_timer( queue, 0, req->msg, id ))) |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1945 | { |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 1946 | /* free and reuse id */ |
| 1947 | free_timer( queue, timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1948 | } |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 1949 | else |
| 1950 | { |
| 1951 | /* find a free id for it */ |
| 1952 | do |
| 1953 | { |
| 1954 | id = queue->next_timer_id; |
Dmitry Timoshkov | b4227d7 | 2007-11-13 20:41:01 +0800 | [diff] [blame] | 1955 | if (--queue->next_timer_id <= 0x100) queue->next_timer_id = 0x7fff; |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 1956 | } |
| 1957 | while (find_timer( queue, 0, req->msg, id )); |
| 1958 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1959 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1960 | |
| 1961 | if ((timer = set_timer( queue, req->rate ))) |
| 1962 | { |
Alexandre Julliard | bc878ef | 2001-09-12 17:09:24 +0000 | [diff] [blame] | 1963 | timer->win = win; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1964 | timer->msg = req->msg; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1965 | timer->id = id; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1966 | timer->lparam = req->lparam; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1967 | reply->id = id; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1968 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1969 | if (thread) release_object( thread ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | /* kill a window timer */ |
| 1973 | DECL_HANDLER(kill_win_timer) |
| 1974 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1975 | struct timer *timer; |
| 1976 | struct thread *thread; |
| 1977 | user_handle_t win = 0; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1978 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1979 | if (req->win) |
| 1980 | { |
| 1981 | if (!(win = get_user_full_handle( req->win )) || !(thread = get_window_thread( win ))) |
| 1982 | { |
| 1983 | set_error( STATUS_INVALID_HANDLE ); |
| 1984 | return; |
| 1985 | } |
| 1986 | if (thread->process != current->process) |
| 1987 | { |
| 1988 | release_object( thread ); |
| 1989 | set_error( STATUS_ACCESS_DENIED ); |
| 1990 | return; |
| 1991 | } |
| 1992 | } |
| 1993 | else thread = (struct thread *)grab_object( current ); |
| 1994 | |
| 1995 | if (thread->queue && (timer = find_timer( thread->queue, win, req->msg, req->id ))) |
| 1996 | free_timer( thread->queue, timer ); |
| 1997 | else |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1998 | set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1999 | |
| 2000 | release_object( thread ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2001 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2002 | |
| 2003 | |
| 2004 | /* attach (or detach) thread inputs */ |
| 2005 | DECL_HANDLER(attach_thread_input) |
| 2006 | { |
| 2007 | struct thread *thread_from = get_thread_from_id( req->tid_from ); |
| 2008 | struct thread *thread_to = get_thread_from_id( req->tid_to ); |
| 2009 | |
| 2010 | if (!thread_from || !thread_to) |
| 2011 | { |
| 2012 | if (thread_from) release_object( thread_from ); |
| 2013 | if (thread_to) release_object( thread_to ); |
| 2014 | return; |
| 2015 | } |
| 2016 | if (thread_from != thread_to) |
| 2017 | { |
| 2018 | if (req->attach) attach_thread_input( thread_from, thread_to ); |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 2019 | else |
| 2020 | { |
| 2021 | if (thread_from->queue && thread_to->queue && |
| 2022 | thread_from->queue->input == thread_to->queue->input) |
| 2023 | detach_thread_input( thread_from ); |
| 2024 | else |
| 2025 | set_error( STATUS_ACCESS_DENIED ); |
| 2026 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2027 | } |
| 2028 | else set_error( STATUS_ACCESS_DENIED ); |
| 2029 | release_object( thread_from ); |
| 2030 | release_object( thread_to ); |
| 2031 | } |
| 2032 | |
| 2033 | |
| 2034 | /* get thread input data */ |
| 2035 | DECL_HANDLER(get_thread_input) |
| 2036 | { |
| 2037 | struct thread *thread = NULL; |
| 2038 | struct thread_input *input; |
| 2039 | |
| 2040 | if (req->tid) |
| 2041 | { |
| 2042 | if (!(thread = get_thread_from_id( req->tid ))) return; |
| 2043 | input = thread->queue ? thread->queue->input : NULL; |
| 2044 | } |
| 2045 | else input = foreground_input; /* get the foreground thread info */ |
| 2046 | |
| 2047 | if (input) |
| 2048 | { |
| 2049 | reply->focus = input->focus; |
| 2050 | reply->capture = input->capture; |
| 2051 | reply->active = input->active; |
| 2052 | reply->menu_owner = input->menu_owner; |
| 2053 | reply->move_size = input->move_size; |
| 2054 | reply->caret = input->caret; |
Alexandre Julliard | c545982 | 2010-05-11 11:21:03 +0200 | [diff] [blame] | 2055 | reply->cursor = input->cursor; |
| 2056 | reply->show_count = input->cursor_count; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 2057 | reply->rect = input->caret_rect; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2058 | } |
Alexandre Julliard | c545982 | 2010-05-11 11:21:03 +0200 | [diff] [blame] | 2059 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2060 | /* foreground window is active window of foreground thread */ |
| 2061 | reply->foreground = foreground_input ? foreground_input->active : 0; |
| 2062 | if (thread) release_object( thread ); |
| 2063 | } |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2064 | |
| 2065 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2066 | /* retrieve queue keyboard state for a given thread */ |
| 2067 | DECL_HANDLER(get_key_state) |
| 2068 | { |
| 2069 | struct thread *thread; |
| 2070 | struct thread_input *input; |
| 2071 | |
| 2072 | if (!(thread = get_thread_from_id( req->tid ))) return; |
| 2073 | input = thread->queue ? thread->queue->input : NULL; |
| 2074 | if (input) |
| 2075 | { |
| 2076 | if (req->key >= 0) reply->state = input->keystate[req->key & 0xff]; |
| 2077 | set_reply_data( input->keystate, min( get_reply_max_size(), sizeof(input->keystate) )); |
| 2078 | } |
| 2079 | release_object( thread ); |
| 2080 | } |
| 2081 | |
| 2082 | |
| 2083 | /* set queue keyboard state for a given thread */ |
| 2084 | DECL_HANDLER(set_key_state) |
| 2085 | { |
| 2086 | struct thread *thread = NULL; |
| 2087 | struct thread_input *input; |
| 2088 | |
| 2089 | if (!(thread = get_thread_from_id( req->tid ))) return; |
| 2090 | input = thread->queue ? thread->queue->input : NULL; |
| 2091 | if (input) |
| 2092 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 2093 | data_size_t size = min( sizeof(input->keystate), get_req_data_size() ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2094 | if (size) memcpy( input->keystate, get_req_data(), size ); |
| 2095 | } |
| 2096 | release_object( thread ); |
| 2097 | } |
| 2098 | |
| 2099 | |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2100 | /* set the system foreground window */ |
| 2101 | DECL_HANDLER(set_foreground_window) |
| 2102 | { |
Dmitry Timoshkov | 19e7fab | 2006-07-07 23:01:51 +0900 | [diff] [blame] | 2103 | struct thread *thread; |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2104 | struct msg_queue *queue = get_current_queue(); |
| 2105 | |
| 2106 | reply->previous = foreground_input ? foreground_input->active : 0; |
| 2107 | reply->send_msg_old = (reply->previous && foreground_input != queue->input); |
| 2108 | reply->send_msg_new = FALSE; |
| 2109 | |
Dmitry Timoshkov | 19e7fab | 2006-07-07 23:01:51 +0900 | [diff] [blame] | 2110 | if (is_top_level_window( req->handle ) && |
| 2111 | ((thread = get_window_thread( req->handle )))) |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2112 | { |
Dmitry Timoshkov | 19e7fab | 2006-07-07 23:01:51 +0900 | [diff] [blame] | 2113 | foreground_input = thread->queue->input; |
| 2114 | reply->send_msg_new = (foreground_input != queue->input); |
| 2115 | release_object( thread ); |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2116 | } |
Dmitry Timoshkov | 19e7fab | 2006-07-07 23:01:51 +0900 | [diff] [blame] | 2117 | else set_win32_error( ERROR_INVALID_WINDOW_HANDLE ); |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | /* set the current thread focus window */ |
| 2122 | DECL_HANDLER(set_focus_window) |
| 2123 | { |
| 2124 | struct msg_queue *queue = get_current_queue(); |
| 2125 | |
| 2126 | reply->previous = 0; |
| 2127 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2128 | { |
| 2129 | reply->previous = queue->input->focus; |
| 2130 | queue->input->focus = get_user_full_handle( req->handle ); |
| 2131 | } |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | /* set the current thread active window */ |
| 2136 | DECL_HANDLER(set_active_window) |
| 2137 | { |
| 2138 | struct msg_queue *queue = get_current_queue(); |
| 2139 | |
| 2140 | reply->previous = 0; |
| 2141 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2142 | { |
| 2143 | if (!req->handle || make_window_active( req->handle )) |
| 2144 | { |
| 2145 | reply->previous = queue->input->active; |
| 2146 | queue->input->active = get_user_full_handle( req->handle ); |
| 2147 | } |
| 2148 | else set_error( STATUS_INVALID_HANDLE ); |
| 2149 | } |
| 2150 | } |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 2151 | |
| 2152 | |
| 2153 | /* set the current thread capture window */ |
| 2154 | DECL_HANDLER(set_capture_window) |
| 2155 | { |
| 2156 | struct msg_queue *queue = get_current_queue(); |
| 2157 | |
| 2158 | reply->previous = reply->full_handle = 0; |
| 2159 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2160 | { |
| 2161 | struct thread_input *input = queue->input; |
| 2162 | |
Peter Dons Tychsen | d21c131 | 2010-01-11 21:47:43 +0100 | [diff] [blame] | 2163 | /* if in menu mode, reject all requests to change focus, except if the menu bit is set */ |
| 2164 | if (input->menu_owner && !(req->flags & CAPTURE_MENU)) |
| 2165 | { |
| 2166 | set_error(STATUS_ACCESS_DENIED); |
| 2167 | return; |
| 2168 | } |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 2169 | reply->previous = input->capture; |
| 2170 | input->capture = get_user_full_handle( req->handle ); |
| 2171 | input->menu_owner = (req->flags & CAPTURE_MENU) ? input->capture : 0; |
| 2172 | input->move_size = (req->flags & CAPTURE_MOVESIZE) ? input->capture : 0; |
| 2173 | reply->full_handle = input->capture; |
| 2174 | } |
| 2175 | } |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 2176 | |
| 2177 | |
| 2178 | /* Set the current thread caret window */ |
| 2179 | DECL_HANDLER(set_caret_window) |
| 2180 | { |
| 2181 | struct msg_queue *queue = get_current_queue(); |
| 2182 | |
| 2183 | reply->previous = 0; |
| 2184 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2185 | { |
| 2186 | struct thread_input *input = queue->input; |
| 2187 | |
| 2188 | reply->previous = input->caret; |
| 2189 | reply->old_rect = input->caret_rect; |
| 2190 | reply->old_hide = input->caret_hide; |
| 2191 | reply->old_state = input->caret_state; |
| 2192 | |
| 2193 | set_caret_window( input, get_user_full_handle(req->handle) ); |
Krzysztof Foltman | b850172 | 2005-02-18 20:02:55 +0000 | [diff] [blame] | 2194 | input->caret_rect.right = input->caret_rect.left + req->width; |
| 2195 | input->caret_rect.bottom = input->caret_rect.top + req->height; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | |
| 2200 | /* Set the current thread caret information */ |
| 2201 | DECL_HANDLER(set_caret_info) |
| 2202 | { |
| 2203 | struct msg_queue *queue = get_current_queue(); |
| 2204 | struct thread_input *input; |
| 2205 | |
| 2206 | if (!queue) return; |
| 2207 | input = queue->input; |
| 2208 | reply->full_handle = input->caret; |
| 2209 | reply->old_rect = input->caret_rect; |
| 2210 | reply->old_hide = input->caret_hide; |
| 2211 | reply->old_state = input->caret_state; |
| 2212 | |
| 2213 | if (req->handle && get_user_full_handle(req->handle) != input->caret) |
| 2214 | { |
| 2215 | set_error( STATUS_ACCESS_DENIED ); |
| 2216 | return; |
| 2217 | } |
| 2218 | if (req->flags & SET_CARET_POS) |
| 2219 | { |
| 2220 | input->caret_rect.right += req->x - input->caret_rect.left; |
| 2221 | input->caret_rect.bottom += req->y - input->caret_rect.top; |
| 2222 | input->caret_rect.left = req->x; |
| 2223 | input->caret_rect.top = req->y; |
| 2224 | } |
| 2225 | if (req->flags & SET_CARET_HIDE) |
| 2226 | { |
| 2227 | input->caret_hide += req->hide; |
| 2228 | if (input->caret_hide < 0) input->caret_hide = 0; |
| 2229 | } |
| 2230 | if (req->flags & SET_CARET_STATE) |
| 2231 | { |
| 2232 | if (req->state == -1) input->caret_state = !input->caret_state; |
| 2233 | else input->caret_state = !!req->state; |
| 2234 | } |
| 2235 | } |
Mike McCormack | abe70f7 | 2005-04-28 12:04:14 +0000 | [diff] [blame] | 2236 | |
| 2237 | |
| 2238 | /* get the time of the last input event */ |
| 2239 | DECL_HANDLER(get_last_input_time) |
| 2240 | { |
| 2241 | reply->time = last_input_time; |
| 2242 | } |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 2243 | |
| 2244 | /* set/get the current cursor */ |
| 2245 | DECL_HANDLER(set_cursor) |
| 2246 | { |
| 2247 | struct msg_queue *queue = get_current_queue(); |
| 2248 | struct thread_input *input; |
| 2249 | |
| 2250 | if (!queue) return; |
| 2251 | input = queue->input; |
| 2252 | |
| 2253 | reply->prev_handle = input->cursor; |
| 2254 | reply->prev_count = input->cursor_count; |
| 2255 | |
| 2256 | if (req->flags & SET_CURSOR_HANDLE) |
| 2257 | { |
| 2258 | if (req->handle && !get_user_object( req->handle, USER_CLIENT )) |
| 2259 | { |
| 2260 | set_win32_error( ERROR_INVALID_CURSOR_HANDLE ); |
| 2261 | return; |
| 2262 | } |
| 2263 | input->cursor = req->handle; |
| 2264 | } |
| 2265 | |
| 2266 | if (req->flags & SET_CURSOR_COUNT) |
| 2267 | { |
| 2268 | queue->cursor_count += req->show_count; |
| 2269 | input->cursor_count += req->show_count; |
| 2270 | } |
| 2271 | } |