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 no_get_fd
, /* get_fd */
147 msg_queue_destroy
/* destroy */
151 static const struct object_ops thread_input_ops
=
153 sizeof(struct thread_input
), /* size */
154 thread_input_dump
, /* dump */
155 no_add_queue
, /* add_queue */
156 NULL
, /* remove_queue */
158 NULL
, /* satisfied */
159 no_get_fd
, /* get_fd */
160 thread_input_destroy
/* destroy */
163 /* pointer to input structure of foreground thread */
164 static struct thread_input
*foreground_input
;
167 /* set the caret window in a given thread input */
168 static void set_caret_window( struct thread_input
*input
, user_handle_t win
)
171 input
->caret_rect
.left
= 0;
172 input
->caret_rect
.top
= 0;
173 input
->caret_rect
.right
= 0;
174 input
->caret_rect
.bottom
= 0;
175 input
->caret_hide
= 1;
176 input
->caret_state
= 0;
179 /* create a thread input object */
180 static struct thread_input
*create_thread_input(void)
182 struct thread_input
*input
;
184 if ((input
= alloc_object( &thread_input_ops
, -1 )))
189 input
->menu_owner
= 0;
190 input
->move_size
= 0;
192 input
->msg_thread
= NULL
;
193 input
->msg_list
.first
= input
->msg_list
.last
= NULL
;
194 set_caret_window( input
, 0 );
195 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
200 /* create a message queue object */
201 static struct msg_queue
*create_msg_queue( struct thread
*thread
, struct thread_input
*input
)
203 struct msg_queue
*queue
;
206 if (!input
&& !(input
= create_thread_input())) return NULL
;
207 if ((queue
= alloc_object( &msg_queue_ops
, -1 )))
209 queue
->wake_bits
= 0;
210 queue
->wake_mask
= 0;
211 queue
->changed_bits
= 0;
212 queue
->changed_mask
= 0;
213 queue
->paint_count
= 0;
214 queue
->send_result
= NULL
;
215 queue
->recv_result
= NULL
;
216 queue
->first_timer
= NULL
;
217 queue
->last_timer
= NULL
;
218 queue
->next_timer
= NULL
;
219 queue
->timeout
= NULL
;
220 queue
->input
= (struct thread_input
*)grab_object( input
);
221 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
222 queue
->msg_list
[i
].first
= queue
->msg_list
[i
].last
= NULL
;
224 thread
->queue
= queue
;
225 if (!thread
->process
->queue
)
226 thread
->process
->queue
= (struct msg_queue
*)grab_object( queue
);
228 release_object( input
);
232 /* free the message queue of a thread at thread exit */
233 void free_msg_queue( struct thread
*thread
)
235 struct process
*process
= thread
->process
;
237 if (!thread
->queue
) return;
238 if (process
->queue
== thread
->queue
) /* is it the process main queue? */
240 release_object( process
->queue
);
241 process
->queue
= NULL
;
242 if (process
->idle_event
)
244 set_event( process
->idle_event
);
245 release_object( process
->idle_event
);
246 process
->idle_event
= NULL
;
249 release_object( thread
->queue
);
250 thread
->queue
= NULL
;
253 /* check the queue status */
254 inline static int is_signaled( struct msg_queue
*queue
)
256 return ((queue
->wake_bits
& queue
->wake_mask
) || (queue
->changed_bits
& queue
->changed_mask
));
259 /* set some queue bits */
260 inline static void set_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
262 queue
->wake_bits
|= bits
;
263 queue
->changed_bits
|= bits
;
264 if (is_signaled( queue
)) wake_up( &queue
->obj
, 0 );
267 /* clear some queue bits */
268 inline static void clear_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
270 queue
->wake_bits
&= ~bits
;
271 queue
->changed_bits
&= ~bits
;
274 /* check whether msg is a keyboard message */
275 inline static int is_keyboard_msg( struct message
*msg
)
277 return (msg
->msg
>= WM_KEYFIRST
&& msg
->msg
<= WM_KEYLAST
);
280 /* get the QS_* bit corresponding to a given hardware message */
281 inline static int get_hardware_msg_bit( struct message
*msg
)
283 if (msg
->msg
== WM_MOUSEMOVE
|| msg
->msg
== WM_NCMOUSEMOVE
) return QS_MOUSEMOVE
;
284 if (is_keyboard_msg( msg
)) return QS_KEY
;
285 return QS_MOUSEBUTTON
;
288 /* get the current thread queue, creating it if needed */
289 inline static struct msg_queue
*get_current_queue(void)
291 struct msg_queue
*queue
= current
->queue
;
292 if (!queue
) queue
= create_msg_queue( current
, NULL
);
296 /* append a message to the end of a list */
297 inline static void append_message( struct message_list
*list
, struct message
*msg
)
300 if ((msg
->prev
= list
->last
)) msg
->prev
->next
= msg
;
301 else list
->first
= msg
;
305 /* unlink a message from a list it */
306 inline static void unlink_message( struct message_list
*list
, struct message
*msg
)
308 if (msg
->next
) msg
->next
->prev
= msg
->prev
;
309 else list
->last
= msg
->prev
;
310 if (msg
->prev
) msg
->prev
->next
= msg
->next
;
311 else list
->first
= msg
->next
;
314 /* try to merge a message with the last in the list; return 1 if successful */
315 static int merge_message( struct thread_input
*input
, const struct message
*msg
)
317 struct message
*prev
= input
->msg_list
.last
;
320 if (input
->msg
== prev
) return 0;
321 if (prev
->result
) return 0;
322 if (prev
->win
!= msg
->win
) return 0;
323 if (prev
->msg
!= msg
->msg
) return 0;
324 if (prev
->type
!= msg
->type
) return 0;
325 /* now we can merge it */
326 prev
->wparam
= msg
->wparam
;
327 prev
->lparam
= msg
->lparam
;
330 prev
->time
= msg
->time
;
331 prev
->info
= msg
->info
;
335 /* free a result structure */
336 static void free_result( struct message_result
*result
)
338 if (result
->timeout
) remove_timeout_user( result
->timeout
);
339 if (result
->data
) free( result
->data
);
343 /* store the message result in the appropriate structure */
344 static void store_message_result( struct message_result
*res
, unsigned int result
,
347 res
->result
= result
;
352 remove_timeout_user( res
->timeout
);
355 /* wake sender queue if waiting on this result */
356 if (res
->sender
&& res
->sender
->send_result
== res
)
357 set_queue_bits( res
->sender
, QS_SMRESULT
);
360 /* free a message when deleting a queue or window */
361 static void free_message( struct message
*msg
)
363 struct message_result
*result
= msg
->result
;
368 result
->receiver
= NULL
;
369 store_message_result( result
, 0, STATUS_ACCESS_DENIED
/*FIXME*/ );
371 else free_result( result
);
373 if (msg
->data
) free( msg
->data
);
377 /* remove (and free) a message from a message list */
378 static void remove_queue_message( struct msg_queue
*queue
, struct message
*msg
,
379 enum message_kind kind
)
381 unlink_message( &queue
->msg_list
[kind
], msg
);
385 if (!queue
->msg_list
[kind
].first
) clear_queue_bits( queue
, QS_SENDMESSAGE
);
388 if (!queue
->msg_list
[kind
].first
) clear_queue_bits( queue
, QS_POSTMESSAGE
);
394 /* message timed out without getting a reply */
395 static void result_timeout( void *private )
397 struct message_result
*result
= private;
399 assert( !result
->replied
);
401 result
->timeout
= NULL
;
402 store_message_result( result
, 0, STATUS_TIMEOUT
);
405 /* allocate and fill a message result structure */
406 static struct message_result
*alloc_message_result( struct msg_queue
*send_queue
,
407 struct msg_queue
*recv_queue
,
408 unsigned int timeout
)
410 struct message_result
*result
= mem_alloc( sizeof(*result
) );
413 /* put the result on the sender result stack */
414 result
->sender
= send_queue
;
415 result
->receiver
= recv_queue
;
418 result
->data_size
= 0;
419 result
->timeout
= NULL
;
420 result
->send_next
= send_queue
->send_result
;
421 send_queue
->send_result
= result
;
425 gettimeofday( &when
, 0 );
426 add_timeout( &when
, timeout
);
427 result
->timeout
= add_timeout_user( &when
, result_timeout
, result
);
433 /* receive a message, removing it from the sent queue */
434 static void receive_message( struct msg_queue
*queue
, struct message
*msg
,
435 struct get_message_reply
*reply
)
437 struct message_result
*result
= msg
->result
;
439 reply
->total
= msg
->data_size
;
440 if (msg
->data_size
> get_reply_max_size())
442 set_error( STATUS_BUFFER_OVERFLOW
);
445 reply
->type
= msg
->type
;
446 reply
->win
= msg
->win
;
447 reply
->msg
= msg
->msg
;
448 reply
->wparam
= msg
->wparam
;
449 reply
->lparam
= msg
->lparam
;
452 reply
->time
= msg
->time
;
453 reply
->info
= msg
->info
;
455 if (msg
->data
) set_reply_data_ptr( msg
->data
, msg
->data_size
);
457 unlink_message( &queue
->msg_list
[SEND_MESSAGE
], msg
);
458 /* put the result on the receiver result stack */
461 result
->recv_next
= queue
->recv_result
;
462 queue
->recv_result
= result
;
465 if (!queue
->msg_list
[SEND_MESSAGE
].first
) clear_queue_bits( queue
, QS_SENDMESSAGE
);
468 /* set the result of the current received message */
469 static void reply_message( struct msg_queue
*queue
, unsigned int result
,
470 unsigned int error
, int remove
, const void *data
, size_t len
)
472 struct message_result
*res
= queue
->recv_result
;
476 queue
->recv_result
= res
->recv_next
;
477 res
->receiver
= NULL
;
478 if (!res
->sender
) /* no one waiting for it */
486 if (len
&& (res
->data
= memdup( data
, len
))) res
->data_size
= len
;
487 store_message_result( res
, result
, error
);
491 /* retrieve a posted message */
492 static int get_posted_message( struct msg_queue
*queue
, user_handle_t win
,
493 unsigned int first
, unsigned int last
, unsigned int flags
,
494 struct get_message_reply
*reply
)
497 struct message_list
*list
= &queue
->msg_list
[POST_MESSAGE
];
499 /* check against the filters */
500 for (msg
= list
->first
; msg
; msg
= msg
->next
)
502 if (msg
->msg
== WM_QUIT
) break; /* WM_QUIT is never filtered */
503 if (win
&& msg
->win
&& msg
->win
!= win
&& !is_child_window( win
, msg
->win
)) continue;
504 if (msg
->msg
< first
) continue;
505 if (msg
->msg
> last
) continue;
506 break; /* found one */
510 /* return it to the app */
512 reply
->total
= msg
->data_size
;
513 if (msg
->data_size
> get_reply_max_size())
515 set_error( STATUS_BUFFER_OVERFLOW
);
518 reply
->type
= msg
->type
;
519 reply
->win
= msg
->win
;
520 reply
->msg
= msg
->msg
;
521 reply
->wparam
= msg
->wparam
;
522 reply
->lparam
= msg
->lparam
;
525 reply
->time
= msg
->time
;
526 reply
->info
= msg
->info
;
528 if (flags
& GET_MSG_REMOVE
)
532 set_reply_data_ptr( msg
->data
, msg
->data_size
);
536 remove_queue_message( queue
, msg
, POST_MESSAGE
);
538 else if (msg
->data
) set_reply_data( msg
->data
, msg
->data_size
);
543 /* empty a message list and free all the messages */
544 static void empty_msg_list( struct message_list
*list
)
546 struct message
*msg
= list
->first
;
549 struct message
*next
= msg
->next
;
555 /* cleanup all pending results when deleting a queue */
556 static void cleanup_results( struct msg_queue
*queue
)
558 struct message_result
*result
, *next
;
560 result
= queue
->send_result
;
563 next
= result
->send_next
;
564 result
->sender
= NULL
;
565 if (!result
->receiver
) free_result( result
);
569 while (queue
->recv_result
)
570 reply_message( queue
, 0, STATUS_ACCESS_DENIED
/*FIXME*/, 1, NULL
, 0 );
573 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
)
575 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
576 struct process
*process
= entry
->thread
->process
;
578 /* a thread can only wait on its own queue */
579 if (entry
->thread
->queue
!= queue
)
581 set_error( STATUS_ACCESS_DENIED
);
584 /* if waiting on the main process queue, set the idle event */
585 if (process
->queue
== queue
)
587 if (process
->idle_event
) set_event( process
->idle_event
);
589 add_queue( obj
, entry
);
593 static void msg_queue_remove_queue(struct object
*obj
, struct wait_queue_entry
*entry
)
595 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
596 struct process
*process
= entry
->thread
->process
;
598 remove_queue( obj
, entry
);
600 assert( entry
->thread
->queue
== queue
);
602 /* if waiting on the main process queue, reset the idle event */
603 if (process
->queue
== queue
)
605 if (process
->idle_event
) reset_event( process
->idle_event
);
609 static void msg_queue_dump( struct object
*obj
, int verbose
)
611 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
612 fprintf( stderr
, "Msg queue bits=%x mask=%x\n",
613 queue
->wake_bits
, queue
->wake_mask
);
616 static int msg_queue_signaled( struct object
*obj
, struct thread
*thread
)
618 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
619 return is_signaled( queue
);
622 static int msg_queue_satisfied( struct object
*obj
, struct thread
*thread
)
624 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
625 queue
->wake_mask
= 0;
626 queue
->changed_mask
= 0;
627 return 0; /* Not abandoned */
630 static void msg_queue_destroy( struct object
*obj
)
632 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
633 struct timer
*timer
= queue
->first_timer
;
636 cleanup_results( queue
);
637 for (i
= 0; i
< NB_MSG_KINDS
; i
++) empty_msg_list( &queue
->msg_list
[i
] );
641 struct timer
*next
= timer
->next
;
645 if (queue
->timeout
) remove_timeout_user( queue
->timeout
);
646 if (queue
->input
) release_object( queue
->input
);
649 static void thread_input_dump( struct object
*obj
, int verbose
)
651 struct thread_input
*input
= (struct thread_input
*)obj
;
652 fprintf( stderr
, "Thread input focus=%p capture=%p active=%p\n",
653 input
->focus
, input
->capture
, input
->active
);
656 static void thread_input_destroy( struct object
*obj
)
658 struct thread_input
*input
= (struct thread_input
*)obj
;
660 if (foreground_input
== input
) foreground_input
= NULL
;
661 if (input
->msg_thread
) release_object( input
->msg_thread
);
662 empty_msg_list( &input
->msg_list
);
665 /* fix the thread input data when a window is destroyed */
666 inline static void thread_input_cleanup_window( struct msg_queue
*queue
, user_handle_t window
)
668 struct thread_input
*input
= queue
->input
;
670 if (window
== input
->focus
) input
->focus
= 0;
671 if (window
== input
->capture
) input
->capture
= 0;
672 if (window
== input
->active
) input
->active
= 0;
673 if (window
== input
->menu_owner
) input
->menu_owner
= 0;
674 if (window
== input
->move_size
) input
->move_size
= 0;
675 if (window
== input
->caret
) set_caret_window( input
, 0 );
678 /* check if the specified window can be set in the input data of a given queue */
679 static int check_queue_input_window( struct msg_queue
*queue
, user_handle_t window
)
681 struct thread
*thread
;
684 if (!window
) return 1; /* we can always clear the data */
686 if ((thread
= get_window_thread( window
)))
688 ret
= (queue
->input
== thread
->queue
->input
);
689 if (!ret
) set_error( STATUS_ACCESS_DENIED
);
690 release_object( thread
);
692 else set_error( STATUS_INVALID_HANDLE
);
697 /* attach two thread input data structures */
698 int attach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
700 struct thread_input
*input
;
702 if (!thread_to
->queue
&& !(thread_to
->queue
= create_msg_queue( thread_to
, NULL
))) return 0;
703 input
= (struct thread_input
*)grab_object( thread_to
->queue
->input
);
705 if (thread_from
->queue
)
707 release_object( thread_from
->queue
->input
);
708 thread_from
->queue
->input
= input
;
712 if (!(thread_from
->queue
= create_msg_queue( thread_from
, input
))) return 0;
714 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
718 /* detach two thread input data structures */
719 static void detach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
721 struct thread_input
*input
;
723 if (!thread_from
->queue
|| !thread_to
->queue
||
724 thread_from
->queue
->input
!= thread_to
->queue
->input
)
726 set_error( STATUS_ACCESS_DENIED
);
729 if ((input
= create_thread_input()))
731 release_object( thread_from
->queue
->input
);
732 thread_from
->queue
->input
= input
;
737 /* set the next timer to expire */
738 static void set_next_timer( struct msg_queue
*queue
, struct timer
*timer
)
742 remove_timeout_user( queue
->timeout
);
743 queue
->timeout
= NULL
;
745 if ((queue
->next_timer
= timer
))
746 queue
->timeout
= add_timeout_user( &timer
->when
, timer_callback
, queue
);
748 /* set/clear QS_TIMER bit */
749 if (queue
->next_timer
== queue
->first_timer
)
750 clear_queue_bits( queue
, QS_TIMER
);
752 set_queue_bits( queue
, QS_TIMER
);
755 /* callback for the next timer expiration */
756 static void timer_callback( void *private )
758 struct msg_queue
*queue
= private;
760 queue
->timeout
= NULL
;
761 /* move on to the next timer */
762 set_next_timer( queue
, queue
->next_timer
->next
);
765 /* link a timer at its rightful place in the queue list */
766 static void link_timer( struct msg_queue
*queue
, struct timer
*timer
)
768 struct timer
*pos
= queue
->next_timer
;
770 while (pos
&& time_before( &pos
->when
, &timer
->when
)) pos
= pos
->next
;
772 if (pos
) /* insert before pos */
774 if ((timer
->prev
= pos
->prev
)) timer
->prev
->next
= timer
;
775 else queue
->first_timer
= timer
;
779 else /* insert at end */
782 timer
->prev
= queue
->last_timer
;
783 if (queue
->last_timer
) queue
->last_timer
->next
= timer
;
784 else queue
->first_timer
= timer
;
785 queue
->last_timer
= timer
;
787 /* check if we replaced the next timer */
788 if (pos
== queue
->next_timer
) set_next_timer( queue
, timer
);
791 /* remove a timer from the queue timer list */
792 static void unlink_timer( struct msg_queue
*queue
, struct timer
*timer
)
794 if (timer
->next
) timer
->next
->prev
= timer
->prev
;
795 else queue
->last_timer
= timer
->prev
;
796 if (timer
->prev
) timer
->prev
->next
= timer
->next
;
797 else queue
->first_timer
= timer
->next
;
798 /* check if we removed the next timer */
799 if (queue
->next_timer
== timer
) set_next_timer( queue
, timer
->next
);
800 else if (queue
->next_timer
== queue
->first_timer
) clear_queue_bits( queue
, QS_TIMER
);
803 /* restart an expired timer */
804 static void restart_timer( struct msg_queue
*queue
, struct timer
*timer
)
807 unlink_timer( queue
, timer
);
808 gettimeofday( &now
, 0 );
809 while (!time_before( &now
, &timer
->when
)) add_timeout( &timer
->when
, timer
->rate
);
810 link_timer( queue
, timer
);
813 /* find an expired timer matching the filtering parameters */
814 static struct timer
*find_expired_timer( struct msg_queue
*queue
, user_handle_t win
,
815 unsigned int get_first
, unsigned int get_last
,
819 for (timer
= queue
->first_timer
; (timer
&& timer
!= queue
->next_timer
); timer
= timer
->next
)
821 if (win
&& timer
->win
!= win
) continue;
822 if (timer
->msg
>= get_first
&& timer
->msg
<= get_last
)
824 if (remove
) restart_timer( queue
, timer
);
832 static int kill_timer( struct msg_queue
*queue
, user_handle_t win
,
833 unsigned int msg
, unsigned int id
)
837 for (timer
= queue
->first_timer
; timer
; timer
= timer
->next
)
839 if (timer
->win
!= win
|| timer
->msg
!= msg
|| timer
->id
!= id
) continue;
840 unlink_timer( queue
, timer
);
848 static struct timer
*set_timer( struct msg_queue
*queue
, unsigned int rate
)
850 struct timer
*timer
= mem_alloc( sizeof(*timer
) );
854 gettimeofday( &timer
->when
, 0 );
855 add_timeout( &timer
->when
, rate
);
856 link_timer( queue
, timer
);
861 /* change the input key state for a given key */
862 static void set_input_key_state( struct thread_input
*input
, unsigned char key
, int down
)
866 if (!(input
->keystate
[key
] & 0x80)) input
->keystate
[key
] ^= 0x01;
867 input
->keystate
[key
] |= 0x80;
869 else input
->keystate
[key
] &= ~0x80;
872 /* update the input key state for a keyboard message */
873 static void update_input_key_state( struct thread_input
*input
, const struct message
*msg
)
876 int down
= 0, extended
;
884 set_input_key_state( input
, VK_LBUTTON
, down
);
890 set_input_key_state( input
, VK_MBUTTON
, down
);
896 set_input_key_state( input
, VK_RBUTTON
, down
);
904 key
= (unsigned char)msg
->wparam
;
905 extended
= ((msg
->lparam
>> 16) & KF_EXTENDED
) != 0;
906 set_input_key_state( input
, key
, down
);
910 set_input_key_state( input
, extended
? VK_RSHIFT
: VK_LSHIFT
, down
);
913 set_input_key_state( input
, extended
? VK_RCONTROL
: VK_LCONTROL
, down
);
916 set_input_key_state( input
, extended
? VK_RMENU
: VK_LMENU
, down
);
923 /* release the hardware message currently being processed by the given thread */
924 static void release_hardware_message( struct thread
*thread
, int remove
)
926 struct thread_input
*input
= thread
->queue
->input
;
928 if (input
->msg_thread
!= thread
) return;
931 struct message
*other
;
934 update_input_key_state( input
, input
->msg
);
935 unlink_message( &input
->msg_list
, input
->msg
);
936 clr_bit
= get_hardware_msg_bit( input
->msg
);
937 for (other
= input
->msg_list
.first
; other
; other
= other
->next
)
938 if (get_hardware_msg_bit( other
) == clr_bit
) break;
939 if (!other
) clear_queue_bits( thread
->queue
, clr_bit
);
940 free_message( input
->msg
);
942 release_object( input
->msg_thread
);
944 input
->msg_thread
= NULL
;
947 /* find the window that should receive a given hardware message */
948 static user_handle_t
find_hardware_message_window( struct thread_input
*input
, struct message
*msg
,
949 unsigned int *msg_code
)
951 user_handle_t win
= 0;
953 *msg_code
= msg
->msg
;
954 if (is_keyboard_msg( msg
))
956 if (input
&& !(win
= input
->focus
))
959 if (*msg_code
< WM_SYSKEYDOWN
) *msg_code
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
962 else /* mouse message */
964 if (!input
|| !(win
= input
->capture
))
966 if (!(win
= msg
->win
)) win
= window_from_point( msg
->x
, msg
->y
);
972 /* queue a hardware message into a given thread input */
973 static void queue_hardware_message( struct msg_queue
*queue
, struct message
*msg
)
976 struct thread
*thread
;
977 struct thread_input
*input
;
978 unsigned int msg_code
;
980 win
= find_hardware_message_window( queue
? queue
->input
: foreground_input
, msg
, &msg_code
);
981 if (!win
|| !(thread
= get_window_thread(win
)))
986 input
= thread
->queue
->input
;
988 if (msg
->msg
== WM_MOUSEMOVE
&& merge_message( input
, msg
)) free( msg
);
991 append_message( &input
->msg_list
, msg
);
992 set_queue_bits( thread
->queue
, get_hardware_msg_bit(msg
) );
994 release_object( thread
);
997 /* find a hardware message for the given queue */
998 static int get_hardware_message( struct thread
*thread
, struct message
*first
,
999 user_handle_t filter_win
, struct get_message_reply
*reply
)
1001 struct thread_input
*input
= thread
->queue
->input
;
1002 struct thread
*win_thread
;
1003 struct message
*msg
;
1005 int clear_bits
, got_one
= 0;
1006 unsigned int msg_code
;
1008 if (input
->msg_thread
&& input
->msg_thread
!= thread
)
1009 return 0; /* locked by another thread */
1013 msg
= input
->msg_list
.first
;
1014 clear_bits
= QS_KEY
| QS_MOUSEMOVE
| QS_MOUSEBUTTON
;
1019 clear_bits
= 0; /* don't clear bits if we don't go through the whole list */
1024 win
= find_hardware_message_window( input
, msg
, &msg_code
);
1025 if (!win
|| !(win_thread
= get_window_thread( win
)))
1027 /* no window at all, remove it */
1028 struct message
*next
= msg
->next
;
1029 update_input_key_state( input
, msg
);
1030 unlink_message( &input
->msg_list
, msg
);
1031 free_message( msg
);
1035 if (win_thread
!= thread
)
1037 /* wake the other thread */
1038 set_queue_bits( win_thread
->queue
, get_hardware_msg_bit(msg
) );
1039 release_object( win_thread
);
1044 /* if we already got a message for another thread, or if it doesn't
1045 * match the filter we skip it (filter is only checked for keyboard
1046 * messages since the dest window for a mouse message depends on hittest)
1049 (filter_win
&& is_keyboard_msg(msg
) &&
1050 win
!= filter_win
&& !is_child_window( filter_win
, win
)))
1052 clear_bits
&= ~get_hardware_msg_bit( msg
);
1056 /* now we can return it */
1057 if (!input
->msg_thread
) input
->msg_thread
= win_thread
;
1058 else release_object( win_thread
);
1061 reply
->type
= MSG_HARDWARE
;
1063 reply
->msg
= msg_code
;
1064 reply
->wparam
= msg
->wparam
;
1065 reply
->lparam
= msg
->lparam
;
1068 reply
->time
= msg
->time
;
1069 reply
->info
= msg
->info
;
1072 /* nothing found, clear the hardware queue bits */
1073 clear_queue_bits( thread
->queue
, clear_bits
);
1074 if (input
->msg_thread
) release_object( input
->msg_thread
);
1076 input
->msg_thread
= NULL
;
1080 /* increment (or decrement if 'incr' is negative) the queue paint count */
1081 void inc_queue_paint_count( struct thread
*thread
, int incr
)
1083 struct msg_queue
*queue
= thread
->queue
;
1087 if ((queue
->paint_count
+= incr
) < 0) queue
->paint_count
= 0;
1089 if (queue
->paint_count
)
1090 set_queue_bits( queue
, QS_PAINT
);
1092 clear_queue_bits( queue
, QS_PAINT
);
1096 /* remove all messages and timers belonging to a certain window */
1097 void queue_cleanup_window( struct thread
*thread
, user_handle_t win
)
1099 struct msg_queue
*queue
= thread
->queue
;
1100 struct timer
*timer
;
1101 struct message
*msg
;
1107 timer
= queue
->first_timer
;
1110 struct timer
*next
= timer
->next
;
1111 if (timer
->win
== win
)
1113 unlink_timer( queue
, timer
);
1119 /* remove messages */
1120 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
1122 msg
= queue
->msg_list
[i
].first
;
1125 struct message
*next
= msg
->next
;
1126 if (msg
->win
== win
) remove_queue_message( queue
, msg
, i
);
1131 thread_input_cleanup_window( queue
, win
);
1134 /* post a message to a window; used by socket handling */
1135 void post_message( user_handle_t win
, unsigned int message
,
1136 unsigned int wparam
, unsigned int lparam
)
1138 struct message
*msg
;
1139 struct thread
*thread
= get_window_thread( win
);
1141 if (!thread
) return;
1143 if (thread
->queue
&& (msg
= mem_alloc( sizeof(*msg
) )))
1145 msg
->type
= MSG_POSTED
;
1146 msg
->win
= get_user_full_handle( win
);
1148 msg
->wparam
= wparam
;
1149 msg
->lparam
= lparam
;
1150 msg
->time
= get_tick_count();
1158 append_message( &thread
->queue
->msg_list
[POST_MESSAGE
], msg
);
1159 set_queue_bits( thread
->queue
, QS_POSTMESSAGE
);
1161 release_object( thread
);
1165 /* get the message queue of the current thread */
1166 DECL_HANDLER(get_msg_queue
)
1168 struct msg_queue
*queue
= get_current_queue();
1171 if (queue
) reply
->handle
= alloc_handle( current
->process
, queue
, SYNCHRONIZE
, 0 );
1175 /* set the current message queue wakeup mask */
1176 DECL_HANDLER(set_queue_mask
)
1178 struct msg_queue
*queue
= get_current_queue();
1182 queue
->wake_mask
= req
->wake_mask
;
1183 queue
->changed_mask
= req
->changed_mask
;
1184 reply
->wake_bits
= queue
->wake_bits
;
1185 reply
->changed_bits
= queue
->changed_bits
;
1186 if (is_signaled( queue
))
1188 /* if skip wait is set, do what would have been done in the subsequent wait */
1189 if (req
->skip_wait
) msg_queue_satisfied( &queue
->obj
, current
);
1190 else wake_up( &queue
->obj
, 0 );
1196 /* get the current message queue status */
1197 DECL_HANDLER(get_queue_status
)
1199 struct msg_queue
*queue
= current
->queue
;
1202 reply
->wake_bits
= queue
->wake_bits
;
1203 reply
->changed_bits
= queue
->changed_bits
;
1204 if (req
->clear
) queue
->changed_bits
= 0;
1206 else reply
->wake_bits
= reply
->changed_bits
= 0;
1210 /* send a message to a thread queue */
1211 DECL_HANDLER(send_message
)
1213 struct message
*msg
;
1214 struct msg_queue
*send_queue
= get_current_queue();
1215 struct msg_queue
*recv_queue
= NULL
;
1216 struct thread
*thread
= NULL
;
1220 if (!(thread
= get_thread_from_id( req
->id
))) return;
1222 else if (req
->type
!= MSG_HARDWARE
)
1224 /* only hardware messages are allowed without destination thread */
1225 set_error( STATUS_INVALID_PARAMETER
);
1229 if (thread
&& !(recv_queue
= thread
->queue
))
1231 set_error( STATUS_INVALID_PARAMETER
);
1232 release_object( thread
);
1236 if ((msg
= mem_alloc( sizeof(*msg
) )))
1238 msg
->type
= req
->type
;
1239 msg
->win
= get_user_full_handle( req
->win
);
1240 msg
->msg
= req
->msg
;
1241 msg
->wparam
= req
->wparam
;
1242 msg
->lparam
= req
->lparam
;
1243 msg
->time
= req
->time
;
1246 msg
->info
= req
->info
;
1253 case MSG_OTHER_PROCESS
:
1254 msg
->data_size
= get_req_data_size();
1255 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
1264 if (!(msg
->result
= alloc_message_result( send_queue
, recv_queue
, req
->timeout
)))
1271 append_message( &recv_queue
->msg_list
[SEND_MESSAGE
], msg
);
1272 set_queue_bits( recv_queue
, QS_SENDMESSAGE
);
1275 /* needed for posted DDE messages */
1276 msg
->data_size
= get_req_data_size();
1277 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
1282 append_message( &recv_queue
->msg_list
[POST_MESSAGE
], msg
);
1283 set_queue_bits( recv_queue
, QS_POSTMESSAGE
);
1286 queue_hardware_message( recv_queue
, msg
);
1289 set_error( STATUS_INVALID_PARAMETER
);
1294 if (thread
) release_object( thread
);
1298 /* get a message from the current queue */
1299 DECL_HANDLER(get_message
)
1301 struct timer
*timer
;
1302 struct message
*msg
;
1303 struct message
*first_hw_msg
= NULL
;
1304 struct msg_queue
*queue
= get_current_queue();
1305 user_handle_t get_win
= get_user_full_handle( req
->get_win
);
1309 /* first of all release the hardware input lock if we own it */
1310 /* we'll grab it again if we find a hardware message */
1311 if (queue
->input
->msg_thread
== current
)
1313 first_hw_msg
= queue
->input
->msg
;
1314 release_hardware_message( current
, 0 );
1317 /* first check for sent messages */
1318 if ((msg
= queue
->msg_list
[SEND_MESSAGE
].first
))
1320 receive_message( queue
, msg
, reply
);
1323 if (req
->flags
& GET_MSG_SENT_ONLY
) goto done
; /* nothing else to check */
1325 /* clear changed bits so we can wait on them if we don't find a message */
1326 queue
->changed_bits
= 0;
1328 /* then check for posted messages */
1329 if (get_posted_message( queue
, get_win
, req
->get_first
, req
->get_last
, req
->flags
, reply
))
1332 /* then check for any raw hardware message */
1333 if (get_hardware_message( current
, first_hw_msg
, get_win
, reply
))
1336 /* now check for WM_PAINT */
1337 if (queue
->paint_count
&&
1338 (WM_PAINT
>= req
->get_first
) && (WM_PAINT
<= req
->get_last
) &&
1339 (reply
->win
= find_window_to_repaint( get_win
, current
)))
1341 reply
->type
= MSG_POSTED
;
1342 reply
->msg
= WM_PAINT
;
1347 reply
->time
= get_tick_count();
1352 /* now check for timer */
1353 if ((timer
= find_expired_timer( queue
, get_win
, req
->get_first
,
1354 req
->get_last
, (req
->flags
& GET_MSG_REMOVE
) )))
1356 reply
->type
= MSG_POSTED
;
1357 reply
->win
= timer
->win
;
1358 reply
->msg
= timer
->msg
;
1359 reply
->wparam
= timer
->id
;
1360 reply
->lparam
= timer
->lparam
;
1363 reply
->time
= get_tick_count();
1369 set_error( STATUS_PENDING
); /* FIXME */
1373 /* reply to a sent message */
1374 DECL_HANDLER(reply_message
)
1376 if (!current
->queue
)
1378 set_error( STATUS_ACCESS_DENIED
);
1381 if (current
->queue
->recv_result
)
1382 reply_message( current
->queue
, req
->result
, 0, req
->remove
,
1383 get_req_data(), get_req_data_size() );
1386 struct thread_input
*input
= current
->queue
->input
;
1387 if (input
->msg_thread
== current
) release_hardware_message( current
, req
->remove
);
1388 else set_error( STATUS_ACCESS_DENIED
);
1393 /* retrieve the reply for the last message sent */
1394 DECL_HANDLER(get_message_reply
)
1396 struct msg_queue
*queue
= current
->queue
;
1400 struct message_result
*result
= queue
->send_result
;
1402 set_error( STATUS_PENDING
);
1405 if (result
&& (result
->replied
|| req
->cancel
))
1407 if (result
->replied
)
1409 reply
->result
= result
->result
;
1410 set_error( result
->error
);
1413 size_t data_len
= min( result
->data_size
, get_reply_max_size() );
1414 set_reply_data_ptr( result
->data
, data_len
);
1415 result
->data
= NULL
;
1416 result
->data_size
= 0;
1419 queue
->send_result
= result
->send_next
;
1420 result
->sender
= NULL
;
1421 if (!result
->receiver
) free_result( result
);
1422 if (!queue
->send_result
|| !queue
->send_result
->replied
)
1423 clear_queue_bits( queue
, QS_SMRESULT
);
1426 else set_error( STATUS_ACCESS_DENIED
);
1430 /* set a window timer */
1431 DECL_HANDLER(set_win_timer
)
1433 struct timer
*timer
;
1434 struct msg_queue
*queue
= get_current_queue();
1435 user_handle_t win
= get_user_full_handle( req
->win
);
1439 /* remove it if it existed already */
1440 if (win
) kill_timer( queue
, win
, req
->msg
, req
->id
);
1442 if ((timer
= set_timer( queue
, req
->rate
)))
1445 timer
->msg
= req
->msg
;
1446 timer
->id
= req
->id
;
1447 timer
->lparam
= req
->lparam
;
1451 /* kill a window timer */
1452 DECL_HANDLER(kill_win_timer
)
1454 struct msg_queue
*queue
= current
->queue
;
1456 if (!queue
|| !kill_timer( queue
, get_user_full_handle(req
->win
), req
->msg
, req
->id
))
1457 set_error( STATUS_INVALID_PARAMETER
);
1461 /* attach (or detach) thread inputs */
1462 DECL_HANDLER(attach_thread_input
)
1464 struct thread
*thread_from
= get_thread_from_id( req
->tid_from
);
1465 struct thread
*thread_to
= get_thread_from_id( req
->tid_to
);
1467 if (!thread_from
|| !thread_to
)
1469 if (thread_from
) release_object( thread_from
);
1470 if (thread_to
) release_object( thread_to
);
1473 if (thread_from
!= thread_to
)
1475 if (req
->attach
) attach_thread_input( thread_from
, thread_to
);
1476 else detach_thread_input( thread_from
, thread_to
);
1478 else set_error( STATUS_ACCESS_DENIED
);
1479 release_object( thread_from
);
1480 release_object( thread_to
);
1484 /* get thread input data */
1485 DECL_HANDLER(get_thread_input
)
1487 struct thread
*thread
= NULL
;
1488 struct thread_input
*input
;
1492 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1493 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1495 else input
= foreground_input
; /* get the foreground thread info */
1499 reply
->focus
= input
->focus
;
1500 reply
->capture
= input
->capture
;
1501 reply
->active
= input
->active
;
1502 reply
->menu_owner
= input
->menu_owner
;
1503 reply
->move_size
= input
->move_size
;
1504 reply
->caret
= input
->caret
;
1505 reply
->rect
= input
->caret_rect
;
1512 reply
->menu_owner
= 0;
1513 reply
->move_size
= 0;
1515 reply
->rect
.left
= reply
->rect
.top
= reply
->rect
.right
= reply
->rect
.bottom
= 0;
1517 /* foreground window is active window of foreground thread */
1518 reply
->foreground
= foreground_input
? foreground_input
->active
: 0;
1519 if (thread
) release_object( thread
);
1523 /* retrieve queue keyboard state for a given thread */
1524 DECL_HANDLER(get_key_state
)
1526 struct thread
*thread
;
1527 struct thread_input
*input
;
1529 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1530 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1533 if (req
->key
>= 0) reply
->state
= input
->keystate
[req
->key
& 0xff];
1534 set_reply_data( input
->keystate
, min( get_reply_max_size(), sizeof(input
->keystate
) ));
1536 release_object( thread
);
1540 /* set queue keyboard state for a given thread */
1541 DECL_HANDLER(set_key_state
)
1543 struct thread
*thread
= NULL
;
1544 struct thread_input
*input
;
1546 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1547 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1550 size_t size
= min( sizeof(input
->keystate
), get_req_data_size() );
1551 if (size
) memcpy( input
->keystate
, get_req_data(), size
);
1553 release_object( thread
);
1557 /* set the system foreground window */
1558 DECL_HANDLER(set_foreground_window
)
1560 struct msg_queue
*queue
= get_current_queue();
1562 reply
->previous
= foreground_input
? foreground_input
->active
: 0;
1563 reply
->send_msg_old
= (reply
->previous
&& foreground_input
!= queue
->input
);
1564 reply
->send_msg_new
= FALSE
;
1568 struct thread
*thread
;
1570 if (is_top_level_window( req
->handle
) &&
1571 ((thread
= get_window_thread( req
->handle
))))
1573 foreground_input
= thread
->queue
->input
;
1574 reply
->send_msg_new
= (foreground_input
!= queue
->input
);
1575 release_object( thread
);
1577 else set_error( STATUS_INVALID_HANDLE
);
1579 else foreground_input
= NULL
;
1583 /* set the current thread focus window */
1584 DECL_HANDLER(set_focus_window
)
1586 struct msg_queue
*queue
= get_current_queue();
1588 reply
->previous
= 0;
1589 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1591 reply
->previous
= queue
->input
->focus
;
1592 queue
->input
->focus
= get_user_full_handle( req
->handle
);
1597 /* set the current thread active window */
1598 DECL_HANDLER(set_active_window
)
1600 struct msg_queue
*queue
= get_current_queue();
1602 reply
->previous
= 0;
1603 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1605 if (!req
->handle
|| make_window_active( req
->handle
))
1607 reply
->previous
= queue
->input
->active
;
1608 queue
->input
->active
= get_user_full_handle( req
->handle
);
1610 else set_error( STATUS_INVALID_HANDLE
);
1615 /* set the current thread capture window */
1616 DECL_HANDLER(set_capture_window
)
1618 struct msg_queue
*queue
= get_current_queue();
1620 reply
->previous
= reply
->full_handle
= 0;
1621 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1623 struct thread_input
*input
= queue
->input
;
1625 reply
->previous
= input
->capture
;
1626 input
->capture
= get_user_full_handle( req
->handle
);
1627 input
->menu_owner
= (req
->flags
& CAPTURE_MENU
) ? input
->capture
: 0;
1628 input
->move_size
= (req
->flags
& CAPTURE_MOVESIZE
) ? input
->capture
: 0;
1629 reply
->full_handle
= input
->capture
;
1634 /* Set the current thread caret window */
1635 DECL_HANDLER(set_caret_window
)
1637 struct msg_queue
*queue
= get_current_queue();
1639 reply
->previous
= 0;
1640 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1642 struct thread_input
*input
= queue
->input
;
1644 reply
->previous
= input
->caret
;
1645 reply
->old_rect
= input
->caret_rect
;
1646 reply
->old_hide
= input
->caret_hide
;
1647 reply
->old_state
= input
->caret_state
;
1649 set_caret_window( input
, get_user_full_handle(req
->handle
) );
1650 input
->caret_rect
.right
= req
->width
;
1651 input
->caret_rect
.bottom
= req
->height
;
1656 /* Set the current thread caret information */
1657 DECL_HANDLER(set_caret_info
)
1659 struct msg_queue
*queue
= get_current_queue();
1660 struct thread_input
*input
;
1663 input
= queue
->input
;
1664 reply
->full_handle
= input
->caret
;
1665 reply
->old_rect
= input
->caret_rect
;
1666 reply
->old_hide
= input
->caret_hide
;
1667 reply
->old_state
= input
->caret_state
;
1669 if (req
->handle
&& get_user_full_handle(req
->handle
) != input
->caret
)
1671 set_error( STATUS_ACCESS_DENIED
);
1674 if (req
->flags
& SET_CARET_POS
)
1676 input
->caret_rect
.right
+= req
->x
- input
->caret_rect
.left
;
1677 input
->caret_rect
.bottom
+= req
->y
- input
->caret_rect
.top
;
1678 input
->caret_rect
.left
= req
->x
;
1679 input
->caret_rect
.top
= req
->y
;
1681 if (req
->flags
& SET_CARET_HIDE
)
1683 input
->caret_hide
+= req
->hide
;
1684 if (input
->caret_hide
< 0) input
->caret_hide
= 0;
1686 if (req
->flags
& SET_CARET_STATE
)
1688 if (req
->state
== -1) input
->caret_state
= !input
->caret_state
;
1689 else input
->caret_state
= !!req
->state
;