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 | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 61 | struct message *hardware_msg; /* hardware message if low-level hook result */ |
| 62 | struct desktop *desktop; /* desktop for hardware message */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 63 | struct message *callback_msg; /* message to queue for callback */ |
| 64 | void *data; /* message reply data */ |
| 65 | unsigned int data_size; /* size of message reply data */ |
| 66 | struct timeout_user *timeout; /* result timeout */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct message |
| 70 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 71 | struct list entry; /* entry in message list */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 72 | enum message_type type; /* message type */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 73 | user_handle_t win; /* window handle */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 74 | unsigned int msg; /* message code */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 75 | lparam_t wparam; /* parameters */ |
| 76 | lparam_t lparam; /* parameters */ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 77 | unsigned int time; /* message time */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 78 | void *data; /* message data for sent messages */ |
| 79 | unsigned int data_size; /* size of message data */ |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 80 | unsigned int unique_id; /* unique id for nested hw message waits */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 81 | struct message_result *result; /* result in sender queue */ |
| 82 | }; |
| 83 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 84 | struct timer |
| 85 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 86 | struct list entry; /* entry in timer list */ |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 87 | timeout_t when; /* next expiration */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 88 | unsigned int rate; /* timer rate in ms */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 89 | user_handle_t win; /* window handle */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 90 | unsigned int msg; /* message to post */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 91 | lparam_t id; /* timer id */ |
| 92 | lparam_t lparam; /* lparam for message */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 95 | struct thread_input |
| 96 | { |
| 97 | struct object obj; /* object header */ |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 98 | struct desktop *desktop; /* desktop that this thread input belongs to */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 99 | user_handle_t focus; /* focus window */ |
| 100 | user_handle_t capture; /* capture window */ |
| 101 | user_handle_t active; /* active window */ |
| 102 | user_handle_t menu_owner; /* current menu owner window */ |
| 103 | user_handle_t move_size; /* current moving/resizing window */ |
| 104 | user_handle_t caret; /* caret window */ |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 105 | rectangle_t caret_rect; /* caret rectangle */ |
| 106 | int caret_hide; /* caret hide count */ |
| 107 | int caret_state; /* caret on/off state */ |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 108 | user_handle_t cursor; /* current cursor */ |
| 109 | int cursor_count; /* cursor show count */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 110 | struct list msg_list; /* list of hardware messages */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 111 | unsigned char keystate[256]; /* state of each key */ |
| 112 | }; |
| 113 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 114 | struct msg_queue |
| 115 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 116 | struct object obj; /* object header */ |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 117 | struct fd *fd; /* optional file descriptor to poll */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 118 | unsigned int wake_bits; /* wakeup bits */ |
| 119 | unsigned int wake_mask; /* wakeup mask */ |
| 120 | unsigned int changed_bits; /* changed wakeup bits */ |
| 121 | unsigned int changed_mask; /* changed wakeup mask */ |
| 122 | int paint_count; /* pending paint messages count */ |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 123 | int hotkey_count; /* pending hotkey messages count */ |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 124 | int quit_message; /* is there a pending quit message? */ |
| 125 | int exit_code; /* exit code of pending quit message */ |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 126 | int cursor_count; /* per-queue cursor show count */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 127 | struct list msg_list[NB_MSG_KINDS]; /* lists of messages */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 128 | struct list send_result; /* stack of sent messages waiting for result */ |
| 129 | struct list callback_result; /* list of callback messages waiting for result */ |
| 130 | struct message_result *recv_result; /* stack of received messages waiting for result */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 131 | struct list pending_timers; /* list of pending timers */ |
| 132 | struct list expired_timers; /* list of expired timers */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 133 | 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] | 134 | struct timeout_user *timeout; /* timeout for next timer to expire */ |
| 135 | struct thread_input *input; /* thread input descriptor */ |
| 136 | struct hook_table *hooks; /* hook table */ |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 137 | timeout_t last_get_msg; /* time of last get message call */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
Vincent Povirk | 4c83138 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 140 | struct hotkey |
| 141 | { |
| 142 | struct list entry; /* entry in desktop hotkey list */ |
| 143 | struct msg_queue *queue; /* queue owning this hotkey */ |
| 144 | user_handle_t win; /* window handle */ |
| 145 | int id; /* hotkey id */ |
| 146 | unsigned int vkey; /* virtual key code */ |
| 147 | unsigned int flags; /* key modifiers */ |
| 148 | }; |
| 149 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 150 | static void msg_queue_dump( struct object *obj, int verbose ); |
| 151 | static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry ); |
| 152 | static void msg_queue_remove_queue( struct object *obj, struct wait_queue_entry *entry ); |
| 153 | static int msg_queue_signaled( struct object *obj, struct thread *thread ); |
| 154 | static int msg_queue_satisfied( struct object *obj, struct thread *thread ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 155 | static void msg_queue_destroy( struct object *obj ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 156 | static void msg_queue_poll_event( struct fd *fd, int event ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 157 | static void thread_input_dump( struct object *obj, int verbose ); |
| 158 | static void thread_input_destroy( struct object *obj ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 159 | static void timer_callback( void *private ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 160 | |
| 161 | static const struct object_ops msg_queue_ops = |
| 162 | { |
| 163 | sizeof(struct msg_queue), /* size */ |
| 164 | msg_queue_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 165 | no_get_type, /* get_type */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 166 | msg_queue_add_queue, /* add_queue */ |
| 167 | msg_queue_remove_queue, /* remove_queue */ |
| 168 | msg_queue_signaled, /* signaled */ |
| 169 | msg_queue_satisfied, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 170 | no_signal, /* signal */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 171 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 172 | no_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 173 | default_get_sd, /* get_sd */ |
| 174 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 175 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 176 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 177 | no_close_handle, /* close_handle */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 178 | msg_queue_destroy /* destroy */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 181 | static const struct fd_ops msg_queue_fd_ops = |
| 182 | { |
| 183 | NULL, /* get_poll_events */ |
| 184 | msg_queue_poll_event, /* poll_event */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 185 | NULL, /* flush */ |
| 186 | NULL, /* get_fd_type */ |
Alexandre Julliard | 6357143 | 2007-04-16 14:45:03 +0200 | [diff] [blame] | 187 | NULL, /* ioctl */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 188 | NULL, /* queue_async */ |
Alexandre Julliard | 72bff2e | 2007-04-10 17:07:27 +0200 | [diff] [blame] | 189 | NULL, /* reselect_async */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 190 | NULL /* cancel async */ |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 191 | }; |
| 192 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 193 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 194 | static const struct object_ops thread_input_ops = |
| 195 | { |
| 196 | sizeof(struct thread_input), /* size */ |
| 197 | thread_input_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 198 | no_get_type, /* get_type */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 199 | no_add_queue, /* add_queue */ |
| 200 | NULL, /* remove_queue */ |
| 201 | NULL, /* signaled */ |
| 202 | NULL, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 203 | no_signal, /* signal */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 204 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 205 | no_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 206 | default_get_sd, /* get_sd */ |
| 207 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 208 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 209 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 210 | no_close_handle, /* close_handle */ |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 211 | thread_input_destroy /* destroy */ |
| 212 | }; |
| 213 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 214 | /* pointer to input structure of foreground thread */ |
Mike McCormack | abe70f7 | 2005-04-28 12:04:14 +0000 | [diff] [blame] | 215 | static unsigned int last_input_time; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 216 | |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 217 | static void queue_hardware_message( struct desktop *desktop, struct message *msg, int always_queue ); |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 218 | static void free_message( struct message *msg ); |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 219 | |
| 220 | /* set the caret window in a given thread input */ |
| 221 | static void set_caret_window( struct thread_input *input, user_handle_t win ) |
| 222 | { |
Krzysztof Foltman | b850172 | 2005-02-18 20:02:55 +0000 | [diff] [blame] | 223 | if (!win || win != input->caret) |
| 224 | { |
| 225 | input->caret_rect.left = 0; |
| 226 | input->caret_rect.top = 0; |
| 227 | input->caret_rect.right = 0; |
| 228 | input->caret_rect.bottom = 0; |
| 229 | } |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 230 | input->caret = win; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 231 | input->caret_hide = 1; |
| 232 | input->caret_state = 0; |
| 233 | } |
| 234 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 235 | /* create a thread input object */ |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 236 | static struct thread_input *create_thread_input( struct thread *thread ) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 237 | { |
| 238 | struct thread_input *input; |
| 239 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 240 | if ((input = alloc_object( &thread_input_ops ))) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 241 | { |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 242 | input->focus = 0; |
| 243 | input->capture = 0; |
| 244 | input->active = 0; |
| 245 | input->menu_owner = 0; |
| 246 | input->move_size = 0; |
| 247 | input->cursor = 0; |
| 248 | input->cursor_count = 0; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 249 | list_init( &input->msg_list ); |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 250 | set_caret_window( input, 0 ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 251 | memset( input->keystate, 0, sizeof(input->keystate) ); |
Robert Shearman | d8058fb | 2006-04-07 11:15:19 +0100 | [diff] [blame] | 252 | |
| 253 | if (!(input->desktop = get_thread_desktop( thread, 0 /* FIXME: access rights */ ))) |
| 254 | { |
| 255 | release_object( input ); |
| 256 | return NULL; |
| 257 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 258 | } |
| 259 | return input; |
| 260 | } |
| 261 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 262 | /* create a message queue object */ |
| 263 | 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] | 264 | { |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 265 | struct thread_input *new_input = NULL; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 266 | struct msg_queue *queue; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 267 | int i; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 268 | |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 269 | if (!input) |
| 270 | { |
| 271 | if (!(new_input = create_thread_input( thread ))) return NULL; |
| 272 | input = new_input; |
| 273 | } |
| 274 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 275 | if ((queue = alloc_object( &msg_queue_ops ))) |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 276 | { |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 277 | queue->fd = NULL; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 278 | queue->wake_bits = 0; |
| 279 | queue->wake_mask = 0; |
| 280 | queue->changed_bits = 0; |
| 281 | queue->changed_mask = 0; |
Alexandre Julliard | 4b0343d | 2001-06-20 22:55:31 +0000 | [diff] [blame] | 282 | queue->paint_count = 0; |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 283 | queue->hotkey_count = 0; |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 284 | queue->quit_message = 0; |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 285 | queue->cursor_count = 0; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 286 | queue->recv_result = NULL; |
Dmitry Timoshkov | b4227d7 | 2007-11-13 20:41:01 +0800 | [diff] [blame] | 287 | queue->next_timer_id = 0x7fff; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 288 | queue->timeout = NULL; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 289 | queue->input = (struct thread_input *)grab_object( input ); |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 290 | queue->hooks = NULL; |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 291 | queue->last_get_msg = current_time; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 292 | list_init( &queue->send_result ); |
| 293 | list_init( &queue->callback_result ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 294 | list_init( &queue->pending_timers ); |
| 295 | list_init( &queue->expired_timers ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 296 | 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] | 297 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 298 | thread->queue = queue; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 299 | } |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 300 | if (new_input) release_object( new_input ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 301 | return queue; |
| 302 | } |
| 303 | |
Alexandre Julliard | 31022d6 | 2002-08-16 23:30:41 +0000 | [diff] [blame] | 304 | /* free the message queue of a thread at thread exit */ |
| 305 | void free_msg_queue( struct thread *thread ) |
| 306 | { |
Alexandre Julliard | ca3ac8f | 2003-07-11 21:55:58 +0000 | [diff] [blame] | 307 | remove_thread_hooks( thread ); |
Alexandre Julliard | 31022d6 | 2002-08-16 23:30:41 +0000 | [diff] [blame] | 308 | if (!thread->queue) return; |
Alexandre Julliard | 31022d6 | 2002-08-16 23:30:41 +0000 | [diff] [blame] | 309 | release_object( thread->queue ); |
| 310 | thread->queue = NULL; |
| 311 | } |
| 312 | |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 313 | /* change the thread input data of a given thread */ |
| 314 | static int assign_thread_input( struct thread *thread, struct thread_input *new_input ) |
| 315 | { |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 316 | struct msg_queue *queue = thread->queue; |
| 317 | |
| 318 | if (!queue) |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 319 | { |
| 320 | thread->queue = create_msg_queue( thread, new_input ); |
| 321 | return thread->queue != NULL; |
| 322 | } |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 323 | if (queue->input) |
| 324 | { |
| 325 | queue->input->cursor_count -= queue->cursor_count; |
| 326 | release_object( queue->input ); |
| 327 | } |
| 328 | queue->input = (struct thread_input *)grab_object( new_input ); |
| 329 | new_input->cursor_count += queue->cursor_count; |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 330 | return 1; |
| 331 | } |
| 332 | |
Alexandre Julliard | 39bac05 | 2011-04-06 20:29:38 +0200 | [diff] [blame] | 333 | /* set the cursor position and queue the corresponding mouse message */ |
| 334 | static void set_cursor_pos( struct desktop *desktop, int x, int y ) |
| 335 | { |
| 336 | struct hardware_msg_data *msg_data; |
| 337 | struct message *msg; |
| 338 | |
| 339 | if (!(msg = mem_alloc( sizeof(*msg) ))) return; |
| 340 | if (!(msg_data = mem_alloc( sizeof(*msg_data) ))) |
| 341 | { |
| 342 | free( msg ); |
| 343 | return; |
| 344 | } |
| 345 | memset( msg_data, 0, sizeof(*msg_data) ); |
| 346 | |
| 347 | msg->type = MSG_HARDWARE; |
| 348 | msg->win = 0; |
| 349 | msg->msg = WM_MOUSEMOVE; |
| 350 | msg->wparam = 0; |
| 351 | msg->lparam = 0; |
| 352 | msg->time = get_tick_count(); |
| 353 | msg->result = NULL; |
| 354 | msg->data = msg_data; |
| 355 | msg->data_size = sizeof(*msg_data); |
| 356 | msg_data->x = x; |
| 357 | msg_data->y = y; |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 358 | queue_hardware_message( desktop, msg, 1 ); |
Alexandre Julliard | 39bac05 | 2011-04-06 20:29:38 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Julliard | 21e86f6 | 2011-03-31 20:27:29 +0200 | [diff] [blame] | 361 | /* set the cursor clip rectangle */ |
| 362 | static void set_clip_rectangle( struct desktop *desktop, const rectangle_t *rect ) |
| 363 | { |
Alexandre Julliard | 6b0d9ff | 2011-06-21 14:50:23 +0200 | [diff] [blame] | 364 | rectangle_t top_rect; |
Alexandre Julliard | 34b8c63 | 2011-04-06 20:36:36 +0200 | [diff] [blame] | 365 | int x, y; |
Alexandre Julliard | 21e86f6 | 2011-03-31 20:27:29 +0200 | [diff] [blame] | 366 | |
| 367 | get_top_window_rectangle( desktop, &top_rect ); |
Alexandre Julliard | 6b0d9ff | 2011-06-21 14:50:23 +0200 | [diff] [blame] | 368 | if (rect) |
| 369 | { |
| 370 | rectangle_t new_rect = *rect; |
| 371 | if (new_rect.left < top_rect.left) new_rect.left = top_rect.left; |
| 372 | if (new_rect.right > top_rect.right) new_rect.right = top_rect.right; |
| 373 | if (new_rect.top < top_rect.top) new_rect.top = top_rect.top; |
| 374 | if (new_rect.bottom > top_rect.bottom) new_rect.bottom = top_rect.bottom; |
| 375 | if (new_rect.left > new_rect.right || new_rect.top > new_rect.bottom) new_rect = top_rect; |
| 376 | desktop->cursor.clip = new_rect; |
| 377 | } |
| 378 | else desktop->cursor.clip = top_rect; |
| 379 | |
Alexandre Julliard | 8aa1a26 | 2011-04-22 15:22:07 +0200 | [diff] [blame] | 380 | if (desktop->cursor.clip_msg) |
| 381 | post_desktop_message( desktop, desktop->cursor.clip_msg, rect != NULL, 0 ); |
Alexandre Julliard | 34b8c63 | 2011-04-06 20:36:36 +0200 | [diff] [blame] | 382 | |
| 383 | /* warp the mouse to be inside the clip rect */ |
| 384 | x = min( max( desktop->cursor.x, desktop->cursor.clip.left ), desktop->cursor.clip.right-1 ); |
| 385 | y = min( max( desktop->cursor.y, desktop->cursor.clip.top ), desktop->cursor.clip.bottom-1 ); |
| 386 | if (x != desktop->cursor.x || y != desktop->cursor.y) set_cursor_pos( desktop, x, y ); |
Alexandre Julliard | 21e86f6 | 2011-03-31 20:27:29 +0200 | [diff] [blame] | 387 | } |
| 388 | |
Alexandre Julliard | 2b96875 | 2011-03-30 12:34:32 +0200 | [diff] [blame] | 389 | /* change the foreground input and reset the cursor clip rect */ |
| 390 | static void set_foreground_input( struct desktop *desktop, struct thread_input *input ) |
| 391 | { |
| 392 | if (desktop->foreground_input == input) return; |
Alexandre Julliard | 21e86f6 | 2011-03-31 20:27:29 +0200 | [diff] [blame] | 393 | set_clip_rectangle( desktop, NULL ); |
Alexandre Julliard | 2b96875 | 2011-03-30 12:34:32 +0200 | [diff] [blame] | 394 | desktop->foreground_input = input; |
| 395 | } |
| 396 | |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 397 | /* get the hook table for a given thread */ |
| 398 | struct hook_table *get_queue_hooks( struct thread *thread ) |
| 399 | { |
| 400 | if (!thread->queue) return NULL; |
| 401 | return thread->queue->hooks; |
| 402 | } |
| 403 | |
| 404 | /* set the hook table for a given thread, allocating the queue if needed */ |
| 405 | void set_queue_hooks( struct thread *thread, struct hook_table *hooks ) |
| 406 | { |
| 407 | struct msg_queue *queue = thread->queue; |
Alexandre Julliard | d70a253 | 2005-04-26 14:31:33 +0000 | [diff] [blame] | 408 | if (!queue && !(queue = create_msg_queue( thread, NULL ))) return; |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 409 | if (queue->hooks) release_object( queue->hooks ); |
| 410 | queue->hooks = hooks; |
| 411 | } |
| 412 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 413 | /* check the queue status */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 414 | static inline int is_signaled( struct msg_queue *queue ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 415 | { |
| 416 | return ((queue->wake_bits & queue->wake_mask) || (queue->changed_bits & queue->changed_mask)); |
| 417 | } |
| 418 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 419 | /* set some queue bits */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 420 | 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] | 421 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 422 | queue->wake_bits |= bits; |
| 423 | queue->changed_bits |= bits; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 424 | if (is_signaled( queue )) wake_up( &queue->obj, 0 ); |
| 425 | } |
| 426 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 427 | /* clear some queue bits */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 428 | 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] | 429 | { |
| 430 | queue->wake_bits &= ~bits; |
| 431 | queue->changed_bits &= ~bits; |
| 432 | } |
| 433 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 434 | /* check whether msg is a keyboard message */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 435 | static inline int is_keyboard_msg( struct message *msg ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 436 | { |
| 437 | return (msg->msg >= WM_KEYFIRST && msg->msg <= WM_KEYLAST); |
| 438 | } |
| 439 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 440 | /* check if message is matched by the filter */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 441 | 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] | 442 | { |
| 443 | return (msg >= first && msg <= last); |
| 444 | } |
| 445 | |
Alexandre Julliard | cf2f142 | 2005-03-14 17:17:09 +0000 | [diff] [blame] | 446 | /* check whether a message filter contains at least one potential hardware message */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 447 | 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] | 448 | { |
| 449 | /* hardware message ranges are (in numerical order): |
| 450 | * WM_NCMOUSEFIRST .. WM_NCMOUSELAST |
| 451 | * WM_KEYFIRST .. WM_KEYLAST |
| 452 | * WM_MOUSEFIRST .. WM_MOUSELAST |
| 453 | */ |
| 454 | if (last < WM_NCMOUSEFIRST) return 0; |
| 455 | if (first > WM_NCMOUSELAST && last < WM_KEYFIRST) return 0; |
| 456 | if (first > WM_KEYLAST && last < WM_MOUSEFIRST) return 0; |
| 457 | if (first > WM_MOUSELAST) return 0; |
| 458 | return 1; |
| 459 | } |
| 460 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 461 | /* get the QS_* bit corresponding to a given hardware message */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 462 | static inline int get_hardware_msg_bit( struct message *msg ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 463 | { |
| 464 | if (msg->msg == WM_MOUSEMOVE || msg->msg == WM_NCMOUSEMOVE) return QS_MOUSEMOVE; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 465 | if (is_keyboard_msg( msg )) return QS_KEY; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 466 | return QS_MOUSEBUTTON; |
| 467 | } |
| 468 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 469 | /* get the current thread queue, creating it if needed */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 470 | static inline struct msg_queue *get_current_queue(void) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 471 | { |
| 472 | struct msg_queue *queue = current->queue; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 473 | if (!queue) queue = create_msg_queue( current, NULL ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 474 | return queue; |
| 475 | } |
| 476 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 477 | /* get a (pseudo-)unique id to tag hardware messages */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 478 | static inline unsigned int get_unique_id(void) |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 479 | { |
| 480 | static unsigned int id; |
| 481 | if (!++id) id = 1; /* avoid an id of 0 */ |
| 482 | return id; |
| 483 | } |
| 484 | |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 485 | /* 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] | 486 | static int merge_message( struct thread_input *input, const struct message *msg ) |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 487 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 488 | struct message *prev; |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 489 | struct list *ptr; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 490 | |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 491 | if (msg->msg != WM_MOUSEMOVE) return 0; |
| 492 | if (!(ptr = list_tail( &input->msg_list ))) return 0; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 493 | prev = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 494 | if (prev->result) return 0; |
Alexandre Julliard | 942a70d | 2007-11-27 16:43:00 +0100 | [diff] [blame] | 495 | if (prev->win && msg->win && prev->win != msg->win) return 0; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 496 | if (prev->msg != msg->msg) return 0; |
| 497 | if (prev->type != msg->type) return 0; |
| 498 | /* now we can merge it */ |
| 499 | prev->wparam = msg->wparam; |
| 500 | prev->lparam = msg->lparam; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 501 | prev->time = msg->time; |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 502 | if (msg->type == MSG_HARDWARE && prev->data && msg->data) |
| 503 | { |
| 504 | struct hardware_msg_data *prev_data = prev->data; |
| 505 | struct hardware_msg_data *msg_data = msg->data; |
| 506 | prev_data->x = msg_data->x; |
| 507 | prev_data->y = msg_data->y; |
| 508 | prev_data->info = msg_data->info; |
| 509 | } |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 510 | return 1; |
| 511 | } |
| 512 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 513 | /* free a result structure */ |
| 514 | static void free_result( struct message_result *result ) |
| 515 | { |
| 516 | if (result->timeout) remove_timeout_user( result->timeout ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 517 | free( result->data ); |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 518 | if (result->callback_msg) free_message( result->callback_msg ); |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 519 | if (result->hardware_msg) free_message( result->hardware_msg ); |
| 520 | if (result->desktop) release_object( result->desktop ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 521 | free( result ); |
| 522 | } |
| 523 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 524 | /* remove the result from the sender list it is on */ |
| 525 | static inline void remove_result_from_sender( struct message_result *result ) |
| 526 | { |
| 527 | assert( result->sender ); |
| 528 | |
| 529 | list_remove( &result->sender_entry ); |
| 530 | result->sender = NULL; |
| 531 | if (!result->receiver) free_result( result ); |
| 532 | } |
| 533 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 534 | /* store the message result in the appropriate structure */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 535 | 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] | 536 | { |
| 537 | res->result = result; |
| 538 | res->error = error; |
| 539 | res->replied = 1; |
| 540 | if (res->timeout) |
| 541 | { |
| 542 | remove_timeout_user( res->timeout ); |
| 543 | res->timeout = NULL; |
| 544 | } |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 545 | |
| 546 | if (res->hardware_msg) |
| 547 | { |
| 548 | if (!error && result) /* rejected by the hook */ |
| 549 | free_message( res->hardware_msg ); |
| 550 | else |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 551 | queue_hardware_message( res->desktop, res->hardware_msg, 0 ); |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 552 | |
| 553 | res->hardware_msg = NULL; |
| 554 | } |
| 555 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 556 | if (res->sender) |
| 557 | { |
| 558 | if (res->callback_msg) |
| 559 | { |
| 560 | /* queue the callback message in the sender queue */ |
Alexandre Julliard | 29a3ce9 | 2006-10-04 16:29:45 +0200 | [diff] [blame] | 561 | struct callback_msg_data *data = res->callback_msg->data; |
| 562 | data->result = result; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 563 | 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] | 564 | set_queue_bits( res->sender, QS_SENDMESSAGE ); |
| 565 | res->callback_msg = NULL; |
| 566 | remove_result_from_sender( res ); |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | /* wake sender queue if waiting on this result */ |
| 571 | if (list_head(&res->sender->send_result) == &res->sender_entry) |
| 572 | set_queue_bits( res->sender, QS_SMRESULT ); |
| 573 | } |
| 574 | } |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 575 | else if (!res->receiver) free_result( res ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 578 | /* free a message when deleting a queue or window */ |
| 579 | static void free_message( struct message *msg ) |
| 580 | { |
| 581 | struct message_result *result = msg->result; |
| 582 | if (result) |
| 583 | { |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 584 | result->msg = NULL; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 585 | result->receiver = NULL; |
| 586 | store_message_result( result, 0, STATUS_ACCESS_DENIED /*FIXME*/ ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 587 | } |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 588 | free( msg->data ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 589 | free( msg ); |
| 590 | } |
| 591 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 592 | /* remove (and free) a message from a message list */ |
| 593 | static void remove_queue_message( struct msg_queue *queue, struct message *msg, |
| 594 | enum message_kind kind ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 595 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 596 | list_remove( &msg->entry ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 597 | switch(kind) |
| 598 | { |
| 599 | case SEND_MESSAGE: |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 600 | 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] | 601 | break; |
| 602 | case POST_MESSAGE: |
Robert Shearman | 22bd7a3 | 2006-05-22 22:16:53 +0100 | [diff] [blame] | 603 | if (list_empty( &queue->msg_list[kind] ) && !queue->quit_message) |
| 604 | clear_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 605 | if (msg->msg == WM_HOTKEY && --queue->hotkey_count == 0) |
| 606 | clear_queue_bits( queue, QS_HOTKEY ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 607 | break; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 608 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 609 | free_message( msg ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 612 | /* message timed out without getting a reply */ |
| 613 | static void result_timeout( void *private ) |
| 614 | { |
| 615 | struct message_result *result = private; |
| 616 | |
| 617 | assert( !result->replied ); |
| 618 | |
| 619 | result->timeout = NULL; |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 620 | |
| 621 | if (result->msg) /* not received yet */ |
| 622 | { |
| 623 | struct message *msg = result->msg; |
| 624 | |
| 625 | result->msg = NULL; |
| 626 | msg->result = NULL; |
| 627 | remove_queue_message( result->receiver, msg, SEND_MESSAGE ); |
| 628 | result->receiver = NULL; |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 629 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 630 | store_message_result( result, 0, STATUS_TIMEOUT ); |
| 631 | } |
| 632 | |
| 633 | /* allocate and fill a message result structure */ |
| 634 | static struct message_result *alloc_message_result( struct msg_queue *send_queue, |
| 635 | struct msg_queue *recv_queue, |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 636 | struct message *msg, timeout_t timeout ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 637 | { |
| 638 | struct message_result *result = mem_alloc( sizeof(*result) ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 639 | if (result) |
| 640 | { |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 641 | result->msg = msg; |
| 642 | result->sender = send_queue; |
| 643 | result->receiver = recv_queue; |
| 644 | result->replied = 0; |
| 645 | result->data = NULL; |
| 646 | result->data_size = 0; |
| 647 | result->timeout = NULL; |
| 648 | result->hardware_msg = NULL; |
| 649 | result->desktop = NULL; |
| 650 | result->callback_msg = NULL; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 651 | |
| 652 | if (msg->type == MSG_CALLBACK) |
| 653 | { |
| 654 | struct message *callback_msg = mem_alloc( sizeof(*callback_msg) ); |
Alexandre Julliard | 29a3ce9 | 2006-10-04 16:29:45 +0200 | [diff] [blame] | 655 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 656 | if (!callback_msg) |
| 657 | { |
| 658 | free( result ); |
| 659 | return NULL; |
| 660 | } |
| 661 | callback_msg->type = MSG_CALLBACK_RESULT; |
| 662 | callback_msg->win = msg->win; |
| 663 | callback_msg->msg = msg->msg; |
Alexandre Julliard | 29a3ce9 | 2006-10-04 16:29:45 +0200 | [diff] [blame] | 664 | callback_msg->wparam = 0; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 665 | callback_msg->lparam = 0; |
| 666 | callback_msg->time = get_tick_count(); |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 667 | callback_msg->result = NULL; |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 668 | /* steal the data from the original message */ |
| 669 | callback_msg->data = msg->data; |
| 670 | callback_msg->data_size = msg->data_size; |
| 671 | msg->data = NULL; |
| 672 | msg->data_size = 0; |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 673 | |
| 674 | result->callback_msg = callback_msg; |
| 675 | list_add_head( &send_queue->callback_result, &result->sender_entry ); |
| 676 | } |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 677 | else if (send_queue) list_add_head( &send_queue->send_result, &result->sender_entry ); |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 678 | |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 679 | if (timeout != TIMEOUT_INFINITE) |
| 680 | result->timeout = add_timeout_user( timeout, result_timeout, result ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 681 | } |
| 682 | return result; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /* receive a message, removing it from the sent queue */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 686 | static void receive_message( struct msg_queue *queue, struct message *msg, |
| 687 | struct get_message_reply *reply ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 688 | { |
| 689 | struct message_result *result = msg->result; |
| 690 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 691 | reply->total = msg->data_size; |
| 692 | if (msg->data_size > get_reply_max_size()) |
| 693 | { |
| 694 | set_error( STATUS_BUFFER_OVERFLOW ); |
| 695 | return; |
| 696 | } |
| 697 | reply->type = msg->type; |
| 698 | reply->win = msg->win; |
| 699 | reply->msg = msg->msg; |
| 700 | reply->wparam = msg->wparam; |
| 701 | reply->lparam = msg->lparam; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 702 | reply->time = msg->time; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 703 | |
| 704 | if (msg->data) set_reply_data_ptr( msg->data, msg->data_size ); |
| 705 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 706 | list_remove( &msg->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 707 | /* put the result on the receiver result stack */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 708 | if (result) |
| 709 | { |
Alexandre Julliard | 127127f | 2005-09-13 14:46:46 +0000 | [diff] [blame] | 710 | result->msg = NULL; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 711 | result->recv_next = queue->recv_result; |
| 712 | queue->recv_result = result; |
| 713 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 714 | free( msg ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 715 | 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] | 716 | } |
| 717 | |
| 718 | /* set the result of the current received message */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 719 | static void reply_message( struct msg_queue *queue, lparam_t result, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 720 | unsigned int error, int remove, const void *data, data_size_t len ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 721 | { |
| 722 | struct message_result *res = queue->recv_result; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 723 | |
| 724 | if (remove) |
| 725 | { |
| 726 | queue->recv_result = res->recv_next; |
| 727 | res->receiver = NULL; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 728 | if (!res->sender && !res->hardware_msg) /* no one waiting for it */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 729 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 730 | free_result( res ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | } |
| 734 | if (!res->replied) |
| 735 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 736 | if (len && (res->data = memdup( data, len ))) res->data_size = len; |
| 737 | store_message_result( res, result, error ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
Dmitry Timoshkov | acb0566 | 2009-06-11 21:49:31 +0900 | [diff] [blame] | 741 | static int match_window( user_handle_t win, user_handle_t msg_win ) |
| 742 | { |
| 743 | if (!win) return 1; |
Alexandre Julliard | 4d33d49 | 2010-03-03 13:18:33 +0100 | [diff] [blame] | 744 | if (win == -1 || win == 1) return !msg_win; |
Dmitry Timoshkov | acb0566 | 2009-06-11 21:49:31 +0900 | [diff] [blame] | 745 | if (msg_win == win) return 1; |
| 746 | return is_child_window( win, msg_win ); |
| 747 | } |
| 748 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 749 | /* retrieve a posted message */ |
| 750 | static int get_posted_message( struct msg_queue *queue, user_handle_t win, |
| 751 | unsigned int first, unsigned int last, unsigned int flags, |
| 752 | struct get_message_reply *reply ) |
| 753 | { |
| 754 | struct message *msg; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 755 | |
| 756 | /* check against the filters */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 757 | 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] | 758 | { |
Dmitry Timoshkov | acb0566 | 2009-06-11 21:49:31 +0900 | [diff] [blame] | 759 | if (!match_window( win, msg->win )) continue; |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 760 | if (!check_msg_filter( msg->msg, first, last )) continue; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 761 | goto found; /* found one */ |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 762 | } |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 763 | return 0; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 764 | |
| 765 | /* return it to the app */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 766 | found: |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 767 | reply->total = msg->data_size; |
| 768 | if (msg->data_size > get_reply_max_size()) |
| 769 | { |
| 770 | set_error( STATUS_BUFFER_OVERFLOW ); |
| 771 | return 1; |
| 772 | } |
| 773 | reply->type = msg->type; |
| 774 | reply->win = msg->win; |
| 775 | reply->msg = msg->msg; |
| 776 | reply->wparam = msg->wparam; |
| 777 | reply->lparam = msg->lparam; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 778 | reply->time = msg->time; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 779 | |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 780 | if (flags & PM_REMOVE) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 781 | { |
| 782 | if (msg->data) |
| 783 | { |
| 784 | set_reply_data_ptr( msg->data, msg->data_size ); |
| 785 | msg->data = NULL; |
| 786 | msg->data_size = 0; |
| 787 | } |
| 788 | remove_queue_message( queue, msg, POST_MESSAGE ); |
| 789 | } |
| 790 | else if (msg->data) set_reply_data( msg->data, msg->data_size ); |
| 791 | |
| 792 | return 1; |
| 793 | } |
| 794 | |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 795 | static int get_quit_message( struct msg_queue *queue, unsigned int flags, |
| 796 | struct get_message_reply *reply ) |
| 797 | { |
| 798 | if (queue->quit_message) |
| 799 | { |
| 800 | reply->total = 0; |
| 801 | reply->type = MSG_POSTED; |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 802 | reply->win = 0; |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 803 | reply->msg = WM_QUIT; |
| 804 | reply->wparam = queue->exit_code; |
| 805 | reply->lparam = 0; |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 806 | reply->time = get_tick_count(); |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 807 | |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 808 | if (flags & PM_REMOVE) |
Robert Shearman | 22bd7a3 | 2006-05-22 22:16:53 +0100 | [diff] [blame] | 809 | { |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 810 | queue->quit_message = 0; |
Robert Shearman | 22bd7a3 | 2006-05-22 22:16:53 +0100 | [diff] [blame] | 811 | if (list_empty( &queue->msg_list[POST_MESSAGE] )) |
| 812 | clear_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
| 813 | } |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 814 | return 1; |
| 815 | } |
| 816 | else |
| 817 | return 0; |
| 818 | } |
| 819 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 820 | /* empty a message list and free all the messages */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 821 | static void empty_msg_list( struct list *list ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 822 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 823 | struct list *ptr; |
| 824 | |
| 825 | while ((ptr = list_head( list )) != NULL) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 826 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 827 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
| 828 | list_remove( &msg->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 829 | free_message( msg ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
| 833 | /* cleanup all pending results when deleting a queue */ |
| 834 | static void cleanup_results( struct msg_queue *queue ) |
| 835 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 836 | struct list *entry; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 837 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 838 | while ((entry = list_head( &queue->send_result )) != NULL) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 839 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 840 | remove_result_from_sender( LIST_ENTRY( entry, struct message_result, sender_entry ) ); |
| 841 | } |
| 842 | |
| 843 | while ((entry = list_head( &queue->callback_result )) != NULL) |
| 844 | { |
| 845 | remove_result_from_sender( LIST_ENTRY( entry, struct message_result, sender_entry ) ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 848 | while (queue->recv_result) |
| 849 | reply_message( queue, 0, STATUS_ACCESS_DENIED /*FIXME*/, 1, NULL, 0 ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 852 | /* check if the thread owning the queue is hung (not checking for messages) */ |
| 853 | static int is_queue_hung( struct msg_queue *queue ) |
| 854 | { |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 855 | struct wait_queue_entry *entry; |
| 856 | |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 857 | if (current_time - queue->last_get_msg <= 5 * TICKS_PER_SEC) |
Alexandre Julliard | 09029b2 | 2003-07-11 04:09:42 +0000 | [diff] [blame] | 858 | return 0; /* less than 5 seconds since last get message -> not hung */ |
| 859 | |
Alexandre Julliard | aa34768 | 2005-03-01 11:49:58 +0000 | [diff] [blame] | 860 | 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] | 861 | { |
| 862 | if (entry->thread->queue == queue) |
| 863 | return 0; /* thread is waiting on queue -> not hung */ |
| 864 | } |
| 865 | return 1; |
| 866 | } |
| 867 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 868 | static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry ) |
| 869 | { |
| 870 | struct msg_queue *queue = (struct msg_queue *)obj; |
| 871 | struct process *process = entry->thread->process; |
| 872 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 873 | /* a thread can only wait on its own queue */ |
| 874 | if (entry->thread->queue != queue) |
| 875 | { |
| 876 | set_error( STATUS_ACCESS_DENIED ); |
| 877 | return 0; |
| 878 | } |
Alexandre Julliard | 92e704e | 2009-12-16 17:32:15 +0100 | [diff] [blame] | 879 | if (process->idle_event && !(queue->wake_mask & QS_SMRESULT)) set_event( process->idle_event ); |
Alexandre Julliard | 7d4e284 | 2009-12-16 17:25:01 +0100 | [diff] [blame] | 880 | |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 881 | if (queue->fd && list_empty( &obj->wait_queue )) /* first on the queue */ |
| 882 | set_fd_events( queue->fd, POLLIN ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 883 | add_queue( obj, entry ); |
| 884 | return 1; |
| 885 | } |
| 886 | |
| 887 | static void msg_queue_remove_queue(struct object *obj, struct wait_queue_entry *entry ) |
| 888 | { |
| 889 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 890 | |
| 891 | remove_queue( obj, entry ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 892 | if (queue->fd && list_empty( &obj->wait_queue )) /* last on the queue is gone */ |
| 893 | set_fd_events( queue->fd, 0 ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | static void msg_queue_dump( struct object *obj, int verbose ) |
| 897 | { |
| 898 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 899 | fprintf( stderr, "Msg queue bits=%x mask=%x\n", |
| 900 | queue->wake_bits, queue->wake_mask ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | static int msg_queue_signaled( struct object *obj, struct thread *thread ) |
| 904 | { |
| 905 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 906 | int ret = 0; |
| 907 | |
| 908 | if (queue->fd) |
| 909 | { |
| 910 | if ((ret = check_fd_events( queue->fd, POLLIN ))) |
| 911 | /* stop waiting on select() if we are signaled */ |
| 912 | set_fd_events( queue->fd, 0 ); |
| 913 | else if (!list_empty( &obj->wait_queue )) |
| 914 | /* restart waiting on poll() if we are no longer signaled */ |
| 915 | set_fd_events( queue->fd, POLLIN ); |
| 916 | } |
| 917 | return ret || is_signaled( queue ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static int msg_queue_satisfied( struct object *obj, struct thread *thread ) |
| 921 | { |
| 922 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 923 | queue->wake_mask = 0; |
| 924 | queue->changed_mask = 0; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 925 | return 0; /* Not abandoned */ |
| 926 | } |
| 927 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 928 | static void msg_queue_destroy( struct object *obj ) |
| 929 | { |
| 930 | struct msg_queue *queue = (struct msg_queue *)obj; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 931 | struct list *ptr; |
Vincent Povirk | 4c83138 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 932 | struct hotkey *hotkey, *hotkey2; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 933 | int i; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 934 | |
| 935 | cleanup_results( queue ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 936 | 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] | 937 | |
Vincent Povirk | 4c83138 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 938 | LIST_FOR_EACH_ENTRY_SAFE( hotkey, hotkey2, &queue->input->desktop->hotkeys, struct hotkey, entry ) |
| 939 | { |
| 940 | if (hotkey->queue == queue) |
| 941 | { |
| 942 | list_remove( &hotkey->entry ); |
| 943 | free( hotkey ); |
| 944 | } |
| 945 | } |
| 946 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 947 | while ((ptr = list_head( &queue->pending_timers ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 948 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 949 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 950 | list_remove( &timer->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 951 | free( timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 952 | } |
| 953 | while ((ptr = list_head( &queue->expired_timers ))) |
| 954 | { |
| 955 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 956 | list_remove( &timer->entry ); |
| 957 | free( timer ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 958 | } |
| 959 | if (queue->timeout) remove_timeout_user( queue->timeout ); |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 960 | if (queue->input) |
| 961 | { |
| 962 | queue->input->cursor_count -= queue->cursor_count; |
| 963 | release_object( queue->input ); |
| 964 | } |
Alexandre Julliard | d55e7f1 | 2003-07-03 18:16:48 +0000 | [diff] [blame] | 965 | if (queue->hooks) release_object( queue->hooks ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 966 | if (queue->fd) release_object( queue->fd ); |
| 967 | } |
| 968 | |
| 969 | static void msg_queue_poll_event( struct fd *fd, int event ) |
| 970 | { |
| 971 | struct msg_queue *queue = get_fd_user( fd ); |
| 972 | assert( queue->obj.ops == &msg_queue_ops ); |
| 973 | |
| 974 | if (event & (POLLERR | POLLHUP)) set_fd_events( fd, -1 ); |
Alexandre Julliard | 2d69ba4 | 2009-06-02 22:14:40 +0200 | [diff] [blame] | 975 | else set_fd_events( queue->fd, 0 ); |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 976 | wake_up( &queue->obj, 0 ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 979 | static void thread_input_dump( struct object *obj, int verbose ) |
| 980 | { |
| 981 | struct thread_input *input = (struct thread_input *)obj; |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 982 | fprintf( stderr, "Thread input focus=%08x capture=%08x active=%08x\n", |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 983 | input->focus, input->capture, input->active ); |
| 984 | } |
| 985 | |
| 986 | static void thread_input_destroy( struct object *obj ) |
| 987 | { |
| 988 | struct thread_input *input = (struct thread_input *)obj; |
| 989 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 990 | empty_msg_list( &input->msg_list ); |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 991 | if (input->desktop) |
| 992 | { |
Alexandre Julliard | 2b96875 | 2011-03-30 12:34:32 +0200 | [diff] [blame] | 993 | if (input->desktop->foreground_input == input) set_foreground_input( input->desktop, NULL ); |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 994 | release_object( input->desktop ); |
| 995 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /* fix the thread input data when a window is destroyed */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 999 | 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] | 1000 | { |
| 1001 | struct thread_input *input = queue->input; |
| 1002 | |
| 1003 | if (window == input->focus) input->focus = 0; |
| 1004 | if (window == input->capture) input->capture = 0; |
| 1005 | if (window == input->active) input->active = 0; |
| 1006 | if (window == input->menu_owner) input->menu_owner = 0; |
| 1007 | if (window == input->move_size) input->move_size = 0; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 1008 | if (window == input->caret) set_caret_window( input, 0 ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 1011 | /* check if the specified window can be set in the input data of a given queue */ |
| 1012 | static int check_queue_input_window( struct msg_queue *queue, user_handle_t window ) |
| 1013 | { |
| 1014 | struct thread *thread; |
| 1015 | int ret = 0; |
| 1016 | |
| 1017 | if (!window) return 1; /* we can always clear the data */ |
| 1018 | |
| 1019 | if ((thread = get_window_thread( window ))) |
| 1020 | { |
| 1021 | ret = (queue->input == thread->queue->input); |
| 1022 | if (!ret) set_error( STATUS_ACCESS_DENIED ); |
| 1023 | release_object( thread ); |
| 1024 | } |
| 1025 | else set_error( STATUS_INVALID_HANDLE ); |
| 1026 | |
| 1027 | return ret; |
| 1028 | } |
| 1029 | |
Alexandre Julliard | d70a253 | 2005-04-26 14:31:33 +0000 | [diff] [blame] | 1030 | /* make sure the specified thread has a queue */ |
| 1031 | int init_thread_queue( struct thread *thread ) |
| 1032 | { |
| 1033 | if (thread->queue) return 1; |
| 1034 | return (create_msg_queue( thread, NULL ) != NULL); |
| 1035 | } |
| 1036 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1037 | /* attach two thread input data structures */ |
| 1038 | int attach_thread_input( struct thread *thread_from, struct thread *thread_to ) |
| 1039 | { |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 1040 | struct desktop *desktop; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1041 | struct thread_input *input; |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 1042 | int ret; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1043 | |
| 1044 | 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] | 1045 | if (!(desktop = get_thread_desktop( thread_from, 0 ))) return 0; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1046 | input = (struct thread_input *)grab_object( thread_to->queue->input ); |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 1047 | if (input->desktop != desktop) |
| 1048 | { |
| 1049 | set_error( STATUS_ACCESS_DENIED ); |
| 1050 | release_object( input ); |
| 1051 | release_object( desktop ); |
| 1052 | return 0; |
| 1053 | } |
| 1054 | release_object( desktop ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1055 | |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 1056 | ret = assign_thread_input( thread_from, input ); |
| 1057 | if (ret) memset( input->keystate, 0, sizeof(input->keystate) ); |
| 1058 | release_object( input ); |
| 1059 | return ret; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | /* detach two thread input data structures */ |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 1063 | void detach_thread_input( struct thread *thread_from ) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1064 | { |
| 1065 | struct thread_input *input; |
| 1066 | |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 1067 | if ((input = create_thread_input( thread_from ))) |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1068 | { |
Alexandre Julliard | 5efe996 | 2010-03-22 17:48:22 +0100 | [diff] [blame] | 1069 | assign_thread_input( thread_from, input ); |
| 1070 | release_object( input ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1075 | /* set the next timer to expire */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1076 | static void set_next_timer( struct msg_queue *queue ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1077 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1078 | struct list *ptr; |
| 1079 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1080 | if (queue->timeout) |
| 1081 | { |
| 1082 | remove_timeout_user( queue->timeout ); |
| 1083 | queue->timeout = NULL; |
| 1084 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1085 | if ((ptr = list_head( &queue->pending_timers ))) |
| 1086 | { |
| 1087 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1088 | queue->timeout = add_timeout_user( timer->when, timer_callback, queue ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1089 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1090 | /* set/clear QS_TIMER bit */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1091 | if (list_empty( &queue->expired_timers )) |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1092 | clear_queue_bits( queue, QS_TIMER ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1093 | else |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 1094 | set_queue_bits( queue, QS_TIMER ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1097 | /* find a timer from its window and id */ |
| 1098 | 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] | 1099 | unsigned int msg, lparam_t id ) |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1100 | { |
| 1101 | struct list *ptr; |
| 1102 | |
| 1103 | /* we need to search both lists */ |
| 1104 | |
| 1105 | LIST_FOR_EACH( ptr, &queue->pending_timers ) |
| 1106 | { |
| 1107 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1108 | if (timer->win == win && timer->msg == msg && timer->id == id) return timer; |
| 1109 | } |
| 1110 | LIST_FOR_EACH( ptr, &queue->expired_timers ) |
| 1111 | { |
| 1112 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1113 | if (timer->win == win && timer->msg == msg && timer->id == id) return timer; |
| 1114 | } |
| 1115 | return NULL; |
| 1116 | } |
| 1117 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1118 | /* callback for the next timer expiration */ |
| 1119 | static void timer_callback( void *private ) |
| 1120 | { |
| 1121 | struct msg_queue *queue = private; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1122 | struct list *ptr; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1123 | |
| 1124 | queue->timeout = NULL; |
| 1125 | /* move on to the next timer */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1126 | ptr = list_head( &queue->pending_timers ); |
| 1127 | list_remove( ptr ); |
| 1128 | list_add_tail( &queue->expired_timers, ptr ); |
| 1129 | set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /* link a timer at its rightful place in the queue list */ |
| 1133 | static void link_timer( struct msg_queue *queue, struct timer *timer ) |
| 1134 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1135 | struct list *ptr; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1136 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1137 | 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] | 1138 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1139 | struct timer *t = LIST_ENTRY( ptr, struct timer, entry ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1140 | if (t->when >= timer->when) break; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1141 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1142 | list_add_before( ptr, &timer->entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1145 | /* remove a timer from the queue timer list and free it */ |
| 1146 | static void free_timer( struct msg_queue *queue, struct timer *timer ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1147 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1148 | list_remove( &timer->entry ); |
| 1149 | free( timer ); |
| 1150 | set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | /* restart an expired timer */ |
| 1154 | static void restart_timer( struct msg_queue *queue, struct timer *timer ) |
| 1155 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1156 | list_remove( &timer->entry ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1157 | while (timer->when <= current_time) timer->when += (timeout_t)timer->rate * 10000; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1158 | link_timer( queue, timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1159 | set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* find an expired timer matching the filtering parameters */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1163 | 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] | 1164 | unsigned int get_first, unsigned int get_last, |
| 1165 | int remove ) |
| 1166 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1167 | struct list *ptr; |
| 1168 | |
| 1169 | LIST_FOR_EACH( ptr, &queue->expired_timers ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1170 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1171 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1172 | if (win && timer->win != win) continue; |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1173 | if (check_msg_filter( timer->msg, get_first, get_last )) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1174 | { |
| 1175 | if (remove) restart_timer( queue, timer ); |
| 1176 | return timer; |
| 1177 | } |
| 1178 | } |
| 1179 | return NULL; |
| 1180 | } |
| 1181 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1182 | /* add a timer */ |
| 1183 | static struct timer *set_timer( struct msg_queue *queue, unsigned int rate ) |
| 1184 | { |
| 1185 | struct timer *timer = mem_alloc( sizeof(*timer) ); |
| 1186 | if (timer) |
| 1187 | { |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 1188 | timer->rate = max( rate, 1 ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1189 | timer->when = current_time + (timeout_t)timer->rate * 10000; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1190 | link_timer( queue, timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1191 | /* check if we replaced the next timer */ |
| 1192 | if (list_head( &queue->pending_timers ) == &timer->entry) set_next_timer( queue ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1193 | } |
| 1194 | return timer; |
| 1195 | } |
| 1196 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1197 | /* change the input key state for a given key */ |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1198 | static void set_input_key_state( unsigned char *keystate, unsigned char key, int down ) |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1199 | { |
| 1200 | if (down) |
| 1201 | { |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1202 | if (!(keystate[key] & 0x80)) keystate[key] ^= 0x01; |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1203 | keystate[key] |= down; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1204 | } |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1205 | else keystate[key] &= ~0x80; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | /* update the input key state for a keyboard message */ |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1209 | static void update_input_key_state( struct desktop *desktop, unsigned char *keystate, |
| 1210 | const struct message *msg ) |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1211 | { |
| 1212 | unsigned char key; |
Vitaliy Margolen | 9faf7e3 | 2008-04-01 23:13:45 -0600 | [diff] [blame] | 1213 | int down = 0; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1214 | |
| 1215 | switch (msg->msg) |
| 1216 | { |
| 1217 | case WM_LBUTTONDOWN: |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1218 | down = (keystate == desktop->keystate) ? 0xc0 : 0x80; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1219 | /* fall through */ |
| 1220 | case WM_LBUTTONUP: |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1221 | set_input_key_state( keystate, VK_LBUTTON, down ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1222 | break; |
| 1223 | case WM_MBUTTONDOWN: |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1224 | down = (keystate == desktop->keystate) ? 0xc0 : 0x80; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1225 | /* fall through */ |
| 1226 | case WM_MBUTTONUP: |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1227 | set_input_key_state( keystate, VK_MBUTTON, down ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1228 | break; |
| 1229 | case WM_RBUTTONDOWN: |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1230 | down = (keystate == desktop->keystate) ? 0xc0 : 0x80; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1231 | /* fall through */ |
| 1232 | case WM_RBUTTONUP: |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1233 | set_input_key_state( keystate, VK_RBUTTON, down ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1234 | break; |
Alexandre Julliard | cb7aa87 | 2005-03-24 19:16:54 +0000 | [diff] [blame] | 1235 | case WM_XBUTTONDOWN: |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1236 | down = (keystate == desktop->keystate) ? 0xc0 : 0x80; |
Alexandre Julliard | cb7aa87 | 2005-03-24 19:16:54 +0000 | [diff] [blame] | 1237 | /* fall through */ |
| 1238 | case WM_XBUTTONUP: |
Alexandre Julliard | 0b8571e | 2011-03-07 23:48:03 +0100 | [diff] [blame] | 1239 | if (msg->wparam >> 16 == XBUTTON1) set_input_key_state( keystate, VK_XBUTTON1, down ); |
| 1240 | else if (msg->wparam >> 16 == XBUTTON2) set_input_key_state( keystate, VK_XBUTTON2, down ); |
Alexandre Julliard | cb7aa87 | 2005-03-24 19:16:54 +0000 | [diff] [blame] | 1241 | break; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1242 | case WM_KEYDOWN: |
| 1243 | case WM_SYSKEYDOWN: |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1244 | down = (keystate == desktop->keystate) ? 0xc0 : 0x80; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1245 | /* fall through */ |
| 1246 | case WM_KEYUP: |
| 1247 | case WM_SYSKEYUP: |
| 1248 | key = (unsigned char)msg->wparam; |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1249 | set_input_key_state( keystate, key, down ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1250 | switch(key) |
| 1251 | { |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1252 | case VK_LCONTROL: |
| 1253 | case VK_RCONTROL: |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1254 | down = (keystate[VK_LCONTROL] | keystate[VK_RCONTROL]) & 0x80; |
| 1255 | set_input_key_state( keystate, VK_CONTROL, down ); |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1256 | break; |
| 1257 | case VK_LMENU: |
| 1258 | case VK_RMENU: |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1259 | down = (keystate[VK_LMENU] | keystate[VK_RMENU]) & 0x80; |
| 1260 | set_input_key_state( keystate, VK_MENU, down ); |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1261 | break; |
| 1262 | case VK_LSHIFT: |
| 1263 | case VK_RSHIFT: |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 1264 | down = (keystate[VK_LSHIFT] | keystate[VK_RSHIFT]) & 0x80; |
| 1265 | set_input_key_state( keystate, VK_SHIFT, down ); |
Thomas Kho | 0e81484 | 2006-04-12 11:13:46 -0700 | [diff] [blame] | 1266 | break; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1267 | } |
| 1268 | break; |
| 1269 | } |
| 1270 | } |
| 1271 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1272 | /* release the hardware message currently being processed by the given thread */ |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1273 | static void release_hardware_message( struct msg_queue *queue, unsigned int hw_id, |
| 1274 | int remove, user_handle_t new_win ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1275 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1276 | struct thread_input *input = queue->input; |
| 1277 | struct message *msg; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1278 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1279 | LIST_FOR_EACH_ENTRY( msg, &input->msg_list, struct message, entry ) |
| 1280 | { |
| 1281 | if (msg->unique_id == hw_id) break; |
| 1282 | } |
| 1283 | if (&msg->entry == &input->msg_list) return; /* not found */ |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1284 | |
| 1285 | /* clear the queue bit for that message */ |
| 1286 | if (remove || new_win) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1287 | { |
| 1288 | struct message *other; |
| 1289 | int clr_bit; |
| 1290 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1291 | clr_bit = get_hardware_msg_bit( msg ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1292 | LIST_FOR_EACH_ENTRY( other, &input->msg_list, struct message, entry ) |
| 1293 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1294 | if (other != msg && get_hardware_msg_bit( other ) == clr_bit) |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1295 | { |
| 1296 | clr_bit = 0; |
| 1297 | break; |
| 1298 | } |
| 1299 | } |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1300 | if (clr_bit) clear_queue_bits( queue, clr_bit ); |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | if (new_win) /* set the new window */ |
| 1304 | { |
| 1305 | struct thread *owner = get_window_thread( new_win ); |
| 1306 | if (owner) |
| 1307 | { |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1308 | msg->win = new_win; |
| 1309 | if (owner->queue->input != input) |
Alexandre Julliard | 90b48e9 | 2005-05-13 14:00:19 +0000 | [diff] [blame] | 1310 | { |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1311 | list_remove( &msg->entry ); |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1312 | if (merge_message( owner->queue->input, msg )) |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1313 | { |
| 1314 | free_message( msg ); |
| 1315 | release_object( owner ); |
| 1316 | return; |
| 1317 | } |
| 1318 | list_add_tail( &owner->queue->input->msg_list, &msg->entry ); |
Alexandre Julliard | 90b48e9 | 2005-05-13 14:00:19 +0000 | [diff] [blame] | 1319 | } |
Alexandre Julliard | 93938eb | 2007-11-08 13:53:26 +0100 | [diff] [blame] | 1320 | set_queue_bits( owner->queue, get_hardware_msg_bit( msg )); |
| 1321 | remove = 0; |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1322 | release_object( owner ); |
| 1323 | } |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1324 | } |
Alexandre Julliard | 90b48e9 | 2005-05-13 14:00:19 +0000 | [diff] [blame] | 1325 | if (remove) |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 1326 | { |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1327 | update_input_key_state( input->desktop, input->keystate, msg ); |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1328 | list_remove( &msg->entry ); |
| 1329 | free_message( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1330 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Vincent Povirk | cc0ea69 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 1333 | static int queue_hotkey_message( struct desktop *desktop, struct message *msg ) |
| 1334 | { |
| 1335 | struct hotkey *hotkey; |
| 1336 | unsigned int modifiers = 0; |
| 1337 | |
| 1338 | if (msg->msg != WM_KEYDOWN) return 0; |
| 1339 | |
| 1340 | if (desktop->keystate[VK_MENU] & 0x80) modifiers |= MOD_ALT; |
| 1341 | if (desktop->keystate[VK_CONTROL] & 0x80) modifiers |= MOD_CONTROL; |
| 1342 | if (desktop->keystate[VK_SHIFT] & 0x80) modifiers |= MOD_SHIFT; |
| 1343 | if ((desktop->keystate[VK_LWIN] & 0x80) || (desktop->keystate[VK_RWIN] & 0x80)) modifiers |= MOD_WIN; |
| 1344 | |
| 1345 | LIST_FOR_EACH_ENTRY( hotkey, &desktop->hotkeys, struct hotkey, entry ) |
| 1346 | { |
| 1347 | if (hotkey->vkey != msg->wparam) continue; |
| 1348 | if ((hotkey->flags & (MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN)) == modifiers) goto found; |
| 1349 | } |
| 1350 | |
| 1351 | return 0; |
| 1352 | |
| 1353 | found: |
| 1354 | msg->type = MSG_POSTED; |
| 1355 | msg->win = hotkey->win; |
| 1356 | msg->msg = WM_HOTKEY; |
| 1357 | msg->wparam = hotkey->id; |
| 1358 | msg->lparam = ((hotkey->vkey & 0xffff) << 16) | modifiers; |
| 1359 | |
| 1360 | free( msg->data ); |
| 1361 | msg->data = NULL; |
| 1362 | msg->data_size = 0; |
| 1363 | |
| 1364 | list_add_tail( &hotkey->queue->msg_list[POST_MESSAGE], &msg->entry ); |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 1365 | set_queue_bits( hotkey->queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE|QS_HOTKEY ); |
| 1366 | hotkey->queue->hotkey_count++; |
Vincent Povirk | cc0ea69 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 1367 | return 1; |
| 1368 | } |
| 1369 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1370 | /* find the window that should receive a given hardware message */ |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 1371 | static user_handle_t find_hardware_message_window( struct desktop *desktop, struct thread_input *input, |
| 1372 | struct message *msg, unsigned int *msg_code ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1373 | { |
Alexandre Julliard | 183c41b | 2011-02-24 17:47:59 +0100 | [diff] [blame] | 1374 | struct hardware_msg_data *data = msg->data; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1375 | user_handle_t win = 0; |
| 1376 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1377 | *msg_code = msg->msg; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1378 | if (is_keyboard_msg( msg )) |
| 1379 | { |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1380 | if (input && !(win = input->focus)) |
| 1381 | { |
| 1382 | win = input->active; |
| 1383 | if (*msg_code < WM_SYSKEYDOWN) *msg_code += WM_SYSKEYDOWN - WM_KEYDOWN; |
| 1384 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1385 | } |
| 1386 | else /* mouse message */ |
| 1387 | { |
| 1388 | if (!input || !(win = input->capture)) |
| 1389 | { |
Dmitry Timoshkov | 66e981e | 2010-06-11 19:20:41 +0900 | [diff] [blame] | 1390 | if (!(win = msg->win) || !is_window_visible( win ) || is_window_transparent( win )) |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 1391 | win = window_from_point( desktop, data->x, data->y ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | return win; |
| 1395 | } |
| 1396 | |
| 1397 | /* queue a hardware message into a given thread input */ |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1398 | static void queue_hardware_message( struct desktop *desktop, struct message *msg, int always_queue ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1399 | { |
| 1400 | user_handle_t win; |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1401 | struct thread *thread; |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 1402 | struct thread_input *input; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1403 | unsigned int msg_code; |
Alexandre Julliard | 183c41b | 2011-02-24 17:47:59 +0100 | [diff] [blame] | 1404 | struct hardware_msg_data *data = msg->data; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1405 | |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1406 | update_input_key_state( desktop, desktop->keystate, msg ); |
Mike McCormack | abe70f7 | 2005-04-28 12:04:14 +0000 | [diff] [blame] | 1407 | last_input_time = get_tick_count(); |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1408 | if (msg->msg != WM_MOUSEMOVE) always_queue = 1; |
Alexandre Julliard | b9e4b5a | 2011-02-28 21:37:09 +0100 | [diff] [blame] | 1409 | |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1410 | if (is_keyboard_msg( msg )) |
| 1411 | { |
Vincent Povirk | cc0ea69 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 1412 | if (queue_hotkey_message( desktop, msg )) return; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1413 | if (desktop->keystate[VK_MENU] & 0x80) msg->lparam |= KF_ALTDOWN << 16; |
| 1414 | if (msg->wparam == VK_SHIFT || msg->wparam == VK_LSHIFT || msg->wparam == VK_RSHIFT) |
| 1415 | msg->lparam &= ~(KF_EXTENDED << 16); |
| 1416 | } |
| 1417 | else |
Alexandre Julliard | b9e4b5a | 2011-02-28 21:37:09 +0100 | [diff] [blame] | 1418 | { |
Alexandre Julliard | 39bac05 | 2011-04-06 20:29:38 +0200 | [diff] [blame] | 1419 | if (msg->msg == WM_MOUSEMOVE) |
| 1420 | { |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1421 | int x = min( max( data->x, desktop->cursor.clip.left ), desktop->cursor.clip.right-1 ); |
| 1422 | int y = min( max( data->y, desktop->cursor.clip.top ), desktop->cursor.clip.bottom-1 ); |
| 1423 | if (desktop->cursor.x != x || desktop->cursor.y != y) always_queue = 1; |
| 1424 | desktop->cursor.x = x; |
| 1425 | desktop->cursor.y = y; |
Alexandre Julliard | 39bac05 | 2011-04-06 20:29:38 +0200 | [diff] [blame] | 1426 | desktop->cursor.last_change = get_tick_count(); |
| 1427 | } |
Alexandre Julliard | b9e4b5a | 2011-02-28 21:37:09 +0100 | [diff] [blame] | 1428 | if (desktop->keystate[VK_LBUTTON] & 0x80) msg->wparam |= MK_LBUTTON; |
| 1429 | if (desktop->keystate[VK_MBUTTON] & 0x80) msg->wparam |= MK_MBUTTON; |
| 1430 | if (desktop->keystate[VK_RBUTTON] & 0x80) msg->wparam |= MK_RBUTTON; |
| 1431 | if (desktop->keystate[VK_SHIFT] & 0x80) msg->wparam |= MK_SHIFT; |
| 1432 | if (desktop->keystate[VK_CONTROL] & 0x80) msg->wparam |= MK_CONTROL; |
| 1433 | if (desktop->keystate[VK_XBUTTON1] & 0x80) msg->wparam |= MK_XBUTTON1; |
| 1434 | if (desktop->keystate[VK_XBUTTON2] & 0x80) msg->wparam |= MK_XBUTTON2; |
| 1435 | } |
Alexandre Julliard | c64c36f | 2011-03-31 19:54:22 +0200 | [diff] [blame] | 1436 | data->x = desktop->cursor.x; |
| 1437 | data->y = desktop->cursor.y; |
Alexandre Julliard | b9e4b5a | 2011-02-28 21:37:09 +0100 | [diff] [blame] | 1438 | |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 1439 | if (msg->win && (thread = get_window_thread( msg->win ))) |
| 1440 | { |
| 1441 | input = thread->queue->input; |
| 1442 | release_object( thread ); |
| 1443 | } |
| 1444 | else input = desktop->foreground_input; |
| 1445 | |
| 1446 | win = find_hardware_message_window( desktop, input, msg, &msg_code ); |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1447 | if (!win || !(thread = get_window_thread(win))) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1448 | { |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1449 | if (input) update_input_key_state( input->desktop, input->keystate, msg ); |
Alexandre Julliard | 9c8bbcd | 2011-04-06 20:00:40 +0200 | [diff] [blame] | 1450 | free_message( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1451 | return; |
| 1452 | } |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1453 | input = thread->queue->input; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1454 | |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1455 | if (win != desktop->cursor.win) always_queue = 1; |
| 1456 | desktop->cursor.win = win; |
| 1457 | |
| 1458 | if (!always_queue || merge_message( input, msg )) free_message( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1459 | else |
| 1460 | { |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1461 | 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] | 1462 | list_add_tail( &input->msg_list, &msg->entry ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1463 | set_queue_bits( thread->queue, get_hardware_msg_bit(msg) ); |
| 1464 | } |
Alexandre Julliard | e3fe689 | 2005-03-17 20:51:53 +0000 | [diff] [blame] | 1465 | release_object( thread ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1468 | /* send the low-level hook message for a given hardware message */ |
| 1469 | static int send_hook_ll_message( struct desktop *desktop, struct message *hardware_msg, |
| 1470 | const hw_input_t *input, struct msg_queue *sender ) |
| 1471 | { |
| 1472 | struct thread *hook_thread; |
| 1473 | struct msg_queue *queue; |
| 1474 | struct message *msg; |
| 1475 | timeout_t timeout = 2000 * -10000; /* FIXME: load from registry */ |
| 1476 | int id = (input->type == INPUT_MOUSE) ? WH_MOUSE_LL : WH_KEYBOARD_LL; |
| 1477 | |
| 1478 | if (!(hook_thread = get_first_global_hook( id ))) return 0; |
| 1479 | if (!(queue = hook_thread->queue)) return 0; |
Alexandre Julliard | f6b0ce3 | 2011-06-17 11:54:43 +0200 | [diff] [blame] | 1480 | if (is_queue_hung( queue )) return 0; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1481 | |
| 1482 | if (!(msg = mem_alloc( sizeof(*msg) ))) return 0; |
| 1483 | |
| 1484 | msg->type = MSG_HOOK_LL; |
| 1485 | msg->win = 0; |
| 1486 | msg->msg = id; |
| 1487 | msg->wparam = hardware_msg->msg; |
| 1488 | msg->time = hardware_msg->time; |
| 1489 | msg->data_size = hardware_msg->data_size; |
| 1490 | msg->result = NULL; |
| 1491 | |
| 1492 | if (input->type == INPUT_KEYBOARD) |
| 1493 | { |
| 1494 | unsigned short vkey = input->kbd.vkey; |
| 1495 | if (input->kbd.flags & KEYEVENTF_UNICODE) vkey = VK_PACKET; |
| 1496 | msg->lparam = (input->kbd.scan << 16) | vkey; |
| 1497 | } |
Alexandre Julliard | 34efca0 | 2011-03-07 11:07:35 +0100 | [diff] [blame] | 1498 | else msg->lparam = input->mouse.data << 16; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1499 | |
| 1500 | if (!(msg->data = memdup( hardware_msg->data, hardware_msg->data_size )) || |
| 1501 | !(msg->result = alloc_message_result( sender, queue, msg, timeout ))) |
| 1502 | { |
| 1503 | free_message( msg ); |
| 1504 | return 0; |
| 1505 | } |
| 1506 | msg->result->hardware_msg = hardware_msg; |
| 1507 | msg->result->desktop = (struct desktop *)grab_object( desktop ); |
| 1508 | list_add_tail( &queue->msg_list[SEND_MESSAGE], &msg->entry ); |
| 1509 | set_queue_bits( queue, QS_SENDMESSAGE ); |
| 1510 | return 1; |
| 1511 | } |
| 1512 | |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1513 | /* queue a hardware message for a mouse event */ |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1514 | static int queue_mouse_message( struct desktop *desktop, user_handle_t win, const hw_input_t *input, |
| 1515 | unsigned int hook_flags, struct msg_queue *sender ) |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1516 | { |
| 1517 | struct hardware_msg_data *msg_data; |
| 1518 | struct message *msg; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1519 | unsigned int i, time, flags; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1520 | int wait = 0, x, y; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1521 | |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1522 | static const unsigned int messages[] = |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1523 | { |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1524 | WM_MOUSEMOVE, /* 0x0001 = MOUSEEVENTF_MOVE */ |
| 1525 | WM_LBUTTONDOWN, /* 0x0002 = MOUSEEVENTF_LEFTDOWN */ |
| 1526 | WM_LBUTTONUP, /* 0x0004 = MOUSEEVENTF_LEFTUP */ |
| 1527 | WM_RBUTTONDOWN, /* 0x0008 = MOUSEEVENTF_RIGHTDOWN */ |
| 1528 | WM_RBUTTONUP, /* 0x0010 = MOUSEEVENTF_RIGHTUP */ |
| 1529 | WM_MBUTTONDOWN, /* 0x0020 = MOUSEEVENTF_MIDDLEDOWN */ |
| 1530 | WM_MBUTTONUP, /* 0x0040 = MOUSEEVENTF_MIDDLEUP */ |
| 1531 | WM_XBUTTONDOWN, /* 0x0080 = MOUSEEVENTF_XDOWN */ |
| 1532 | WM_XBUTTONUP, /* 0x0100 = MOUSEEVENTF_XUP */ |
| 1533 | 0, /* 0x0200 = unused */ |
| 1534 | 0, /* 0x0400 = unused */ |
| 1535 | WM_MOUSEWHEEL, /* 0x0800 = MOUSEEVENTF_WHEEL */ |
| 1536 | WM_MOUSEHWHEEL /* 0x1000 = MOUSEEVENTF_HWHEEL */ |
| 1537 | }; |
| 1538 | |
Alexandre Julliard | 6576703 | 2011-03-31 20:15:56 +0200 | [diff] [blame] | 1539 | desktop->cursor.last_change = get_tick_count(); |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1540 | flags = input->mouse.flags; |
| 1541 | time = input->mouse.time; |
Alexandre Julliard | 6576703 | 2011-03-31 20:15:56 +0200 | [diff] [blame] | 1542 | if (!time) time = desktop->cursor.last_change; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1543 | |
| 1544 | if (flags & MOUSEEVENTF_MOVE) |
| 1545 | { |
| 1546 | if (flags & MOUSEEVENTF_ABSOLUTE) |
| 1547 | { |
| 1548 | x = input->mouse.x; |
| 1549 | y = input->mouse.y; |
| 1550 | if (flags & ~(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE) && |
Alexandre Julliard | c64c36f | 2011-03-31 19:54:22 +0200 | [diff] [blame] | 1551 | x == desktop->cursor.x && y == desktop->cursor.y) |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1552 | flags &= ~MOUSEEVENTF_MOVE; |
| 1553 | } |
| 1554 | else |
| 1555 | { |
Alexandre Julliard | c64c36f | 2011-03-31 19:54:22 +0200 | [diff] [blame] | 1556 | x = desktop->cursor.x + input->mouse.x; |
| 1557 | y = desktop->cursor.y + input->mouse.y; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1558 | } |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1559 | } |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1560 | else |
| 1561 | { |
Alexandre Julliard | c64c36f | 2011-03-31 19:54:22 +0200 | [diff] [blame] | 1562 | x = desktop->cursor.x; |
| 1563 | y = desktop->cursor.y; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1564 | } |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1565 | |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1566 | for (i = 0; i < sizeof(messages)/sizeof(messages[0]); i++) |
| 1567 | { |
| 1568 | if (!messages[i]) continue; |
| 1569 | if (!(flags & (1 << i))) continue; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1570 | flags &= ~(1 << i); |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1571 | |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1572 | if (!(msg = mem_alloc( sizeof(*msg) ))) return 0; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1573 | if (!(msg_data = mem_alloc( sizeof(*msg_data) ))) |
| 1574 | { |
| 1575 | free( msg ); |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1576 | return 0; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1577 | } |
| 1578 | memset( msg_data, 0, sizeof(*msg_data) ); |
| 1579 | |
| 1580 | msg->type = MSG_HARDWARE; |
| 1581 | msg->win = get_user_full_handle( win ); |
| 1582 | msg->msg = messages[i]; |
| 1583 | msg->wparam = input->mouse.data << 16; |
| 1584 | msg->lparam = 0; |
| 1585 | msg->time = time; |
| 1586 | msg->result = NULL; |
| 1587 | msg->data = msg_data; |
| 1588 | msg->data_size = sizeof(*msg_data); |
| 1589 | msg_data->x = x; |
| 1590 | msg_data->y = y; |
| 1591 | msg_data->info = input->mouse.info; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1592 | if (hook_flags & SEND_HWMSG_INJECTED) msg_data->flags = LLMHF_INJECTED; |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1593 | |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1594 | /* specify a sender only when sending the last message */ |
| 1595 | if (!(flags & ((1 << sizeof(messages)/sizeof(messages[0])) - 1))) |
| 1596 | { |
| 1597 | if (!(wait = send_hook_ll_message( desktop, msg, input, sender ))) |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1598 | queue_hardware_message( desktop, msg, 0 ); |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1599 | } |
| 1600 | else if (!send_hook_ll_message( desktop, msg, input, NULL )) |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1601 | queue_hardware_message( desktop, msg, 0 ); |
Alexandre Julliard | 0f18d2b | 2011-03-02 11:59:38 +0100 | [diff] [blame] | 1602 | } |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1603 | return wait; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | /* queue a hardware message for a keyboard event */ |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1607 | static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, const hw_input_t *input, |
| 1608 | unsigned int hook_flags, struct msg_queue *sender ) |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1609 | { |
| 1610 | struct hardware_msg_data *msg_data; |
| 1611 | struct message *msg; |
| 1612 | unsigned char vkey = input->kbd.vkey; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1613 | int wait; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1614 | |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1615 | if (!(msg = mem_alloc( sizeof(*msg) ))) return 0; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1616 | if (!(msg_data = mem_alloc( sizeof(*msg_data) ))) |
| 1617 | { |
| 1618 | free( msg ); |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1619 | return 0; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1620 | } |
| 1621 | memset( msg_data, 0, sizeof(*msg_data) ); |
| 1622 | |
| 1623 | msg->type = MSG_HARDWARE; |
| 1624 | msg->win = get_user_full_handle( win ); |
Marcus Meissner | 67320c4 | 2011-06-28 09:37:04 +0200 | [diff] [blame] | 1625 | msg->lparam = (input->kbd.scan << 16) | 1u; /* repeat count */ |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1626 | msg->time = input->kbd.time; |
| 1627 | msg->result = NULL; |
| 1628 | msg->data = msg_data; |
| 1629 | msg->data_size = sizeof(*msg_data); |
| 1630 | msg_data->info = input->kbd.info; |
| 1631 | if (!msg->time) msg->time = get_tick_count(); |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1632 | if (hook_flags & SEND_HWMSG_INJECTED) msg_data->flags = LLKHF_INJECTED; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1633 | |
| 1634 | if (input->kbd.flags & KEYEVENTF_UNICODE) |
| 1635 | { |
| 1636 | msg->wparam = VK_PACKET; |
| 1637 | } |
| 1638 | else |
| 1639 | { |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1640 | unsigned int flags = 0; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1641 | switch (vkey) |
| 1642 | { |
| 1643 | case VK_MENU: |
| 1644 | case VK_LMENU: |
| 1645 | case VK_RMENU: |
| 1646 | vkey = (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) ? VK_RMENU : VK_LMENU; |
| 1647 | break; |
| 1648 | case VK_CONTROL: |
| 1649 | case VK_LCONTROL: |
| 1650 | case VK_RCONTROL: |
| 1651 | vkey = (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) ? VK_RCONTROL : VK_LCONTROL; |
| 1652 | break; |
| 1653 | case VK_SHIFT: |
| 1654 | case VK_LSHIFT: |
| 1655 | case VK_RSHIFT: |
| 1656 | vkey = (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) ? VK_RSHIFT : VK_LSHIFT; |
| 1657 | break; |
| 1658 | } |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1659 | if (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) flags |= KF_EXTENDED; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1660 | /* FIXME: set KF_DLGMODE and KF_MENUMODE when needed */ |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1661 | if (input->kbd.flags & KEYEVENTF_KEYUP) flags |= KF_REPEAT | KF_UP; |
| 1662 | else if (desktop->keystate[vkey] & 0x80) flags |= KF_REPEAT; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1663 | |
| 1664 | msg->wparam = vkey; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1665 | msg->lparam |= flags << 16; |
| 1666 | msg_data->flags |= (flags & (KF_EXTENDED | KF_ALTDOWN | KF_UP)) >> 8; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
Alexandre Julliard | 9731d44 | 2011-03-02 11:34:59 +0100 | [diff] [blame] | 1669 | msg->msg = (input->kbd.flags & KEYEVENTF_KEYUP) ? WM_KEYUP : WM_KEYDOWN; |
| 1670 | |
| 1671 | switch (vkey) |
| 1672 | { |
| 1673 | case VK_LMENU: |
| 1674 | case VK_RMENU: |
| 1675 | if (input->kbd.flags & KEYEVENTF_KEYUP) |
| 1676 | { |
| 1677 | /* send WM_SYSKEYUP if Alt still pressed and no other key in between */ |
| 1678 | /* we use 0x02 as a flag to track if some other SYSKEYUP was sent already */ |
| 1679 | if ((desktop->keystate[VK_MENU] & 0x82) != 0x82) break; |
| 1680 | msg->msg = WM_SYSKEYUP; |
| 1681 | desktop->keystate[VK_MENU] &= ~0x02; |
| 1682 | } |
| 1683 | else |
| 1684 | { |
| 1685 | /* send WM_SYSKEYDOWN for Alt except with Ctrl */ |
| 1686 | if (desktop->keystate[VK_CONTROL] & 0x80) break; |
| 1687 | msg->msg = WM_SYSKEYDOWN; |
| 1688 | desktop->keystate[VK_MENU] |= 0x02; |
| 1689 | } |
| 1690 | break; |
| 1691 | |
| 1692 | case VK_LCONTROL: |
| 1693 | case VK_RCONTROL: |
| 1694 | /* send WM_SYSKEYUP on release if Alt still pressed */ |
| 1695 | if (!(input->kbd.flags & KEYEVENTF_KEYUP)) break; |
| 1696 | if (!(desktop->keystate[VK_MENU] & 0x80)) break; |
| 1697 | msg->msg = WM_SYSKEYUP; |
| 1698 | desktop->keystate[VK_MENU] &= ~0x02; |
| 1699 | break; |
| 1700 | |
| 1701 | default: |
| 1702 | /* send WM_SYSKEY for Alt-anykey and for F10 */ |
| 1703 | if (desktop->keystate[VK_CONTROL] & 0x80) break; |
| 1704 | if (!(desktop->keystate[VK_MENU] & 0x80)) break; |
| 1705 | /* fall through */ |
| 1706 | case VK_F10: |
| 1707 | msg->msg = (input->kbd.flags & KEYEVENTF_KEYUP) ? WM_SYSKEYUP : WM_SYSKEYDOWN; |
| 1708 | desktop->keystate[VK_MENU] &= ~0x02; |
| 1709 | break; |
| 1710 | } |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1711 | if (!(wait = send_hook_ll_message( desktop, msg, input, sender ))) |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1712 | queue_hardware_message( desktop, msg, 1 ); |
Alexandre Julliard | 9731d44 | 2011-03-02 11:34:59 +0100 | [diff] [blame] | 1713 | |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 1714 | return wait; |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /* queue a hardware message for a custom type of event */ |
| 1718 | static void queue_custom_hardware_message( struct desktop *desktop, user_handle_t win, |
| 1719 | const hw_input_t *input ) |
| 1720 | { |
| 1721 | struct hardware_msg_data *msg_data; |
| 1722 | struct message *msg; |
| 1723 | |
| 1724 | if (!(msg = mem_alloc( sizeof(*msg) ))) return; |
| 1725 | if (!(msg_data = mem_alloc( sizeof(*msg_data) ))) |
| 1726 | { |
| 1727 | free( msg ); |
| 1728 | return; |
| 1729 | } |
| 1730 | memset( msg_data, 0, sizeof(*msg_data) ); |
| 1731 | |
| 1732 | msg->type = MSG_HARDWARE; |
| 1733 | msg->win = get_user_full_handle( win ); |
| 1734 | msg->msg = input->hw.msg; |
| 1735 | msg->wparam = 0; |
| 1736 | msg->lparam = input->hw.lparam; |
| 1737 | msg->time = get_tick_count(); |
| 1738 | msg->result = NULL; |
| 1739 | msg->data = msg_data; |
| 1740 | msg->data_size = sizeof(*msg_data); |
| 1741 | |
Alexandre Julliard | 3909f51 | 2011-04-06 21:07:04 +0200 | [diff] [blame] | 1742 | queue_hardware_message( desktop, msg, 1 ); |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 1743 | } |
| 1744 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1745 | /* check message filter for a hardware message */ |
| 1746 | static int check_hw_message_filter( user_handle_t win, unsigned int msg_code, |
| 1747 | user_handle_t filter_win, unsigned int first, unsigned int last ) |
| 1748 | { |
| 1749 | if (msg_code >= WM_KEYFIRST && msg_code <= WM_KEYLAST) |
| 1750 | { |
| 1751 | /* we can only test the window for a keyboard message since the |
| 1752 | * dest window for a mouse message depends on hittest */ |
| 1753 | if (filter_win && win != filter_win && !is_child_window( filter_win, win )) |
| 1754 | return 0; |
| 1755 | /* the message code is final for a keyboard message, we can simply check it */ |
| 1756 | return check_msg_filter( msg_code, first, last ); |
| 1757 | } |
| 1758 | else /* mouse message */ |
| 1759 | { |
| 1760 | /* we need to check all possible values that the message can have in the end */ |
| 1761 | |
| 1762 | if (check_msg_filter( msg_code, first, last )) return 1; |
| 1763 | if (msg_code == WM_MOUSEWHEEL) return 0; /* no other possible value for this one */ |
| 1764 | |
| 1765 | /* all other messages can become non-client messages */ |
| 1766 | if (check_msg_filter( msg_code + (WM_NCMOUSEFIRST - WM_MOUSEFIRST), first, last )) return 1; |
| 1767 | |
| 1768 | /* clicks can become double-clicks or non-client double-clicks */ |
| 1769 | if (msg_code == WM_LBUTTONDOWN || msg_code == WM_MBUTTONDOWN || |
| 1770 | msg_code == WM_RBUTTONDOWN || msg_code == WM_XBUTTONDOWN) |
| 1771 | { |
| 1772 | if (check_msg_filter( msg_code + (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN), first, last )) return 1; |
| 1773 | if (check_msg_filter( msg_code + (WM_NCLBUTTONDBLCLK - WM_LBUTTONDOWN), first, last )) return 1; |
| 1774 | } |
| 1775 | return 0; |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1780 | /* find a hardware message for the given queue */ |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 1781 | 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] | 1782 | unsigned int first, unsigned int last, struct get_message_reply *reply ) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1783 | { |
| 1784 | struct thread_input *input = thread->queue->input; |
| 1785 | struct thread *win_thread; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1786 | struct list *ptr; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1787 | user_handle_t win; |
| 1788 | int clear_bits, got_one = 0; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1789 | unsigned int msg_code; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1790 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1791 | ptr = list_head( &input->msg_list ); |
| 1792 | if (hw_id) |
| 1793 | { |
| 1794 | while (ptr) |
| 1795 | { |
| 1796 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
| 1797 | if (msg->unique_id == hw_id) break; |
| 1798 | ptr = list_next( &input->msg_list, ptr ); |
| 1799 | } |
| 1800 | if (!ptr) ptr = list_head( &input->msg_list ); |
| 1801 | else ptr = list_next( &input->msg_list, ptr ); /* start from the next one */ |
| 1802 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1803 | |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1804 | if (ptr == list_head( &input->msg_list )) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1805 | clear_bits = QS_KEY | QS_MOUSEMOVE | QS_MOUSEBUTTON; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1806 | else |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1807 | 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] | 1808 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1809 | while (ptr) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1810 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1811 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1812 | struct hardware_msg_data *data = msg->data; |
| 1813 | |
Alexandre Julliard | 55d449e | 2005-05-14 11:08:05 +0000 | [diff] [blame] | 1814 | ptr = list_next( &input->msg_list, ptr ); |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 1815 | win = find_hardware_message_window( input->desktop, input, msg, &msg_code ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1816 | if (!win || !(win_thread = get_window_thread( win ))) |
| 1817 | { |
| 1818 | /* no window at all, remove it */ |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1819 | update_input_key_state( input->desktop, input->keystate, msg ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1820 | list_remove( &msg->entry ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1821 | free_message( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1822 | continue; |
| 1823 | } |
| 1824 | if (win_thread != thread) |
| 1825 | { |
Alexandre Julliard | 55d449e | 2005-05-14 11:08:05 +0000 | [diff] [blame] | 1826 | if (win_thread->queue->input == input) |
| 1827 | { |
| 1828 | /* wake the other thread */ |
| 1829 | set_queue_bits( win_thread->queue, get_hardware_msg_bit(msg) ); |
| 1830 | got_one = 1; |
| 1831 | } |
| 1832 | else |
| 1833 | { |
| 1834 | /* for another thread input, drop it */ |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 1835 | update_input_key_state( input->desktop, input->keystate, msg ); |
Alexandre Julliard | 55d449e | 2005-05-14 11:08:05 +0000 | [diff] [blame] | 1836 | list_remove( &msg->entry ); |
| 1837 | free_message( msg ); |
| 1838 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1839 | release_object( win_thread ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1840 | continue; |
| 1841 | } |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1842 | release_object( win_thread ); |
| 1843 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1844 | /* 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] | 1845 | * match the filter we skip it */ |
| 1846 | 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] | 1847 | { |
| 1848 | clear_bits &= ~get_hardware_msg_bit( msg ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1849 | continue; |
| 1850 | } |
| 1851 | /* now we can return it */ |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 1852 | if (!msg->unique_id) msg->unique_id = get_unique_id(); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1853 | reply->type = MSG_HARDWARE; |
| 1854 | reply->win = win; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 1855 | reply->msg = msg_code; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1856 | reply->wparam = msg->wparam; |
| 1857 | reply->lparam = msg->lparam; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1858 | reply->time = msg->time; |
Alexandre Julliard | d1d7b9f | 2008-12-24 11:59:09 +0100 | [diff] [blame] | 1859 | |
| 1860 | data->hw_id = msg->unique_id; |
| 1861 | set_reply_data( msg->data, msg->data_size ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1862 | return 1; |
| 1863 | } |
| 1864 | /* nothing found, clear the hardware queue bits */ |
| 1865 | clear_queue_bits( thread->queue, clear_bits ); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 1866 | return 0; |
| 1867 | } |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 1868 | |
| 1869 | /* increment (or decrement if 'incr' is negative) the queue paint count */ |
| 1870 | void inc_queue_paint_count( struct thread *thread, int incr ) |
| 1871 | { |
| 1872 | struct msg_queue *queue = thread->queue; |
| 1873 | |
| 1874 | assert( queue ); |
| 1875 | |
| 1876 | if ((queue->paint_count += incr) < 0) queue->paint_count = 0; |
| 1877 | |
| 1878 | if (queue->paint_count) |
| 1879 | set_queue_bits( queue, QS_PAINT ); |
| 1880 | else |
| 1881 | clear_queue_bits( queue, QS_PAINT ); |
| 1882 | } |
| 1883 | |
| 1884 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1885 | /* remove all messages and timers belonging to a certain window */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1886 | void queue_cleanup_window( struct thread *thread, user_handle_t win ) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1887 | { |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1888 | struct msg_queue *queue = thread->queue; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1889 | struct list *ptr; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1890 | int i; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1891 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1892 | if (!queue) return; |
| 1893 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1894 | /* remove timers */ |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1895 | |
| 1896 | ptr = list_head( &queue->pending_timers ); |
| 1897 | while (ptr) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1898 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 1899 | struct list *next = list_next( &queue->pending_timers, ptr ); |
| 1900 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1901 | if (timer->win == win) free_timer( queue, timer ); |
| 1902 | ptr = next; |
| 1903 | } |
| 1904 | ptr = list_head( &queue->expired_timers ); |
| 1905 | while (ptr) |
| 1906 | { |
| 1907 | struct list *next = list_next( &queue->expired_timers, ptr ); |
| 1908 | struct timer *timer = LIST_ENTRY( ptr, struct timer, entry ); |
| 1909 | if (timer->win == win) free_timer( queue, timer ); |
| 1910 | ptr = next; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1913 | /* remove messages */ |
| 1914 | for (i = 0; i < NB_MSG_KINDS; i++) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1915 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1916 | struct list *ptr, *next; |
| 1917 | |
| 1918 | LIST_FOR_EACH_SAFE( ptr, next, &queue->msg_list[i] ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1919 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1920 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
Francois Gouget | ff8f6e8 | 2011-08-05 20:29:52 +0200 | [diff] [blame] | 1921 | if (msg->win == win) |
| 1922 | { |
| 1923 | if (msg->msg == WM_QUIT && !queue->quit_message) |
| 1924 | { |
| 1925 | queue->quit_message = 1; |
| 1926 | queue->exit_code = msg->wparam; |
| 1927 | } |
| 1928 | remove_queue_message( queue, msg, i ); |
| 1929 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 1930 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1931 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 1932 | |
| 1933 | thread_input_cleanup_window( queue, win ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1936 | /* post a message to a window; used by socket handling */ |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 1937 | 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] | 1938 | { |
| 1939 | struct message *msg; |
| 1940 | struct thread *thread = get_window_thread( win ); |
| 1941 | |
| 1942 | if (!thread) return; |
| 1943 | |
| 1944 | if (thread->queue && (msg = mem_alloc( sizeof(*msg) ))) |
| 1945 | { |
| 1946 | msg->type = MSG_POSTED; |
| 1947 | msg->win = get_user_full_handle( win ); |
| 1948 | msg->msg = message; |
| 1949 | msg->wparam = wparam; |
| 1950 | msg->lparam = lparam; |
| 1951 | msg->time = get_tick_count(); |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1952 | msg->result = NULL; |
| 1953 | msg->data = NULL; |
| 1954 | msg->data_size = 0; |
| 1955 | |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 1956 | list_add_tail( &thread->queue->msg_list[POST_MESSAGE], &msg->entry ); |
Alexandre Julliard | 80b997a | 2005-11-14 15:17:09 +0000 | [diff] [blame] | 1957 | set_queue_bits( thread->queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 1958 | if (message == WM_HOTKEY) |
| 1959 | { |
| 1960 | set_queue_bits( thread->queue, QS_HOTKEY ); |
| 1961 | thread->queue->hotkey_count++; |
| 1962 | } |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 1963 | } |
| 1964 | release_object( thread ); |
| 1965 | } |
| 1966 | |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1967 | /* post a win event */ |
| 1968 | void post_win_event( struct thread *thread, unsigned int event, |
| 1969 | user_handle_t win, unsigned int object_id, |
Alexandre Julliard | cc55fd3 | 2008-12-29 17:35:35 +0100 | [diff] [blame] | 1970 | unsigned int child_id, client_ptr_t hook_proc, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1971 | const WCHAR *module, data_size_t module_size, |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1972 | user_handle_t hook) |
| 1973 | { |
| 1974 | struct message *msg; |
| 1975 | |
| 1976 | if (thread->queue && (msg = mem_alloc( sizeof(*msg) ))) |
| 1977 | { |
Alexandre Julliard | 59dc456 | 2006-10-04 16:04:53 +0200 | [diff] [blame] | 1978 | struct winevent_msg_data *data; |
| 1979 | |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1980 | msg->type = MSG_WINEVENT; |
| 1981 | msg->win = get_user_full_handle( win ); |
| 1982 | msg->msg = event; |
| 1983 | msg->wparam = object_id; |
| 1984 | msg->lparam = child_id; |
| 1985 | msg->time = get_tick_count(); |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1986 | msg->result = NULL; |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1987 | |
Alexandre Julliard | 59dc456 | 2006-10-04 16:04:53 +0200 | [diff] [blame] | 1988 | if ((data = malloc( sizeof(*data) + module_size ))) |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1989 | { |
Alexandre Julliard | 59dc456 | 2006-10-04 16:04:53 +0200 | [diff] [blame] | 1990 | data->hook = hook; |
| 1991 | data->tid = get_thread_id( current ); |
| 1992 | data->hook_proc = hook_proc; |
| 1993 | memcpy( data + 1, module, module_size ); |
| 1994 | |
| 1995 | msg->data = data; |
| 1996 | msg->data_size = sizeof(*data) + module_size; |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1997 | |
| 1998 | if (debug_level > 1) |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 1999 | 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] | 2000 | get_thread_id(thread), event, win, object_id, child_id ); |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 2001 | list_add_tail( &thread->queue->msg_list[SEND_MESSAGE], &msg->entry ); |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 2002 | set_queue_bits( thread->queue, QS_SENDMESSAGE ); |
| 2003 | } |
| 2004 | else |
| 2005 | free( msg ); |
| 2006 | } |
| 2007 | } |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 2008 | |
Vincent Povirk | 4c83138 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 2009 | /* free all hotkeys on a desktop, optionally filtering by window */ |
| 2010 | void free_hotkeys( struct desktop *desktop, user_handle_t window ) |
| 2011 | { |
| 2012 | struct hotkey *hotkey, *hotkey2; |
| 2013 | |
| 2014 | LIST_FOR_EACH_ENTRY_SAFE( hotkey, hotkey2, &desktop->hotkeys, struct hotkey, entry ) |
| 2015 | { |
| 2016 | if (!window || hotkey->win == window) |
| 2017 | { |
| 2018 | list_remove( &hotkey->entry ); |
| 2019 | free( hotkey ); |
| 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | |
Dmitry Timoshkov | e735e19 | 2007-12-28 10:59:13 +0800 | [diff] [blame] | 2024 | |
| 2025 | /* check if the thread owning the window is hung */ |
| 2026 | DECL_HANDLER(is_window_hung) |
| 2027 | { |
| 2028 | struct thread *thread; |
| 2029 | |
| 2030 | thread = get_window_thread( req->win ); |
| 2031 | if (thread) |
| 2032 | { |
| 2033 | reply->is_hung = is_queue_hung( thread->queue ); |
| 2034 | release_object( thread ); |
| 2035 | } |
| 2036 | else reply->is_hung = 0; |
| 2037 | } |
| 2038 | |
| 2039 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 2040 | /* get the message queue of the current thread */ |
| 2041 | DECL_HANDLER(get_msg_queue) |
| 2042 | { |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2043 | struct msg_queue *queue = get_current_queue(); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 2044 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2045 | reply->handle = 0; |
| 2046 | if (queue) reply->handle = alloc_handle( current->process, queue, SYNCHRONIZE, 0 ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2049 | |
Alexandre Julliard | 0cb29f4 | 2007-04-04 18:02:01 +0200 | [diff] [blame] | 2050 | /* set the file descriptor associated to the current thread queue */ |
| 2051 | DECL_HANDLER(set_queue_fd) |
| 2052 | { |
| 2053 | struct msg_queue *queue = get_current_queue(); |
| 2054 | struct file *file; |
| 2055 | int unix_fd; |
| 2056 | |
| 2057 | if (queue->fd) /* fd can only be set once */ |
| 2058 | { |
| 2059 | set_error( STATUS_ACCESS_DENIED ); |
| 2060 | return; |
| 2061 | } |
| 2062 | if (!(file = get_file_obj( current->process, req->handle, SYNCHRONIZE ))) return; |
| 2063 | |
| 2064 | if ((unix_fd = get_file_unix_fd( file )) != -1) |
| 2065 | { |
| 2066 | if ((unix_fd = dup( unix_fd )) != -1) |
Alexandre Julliard | f85437c | 2007-04-10 22:25:07 +0200 | [diff] [blame] | 2067 | 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] | 2068 | else |
| 2069 | file_set_error(); |
| 2070 | } |
| 2071 | release_object( file ); |
| 2072 | } |
| 2073 | |
| 2074 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2075 | /* set the current message queue wakeup mask */ |
| 2076 | DECL_HANDLER(set_queue_mask) |
| 2077 | { |
| 2078 | struct msg_queue *queue = get_current_queue(); |
| 2079 | |
| 2080 | if (queue) |
| 2081 | { |
| 2082 | queue->wake_mask = req->wake_mask; |
| 2083 | queue->changed_mask = req->changed_mask; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2084 | reply->wake_bits = queue->wake_bits; |
| 2085 | reply->changed_bits = queue->changed_bits; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2086 | if (is_signaled( queue )) |
| 2087 | { |
| 2088 | /* if skip wait is set, do what would have been done in the subsequent wait */ |
| 2089 | if (req->skip_wait) msg_queue_satisfied( &queue->obj, current ); |
| 2090 | else wake_up( &queue->obj, 0 ); |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | |
| 2096 | /* get the current message queue status */ |
| 2097 | DECL_HANDLER(get_queue_status) |
| 2098 | { |
| 2099 | struct msg_queue *queue = current->queue; |
| 2100 | if (queue) |
| 2101 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2102 | reply->wake_bits = queue->wake_bits; |
| 2103 | reply->changed_bits = queue->changed_bits; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2104 | if (req->clear) queue->changed_bits = 0; |
| 2105 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2106 | else reply->wake_bits = reply->changed_bits = 0; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | /* send a message to a thread queue */ |
| 2111 | DECL_HANDLER(send_message) |
| 2112 | { |
| 2113 | struct message *msg; |
| 2114 | struct msg_queue *send_queue = get_current_queue(); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 2115 | struct msg_queue *recv_queue = NULL; |
| 2116 | struct thread *thread = NULL; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2117 | |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2118 | if (!(thread = get_thread_from_id( req->id ))) return; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2119 | |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2120 | if (!(recv_queue = thread->queue)) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2121 | { |
| 2122 | set_error( STATUS_INVALID_PARAMETER ); |
| 2123 | release_object( thread ); |
| 2124 | return; |
| 2125 | } |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2126 | 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] | 2127 | { |
| 2128 | set_error( STATUS_TIMEOUT ); |
| 2129 | release_object( thread ); |
| 2130 | return; |
| 2131 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2132 | |
| 2133 | if ((msg = mem_alloc( sizeof(*msg) ))) |
| 2134 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2135 | msg->type = req->type; |
Alexandre Julliard | bc878ef | 2001-09-12 17:09:24 +0000 | [diff] [blame] | 2136 | msg->win = get_user_full_handle( req->win ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2137 | msg->msg = req->msg; |
| 2138 | msg->wparam = req->wparam; |
| 2139 | msg->lparam = req->lparam; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2140 | msg->time = get_tick_count(); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2141 | msg->result = NULL; |
| 2142 | msg->data = NULL; |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 2143 | msg->data_size = get_req_data_size(); |
| 2144 | |
| 2145 | if (msg->data_size && !(msg->data = memdup( get_req_data(), msg->data_size ))) |
| 2146 | { |
| 2147 | free( msg ); |
| 2148 | release_object( thread ); |
| 2149 | return; |
| 2150 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2151 | |
| 2152 | switch(msg->type) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2153 | { |
Eric Pouech | 0faceb0 | 2002-01-18 19:22:55 +0000 | [diff] [blame] | 2154 | case MSG_OTHER_PROCESS: |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2155 | case MSG_ASCII: |
| 2156 | case MSG_UNICODE: |
| 2157 | case MSG_CALLBACK: |
Alexandre Julliard | 3ad9798 | 2006-10-04 20:25:42 +0200 | [diff] [blame] | 2158 | 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] | 2159 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 2160 | free_message( msg ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2161 | break; |
Alexandre Julliard | e630aa0 | 2001-07-11 17:29:01 +0000 | [diff] [blame] | 2162 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2163 | /* fall through */ |
| 2164 | case MSG_NOTIFY: |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 2165 | list_add_tail( &recv_queue->msg_list[SEND_MESSAGE], &msg->entry ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2166 | set_queue_bits( recv_queue, QS_SENDMESSAGE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2167 | break; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2168 | case MSG_POSTED: |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 2169 | list_add_tail( &recv_queue->msg_list[POST_MESSAGE], &msg->entry ); |
Alexandre Julliard | 80b997a | 2005-11-14 15:17:09 +0000 | [diff] [blame] | 2170 | set_queue_bits( recv_queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 2171 | if (msg->msg == WM_HOTKEY) |
| 2172 | { |
| 2173 | set_queue_bits( recv_queue, QS_HOTKEY ); |
| 2174 | recv_queue->hotkey_count++; |
| 2175 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2176 | break; |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2177 | case MSG_HARDWARE: /* should use send_hardware_message instead */ |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 2178 | case MSG_CALLBACK_RESULT: /* cannot send this one */ |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 2179 | case MSG_HOOK_LL: /* generated internally */ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2180 | default: |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2181 | set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2182 | free( msg ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2183 | break; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2184 | } |
| 2185 | } |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2186 | release_object( thread ); |
| 2187 | } |
| 2188 | |
| 2189 | /* send a hardware message to a thread queue */ |
| 2190 | DECL_HANDLER(send_hardware_message) |
| 2191 | { |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2192 | struct thread *thread = NULL; |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 2193 | struct desktop *desktop; |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 2194 | struct msg_queue *sender = get_current_queue(); |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2195 | |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 2196 | if (req->win) |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2197 | { |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 2198 | if (!(thread = get_window_thread( req->win ))) return; |
| 2199 | desktop = (struct desktop *)grab_object( thread->queue->input->desktop ); |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2200 | } |
Alexandre Julliard | bc4afb0 | 2011-03-01 11:54:55 +0100 | [diff] [blame] | 2201 | else if (!(desktop = get_thread_desktop( current, 0 ))) return; |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2202 | |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 2203 | switch (req->input.type) |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2204 | { |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 2205 | case INPUT_MOUSE: |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 2206 | reply->wait = queue_mouse_message( desktop, req->win, &req->input, req->flags, sender ); |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 2207 | break; |
| 2208 | case INPUT_KEYBOARD: |
Alexandre Julliard | c7efa29 | 2011-03-02 19:53:03 +0100 | [diff] [blame] | 2209 | reply->wait = queue_keyboard_message( desktop, req->win, &req->input, req->flags, sender ); |
Alexandre Julliard | 02e30f5 | 2011-03-01 20:33:15 +0100 | [diff] [blame] | 2210 | break; |
| 2211 | case INPUT_HARDWARE: |
| 2212 | queue_custom_hardware_message( desktop, req->win, &req->input ); |
| 2213 | break; |
| 2214 | default: |
| 2215 | set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | d3b3096 | 2006-08-09 16:45:26 +0200 | [diff] [blame] | 2216 | } |
Alexandre Julliard | 5ee89aa | 2010-05-12 13:48:00 +0200 | [diff] [blame] | 2217 | if (thread) release_object( thread ); |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2218 | release_object( desktop ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 2221 | /* post a quit message to the current queue */ |
| 2222 | DECL_HANDLER(post_quit_message) |
| 2223 | { |
| 2224 | struct msg_queue *queue = get_current_queue(); |
| 2225 | |
| 2226 | if (!queue) |
| 2227 | return; |
| 2228 | |
| 2229 | queue->quit_message = 1; |
| 2230 | queue->exit_code = req->exit_code; |
| 2231 | set_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE ); |
| 2232 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2233 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2234 | /* get a message from the current queue */ |
| 2235 | DECL_HANDLER(get_message) |
| 2236 | { |
| 2237 | struct timer *timer; |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 2238 | struct list *ptr; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2239 | struct msg_queue *queue = get_current_queue(); |
Alexandre Julliard | bc878ef | 2001-09-12 17:09:24 +0000 | [diff] [blame] | 2240 | user_handle_t get_win = get_user_full_handle( req->get_win ); |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 2241 | unsigned int filter = req->flags >> 16; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2242 | |
Alexandre Julliard | 6334235 | 2005-05-11 13:03:15 +0000 | [diff] [blame] | 2243 | reply->active_hooks = get_active_hooks(); |
| 2244 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2245 | if (!queue) return; |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 2246 | queue->last_get_msg = current_time; |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 2247 | if (!filter) filter = QS_ALLINPUT; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2248 | |
| 2249 | /* first check for sent messages */ |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 2250 | if ((ptr = list_head( &queue->msg_list[SEND_MESSAGE] ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2251 | { |
Alexandre Julliard | 8e3b072 | 2005-02-25 21:05:11 +0000 | [diff] [blame] | 2252 | struct message *msg = LIST_ENTRY( ptr, struct message, entry ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2253 | receive_message( queue, msg, reply ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2254 | return; |
| 2255 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2256 | |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 2257 | /* 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] | 2258 | if (filter & QS_POSTMESSAGE) |
| 2259 | { |
| 2260 | queue->changed_bits &= ~(QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER); |
| 2261 | if (req->get_first == 0 && req->get_last == ~0U) queue->changed_bits &= ~QS_ALLPOSTMESSAGE; |
| 2262 | } |
| 2263 | if (filter & QS_INPUT) queue->changed_bits &= ~QS_INPUT; |
| 2264 | if (filter & QS_PAINT) queue->changed_bits &= ~QS_PAINT; |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 2265 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2266 | /* then check for posted messages */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 2267 | if ((filter & QS_POSTMESSAGE) && |
| 2268 | 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] | 2269 | return; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2270 | |
Vincent Povirk | 79556ae | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 2271 | if ((filter & QS_HOTKEY) && queue->hotkey_count && |
| 2272 | req->get_first <= WM_HOTKEY && req->get_last >= WM_HOTKEY && |
| 2273 | get_posted_message( queue, get_win, WM_HOTKEY, WM_HOTKEY, req->flags, reply )) |
| 2274 | return; |
| 2275 | |
Robert Shearman | a40ce39 | 2006-01-17 13:14:31 +0100 | [diff] [blame] | 2276 | /* only check for quit messages if not posted messages pending. |
| 2277 | * note: the quit message isn't filtered */ |
| 2278 | if (get_quit_message( queue, req->flags, reply )) |
| 2279 | return; |
| 2280 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 2281 | /* then check for any raw hardware message */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 2282 | if ((filter & QS_INPUT) && |
| 2283 | filter_contains_hw_range( req->get_first, req->get_last ) && |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 2284 | 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] | 2285 | return; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2286 | |
| 2287 | /* now check for WM_PAINT */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 2288 | if ((filter & QS_PAINT) && |
| 2289 | queue->paint_count && |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 2290 | check_msg_filter( WM_PAINT, req->get_first, req->get_last ) && |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2291 | (reply->win = find_window_to_repaint( get_win, current ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2292 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2293 | reply->type = MSG_POSTED; |
| 2294 | reply->msg = WM_PAINT; |
| 2295 | reply->wparam = 0; |
| 2296 | reply->lparam = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2297 | reply->time = get_tick_count(); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2298 | return; |
| 2299 | } |
| 2300 | |
| 2301 | /* now check for timer */ |
Alexandre Julliard | 89faee0 | 2007-02-21 15:21:05 +0100 | [diff] [blame] | 2302 | if ((filter & QS_TIMER) && |
| 2303 | (timer = find_expired_timer( queue, get_win, req->get_first, |
| 2304 | req->get_last, (req->flags & PM_REMOVE) ))) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2305 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2306 | reply->type = MSG_POSTED; |
| 2307 | reply->win = timer->win; |
| 2308 | reply->msg = timer->msg; |
| 2309 | reply->wparam = timer->id; |
| 2310 | reply->lparam = timer->lparam; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2311 | reply->time = get_tick_count(); |
Alexandre Julliard | 7265e89 | 2009-12-16 18:18:07 +0100 | [diff] [blame] | 2312 | if (!(req->flags & PM_NOYIELD) && current->process->idle_event) |
| 2313 | set_event( current->process->idle_event ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2314 | return; |
| 2315 | } |
| 2316 | |
Alexandre Julliard | b0760fc | 2010-03-03 13:19:13 +0100 | [diff] [blame] | 2317 | if (get_win == -1 && current->process->idle_event) set_event( current->process->idle_event ); |
Alexandre Julliard | 2896540 | 2007-08-29 18:13:13 +0200 | [diff] [blame] | 2318 | queue->wake_mask = req->wake_mask; |
| 2319 | queue->changed_mask = req->changed_mask; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2320 | set_error( STATUS_PENDING ); /* FIXME */ |
| 2321 | } |
| 2322 | |
| 2323 | |
| 2324 | /* reply to a sent message */ |
| 2325 | DECL_HANDLER(reply_message) |
| 2326 | { |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 2327 | if (!current->queue) set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | b1095da | 2003-03-19 00:12:17 +0000 | [diff] [blame] | 2328 | else if (current->queue->recv_result) |
| 2329 | reply_message( current->queue, req->result, 0, req->remove, |
| 2330 | get_req_data(), get_req_data_size() ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 2334 | /* accept the current hardware message */ |
| 2335 | DECL_HANDLER(accept_hardware_message) |
| 2336 | { |
| 2337 | if (current->queue) |
Alexandre Julliard | 3e2f2a5 | 2005-04-20 13:03:59 +0000 | [diff] [blame] | 2338 | release_hardware_message( current->queue, req->hw_id, req->remove, req->new_win ); |
| 2339 | else |
| 2340 | set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 0bc8377 | 2005-03-23 10:33:17 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2344 | /* retrieve the reply for the last message sent */ |
| 2345 | DECL_HANDLER(get_message_reply) |
| 2346 | { |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 2347 | struct message_result *result; |
| 2348 | struct list *entry; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2349 | struct msg_queue *queue = current->queue; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2350 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2351 | if (queue) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2352 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2353 | set_error( STATUS_PENDING ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2354 | reply->result = 0; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2355 | |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 2356 | if (!(entry = list_head( &queue->send_result ))) return; /* no reply ready */ |
| 2357 | |
| 2358 | result = LIST_ENTRY( entry, struct message_result, sender_entry ); |
| 2359 | if (result->replied || req->cancel) |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2360 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2361 | if (result->replied) |
| 2362 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2363 | reply->result = result->result; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2364 | set_error( result->error ); |
| 2365 | if (result->data) |
| 2366 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 2367 | 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] | 2368 | set_reply_data_ptr( result->data, data_len ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2369 | result->data = NULL; |
| 2370 | result->data_size = 0; |
| 2371 | } |
| 2372 | } |
Alexandre Julliard | 039e131 | 2003-07-26 20:36:43 +0000 | [diff] [blame] | 2373 | remove_result_from_sender( result ); |
| 2374 | |
| 2375 | entry = list_head( &queue->send_result ); |
| 2376 | if (!entry) clear_queue_bits( queue, QS_SMRESULT ); |
| 2377 | else |
| 2378 | { |
| 2379 | result = LIST_ENTRY( entry, struct message_result, sender_entry ); |
| 2380 | if (!result->replied) clear_queue_bits( queue, QS_SMRESULT ); |
| 2381 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2382 | } |
| 2383 | } |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 2384 | else set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2388 | /* set a window timer */ |
| 2389 | DECL_HANDLER(set_win_timer) |
| 2390 | { |
| 2391 | struct timer *timer; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2392 | struct msg_queue *queue; |
| 2393 | struct thread *thread = NULL; |
| 2394 | user_handle_t win = 0; |
Alexandre Julliard | 31282b3 | 2008-12-10 16:01:50 +0100 | [diff] [blame] | 2395 | lparam_t id = req->id; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2396 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2397 | if (req->win) |
| 2398 | { |
| 2399 | if (!(win = get_user_full_handle( req->win )) || !(thread = get_window_thread( win ))) |
| 2400 | { |
| 2401 | set_error( STATUS_INVALID_HANDLE ); |
| 2402 | return; |
| 2403 | } |
| 2404 | if (thread->process != current->process) |
| 2405 | { |
| 2406 | release_object( thread ); |
| 2407 | set_error( STATUS_ACCESS_DENIED ); |
| 2408 | return; |
| 2409 | } |
| 2410 | queue = thread->queue; |
| 2411 | /* remove it if it existed already */ |
| 2412 | if ((timer = find_timer( queue, win, req->msg, id ))) free_timer( queue, timer ); |
| 2413 | } |
| 2414 | else |
| 2415 | { |
| 2416 | queue = get_current_queue(); |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 2417 | /* look for a timer with this id */ |
Alexandre Julliard | d764107 | 2008-12-08 16:57:38 +0100 | [diff] [blame] | 2418 | if (id && (timer = find_timer( queue, 0, req->msg, id ))) |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2419 | { |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 2420 | /* free and reuse id */ |
| 2421 | free_timer( queue, timer ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2422 | } |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 2423 | else |
| 2424 | { |
| 2425 | /* find a free id for it */ |
| 2426 | do |
| 2427 | { |
| 2428 | id = queue->next_timer_id; |
Dmitry Timoshkov | b4227d7 | 2007-11-13 20:41:01 +0800 | [diff] [blame] | 2429 | if (--queue->next_timer_id <= 0x100) queue->next_timer_id = 0x7fff; |
Trent Waddington | fc635fa | 2007-08-30 19:05:50 +1000 | [diff] [blame] | 2430 | } |
| 2431 | while (find_timer( queue, 0, req->msg, id )); |
| 2432 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2433 | } |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2434 | |
| 2435 | if ((timer = set_timer( queue, req->rate ))) |
| 2436 | { |
Alexandre Julliard | bc878ef | 2001-09-12 17:09:24 +0000 | [diff] [blame] | 2437 | timer->win = win; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2438 | timer->msg = req->msg; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2439 | timer->id = id; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2440 | timer->lparam = req->lparam; |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2441 | reply->id = id; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2442 | } |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2443 | if (thread) release_object( thread ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | /* kill a window timer */ |
| 2447 | DECL_HANDLER(kill_win_timer) |
| 2448 | { |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2449 | struct timer *timer; |
| 2450 | struct thread *thread; |
| 2451 | user_handle_t win = 0; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2452 | |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2453 | if (req->win) |
| 2454 | { |
| 2455 | if (!(win = get_user_full_handle( req->win )) || !(thread = get_window_thread( win ))) |
| 2456 | { |
| 2457 | set_error( STATUS_INVALID_HANDLE ); |
| 2458 | return; |
| 2459 | } |
| 2460 | if (thread->process != current->process) |
| 2461 | { |
| 2462 | release_object( thread ); |
| 2463 | set_error( STATUS_ACCESS_DENIED ); |
| 2464 | return; |
| 2465 | } |
| 2466 | } |
| 2467 | else thread = (struct thread *)grab_object( current ); |
| 2468 | |
| 2469 | if (thread->queue && (timer = find_timer( thread->queue, win, req->msg, req->id ))) |
| 2470 | free_timer( thread->queue, timer ); |
| 2471 | else |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2472 | set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | ff986a5 | 2004-11-29 18:08:18 +0000 | [diff] [blame] | 2473 | |
| 2474 | release_object( thread ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 2475 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2476 | |
Vincent Povirk | 4c83138 | 2011-05-26 15:52:17 -0500 | [diff] [blame] | 2477 | DECL_HANDLER(register_hotkey) |
| 2478 | { |
| 2479 | struct desktop *desktop; |
| 2480 | user_handle_t win_handle = req->window; |
| 2481 | struct hotkey *hotkey; |
| 2482 | struct hotkey *new_hotkey = NULL; |
| 2483 | struct thread *thread; |
| 2484 | const int modifier_flags = MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN; |
| 2485 | |
| 2486 | if (!(desktop = get_thread_desktop( current, 0 ))) return; |
| 2487 | |
| 2488 | if (win_handle) |
| 2489 | { |
| 2490 | if (!get_user_object_handle( &win_handle, USER_WINDOW )) |
| 2491 | { |
| 2492 | release_object( desktop ); |
| 2493 | set_win32_error( ERROR_INVALID_WINDOW_HANDLE ); |
| 2494 | return; |
| 2495 | } |
| 2496 | |
| 2497 | thread = get_window_thread( win_handle ); |
| 2498 | if (thread) release_object( thread ); |
| 2499 | |
| 2500 | if (thread != current) |
| 2501 | { |
| 2502 | release_object( desktop ); |
| 2503 | set_win32_error( ERROR_WINDOW_OF_OTHER_THREAD ); |
| 2504 | return; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | LIST_FOR_EACH_ENTRY( hotkey, &desktop->hotkeys, struct hotkey, entry ) |
| 2509 | { |
| 2510 | if (req->vkey == hotkey->vkey && |
| 2511 | (req->flags & modifier_flags) == (hotkey->flags & modifier_flags)) |
| 2512 | { |
| 2513 | release_object( desktop ); |
| 2514 | set_win32_error( ERROR_HOTKEY_ALREADY_REGISTERED ); |
| 2515 | return; |
| 2516 | } |
| 2517 | if (current->queue == hotkey->queue && win_handle == hotkey->win && req->id == hotkey->id) |
| 2518 | new_hotkey = hotkey; |
| 2519 | } |
| 2520 | |
| 2521 | if (new_hotkey) |
| 2522 | { |
| 2523 | reply->replaced = 1; |
| 2524 | reply->flags = new_hotkey->flags; |
| 2525 | reply->vkey = new_hotkey->vkey; |
| 2526 | } |
| 2527 | else |
| 2528 | { |
| 2529 | new_hotkey = mem_alloc( sizeof(*new_hotkey) ); |
| 2530 | if (new_hotkey) |
| 2531 | { |
| 2532 | list_add_tail( &desktop->hotkeys, &new_hotkey->entry ); |
| 2533 | new_hotkey->queue = current->queue; |
| 2534 | new_hotkey->win = win_handle; |
| 2535 | new_hotkey->id = req->id; |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | if (new_hotkey) |
| 2540 | { |
| 2541 | new_hotkey->flags = req->flags; |
| 2542 | new_hotkey->vkey = req->vkey; |
| 2543 | } |
| 2544 | |
| 2545 | release_object( desktop ); |
| 2546 | } |
| 2547 | |
| 2548 | DECL_HANDLER(unregister_hotkey) |
| 2549 | { |
| 2550 | struct desktop *desktop; |
| 2551 | user_handle_t win_handle = req->window; |
| 2552 | struct hotkey *hotkey; |
| 2553 | struct thread *thread; |
| 2554 | |
| 2555 | if (!(desktop = get_thread_desktop( current, 0 ))) return; |
| 2556 | |
| 2557 | if (win_handle) |
| 2558 | { |
| 2559 | if (!get_user_object_handle( &win_handle, USER_WINDOW )) |
| 2560 | { |
| 2561 | release_object( desktop ); |
| 2562 | set_win32_error( ERROR_INVALID_WINDOW_HANDLE ); |
| 2563 | return; |
| 2564 | } |
| 2565 | |
| 2566 | thread = get_window_thread( win_handle ); |
| 2567 | if (thread) release_object( thread ); |
| 2568 | |
| 2569 | if (thread != current) |
| 2570 | { |
| 2571 | release_object( desktop ); |
| 2572 | set_win32_error( ERROR_WINDOW_OF_OTHER_THREAD ); |
| 2573 | return; |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | LIST_FOR_EACH_ENTRY( hotkey, &desktop->hotkeys, struct hotkey, entry ) |
| 2578 | { |
| 2579 | if (current->queue == hotkey->queue && win_handle == hotkey->win && req->id == hotkey->id) |
| 2580 | goto found; |
| 2581 | } |
| 2582 | |
| 2583 | release_object( desktop ); |
| 2584 | set_win32_error( ERROR_HOTKEY_NOT_REGISTERED ); |
| 2585 | return; |
| 2586 | |
| 2587 | found: |
| 2588 | reply->flags = hotkey->flags; |
| 2589 | reply->vkey = hotkey->vkey; |
| 2590 | list_remove( &hotkey->entry ); |
| 2591 | free( hotkey ); |
| 2592 | release_object( desktop ); |
| 2593 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2594 | |
| 2595 | /* attach (or detach) thread inputs */ |
| 2596 | DECL_HANDLER(attach_thread_input) |
| 2597 | { |
| 2598 | struct thread *thread_from = get_thread_from_id( req->tid_from ); |
| 2599 | struct thread *thread_to = get_thread_from_id( req->tid_to ); |
| 2600 | |
| 2601 | if (!thread_from || !thread_to) |
| 2602 | { |
| 2603 | if (thread_from) release_object( thread_from ); |
| 2604 | if (thread_to) release_object( thread_to ); |
| 2605 | return; |
| 2606 | } |
| 2607 | if (thread_from != thread_to) |
| 2608 | { |
| 2609 | if (req->attach) attach_thread_input( thread_from, thread_to ); |
Alexandre Julliard | 5ad90c0 | 2005-07-11 13:30:23 +0000 | [diff] [blame] | 2610 | else |
| 2611 | { |
| 2612 | if (thread_from->queue && thread_to->queue && |
| 2613 | thread_from->queue->input == thread_to->queue->input) |
| 2614 | detach_thread_input( thread_from ); |
| 2615 | else |
| 2616 | set_error( STATUS_ACCESS_DENIED ); |
| 2617 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2618 | } |
| 2619 | else set_error( STATUS_ACCESS_DENIED ); |
| 2620 | release_object( thread_from ); |
| 2621 | release_object( thread_to ); |
| 2622 | } |
| 2623 | |
| 2624 | |
| 2625 | /* get thread input data */ |
| 2626 | DECL_HANDLER(get_thread_input) |
| 2627 | { |
| 2628 | struct thread *thread = NULL; |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2629 | struct desktop *desktop; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2630 | struct thread_input *input; |
| 2631 | |
| 2632 | if (req->tid) |
| 2633 | { |
| 2634 | if (!(thread = get_thread_from_id( req->tid ))) return; |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2635 | if (!(desktop = get_thread_desktop( thread, 0 ))) |
| 2636 | { |
| 2637 | release_object( thread ); |
| 2638 | return; |
| 2639 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2640 | input = thread->queue ? thread->queue->input : NULL; |
| 2641 | } |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2642 | else |
| 2643 | { |
| 2644 | if (!(desktop = get_thread_desktop( current, 0 ))) return; |
| 2645 | input = desktop->foreground_input; /* get the foreground thread info */ |
| 2646 | } |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2647 | |
| 2648 | if (input) |
| 2649 | { |
| 2650 | reply->focus = input->focus; |
| 2651 | reply->capture = input->capture; |
| 2652 | reply->active = input->active; |
| 2653 | reply->menu_owner = input->menu_owner; |
| 2654 | reply->move_size = input->move_size; |
| 2655 | reply->caret = input->caret; |
Alexandre Julliard | c545982 | 2010-05-11 11:21:03 +0200 | [diff] [blame] | 2656 | reply->cursor = input->cursor; |
| 2657 | reply->show_count = input->cursor_count; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 2658 | reply->rect = input->caret_rect; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2659 | } |
Alexandre Julliard | c545982 | 2010-05-11 11:21:03 +0200 | [diff] [blame] | 2660 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2661 | /* foreground window is active window of foreground thread */ |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2662 | reply->foreground = desktop->foreground_input ? desktop->foreground_input->active : 0; |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2663 | if (thread) release_object( thread ); |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2664 | release_object( desktop ); |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 2665 | } |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2666 | |
| 2667 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2668 | /* retrieve queue keyboard state for a given thread */ |
| 2669 | DECL_HANDLER(get_key_state) |
| 2670 | { |
| 2671 | struct thread *thread; |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2672 | struct desktop *desktop; |
| 2673 | data_size_t size = min( 256, get_reply_max_size() ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2674 | |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2675 | if (!req->tid) /* get global async key state */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2676 | { |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2677 | if (!(desktop = get_thread_desktop( current, 0 ))) return; |
Alexandre Julliard | 22468ec | 2011-02-28 21:43:44 +0100 | [diff] [blame] | 2678 | if (req->key >= 0) |
| 2679 | { |
| 2680 | reply->state = desktop->keystate[req->key & 0xff]; |
| 2681 | desktop->keystate[req->key & 0xff] &= ~0x40; |
| 2682 | } |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2683 | set_reply_data( desktop->keystate, size ); |
| 2684 | release_object( desktop ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2685 | } |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2686 | else |
| 2687 | { |
| 2688 | if (!(thread = get_thread_from_id( req->tid ))) return; |
| 2689 | if (thread->queue) |
| 2690 | { |
| 2691 | if (req->key >= 0) reply->state = thread->queue->input->keystate[req->key & 0xff]; |
| 2692 | set_reply_data( thread->queue->input->keystate, size ); |
| 2693 | } |
| 2694 | release_object( thread ); |
| 2695 | } |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | |
| 2699 | /* set queue keyboard state for a given thread */ |
| 2700 | DECL_HANDLER(set_key_state) |
| 2701 | { |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2702 | struct thread *thread; |
| 2703 | struct desktop *desktop; |
| 2704 | data_size_t size = min( 256, get_req_data_size() ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2705 | |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2706 | if (!req->tid) /* set global async key state */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2707 | { |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2708 | if (!(desktop = get_thread_desktop( current, 0 ))) return; |
| 2709 | memcpy( desktop->keystate, get_req_data(), size ); |
| 2710 | release_object( desktop ); |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2711 | } |
Alexandre Julliard | 06b78fe | 2011-02-25 12:10:04 +0100 | [diff] [blame] | 2712 | else |
| 2713 | { |
| 2714 | if (!(thread = get_thread_from_id( req->tid ))) return; |
| 2715 | if (thread->queue) memcpy( thread->queue->input->keystate, get_req_data(), size ); |
| 2716 | release_object( thread ); |
| 2717 | } |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2721 | /* set the system foreground window */ |
| 2722 | DECL_HANDLER(set_foreground_window) |
| 2723 | { |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2724 | struct thread *thread = NULL; |
| 2725 | struct desktop *desktop; |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2726 | struct msg_queue *queue = get_current_queue(); |
| 2727 | |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2728 | if (!(desktop = get_thread_desktop( current, 0 ))) return; |
| 2729 | reply->previous = desktop->foreground_input ? desktop->foreground_input->active : 0; |
| 2730 | reply->send_msg_old = (reply->previous && desktop->foreground_input != queue->input); |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2731 | reply->send_msg_new = FALSE; |
| 2732 | |
Dmitry Timoshkov | 19e7fab | 2006-07-07 23:01:51 +0900 | [diff] [blame] | 2733 | if (is_top_level_window( req->handle ) && |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2734 | ((thread = get_window_thread( req->handle ))) && |
| 2735 | (thread->queue->input->desktop == desktop)) |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2736 | { |
Alexandre Julliard | 2b96875 | 2011-03-30 12:34:32 +0200 | [diff] [blame] | 2737 | set_foreground_input( desktop, thread->queue->input ); |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2738 | reply->send_msg_new = (desktop->foreground_input != queue->input); |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2739 | } |
Dmitry Timoshkov | 19e7fab | 2006-07-07 23:01:51 +0900 | [diff] [blame] | 2740 | else set_win32_error( ERROR_INVALID_WINDOW_HANDLE ); |
Alexandre Julliard | ac4aac7 | 2011-02-24 16:45:04 +0100 | [diff] [blame] | 2741 | |
| 2742 | if (thread) release_object( thread ); |
| 2743 | release_object( desktop ); |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | /* set the current thread focus window */ |
| 2748 | DECL_HANDLER(set_focus_window) |
| 2749 | { |
| 2750 | struct msg_queue *queue = get_current_queue(); |
| 2751 | |
| 2752 | reply->previous = 0; |
| 2753 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2754 | { |
| 2755 | reply->previous = queue->input->focus; |
| 2756 | queue->input->focus = get_user_full_handle( req->handle ); |
| 2757 | } |
| 2758 | } |
| 2759 | |
| 2760 | |
| 2761 | /* set the current thread active window */ |
| 2762 | DECL_HANDLER(set_active_window) |
| 2763 | { |
| 2764 | struct msg_queue *queue = get_current_queue(); |
| 2765 | |
| 2766 | reply->previous = 0; |
| 2767 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2768 | { |
| 2769 | if (!req->handle || make_window_active( req->handle )) |
| 2770 | { |
| 2771 | reply->previous = queue->input->active; |
| 2772 | queue->input->active = get_user_full_handle( req->handle ); |
| 2773 | } |
| 2774 | else set_error( STATUS_INVALID_HANDLE ); |
| 2775 | } |
| 2776 | } |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 2777 | |
| 2778 | |
| 2779 | /* set the current thread capture window */ |
| 2780 | DECL_HANDLER(set_capture_window) |
| 2781 | { |
| 2782 | struct msg_queue *queue = get_current_queue(); |
| 2783 | |
| 2784 | reply->previous = reply->full_handle = 0; |
| 2785 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2786 | { |
| 2787 | struct thread_input *input = queue->input; |
| 2788 | |
Peter Dons Tychsen | d21c131 | 2010-01-11 21:47:43 +0100 | [diff] [blame] | 2789 | /* if in menu mode, reject all requests to change focus, except if the menu bit is set */ |
| 2790 | if (input->menu_owner && !(req->flags & CAPTURE_MENU)) |
| 2791 | { |
| 2792 | set_error(STATUS_ACCESS_DENIED); |
| 2793 | return; |
| 2794 | } |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 2795 | reply->previous = input->capture; |
| 2796 | input->capture = get_user_full_handle( req->handle ); |
| 2797 | input->menu_owner = (req->flags & CAPTURE_MENU) ? input->capture : 0; |
| 2798 | input->move_size = (req->flags & CAPTURE_MOVESIZE) ? input->capture : 0; |
| 2799 | reply->full_handle = input->capture; |
| 2800 | } |
| 2801 | } |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 2802 | |
| 2803 | |
| 2804 | /* Set the current thread caret window */ |
| 2805 | DECL_HANDLER(set_caret_window) |
| 2806 | { |
| 2807 | struct msg_queue *queue = get_current_queue(); |
| 2808 | |
| 2809 | reply->previous = 0; |
| 2810 | if (queue && check_queue_input_window( queue, req->handle )) |
| 2811 | { |
| 2812 | struct thread_input *input = queue->input; |
| 2813 | |
| 2814 | reply->previous = input->caret; |
| 2815 | reply->old_rect = input->caret_rect; |
| 2816 | reply->old_hide = input->caret_hide; |
| 2817 | reply->old_state = input->caret_state; |
| 2818 | |
| 2819 | set_caret_window( input, get_user_full_handle(req->handle) ); |
Krzysztof Foltman | b850172 | 2005-02-18 20:02:55 +0000 | [diff] [blame] | 2820 | input->caret_rect.right = input->caret_rect.left + req->width; |
| 2821 | input->caret_rect.bottom = input->caret_rect.top + req->height; |
Alexandre Julliard | 11e3523 | 2002-10-17 01:24:33 +0000 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | |
| 2826 | /* Set the current thread caret information */ |
| 2827 | DECL_HANDLER(set_caret_info) |
| 2828 | { |
| 2829 | struct msg_queue *queue = get_current_queue(); |
| 2830 | struct thread_input *input; |
| 2831 | |
| 2832 | if (!queue) return; |
| 2833 | input = queue->input; |
| 2834 | reply->full_handle = input->caret; |
| 2835 | reply->old_rect = input->caret_rect; |
| 2836 | reply->old_hide = input->caret_hide; |
| 2837 | reply->old_state = input->caret_state; |
| 2838 | |
| 2839 | if (req->handle && get_user_full_handle(req->handle) != input->caret) |
| 2840 | { |
| 2841 | set_error( STATUS_ACCESS_DENIED ); |
| 2842 | return; |
| 2843 | } |
| 2844 | if (req->flags & SET_CARET_POS) |
| 2845 | { |
| 2846 | input->caret_rect.right += req->x - input->caret_rect.left; |
| 2847 | input->caret_rect.bottom += req->y - input->caret_rect.top; |
| 2848 | input->caret_rect.left = req->x; |
| 2849 | input->caret_rect.top = req->y; |
| 2850 | } |
| 2851 | if (req->flags & SET_CARET_HIDE) |
| 2852 | { |
| 2853 | input->caret_hide += req->hide; |
| 2854 | if (input->caret_hide < 0) input->caret_hide = 0; |
| 2855 | } |
| 2856 | if (req->flags & SET_CARET_STATE) |
| 2857 | { |
| 2858 | if (req->state == -1) input->caret_state = !input->caret_state; |
| 2859 | else input->caret_state = !!req->state; |
| 2860 | } |
| 2861 | } |
Mike McCormack | abe70f7 | 2005-04-28 12:04:14 +0000 | [diff] [blame] | 2862 | |
| 2863 | |
| 2864 | /* get the time of the last input event */ |
| 2865 | DECL_HANDLER(get_last_input_time) |
| 2866 | { |
| 2867 | reply->time = last_input_time; |
| 2868 | } |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 2869 | |
| 2870 | /* set/get the current cursor */ |
| 2871 | DECL_HANDLER(set_cursor) |
| 2872 | { |
| 2873 | struct msg_queue *queue = get_current_queue(); |
| 2874 | struct thread_input *input; |
| 2875 | |
| 2876 | if (!queue) return; |
| 2877 | input = queue->input; |
| 2878 | |
| 2879 | reply->prev_handle = input->cursor; |
| 2880 | reply->prev_count = input->cursor_count; |
Alexandre Julliard | abe5440 | 2011-04-20 20:29:16 +0200 | [diff] [blame] | 2881 | reply->prev_x = input->desktop->cursor.x; |
| 2882 | reply->prev_y = input->desktop->cursor.y; |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 2883 | |
| 2884 | if (req->flags & SET_CURSOR_HANDLE) |
| 2885 | { |
| 2886 | if (req->handle && !get_user_object( req->handle, USER_CLIENT )) |
| 2887 | { |
| 2888 | set_win32_error( ERROR_INVALID_CURSOR_HANDLE ); |
| 2889 | return; |
| 2890 | } |
| 2891 | input->cursor = req->handle; |
| 2892 | } |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 2893 | if (req->flags & SET_CURSOR_COUNT) |
| 2894 | { |
| 2895 | queue->cursor_count += req->show_count; |
| 2896 | input->cursor_count += req->show_count; |
| 2897 | } |
Alexandre Julliard | 183c41b | 2011-02-24 17:47:59 +0100 | [diff] [blame] | 2898 | if (req->flags & SET_CURSOR_POS) |
| 2899 | { |
Alexandre Julliard | 02e8174 | 2011-02-25 11:31:47 +0100 | [diff] [blame] | 2900 | set_cursor_pos( input->desktop, req->x, req->y ); |
| 2901 | } |
Alexandre Julliard | 6b0d9ff | 2011-06-21 14:50:23 +0200 | [diff] [blame] | 2902 | if (req->flags & (SET_CURSOR_CLIP | SET_CURSOR_NOCLIP)) |
Alexandre Julliard | 02e8174 | 2011-02-25 11:31:47 +0100 | [diff] [blame] | 2903 | { |
Alexandre Julliard | 21e86f6 | 2011-03-31 20:27:29 +0200 | [diff] [blame] | 2904 | struct desktop *desktop = input->desktop; |
| 2905 | |
| 2906 | /* only the desktop owner can set the message */ |
| 2907 | if (req->clip_msg && get_top_window_owner(desktop) == current->process) |
| 2908 | desktop->cursor.clip_msg = req->clip_msg; |
| 2909 | |
Alexandre Julliard | 6b0d9ff | 2011-06-21 14:50:23 +0200 | [diff] [blame] | 2910 | set_clip_rectangle( desktop, (req->flags & SET_CURSOR_NOCLIP) ? NULL : &req->clip ); |
Alexandre Julliard | 183c41b | 2011-02-24 17:47:59 +0100 | [diff] [blame] | 2911 | } |
| 2912 | |
Alexandre Julliard | 6576703 | 2011-03-31 20:15:56 +0200 | [diff] [blame] | 2913 | reply->new_x = input->desktop->cursor.x; |
| 2914 | reply->new_y = input->desktop->cursor.y; |
| 2915 | reply->new_clip = input->desktop->cursor.clip; |
| 2916 | reply->last_change = input->desktop->cursor.last_change; |
Alexandre Julliard | 8159d4e | 2010-03-22 17:52:23 +0100 | [diff] [blame] | 2917 | } |