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"
39 enum message_kind
{ SEND_MESSAGE
, POST_MESSAGE
};
40 #define NB_MSG_KINDS (POST_MESSAGE+1)
45 struct message_result
*send_next
; /* next in sender list */
46 struct message_result
*recv_next
; /* next in receiver list */
47 struct msg_queue
*sender
; /* sender queue */
48 struct msg_queue
*receiver
; /* receiver queue */
49 int replied
; /* has it been replied to? */
50 unsigned int result
; /* reply result */
51 unsigned int error
; /* error code to pass back to sender */
52 void *data
; /* message reply data */
53 unsigned int data_size
; /* size of message reply data */
54 struct timeout_user
*timeout
; /* result timeout */
59 struct message
*next
; /* next message in list */
60 struct message
*prev
; /* prev message in list */
61 enum message_type type
; /* message type */
62 user_handle_t win
; /* window handle */
63 unsigned int msg
; /* message code */
64 unsigned int wparam
; /* parameters */
65 unsigned int lparam
; /* parameters */
66 int x
; /* x position */
67 int y
; /* y position */
68 unsigned int time
; /* message time */
69 unsigned int info
; /* extra info */
70 void *data
; /* message data for sent messages */
71 unsigned int data_size
; /* size of message data */
72 struct message_result
*result
; /* result in sender queue */
77 struct message
*first
; /* head of list */
78 struct message
*last
; /* tail of list */
83 struct timer
*next
; /* next timer in list */
84 struct timer
*prev
; /* prev timer in list */
85 struct timeval when
; /* next expiration */
86 unsigned int rate
; /* timer rate in ms */
87 user_handle_t win
; /* window handle */
88 unsigned int msg
; /* message to post */
89 unsigned int id
; /* timer id */
90 unsigned int lparam
; /* lparam for message */
95 struct object obj
; /* object header */
96 user_handle_t focus
; /* focus window */
97 user_handle_t capture
; /* capture window */
98 user_handle_t active
; /* active window */
99 user_handle_t menu_owner
; /* current menu owner window */
100 user_handle_t move_size
; /* current moving/resizing window */
101 user_handle_t caret
; /* caret window */
102 rectangle_t caret_rect
; /* caret rectangle */
103 int caret_hide
; /* caret hide count */
104 int caret_state
; /* caret on/off state */
105 struct message
*msg
; /* message currently processed */
106 struct thread
*msg_thread
; /* thread processing the message */
107 struct message_list msg_list
; /* list of hardware messages */
108 unsigned char keystate
[256]; /* state of each key */
113 struct object obj
; /* object header */
114 unsigned int wake_bits
; /* wakeup bits */
115 unsigned int wake_mask
; /* wakeup mask */
116 unsigned int changed_bits
; /* changed wakeup bits */
117 unsigned int changed_mask
; /* changed wakeup mask */
118 int paint_count
; /* pending paint messages count */
119 struct message_list msg_list
[NB_MSG_KINDS
]; /* lists of messages */
120 struct message_result
*send_result
; /* stack of sent messages waiting for result */
121 struct message_result
*recv_result
; /* stack of received messages waiting for result */
122 struct timer
*first_timer
; /* head of timer list */
123 struct timer
*last_timer
; /* tail of timer list */
124 struct timer
*next_timer
; /* next timer to expire */
125 struct timeout_user
*timeout
; /* timeout for next timer to expire */
126 struct thread_input
*input
; /* thread input descriptor */
129 static void msg_queue_dump( struct object
*obj
, int verbose
);
130 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
);
131 static void msg_queue_remove_queue( struct object
*obj
, struct wait_queue_entry
*entry
);
132 static int msg_queue_signaled( struct object
*obj
, struct thread
*thread
);
133 static int msg_queue_satisfied( struct object
*obj
, struct thread
*thread
);
134 static void msg_queue_destroy( struct object
*obj
);
135 static void thread_input_dump( struct object
*obj
, int verbose
);
136 static void thread_input_destroy( struct object
*obj
);
137 static void timer_callback( void *private );
139 static const struct object_ops msg_queue_ops
=
141 sizeof(struct msg_queue
), /* size */
142 msg_queue_dump
, /* dump */
143 msg_queue_add_queue
, /* add_queue */
144 msg_queue_remove_queue
, /* remove_queue */
145 msg_queue_signaled
, /* signaled */
146 msg_queue_satisfied
, /* satisfied */
147 no_get_fd
, /* get_fd */
148 msg_queue_destroy
/* destroy */
152 static const struct object_ops thread_input_ops
=
154 sizeof(struct thread_input
), /* size */
155 thread_input_dump
, /* dump */
156 no_add_queue
, /* add_queue */
157 NULL
, /* remove_queue */
159 NULL
, /* satisfied */
160 no_get_fd
, /* get_fd */
161 thread_input_destroy
/* destroy */
164 /* pointer to input structure of foreground thread */
165 static struct thread_input
*foreground_input
;
168 /* set the caret window in a given thread input */
169 static void set_caret_window( struct thread_input
*input
, user_handle_t win
)
172 input
->caret_rect
.left
= 0;
173 input
->caret_rect
.top
= 0;
174 input
->caret_rect
.right
= 0;
175 input
->caret_rect
.bottom
= 0;
176 input
->caret_hide
= 1;
177 input
->caret_state
= 0;
180 /* create a thread input object */
181 static struct thread_input
*create_thread_input(void)
183 struct thread_input
*input
;
185 if ((input
= alloc_object( &thread_input_ops
)))
190 input
->menu_owner
= 0;
191 input
->move_size
= 0;
193 input
->msg_thread
= NULL
;
194 input
->msg_list
.first
= input
->msg_list
.last
= NULL
;
195 set_caret_window( input
, 0 );
196 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
201 /* create a message queue object */
202 static struct msg_queue
*create_msg_queue( struct thread
*thread
, struct thread_input
*input
)
204 struct msg_queue
*queue
;
207 if (!input
&& !(input
= create_thread_input())) return NULL
;
208 if ((queue
= alloc_object( &msg_queue_ops
)))
210 queue
->wake_bits
= 0;
211 queue
->wake_mask
= 0;
212 queue
->changed_bits
= 0;
213 queue
->changed_mask
= 0;
214 queue
->paint_count
= 0;
215 queue
->send_result
= NULL
;
216 queue
->recv_result
= NULL
;
217 queue
->first_timer
= NULL
;
218 queue
->last_timer
= NULL
;
219 queue
->next_timer
= NULL
;
220 queue
->timeout
= NULL
;
221 queue
->input
= (struct thread_input
*)grab_object( input
);
222 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
223 queue
->msg_list
[i
].first
= queue
->msg_list
[i
].last
= NULL
;
225 thread
->queue
= queue
;
226 if (!thread
->process
->queue
)
227 thread
->process
->queue
= (struct msg_queue
*)grab_object( queue
);
229 release_object( input
);
233 /* free the message queue of a thread at thread exit */
234 void free_msg_queue( struct thread
*thread
)
236 struct process
*process
= thread
->process
;
238 if (!thread
->queue
) return;
239 if (process
->queue
== thread
->queue
) /* is it the process main queue? */
241 release_object( process
->queue
);
242 process
->queue
= NULL
;
243 if (process
->idle_event
)
245 set_event( process
->idle_event
);
246 release_object( process
->idle_event
);
247 process
->idle_event
= NULL
;
250 release_object( thread
->queue
);
251 thread
->queue
= NULL
;
254 /* check the queue status */
255 inline static int is_signaled( struct msg_queue
*queue
)
257 return ((queue
->wake_bits
& queue
->wake_mask
) || (queue
->changed_bits
& queue
->changed_mask
));
260 /* set some queue bits */
261 inline static void set_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
263 queue
->wake_bits
|= bits
;
264 queue
->changed_bits
|= bits
;
265 if (is_signaled( queue
)) wake_up( &queue
->obj
, 0 );
268 /* clear some queue bits */
269 inline static void clear_queue_bits( struct msg_queue
*queue
, unsigned int bits
)
271 queue
->wake_bits
&= ~bits
;
272 queue
->changed_bits
&= ~bits
;
275 /* check whether msg is a keyboard message */
276 inline static int is_keyboard_msg( struct message
*msg
)
278 return (msg
->msg
>= WM_KEYFIRST
&& msg
->msg
<= WM_KEYLAST
);
281 /* get the QS_* bit corresponding to a given hardware message */
282 inline static int get_hardware_msg_bit( struct message
*msg
)
284 if (msg
->msg
== WM_MOUSEMOVE
|| msg
->msg
== WM_NCMOUSEMOVE
) return QS_MOUSEMOVE
;
285 if (is_keyboard_msg( msg
)) return QS_KEY
;
286 return QS_MOUSEBUTTON
;
289 /* get the current thread queue, creating it if needed */
290 inline static struct msg_queue
*get_current_queue(void)
292 struct msg_queue
*queue
= current
->queue
;
293 if (!queue
) queue
= create_msg_queue( current
, NULL
);
297 /* append a message to the end of a list */
298 inline static void append_message( struct message_list
*list
, struct message
*msg
)
301 if ((msg
->prev
= list
->last
)) msg
->prev
->next
= msg
;
302 else list
->first
= msg
;
306 /* unlink a message from a list it */
307 inline static void unlink_message( struct message_list
*list
, struct message
*msg
)
309 if (msg
->next
) msg
->next
->prev
= msg
->prev
;
310 else list
->last
= msg
->prev
;
311 if (msg
->prev
) msg
->prev
->next
= msg
->next
;
312 else list
->first
= msg
->next
;
315 /* try to merge a message with the last in the list; return 1 if successful */
316 static int merge_message( struct thread_input
*input
, const struct message
*msg
)
318 struct message
*prev
= input
->msg_list
.last
;
321 if (input
->msg
== prev
) return 0;
322 if (prev
->result
) return 0;
323 if (prev
->win
!= msg
->win
) return 0;
324 if (prev
->msg
!= msg
->msg
) return 0;
325 if (prev
->type
!= msg
->type
) return 0;
326 /* now we can merge it */
327 prev
->wparam
= msg
->wparam
;
328 prev
->lparam
= msg
->lparam
;
331 prev
->time
= msg
->time
;
332 prev
->info
= msg
->info
;
336 /* free a result structure */
337 static void free_result( struct message_result
*result
)
339 if (result
->timeout
) remove_timeout_user( result
->timeout
);
340 if (result
->data
) free( result
->data
);
344 /* store the message result in the appropriate structure */
345 static void store_message_result( struct message_result
*res
, unsigned int result
,
348 res
->result
= result
;
353 remove_timeout_user( res
->timeout
);
356 /* wake sender queue if waiting on this result */
357 if (res
->sender
&& res
->sender
->send_result
== res
)
358 set_queue_bits( res
->sender
, QS_SMRESULT
);
361 /* free a message when deleting a queue or window */
362 static void free_message( struct message
*msg
)
364 struct message_result
*result
= msg
->result
;
369 result
->receiver
= NULL
;
370 store_message_result( result
, 0, STATUS_ACCESS_DENIED
/*FIXME*/ );
372 else free_result( result
);
374 if (msg
->data
) free( msg
->data
);
378 /* remove (and free) a message from a message list */
379 static void remove_queue_message( struct msg_queue
*queue
, struct message
*msg
,
380 enum message_kind kind
)
382 unlink_message( &queue
->msg_list
[kind
], msg
);
386 if (!queue
->msg_list
[kind
].first
) clear_queue_bits( queue
, QS_SENDMESSAGE
);
389 if (!queue
->msg_list
[kind
].first
) clear_queue_bits( queue
, QS_POSTMESSAGE
);
395 /* message timed out without getting a reply */
396 static void result_timeout( void *private )
398 struct message_result
*result
= private;
400 assert( !result
->replied
);
402 result
->timeout
= NULL
;
403 store_message_result( result
, 0, STATUS_TIMEOUT
);
406 /* allocate and fill a message result structure */
407 static struct message_result
*alloc_message_result( struct msg_queue
*send_queue
,
408 struct msg_queue
*recv_queue
,
409 unsigned int timeout
)
411 struct message_result
*result
= mem_alloc( sizeof(*result
) );
414 /* put the result on the sender result stack */
415 result
->sender
= send_queue
;
416 result
->receiver
= recv_queue
;
419 result
->data_size
= 0;
420 result
->timeout
= NULL
;
421 result
->send_next
= send_queue
->send_result
;
422 send_queue
->send_result
= result
;
426 gettimeofday( &when
, 0 );
427 add_timeout( &when
, timeout
);
428 result
->timeout
= add_timeout_user( &when
, result_timeout
, result
);
434 /* receive a message, removing it from the sent queue */
435 static void receive_message( struct msg_queue
*queue
, struct message
*msg
,
436 struct get_message_reply
*reply
)
438 struct message_result
*result
= msg
->result
;
440 reply
->total
= msg
->data_size
;
441 if (msg
->data_size
> get_reply_max_size())
443 set_error( STATUS_BUFFER_OVERFLOW
);
446 reply
->type
= msg
->type
;
447 reply
->win
= msg
->win
;
448 reply
->msg
= msg
->msg
;
449 reply
->wparam
= msg
->wparam
;
450 reply
->lparam
= msg
->lparam
;
453 reply
->time
= msg
->time
;
454 reply
->info
= msg
->info
;
456 if (msg
->data
) set_reply_data_ptr( msg
->data
, msg
->data_size
);
458 unlink_message( &queue
->msg_list
[SEND_MESSAGE
], msg
);
459 /* put the result on the receiver result stack */
462 result
->recv_next
= queue
->recv_result
;
463 queue
->recv_result
= result
;
466 if (!queue
->msg_list
[SEND_MESSAGE
].first
) clear_queue_bits( queue
, QS_SENDMESSAGE
);
469 /* set the result of the current received message */
470 static void reply_message( struct msg_queue
*queue
, unsigned int result
,
471 unsigned int error
, int remove
, const void *data
, size_t len
)
473 struct message_result
*res
= queue
->recv_result
;
477 queue
->recv_result
= res
->recv_next
;
478 res
->receiver
= NULL
;
479 if (!res
->sender
) /* no one waiting for it */
487 if (len
&& (res
->data
= memdup( data
, len
))) res
->data_size
= len
;
488 store_message_result( res
, result
, error
);
492 /* retrieve a posted message */
493 static int get_posted_message( struct msg_queue
*queue
, user_handle_t win
,
494 unsigned int first
, unsigned int last
, unsigned int flags
,
495 struct get_message_reply
*reply
)
498 struct message_list
*list
= &queue
->msg_list
[POST_MESSAGE
];
500 /* check against the filters */
501 for (msg
= list
->first
; msg
; msg
= msg
->next
)
503 if (msg
->msg
== WM_QUIT
) break; /* WM_QUIT is never filtered */
504 if (win
&& msg
->win
&& msg
->win
!= win
&& !is_child_window( win
, msg
->win
)) continue;
505 if (msg
->msg
< first
) continue;
506 if (msg
->msg
> last
) continue;
507 break; /* found one */
511 /* return it to the app */
513 reply
->total
= msg
->data_size
;
514 if (msg
->data_size
> get_reply_max_size())
516 set_error( STATUS_BUFFER_OVERFLOW
);
519 reply
->type
= msg
->type
;
520 reply
->win
= msg
->win
;
521 reply
->msg
= msg
->msg
;
522 reply
->wparam
= msg
->wparam
;
523 reply
->lparam
= msg
->lparam
;
526 reply
->time
= msg
->time
;
527 reply
->info
= msg
->info
;
529 if (flags
& GET_MSG_REMOVE
)
533 set_reply_data_ptr( msg
->data
, msg
->data_size
);
537 remove_queue_message( queue
, msg
, POST_MESSAGE
);
539 else if (msg
->data
) set_reply_data( msg
->data
, msg
->data_size
);
544 /* empty a message list and free all the messages */
545 static void empty_msg_list( struct message_list
*list
)
547 struct message
*msg
= list
->first
;
550 struct message
*next
= msg
->next
;
556 /* cleanup all pending results when deleting a queue */
557 static void cleanup_results( struct msg_queue
*queue
)
559 struct message_result
*result
, *next
;
561 result
= queue
->send_result
;
564 next
= result
->send_next
;
565 result
->sender
= NULL
;
566 if (!result
->receiver
) free_result( result
);
570 while (queue
->recv_result
)
571 reply_message( queue
, 0, STATUS_ACCESS_DENIED
/*FIXME*/, 1, NULL
, 0 );
574 static int msg_queue_add_queue( struct object
*obj
, struct wait_queue_entry
*entry
)
576 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
577 struct process
*process
= entry
->thread
->process
;
579 /* a thread can only wait on its own queue */
580 if (entry
->thread
->queue
!= queue
)
582 set_error( STATUS_ACCESS_DENIED
);
585 /* if waiting on the main process queue, set the idle event */
586 if (process
->queue
== queue
)
588 if (process
->idle_event
) set_event( process
->idle_event
);
590 add_queue( obj
, entry
);
594 static void msg_queue_remove_queue(struct object
*obj
, struct wait_queue_entry
*entry
)
596 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
597 struct process
*process
= entry
->thread
->process
;
599 remove_queue( obj
, entry
);
601 assert( entry
->thread
->queue
== queue
);
603 /* if waiting on the main process queue, reset the idle event */
604 if (process
->queue
== queue
)
606 if (process
->idle_event
) reset_event( process
->idle_event
);
610 static void msg_queue_dump( struct object
*obj
, int verbose
)
612 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
613 fprintf( stderr
, "Msg queue bits=%x mask=%x\n",
614 queue
->wake_bits
, queue
->wake_mask
);
617 static int msg_queue_signaled( struct object
*obj
, struct thread
*thread
)
619 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
620 return is_signaled( queue
);
623 static int msg_queue_satisfied( struct object
*obj
, struct thread
*thread
)
625 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
626 queue
->wake_mask
= 0;
627 queue
->changed_mask
= 0;
628 return 0; /* Not abandoned */
631 static void msg_queue_destroy( struct object
*obj
)
633 struct msg_queue
*queue
= (struct msg_queue
*)obj
;
634 struct timer
*timer
= queue
->first_timer
;
637 cleanup_results( queue
);
638 for (i
= 0; i
< NB_MSG_KINDS
; i
++) empty_msg_list( &queue
->msg_list
[i
] );
642 struct timer
*next
= timer
->next
;
646 if (queue
->timeout
) remove_timeout_user( queue
->timeout
);
647 if (queue
->input
) release_object( queue
->input
);
650 static void thread_input_dump( struct object
*obj
, int verbose
)
652 struct thread_input
*input
= (struct thread_input
*)obj
;
653 fprintf( stderr
, "Thread input focus=%p capture=%p active=%p\n",
654 input
->focus
, input
->capture
, input
->active
);
657 static void thread_input_destroy( struct object
*obj
)
659 struct thread_input
*input
= (struct thread_input
*)obj
;
661 if (foreground_input
== input
) foreground_input
= NULL
;
662 if (input
->msg_thread
) release_object( input
->msg_thread
);
663 empty_msg_list( &input
->msg_list
);
666 /* fix the thread input data when a window is destroyed */
667 inline static void thread_input_cleanup_window( struct msg_queue
*queue
, user_handle_t window
)
669 struct thread_input
*input
= queue
->input
;
671 if (window
== input
->focus
) input
->focus
= 0;
672 if (window
== input
->capture
) input
->capture
= 0;
673 if (window
== input
->active
) input
->active
= 0;
674 if (window
== input
->menu_owner
) input
->menu_owner
= 0;
675 if (window
== input
->move_size
) input
->move_size
= 0;
676 if (window
== input
->caret
) set_caret_window( input
, 0 );
679 /* check if the specified window can be set in the input data of a given queue */
680 static int check_queue_input_window( struct msg_queue
*queue
, user_handle_t window
)
682 struct thread
*thread
;
685 if (!window
) return 1; /* we can always clear the data */
687 if ((thread
= get_window_thread( window
)))
689 ret
= (queue
->input
== thread
->queue
->input
);
690 if (!ret
) set_error( STATUS_ACCESS_DENIED
);
691 release_object( thread
);
693 else set_error( STATUS_INVALID_HANDLE
);
698 /* attach two thread input data structures */
699 int attach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
701 struct thread_input
*input
;
703 if (!thread_to
->queue
&& !(thread_to
->queue
= create_msg_queue( thread_to
, NULL
))) return 0;
704 input
= (struct thread_input
*)grab_object( thread_to
->queue
->input
);
706 if (thread_from
->queue
)
708 release_object( thread_from
->queue
->input
);
709 thread_from
->queue
->input
= input
;
713 if (!(thread_from
->queue
= create_msg_queue( thread_from
, input
))) return 0;
715 memset( input
->keystate
, 0, sizeof(input
->keystate
) );
719 /* detach two thread input data structures */
720 static void detach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
)
722 struct thread_input
*input
;
724 if (!thread_from
->queue
|| !thread_to
->queue
||
725 thread_from
->queue
->input
!= thread_to
->queue
->input
)
727 set_error( STATUS_ACCESS_DENIED
);
730 if ((input
= create_thread_input()))
732 release_object( thread_from
->queue
->input
);
733 thread_from
->queue
->input
= input
;
738 /* set the next timer to expire */
739 static void set_next_timer( struct msg_queue
*queue
, struct timer
*timer
)
743 remove_timeout_user( queue
->timeout
);
744 queue
->timeout
= NULL
;
746 if ((queue
->next_timer
= timer
))
747 queue
->timeout
= add_timeout_user( &timer
->when
, timer_callback
, queue
);
749 /* set/clear QS_TIMER bit */
750 if (queue
->next_timer
== queue
->first_timer
)
751 clear_queue_bits( queue
, QS_TIMER
);
753 set_queue_bits( queue
, QS_TIMER
);
756 /* callback for the next timer expiration */
757 static void timer_callback( void *private )
759 struct msg_queue
*queue
= private;
761 queue
->timeout
= NULL
;
762 /* move on to the next timer */
763 set_next_timer( queue
, queue
->next_timer
->next
);
766 /* link a timer at its rightful place in the queue list */
767 static void link_timer( struct msg_queue
*queue
, struct timer
*timer
)
769 struct timer
*pos
= queue
->next_timer
;
771 while (pos
&& time_before( &pos
->when
, &timer
->when
)) pos
= pos
->next
;
773 if (pos
) /* insert before pos */
775 if ((timer
->prev
= pos
->prev
)) timer
->prev
->next
= timer
;
776 else queue
->first_timer
= timer
;
780 else /* insert at end */
783 timer
->prev
= queue
->last_timer
;
784 if (queue
->last_timer
) queue
->last_timer
->next
= timer
;
785 else queue
->first_timer
= timer
;
786 queue
->last_timer
= timer
;
788 /* check if we replaced the next timer */
789 if (pos
== queue
->next_timer
) set_next_timer( queue
, timer
);
792 /* remove a timer from the queue timer list */
793 static void unlink_timer( struct msg_queue
*queue
, struct timer
*timer
)
795 if (timer
->next
) timer
->next
->prev
= timer
->prev
;
796 else queue
->last_timer
= timer
->prev
;
797 if (timer
->prev
) timer
->prev
->next
= timer
->next
;
798 else queue
->first_timer
= timer
->next
;
799 /* check if we removed the next timer */
800 if (queue
->next_timer
== timer
) set_next_timer( queue
, timer
->next
);
801 else if (queue
->next_timer
== queue
->first_timer
) clear_queue_bits( queue
, QS_TIMER
);
804 /* restart an expired timer */
805 static void restart_timer( struct msg_queue
*queue
, struct timer
*timer
)
808 unlink_timer( queue
, timer
);
809 gettimeofday( &now
, 0 );
810 while (!time_before( &now
, &timer
->when
)) add_timeout( &timer
->when
, timer
->rate
);
811 link_timer( queue
, timer
);
814 /* find an expired timer matching the filtering parameters */
815 static struct timer
*find_expired_timer( struct msg_queue
*queue
, user_handle_t win
,
816 unsigned int get_first
, unsigned int get_last
,
820 for (timer
= queue
->first_timer
; (timer
&& timer
!= queue
->next_timer
); timer
= timer
->next
)
822 if (win
&& timer
->win
!= win
) continue;
823 if (timer
->msg
>= get_first
&& timer
->msg
<= get_last
)
825 if (remove
) restart_timer( queue
, timer
);
833 static int kill_timer( struct msg_queue
*queue
, user_handle_t win
,
834 unsigned int msg
, unsigned int id
)
838 for (timer
= queue
->first_timer
; timer
; timer
= timer
->next
)
840 if (timer
->win
!= win
|| timer
->msg
!= msg
|| timer
->id
!= id
) continue;
841 unlink_timer( queue
, timer
);
849 static struct timer
*set_timer( struct msg_queue
*queue
, unsigned int rate
)
851 struct timer
*timer
= mem_alloc( sizeof(*timer
) );
855 gettimeofday( &timer
->when
, 0 );
856 add_timeout( &timer
->when
, rate
);
857 link_timer( queue
, timer
);
862 /* change the input key state for a given key */
863 static void set_input_key_state( struct thread_input
*input
, unsigned char key
, int down
)
867 if (!(input
->keystate
[key
] & 0x80)) input
->keystate
[key
] ^= 0x01;
868 input
->keystate
[key
] |= 0x80;
870 else input
->keystate
[key
] &= ~0x80;
873 /* update the input key state for a keyboard message */
874 static void update_input_key_state( struct thread_input
*input
, const struct message
*msg
)
877 int down
= 0, extended
;
885 set_input_key_state( input
, VK_LBUTTON
, down
);
891 set_input_key_state( input
, VK_MBUTTON
, down
);
897 set_input_key_state( input
, VK_RBUTTON
, down
);
905 key
= (unsigned char)msg
->wparam
;
906 extended
= ((msg
->lparam
>> 16) & KF_EXTENDED
) != 0;
907 set_input_key_state( input
, key
, down
);
911 set_input_key_state( input
, extended
? VK_RSHIFT
: VK_LSHIFT
, down
);
914 set_input_key_state( input
, extended
? VK_RCONTROL
: VK_LCONTROL
, down
);
917 set_input_key_state( input
, extended
? VK_RMENU
: VK_LMENU
, down
);
924 /* release the hardware message currently being processed by the given thread */
925 static void release_hardware_message( struct thread
*thread
, int remove
)
927 struct thread_input
*input
= thread
->queue
->input
;
929 if (input
->msg_thread
!= thread
) return;
932 struct message
*other
;
935 update_input_key_state( input
, input
->msg
);
936 unlink_message( &input
->msg_list
, input
->msg
);
937 clr_bit
= get_hardware_msg_bit( input
->msg
);
938 for (other
= input
->msg_list
.first
; other
; other
= other
->next
)
939 if (get_hardware_msg_bit( other
) == clr_bit
) break;
940 if (!other
) clear_queue_bits( thread
->queue
, clr_bit
);
941 free_message( input
->msg
);
943 release_object( input
->msg_thread
);
945 input
->msg_thread
= NULL
;
948 /* find the window that should receive a given hardware message */
949 static user_handle_t
find_hardware_message_window( struct thread_input
*input
, struct message
*msg
,
950 unsigned int *msg_code
)
952 user_handle_t win
= 0;
954 *msg_code
= msg
->msg
;
955 if (is_keyboard_msg( msg
))
957 if (input
&& !(win
= input
->focus
))
960 if (*msg_code
< WM_SYSKEYDOWN
) *msg_code
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
963 else /* mouse message */
965 if (!input
|| !(win
= input
->capture
))
967 if (!(win
= msg
->win
)) win
= window_from_point( msg
->x
, msg
->y
);
973 /* queue a hardware message into a given thread input */
974 static void queue_hardware_message( struct msg_queue
*queue
, struct message
*msg
)
977 struct thread
*thread
;
978 struct thread_input
*input
;
979 unsigned int msg_code
;
981 win
= find_hardware_message_window( queue
? queue
->input
: foreground_input
, msg
, &msg_code
);
982 if (!win
|| !(thread
= get_window_thread(win
)))
987 input
= thread
->queue
->input
;
989 if (msg
->msg
== WM_MOUSEMOVE
&& merge_message( input
, msg
)) free( msg
);
992 append_message( &input
->msg_list
, msg
);
993 set_queue_bits( thread
->queue
, get_hardware_msg_bit(msg
) );
995 release_object( thread
);
998 /* find a hardware message for the given queue */
999 static int get_hardware_message( struct thread
*thread
, struct message
*first
,
1000 user_handle_t filter_win
, struct get_message_reply
*reply
)
1002 struct thread_input
*input
= thread
->queue
->input
;
1003 struct thread
*win_thread
;
1004 struct message
*msg
;
1006 int clear_bits
, got_one
= 0;
1007 unsigned int msg_code
;
1009 if (input
->msg_thread
&& input
->msg_thread
!= thread
)
1010 return 0; /* locked by another thread */
1014 msg
= input
->msg_list
.first
;
1015 clear_bits
= QS_KEY
| QS_MOUSEMOVE
| QS_MOUSEBUTTON
;
1020 clear_bits
= 0; /* don't clear bits if we don't go through the whole list */
1025 win
= find_hardware_message_window( input
, msg
, &msg_code
);
1026 if (!win
|| !(win_thread
= get_window_thread( win
)))
1028 /* no window at all, remove it */
1029 struct message
*next
= msg
->next
;
1030 update_input_key_state( input
, msg
);
1031 unlink_message( &input
->msg_list
, msg
);
1032 free_message( msg
);
1036 if (win_thread
!= thread
)
1038 /* wake the other thread */
1039 set_queue_bits( win_thread
->queue
, get_hardware_msg_bit(msg
) );
1040 release_object( win_thread
);
1045 /* if we already got a message for another thread, or if it doesn't
1046 * match the filter we skip it (filter is only checked for keyboard
1047 * messages since the dest window for a mouse message depends on hittest)
1050 (filter_win
&& is_keyboard_msg(msg
) &&
1051 win
!= filter_win
&& !is_child_window( filter_win
, win
)))
1053 clear_bits
&= ~get_hardware_msg_bit( msg
);
1054 release_object( win_thread
);
1058 /* now we can return it */
1059 if (!input
->msg_thread
) input
->msg_thread
= win_thread
;
1060 else release_object( win_thread
);
1063 reply
->type
= MSG_HARDWARE
;
1065 reply
->msg
= msg_code
;
1066 reply
->wparam
= msg
->wparam
;
1067 reply
->lparam
= msg
->lparam
;
1070 reply
->time
= msg
->time
;
1071 reply
->info
= msg
->info
;
1074 /* nothing found, clear the hardware queue bits */
1075 clear_queue_bits( thread
->queue
, clear_bits
);
1076 if (input
->msg_thread
) release_object( input
->msg_thread
);
1078 input
->msg_thread
= NULL
;
1082 /* increment (or decrement if 'incr' is negative) the queue paint count */
1083 void inc_queue_paint_count( struct thread
*thread
, int incr
)
1085 struct msg_queue
*queue
= thread
->queue
;
1089 if ((queue
->paint_count
+= incr
) < 0) queue
->paint_count
= 0;
1091 if (queue
->paint_count
)
1092 set_queue_bits( queue
, QS_PAINT
);
1094 clear_queue_bits( queue
, QS_PAINT
);
1098 /* remove all messages and timers belonging to a certain window */
1099 void queue_cleanup_window( struct thread
*thread
, user_handle_t win
)
1101 struct msg_queue
*queue
= thread
->queue
;
1102 struct timer
*timer
;
1103 struct message
*msg
;
1109 timer
= queue
->first_timer
;
1112 struct timer
*next
= timer
->next
;
1113 if (timer
->win
== win
)
1115 unlink_timer( queue
, timer
);
1121 /* remove messages */
1122 for (i
= 0; i
< NB_MSG_KINDS
; i
++)
1124 msg
= queue
->msg_list
[i
].first
;
1127 struct message
*next
= msg
->next
;
1128 if (msg
->win
== win
) remove_queue_message( queue
, msg
, i
);
1133 thread_input_cleanup_window( queue
, win
);
1136 /* post a message to a window; used by socket handling */
1137 void post_message( user_handle_t win
, unsigned int message
,
1138 unsigned int wparam
, unsigned int lparam
)
1140 struct message
*msg
;
1141 struct thread
*thread
= get_window_thread( win
);
1143 if (!thread
) return;
1145 if (thread
->queue
&& (msg
= mem_alloc( sizeof(*msg
) )))
1147 msg
->type
= MSG_POSTED
;
1148 msg
->win
= get_user_full_handle( win
);
1150 msg
->wparam
= wparam
;
1151 msg
->lparam
= lparam
;
1152 msg
->time
= get_tick_count();
1160 append_message( &thread
->queue
->msg_list
[POST_MESSAGE
], msg
);
1161 set_queue_bits( thread
->queue
, QS_POSTMESSAGE
);
1163 release_object( thread
);
1167 /* get the message queue of the current thread */
1168 DECL_HANDLER(get_msg_queue
)
1170 struct msg_queue
*queue
= get_current_queue();
1173 if (queue
) reply
->handle
= alloc_handle( current
->process
, queue
, SYNCHRONIZE
, 0 );
1177 /* set the current message queue wakeup mask */
1178 DECL_HANDLER(set_queue_mask
)
1180 struct msg_queue
*queue
= get_current_queue();
1184 queue
->wake_mask
= req
->wake_mask
;
1185 queue
->changed_mask
= req
->changed_mask
;
1186 reply
->wake_bits
= queue
->wake_bits
;
1187 reply
->changed_bits
= queue
->changed_bits
;
1188 if (is_signaled( queue
))
1190 /* if skip wait is set, do what would have been done in the subsequent wait */
1191 if (req
->skip_wait
) msg_queue_satisfied( &queue
->obj
, current
);
1192 else wake_up( &queue
->obj
, 0 );
1198 /* get the current message queue status */
1199 DECL_HANDLER(get_queue_status
)
1201 struct msg_queue
*queue
= current
->queue
;
1204 reply
->wake_bits
= queue
->wake_bits
;
1205 reply
->changed_bits
= queue
->changed_bits
;
1206 if (req
->clear
) queue
->changed_bits
= 0;
1208 else reply
->wake_bits
= reply
->changed_bits
= 0;
1212 /* send a message to a thread queue */
1213 DECL_HANDLER(send_message
)
1215 struct message
*msg
;
1216 struct msg_queue
*send_queue
= get_current_queue();
1217 struct msg_queue
*recv_queue
= NULL
;
1218 struct thread
*thread
= NULL
;
1222 if (!(thread
= get_thread_from_id( req
->id
))) return;
1224 else if (req
->type
!= MSG_HARDWARE
)
1226 /* only hardware messages are allowed without destination thread */
1227 set_error( STATUS_INVALID_PARAMETER
);
1231 if (thread
&& !(recv_queue
= thread
->queue
))
1233 set_error( STATUS_INVALID_PARAMETER
);
1234 release_object( thread
);
1238 if ((msg
= mem_alloc( sizeof(*msg
) )))
1240 msg
->type
= req
->type
;
1241 msg
->win
= get_user_full_handle( req
->win
);
1242 msg
->msg
= req
->msg
;
1243 msg
->wparam
= req
->wparam
;
1244 msg
->lparam
= req
->lparam
;
1245 msg
->time
= req
->time
;
1248 msg
->info
= req
->info
;
1255 case MSG_OTHER_PROCESS
:
1256 msg
->data_size
= get_req_data_size();
1257 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
1266 if (!(msg
->result
= alloc_message_result( send_queue
, recv_queue
, req
->timeout
)))
1273 append_message( &recv_queue
->msg_list
[SEND_MESSAGE
], msg
);
1274 set_queue_bits( recv_queue
, QS_SENDMESSAGE
);
1277 /* needed for posted DDE messages */
1278 msg
->data_size
= get_req_data_size();
1279 if (msg
->data_size
&& !(msg
->data
= memdup( get_req_data(), msg
->data_size
)))
1284 append_message( &recv_queue
->msg_list
[POST_MESSAGE
], msg
);
1285 set_queue_bits( recv_queue
, QS_POSTMESSAGE
);
1288 queue_hardware_message( recv_queue
, msg
);
1291 set_error( STATUS_INVALID_PARAMETER
);
1296 if (thread
) release_object( thread
);
1300 /* get a message from the current queue */
1301 DECL_HANDLER(get_message
)
1303 struct timer
*timer
;
1304 struct message
*msg
;
1305 struct message
*first_hw_msg
= NULL
;
1306 struct msg_queue
*queue
= get_current_queue();
1307 user_handle_t get_win
= get_user_full_handle( req
->get_win
);
1311 /* first of all release the hardware input lock if we own it */
1312 /* we'll grab it again if we find a hardware message */
1313 if (queue
->input
->msg_thread
== current
)
1315 first_hw_msg
= queue
->input
->msg
;
1316 release_hardware_message( current
, 0 );
1319 /* first check for sent messages */
1320 if ((msg
= queue
->msg_list
[SEND_MESSAGE
].first
))
1322 receive_message( queue
, msg
, reply
);
1325 if (req
->flags
& GET_MSG_SENT_ONLY
) goto done
; /* nothing else to check */
1327 /* clear changed bits so we can wait on them if we don't find a message */
1328 queue
->changed_bits
= 0;
1330 /* then check for posted messages */
1331 if (get_posted_message( queue
, get_win
, req
->get_first
, req
->get_last
, req
->flags
, reply
))
1334 /* then check for any raw hardware message */
1335 if (get_hardware_message( current
, first_hw_msg
, get_win
, reply
))
1338 /* now check for WM_PAINT */
1339 if (queue
->paint_count
&&
1340 (WM_PAINT
>= req
->get_first
) && (WM_PAINT
<= req
->get_last
) &&
1341 (reply
->win
= find_window_to_repaint( get_win
, current
)))
1343 reply
->type
= MSG_POSTED
;
1344 reply
->msg
= WM_PAINT
;
1349 reply
->time
= get_tick_count();
1354 /* now check for timer */
1355 if ((timer
= find_expired_timer( queue
, get_win
, req
->get_first
,
1356 req
->get_last
, (req
->flags
& GET_MSG_REMOVE
) )))
1358 reply
->type
= MSG_POSTED
;
1359 reply
->win
= timer
->win
;
1360 reply
->msg
= timer
->msg
;
1361 reply
->wparam
= timer
->id
;
1362 reply
->lparam
= timer
->lparam
;
1365 reply
->time
= get_tick_count();
1371 set_error( STATUS_PENDING
); /* FIXME */
1375 /* reply to a sent message */
1376 DECL_HANDLER(reply_message
)
1378 if (!current
->queue
)
1380 set_error( STATUS_ACCESS_DENIED
);
1383 if (req
->type
== MSG_HARDWARE
)
1385 struct thread_input
*input
= current
->queue
->input
;
1386 if (input
->msg_thread
== current
) release_hardware_message( current
, req
->remove
);
1387 else set_error( STATUS_ACCESS_DENIED
);
1389 else if (current
->queue
->recv_result
)
1390 reply_message( current
->queue
, req
->result
, 0, req
->remove
,
1391 get_req_data(), get_req_data_size() );
1395 /* retrieve the reply for the last message sent */
1396 DECL_HANDLER(get_message_reply
)
1398 struct msg_queue
*queue
= current
->queue
;
1402 struct message_result
*result
= queue
->send_result
;
1404 set_error( STATUS_PENDING
);
1407 if (result
&& (result
->replied
|| req
->cancel
))
1409 if (result
->replied
)
1411 reply
->result
= result
->result
;
1412 set_error( result
->error
);
1415 size_t data_len
= min( result
->data_size
, get_reply_max_size() );
1416 set_reply_data_ptr( result
->data
, data_len
);
1417 result
->data
= NULL
;
1418 result
->data_size
= 0;
1421 queue
->send_result
= result
->send_next
;
1422 result
->sender
= NULL
;
1423 if (!result
->receiver
) free_result( result
);
1424 if (!queue
->send_result
|| !queue
->send_result
->replied
)
1425 clear_queue_bits( queue
, QS_SMRESULT
);
1428 else set_error( STATUS_ACCESS_DENIED
);
1432 /* set a window timer */
1433 DECL_HANDLER(set_win_timer
)
1435 struct timer
*timer
;
1436 struct msg_queue
*queue
= get_current_queue();
1437 user_handle_t win
= get_user_full_handle( req
->win
);
1441 /* remove it if it existed already */
1442 if (win
) kill_timer( queue
, win
, req
->msg
, req
->id
);
1444 if ((timer
= set_timer( queue
, req
->rate
)))
1447 timer
->msg
= req
->msg
;
1448 timer
->id
= req
->id
;
1449 timer
->lparam
= req
->lparam
;
1453 /* kill a window timer */
1454 DECL_HANDLER(kill_win_timer
)
1456 struct msg_queue
*queue
= current
->queue
;
1458 if (!queue
|| !kill_timer( queue
, get_user_full_handle(req
->win
), req
->msg
, req
->id
))
1459 set_error( STATUS_INVALID_PARAMETER
);
1463 /* attach (or detach) thread inputs */
1464 DECL_HANDLER(attach_thread_input
)
1466 struct thread
*thread_from
= get_thread_from_id( req
->tid_from
);
1467 struct thread
*thread_to
= get_thread_from_id( req
->tid_to
);
1469 if (!thread_from
|| !thread_to
)
1471 if (thread_from
) release_object( thread_from
);
1472 if (thread_to
) release_object( thread_to
);
1475 if (thread_from
!= thread_to
)
1477 if (req
->attach
) attach_thread_input( thread_from
, thread_to
);
1478 else detach_thread_input( thread_from
, thread_to
);
1480 else set_error( STATUS_ACCESS_DENIED
);
1481 release_object( thread_from
);
1482 release_object( thread_to
);
1486 /* get thread input data */
1487 DECL_HANDLER(get_thread_input
)
1489 struct thread
*thread
= NULL
;
1490 struct thread_input
*input
;
1494 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1495 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1497 else input
= foreground_input
; /* get the foreground thread info */
1501 reply
->focus
= input
->focus
;
1502 reply
->capture
= input
->capture
;
1503 reply
->active
= input
->active
;
1504 reply
->menu_owner
= input
->menu_owner
;
1505 reply
->move_size
= input
->move_size
;
1506 reply
->caret
= input
->caret
;
1507 reply
->rect
= input
->caret_rect
;
1514 reply
->menu_owner
= 0;
1515 reply
->move_size
= 0;
1517 reply
->rect
.left
= reply
->rect
.top
= reply
->rect
.right
= reply
->rect
.bottom
= 0;
1519 /* foreground window is active window of foreground thread */
1520 reply
->foreground
= foreground_input
? foreground_input
->active
: 0;
1521 if (thread
) release_object( thread
);
1525 /* retrieve queue keyboard state for a given thread */
1526 DECL_HANDLER(get_key_state
)
1528 struct thread
*thread
;
1529 struct thread_input
*input
;
1531 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1532 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1535 if (req
->key
>= 0) reply
->state
= input
->keystate
[req
->key
& 0xff];
1536 set_reply_data( input
->keystate
, min( get_reply_max_size(), sizeof(input
->keystate
) ));
1538 release_object( thread
);
1542 /* set queue keyboard state for a given thread */
1543 DECL_HANDLER(set_key_state
)
1545 struct thread
*thread
= NULL
;
1546 struct thread_input
*input
;
1548 if (!(thread
= get_thread_from_id( req
->tid
))) return;
1549 input
= thread
->queue
? thread
->queue
->input
: NULL
;
1552 size_t size
= min( sizeof(input
->keystate
), get_req_data_size() );
1553 if (size
) memcpy( input
->keystate
, get_req_data(), size
);
1555 release_object( thread
);
1559 /* set the system foreground window */
1560 DECL_HANDLER(set_foreground_window
)
1562 struct msg_queue
*queue
= get_current_queue();
1564 reply
->previous
= foreground_input
? foreground_input
->active
: 0;
1565 reply
->send_msg_old
= (reply
->previous
&& foreground_input
!= queue
->input
);
1566 reply
->send_msg_new
= FALSE
;
1570 struct thread
*thread
;
1572 if (is_top_level_window( req
->handle
) &&
1573 ((thread
= get_window_thread( req
->handle
))))
1575 foreground_input
= thread
->queue
->input
;
1576 reply
->send_msg_new
= (foreground_input
!= queue
->input
);
1577 release_object( thread
);
1579 else set_error( STATUS_INVALID_HANDLE
);
1581 else foreground_input
= NULL
;
1585 /* set the current thread focus window */
1586 DECL_HANDLER(set_focus_window
)
1588 struct msg_queue
*queue
= get_current_queue();
1590 reply
->previous
= 0;
1591 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1593 reply
->previous
= queue
->input
->focus
;
1594 queue
->input
->focus
= get_user_full_handle( req
->handle
);
1599 /* set the current thread active window */
1600 DECL_HANDLER(set_active_window
)
1602 struct msg_queue
*queue
= get_current_queue();
1604 reply
->previous
= 0;
1605 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1607 if (!req
->handle
|| make_window_active( req
->handle
))
1609 reply
->previous
= queue
->input
->active
;
1610 queue
->input
->active
= get_user_full_handle( req
->handle
);
1612 else set_error( STATUS_INVALID_HANDLE
);
1617 /* set the current thread capture window */
1618 DECL_HANDLER(set_capture_window
)
1620 struct msg_queue
*queue
= get_current_queue();
1622 reply
->previous
= reply
->full_handle
= 0;
1623 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1625 struct thread_input
*input
= queue
->input
;
1627 reply
->previous
= input
->capture
;
1628 input
->capture
= get_user_full_handle( req
->handle
);
1629 input
->menu_owner
= (req
->flags
& CAPTURE_MENU
) ? input
->capture
: 0;
1630 input
->move_size
= (req
->flags
& CAPTURE_MOVESIZE
) ? input
->capture
: 0;
1631 reply
->full_handle
= input
->capture
;
1636 /* Set the current thread caret window */
1637 DECL_HANDLER(set_caret_window
)
1639 struct msg_queue
*queue
= get_current_queue();
1641 reply
->previous
= 0;
1642 if (queue
&& check_queue_input_window( queue
, req
->handle
))
1644 struct thread_input
*input
= queue
->input
;
1646 reply
->previous
= input
->caret
;
1647 reply
->old_rect
= input
->caret_rect
;
1648 reply
->old_hide
= input
->caret_hide
;
1649 reply
->old_state
= input
->caret_state
;
1651 set_caret_window( input
, get_user_full_handle(req
->handle
) );
1652 input
->caret_rect
.right
= req
->width
;
1653 input
->caret_rect
.bottom
= req
->height
;
1658 /* Set the current thread caret information */
1659 DECL_HANDLER(set_caret_info
)
1661 struct msg_queue
*queue
= get_current_queue();
1662 struct thread_input
*input
;
1665 input
= queue
->input
;
1666 reply
->full_handle
= input
->caret
;
1667 reply
->old_rect
= input
->caret_rect
;
1668 reply
->old_hide
= input
->caret_hide
;
1669 reply
->old_state
= input
->caret_state
;
1671 if (req
->handle
&& get_user_full_handle(req
->handle
) != input
->caret
)
1673 set_error( STATUS_ACCESS_DENIED
);
1676 if (req
->flags
& SET_CARET_POS
)
1678 input
->caret_rect
.right
+= req
->x
- input
->caret_rect
.left
;
1679 input
->caret_rect
.bottom
+= req
->y
- input
->caret_rect
.top
;
1680 input
->caret_rect
.left
= req
->x
;
1681 input
->caret_rect
.top
= req
->y
;
1683 if (req
->flags
& SET_CARET_HIDE
)
1685 input
->caret_hide
+= req
->hide
;
1686 if (input
->caret_hide
< 0) input
->caret_hide
= 0;
1688 if (req
->flags
& SET_CARET_STATE
)
1690 if (req
->state
== -1) input
->caret_state
= !input
->caret_state
;
1691 else input
->caret_state
= !!req
->state
;