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