2 * Server-side message queues
4 * Copyright (C) 2000 Alexandre Julliard
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.
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.
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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define WIN32_NO_STATUS
46 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
47 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
49 enum message_kind
{ SEND_MESSAGE
, POST_MESSAGE
};
50 #define NB_MSG_KINDS (POST_MESSAGE+1)
55 struct list sender_entry
; /* entry in sender list */
56 struct message
*msg
; /* message the result is for */
57 struct message_result
*recv_next
; /* next in receiver list */
58 struct msg_queue
*sender
; /* sender queue */
59 struct msg_queue
*receiver
; /* receiver queue */
60 int replied
; /* has it been replied to? */
61 unsigned int error
; /* error code to pass back to sender */
62 lparam_t result
; /* reply result */
63 struct message
*hardware_msg
; /* hardware message if low-level hook result */
64 struct desktop
*desktop
; /* desktop for hardware message */
65 struct message
*callback_msg
; /* message to queue for callback */
66 void *data
; /* message reply data */
67 unsigned int data_size
; /* size of message reply data */
68 struct timeout_user
*timeout
; /* result timeout */
73 struct list entry
; /* entry in message list */
74 enum message_type type
; /* message type */
75 user_handle_t win
; /* window handle */
76 unsigned int msg
; /* message code */
77 lparam_t wparam
; /* parameters */
78 lparam_t lparam
; /* parameters */
79 int x
; /* message position */
81 unsigned int time
; /* message time */
82 void *data
; /* message data for sent messages */
83 unsigned int data_size
; /* size of message data */
84 unsigned int unique_id
; /* unique id for nested hw message waits */
85 struct message_result
*result
; /* result in sender queue */
90 struct list entry
; /* entry in timer list */
91 abstime_t when
; /* next expiration */
92 unsigned int rate
; /* timer rate in ms */
93 user_handle_t win
; /* window handle */
94 unsigned int msg
; /* message to post */
95 lparam_t id
; /* timer id */
96 lparam_t lparam
; /* lparam for message */
101 struct object obj
; /* object header */
102 struct desktop
*desktop
; /* desktop that this thread input belongs to */
103 user_handle_t focus
; /* focus window */
104 user_handle_t capture
; /* capture window */
105 user_handle_t active
; /* active window */
106 user_handle_t menu_owner
; /* current menu owner window */
107 user_handle_t move_size
; /* current moving/resizing window */
108 user_handle_t caret
; /* caret window */
109 rectangle_t caret_rect
; /* caret rectangle */
110 int caret_hide
; /* caret hide count */
111 int caret_state
; /* caret on/off state */
112 user_handle_t cursor
; /* current cursor */
113 int cursor_count
; /* cursor show count */
114 struct list msg_list
; /* list of hardware messages */
115 unsigned char keystate
[256]; /* state of each key */
116 unsigned char desktop_keystate
[256]; /* desktop keystate when keystate was synced */
117 int keystate_lock
; /* keystate is locked */
122 struct object obj
; /* object header */
123 struct fd
*fd
; /* optional file descriptor to poll */
124 unsigned int wake_bits
; /* wakeup bits */
125 unsigned int wake_mask
; /* wakeup mask */
126 unsigned int changed_bits
; /* changed wakeup bits */
127 unsigned int changed_mask
; /* changed wakeup mask */
128 int paint_count
; /* pending paint messages count */
129 int hotkey_count
; /* pending hotkey messages count */
130 int quit_message
; /* is there a pending quit message? */
131 int exit_code
; /* exit code of pending quit message */
132 int cursor_count
; /* per-queue cursor show count */
133 struct list msg_list
[NB_MSG_KINDS
]; /* lists of messages */
134 struct list send_result
; /* stack of sent messages waiting for result */
135 struct list callback_result
; /* list of callback messages waiting for result */
136 struct message_result
*recv_result
; /* stack of received messages waiting for result */
137 struct list pending_timers
; /* list of pending timers */
138 struct list expired_timers
; /* list of expired timers */
139 lparam_t next_timer_id
; /* id for the next timer with a 0 window */
140 struct timeout_user
*timeout
; /* timeout for next timer to expire */
141 struct thread_input
*input
; /* thread input descriptor */
142 struct hook_table
*hooks
; /* hook table */
143 timeout_t last_get_msg
; /* time of last get message call */
144 int keystate_lock
; /* owns an input keystate lock */
149 struct list entry
; /* entry in desktop hotkey list */
150 struct msg_queue
*queue
; /* queue owning this hotkey */
151 user_handle_t win
; /* window handle */
152 int id
; /* hotkey id */
153 unsigned int vkey
; /* virtual key code */
154 unsigned int flags
; /* key modifiers */
157 static void msg_queue_dump( struct object
*obj
, int verbose
);
158 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
);
159 static void msg_queue_remove_queue( struct object
*obj
, struct wait_queue_entry
*entry
);
160 static int msg_queue_signaled( struct object
*obj
, struct wait_queue_entry
*entry
);
161 static void msg_queue_satisfied( struct object
*obj
, struct wait_queue_entry
*entry
);
162 static void msg_queue_destroy( struct object
*obj
);
163 static void msg_queue_poll_event( struct fd
*fd
, int event
);
164 static void thread_input_dump( struct object
*obj
, int verbose
);
165 static void thread_input_destroy( struct object
*obj
);
166 static void timer_callback( void *private );
168 static const struct object_ops msg_queue_ops
=
170 sizeof(struct msg_queue
), /* size */
172 msg_queue_dump
, /* dump */
173 msg_queue_add_queue
, /* add_queue */
174 msg_queue_remove_queue
, /* remove_queue */
175 msg_queue_signaled
, /* signaled */
176 msg_queue_satisfied
, /* satisfied */
177 no_signal
, /* signal */
178 no_get_fd
, /* get_fd */
179 default_map_access
, /* map_access */
180 default_get_sd
, /* get_sd */
181 default_set_sd
, /* set_sd */
182 no_get_full_name
, /* get_full_name */
183 no_lookup_name
, /* lookup_name */
184 no_link_name
, /* link_name */
185 NULL
, /* unlink_name */
186 no_open_file
, /* open_file */
187 no_kernel_obj_list
, /* get_kernel_obj_list */
188 no_close_handle
, /* close_handle */
189 msg_queue_destroy
/* destroy */
192 static const struct fd_ops msg_queue_fd_ops
=
194 NULL
, /* get_poll_events */
195 msg_queue_poll_event
, /* poll_event */
197 NULL
, /* get_fd_type */
199 NULL
, /* queue_async */
200 NULL
, /* reselect_async */
201 NULL
/* cancel async */
205 static const struct object_ops thread_input_ops
=
207 sizeof(struct thread_input
), /* size */
209 thread_input_dump
, /* dump */
210 no_add_queue
, /* add_queue */
211 NULL
, /* remove_queue */
213 NULL
, /* satisfied */
214 no_signal
, /* signal */
215 no_get_fd
, /* get_fd */
216 default_map_access
, /* map_access */
217 default_get_sd
, /* get_sd */
218 default_set_sd
, /* set_sd */
219 no_get_full_name
, /* get_full_name */
220 no_lookup_name
, /* lookup_name */
221 no_link_name
, /* link_name */
222 NULL
, /* unlink_name */
223 no_open_file
, /* open_file */
224 no_kernel_obj_list
, /* get_kernel_obj_list */
225 no_close_handle
, /* close_handle */
226 thread_input_destroy
/* destroy */
229 /* pointer to input structure of foreground thread */
230 static unsigned int last_input_time
;
232 static cursor_pos_t cursor_history
[64];
233 static unsigned int cursor_history_latest
;
235 static void queue_hardware_message( struct desktop
*desktop
, struct message
*msg
, int always_queue
);
236 static void free_message( struct message
*msg
);
238 /* set the caret window in a given thread input */
239 static void set_caret_window( struct thread_input
*input
, user_handle_t win
)
241 if (!win
|| win
!= input
->caret
)
243 input
->caret_rect
.left
= 0;
244 input
->caret_rect
.top
= 0;
245 input
->caret_rect
.right
= 0;
246 input
->caret_rect
.bottom
= 0;
249 input
->caret_hide
= 1;
250 input
->caret_state
= 0;
253 /* create a thread input object */
254 static struct thread_input
*create_thread_input( struct thread
*thread
)
256 struct thread_input
*input
;
258 if ((input
= alloc_object( &thread_input_ops
)))
263 input
->menu_owner
= 0;
264 input
->move_size
= 0;
266 input
->cursor_count
= 0;
267 list_init( &input
->msg_list
);
268 set_caret_window( input
, 0 );
269 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
270 input
->keystate_lock
= 0;
272 if (!(input
->desktop
= get_thread_desktop( thread
, 0 /* FIXME: access rights */ )))
274 release_object( input
);
277 memcpy( input
->desktop_keystate
, input
->desktop
->keystate
, sizeof(input
->desktop_keystate
) );
282 /* create a message queue object */
283 static struct msg_queue
*create_msg_queue( struct thread
*thread
, struct thread_input
*input
)
285 struct thread_input
*new_input
= NULL
;
286 struct msg_queue
*queue
;
291 if (!(new_input
= create_thread_input( thread
))) return NULL
;
295 if ((queue
= alloc_object( &msg_queue_ops
)))
298 queue
->wake_bits
= 0;
299 queue
->wake_mask
= 0;
300 queue
->changed_bits
= 0;
301 queue
->changed_mask
= 0;
302 queue
->paint_count
= 0;
303 queue
->hotkey_count
= 0;
304 queue
->quit_message
= 0;
305 queue
->cursor_count
= 0;
306 queue
->recv_result
= NULL
;
307 queue
->next_timer_id
= 0x7fff;
308 queue
->timeout
= NULL
;
309 queue
->input
= (struct thread_input
*)grab_object( input
);
311 queue
->last_get_msg
= current_time
;
312 queue
->keystate_lock
= 0;
313 list_init( &queue
->send_result
);
314 list_init( &queue
->callback_result
);
315 list_init( &queue
->pending_timers
);
316 list_init( &queue
->expired_timers
);
317 for (i
= 0; i
< NB_MSG_KINDS
; i
++) list_init( &queue
->msg_list
[i
] );
319 thread
->queue
= queue
;
321 if (new_input
) release_object( new_input
);
325 /* free the message queue of a thread at thread exit */
326 void free_msg_queue( struct thread
*thread
)
328 remove_thread_hooks( thread
);
329 if (!thread
->queue
) return;
330 release_object( thread
->queue
);
331 thread
->queue
= NULL
;
334 /* synchronize thread input keystate with the desktop */
335 static void sync_input_keystate( struct thread_input
*input
)
338 if (!input
->desktop
|| input
->keystate_lock
) return;
339 for (i
= 0; i
< sizeof(input
->keystate
); ++i
)
341 if (input
->desktop_keystate
[i
] == input
->desktop
->keystate
[i
]) continue;
342 input
->keystate
[i
] = input
->desktop_keystate
[i
] = input
->desktop
->keystate
[i
];
346 /* locks thread input keystate to prevent synchronization */
347 static void lock_input_keystate( struct thread_input
*input
)
349 input
->keystate_lock
++;
352 /* unlock the thread input keystate and synchronize it again */
353 static void unlock_input_keystate( struct thread_input
*input
)
355 input
->keystate_lock
--;
356 if (!input
->keystate_lock
) sync_input_keystate( input
);
359 /* change the thread input data of a given thread */
360 static int assign_thread_input( struct thread
*thread
, struct thread_input
*new_input
)
362 struct msg_queue
*queue
= thread
->queue
;
366 thread
->queue
= create_msg_queue( thread
, new_input
);
367 return thread
->queue
!= NULL
;
371 queue
->input
->cursor_count
-= queue
->cursor_count
;
372 if (queue
->keystate_lock
) unlock_input_keystate( queue
->input
);
373 release_object( queue
->input
);
375 queue
->input
= (struct thread_input
*)grab_object( new_input
);
376 if (queue
->keystate_lock
) lock_input_keystate( queue
->input
);
377 new_input
->cursor_count
+= queue
->cursor_count
;
381 /* allocate a hardware message and its data */
382 static struct message
*alloc_hardware_message( lparam_t info
, struct hw_msg_source source
,
383 unsigned int time
, data_size_t extra_size
)
385 struct hardware_msg_data
*msg_data
;
388 if (!(msg
= mem_alloc( sizeof(*msg
) ))) return NULL
;
389 if (!(msg_data
= mem_alloc( sizeof(*msg_data
) + extra_size
)))
394 memset( msg
, 0, sizeof(*msg
) );
395 msg
->type
= MSG_HARDWARE
;
397 msg
->data
= msg_data
;
398 msg
->data_size
= sizeof(*msg_data
) + extra_size
;
400 memset( msg_data
, 0, sizeof(*msg_data
) + extra_size
);
401 msg_data
->info
= info
;
402 msg_data
->size
= msg
->data_size
;
403 msg_data
->source
= source
;
407 static int is_cursor_clipped( struct desktop
*desktop
)
409 rectangle_t top_rect
, clip_rect
= desktop
->cursor
.clip
;
410 get_top_window_rectangle( desktop
, &top_rect
);
411 return !is_rect_equal( &clip_rect
, &top_rect
);
414 static void queue_cursor_message( struct desktop
*desktop
, user_handle_t win
, unsigned int message
,
415 lparam_t wparam
, lparam_t lparam
)
417 static const struct hw_msg_source source
= { IMDT_UNAVAILABLE
, IMO_SYSTEM
};
418 struct thread_input
*input
;
421 if (!(msg
= alloc_hardware_message( 0, source
, get_tick_count(), 0 ))) return;
424 msg
->wparam
= wparam
;
425 msg
->lparam
= lparam
;
426 msg
->x
= desktop
->cursor
.x
;
427 msg
->y
= desktop
->cursor
.y
;
428 if (!(msg
->win
= win
) && (input
= desktop
->foreground_input
)) msg
->win
= input
->active
;
429 queue_hardware_message( desktop
, msg
, 1 );
432 static int update_desktop_cursor_window( struct desktop
*desktop
, user_handle_t win
)
434 int updated
= win
!= desktop
->cursor
.win
;
435 user_handle_t handle
= desktop
->cursor
.handle
;
436 desktop
->cursor
.win
= win
;
439 /* when clipping send the message to the foreground window as well, as some driver have an artificial overlay window */
440 if (is_cursor_clipped( desktop
)) queue_cursor_message( desktop
, 0, WM_WINE_SETCURSOR
, win
, handle
);
441 queue_cursor_message( desktop
, win
, WM_WINE_SETCURSOR
, win
, handle
);
446 static int update_desktop_cursor_pos( struct desktop
*desktop
, user_handle_t win
, int x
, int y
)
448 struct thread_input
*input
;
451 x
= max( min( x
, desktop
->cursor
.clip
.right
- 1 ), desktop
->cursor
.clip
.left
);
452 y
= max( min( y
, desktop
->cursor
.clip
.bottom
- 1 ), desktop
->cursor
.clip
.top
);
453 updated
= (desktop
->cursor
.x
!= x
|| desktop
->cursor
.y
!= y
);
454 desktop
->cursor
.x
= x
;
455 desktop
->cursor
.y
= y
;
456 desktop
->cursor
.last_change
= get_tick_count();
458 if (!win
&& (input
= desktop
->foreground_input
)) win
= input
->capture
;
459 if (!win
|| !is_window_visible( win
) || is_window_transparent( win
))
460 win
= shallow_window_from_point( desktop
, x
, y
);
461 if (update_desktop_cursor_window( desktop
, win
)) updated
= 1;
466 static void update_desktop_cursor_handle( struct desktop
*desktop
, user_handle_t handle
)
468 int updated
= desktop
->cursor
.handle
!= handle
;
469 user_handle_t win
= desktop
->cursor
.win
;
470 desktop
->cursor
.handle
= handle
;
473 /* when clipping send the message to the foreground window as well, as some driver have an artificial overlay window */
474 if (is_cursor_clipped( desktop
)) queue_cursor_message( desktop
, 0, WM_WINE_SETCURSOR
, win
, handle
);
475 queue_cursor_message( desktop
, win
, WM_WINE_SETCURSOR
, win
, handle
);
479 /* set the cursor position and queue the corresponding mouse message */
480 static void set_cursor_pos( struct desktop
*desktop
, int x
, int y
)
482 static const struct hw_msg_source source
= { IMDT_UNAVAILABLE
, IMO_SYSTEM
};
483 const struct rawinput_device
*device
;
486 if ((device
= current
->process
->rawinput_mouse
) && (device
->flags
& RIDEV_NOLEGACY
))
488 update_desktop_cursor_pos( desktop
, 0, x
, y
);
492 if (!(msg
= alloc_hardware_message( 0, source
, get_tick_count(), 0 ))) return;
494 msg
->msg
= WM_MOUSEMOVE
;
497 queue_hardware_message( desktop
, msg
, 1 );
500 /* retrieve default position and time for synthesized messages */
501 static void get_message_defaults( struct msg_queue
*queue
, int *x
, int *y
, unsigned int *time
)
503 struct desktop
*desktop
= queue
->input
->desktop
;
505 *x
= desktop
->cursor
.x
;
506 *y
= desktop
->cursor
.y
;
507 *time
= get_tick_count();
510 /* set the cursor clip rectangle */
511 void set_clip_rectangle( struct desktop
*desktop
, const rectangle_t
*rect
, unsigned int flags
, int reset
)
513 rectangle_t top_rect
;
516 get_top_window_rectangle( desktop
, &top_rect
);
519 rectangle_t new_rect
= *rect
;
520 if (new_rect
.left
< top_rect
.left
) new_rect
.left
= top_rect
.left
;
521 if (new_rect
.right
> top_rect
.right
) new_rect
.right
= top_rect
.right
;
522 if (new_rect
.top
< top_rect
.top
) new_rect
.top
= top_rect
.top
;
523 if (new_rect
.bottom
> top_rect
.bottom
) new_rect
.bottom
= top_rect
.bottom
;
524 if (new_rect
.left
> new_rect
.right
|| new_rect
.top
> new_rect
.bottom
) new_rect
= top_rect
;
525 desktop
->cursor
.clip
= new_rect
;
527 else desktop
->cursor
.clip
= top_rect
;
529 /* warp the mouse to be inside the clip rect */
530 x
= max( min( desktop
->cursor
.x
, desktop
->cursor
.clip
.right
- 1 ), desktop
->cursor
.clip
.left
);
531 y
= max( min( desktop
->cursor
.y
, desktop
->cursor
.clip
.bottom
- 1 ), desktop
->cursor
.clip
.top
);
532 if (x
!= desktop
->cursor
.x
|| y
!= desktop
->cursor
.y
) set_cursor_pos( desktop
, x
, y
);
534 /* request clip cursor rectangle reset to the desktop thread */
535 if (reset
) post_desktop_message( desktop
, WM_WINE_CLIPCURSOR
, flags
, FALSE
);
537 /* notify foreground thread, of reset, or to apply new cursor clipping rect */
538 queue_cursor_message( desktop
, 0, WM_WINE_CLIPCURSOR
, flags
, reset
);
541 /* change the foreground input and reset the cursor clip rect */
542 static void set_foreground_input( struct desktop
*desktop
, struct thread_input
*input
)
544 if (desktop
->foreground_input
== input
) return;
545 set_clip_rectangle( desktop
, NULL
, SET_CURSOR_NOCLIP
, 1 );
546 desktop
->foreground_input
= input
;
549 /* get the hook table for a given thread */
550 struct hook_table
*get_queue_hooks( struct thread
*thread
)
552 if (!thread
->queue
) return NULL
;
553 return thread
->queue
->hooks
;
556 /* set the hook table for a given thread, allocating the queue if needed */
557 void set_queue_hooks( struct thread
*thread
, struct hook_table
*hooks
)
559 struct msg_queue
*queue
= thread
->queue
;
560 if (!queue
&& !(queue
= create_msg_queue( thread
, NULL
))) return;
561 if (queue
->hooks
) release_object( queue
->hooks
);
562 queue
->hooks
= hooks
;
565 /* check the queue status */
566 static inline int is_signaled( struct msg_queue
*queue
)
568 return ((queue
->wake_bits
& queue
->wake_mask
) || (queue
->changed_bits
& queue
->changed_mask
));
571 /* set some queue bits */
572 static inline void set_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
574 if (bits
& (QS_KEY
| QS_MOUSEBUTTON
))
576 if (!queue
->keystate_lock
) lock_input_keystate( queue
->input
);
577 queue
->keystate_lock
= 1;
579 queue
->wake_bits
|= bits
;
580 queue
->changed_bits
|= bits
;
581 if (is_signaled( queue
)) wake_up( &queue
->obj
, 0 );
584 /* clear some queue bits */
585 static inline void clear_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
587 queue
->wake_bits
&= ~bits
;
588 queue
->changed_bits
&= ~bits
;
589 if (!(queue
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
)))
591 if (queue
->keystate_lock
) unlock_input_keystate( queue
->input
);
592 queue
->keystate_lock
= 0;
596 /* check if message is matched by the filter */
597 static inline int check_msg_filter( unsigned int msg
, unsigned int first
, unsigned int last
)
599 return (msg
>= first
&& msg
<= last
);
602 /* check whether a message filter contains at least one potential hardware message */
603 static inline int filter_contains_hw_range( unsigned int first
, unsigned int last
)
605 /* hardware message ranges are (in numerical order):
606 * WM_NCMOUSEFIRST .. WM_NCMOUSELAST
607 * WM_INPUT_DEVICE_CHANGE .. WM_KEYLAST
608 * WM_MOUSEFIRST .. WM_MOUSELAST
610 if (last
< WM_NCMOUSEFIRST
) return 0;
611 if (first
> WM_NCMOUSELAST
&& last
< WM_INPUT_DEVICE_CHANGE
) return 0;
612 if (first
> WM_KEYLAST
&& last
< WM_MOUSEFIRST
) return 0;
613 if (first
> WM_MOUSELAST
) return 0;
617 /* get the QS_* bit corresponding to a given hardware message */
618 static inline int get_hardware_msg_bit( unsigned int message
)
620 if (message
== WM_INPUT_DEVICE_CHANGE
|| message
== WM_INPUT
) return QS_RAWINPUT
;
621 if (message
== WM_MOUSEMOVE
|| message
== WM_NCMOUSEMOVE
) return QS_MOUSEMOVE
;
622 if (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
) return QS_KEY
;
623 if (message
== WM_WINE_CLIPCURSOR
) return QS_RAWINPUT
;
624 if (message
== WM_WINE_SETCURSOR
) return QS_RAWINPUT
;
625 return QS_MOUSEBUTTON
;
628 /* get the current thread queue, creating it if needed */
629 static inline struct msg_queue
*get_current_queue(void)
631 struct msg_queue
*queue
= current
->queue
;
632 if (!queue
) queue
= create_msg_queue( current
, NULL
);
636 /* get a (pseudo-)unique id to tag hardware messages */
637 static inline unsigned int get_unique_id(void)
639 static unsigned int id
;
640 if (!++id
) id
= 1; /* avoid an id of 0 */
644 /* try to merge a WM_MOUSEMOVE message with the last in the list; return 1 if successful */
645 static int merge_mousemove( struct thread_input
*input
, const struct message
*msg
)
647 struct message
*prev
;
650 for (ptr
= list_tail( &input
->msg_list
); ptr
; ptr
= list_prev( &input
->msg_list
, ptr
))
652 prev
= LIST_ENTRY( ptr
, struct message
, entry
);
653 if (prev
->msg
!= WM_INPUT
) break;
656 if (prev
->result
) return 0;
657 if (prev
->win
&& msg
->win
&& prev
->win
!= msg
->win
) return 0;
658 if (prev
->msg
!= msg
->msg
) return 0;
659 if (prev
->type
!= msg
->type
) return 0;
660 /* now we can merge it */
661 prev
->wparam
= msg
->wparam
;
662 prev
->lparam
= msg
->lparam
;
665 prev
->time
= msg
->time
;
666 if (msg
->type
== MSG_HARDWARE
&& prev
->data
&& msg
->data
)
668 struct hardware_msg_data
*prev_data
= prev
->data
;
669 struct hardware_msg_data
*msg_data
= msg
->data
;
670 prev_data
->info
= msg_data
->info
;
673 list_add_tail( &input
->msg_list
, ptr
);
677 /* try to merge a unique message with the last in the list; return 1 if successful */
678 static int merge_unique_message( struct thread_input
*input
, unsigned int message
, const struct message
*msg
)
680 struct message
*prev
;
682 LIST_FOR_EACH_ENTRY_REV( prev
, &input
->msg_list
, struct message
, entry
)
683 if (prev
->msg
== message
) break;
684 if (&prev
->entry
== &input
->msg_list
) return 0;
686 if (prev
->result
) return 0;
687 if (prev
->win
!= msg
->win
) return 0;
688 if (prev
->type
!= msg
->type
) return 0;
690 /* now we can merge it */
691 prev
->wparam
= msg
->wparam
;
692 prev
->lparam
= msg
->lparam
;
695 prev
->time
= msg
->time
;
696 list_remove( &prev
->entry
);
697 list_add_tail( &input
->msg_list
, &prev
->entry
);
702 /* try to merge a message with the messages in the list; return 1 if successful */
703 static int merge_message( struct thread_input
*input
, const struct message
*msg
)
705 if (msg
->msg
== WM_MOUSEMOVE
) return merge_mousemove( input
, msg
);
706 if (msg
->msg
== WM_WINE_CLIPCURSOR
) return merge_unique_message( input
, WM_WINE_CLIPCURSOR
, msg
);
707 if (msg
->msg
== WM_WINE_SETCURSOR
) return merge_unique_message( input
, WM_WINE_SETCURSOR
, msg
);
711 /* free a result structure */
712 static void free_result( struct message_result
*result
)
714 if (result
->timeout
) remove_timeout_user( result
->timeout
);
715 free( result
->data
);
716 if (result
->callback_msg
) free_message( result
->callback_msg
);
717 if (result
->hardware_msg
) free_message( result
->hardware_msg
);
718 if (result
->desktop
) release_object( result
->desktop
);
722 /* remove the result from the sender list it is on */
723 static inline void remove_result_from_sender( struct message_result
*result
)
725 assert( result
->sender
);
727 list_remove( &result
->sender_entry
);
728 result
->sender
= NULL
;
729 if (!result
->receiver
) free_result( result
);
732 /* store the message result in the appropriate structure */
733 static void store_message_result( struct message_result
*res
, lparam_t result
, unsigned int error
)
735 res
->result
= result
;
740 remove_timeout_user( res
->timeout
);
744 if (res
->hardware_msg
)
746 if (!error
&& result
) /* rejected by the hook */
747 free_message( res
->hardware_msg
);
749 queue_hardware_message( res
->desktop
, res
->hardware_msg
, 0 );
751 res
->hardware_msg
= NULL
;
756 if (res
->callback_msg
)
758 /* queue the callback message in the sender queue */
759 struct callback_msg_data
*data
= res
->callback_msg
->data
;
760 data
->result
= result
;
761 list_add_tail( &res
->sender
->msg_list
[SEND_MESSAGE
], &res
->callback_msg
->entry
);
762 set_queue_bits( res
->sender
, QS_SENDMESSAGE
);
763 res
->callback_msg
= NULL
;
764 remove_result_from_sender( res
);
768 /* wake sender queue if waiting on this result */
769 if (list_head(&res
->sender
->send_result
) == &res
->sender_entry
)
770 set_queue_bits( res
->sender
, QS_SMRESULT
);
773 else if (!res
->receiver
) free_result( res
);
776 /* free a message when deleting a queue or window */
777 static void free_message( struct message
*msg
)
779 struct message_result
*result
= msg
->result
;
783 result
->receiver
= NULL
;
784 store_message_result( result
, 0, STATUS_ACCESS_DENIED
/*FIXME*/ );
790 /* remove (and free) a message from a message list */
791 static void remove_queue_message( struct msg_queue
*queue
, struct message
*msg
,
792 enum message_kind kind
)
794 list_remove( &msg
->entry
);
798 if (list_empty( &queue
->msg_list
[kind
] )) clear_queue_bits( queue
, QS_SENDMESSAGE
);
801 if (list_empty( &queue
->msg_list
[kind
] ) && !queue
->quit_message
)
802 clear_queue_bits( queue
, QS_POSTMESSAGE
|QS_ALLPOSTMESSAGE
);
803 if (msg
->msg
== WM_HOTKEY
&& --queue
->hotkey_count
== 0)
804 clear_queue_bits( queue
, QS_HOTKEY
);
810 /* message timed out without getting a reply */
811 static void result_timeout( void *private )
813 struct message_result
*result
= private;
815 assert( !result
->replied
);
817 result
->timeout
= NULL
;
819 if (result
->msg
) /* not received yet */
821 struct message
*msg
= result
->msg
;
825 remove_queue_message( result
->receiver
, msg
, SEND_MESSAGE
);
826 result
->receiver
= NULL
;
828 store_message_result( result
, 0, STATUS_TIMEOUT
);
831 /* allocate and fill a message result structure */
832 static struct message_result
*alloc_message_result( struct msg_queue
*send_queue
,
833 struct msg_queue
*recv_queue
,
834 struct message
*msg
, timeout_t timeout
)
836 struct message_result
*result
= mem_alloc( sizeof(*result
) );
840 result
->sender
= send_queue
;
841 result
->receiver
= recv_queue
;
844 result
->data_size
= 0;
845 result
->timeout
= NULL
;
846 result
->hardware_msg
= NULL
;
847 result
->desktop
= NULL
;
848 result
->callback_msg
= NULL
;
850 if (msg
->type
== MSG_CALLBACK
)
852 struct message
*callback_msg
= mem_alloc( sizeof(*callback_msg
) );
859 callback_msg
->type
= MSG_CALLBACK_RESULT
;
860 callback_msg
->win
= msg
->win
;
861 callback_msg
->msg
= msg
->msg
;
862 callback_msg
->wparam
= 0;
863 callback_msg
->lparam
= 0;
864 callback_msg
->time
= get_tick_count();
865 callback_msg
->result
= NULL
;
866 /* steal the data from the original message */
867 callback_msg
->data
= msg
->data
;
868 callback_msg
->data_size
= msg
->data_size
;
872 result
->callback_msg
= callback_msg
;
873 list_add_head( &send_queue
->callback_result
, &result
->sender_entry
);
877 list_add_head( &send_queue
->send_result
, &result
->sender_entry
);
878 clear_queue_bits( send_queue
, QS_SMRESULT
);
881 if (timeout
!= TIMEOUT_INFINITE
)
882 result
->timeout
= add_timeout_user( timeout
, result_timeout
, result
);
887 /* receive a message, removing it from the sent queue */
888 static void receive_message( struct msg_queue
*queue
, struct message
*msg
,
889 struct get_message_reply
*reply
)
891 struct message_result
*result
= msg
->result
;
893 reply
->total
= msg
->data_size
;
894 if (msg
->data_size
> get_reply_max_size())
896 set_error( STATUS_BUFFER_OVERFLOW
);
899 reply
->type
= msg
->type
;
900 reply
->win
= msg
->win
;
901 reply
->msg
= msg
->msg
;
902 reply
->wparam
= msg
->wparam
;
903 reply
->lparam
= msg
->lparam
;
906 reply
->time
= msg
->time
;
908 if (msg
->data
) set_reply_data_ptr( msg
->data
, msg
->data_size
);
910 list_remove( &msg
->entry
);
911 /* put the result on the receiver result stack */
915 result
->recv_next
= queue
->recv_result
;
916 queue
->recv_result
= result
;
919 if (list_empty( &queue
->msg_list
[SEND_MESSAGE
] )) clear_queue_bits( queue
, QS_SENDMESSAGE
);
922 /* set the result of the current received message */
923 static void reply_message( struct msg_queue
*queue
, lparam_t result
,
924 unsigned int error
, int remove
, const void *data
, data_size_t len
)
926 struct message_result
*res
= queue
->recv_result
;
930 queue
->recv_result
= res
->recv_next
;
931 res
->receiver
= NULL
;
932 if (!res
->sender
&& !res
->hardware_msg
) /* no one waiting for it */
940 if (len
&& (res
->data
= memdup( data
, len
))) res
->data_size
= len
;
941 store_message_result( res
, result
, error
);
945 static int match_window( user_handle_t win
, user_handle_t msg_win
)
948 if (win
== -1 || win
== 1) return !msg_win
;
949 if (msg_win
== win
) return 1;
950 return is_child_window( win
, msg_win
);
953 /* retrieve a posted message */
954 static int get_posted_message( struct msg_queue
*queue
, user_handle_t win
,
955 unsigned int first
, unsigned int last
, unsigned int flags
,
956 struct get_message_reply
*reply
)
960 /* check against the filters */
961 LIST_FOR_EACH_ENTRY( msg
, &queue
->msg_list
[POST_MESSAGE
], struct message
, entry
)
963 if (!match_window( win
, msg
->win
)) continue;
964 if (!check_msg_filter( msg
->msg
, first
, last
)) continue;
965 goto found
; /* found one */
969 /* return it to the app */
971 reply
->total
= msg
->data_size
;
972 if (msg
->data_size
> get_reply_max_size())
974 set_error( STATUS_BUFFER_OVERFLOW
);
977 reply
->type
= msg
->type
;
978 reply
->win
= msg
->win
;
979 reply
->msg
= msg
->msg
;
980 reply
->wparam
= msg
->wparam
;
981 reply
->lparam
= msg
->lparam
;
984 reply
->time
= msg
->time
;
986 if (flags
& PM_REMOVE
)
990 set_reply_data_ptr( msg
->data
, msg
->data_size
);
994 remove_queue_message( queue
, msg
, POST_MESSAGE
);
996 else if (msg
->data
) set_reply_data( msg
->data
, msg
->data_size
);
1001 static int get_quit_message( struct msg_queue
*queue
, unsigned int flags
,
1002 struct get_message_reply
*reply
)
1004 if (queue
->quit_message
)
1007 reply
->type
= MSG_POSTED
;
1009 reply
->msg
= WM_QUIT
;
1010 reply
->wparam
= queue
->exit_code
;
1013 get_message_defaults( queue
, &reply
->x
, &reply
->y
, &reply
->time
);
1015 if (flags
& PM_REMOVE
)
1017 queue
->quit_message
= 0;
1018 if (list_empty( &queue
->msg_list
[POST_MESSAGE
] ))
1019 clear_queue_bits( queue
, QS_POSTMESSAGE
|QS_ALLPOSTMESSAGE
);
1027 /* empty a message list and free all the messages */
1028 static void empty_msg_list( struct list
*list
)
1032 while ((ptr
= list_head( list
)) != NULL
)
1034 struct message
*msg
= LIST_ENTRY( ptr
, struct message
, entry
);
1035 list_remove( &msg
->entry
);
1036 free_message( msg
);
1040 /* cleanup all pending results when deleting a queue */
1041 static void cleanup_results( struct msg_queue
*queue
)
1045 while ((entry
= list_head( &queue
->send_result
)) != NULL
)
1047 remove_result_from_sender( LIST_ENTRY( entry
, struct message_result
, sender_entry
) );
1050 while ((entry
= list_head( &queue
->callback_result
)) != NULL
)
1052 remove_result_from_sender( LIST_ENTRY( entry
, struct message_result
, sender_entry
) );
1055 while (queue
->recv_result
)
1056 reply_message( queue
, 0, STATUS_ACCESS_DENIED
/*FIXME*/, 1, NULL
, 0 );
1059 /* check if the thread owning the queue is hung (not checking for messages) */
1060 static int is_queue_hung( struct msg_queue
*queue
)
1062 struct wait_queue_entry
*entry
;
1064 if (current_time
- queue
->last_get_msg
<= 5 * TICKS_PER_SEC
)
1065 return 0; /* less than 5 seconds since last get message -> not hung */
1067 LIST_FOR_EACH_ENTRY( entry
, &queue
->obj
.wait_queue
, struct wait_queue_entry
, entry
)
1069 if (get_wait_queue_thread(entry
)->queue
== queue
)
1070 return 0; /* thread is waiting on queue -> not hung */
1075 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
)
1077 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
1078 struct process
*process
= get_wait_queue_thread(entry
)->process
;
1080 /* a thread can only wait on its own queue */
1081 if (get_wait_queue_thread(entry
)->queue
!= queue
)
1083 set_error( STATUS_ACCESS_DENIED
);
1086 if (process
->idle_event
&& !(queue
->wake_mask
& QS_SMRESULT
)) set_event( process
->idle_event
);
1088 if (queue
->fd
&& list_empty( &obj
->wait_queue
)) /* first on the queue */
1089 set_fd_events( queue
->fd
, POLLIN
);
1090 add_queue( obj
, entry
);
1094 static void msg_queue_remove_queue(struct object
*obj
, struct wait_queue_entry
*entry
)
1096 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
1098 remove_queue( obj
, entry
);
1099 if (queue
->fd
&& list_empty( &obj
->wait_queue
)) /* last on the queue is gone */
1100 set_fd_events( queue
->fd
, 0 );
1103 static void msg_queue_dump( struct object
*obj
, int verbose
)
1105 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
1106 fprintf( stderr
, "Msg queue bits=%x mask=%x\n",
1107 queue
->wake_bits
, queue
->wake_mask
);
1110 static int msg_queue_signaled( struct object
*obj
, struct wait_queue_entry
*entry
)
1112 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
1117 if ((ret
= check_fd_events( queue
->fd
, POLLIN
)))
1118 /* stop waiting on select() if we are signaled */
1119 set_fd_events( queue
->fd
, 0 );
1120 else if (!list_empty( &obj
->wait_queue
))
1121 /* restart waiting on poll() if we are no longer signaled */
1122 set_fd_events( queue
->fd
, POLLIN
);
1124 return ret
|| is_signaled( queue
);
1127 static void msg_queue_satisfied( struct object
*obj
, struct wait_queue_entry
*entry
)
1129 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
1130 queue
->wake_mask
= 0;
1131 queue
->changed_mask
= 0;
1134 static void msg_queue_destroy( struct object
*obj
)
1136 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
1138 struct hotkey
*hotkey
, *hotkey2
;
1141 cleanup_results( queue
);
1142 for (i
= 0; i
< NB_MSG_KINDS
; i
++) empty_msg_list( &queue
->msg_list
[i
] );
1144 LIST_FOR_EACH_ENTRY_SAFE( hotkey
, hotkey2
, &queue
->input
->desktop
->hotkeys
, struct hotkey
, entry
)
1146 if (hotkey
->queue
== queue
)
1148 list_remove( &hotkey
->entry
);
1153 while ((ptr
= list_head( &queue
->pending_timers
)))
1155 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
1156 list_remove( &timer
->entry
);
1159 while ((ptr
= list_head( &queue
->expired_timers
)))
1161 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
1162 list_remove( &timer
->entry
);
1165 if (queue
->timeout
) remove_timeout_user( queue
->timeout
);
1166 queue
->input
->cursor_count
-= queue
->cursor_count
;
1167 if (queue
->keystate_lock
) unlock_input_keystate( queue
->input
);
1168 release_object( queue
->input
);
1169 if (queue
->hooks
) release_object( queue
->hooks
);
1170 if (queue
->fd
) release_object( queue
->fd
);
1173 static void msg_queue_poll_event( struct fd
*fd
, int event
)
1175 struct msg_queue
*queue
= get_fd_user( fd
);
1176 assert( queue
->obj
.ops
== &msg_queue_ops
);
1178 if (event
& (POLLERR
| POLLHUP
)) set_fd_events( fd
, -1 );
1179 else set_fd_events( queue
->fd
, 0 );
1180 wake_up( &queue
->obj
, 0 );
1183 static void thread_input_dump( struct object
*obj
, int verbose
)
1185 struct thread_input
*input
= (struct thread_input
*)obj
;
1186 fprintf( stderr
, "Thread input focus=%08x capture=%08x active=%08x\n",
1187 input
->focus
, input
->capture
, input
->active
);
1190 static void thread_input_destroy( struct object
*obj
)
1192 struct thread_input
*input
= (struct thread_input
*)obj
;
1193 struct desktop
*desktop
;
1195 empty_msg_list( &input
->msg_list
);
1196 if ((desktop
= input
->desktop
))
1198 if (desktop
->foreground_input
== input
) desktop
->foreground_input
= NULL
;
1199 release_object( desktop
);
1203 /* fix the thread input data when a window is destroyed */
1204 static inline void thread_input_cleanup_window( struct msg_queue
*queue
, user_handle_t window
)
1206 struct thread_input
*input
= queue
->input
;
1208 if (window
== input
->focus
) input
->focus
= 0;
1209 if (window
== input
->capture
) input
->capture
= 0;
1210 if (window
== input
->active
) input
->active
= 0;
1211 if (window
== input
->menu_owner
) input
->menu_owner
= 0;
1212 if (window
== input
->move_size
) input
->move_size
= 0;
1213 if (window
== input
->caret
) set_caret_window( input
, 0 );
1216 /* check if the specified window can be set in the input data of a given queue */
1217 static int check_queue_input_window( struct msg_queue
*queue
, user_handle_t window
)
1219 struct thread
*thread
;
1222 if (!window
) return 1; /* we can always clear the data */
1224 if ((thread
= get_window_thread( window
)))
1226 ret
= (queue
->input
== thread
->queue
->input
);
1227 if (!ret
) set_error( STATUS_ACCESS_DENIED
);
1228 release_object( thread
);
1230 else set_error( STATUS_INVALID_HANDLE
);
1235 /* make sure the specified thread has a queue */
1236 int init_thread_queue( struct thread
*thread
)
1238 if (thread
->queue
) return 1;
1239 return (create_msg_queue( thread
, NULL
) != NULL
);
1242 /* attach two thread input data structures */
1243 int attach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
1245 struct desktop
*desktop
;
1246 struct thread_input
*input
;
1249 if (!thread_to
->queue
&& !(thread_to
->queue
= create_msg_queue( thread_to
, NULL
))) return 0;
1250 if (!(desktop
= get_thread_desktop( thread_from
, 0 ))) return 0;
1251 input
= (struct thread_input
*)grab_object( thread_to
->queue
->input
);
1252 if (input
->desktop
!= desktop
)
1254 set_error( STATUS_ACCESS_DENIED
);
1255 release_object( input
);
1256 release_object( desktop
);
1259 release_object( desktop
);
1261 if (thread_from
->queue
)
1263 if (!input
->focus
) input
->focus
= thread_from
->queue
->input
->focus
;
1264 if (!input
->active
) input
->active
= thread_from
->queue
->input
->active
;
1267 ret
= assign_thread_input( thread_from
, input
);
1268 if (ret
) memset( input
->keystate
, 0, sizeof(input
->keystate
) );
1269 release_object( input
);
1273 /* detach two thread input data structures */
1274 void detach_thread_input( struct thread
*thread_from
)
1276 struct thread
*thread
;
1277 struct thread_input
*input
, *old_input
= thread_from
->queue
->input
;
1279 if ((input
= create_thread_input( thread_from
)))
1281 if (old_input
->focus
&& (thread
= get_window_thread( old_input
->focus
)))
1283 if (thread
== thread_from
)
1285 input
->focus
= old_input
->focus
;
1286 old_input
->focus
= 0;
1288 release_object( thread
);
1290 if (old_input
->active
&& (thread
= get_window_thread( old_input
->active
)))
1292 if (thread
== thread_from
)
1294 input
->active
= old_input
->active
;
1295 old_input
->active
= 0;
1297 release_object( thread
);
1299 assign_thread_input( thread_from
, input
);
1300 release_object( input
);
1305 /* set the next timer to expire */
1306 static void set_next_timer( struct msg_queue
*queue
)
1312 remove_timeout_user( queue
->timeout
);
1313 queue
->timeout
= NULL
;
1315 if ((ptr
= list_head( &queue
->pending_timers
)))
1317 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
1318 queue
->timeout
= add_timeout_user( abstime_to_timeout(timer
->when
), timer_callback
, queue
);
1320 /* set/clear QS_TIMER bit */
1321 if (list_empty( &queue
->expired_timers
))
1322 clear_queue_bits( queue
, QS_TIMER
);
1324 set_queue_bits( queue
, QS_TIMER
);
1327 /* find a timer from its window and id */
1328 static struct timer
*find_timer( struct msg_queue
*queue
, user_handle_t win
,
1329 unsigned int msg
, lparam_t id
)
1333 /* we need to search both lists */
1335 LIST_FOR_EACH( ptr
, &queue
->pending_timers
)
1337 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
1338 if (timer
->win
== win
&& timer
->msg
== msg
&& timer
->id
== id
) return timer
;
1340 LIST_FOR_EACH( ptr
, &queue
->expired_timers
)
1342 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
1343 if (timer
->win
== win
&& timer
->msg
== msg
&& timer
->id
== id
) return timer
;
1348 /* callback for the next timer expiration */
1349 static void timer_callback( void *private )
1351 struct msg_queue
*queue
= private;
1354 queue
->timeout
= NULL
;
1355 /* move on to the next timer */
1356 ptr
= list_head( &queue
->pending_timers
);
1358 list_add_tail( &queue
->expired_timers
, ptr
);
1359 set_next_timer( queue
);
1362 /* link a timer at its rightful place in the queue list */
1363 static void link_timer( struct msg_queue
*queue
, struct timer
*timer
)
1367 for (ptr
= queue
->pending_timers
.next
; ptr
!= &queue
->pending_timers
; ptr
= ptr
->next
)
1369 struct timer
*t
= LIST_ENTRY( ptr
, struct timer
, entry
);
1370 if (t
->when
<= timer
->when
) break;
1372 list_add_before( ptr
, &timer
->entry
);
1375 /* remove a timer from the queue timer list and free it */
1376 static void free_timer( struct msg_queue
*queue
, struct timer
*timer
)
1378 list_remove( &timer
->entry
);
1380 set_next_timer( queue
);
1383 /* restart an expired timer */
1384 static void restart_timer( struct msg_queue
*queue
, struct timer
*timer
)
1386 list_remove( &timer
->entry
);
1387 while (-timer
->when
<= monotonic_time
) timer
->when
-= (timeout_t
)timer
->rate
* 10000;
1388 link_timer( queue
, timer
);
1389 set_next_timer( queue
);
1392 /* find an expired timer matching the filtering parameters */
1393 static struct timer
*find_expired_timer( struct msg_queue
*queue
, user_handle_t win
,
1394 unsigned int get_first
, unsigned int get_last
,
1399 LIST_FOR_EACH( ptr
, &queue
->expired_timers
)
1401 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
1402 if (win
&& timer
->win
!= win
) continue;
1403 if (check_msg_filter( timer
->msg
, get_first
, get_last
))
1405 if (remove
) restart_timer( queue
, timer
);
1413 static struct timer
*set_timer( struct msg_queue
*queue
, unsigned int rate
)
1415 struct timer
*timer
= mem_alloc( sizeof(*timer
) );
1418 timer
->rate
= max( rate
, 1 );
1419 timer
->when
= -monotonic_time
- (timeout_t
)timer
->rate
* 10000;
1420 link_timer( queue
, timer
);
1421 /* check if we replaced the next timer */
1422 if (list_head( &queue
->pending_timers
) == &timer
->entry
) set_next_timer( queue
);
1427 /* change the input key state for a given key */
1428 static void set_input_key_state( unsigned char *keystate
, unsigned char key
, int down
)
1432 if (!(keystate
[key
] & 0x80)) keystate
[key
] ^= 0x01;
1433 keystate
[key
] |= down
;
1435 else keystate
[key
] &= ~0x80;
1438 /* update the input key state for a keyboard message */
1439 static void update_input_key_state( struct desktop
*desktop
, unsigned char *keystate
,
1440 unsigned int msg
, lparam_t wparam
)
1447 case WM_LBUTTONDOWN
:
1448 down
= (keystate
== desktop
->keystate
) ? 0xc0 : 0x80;
1451 set_input_key_state( keystate
, VK_LBUTTON
, down
);
1453 case WM_MBUTTONDOWN
:
1454 down
= (keystate
== desktop
->keystate
) ? 0xc0 : 0x80;
1457 set_input_key_state( keystate
, VK_MBUTTON
, down
);
1459 case WM_RBUTTONDOWN
:
1460 down
= (keystate
== desktop
->keystate
) ? 0xc0 : 0x80;
1463 set_input_key_state( keystate
, VK_RBUTTON
, down
);
1465 case WM_XBUTTONDOWN
:
1466 down
= (keystate
== desktop
->keystate
) ? 0xc0 : 0x80;
1469 if (wparam
>> 16 == XBUTTON1
) set_input_key_state( keystate
, VK_XBUTTON1
, down
);
1470 else if (wparam
>> 16 == XBUTTON2
) set_input_key_state( keystate
, VK_XBUTTON2
, down
);
1474 down
= (keystate
== desktop
->keystate
) ? 0xc0 : 0x80;
1478 key
= (unsigned char)wparam
;
1479 set_input_key_state( keystate
, key
, down
);
1484 down
= (keystate
[VK_LCONTROL
] | keystate
[VK_RCONTROL
]) & 0x80;
1485 set_input_key_state( keystate
, VK_CONTROL
, down
);
1489 down
= (keystate
[VK_LMENU
] | keystate
[VK_RMENU
]) & 0x80;
1490 set_input_key_state( keystate
, VK_MENU
, down
);
1494 down
= (keystate
[VK_LSHIFT
] | keystate
[VK_RSHIFT
]) & 0x80;
1495 set_input_key_state( keystate
, VK_SHIFT
, down
);
1502 /* update the desktop key state according to a mouse message flags */
1503 static void update_desktop_mouse_state( struct desktop
*desktop
, unsigned int flags
, lparam_t wparam
)
1505 if (flags
& MOUSEEVENTF_LEFTDOWN
)
1506 update_input_key_state( desktop
, desktop
->keystate
, WM_LBUTTONDOWN
, wparam
);
1507 if (flags
& MOUSEEVENTF_LEFTUP
)
1508 update_input_key_state( desktop
, desktop
->keystate
, WM_LBUTTONUP
, wparam
);
1509 if (flags
& MOUSEEVENTF_RIGHTDOWN
)
1510 update_input_key_state( desktop
, desktop
->keystate
, WM_RBUTTONDOWN
, wparam
);
1511 if (flags
& MOUSEEVENTF_RIGHTUP
)
1512 update_input_key_state( desktop
, desktop
->keystate
, WM_RBUTTONUP
, wparam
);
1513 if (flags
& MOUSEEVENTF_MIDDLEDOWN
)
1514 update_input_key_state( desktop
, desktop
->keystate
, WM_MBUTTONDOWN
, wparam
);
1515 if (flags
& MOUSEEVENTF_MIDDLEUP
)
1516 update_input_key_state( desktop
, desktop
->keystate
, WM_MBUTTONUP
, wparam
);
1517 if (flags
& MOUSEEVENTF_XDOWN
)
1518 update_input_key_state( desktop
, desktop
->keystate
, WM_XBUTTONDOWN
, wparam
);
1519 if (flags
& MOUSEEVENTF_XUP
)
1520 update_input_key_state( desktop
, desktop
->keystate
, WM_XBUTTONUP
, wparam
);
1523 /* release the hardware message currently being processed by the given thread */
1524 static void release_hardware_message( struct msg_queue
*queue
, unsigned int hw_id
)
1526 struct thread_input
*input
= queue
->input
;
1527 struct message
*msg
, *other
;
1530 LIST_FOR_EACH_ENTRY( msg
, &input
->msg_list
, struct message
, entry
)
1532 if (msg
->unique_id
== hw_id
) break;
1534 if (&msg
->entry
== &input
->msg_list
) return; /* not found */
1536 /* clear the queue bit for that message */
1537 clr_bit
= get_hardware_msg_bit( msg
->msg
);
1538 LIST_FOR_EACH_ENTRY( other
, &input
->msg_list
, struct message
, entry
)
1540 if (other
!= msg
&& get_hardware_msg_bit( other
->msg
) == clr_bit
)
1546 if (clr_bit
) clear_queue_bits( queue
, clr_bit
);
1548 update_input_key_state( input
->desktop
, input
->keystate
, msg
->msg
, msg
->wparam
);
1549 list_remove( &msg
->entry
);
1550 free_message( msg
);
1553 static int queue_hotkey_message( struct desktop
*desktop
, struct message
*msg
)
1555 struct hotkey
*hotkey
;
1556 unsigned int modifiers
= 0;
1558 if (msg
->msg
!= WM_KEYDOWN
&& msg
->msg
!= WM_SYSKEYDOWN
) return 0;
1560 if (desktop
->keystate
[VK_MENU
] & 0x80) modifiers
|= MOD_ALT
;
1561 if (desktop
->keystate
[VK_CONTROL
] & 0x80) modifiers
|= MOD_CONTROL
;
1562 if (desktop
->keystate
[VK_SHIFT
] & 0x80) modifiers
|= MOD_SHIFT
;
1563 if ((desktop
->keystate
[VK_LWIN
] & 0x80) || (desktop
->keystate
[VK_RWIN
] & 0x80)) modifiers
|= MOD_WIN
;
1565 LIST_FOR_EACH_ENTRY( hotkey
, &desktop
->hotkeys
, struct hotkey
, entry
)
1567 if (hotkey
->vkey
!= msg
->wparam
) continue;
1568 if ((hotkey
->flags
& (MOD_ALT
|MOD_CONTROL
|MOD_SHIFT
|MOD_WIN
)) == modifiers
) goto found
;
1574 msg
->type
= MSG_POSTED
;
1575 msg
->win
= hotkey
->win
;
1576 msg
->msg
= WM_HOTKEY
;
1577 msg
->wparam
= hotkey
->id
;
1578 msg
->lparam
= ((hotkey
->vkey
& 0xffff) << 16) | modifiers
;
1584 list_add_tail( &hotkey
->queue
->msg_list
[POST_MESSAGE
], &msg
->entry
);
1585 set_queue_bits( hotkey
->queue
, QS_POSTMESSAGE
|QS_ALLPOSTMESSAGE
|QS_HOTKEY
);
1586 hotkey
->queue
->hotkey_count
++;
1590 /* find the window that should receive a given hardware message */
1591 static user_handle_t
find_hardware_message_window( struct desktop
*desktop
, struct thread_input
*input
,
1592 struct message
*msg
, unsigned int *msg_code
,
1593 struct thread
**thread
)
1595 user_handle_t win
= 0;
1598 *msg_code
= msg
->msg
;
1599 switch (get_hardware_msg_bit( msg
->msg
))
1602 if (!(win
= msg
->win
) && input
) win
= input
->focus
;
1605 if (input
&& !(win
= input
->focus
))
1607 win
= input
->active
;
1608 if (*msg_code
< WM_SYSKEYDOWN
) *msg_code
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
1612 case QS_MOUSEBUTTON
:
1613 if (!input
|| !(win
= input
->capture
))
1615 if (is_window_visible( msg
->win
) && !is_window_transparent( msg
->win
)) win
= msg
->win
;
1616 else win
= shallow_window_from_point( desktop
, msg
->x
, msg
->y
);
1617 *thread
= window_thread_from_point( win
, msg
->x
, msg
->y
);
1623 *thread
= get_window_thread( win
);
1627 static struct rawinput_device
*find_rawinput_device( struct process
*process
, unsigned short usage_page
, unsigned short usage
)
1629 struct rawinput_device
*device
, *end
;
1631 for (device
= process
->rawinput_devices
, end
= device
+ process
->rawinput_device_count
; device
!= end
; device
++)
1633 if (device
->usage_page
!= usage_page
|| device
->usage
!= usage
) continue;
1640 static void prepend_cursor_history( int x
, int y
, unsigned int time
, lparam_t info
)
1642 cursor_pos_t
*pos
= &cursor_history
[--cursor_history_latest
% ARRAY_SIZE(cursor_history
)];
1650 /* queue a hardware message into a given thread input */
1651 static void queue_hardware_message( struct desktop
*desktop
, struct message
*msg
, int always_queue
)
1654 struct thread
*thread
;
1655 struct thread_input
*input
;
1656 struct hardware_msg_data
*msg_data
= msg
->data
;
1657 unsigned int msg_code
;
1659 update_input_key_state( desktop
, desktop
->keystate
, msg
->msg
, msg
->wparam
);
1660 last_input_time
= get_tick_count();
1661 if (msg
->msg
!= WM_MOUSEMOVE
) always_queue
= 1;
1663 switch (get_hardware_msg_bit( msg
->msg
))
1666 if (queue_hotkey_message( desktop
, msg
)) return;
1667 if (desktop
->keystate
[VK_MENU
] & 0x80) msg
->lparam
|= KF_ALTDOWN
<< 16;
1668 if (msg
->wparam
== VK_SHIFT
|| msg
->wparam
== VK_LSHIFT
|| msg
->wparam
== VK_RSHIFT
)
1669 msg
->lparam
&= ~(KF_EXTENDED
<< 16);
1672 prepend_cursor_history( msg
->x
, msg
->y
, msg
->time
, msg_data
->info
);
1673 if (update_desktop_cursor_pos( desktop
, msg
->win
, msg
->x
, msg
->y
)) always_queue
= 1;
1675 case QS_MOUSEBUTTON
:
1676 if (desktop
->keystate
[VK_LBUTTON
] & 0x80) msg
->wparam
|= MK_LBUTTON
;
1677 if (desktop
->keystate
[VK_MBUTTON
] & 0x80) msg
->wparam
|= MK_MBUTTON
;
1678 if (desktop
->keystate
[VK_RBUTTON
] & 0x80) msg
->wparam
|= MK_RBUTTON
;
1679 if (desktop
->keystate
[VK_SHIFT
] & 0x80) msg
->wparam
|= MK_SHIFT
;
1680 if (desktop
->keystate
[VK_CONTROL
] & 0x80) msg
->wparam
|= MK_CONTROL
;
1681 if (desktop
->keystate
[VK_XBUTTON1
] & 0x80) msg
->wparam
|= MK_XBUTTON1
;
1682 if (desktop
->keystate
[VK_XBUTTON2
] & 0x80) msg
->wparam
|= MK_XBUTTON2
;
1685 msg
->x
= desktop
->cursor
.x
;
1686 msg
->y
= desktop
->cursor
.y
;
1688 if (msg
->win
&& (thread
= get_window_thread( msg
->win
)))
1690 input
= thread
->queue
->input
;
1691 release_object( thread
);
1693 else input
= desktop
->foreground_input
;
1695 win
= find_hardware_message_window( desktop
, input
, msg
, &msg_code
, &thread
);
1696 if (!win
|| !thread
)
1698 if (input
) update_input_key_state( input
->desktop
, input
->keystate
, msg
->msg
, msg
->wparam
);
1699 free_message( msg
);
1702 input
= thread
->queue
->input
;
1704 if (!always_queue
|| merge_message( input
, msg
)) free_message( msg
);
1707 msg
->unique_id
= 0; /* will be set once we return it to the app */
1708 list_add_tail( &input
->msg_list
, &msg
->entry
);
1709 set_queue_bits( thread
->queue
, get_hardware_msg_bit( msg
->msg
) );
1711 release_object( thread
);
1714 /* send the low-level hook message for a given hardware message */
1715 static int send_hook_ll_message( struct desktop
*desktop
, struct message
*hardware_msg
,
1716 const hw_input_t
*input
, struct msg_queue
*sender
)
1718 struct thread
*hook_thread
;
1719 struct msg_queue
*queue
;
1720 struct message
*msg
;
1721 timeout_t timeout
= 2000 * -10000; /* FIXME: load from registry */
1722 int id
= (input
->type
== INPUT_MOUSE
) ? WH_MOUSE_LL
: WH_KEYBOARD_LL
;
1724 if (!(hook_thread
= get_first_global_hook( id
))) return 0;
1725 if (!(queue
= hook_thread
->queue
)) return 0;
1726 if (is_queue_hung( queue
)) return 0;
1728 if (!(msg
= mem_alloc( sizeof(*msg
) ))) return 0;
1730 msg
->type
= MSG_HOOK_LL
;
1733 msg
->wparam
= hardware_msg
->msg
;
1734 msg
->x
= hardware_msg
->x
;
1735 msg
->y
= hardware_msg
->y
;
1736 msg
->time
= hardware_msg
->time
;
1737 msg
->data_size
= hardware_msg
->data_size
;
1740 if (input
->type
== INPUT_KEYBOARD
)
1742 unsigned short vkey
= input
->kbd
.vkey
;
1743 if (input
->kbd
.flags
& KEYEVENTF_UNICODE
) vkey
= VK_PACKET
;
1744 msg
->lparam
= (input
->kbd
.scan
<< 16) | vkey
;
1746 else msg
->lparam
= input
->mouse
.data
<< 16;
1748 if (!(msg
->data
= memdup( hardware_msg
->data
, hardware_msg
->data_size
)) ||
1749 !(msg
->result
= alloc_message_result( sender
, queue
, msg
, timeout
)))
1751 free_message( msg
);
1754 msg
->result
->hardware_msg
= hardware_msg
;
1755 msg
->result
->desktop
= (struct desktop
*)grab_object( desktop
);
1756 list_add_tail( &queue
->msg_list
[SEND_MESSAGE
], &msg
->entry
);
1757 set_queue_bits( queue
, QS_SENDMESSAGE
);
1761 /* get the foreground thread for a desktop and a window receiving input */
1762 static struct thread
*get_foreground_thread( struct desktop
*desktop
, user_handle_t window
)
1764 /* if desktop has no foreground process, assume the receiving window is */
1765 if (desktop
->foreground_input
) return get_window_thread( desktop
->foreground_input
->focus
);
1766 if (window
) return get_window_thread( window
);
1770 struct rawinput_message
1772 struct thread
*foreground
;
1773 struct desktop
*desktop
;
1774 struct hw_msg_source source
;
1776 unsigned int message
;
1777 struct hardware_msg_data data
;
1778 const void *hid_report
;
1781 /* check if process is supposed to receive a WM_INPUT message and eventually queue it */
1782 static int queue_rawinput_message( struct process
* process
, void *arg
)
1784 const struct rawinput_message
* raw_msg
= arg
;
1785 const struct rawinput_device
*device
= NULL
;
1786 struct desktop
*target_desktop
= NULL
, *desktop
= NULL
;
1787 struct thread
*target_thread
= NULL
, *foreground
= NULL
;
1788 struct message
*msg
;
1789 data_size_t report_size
;
1790 int wparam
= RIM_INPUT
;
1792 if (raw_msg
->data
.rawinput
.type
== RIM_TYPEMOUSE
)
1793 device
= process
->rawinput_mouse
;
1794 else if (raw_msg
->data
.rawinput
.type
== RIM_TYPEKEYBOARD
)
1795 device
= process
->rawinput_kbd
;
1797 device
= find_rawinput_device( process
, raw_msg
->data
.rawinput
.hid
.usage_page
, raw_msg
->data
.rawinput
.hid
.usage
);
1798 if (!device
) return 0;
1800 if (raw_msg
->message
== WM_INPUT_DEVICE_CHANGE
&& !(device
->flags
& RIDEV_DEVNOTIFY
)) return 0;
1802 if (raw_msg
->desktop
) desktop
= (struct desktop
*)grab_object( raw_msg
->desktop
);
1803 else if (!(desktop
= get_desktop_obj( process
, process
->desktop
, 0 ))) goto done
;
1805 if (raw_msg
->foreground
) foreground
= (struct thread
*)grab_object( raw_msg
->foreground
);
1806 else if (!(foreground
= get_foreground_thread( desktop
, 0 ))) goto done
;
1808 if (process
!= foreground
->process
)
1810 if (raw_msg
->message
== WM_INPUT
&& !(device
->flags
& RIDEV_INPUTSINK
)) goto done
;
1811 if (!(target_thread
= get_window_thread( device
->target
))) goto done
;
1812 if (!(target_desktop
= get_thread_desktop( target_thread
, 0 ))) goto done
;
1813 if (target_desktop
!= desktop
) goto done
;
1814 wparam
= RIM_INPUTSINK
;
1817 if (raw_msg
->data
.rawinput
.type
!= RIM_TYPEHID
|| !raw_msg
->hid_report
) report_size
= 0;
1818 else report_size
= raw_msg
->data
.size
- sizeof(raw_msg
->data
);
1820 if (!(msg
= alloc_hardware_message( raw_msg
->data
.info
, raw_msg
->source
, raw_msg
->time
, report_size
)))
1823 msg
->win
= device
->target
;
1824 msg
->msg
= raw_msg
->message
;
1825 msg
->wparam
= wparam
;
1827 memcpy( msg
->data
, &raw_msg
->data
, sizeof(raw_msg
->data
) );
1828 if (report_size
) memcpy( (struct hardware_msg_data
*)msg
->data
+ 1, raw_msg
->hid_report
, report_size
);
1830 if (raw_msg
->message
== WM_INPUT_DEVICE_CHANGE
&& raw_msg
->data
.rawinput
.type
== RIM_TYPEHID
)
1832 msg
->wparam
= raw_msg
->data
.rawinput
.hid
.param
;
1833 msg
->lparam
= raw_msg
->data
.rawinput
.hid
.device
;
1836 queue_hardware_message( desktop
, msg
, 1 );
1839 if (target_thread
) release_object( target_thread
);
1840 if (target_desktop
) release_object( target_desktop
);
1841 if (foreground
) release_object( foreground
);
1842 if (desktop
) release_object( desktop
);
1846 /* queue a hardware message for a mouse event */
1847 static int queue_mouse_message( struct desktop
*desktop
, user_handle_t win
, const hw_input_t
*input
,
1848 unsigned int origin
, struct msg_queue
*sender
)
1850 const struct rawinput_device
*device
;
1851 struct hardware_msg_data
*msg_data
;
1852 struct rawinput_message raw_msg
;
1853 struct message
*msg
;
1854 struct thread
*foreground
;
1855 unsigned int i
, time
, flags
;
1856 struct hw_msg_source source
= { IMDT_MOUSE
, origin
};
1859 static const unsigned int messages
[] =
1861 WM_MOUSEMOVE
, /* 0x0001 = MOUSEEVENTF_MOVE */
1862 WM_LBUTTONDOWN
, /* 0x0002 = MOUSEEVENTF_LEFTDOWN */
1863 WM_LBUTTONUP
, /* 0x0004 = MOUSEEVENTF_LEFTUP */
1864 WM_RBUTTONDOWN
, /* 0x0008 = MOUSEEVENTF_RIGHTDOWN */
1865 WM_RBUTTONUP
, /* 0x0010 = MOUSEEVENTF_RIGHTUP */
1866 WM_MBUTTONDOWN
, /* 0x0020 = MOUSEEVENTF_MIDDLEDOWN */
1867 WM_MBUTTONUP
, /* 0x0040 = MOUSEEVENTF_MIDDLEUP */
1868 WM_XBUTTONDOWN
, /* 0x0080 = MOUSEEVENTF_XDOWN */
1869 WM_XBUTTONUP
, /* 0x0100 = MOUSEEVENTF_XUP */
1870 0, /* 0x0200 = unused */
1871 0, /* 0x0400 = unused */
1872 WM_MOUSEWHEEL
, /* 0x0800 = MOUSEEVENTF_WHEEL */
1873 WM_MOUSEHWHEEL
/* 0x1000 = MOUSEEVENTF_HWHEEL */
1876 desktop
->cursor
.last_change
= get_tick_count();
1877 flags
= input
->mouse
.flags
;
1878 time
= input
->mouse
.time
;
1879 if (!time
) time
= desktop
->cursor
.last_change
;
1881 if (flags
& MOUSEEVENTF_MOVE
)
1883 if (flags
& MOUSEEVENTF_ABSOLUTE
)
1887 if (flags
& ~(MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
) &&
1888 x
== desktop
->cursor
.x
&& y
== desktop
->cursor
.y
)
1889 flags
&= ~MOUSEEVENTF_MOVE
;
1893 x
= desktop
->cursor
.x
+ input
->mouse
.x
;
1894 y
= desktop
->cursor
.y
+ input
->mouse
.y
;
1899 x
= desktop
->cursor
.x
;
1900 y
= desktop
->cursor
.y
;
1903 if ((foreground
= get_foreground_thread( desktop
, win
)))
1905 memset( &raw_msg
, 0, sizeof(raw_msg
) );
1906 raw_msg
.foreground
= foreground
;
1907 raw_msg
.desktop
= desktop
;
1908 raw_msg
.source
= source
;
1909 raw_msg
.time
= time
;
1910 raw_msg
.message
= WM_INPUT
;
1912 msg_data
= &raw_msg
.data
;
1913 msg_data
->info
= input
->mouse
.info
;
1914 msg_data
->size
= sizeof(*msg_data
);
1915 msg_data
->flags
= flags
;
1916 msg_data
->rawinput
.type
= RIM_TYPEMOUSE
;
1917 msg_data
->rawinput
.mouse
.x
= x
- desktop
->cursor
.x
;
1918 msg_data
->rawinput
.mouse
.y
= y
- desktop
->cursor
.y
;
1919 msg_data
->rawinput
.mouse
.data
= input
->mouse
.data
;
1921 enum_processes( queue_rawinput_message
, &raw_msg
);
1922 release_object( foreground
);
1925 if ((device
= current
->process
->rawinput_mouse
) && (device
->flags
& RIDEV_NOLEGACY
))
1927 if (flags
& MOUSEEVENTF_MOVE
) update_desktop_cursor_pos( desktop
, win
, x
, y
);
1928 update_desktop_mouse_state( desktop
, flags
, input
->mouse
.data
<< 16 );
1932 for (i
= 0; i
< ARRAY_SIZE( messages
); i
++)
1934 if (!messages
[i
]) continue;
1935 if (!(flags
& (1 << i
))) continue;
1938 if (!(msg
= alloc_hardware_message( input
->mouse
.info
, source
, time
, 0 ))) return 0;
1939 msg_data
= msg
->data
;
1941 msg
->win
= get_user_full_handle( win
);
1942 msg
->msg
= messages
[i
];
1943 msg
->wparam
= input
->mouse
.data
<< 16;
1947 if (origin
== IMO_INJECTED
) msg_data
->flags
= LLMHF_INJECTED
;
1949 /* specify a sender only when sending the last message */
1950 if (!(flags
& ((1 << ARRAY_SIZE( messages
)) - 1)))
1952 if (!(wait
= send_hook_ll_message( desktop
, msg
, input
, sender
)))
1953 queue_hardware_message( desktop
, msg
, 0 );
1955 else if (!send_hook_ll_message( desktop
, msg
, input
, NULL
))
1956 queue_hardware_message( desktop
, msg
, 0 );
1961 /* queue a hardware message for a keyboard event */
1962 static int queue_keyboard_message( struct desktop
*desktop
, user_handle_t win
, const hw_input_t
*input
,
1963 unsigned int origin
, struct msg_queue
*sender
)
1965 struct hw_msg_source source
= { IMDT_KEYBOARD
, origin
};
1966 const struct rawinput_device
*device
;
1967 struct hardware_msg_data
*msg_data
;
1968 struct rawinput_message raw_msg
;
1969 struct message
*msg
;
1970 struct thread
*foreground
;
1971 unsigned char vkey
= input
->kbd
.vkey
;
1972 unsigned int message_code
, time
;
1975 if (!(time
= input
->kbd
.time
)) time
= get_tick_count();
1977 if (!(input
->kbd
.flags
& KEYEVENTF_UNICODE
))
1984 vkey
= (input
->kbd
.flags
& KEYEVENTF_EXTENDEDKEY
) ? VK_RMENU
: VK_LMENU
;
1989 vkey
= (input
->kbd
.flags
& KEYEVENTF_EXTENDEDKEY
) ? VK_RCONTROL
: VK_LCONTROL
;
1994 vkey
= (input
->kbd
.flags
& KEYEVENTF_EXTENDEDKEY
) ? VK_RSHIFT
: VK_LSHIFT
;
1999 message_code
= (input
->kbd
.flags
& KEYEVENTF_KEYUP
) ? WM_KEYUP
: WM_KEYDOWN
;
2004 if (input
->kbd
.flags
& KEYEVENTF_KEYUP
)
2006 /* send WM_SYSKEYUP if Alt still pressed and no other key in between */
2007 /* we use 0x02 as a flag to track if some other SYSKEYUP was sent already */
2008 if ((desktop
->keystate
[VK_MENU
] & 0x82) != 0x82) break;
2009 message_code
= WM_SYSKEYUP
;
2010 desktop
->keystate
[VK_MENU
] &= ~0x02;
2014 /* send WM_SYSKEYDOWN for Alt except with Ctrl */
2015 if (desktop
->keystate
[VK_CONTROL
] & 0x80) break;
2016 message_code
= WM_SYSKEYDOWN
;
2017 desktop
->keystate
[VK_MENU
] |= 0x02;
2023 /* send WM_SYSKEYUP on release if Alt still pressed */
2024 if (!(input
->kbd
.flags
& KEYEVENTF_KEYUP
)) break;
2025 if (!(desktop
->keystate
[VK_MENU
] & 0x80)) break;
2026 message_code
= WM_SYSKEYUP
;
2027 desktop
->keystate
[VK_MENU
] &= ~0x02;
2031 /* send WM_SYSKEY for Alt-anykey and for F10 */
2032 if (desktop
->keystate
[VK_CONTROL
] & 0x80) break;
2033 if (!(desktop
->keystate
[VK_MENU
] & 0x80)) break;
2036 message_code
= (input
->kbd
.flags
& KEYEVENTF_KEYUP
) ? WM_SYSKEYUP
: WM_SYSKEYDOWN
;
2037 desktop
->keystate
[VK_MENU
] &= ~0x02;
2041 if ((foreground
= get_foreground_thread( desktop
, win
)))
2043 memset( &raw_msg
, 0, sizeof(raw_msg
) );
2044 raw_msg
.foreground
= foreground
;
2045 raw_msg
.desktop
= desktop
;
2046 raw_msg
.source
= source
;
2047 raw_msg
.time
= time
;
2048 raw_msg
.message
= WM_INPUT
;
2050 msg_data
= &raw_msg
.data
;
2051 msg_data
->info
= input
->kbd
.info
;
2052 msg_data
->size
= sizeof(*msg_data
);
2053 msg_data
->flags
= input
->kbd
.flags
;
2054 msg_data
->rawinput
.type
= RIM_TYPEKEYBOARD
;
2055 msg_data
->rawinput
.kbd
.message
= message_code
;
2056 msg_data
->rawinput
.kbd
.vkey
= vkey
;
2057 msg_data
->rawinput
.kbd
.scan
= input
->kbd
.scan
;
2059 enum_processes( queue_rawinput_message
, &raw_msg
);
2060 release_object( foreground
);
2063 if ((device
= current
->process
->rawinput_kbd
) && (device
->flags
& RIDEV_NOLEGACY
))
2065 update_input_key_state( desktop
, desktop
->keystate
, message_code
, vkey
);
2069 if (!(msg
= alloc_hardware_message( input
->kbd
.info
, source
, time
, 0 ))) return 0;
2070 msg_data
= msg
->data
;
2072 msg
->win
= get_user_full_handle( win
);
2073 msg
->msg
= message_code
;
2074 msg
->lparam
= (input
->kbd
.scan
<< 16) | 1u; /* repeat count */
2075 if (origin
== IMO_INJECTED
) msg_data
->flags
= LLKHF_INJECTED
;
2077 if (input
->kbd
.flags
& KEYEVENTF_UNICODE
&& !vkey
)
2079 msg
->wparam
= VK_PACKET
;
2083 unsigned int flags
= 0;
2084 if (input
->kbd
.flags
& KEYEVENTF_EXTENDEDKEY
) flags
|= KF_EXTENDED
;
2085 /* FIXME: set KF_DLGMODE and KF_MENUMODE when needed */
2086 if (input
->kbd
.flags
& KEYEVENTF_KEYUP
) flags
|= KF_REPEAT
| KF_UP
;
2087 else if (desktop
->keystate
[vkey
] & 0x80) flags
|= KF_REPEAT
;
2090 msg
->lparam
|= flags
<< 16;
2091 msg_data
->flags
|= (flags
& (KF_EXTENDED
| KF_ALTDOWN
| KF_UP
)) >> 8;
2094 if (!(wait
= send_hook_ll_message( desktop
, msg
, input
, sender
)))
2095 queue_hardware_message( desktop
, msg
, 1 );
2100 /* queue a hardware message for a custom type of event */
2101 static void queue_custom_hardware_message( struct desktop
*desktop
, user_handle_t win
,
2102 unsigned int origin
, const hw_input_t
*input
)
2104 struct hw_msg_source source
= { IMDT_UNAVAILABLE
, origin
};
2105 struct hardware_msg_data
*msg_data
;
2106 struct rawinput_message raw_msg
;
2107 struct message
*msg
;
2108 data_size_t report_size
= 0;
2110 switch (input
->hw
.msg
)
2113 case WM_INPUT_DEVICE_CHANGE
:
2114 memset( &raw_msg
, 0, sizeof(raw_msg
) );
2115 raw_msg
.source
= source
;
2116 raw_msg
.time
= get_tick_count();
2117 raw_msg
.message
= input
->hw
.msg
;
2119 if (input
->hw
.rawinput
.type
== RIM_TYPEHID
)
2121 raw_msg
.hid_report
= get_req_data();
2122 report_size
= input
->hw
.rawinput
.hid
.length
* input
->hw
.rawinput
.hid
.count
;
2125 if (report_size
!= get_req_data_size())
2127 set_error( STATUS_INVALID_PARAMETER
);
2131 msg_data
= &raw_msg
.data
;
2132 msg_data
->size
= sizeof(*msg_data
) + report_size
;
2133 msg_data
->rawinput
= input
->hw
.rawinput
;
2135 enum_processes( queue_rawinput_message
, &raw_msg
);
2139 if (!(msg
= alloc_hardware_message( 0, source
, get_tick_count(), 0 ))) return;
2141 msg
->win
= get_user_full_handle( win
);
2142 msg
->msg
= input
->hw
.msg
;
2144 msg
->lparam
= input
->hw
.lparam
;
2145 msg
->x
= desktop
->cursor
.x
;
2146 msg
->y
= desktop
->cursor
.y
;
2148 queue_hardware_message( desktop
, msg
, 1 );
2151 /* check message filter for a hardware message */
2152 static int check_hw_message_filter( user_handle_t win
, unsigned int msg_code
,
2153 user_handle_t filter_win
, unsigned int first
, unsigned int last
)
2155 switch (get_hardware_msg_bit( msg_code
))
2158 /* we can only test the window for a keyboard message since the
2159 * dest window for a mouse message depends on hittest */
2160 if (filter_win
&& win
!= filter_win
&& !is_child_window( filter_win
, win
))
2162 /* the message code is final for a keyboard message, we can simply check it */
2163 return check_msg_filter( msg_code
, first
, last
);
2166 case QS_MOUSEBUTTON
:
2167 /* we need to check all possible values that the message can have in the end */
2168 if (check_msg_filter( msg_code
, first
, last
)) return 1;
2169 if (msg_code
== WM_MOUSEWHEEL
) return 0; /* no other possible value for this one */
2171 /* all other messages can become non-client messages */
2172 if (check_msg_filter( msg_code
+ (WM_NCMOUSEFIRST
- WM_MOUSEFIRST
), first
, last
)) return 1;
2174 /* clicks can become double-clicks or non-client double-clicks */
2175 if (msg_code
== WM_LBUTTONDOWN
|| msg_code
== WM_MBUTTONDOWN
||
2176 msg_code
== WM_RBUTTONDOWN
|| msg_code
== WM_XBUTTONDOWN
)
2178 if (check_msg_filter( msg_code
+ (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
), first
, last
)) return 1;
2179 if (check_msg_filter( msg_code
+ (WM_NCLBUTTONDBLCLK
- WM_LBUTTONDOWN
), first
, last
)) return 1;
2184 return check_msg_filter( msg_code
, first
, last
);
2189 /* find a hardware message for the given queue */
2190 static int get_hardware_message( struct thread
*thread
, unsigned int hw_id
, user_handle_t filter_win
,
2191 unsigned int first
, unsigned int last
, unsigned int flags
,
2192 struct get_message_reply
*reply
)
2194 struct thread_input
*input
= thread
->queue
->input
;
2195 struct thread
*win_thread
;
2198 int clear_bits
, got_one
= 0;
2199 unsigned int msg_code
;
2201 ptr
= list_head( &input
->msg_list
);
2206 struct message
*msg
= LIST_ENTRY( ptr
, struct message
, entry
);
2207 if (msg
->unique_id
== hw_id
) break;
2208 ptr
= list_next( &input
->msg_list
, ptr
);
2210 if (!ptr
) ptr
= list_head( &input
->msg_list
);
2211 else ptr
= list_next( &input
->msg_list
, ptr
); /* start from the next one */
2214 if (ptr
== list_head( &input
->msg_list
))
2215 clear_bits
= QS_INPUT
;
2217 clear_bits
= 0; /* don't clear bits if we don't go through the whole list */
2221 struct message
*msg
= LIST_ENTRY( ptr
, struct message
, entry
);
2222 struct hardware_msg_data
*data
= msg
->data
;
2224 ptr
= list_next( &input
->msg_list
, ptr
);
2225 win
= find_hardware_message_window( input
->desktop
, input
, msg
, &msg_code
, &win_thread
);
2226 if (!win
|| !win_thread
)
2228 /* no window at all, remove it */
2229 update_input_key_state( input
->desktop
, input
->keystate
, msg
->msg
, msg
->wparam
);
2230 list_remove( &msg
->entry
);
2231 free_message( msg
);
2234 if (win_thread
!= thread
)
2236 if (win_thread
->queue
->input
== input
)
2238 /* wake the other thread */
2239 set_queue_bits( win_thread
->queue
, get_hardware_msg_bit( msg
->msg
) );
2244 /* for another thread input, drop it */
2245 update_input_key_state( input
->desktop
, input
->keystate
, msg
->msg
, msg
->wparam
);
2246 list_remove( &msg
->entry
);
2247 free_message( msg
);
2249 release_object( win_thread
);
2252 release_object( win_thread
);
2254 /* if we already got a message for another thread, or if it doesn't
2255 * match the filter we skip it */
2256 if (got_one
|| !check_hw_message_filter( win
, msg_code
, filter_win
, first
, last
))
2258 clear_bits
&= ~get_hardware_msg_bit( msg
->msg
);
2262 reply
->total
= msg
->data_size
;
2263 if (msg
->data_size
> get_reply_max_size())
2265 set_error( STATUS_BUFFER_OVERFLOW
);
2269 /* now we can return it */
2270 if (!msg
->unique_id
) msg
->unique_id
= get_unique_id();
2271 reply
->type
= MSG_HARDWARE
;
2273 reply
->msg
= msg_code
;
2274 reply
->wparam
= msg
->wparam
;
2275 reply
->lparam
= msg
->lparam
;
2278 reply
->time
= msg
->time
;
2280 data
->hw_id
= msg
->unique_id
;
2281 set_reply_data( msg
->data
, msg
->data_size
);
2282 if (get_hardware_msg_bit( msg
->msg
) == QS_RAWINPUT
&& (flags
& PM_REMOVE
))
2283 release_hardware_message( current
->queue
, data
->hw_id
);
2286 /* nothing found, clear the hardware queue bits */
2287 clear_queue_bits( thread
->queue
, clear_bits
);
2291 /* increment (or decrement if 'incr' is negative) the queue paint count */
2292 void inc_queue_paint_count( struct thread
*thread
, int incr
)
2294 struct msg_queue
*queue
= thread
->queue
;
2298 if ((queue
->paint_count
+= incr
) < 0) queue
->paint_count
= 0;
2300 if (queue
->paint_count
)
2301 set_queue_bits( queue
, QS_PAINT
);
2303 clear_queue_bits( queue
, QS_PAINT
);
2307 /* remove all messages and timers belonging to a certain window */
2308 void queue_cleanup_window( struct thread
*thread
, user_handle_t win
)
2310 struct msg_queue
*queue
= thread
->queue
;
2318 ptr
= list_head( &queue
->pending_timers
);
2321 struct list
*next
= list_next( &queue
->pending_timers
, ptr
);
2322 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
2323 if (timer
->win
== win
) free_timer( queue
, timer
);
2326 ptr
= list_head( &queue
->expired_timers
);
2329 struct list
*next
= list_next( &queue
->expired_timers
, ptr
);
2330 struct timer
*timer
= LIST_ENTRY( ptr
, struct timer
, entry
);
2331 if (timer
->win
== win
) free_timer( queue
, timer
);
2335 /* remove messages */
2336 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
2338 struct list
*ptr
, *next
;
2340 LIST_FOR_EACH_SAFE( ptr
, next
, &queue
->msg_list
[i
] )
2342 struct message
*msg
= LIST_ENTRY( ptr
, struct message
, entry
);
2343 if (msg
->win
== win
)
2345 if (msg
->msg
== WM_QUIT
&& !queue
->quit_message
)
2347 queue
->quit_message
= 1;
2348 queue
->exit_code
= msg
->wparam
;
2350 remove_queue_message( queue
, msg
, i
);
2355 thread_input_cleanup_window( queue
, win
);
2358 /* post a message to a window */
2359 void post_message( user_handle_t win
, unsigned int message
, lparam_t wparam
, lparam_t lparam
)
2361 struct message
*msg
;
2362 struct thread
*thread
= get_window_thread( win
);
2364 if (!thread
) return;
2366 if (thread
->queue
&& (msg
= mem_alloc( sizeof(*msg
) )))
2368 msg
->type
= MSG_POSTED
;
2369 msg
->win
= get_user_full_handle( win
);
2371 msg
->wparam
= wparam
;
2372 msg
->lparam
= lparam
;
2377 get_message_defaults( thread
->queue
, &msg
->x
, &msg
->y
, &msg
->time
);
2379 list_add_tail( &thread
->queue
->msg_list
[POST_MESSAGE
], &msg
->entry
);
2380 set_queue_bits( thread
->queue
, QS_POSTMESSAGE
|QS_ALLPOSTMESSAGE
);
2381 if (message
== WM_HOTKEY
)
2383 set_queue_bits( thread
->queue
, QS_HOTKEY
);
2384 thread
->queue
->hotkey_count
++;
2387 release_object( thread
);
2390 /* send a notify message to a window */
2391 void send_notify_message( user_handle_t win
, unsigned int message
, lparam_t wparam
, lparam_t lparam
)
2393 struct message
*msg
;
2394 struct thread
*thread
= get_window_thread( win
);
2396 if (!thread
) return;
2398 if (thread
->queue
&& (msg
= mem_alloc( sizeof(*msg
) )))
2400 msg
->type
= MSG_NOTIFY
;
2401 msg
->win
= get_user_full_handle( win
);
2403 msg
->wparam
= wparam
;
2404 msg
->lparam
= lparam
;
2409 get_message_defaults( thread
->queue
, &msg
->x
, &msg
->y
, &msg
->time
);
2411 list_add_tail( &thread
->queue
->msg_list
[SEND_MESSAGE
], &msg
->entry
);
2412 set_queue_bits( thread
->queue
, QS_SENDMESSAGE
);
2414 release_object( thread
);
2417 /* post a win event */
2418 void post_win_event( struct thread
*thread
, unsigned int event
,
2419 user_handle_t win
, unsigned int object_id
,
2420 unsigned int child_id
, client_ptr_t hook_proc
,
2421 const WCHAR
*module
, data_size_t module_size
,
2424 struct message
*msg
;
2426 if (thread
->queue
&& (msg
= mem_alloc( sizeof(*msg
) )))
2428 struct winevent_msg_data
*data
;
2430 msg
->type
= MSG_WINEVENT
;
2431 msg
->win
= get_user_full_handle( win
);
2433 msg
->wparam
= object_id
;
2434 msg
->lparam
= child_id
;
2435 msg
->time
= get_tick_count();
2438 if ((data
= malloc( sizeof(*data
) + module_size
)))
2441 data
->tid
= get_thread_id( current
);
2442 data
->hook_proc
= hook_proc
;
2443 memcpy( data
+ 1, module
, module_size
);
2446 msg
->data_size
= sizeof(*data
) + module_size
;
2448 if (debug_level
> 1)
2449 fprintf( stderr
, "post_win_event: tid %04x event %04x win %08x object_id %d child_id %d\n",
2450 get_thread_id(thread
), event
, win
, object_id
, child_id
);
2451 list_add_tail( &thread
->queue
->msg_list
[SEND_MESSAGE
], &msg
->entry
);
2452 set_queue_bits( thread
->queue
, QS_SENDMESSAGE
);
2459 /* free all hotkeys on a desktop, optionally filtering by window */
2460 void free_hotkeys( struct desktop
*desktop
, user_handle_t window
)
2462 struct hotkey
*hotkey
, *hotkey2
;
2464 LIST_FOR_EACH_ENTRY_SAFE( hotkey
, hotkey2
, &desktop
->hotkeys
, struct hotkey
, entry
)
2466 if (!window
|| hotkey
->win
== window
)
2468 list_remove( &hotkey
->entry
);
2475 /* check if the thread owning the window is hung */
2476 DECL_HANDLER(is_window_hung
)
2478 struct thread
*thread
;
2480 thread
= get_window_thread( req
->win
);
2483 reply
->is_hung
= is_queue_hung( thread
->queue
);
2484 release_object( thread
);
2486 else reply
->is_hung
= 0;
2490 /* get the message queue of the current thread */
2491 DECL_HANDLER(get_msg_queue
)
2493 struct msg_queue
*queue
= get_current_queue();
2496 if (queue
) reply
->handle
= alloc_handle( current
->process
, queue
, SYNCHRONIZE
, 0 );
2500 /* set the file descriptor associated to the current thread queue */
2501 DECL_HANDLER(set_queue_fd
)
2503 struct msg_queue
*queue
= get_current_queue();
2507 if (queue
->fd
) /* fd can only be set once */
2509 set_error( STATUS_ACCESS_DENIED
);
2512 if (!(file
= get_file_obj( current
->process
, req
->handle
, SYNCHRONIZE
))) return;
2514 if ((unix_fd
= get_file_unix_fd( file
)) != -1)
2516 if ((unix_fd
= dup( unix_fd
)) != -1)
2517 queue
->fd
= create_anonymous_fd( &msg_queue_fd_ops
, unix_fd
, &queue
->obj
, 0 );
2521 release_object( file
);
2525 /* set the current message queue wakeup mask */
2526 DECL_HANDLER(set_queue_mask
)
2528 struct msg_queue
*queue
= get_current_queue();
2532 queue
->wake_mask
= req
->wake_mask
;
2533 queue
->changed_mask
= req
->changed_mask
;
2534 reply
->wake_bits
= queue
->wake_bits
;
2535 reply
->changed_bits
= queue
->changed_bits
;
2536 if (is_signaled( queue
))
2538 /* if skip wait is set, do what would have been done in the subsequent wait */
2539 if (req
->skip_wait
) queue
->wake_mask
= queue
->changed_mask
= 0;
2540 else wake_up( &queue
->obj
, 0 );
2546 /* get the current message queue status */
2547 DECL_HANDLER(get_queue_status
)
2549 struct msg_queue
*queue
= current
->queue
;
2552 reply
->wake_bits
= queue
->wake_bits
;
2553 reply
->changed_bits
= queue
->changed_bits
;
2554 queue
->changed_bits
&= ~req
->clear_bits
;
2556 else reply
->wake_bits
= reply
->changed_bits
= 0;
2560 /* send a message to a thread queue */
2561 DECL_HANDLER(send_message
)
2563 struct message
*msg
;
2564 struct msg_queue
*send_queue
= get_current_queue();
2565 struct msg_queue
*recv_queue
= NULL
;
2566 struct thread
*thread
= NULL
;
2568 if (!(thread
= get_thread_from_id( req
->id
))) return;
2570 if (!(recv_queue
= thread
->queue
))
2572 set_error( STATUS_INVALID_PARAMETER
);
2573 release_object( thread
);
2576 if ((req
->flags
& SEND_MSG_ABORT_IF_HUNG
) && is_queue_hung(recv_queue
))
2578 set_error( STATUS_TIMEOUT
);
2579 release_object( thread
);
2583 if ((msg
= mem_alloc( sizeof(*msg
) )))
2585 msg
->type
= req
->type
;
2586 msg
->win
= get_user_full_handle( req
->win
);
2587 msg
->msg
= req
->msg
;
2588 msg
->wparam
= req
->wparam
;
2589 msg
->lparam
= req
->lparam
;
2592 msg
->data_size
= get_req_data_size();
2594 get_message_defaults( recv_queue
, &msg
->x
, &msg
->y
, &msg
->time
);
2596 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
2599 release_object( thread
);
2605 case MSG_OTHER_PROCESS
:
2609 if (!(msg
->result
= alloc_message_result( send_queue
, recv_queue
, msg
, req
->timeout
)))
2611 free_message( msg
);
2616 list_add_tail( &recv_queue
->msg_list
[SEND_MESSAGE
], &msg
->entry
);
2617 set_queue_bits( recv_queue
, QS_SENDMESSAGE
);
2620 list_add_tail( &recv_queue
->msg_list
[POST_MESSAGE
], &msg
->entry
);
2621 set_queue_bits( recv_queue
, QS_POSTMESSAGE
|QS_ALLPOSTMESSAGE
);
2622 if (msg
->msg
== WM_HOTKEY
)
2624 set_queue_bits( recv_queue
, QS_HOTKEY
);
2625 recv_queue
->hotkey_count
++;
2628 case MSG_HARDWARE
: /* should use send_hardware_message instead */
2629 case MSG_CALLBACK_RESULT
: /* cannot send this one */
2630 case MSG_HOOK_LL
: /* generated internally */
2632 set_error( STATUS_INVALID_PARAMETER
);
2637 release_object( thread
);
2640 /* send a hardware message to a thread queue */
2641 DECL_HANDLER(send_hardware_message
)
2643 struct thread
*thread
= NULL
;
2644 struct desktop
*desktop
;
2645 unsigned int origin
= (req
->flags
& SEND_HWMSG_INJECTED
? IMO_INJECTED
: IMO_HARDWARE
);
2646 struct msg_queue
*sender
= get_current_queue();
2648 if (!(desktop
= get_thread_desktop( current
, 0 ))) return;
2652 if (!(thread
= get_window_thread( req
->win
))) return;
2653 if (desktop
!= thread
->queue
->input
->desktop
)
2655 /* don't allow queuing events to a different desktop */
2656 release_object( desktop
);
2661 reply
->prev_x
= desktop
->cursor
.x
;
2662 reply
->prev_y
= desktop
->cursor
.y
;
2664 switch (req
->input
.type
)
2667 reply
->wait
= queue_mouse_message( desktop
, req
->win
, &req
->input
, origin
, sender
);
2669 case INPUT_KEYBOARD
:
2670 reply
->wait
= queue_keyboard_message( desktop
, req
->win
, &req
->input
, origin
, sender
);
2672 case INPUT_HARDWARE
:
2673 queue_custom_hardware_message( desktop
, req
->win
, origin
, &req
->input
);
2676 set_error( STATUS_INVALID_PARAMETER
);
2678 if (thread
) release_object( thread
);
2680 reply
->new_x
= desktop
->cursor
.x
;
2681 reply
->new_y
= desktop
->cursor
.y
;
2682 release_object( desktop
);
2685 /* post a quit message to the current queue */
2686 DECL_HANDLER(post_quit_message
)
2688 struct msg_queue
*queue
= get_current_queue();
2693 queue
->quit_message
= 1;
2694 queue
->exit_code
= req
->exit_code
;
2695 set_queue_bits( queue
, QS_POSTMESSAGE
|QS_ALLPOSTMESSAGE
);
2698 /* get a message from the current queue */
2699 DECL_HANDLER(get_message
)
2701 struct timer
*timer
;
2703 struct msg_queue
*queue
= get_current_queue();
2704 user_handle_t get_win
= get_user_full_handle( req
->get_win
);
2705 unsigned int filter
= req
->flags
>> 16;
2707 reply
->active_hooks
= get_active_hooks();
2709 if (get_win
&& get_win
!= 1 && get_win
!= -1 && !get_user_object( get_win
, USER_WINDOW
))
2711 set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
2716 queue
->last_get_msg
= current_time
;
2717 if (!filter
) filter
= QS_ALLINPUT
;
2719 /* first check for sent messages */
2720 if ((ptr
= list_head( &queue
->msg_list
[SEND_MESSAGE
] )))
2722 struct message
*msg
= LIST_ENTRY( ptr
, struct message
, entry
);
2723 receive_message( queue
, msg
, reply
);
2727 /* clear changed bits so we can wait on them if we don't find a message */
2728 if (filter
& QS_POSTMESSAGE
)
2730 queue
->changed_bits
&= ~(QS_POSTMESSAGE
| QS_HOTKEY
| QS_TIMER
);
2731 if (req
->get_first
== 0 && req
->get_last
== ~0U) queue
->changed_bits
&= ~QS_ALLPOSTMESSAGE
;
2733 if (filter
& QS_INPUT
) queue
->changed_bits
&= ~QS_INPUT
;
2734 if (filter
& QS_PAINT
) queue
->changed_bits
&= ~QS_PAINT
;
2736 /* then check for posted messages */
2737 if ((filter
& QS_POSTMESSAGE
) &&
2738 get_posted_message( queue
, get_win
, req
->get_first
, req
->get_last
, req
->flags
, reply
))
2741 if ((filter
& QS_HOTKEY
) && queue
->hotkey_count
&&
2742 req
->get_first
<= WM_HOTKEY
&& req
->get_last
>= WM_HOTKEY
&&
2743 get_posted_message( queue
, get_win
, WM_HOTKEY
, WM_HOTKEY
, req
->flags
, reply
))
2746 /* only check for quit messages if not posted messages pending */
2747 if ((filter
& QS_POSTMESSAGE
) && get_quit_message( queue
, req
->flags
, reply
))
2750 /* then check for any raw hardware message */
2751 if ((filter
& QS_INPUT
) &&
2752 filter_contains_hw_range( req
->get_first
, req
->get_last
) &&
2753 get_hardware_message( current
, req
->hw_id
, get_win
, req
->get_first
, req
->get_last
, req
->flags
, reply
))
2756 /* now check for WM_PAINT */
2757 if ((filter
& QS_PAINT
) &&
2758 queue
->paint_count
&&
2759 check_msg_filter( WM_PAINT
, req
->get_first
, req
->get_last
) &&
2760 (reply
->win
= find_window_to_repaint( get_win
, current
)))
2762 reply
->type
= MSG_POSTED
;
2763 reply
->msg
= WM_PAINT
;
2766 get_message_defaults( queue
, &reply
->x
, &reply
->y
, &reply
->time
);
2770 /* now check for timer */
2771 if ((filter
& QS_TIMER
) &&
2772 (timer
= find_expired_timer( queue
, get_win
, req
->get_first
,
2773 req
->get_last
, (req
->flags
& PM_REMOVE
) )))
2775 reply
->type
= MSG_POSTED
;
2776 reply
->win
= timer
->win
;
2777 reply
->msg
= timer
->msg
;
2778 reply
->wparam
= timer
->id
;
2779 reply
->lparam
= timer
->lparam
;
2780 get_message_defaults( queue
, &reply
->x
, &reply
->y
, &reply
->time
);
2781 if (!(req
->flags
& PM_NOYIELD
) && current
->process
->idle_event
)
2782 set_event( current
->process
->idle_event
);
2786 if (get_win
== -1 && current
->process
->idle_event
) set_event( current
->process
->idle_event
);
2787 queue
->wake_mask
= req
->wake_mask
;
2788 queue
->changed_mask
= req
->changed_mask
;
2789 set_error( STATUS_PENDING
); /* FIXME */
2793 /* reply to a sent message */
2794 DECL_HANDLER(reply_message
)
2796 if (!current
->queue
) set_error( STATUS_ACCESS_DENIED
);
2797 else if (current
->queue
->recv_result
)
2798 reply_message( current
->queue
, req
->result
, 0, req
->remove
,
2799 get_req_data(), get_req_data_size() );
2803 /* accept the current hardware message */
2804 DECL_HANDLER(accept_hardware_message
)
2807 release_hardware_message( current
->queue
, req
->hw_id
);
2809 set_error( STATUS_ACCESS_DENIED
);
2813 /* retrieve the reply for the last message sent */
2814 DECL_HANDLER(get_message_reply
)
2816 struct message_result
*result
;
2818 struct msg_queue
*queue
= current
->queue
;
2822 set_error( STATUS_PENDING
);
2825 if (!(entry
= list_head( &queue
->send_result
))) return; /* no reply ready */
2827 result
= LIST_ENTRY( entry
, struct message_result
, sender_entry
);
2828 if (result
->replied
|| req
->cancel
)
2830 if (result
->replied
)
2832 reply
->result
= result
->result
;
2833 set_error( result
->error
);
2836 data_size_t data_len
= min( result
->data_size
, get_reply_max_size() );
2837 set_reply_data_ptr( result
->data
, data_len
);
2838 result
->data
= NULL
;
2839 result
->data_size
= 0;
2842 remove_result_from_sender( result
);
2844 entry
= list_head( &queue
->send_result
);
2845 if (!entry
) clear_queue_bits( queue
, QS_SMRESULT
);
2848 result
= LIST_ENTRY( entry
, struct message_result
, sender_entry
);
2849 if (result
->replied
) set_queue_bits( queue
, QS_SMRESULT
);
2850 else clear_queue_bits( queue
, QS_SMRESULT
);
2854 else set_error( STATUS_ACCESS_DENIED
);
2858 /* set a window timer */
2859 DECL_HANDLER(set_win_timer
)
2861 struct timer
*timer
;
2862 struct msg_queue
*queue
;
2863 struct thread
*thread
= NULL
;
2864 user_handle_t win
= 0;
2865 lparam_t id
= req
->id
;
2869 if (!(win
= get_user_full_handle( req
->win
)) || !(thread
= get_window_thread( win
)))
2871 set_error( STATUS_INVALID_HANDLE
);
2874 if (thread
->process
!= current
->process
)
2876 release_object( thread
);
2877 set_error( STATUS_ACCESS_DENIED
);
2880 queue
= thread
->queue
;
2881 /* remove it if it existed already */
2882 if ((timer
= find_timer( queue
, win
, req
->msg
, id
))) free_timer( queue
, timer
);
2886 queue
= get_current_queue();
2887 /* look for a timer with this id */
2888 if (id
&& (timer
= find_timer( queue
, 0, req
->msg
, id
)))
2890 /* free and reuse id */
2891 free_timer( queue
, timer
);
2895 lparam_t end_id
= queue
->next_timer_id
;
2897 /* find a free id for it */
2900 id
= queue
->next_timer_id
;
2901 if (--queue
->next_timer_id
<= 0x100) queue
->next_timer_id
= 0x7fff;
2903 if (!find_timer( queue
, 0, req
->msg
, id
)) break;
2904 if (queue
->next_timer_id
== end_id
)
2906 set_win32_error( ERROR_NO_MORE_USER_HANDLES
);
2913 if ((timer
= set_timer( queue
, req
->rate
)))
2916 timer
->msg
= req
->msg
;
2918 timer
->lparam
= req
->lparam
;
2921 if (thread
) release_object( thread
);
2924 /* kill a window timer */
2925 DECL_HANDLER(kill_win_timer
)
2927 struct timer
*timer
;
2928 struct thread
*thread
;
2929 user_handle_t win
= 0;
2933 if (!(win
= get_user_full_handle( req
->win
)) || !(thread
= get_window_thread( win
)))
2935 set_error( STATUS_INVALID_HANDLE
);
2938 if (thread
->process
!= current
->process
)
2940 release_object( thread
);
2941 set_error( STATUS_ACCESS_DENIED
);
2945 else thread
= (struct thread
*)grab_object( current
);
2947 if (thread
->queue
&& (timer
= find_timer( thread
->queue
, win
, req
->msg
, req
->id
)))
2948 free_timer( thread
->queue
, timer
);
2950 set_error( STATUS_INVALID_PARAMETER
);
2952 release_object( thread
);
2955 DECL_HANDLER(register_hotkey
)
2957 struct desktop
*desktop
;
2958 user_handle_t win_handle
= req
->window
;
2959 struct hotkey
*hotkey
;
2960 struct hotkey
*new_hotkey
= NULL
;
2961 struct thread
*thread
;
2962 const int modifier_flags
= MOD_ALT
|MOD_CONTROL
|MOD_SHIFT
|MOD_WIN
;
2964 if (!(desktop
= get_thread_desktop( current
, 0 ))) return;
2968 if (!(win_handle
= get_valid_window_handle( win_handle
)))
2970 release_object( desktop
);
2974 thread
= get_window_thread( win_handle
);
2975 if (thread
) release_object( thread
);
2977 if (thread
!= current
)
2979 release_object( desktop
);
2980 set_win32_error( ERROR_WINDOW_OF_OTHER_THREAD
);
2985 LIST_FOR_EACH_ENTRY( hotkey
, &desktop
->hotkeys
, struct hotkey
, entry
)
2987 if (req
->vkey
== hotkey
->vkey
&&
2988 (req
->flags
& modifier_flags
) == (hotkey
->flags
& modifier_flags
))
2990 release_object( desktop
);
2991 set_win32_error( ERROR_HOTKEY_ALREADY_REGISTERED
);
2994 if (current
->queue
== hotkey
->queue
&& win_handle
== hotkey
->win
&& req
->id
== hotkey
->id
)
2995 new_hotkey
= hotkey
;
3000 reply
->replaced
= 1;
3001 reply
->flags
= new_hotkey
->flags
;
3002 reply
->vkey
= new_hotkey
->vkey
;
3006 new_hotkey
= mem_alloc( sizeof(*new_hotkey
) );
3009 list_add_tail( &desktop
->hotkeys
, &new_hotkey
->entry
);
3010 new_hotkey
->queue
= current
->queue
;
3011 new_hotkey
->win
= win_handle
;
3012 new_hotkey
->id
= req
->id
;
3018 new_hotkey
->flags
= req
->flags
;
3019 new_hotkey
->vkey
= req
->vkey
;
3022 release_object( desktop
);
3025 DECL_HANDLER(unregister_hotkey
)
3027 struct desktop
*desktop
;
3028 user_handle_t win_handle
= req
->window
;
3029 struct hotkey
*hotkey
;
3030 struct thread
*thread
;
3032 if (!(desktop
= get_thread_desktop( current
, 0 ))) return;
3036 if (!(win_handle
= get_valid_window_handle( win_handle
)))
3038 release_object( desktop
);
3042 thread
= get_window_thread( win_handle
);
3043 if (thread
) release_object( thread
);
3045 if (thread
!= current
)
3047 release_object( desktop
);
3048 set_win32_error( ERROR_WINDOW_OF_OTHER_THREAD
);
3053 LIST_FOR_EACH_ENTRY( hotkey
, &desktop
->hotkeys
, struct hotkey
, entry
)
3055 if (current
->queue
== hotkey
->queue
&& win_handle
== hotkey
->win
&& req
->id
== hotkey
->id
)
3059 release_object( desktop
);
3060 set_win32_error( ERROR_HOTKEY_NOT_REGISTERED
);
3064 reply
->flags
= hotkey
->flags
;
3065 reply
->vkey
= hotkey
->vkey
;
3066 list_remove( &hotkey
->entry
);
3068 release_object( desktop
);
3071 /* attach (or detach) thread inputs */
3072 DECL_HANDLER(attach_thread_input
)
3074 struct thread
*thread_from
= get_thread_from_id( req
->tid_from
);
3075 struct thread
*thread_to
= get_thread_from_id( req
->tid_to
);
3077 if (!thread_from
|| !thread_to
)
3079 if (thread_from
) release_object( thread_from
);
3080 if (thread_to
) release_object( thread_to
);
3083 if (thread_from
!= thread_to
)
3087 if ((thread_to
->queue
|| thread_to
== current
) &&
3088 (thread_from
->queue
|| thread_from
== current
))
3089 attach_thread_input( thread_from
, thread_to
);
3091 set_error( STATUS_INVALID_PARAMETER
);
3095 if (thread_from
->queue
&& thread_to
->queue
&&
3096 thread_from
->queue
->input
== thread_to
->queue
->input
)
3097 detach_thread_input( thread_from
);
3099 set_error( STATUS_ACCESS_DENIED
);
3102 else set_error( STATUS_ACCESS_DENIED
);
3103 release_object( thread_from
);
3104 release_object( thread_to
);
3108 /* get thread input data */
3109 DECL_HANDLER(get_thread_input
)
3111 struct thread
*thread
= NULL
;
3112 struct desktop
*desktop
;
3113 struct thread_input
*input
;
3117 if (!(thread
= get_thread_from_id( req
->tid
))) return;
3118 if (!(desktop
= get_thread_desktop( thread
, 0 )))
3120 release_object( thread
);
3123 input
= thread
->queue
? thread
->queue
->input
: NULL
;
3127 if (!(desktop
= get_thread_desktop( current
, 0 ))) return;
3128 input
= desktop
->foreground_input
; /* get the foreground thread info */
3133 reply
->focus
= input
->focus
;
3134 reply
->capture
= input
->capture
;
3135 reply
->active
= input
->active
;
3136 reply
->menu_owner
= input
->menu_owner
;
3137 reply
->move_size
= input
->move_size
;
3138 reply
->caret
= input
->caret
;
3139 reply
->cursor
= input
->cursor
;
3140 reply
->show_count
= input
->cursor_count
;
3141 reply
->rect
= input
->caret_rect
;
3144 /* foreground window is active window of foreground thread */
3145 reply
->foreground
= desktop
->foreground_input
? desktop
->foreground_input
->active
: 0;
3146 if (thread
) release_object( thread
);
3147 release_object( desktop
);
3151 /* retrieve queue keyboard state for current thread or global async state */
3152 DECL_HANDLER(get_key_state
)
3154 struct desktop
*desktop
;
3155 data_size_t size
= min( 256, get_reply_max_size() );
3157 if (req
->async
) /* get global async key state */
3159 if (!(desktop
= get_thread_desktop( current
, 0 ))) return;
3162 reply
->state
= desktop
->keystate
[req
->key
& 0xff];
3163 desktop
->keystate
[req
->key
& 0xff] &= ~0x40;
3165 set_reply_data( desktop
->keystate
, size
);
3166 release_object( desktop
);
3170 struct msg_queue
*queue
= get_current_queue();
3171 unsigned char *keystate
= queue
->input
->keystate
;
3174 sync_input_keystate( queue
->input
);
3175 reply
->state
= keystate
[req
->key
& 0xff];
3177 set_reply_data( keystate
, size
);
3182 /* set queue keyboard state for current thread */
3183 DECL_HANDLER(set_key_state
)
3185 struct desktop
*desktop
;
3186 struct msg_queue
*queue
= get_current_queue();
3187 data_size_t size
= min( 256, get_req_data_size() );
3189 memcpy( queue
->input
->keystate
, get_req_data(), size
);
3190 memcpy( queue
->input
->desktop_keystate
, queue
->input
->desktop
->keystate
, 256 );
3191 if (req
->async
&& (desktop
= get_thread_desktop( current
, 0 )))
3193 memcpy( desktop
->keystate
, get_req_data(), size
);
3194 release_object( desktop
);
3199 /* set the system foreground window */
3200 DECL_HANDLER(set_foreground_window
)
3202 struct thread
*thread
= NULL
;
3203 struct desktop
*desktop
;
3204 struct msg_queue
*queue
= get_current_queue();
3206 if (!(desktop
= get_thread_desktop( current
, 0 ))) return;
3207 reply
->previous
= desktop
->foreground_input
? desktop
->foreground_input
->active
: 0;
3208 reply
->send_msg_old
= (reply
->previous
&& desktop
->foreground_input
!= queue
->input
);
3209 reply
->send_msg_new
= FALSE
;
3211 if (is_valid_foreground_window( req
->handle
) &&
3212 (thread
= get_window_thread( req
->handle
)) &&
3213 thread
->queue
->input
->desktop
== desktop
)
3215 set_foreground_input( desktop
, thread
->queue
->input
);
3216 reply
->send_msg_new
= (desktop
->foreground_input
!= queue
->input
);
3218 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
3220 if (thread
) release_object( thread
);
3221 release_object( desktop
);
3225 /* set the current thread focus window */
3226 DECL_HANDLER(set_focus_window
)
3228 struct msg_queue
*queue
= get_current_queue();
3230 reply
->previous
= 0;
3231 if (queue
&& check_queue_input_window( queue
, req
->handle
))
3233 reply
->previous
= queue
->input
->focus
;
3234 queue
->input
->focus
= get_user_full_handle( req
->handle
);
3239 /* set the current thread active window */
3240 DECL_HANDLER(set_active_window
)
3242 struct msg_queue
*queue
= get_current_queue();
3244 reply
->previous
= 0;
3245 if (queue
&& check_queue_input_window( queue
, req
->handle
))
3247 if (!req
->handle
|| make_window_active( req
->handle
))
3249 reply
->previous
= queue
->input
->active
;
3250 queue
->input
->active
= get_user_full_handle( req
->handle
);
3252 else set_error( STATUS_INVALID_HANDLE
);
3257 /* set the current thread capture window */
3258 DECL_HANDLER(set_capture_window
)
3260 struct msg_queue
*queue
= get_current_queue();
3262 reply
->previous
= reply
->full_handle
= 0;
3263 if (queue
&& check_queue_input_window( queue
, req
->handle
))
3265 struct thread_input
*input
= queue
->input
;
3267 /* if in menu mode, reject all requests to change focus, except if the menu bit is set */
3268 if (input
->menu_owner
&& !(req
->flags
& CAPTURE_MENU
))
3270 set_error(STATUS_ACCESS_DENIED
);
3273 reply
->previous
= input
->capture
;
3274 input
->capture
= get_user_full_handle( req
->handle
);
3275 input
->menu_owner
= (req
->flags
& CAPTURE_MENU
) ? input
->capture
: 0;
3276 input
->move_size
= (req
->flags
& CAPTURE_MOVESIZE
) ? input
->capture
: 0;
3277 reply
->full_handle
= input
->capture
;
3282 /* Set the current thread caret window */
3283 DECL_HANDLER(set_caret_window
)
3285 struct msg_queue
*queue
= get_current_queue();
3287 reply
->previous
= 0;
3288 if (queue
&& check_queue_input_window( queue
, req
->handle
))
3290 struct thread_input
*input
= queue
->input
;
3292 reply
->previous
= input
->caret
;
3293 reply
->old_rect
= input
->caret_rect
;
3294 reply
->old_hide
= input
->caret_hide
;
3295 reply
->old_state
= input
->caret_state
;
3297 set_caret_window( input
, get_user_full_handle(req
->handle
) );
3298 input
->caret_rect
.right
= input
->caret_rect
.left
+ req
->width
;
3299 input
->caret_rect
.bottom
= input
->caret_rect
.top
+ req
->height
;
3304 /* Set the current thread caret information */
3305 DECL_HANDLER(set_caret_info
)
3307 struct msg_queue
*queue
= get_current_queue();
3308 struct thread_input
*input
;
3311 input
= queue
->input
;
3312 reply
->full_handle
= input
->caret
;
3313 reply
->old_rect
= input
->caret_rect
;
3314 reply
->old_hide
= input
->caret_hide
;
3315 reply
->old_state
= input
->caret_state
;
3317 if (req
->handle
&& get_user_full_handle(req
->handle
) != input
->caret
)
3319 set_error( STATUS_ACCESS_DENIED
);
3322 if (req
->flags
& SET_CARET_POS
)
3324 input
->caret_rect
.right
+= req
->x
- input
->caret_rect
.left
;
3325 input
->caret_rect
.bottom
+= req
->y
- input
->caret_rect
.top
;
3326 input
->caret_rect
.left
= req
->x
;
3327 input
->caret_rect
.top
= req
->y
;
3329 if (req
->flags
& SET_CARET_HIDE
)
3331 input
->caret_hide
+= req
->hide
;
3332 if (input
->caret_hide
< 0) input
->caret_hide
= 0;
3334 if (req
->flags
& SET_CARET_STATE
)
3338 case CARET_STATE_OFF
: input
->caret_state
= 0; break;
3339 case CARET_STATE_ON
: input
->caret_state
= 1; break;
3340 case CARET_STATE_TOGGLE
: input
->caret_state
= !input
->caret_state
; break;
3341 case CARET_STATE_ON_IF_MOVED
:
3342 if (req
->x
!= reply
->old_rect
.left
|| req
->y
!= reply
->old_rect
.top
) input
->caret_state
= 1;
3349 /* get the time of the last input event */
3350 DECL_HANDLER(get_last_input_time
)
3352 reply
->time
= last_input_time
;
3355 /* set/get the current cursor */
3356 DECL_HANDLER(set_cursor
)
3358 struct msg_queue
*queue
= get_current_queue();
3359 struct thread_input
*input
;
3360 struct desktop
*desktop
;
3363 input
= queue
->input
;
3364 desktop
= input
->desktop
;
3366 reply
->prev_handle
= input
->cursor
;
3367 reply
->prev_count
= input
->cursor_count
;
3368 reply
->prev_x
= desktop
->cursor
.x
;
3369 reply
->prev_y
= desktop
->cursor
.y
;
3371 if (req
->flags
& SET_CURSOR_HANDLE
)
3373 if (req
->handle
&& !get_user_object( req
->handle
, USER_CLIENT
))
3375 set_win32_error( ERROR_INVALID_CURSOR_HANDLE
);
3378 input
->cursor
= req
->handle
;
3380 if (req
->flags
& SET_CURSOR_COUNT
)
3382 queue
->cursor_count
+= req
->show_count
;
3383 input
->cursor_count
+= req
->show_count
;
3385 if (req
->flags
& SET_CURSOR_POS
) set_cursor_pos( desktop
, req
->x
, req
->y
);
3386 if (req
->flags
& SET_CURSOR_CLIP
) set_clip_rectangle( desktop
, &req
->clip
, req
->flags
, 0 );
3387 if (req
->flags
& SET_CURSOR_NOCLIP
) set_clip_rectangle( desktop
, NULL
, SET_CURSOR_NOCLIP
, 0 );
3389 if (req
->flags
& (SET_CURSOR_HANDLE
| SET_CURSOR_COUNT
))
3391 if (input
->cursor_count
< 0) update_desktop_cursor_handle( desktop
, 0 );
3392 else update_desktop_cursor_handle( desktop
, input
->cursor
);
3395 reply
->new_x
= desktop
->cursor
.x
;
3396 reply
->new_y
= desktop
->cursor
.y
;
3397 reply
->new_clip
= desktop
->cursor
.clip
;
3398 reply
->last_change
= desktop
->cursor
.last_change
;
3401 /* Get the history of the 64 last cursor positions */
3402 DECL_HANDLER(get_cursor_history
)
3405 unsigned int i
, count
= min( 64, get_reply_max_size() / sizeof(*pos
) );
3407 if ((pos
= set_reply_data_size( count
* sizeof(*pos
) )))
3408 for (i
= 0; i
< count
; i
++)
3409 pos
[i
] = cursor_history
[(i
+ cursor_history_latest
) % ARRAY_SIZE(cursor_history
)];
3412 DECL_HANDLER(get_rawinput_buffer
)
3414 struct thread_input
*input
= current
->queue
->input
;
3415 data_size_t size
= 0, next_size
= 0, pos
= 0;
3418 int count
= 0, buf_size
= 16 * sizeof(struct hardware_msg_data
);
3420 if (!req
->buffer_size
) buf
= NULL
;
3421 else if (!(buf
= mem_alloc( buf_size
))) return;
3423 ptr
= list_head( &input
->msg_list
);
3426 struct message
*msg
= LIST_ENTRY( ptr
, struct message
, entry
);
3427 struct hardware_msg_data
*data
= msg
->data
;
3428 data_size_t extra_size
= data
->size
- sizeof(*data
);
3430 ptr
= list_next( &input
->msg_list
, ptr
);
3431 if (msg
->msg
!= WM_INPUT
) continue;
3433 next_size
= req
->rawinput_size
+ extra_size
;
3434 if (size
+ next_size
> req
->buffer_size
) break;
3435 if (pos
+ data
->size
> get_reply_max_size()) break;
3436 if (pos
+ data
->size
> buf_size
)
3438 buf_size
+= buf_size
/ 2 + extra_size
;
3439 if (!(tmp
= realloc( buf
, buf_size
)))
3442 set_error( STATUS_NO_MEMORY
);
3448 memcpy( buf
+ pos
, data
, data
->size
);
3449 list_remove( &msg
->entry
);
3450 free_message( msg
);
3453 pos
+= sizeof(*data
) + extra_size
;
3457 reply
->next_size
= next_size
;
3458 reply
->count
= count
;
3459 set_reply_data_ptr( buf
, pos
);
3462 DECL_HANDLER(update_rawinput_devices
)
3464 const struct rawinput_device
*tmp
, *devices
= get_req_data();
3465 unsigned int device_count
= get_req_data_size() / sizeof (*devices
);
3466 size_t size
= device_count
* sizeof(*devices
);
3467 struct process
*process
= current
->process
;
3471 process
->rawinput_device_count
= 0;
3472 process
->rawinput_mouse
= NULL
;
3473 process
->rawinput_kbd
= NULL
;
3477 if (!(tmp
= realloc( process
->rawinput_devices
, size
)))
3479 set_error( STATUS_NO_MEMORY
);
3482 process
->rawinput_devices
= (struct rawinput_device
*)tmp
;
3483 process
->rawinput_device_count
= device_count
;
3484 memcpy( process
->rawinput_devices
, devices
, size
);
3486 process
->rawinput_mouse
= find_rawinput_device( process
, 1, 2 );
3487 process
->rawinput_kbd
= find_rawinput_device( process
, 1, 6 );