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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
38 enum message_kind
{ SEND_MESSAGE
, POST_MESSAGE
};
39 #define NB_MSG_KINDS (POST_MESSAGE+1)
44 struct message_result
*send_next
; /* next in sender list */
45 struct message_result
*recv_next
; /* next in receiver list */
46 struct msg_queue
*sender
; /* sender queue */
47 struct msg_queue
*receiver
; /* receiver queue */
48 int replied
; /* has it been replied to? */
49 unsigned int result
; /* reply result */
50 unsigned int error
; /* error code to pass back to sender */
51 void *data
; /* message reply data */
52 unsigned int data_size
; /* size of message reply data */
53 struct timeout_user
*timeout
; /* result timeout */
58 struct message
*next
; /* next message in list */
59 struct message
*prev
; /* prev message in list */
60 enum message_type type
; /* message type */
61 user_handle_t win
; /* window handle */
62 unsigned int msg
; /* message code */
63 unsigned int wparam
; /* parameters */
64 unsigned int lparam
; /* parameters */
65 int x
; /* x position */
66 int y
; /* y position */
67 unsigned int time
; /* message time */
68 unsigned int info
; /* extra info */
69 void *data
; /* message data for sent messages */
70 unsigned int data_size
; /* size of message data */
71 struct message_result
*result
; /* result in sender queue */
76 struct message
*first
; /* head of list */
77 struct message
*last
; /* tail of list */
82 struct timer
*next
; /* next timer in list */
83 struct timer
*prev
; /* prev timer in list */
84 struct timeval when
; /* next expiration */
85 unsigned int rate
; /* timer rate in ms */
86 user_handle_t win
; /* window handle */
87 unsigned int msg
; /* message to post */
88 unsigned int id
; /* timer id */
89 unsigned int lparam
; /* lparam for message */
94 struct object obj
; /* object header */
95 user_handle_t focus
; /* focus window */
96 user_handle_t capture
; /* capture window */
97 user_handle_t active
; /* active window */
98 user_handle_t menu_owner
; /* current menu owner window */
99 user_handle_t move_size
; /* current moving/resizing window */
100 user_handle_t caret
; /* caret window */
101 rectangle_t caret_rect
; /* caret rectangle */
102 int caret_hide
; /* caret hide count */
103 int caret_state
; /* caret on/off state */
104 struct message
*msg
; /* message currently processed */
105 struct thread
*msg_thread
; /* thread processing the message */
106 struct message_list msg_list
; /* list of hardware messages */
107 unsigned char keystate
[256]; /* state of each key */
112 struct object obj
; /* object header */
113 unsigned int wake_bits
; /* wakeup bits */
114 unsigned int wake_mask
; /* wakeup mask */
115 unsigned int changed_bits
; /* changed wakeup bits */
116 unsigned int changed_mask
; /* changed wakeup mask */
117 int paint_count
; /* pending paint messages count */
118 struct message_list msg_list
[NB_MSG_KINDS
]; /* lists of messages */
119 struct message_result
*send_result
; /* stack of sent messages waiting for result */
120 struct message_result
*recv_result
; /* stack of received messages waiting for result */
121 struct timer
*first_timer
; /* head of timer list */
122 struct timer
*last_timer
; /* tail of timer list */
123 struct timer
*next_timer
; /* next timer to expire */
124 struct timeout_user
*timeout
; /* timeout for next timer to expire */
125 struct thread_input
*input
; /* thread input descriptor */
128 static void msg_queue_dump( struct object
*obj
, int verbose
);
129 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
);
130 static void msg_queue_remove_queue( struct object
*obj
, struct wait_queue_entry
*entry
);
131 static int msg_queue_signaled( struct object
*obj
, struct thread
*thread
);
132 static int msg_queue_satisfied( struct object
*obj
, struct thread
*thread
);
133 static void msg_queue_destroy( struct object
*obj
);
134 static void thread_input_dump( struct object
*obj
, int verbose
);
135 static void thread_input_destroy( struct object
*obj
);
136 static void timer_callback( void *private );
138 static const struct object_ops msg_queue_ops
=
140 sizeof(struct msg_queue
), /* size */
141 msg_queue_dump
, /* dump */
142 msg_queue_add_queue
, /* add_queue */
143 msg_queue_remove_queue
, /* remove_queue */
144 msg_queue_signaled
, /* signaled */
145 msg_queue_satisfied
, /* satisfied */
146 NULL
, /* get_poll_events */
147 NULL
, /* poll_event */
148 no_get_fd
, /* get_fd */
149 no_flush
, /* flush */
150 no_get_file_info
, /* get_file_info */
151 NULL
, /* queue_async */
152 msg_queue_destroy
/* destroy */
156 static const struct object_ops thread_input_ops
=
158 sizeof(struct thread_input
), /* size */
159 thread_input_dump
, /* dump */
160 no_add_queue
, /* add_queue */
161 NULL
, /* remove_queue */
163 NULL
, /* satisfied */
164 NULL
, /* get_poll_events */
165 NULL
, /* poll_event */
166 no_get_fd
, /* get_fd */
167 no_flush
, /* flush */
168 no_get_file_info
, /* get_file_info */
169 NULL
, /* queue_async */
170 thread_input_destroy
/* destroy */
173 /* pointer to input structure of foreground thread */
174 static struct thread_input
*foreground_input
;
177 /* set the caret window in a given thread input */
178 static void set_caret_window( struct thread_input
*input
, user_handle_t win
)
181 input
->caret_rect
.left
= 0;
182 input
->caret_rect
.top
= 0;
183 input
->caret_rect
.right
= 0;
184 input
->caret_rect
.bottom
= 0;
185 input
->caret_hide
= 1;
186 input
->caret_state
= 0;
189 /* create a thread input object */
190 static struct thread_input
*create_thread_input(void)
192 struct thread_input
*input
;
194 if ((input
= alloc_object( &thread_input_ops
, -1 )))
199 input
->menu_owner
= 0;
200 input
->move_size
= 0;
202 input
->msg_thread
= NULL
;
203 input
->msg_list
.first
= input
->msg_list
.last
= NULL
;
204 set_caret_window( input
, 0 );
205 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
210 /* create a message queue object */
211 static struct msg_queue
*create_msg_queue( struct thread
*thread
, struct thread_input
*input
)
213 struct msg_queue
*queue
;
216 if (!input
&& !(input
= create_thread_input())) return NULL
;
217 if ((queue
= alloc_object( &msg_queue_ops
, -1 )))
219 queue
->wake_bits
= 0;
220 queue
->wake_mask
= 0;
221 queue
->changed_bits
= 0;
222 queue
->changed_mask
= 0;
223 queue
->paint_count
= 0;
224 queue
->send_result
= NULL
;
225 queue
->recv_result
= NULL
;
226 queue
->first_timer
= NULL
;
227 queue
->last_timer
= NULL
;
228 queue
->next_timer
= NULL
;
229 queue
->timeout
= NULL
;
230 queue
->input
= (struct thread_input
*)grab_object( input
);
231 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
232 queue
->msg_list
[i
].first
= queue
->msg_list
[i
].last
= NULL
;
234 thread
->queue
= queue
;
235 if (!thread
->process
->queue
)
236 thread
->process
->queue
= (struct msg_queue
*)grab_object( queue
);
238 release_object( input
);
242 /* free the message queue of a thread at thread exit */
243 void free_msg_queue( struct thread
*thread
)
245 struct process
*process
= thread
->process
;
247 if (!thread
->queue
) return;
248 if (process
->queue
== thread
->queue
) /* is it the process main queue? */
250 release_object( process
->queue
);
251 process
->queue
= NULL
;
252 if (process
->idle_event
)
254 set_event( process
->idle_event
);
255 release_object( process
->idle_event
);
256 process
->idle_event
= NULL
;
259 release_object( thread
->queue
);
260 thread
->queue
= NULL
;
263 /* check the queue status */
264 inline static int is_signaled( struct msg_queue
*queue
)
266 return ((queue
->wake_bits
& queue
->wake_mask
) || (queue
->changed_bits
& queue
->changed_mask
));
269 /* set some queue bits */
270 inline static void set_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
272 queue
->wake_bits
|= bits
;
273 queue
->changed_bits
|= bits
;
274 if (is_signaled( queue
)) wake_up( &queue
->obj
, 0 );
277 /* clear some queue bits */
278 inline static void clear_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
280 queue
->wake_bits
&= ~bits
;
281 queue
->changed_bits
&= ~bits
;
284 /* check whether msg is a keyboard message */
285 inline static int is_keyboard_msg( struct message
*msg
)
287 return (msg
->msg
>= WM_KEYFIRST
&& msg
->msg
<= WM_KEYLAST
);
290 /* get the QS_* bit corresponding to a given hardware message */
291 inline static int get_hardware_msg_bit( struct message
*msg
)
293 if (msg
->msg
== WM_MOUSEMOVE
|| msg
->msg
== WM_NCMOUSEMOVE
) return QS_MOUSEMOVE
;
294 if (is_keyboard_msg( msg
)) return QS_KEY
;
295 return QS_MOUSEBUTTON
;
298 /* get the current thread queue, creating it if needed */
299 inline static struct msg_queue
*get_current_queue(void)
301 struct msg_queue
*queue
= current
->queue
;
302 if (!queue
) queue
= create_msg_queue( current
, NULL
);
306 /* append a message to the end of a list */
307 inline static void append_message( struct message_list
*list
, struct message
*msg
)
310 if ((msg
->prev
= list
->last
)) msg
->prev
->next
= msg
;
311 else list
->first
= msg
;
315 /* unlink a message from a list it */
316 inline static void unlink_message( struct message_list
*list
, struct message
*msg
)
318 if (msg
->next
) msg
->next
->prev
= msg
->prev
;
319 else list
->last
= msg
->prev
;
320 if (msg
->prev
) msg
->prev
->next
= msg
->next
;
321 else list
->first
= msg
->next
;
324 /* try to merge a message with the last in the list; return 1 if successful */
325 static int merge_message( struct thread_input
*input
, const struct message
*msg
)
327 struct message
*prev
= input
->msg_list
.last
;
330 if (input
->msg
== prev
) return 0;
331 if (prev
->result
) return 0;
332 if (prev
->win
!= msg
->win
) return 0;
333 if (prev
->msg
!= msg
->msg
) return 0;
334 if (prev
->type
!= msg
->type
) return 0;
335 /* now we can merge it */
336 prev
->wparam
= msg
->wparam
;
337 prev
->lparam
= msg
->lparam
;
340 prev
->time
= msg
->time
;
341 prev
->info
= msg
->info
;
345 /* free a result structure */
346 static void free_result( struct message_result
*result
)
348 if (result
->timeout
) remove_timeout_user( result
->timeout
);
349 if (result
->data
) free( result
->data
);
353 /* store the message result in the appropriate structure */
354 static void store_message_result( struct message_result
*res
, unsigned int result
,
357 res
->result
= result
;
362 remove_timeout_user( res
->timeout
);
365 /* wake sender queue if waiting on this result */
366 if (res
->sender
&& res
->sender
->send_result
== res
)
367 set_queue_bits( res
->sender
, QS_SMRESULT
);
370 /* free a message when deleting a queue or window */
371 static void free_message( struct message
*msg
)
373 struct message_result
*result
= msg
->result
;
378 result
->receiver
= NULL
;
379 store_message_result( result
, 0, STATUS_ACCESS_DENIED
/*FIXME*/ );
381 else free_result( result
);
383 if (msg
->data
) free( msg
->data
);
387 /* remove (and free) a message from a message list */
388 static void remove_queue_message( struct msg_queue
*queue
, struct message
*msg
,
389 enum message_kind kind
)
391 unlink_message( &queue
->msg_list
[kind
], msg
);
395 if (!queue
->msg_list
[kind
].first
) clear_queue_bits( queue
, QS_SENDMESSAGE
);
398 if (!queue
->msg_list
[kind
].first
) clear_queue_bits( queue
, QS_POSTMESSAGE
);
404 /* message timed out without getting a reply */
405 static void result_timeout( void *private )
407 struct message_result
*result
= private;
409 assert( !result
->replied
);
411 result
->timeout
= NULL
;
412 store_message_result( result
, 0, STATUS_TIMEOUT
);
415 /* allocate and fill a message result structure */
416 static struct message_result
*alloc_message_result( struct msg_queue
*send_queue
,
417 struct msg_queue
*recv_queue
,
418 unsigned int timeout
)
420 struct message_result
*result
= mem_alloc( sizeof(*result
) );
423 /* put the result on the sender result stack */
424 result
->sender
= send_queue
;
425 result
->receiver
= recv_queue
;
428 result
->data_size
= 0;
429 result
->timeout
= NULL
;
430 result
->send_next
= send_queue
->send_result
;
431 send_queue
->send_result
= result
;
435 gettimeofday( &when
, 0 );
436 add_timeout( &when
, timeout
);
437 result
->timeout
= add_timeout_user( &when
, result_timeout
, result
);
443 /* receive a message, removing it from the sent queue */
444 static void receive_message( struct msg_queue
*queue
, struct message
*msg
,
445 struct get_message_reply
*reply
)
447 struct message_result
*result
= msg
->result
;
449 reply
->total
= msg
->data_size
;
450 if (msg
->data_size
> get_reply_max_size())
452 set_error( STATUS_BUFFER_OVERFLOW
);
455 reply
->type
= msg
->type
;
456 reply
->win
= msg
->win
;
457 reply
->msg
= msg
->msg
;
458 reply
->wparam
= msg
->wparam
;
459 reply
->lparam
= msg
->lparam
;
462 reply
->time
= msg
->time
;
463 reply
->info
= msg
->info
;
465 if (msg
->data
) set_reply_data_ptr( msg
->data
, msg
->data_size
);
467 unlink_message( &queue
->msg_list
[SEND_MESSAGE
], msg
);
468 /* put the result on the receiver result stack */
471 result
->recv_next
= queue
->recv_result
;
472 queue
->recv_result
= result
;
475 if (!queue
->msg_list
[SEND_MESSAGE
].first
) clear_queue_bits( queue
, QS_SENDMESSAGE
);
478 /* set the result of the current received message */
479 static void reply_message( struct msg_queue
*queue
, unsigned int result
,
480 unsigned int error
, int remove
, const void *data
, size_t len
)
482 struct message_result
*res
= queue
->recv_result
;
486 queue
->recv_result
= res
->recv_next
;
487 res
->receiver
= NULL
;
488 if (!res
->sender
) /* no one waiting for it */
496 if (len
&& (res
->data
= memdup( data
, len
))) res
->data_size
= len
;
497 store_message_result( res
, result
, error
);
501 /* retrieve a posted message */
502 static int get_posted_message( struct msg_queue
*queue
, user_handle_t win
,
503 unsigned int first
, unsigned int last
, unsigned int flags
,
504 struct get_message_reply
*reply
)
507 struct message_list
*list
= &queue
->msg_list
[POST_MESSAGE
];
509 /* check against the filters */
510 for (msg
= list
->first
; msg
; msg
= msg
->next
)
512 if (msg
->msg
== WM_QUIT
) break; /* WM_QUIT is never filtered */
513 if (win
&& msg
->win
&& msg
->win
!= win
&& !is_child_window( win
, msg
->win
)) continue;
514 if (msg
->msg
< first
) continue;
515 if (msg
->msg
> last
) continue;
516 break; /* found one */
520 /* return it to the app */
522 reply
->total
= msg
->data_size
;
523 if (msg
->data_size
> get_reply_max_size())
525 set_error( STATUS_BUFFER_OVERFLOW
);
528 reply
->type
= msg
->type
;
529 reply
->win
= msg
->win
;
530 reply
->msg
= msg
->msg
;
531 reply
->wparam
= msg
->wparam
;
532 reply
->lparam
= msg
->lparam
;
535 reply
->time
= msg
->time
;
536 reply
->info
= msg
->info
;
538 if (flags
& GET_MSG_REMOVE
)
542 set_reply_data_ptr( msg
->data
, msg
->data_size
);
546 remove_queue_message( queue
, msg
, POST_MESSAGE
);
548 else if (msg
->data
) set_reply_data( msg
->data
, msg
->data_size
);
553 /* empty a message list and free all the messages */
554 static void empty_msg_list( struct message_list
*list
)
556 struct message
*msg
= list
->first
;
559 struct message
*next
= msg
->next
;
565 /* cleanup all pending results when deleting a queue */
566 static void cleanup_results( struct msg_queue
*queue
)
568 struct message_result
*result
, *next
;
570 result
= queue
->send_result
;
573 next
= result
->send_next
;
574 result
->sender
= NULL
;
575 if (!result
->receiver
) free_result( result
);
579 while (queue
->recv_result
)
580 reply_message( queue
, 0, STATUS_ACCESS_DENIED
/*FIXME*/, 1, NULL
, 0 );
583 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
)
585 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
586 struct process
*process
= entry
->thread
->process
;
588 /* a thread can only wait on its own queue */
589 if (entry
->thread
->queue
!= queue
)
591 set_error( STATUS_ACCESS_DENIED
);
594 /* if waiting on the main process queue, set the idle event */
595 if (process
->queue
== queue
)
597 if (process
->idle_event
) set_event( process
->idle_event
);
599 add_queue( obj
, entry
);
603 static void msg_queue_remove_queue(struct object
*obj
, struct wait_queue_entry
*entry
)
605 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
606 struct process
*process
= entry
->thread
->process
;
608 remove_queue( obj
, entry
);
610 assert( entry
->thread
->queue
== queue
);
612 /* if waiting on the main process queue, reset the idle event */
613 if (process
->queue
== queue
)
615 if (process
->idle_event
) reset_event( process
->idle_event
);
619 static void msg_queue_dump( struct object
*obj
, int verbose
)
621 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
622 fprintf( stderr
, "Msg queue bits=%x mask=%x\n",
623 queue
->wake_bits
, queue
->wake_mask
);
626 static int msg_queue_signaled( struct object
*obj
, struct thread
*thread
)
628 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
629 return is_signaled( queue
);
632 static int msg_queue_satisfied( struct object
*obj
, struct thread
*thread
)
634 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
635 queue
->wake_mask
= 0;
636 queue
->changed_mask
= 0;
637 return 0; /* Not abandoned */
640 static void msg_queue_destroy( struct object
*obj
)
642 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
643 struct timer
*timer
= queue
->first_timer
;
646 cleanup_results( queue
);
647 for (i
= 0; i
< NB_MSG_KINDS
; i
++) empty_msg_list( &queue
->msg_list
[i
] );
651 struct timer
*next
= timer
->next
;
655 if (queue
->timeout
) remove_timeout_user( queue
->timeout
);
656 if (queue
->input
) release_object( queue
->input
);
659 static void thread_input_dump( struct object
*obj
, int verbose
)
661 struct thread_input
*input
= (struct thread_input
*)obj
;
662 fprintf( stderr
, "Thread input focus=%p capture=%p active=%p\n",
663 input
->focus
, input
->capture
, input
->active
);
666 static void thread_input_destroy( struct object
*obj
)
668 struct thread_input
*input
= (struct thread_input
*)obj
;
670 if (foreground_input
== input
) foreground_input
= NULL
;
671 if (input
->msg_thread
) release_object( input
->msg_thread
);
672 empty_msg_list( &input
->msg_list
);
675 /* fix the thread input data when a window is destroyed */
676 inline static void thread_input_cleanup_window( struct msg_queue
*queue
, user_handle_t window
)
678 struct thread_input
*input
= queue
->input
;
680 if (window
== input
->focus
) input
->focus
= 0;
681 if (window
== input
->capture
) input
->capture
= 0;
682 if (window
== input
->active
) input
->active
= 0;
683 if (window
== input
->menu_owner
) input
->menu_owner
= 0;
684 if (window
== input
->move_size
) input
->move_size
= 0;
685 if (window
== input
->caret
) set_caret_window( input
, 0 );
688 /* check if the specified window can be set in the input data of a given queue */
689 static int check_queue_input_window( struct msg_queue
*queue
, user_handle_t window
)
691 struct thread
*thread
;
694 if (!window
) return 1; /* we can always clear the data */
696 if ((thread
= get_window_thread( window
)))
698 ret
= (queue
->input
== thread
->queue
->input
);
699 if (!ret
) set_error( STATUS_ACCESS_DENIED
);
700 release_object( thread
);
702 else set_error( STATUS_INVALID_HANDLE
);
707 /* attach two thread input data structures */
708 int attach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
710 struct thread_input
*input
;
712 if (!thread_to
->queue
&& !(thread_to
->queue
= create_msg_queue( thread_to
, NULL
))) return 0;
713 input
= (struct thread_input
*)grab_object( thread_to
->queue
->input
);
715 if (thread_from
->queue
)
717 release_object( thread_from
->queue
->input
);
718 thread_from
->queue
->input
= input
;
722 if (!(thread_from
->queue
= create_msg_queue( thread_from
, input
))) return 0;
724 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
728 /* detach two thread input data structures */
729 static void detach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
731 struct thread_input
*input
;
733 if (!thread_from
->queue
|| !thread_to
->queue
||
734 thread_from
->queue
->input
!= thread_to
->queue
->input
)
736 set_error( STATUS_ACCESS_DENIED
);
739 if ((input
= create_thread_input()))
741 release_object( thread_from
->queue
->input
);
742 thread_from
->queue
->input
= input
;
747 /* set the next timer to expire */
748 static void set_next_timer( struct msg_queue
*queue
, struct timer
*timer
)
752 remove_timeout_user( queue
->timeout
);
753 queue
->timeout
= NULL
;
755 if ((queue
->next_timer
= timer
))
756 queue
->timeout
= add_timeout_user( &timer
->when
, timer_callback
, queue
);
758 /* set/clear QS_TIMER bit */
759 if (queue
->next_timer
== queue
->first_timer
)
760 clear_queue_bits( queue
, QS_TIMER
);
762 set_queue_bits( queue
, QS_TIMER
);
765 /* callback for the next timer expiration */
766 static void timer_callback( void *private )
768 struct msg_queue
*queue
= private;
770 queue
->timeout
= NULL
;
771 /* move on to the next timer */
772 set_next_timer( queue
, queue
->next_timer
->next
);
775 /* link a timer at its rightful place in the queue list */
776 static void link_timer( struct msg_queue
*queue
, struct timer
*timer
)
778 struct timer
*pos
= queue
->next_timer
;
780 while (pos
&& time_before( &pos
->when
, &timer
->when
)) pos
= pos
->next
;
782 if (pos
) /* insert before pos */
784 if ((timer
->prev
= pos
->prev
)) timer
->prev
->next
= timer
;
785 else queue
->first_timer
= timer
;
789 else /* insert at end */
792 timer
->prev
= queue
->last_timer
;
793 if (queue
->last_timer
) queue
->last_timer
->next
= timer
;
794 else queue
->first_timer
= timer
;
795 queue
->last_timer
= timer
;
797 /* check if we replaced the next timer */
798 if (pos
== queue
->next_timer
) set_next_timer( queue
, timer
);
801 /* remove a timer from the queue timer list */
802 static void unlink_timer( struct msg_queue
*queue
, struct timer
*timer
)
804 if (timer
->next
) timer
->next
->prev
= timer
->prev
;
805 else queue
->last_timer
= timer
->prev
;
806 if (timer
->prev
) timer
->prev
->next
= timer
->next
;
807 else queue
->first_timer
= timer
->next
;
808 /* check if we removed the next timer */
809 if (queue
->next_timer
== timer
) set_next_timer( queue
, timer
->next
);
810 else if (queue
->next_timer
== queue
->first_timer
) clear_queue_bits( queue
, QS_TIMER
);
813 /* restart an expired timer */
814 static void restart_timer( struct msg_queue
*queue
, struct timer
*timer
)
817 unlink_timer( queue
, timer
);
818 gettimeofday( &now
, 0 );
819 while (!time_before( &now
, &timer
->when
)) add_timeout( &timer
->when
, timer
->rate
);
820 link_timer( queue
, timer
);
823 /* find an expired timer matching the filtering parameters */
824 static struct timer
*find_expired_timer( struct msg_queue
*queue
, user_handle_t win
,
825 unsigned int get_first
, unsigned int get_last
,
829 for (timer
= queue
->first_timer
; (timer
&& timer
!= queue
->next_timer
); timer
= timer
->next
)
831 if (win
&& timer
->win
!= win
) continue;
832 if (timer
->msg
>= get_first
&& timer
->msg
<= get_last
)
834 if (remove
) restart_timer( queue
, timer
);
842 static int kill_timer( struct msg_queue
*queue
, user_handle_t win
,
843 unsigned int msg
, unsigned int id
)
847 for (timer
= queue
->first_timer
; timer
; timer
= timer
->next
)
849 if (timer
->win
!= win
|| timer
->msg
!= msg
|| timer
->id
!= id
) continue;
850 unlink_timer( queue
, timer
);
858 static struct timer
*set_timer( struct msg_queue
*queue
, unsigned int rate
)
860 struct timer
*timer
= mem_alloc( sizeof(*timer
) );
864 gettimeofday( &timer
->when
, 0 );
865 add_timeout( &timer
->when
, rate
);
866 link_timer( queue
, timer
);
871 /* change the input key state for a given key */
872 static void set_input_key_state( struct thread_input
*input
, unsigned char key
, int down
)
876 if (!(input
->keystate
[key
] & 0x80)) input
->keystate
[key
] ^= 0x01;
877 input
->keystate
[key
] |= 0x80;
879 else input
->keystate
[key
] &= ~0x80;
882 /* update the input key state for a keyboard message */
883 static void update_input_key_state( struct thread_input
*input
, const struct message
*msg
)
886 int down
= 0, extended
;
894 set_input_key_state( input
, VK_LBUTTON
, down
);
900 set_input_key_state( input
, VK_MBUTTON
, down
);
906 set_input_key_state( input
, VK_RBUTTON
, down
);
914 key
= (unsigned char)msg
->wparam
;
915 extended
= ((msg
->lparam
>> 16) & KF_EXTENDED
) != 0;
916 set_input_key_state( input
, key
, down
);
920 set_input_key_state( input
, extended
? VK_RSHIFT
: VK_LSHIFT
, down
);
923 set_input_key_state( input
, extended
? VK_RCONTROL
: VK_LCONTROL
, down
);
926 set_input_key_state( input
, extended
? VK_RMENU
: VK_LMENU
, down
);
933 /* release the hardware message currently being processed by the given thread */
934 static void release_hardware_message( struct thread
*thread
, int remove
)
936 struct thread_input
*input
= thread
->queue
->input
;
938 if (input
->msg_thread
!= thread
) return;
941 struct message
*other
;
944 update_input_key_state( input
, input
->msg
);
945 unlink_message( &input
->msg_list
, input
->msg
);
946 clr_bit
= get_hardware_msg_bit( input
->msg
);
947 for (other
= input
->msg_list
.first
; other
; other
= other
->next
)
948 if (get_hardware_msg_bit( other
) == clr_bit
) break;
949 if (!other
) clear_queue_bits( thread
->queue
, clr_bit
);
950 free_message( input
->msg
);
952 release_object( input
->msg_thread
);
954 input
->msg_thread
= NULL
;
957 /* find the window that should receive a given hardware message */
958 static user_handle_t
find_hardware_message_window( struct thread_input
*input
, struct message
*msg
,
959 unsigned int *msg_code
)
961 user_handle_t win
= 0;
963 *msg_code
= msg
->msg
;
964 if (is_keyboard_msg( msg
))
966 if (input
&& !(win
= input
->focus
))
969 if (*msg_code
< WM_SYSKEYDOWN
) *msg_code
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
972 else /* mouse message */
974 if (!input
|| !(win
= input
->capture
))
976 if (!(win
= msg
->win
)) win
= window_from_point( msg
->x
, msg
->y
);
982 /* queue a hardware message into a given thread input */
983 static void queue_hardware_message( struct msg_queue
*queue
, struct message
*msg
)
986 struct thread
*thread
;
987 struct thread_input
*input
;
988 unsigned int msg_code
;
990 win
= find_hardware_message_window( queue
? queue
->input
: foreground_input
, msg
, &msg_code
);
991 if (!win
|| !(thread
= get_window_thread(win
)))
996 input
= thread
->queue
->input
;
998 if (msg
->msg
== WM_MOUSEMOVE
&& merge_message( input
, msg
)) free( msg
);
1001 append_message( &input
->msg_list
, msg
);
1002 set_queue_bits( thread
->queue
, get_hardware_msg_bit(msg
) );
1004 release_object( thread
);
1007 /* find a hardware message for the given queue */
1008 static int get_hardware_message( struct thread
*thread
, struct message
*first
,
1009 user_handle_t filter_win
, struct get_message_reply
*reply
)
1011 struct thread_input
*input
= thread
->queue
->input
;
1012 struct thread
*win_thread
;
1013 struct message
*msg
;
1015 int clear_bits
, got_one
= 0;
1016 unsigned int msg_code
;
1018 if (input
->msg_thread
&& input
->msg_thread
!= thread
)
1019 return 0; /* locked by another thread */
1023 msg
= input
->msg_list
.first
;
1024 clear_bits
= QS_KEY
| QS_MOUSEMOVE
| QS_MOUSEBUTTON
;
1029 clear_bits
= 0; /* don't clear bits if we don't go through the whole list */
1034 win
= find_hardware_message_window( input
, msg
, &msg_code
);
1035 if (!win
|| !(win_thread
= get_window_thread( win
)))
1037 /* no window at all, remove it */
1038 struct message
*next
= msg
->next
;
1039 update_input_key_state( input
, msg
);
1040 unlink_message( &input
->msg_list
, msg
);
1041 free_message( msg
);
1045 if (win_thread
!= thread
)
1047 /* wake the other thread */
1048 set_queue_bits( win_thread
->queue
, get_hardware_msg_bit(msg
) );
1049 release_object( win_thread
);
1054 /* if we already got a message for another thread, or if it doesn't
1055 * match the filter we skip it (filter is only checked for keyboard
1056 * messages since the dest window for a mouse message depends on hittest)
1059 (filter_win
&& is_keyboard_msg(msg
) &&
1060 win
!= filter_win
&& !is_child_window( filter_win
, win
)))
1062 clear_bits
&= ~get_hardware_msg_bit( msg
);
1066 /* now we can return it */
1067 if (!input
->msg_thread
) input
->msg_thread
= win_thread
;
1068 else release_object( win_thread
);
1071 reply
->type
= MSG_HARDWARE
;
1073 reply
->msg
= msg_code
;
1074 reply
->wparam
= msg
->wparam
;
1075 reply
->lparam
= msg
->lparam
;
1078 reply
->time
= msg
->time
;
1079 reply
->info
= msg
->info
;
1082 /* nothing found, clear the hardware queue bits */
1083 clear_queue_bits( thread
->queue
, clear_bits
);
1084 if (input
->msg_thread
) release_object( input
->msg_thread
);
1086 input
->msg_thread
= NULL
;
1090 /* increment (or decrement if 'incr' is negative) the queue paint count */
1091 void inc_queue_paint_count( struct thread
*thread
, int incr
)
1093 struct msg_queue
*queue
= thread
->queue
;
1097 if ((queue
->paint_count
+= incr
) < 0) queue
->paint_count
= 0;
1099 if (queue
->paint_count
)
1100 set_queue_bits( queue
, QS_PAINT
);
1102 clear_queue_bits( queue
, QS_PAINT
);
1106 /* remove all messages and timers belonging to a certain window */
1107 void queue_cleanup_window( struct thread
*thread
, user_handle_t win
)
1109 struct msg_queue
*queue
= thread
->queue
;
1110 struct timer
*timer
;
1111 struct message
*msg
;
1117 timer
= queue
->first_timer
;
1120 struct timer
*next
= timer
->next
;
1121 if (timer
->win
== win
)
1123 unlink_timer( queue
, timer
);
1129 /* remove messages */
1130 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
1132 msg
= queue
->msg_list
[i
].first
;
1135 struct message
*next
= msg
->next
;
1136 if (msg
->win
== win
) remove_queue_message( queue
, msg
, i
);
1141 thread_input_cleanup_window( queue
, win
);
1144 /* post a message to a window; used by socket handling */
1145 void post_message( user_handle_t win
, unsigned int message
,
1146 unsigned int wparam
, unsigned int lparam
)
1148 struct message
*msg
;
1149 struct thread
*thread
= get_window_thread( win
);
1151 if (!thread
) return;
1153 if (thread
->queue
&& (msg
= mem_alloc( sizeof(*msg
) )))
1155 msg
->type
= MSG_POSTED
;
1156 msg
->win
= get_user_full_handle( win
);
1158 msg
->wparam
= wparam
;
1159 msg
->lparam
= lparam
;
1160 msg
->time
= get_tick_count();
1168 append_message( &thread
->queue
->msg_list
[POST_MESSAGE
], msg
);
1169 set_queue_bits( thread
->queue
, QS_POSTMESSAGE
);
1171 release_object( thread
);
1175 /* get the message queue of the current thread */
1176 DECL_HANDLER(get_msg_queue
)
1178 struct msg_queue
*queue
= get_current_queue();
1181 if (queue
) reply
->handle
= alloc_handle( current
->process
, queue
, SYNCHRONIZE
, 0 );
1185 /* set the current message queue wakeup mask */
1186 DECL_HANDLER(set_queue_mask
)
1188 struct msg_queue
*queue
= get_current_queue();
1192 queue
->wake_mask
= req
->wake_mask
;
1193 queue
->changed_mask
= req
->changed_mask
;
1194 reply
->wake_bits
= queue
->wake_bits
;
1195 reply
->changed_bits
= queue
->changed_bits
;
1196 if (is_signaled( queue
))
1198 /* if skip wait is set, do what would have been done in the subsequent wait */
1199 if (req
->skip_wait
) msg_queue_satisfied( &queue
->obj
, current
);
1200 else wake_up( &queue
->obj
, 0 );
1206 /* get the current message queue status */
1207 DECL_HANDLER(get_queue_status
)
1209 struct msg_queue
*queue
= current
->queue
;
1212 reply
->wake_bits
= queue
->wake_bits
;
1213 reply
->changed_bits
= queue
->changed_bits
;
1214 if (req
->clear
) queue
->changed_bits
= 0;
1216 else reply
->wake_bits
= reply
->changed_bits
= 0;
1220 /* send a message to a thread queue */
1221 DECL_HANDLER(send_message
)
1223 struct message
*msg
;
1224 struct msg_queue
*send_queue
= get_current_queue();
1225 struct msg_queue
*recv_queue
= NULL
;
1226 struct thread
*thread
= NULL
;
1230 if (!(thread
= get_thread_from_id( req
->id
))) return;
1232 else if (req
->type
!= MSG_HARDWARE
)
1234 /* only hardware messages are allowed without destination thread */
1235 set_error( STATUS_INVALID_PARAMETER
);
1239 if (thread
&& !(recv_queue
= thread
->queue
))
1241 set_error( STATUS_INVALID_PARAMETER
);
1242 release_object( thread
);
1246 if ((msg
= mem_alloc( sizeof(*msg
) )))
1248 msg
->type
= req
->type
;
1249 msg
->win
= get_user_full_handle( req
->win
);
1250 msg
->msg
= req
->msg
;
1251 msg
->wparam
= req
->wparam
;
1252 msg
->lparam
= req
->lparam
;
1253 msg
->time
= req
->time
;
1256 msg
->info
= req
->info
;
1263 case MSG_OTHER_PROCESS
:
1264 msg
->data_size
= get_req_data_size();
1265 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
1274 if (!(msg
->result
= alloc_message_result( send_queue
, recv_queue
, req
->timeout
)))
1281 append_message( &recv_queue
->msg_list
[SEND_MESSAGE
], msg
);
1282 set_queue_bits( recv_queue
, QS_SENDMESSAGE
);
1285 /* needed for posted DDE messages */
1286 msg
->data_size
= get_req_data_size();
1287 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
1292 append_message( &recv_queue
->msg_list
[POST_MESSAGE
], msg
);
1293 set_queue_bits( recv_queue
, QS_POSTMESSAGE
);
1296 queue_hardware_message( recv_queue
, msg
);
1299 set_error( STATUS_INVALID_PARAMETER
);
1304 if (thread
) release_object( thread
);
1308 /* get a message from the current queue */
1309 DECL_HANDLER(get_message
)
1311 struct timer
*timer
;
1312 struct message
*msg
;
1313 struct message
*first_hw_msg
= NULL
;
1314 struct msg_queue
*queue
= get_current_queue();
1315 user_handle_t get_win
= get_user_full_handle( req
->get_win
);
1319 /* first of all release the hardware input lock if we own it */
1320 /* we'll grab it again if we find a hardware message */
1321 if (queue
->input
->msg_thread
== current
)
1323 first_hw_msg
= queue
->input
->msg
;
1324 release_hardware_message( current
, 0 );
1327 /* first check for sent messages */
1328 if ((msg
= queue
->msg_list
[SEND_MESSAGE
].first
))
1330 receive_message( queue
, msg
, reply
);
1333 if (req
->flags
& GET_MSG_SENT_ONLY
) goto done
; /* nothing else to check */
1335 /* clear changed bits so we can wait on them if we don't find a message */
1336 queue
->changed_bits
= 0;
1338 /* then check for posted messages */
1339 if (get_posted_message( queue
, get_win
, req
->get_first
, req
->get_last
, req
->flags
, reply
))
1342 /* then check for any raw hardware message */
1343 if (get_hardware_message( current
, first_hw_msg
, get_win
, reply
))
1346 /* now check for WM_PAINT */
1347 if (queue
->paint_count
&&
1348 (WM_PAINT
>= req
->get_first
) && (WM_PAINT
<= req
->get_last
) &&
1349 (reply
->win
= find_window_to_repaint( get_win
, current
)))
1351 reply
->type
= MSG_POSTED
;
1352 reply
->msg
= WM_PAINT
;
1357 reply
->time
= get_tick_count();
1362 /* now check for timer */
1363 if ((timer
= find_expired_timer( queue
, get_win
, req
->get_first
,
1364 req
->get_last
, (req
->flags
& GET_MSG_REMOVE
) )))
1366 reply
->type
= MSG_POSTED
;
1367 reply
->win
= timer
->win
;
1368 reply
->msg
= timer
->msg
;
1369 reply
->wparam
= timer
->id
;
1370 reply
->lparam
= timer
->lparam
;
1373 reply
->time
= get_tick_count();
1379 set_error( STATUS_PENDING
); /* FIXME */
1383 /* reply to a sent message */
1384 DECL_HANDLER(reply_message
)
1386 if (!current
->queue
)
1388 set_error( STATUS_ACCESS_DENIED
);
1391 if (current
->queue
->recv_result
)
1392 reply_message( current
->queue
, req
->result
, 0, req
->remove
,
1393 get_req_data(), get_req_data_size() );
1396 struct thread_input
*input
= current
->queue
->input
;
1397 if (input
->msg_thread
== current
) release_hardware_message( current
, req
->remove
);
1398 else set_error( STATUS_ACCESS_DENIED
);
1403 /* retrieve the reply for the last message sent */
1404 DECL_HANDLER(get_message_reply
)
1406 struct msg_queue
*queue
= current
->queue
;
1410 struct message_result
*result
= queue
->send_result
;
1412 set_error( STATUS_PENDING
);
1415 if (result
&& (result
->replied
|| req
->cancel
))
1417 if (result
->replied
)
1419 reply
->result
= result
->result
;
1420 set_error( result
->error
);
1423 size_t data_len
= min( result
->data_size
, get_reply_max_size() );
1424 set_reply_data_ptr( result
->data
, data_len
);
1425 result
->data
= NULL
;
1426 result
->data_size
= 0;
1429 queue
->send_result
= result
->send_next
;
1430 result
->sender
= NULL
;
1431 if (!result
->receiver
) free_result( result
);
1432 if (!queue
->send_result
|| !queue
->send_result
->replied
)
1433 clear_queue_bits( queue
, QS_SMRESULT
);
1436 else set_error( STATUS_ACCESS_DENIED
);
1440 /* set a window timer */
1441 DECL_HANDLER(set_win_timer
)
1443 struct timer
*timer
;
1444 struct msg_queue
*queue
= get_current_queue();
1445 user_handle_t win
= get_user_full_handle( req
->win
);
1449 /* remove it if it existed already */
1450 if (win
) kill_timer( queue
, win
, req
->msg
, req
->id
);
1452 if ((timer
= set_timer( queue
, req
->rate
)))
1455 timer
->msg
= req
->msg
;
1456 timer
->id
= req
->id
;
1457 timer
->lparam
= req
->lparam
;
1461 /* kill a window timer */
1462 DECL_HANDLER(kill_win_timer
)
1464 struct msg_queue
*queue
= current
->queue
;
1466 if (!queue
|| !kill_timer( queue
, get_user_full_handle(req
->win
), req
->msg
, req
->id
))
1467 set_error( STATUS_INVALID_PARAMETER
);
1471 /* attach (or detach) thread inputs */
1472 DECL_HANDLER(attach_thread_input
)
1474 struct thread
*thread_from
= get_thread_from_id( req
->tid_from
);
1475 struct thread
*thread_to
= get_thread_from_id( req
->tid_to
);
1477 if (!thread_from
|| !thread_to
)
1479 if (thread_from
) release_object( thread_from
);
1480 if (thread_to
) release_object( thread_to
);
1483 if (thread_from
!= thread_to
)
1485 if (req
->attach
) attach_thread_input( thread_from
, thread_to
);
1486 else detach_thread_input( thread_from
, thread_to
);
1488 else set_error( STATUS_ACCESS_DENIED
);
1489 release_object( thread_from
);
1490 release_object( thread_to
);
1494 /* get thread input data */
1495 DECL_HANDLER(get_thread_input
)
1497 struct thread
*thread
= NULL
;
1498 struct thread_input
*input
;
1502 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1503 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1505 else input
= foreground_input
; /* get the foreground thread info */
1509 reply
->focus
= input
->focus
;
1510 reply
->capture
= input
->capture
;
1511 reply
->active
= input
->active
;
1512 reply
->menu_owner
= input
->menu_owner
;
1513 reply
->move_size
= input
->move_size
;
1514 reply
->caret
= input
->caret
;
1515 reply
->rect
= input
->caret_rect
;
1522 reply
->menu_owner
= 0;
1523 reply
->move_size
= 0;
1525 reply
->rect
.left
= reply
->rect
.top
= reply
->rect
.right
= reply
->rect
.bottom
= 0;
1527 /* foreground window is active window of foreground thread */
1528 reply
->foreground
= foreground_input
? foreground_input
->active
: 0;
1529 if (thread
) release_object( thread
);
1533 /* retrieve queue keyboard state for a given thread */
1534 DECL_HANDLER(get_key_state
)
1536 struct thread
*thread
;
1537 struct thread_input
*input
;
1539 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1540 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1543 if (req
->key
>= 0) reply
->state
= input
->keystate
[req
->key
& 0xff];
1544 set_reply_data( input
->keystate
, min( get_reply_max_size(), sizeof(input
->keystate
) ));
1546 release_object( thread
);
1550 /* set queue keyboard state for a given thread */
1551 DECL_HANDLER(set_key_state
)
1553 struct thread
*thread
= NULL
;
1554 struct thread_input
*input
;
1556 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1557 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1560 size_t size
= min( sizeof(input
->keystate
), get_req_data_size() );
1561 if (size
) memcpy( input
->keystate
, get_req_data(), size
);
1563 release_object( thread
);
1567 /* set the system foreground window */
1568 DECL_HANDLER(set_foreground_window
)
1570 struct msg_queue
*queue
= get_current_queue();
1572 reply
->previous
= foreground_input
? foreground_input
->active
: 0;
1573 reply
->send_msg_old
= (reply
->previous
&& foreground_input
!= queue
->input
);
1574 reply
->send_msg_new
= FALSE
;
1578 struct thread
*thread
;
1580 if (is_top_level_window( req
->handle
) &&
1581 ((thread
= get_window_thread( req
->handle
))))
1583 foreground_input
= thread
->queue
->input
;
1584 reply
->send_msg_new
= (foreground_input
!= queue
->input
);
1585 release_object( thread
);
1587 else set_error( STATUS_INVALID_HANDLE
);
1589 else foreground_input
= NULL
;
1593 /* set the current thread focus window */
1594 DECL_HANDLER(set_focus_window
)
1596 struct msg_queue
*queue
= get_current_queue();
1598 reply
->previous
= 0;
1599 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1601 reply
->previous
= queue
->input
->focus
;
1602 queue
->input
->focus
= get_user_full_handle( req
->handle
);
1607 /* set the current thread active window */
1608 DECL_HANDLER(set_active_window
)
1610 struct msg_queue
*queue
= get_current_queue();
1612 reply
->previous
= 0;
1613 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1615 if (!req
->handle
|| make_window_active( req
->handle
))
1617 reply
->previous
= queue
->input
->active
;
1618 queue
->input
->active
= get_user_full_handle( req
->handle
);
1620 else set_error( STATUS_INVALID_HANDLE
);
1625 /* set the current thread capture window */
1626 DECL_HANDLER(set_capture_window
)
1628 struct msg_queue
*queue
= get_current_queue();
1630 reply
->previous
= reply
->full_handle
= 0;
1631 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1633 struct thread_input
*input
= queue
->input
;
1635 reply
->previous
= input
->capture
;
1636 input
->capture
= get_user_full_handle( req
->handle
);
1637 input
->menu_owner
= (req
->flags
& CAPTURE_MENU
) ? input
->capture
: 0;
1638 input
->move_size
= (req
->flags
& CAPTURE_MOVESIZE
) ? input
->capture
: 0;
1639 reply
->full_handle
= input
->capture
;
1644 /* Set the current thread caret window */
1645 DECL_HANDLER(set_caret_window
)
1647 struct msg_queue
*queue
= get_current_queue();
1649 reply
->previous
= 0;
1650 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1652 struct thread_input
*input
= queue
->input
;
1654 reply
->previous
= input
->caret
;
1655 reply
->old_rect
= input
->caret_rect
;
1656 reply
->old_hide
= input
->caret_hide
;
1657 reply
->old_state
= input
->caret_state
;
1659 set_caret_window( input
, get_user_full_handle(req
->handle
) );
1660 input
->caret_rect
.right
= req
->width
;
1661 input
->caret_rect
.bottom
= req
->height
;
1666 /* Set the current thread caret information */
1667 DECL_HANDLER(set_caret_info
)
1669 struct msg_queue
*queue
= get_current_queue();
1670 struct thread_input
*input
;
1673 input
= queue
->input
;
1674 reply
->full_handle
= input
->caret
;
1675 reply
->old_rect
= input
->caret_rect
;
1676 reply
->old_hide
= input
->caret_hide
;
1677 reply
->old_state
= input
->caret_state
;
1679 if (req
->handle
&& get_user_full_handle(req
->handle
) != input
->caret
)
1681 set_error( STATUS_ACCESS_DENIED
);
1684 if (req
->flags
& SET_CARET_POS
)
1686 input
->caret_rect
.right
+= req
->x
- input
->caret_rect
.left
;
1687 input
->caret_rect
.bottom
+= req
->y
- input
->caret_rect
.top
;
1688 input
->caret_rect
.left
= req
->x
;
1689 input
->caret_rect
.top
= req
->y
;
1691 if (req
->flags
& SET_CARET_HIDE
)
1693 input
->caret_hide
+= req
->hide
;
1694 if (input
->caret_hide
< 0) input
->caret_hide
= 0;
1696 if (req
->flags
& SET_CARET_STATE
)
1698 if (req
->state
== -1) input
->caret_state
= !input
->caret_state
;
1699 else input
->caret_state
= !!req
->state
;