12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509 |
- /*
- * Server-side message queues
- *
- * Copyright (C) 2000 Alexandre Julliard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
- #include "config.h"
- #include "wine/port.h"
- #include <assert.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #ifdef HAVE_POLL_H
- # include <poll.h>
- #endif
- #include "ntstatus.h"
- #define WIN32_NO_STATUS
- #include "windef.h"
- #include "winbase.h"
- #include "wingdi.h"
- #include "winuser.h"
- #include "winternl.h"
- #include "handle.h"
- #include "file.h"
- #include "thread.h"
- #include "process.h"
- #include "request.h"
- #include "user.h"
- #include "esync.h"
- #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
- #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
- enum message_kind { SEND_MESSAGE, POST_MESSAGE };
- #define NB_MSG_KINDS (POST_MESSAGE+1)
- struct message_result
- {
- struct list sender_entry; /* entry in sender list */
- struct message *msg; /* message the result is for */
- struct message_result *recv_next; /* next in receiver list */
- struct msg_queue *sender; /* sender queue */
- struct msg_queue *receiver; /* receiver queue */
- int replied; /* has it been replied to? */
- unsigned int error; /* error code to pass back to sender */
- lparam_t result; /* reply result */
- struct message *hardware_msg; /* hardware message if low-level hook result */
- struct desktop *desktop; /* desktop for hardware message */
- struct message *callback_msg; /* message to queue for callback */
- void *data; /* message reply data */
- unsigned int data_size; /* size of message reply data */
- struct timeout_user *timeout; /* result timeout */
- };
- struct message
- {
- struct list entry; /* entry in message list */
- enum message_type type; /* message type */
- user_handle_t win; /* window handle */
- unsigned int msg; /* message code */
- lparam_t wparam; /* parameters */
- lparam_t lparam; /* parameters */
- int x; /* message position */
- int y;
- unsigned int time; /* message time */
- void *data; /* message data for sent messages */
- unsigned int data_size; /* size of message data */
- unsigned int unique_id; /* unique id for nested hw message waits */
- struct message_result *result; /* result in sender queue */
- };
- struct timer
- {
- struct list entry; /* entry in timer list */
- timeout_t when; /* next expiration */
- unsigned int rate; /* timer rate in ms */
- user_handle_t win; /* window handle */
- unsigned int msg; /* message to post */
- lparam_t id; /* timer id */
- lparam_t lparam; /* lparam for message */
- };
- struct thread_input
- {
- struct object obj; /* object header */
- struct desktop *desktop; /* desktop that this thread input belongs to */
- struct list queues; /* list of all queues this input belongs to */
- user_handle_t focus; /* focus window */
- user_handle_t capture; /* capture window */
- user_handle_t active; /* active window */
- user_handle_t menu_owner; /* current menu owner window */
- user_handle_t move_size; /* current moving/resizing window */
- user_handle_t caret; /* caret window */
- rectangle_t caret_rect; /* caret rectangle */
- int caret_hide; /* caret hide count */
- int caret_state; /* caret on/off state */
- user_handle_t cursor; /* current cursor */
- int cursor_count; /* cursor show count */
- struct list msg_list; /* list of hardware messages */
- int lock_count; /* lock counter for keystate */
- unsigned char keystate[256]; /* state of each key */
- unsigned char shadow_keystate[256]; /* shadow copy of keystate */
- };
- struct msg_queue
- {
- struct object obj; /* object header */
- struct thread *thread; /* reference to the thread owning the queue */
- struct fd *fd; /* optional file descriptor to poll */
- int esync_fd; /* esync file descriptor (signalled on message) */
- int esync_in_msgwait; /* our thread is currently waiting on us */
- unsigned int wake_bits; /* wakeup bits */
- unsigned int wake_mask; /* wakeup mask */
- unsigned int changed_bits; /* changed wakeup bits */
- unsigned int changed_mask; /* changed wakeup mask */
- int keystate_locked; /* keystate is locked */
- int paint_count; /* pending paint messages count */
- int hotkey_count; /* pending hotkey messages count */
- int quit_message; /* is there a pending quit message? */
- int exit_code; /* exit code of pending quit message */
- int cursor_count; /* per-queue cursor show count */
- struct list msg_list[NB_MSG_KINDS]; /* lists of messages */
- struct list send_result; /* stack of sent messages waiting for result */
- struct list callback_result; /* list of callback messages waiting for result */
- struct message_result *recv_result; /* stack of received messages waiting for result */
- struct list pending_timers; /* list of pending timers */
- struct list expired_timers; /* list of expired timers */
- lparam_t next_timer_id; /* id for the next timer with a 0 window */
- struct timeout_user *timeout; /* timeout for next timer to expire */
- struct thread_input *input; /* thread input descriptor */
- struct list input_entry; /* entry in input->queues */
- struct hook_table *hooks; /* hook table */
- timeout_t last_get_msg; /* time of last get message call */
- unsigned int ignore_post_msg; /* ignore post messages newer than this unique id */
- };
- struct hotkey
- {
- struct list entry; /* entry in desktop hotkey list */
- struct msg_queue *queue; /* queue owning this hotkey */
- user_handle_t win; /* window handle */
- int id; /* hotkey id */
- unsigned int vkey; /* virtual key code */
- unsigned int flags; /* key modifiers */
- };
- static void msg_queue_dump( struct object *obj, int verbose );
- static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry );
- static void msg_queue_remove_queue( struct object *obj, struct wait_queue_entry *entry );
- static int msg_queue_signaled( struct object *obj, struct wait_queue_entry *entry );
- static int msg_queue_get_esync_fd( struct object *obj, enum esync_type *type );
- static void msg_queue_satisfied( struct object *obj, struct wait_queue_entry *entry );
- static void msg_queue_destroy( struct object *obj );
- static void msg_queue_poll_event( struct fd *fd, int event );
- static void thread_input_dump( struct object *obj, int verbose );
- static void thread_input_destroy( struct object *obj );
- static void timer_callback( void *private );
- static const struct object_ops msg_queue_ops =
- {
- sizeof(struct msg_queue), /* size */
- msg_queue_dump, /* dump */
- no_get_type, /* get_type */
- msg_queue_add_queue, /* add_queue */
- msg_queue_remove_queue, /* remove_queue */
- msg_queue_signaled, /* signaled */
- msg_queue_get_esync_fd, /* get_esync_fd */
- msg_queue_satisfied, /* satisfied */
- no_signal, /* signal */
- no_get_fd, /* get_fd */
- no_map_access, /* map_access */
- default_get_sd, /* get_sd */
- default_set_sd, /* set_sd */
- no_lookup_name, /* lookup_name */
- no_link_name, /* link_name */
- NULL, /* unlink_name */
- no_open_file, /* open_file */
- no_kernel_obj_list, /* get_kernel_obj_list */
- no_alloc_handle, /* alloc_handle */
- no_close_handle, /* close_handle */
- msg_queue_destroy /* destroy */
- };
- static const struct fd_ops msg_queue_fd_ops =
- {
- NULL, /* get_poll_events */
- msg_queue_poll_event, /* poll_event */
- NULL, /* flush */
- NULL, /* get_fd_type */
- NULL, /* ioctl */
- NULL, /* queue_async */
- NULL, /* reselect_async */
- NULL /* cancel async */
- };
- static const struct object_ops thread_input_ops =
- {
- sizeof(struct thread_input), /* size */
- thread_input_dump, /* dump */
- no_get_type, /* get_type */
- no_add_queue, /* add_queue */
- NULL, /* remove_queue */
- NULL, /* signaled */
- NULL, /* get_esync_fd */
- NULL, /* satisfied */
- no_signal, /* signal */
- no_get_fd, /* get_fd */
- no_map_access, /* map_access */
- default_get_sd, /* get_sd */
- default_set_sd, /* set_sd */
- no_lookup_name, /* lookup_name */
- no_link_name, /* link_name */
- NULL, /* unlink_name */
- no_open_file, /* open_file */
- no_kernel_obj_list, /* get_kernel_obj_list */
- no_alloc_handle, /* alloc_handle */
- no_close_handle, /* close_handle */
- thread_input_destroy /* destroy */
- };
- /* pointer to input structure of foreground thread */
- static unsigned int last_input_time;
- static void queue_hardware_message( struct desktop *desktop, struct message *msg, int always_queue );
- static void free_message( struct message *msg );
- /* set the caret window in a given thread input */
- static void set_caret_window( struct thread_input *input, user_handle_t win )
- {
- if (!win || win != input->caret)
- {
- input->caret_rect.left = 0;
- input->caret_rect.top = 0;
- input->caret_rect.right = 0;
- input->caret_rect.bottom = 0;
- }
- input->caret = win;
- input->caret_hide = 1;
- input->caret_state = 0;
- }
- /* create a thread input object */
- static struct thread_input *create_thread_input( struct thread *thread )
- {
- struct thread_input *input;
- if ((input = alloc_object( &thread_input_ops )))
- {
- input->focus = 0;
- input->capture = 0;
- input->active = 0;
- input->menu_owner = 0;
- input->move_size = 0;
- input->cursor = 0;
- input->cursor_count = 0;
- input->lock_count = 0;
- list_init( &input->queues );
- list_init( &input->msg_list );
- set_caret_window( input, 0 );
- memset( input->keystate, 0, sizeof(input->keystate) );
- memset( input->shadow_keystate, 0, sizeof(input->shadow_keystate) );
- if (!(input->desktop = get_thread_desktop( thread, 0 /* FIXME: access rights */ )))
- {
- release_object( input );
- return NULL;
- }
- }
- return input;
- }
- /* synchronize the input state with the shared memory */
- static void update_shm_thread_input( struct thread_input *input )
- {
- struct msg_queue *queue;
- /* the loop doesn't matter, usually it should only have one or a few entries */
- LIST_FOR_EACH_ENTRY( queue, &input->queues, struct msg_queue, input_entry )
- {
- shmlocal_t *shm;
- if (!queue->thread) continue;
- if ((shm = queue->thread->shm))
- {
- shm->input_active = input->active;
- shm->input_focus = input->focus;
- shm->input_capture = input->capture;
- }
- }
- }
- /* create a message queue object */
- static struct msg_queue *create_msg_queue( struct thread *thread, struct thread_input *input )
- {
- struct thread_input *new_input = NULL;
- struct msg_queue *queue;
- int i;
- if (!input)
- {
- if (!(new_input = create_thread_input( thread ))) return NULL;
- input = new_input;
- }
- if ((queue = alloc_object( &msg_queue_ops )))
- {
- queue->fd = NULL;
- queue->esync_fd = -1;
- queue->thread = thread;
- queue->wake_bits = 0;
- queue->wake_mask = 0;
- queue->changed_bits = 0;
- queue->changed_mask = 0;
- queue->keystate_locked = 0;
- queue->paint_count = 0;
- queue->hotkey_count = 0;
- queue->quit_message = 0;
- queue->cursor_count = 0;
- queue->recv_result = NULL;
- queue->next_timer_id = 0x7fff;
- queue->timeout = NULL;
- queue->input = (struct thread_input *)grab_object( input );
- list_add_tail( &input->queues, &queue->input_entry );
- queue->hooks = NULL;
- queue->last_get_msg = current_time;
- queue->ignore_post_msg = 0;
- list_init( &queue->send_result );
- list_init( &queue->callback_result );
- list_init( &queue->pending_timers );
- list_init( &queue->expired_timers );
- for (i = 0; i < NB_MSG_KINDS; i++) list_init( &queue->msg_list[i] );
- if (do_esync())
- queue->esync_fd = esync_create_fd( 0, 0 );
- thread->queue = queue;
- }
- if (new_input)
- {
- update_shm_thread_input( new_input );
- release_object( new_input );
- }
- return queue;
- }
- /* free the message queue of a thread at thread exit */
- void free_msg_queue( struct thread *thread )
- {
- remove_thread_hooks( thread );
- if (!thread->queue) return;
- thread->queue->thread = NULL;
- release_object( thread->queue );
- thread->queue = NULL;
- }
- /* change the thread input data of a given thread */
- static int assign_thread_input( struct thread *thread, struct thread_input *new_input )
- {
- struct msg_queue *queue = thread->queue;
- if (!queue)
- {
- thread->queue = create_msg_queue( thread, new_input );
- return thread->queue != NULL;
- }
- if (queue->input)
- {
- if (queue->keystate_locked) queue->input->lock_count--;
- queue->input->cursor_count -= queue->cursor_count;
- list_remove( &queue->input_entry );
- release_object( queue->input );
- queue->keystate_locked = 0;
- }
- queue->input = (struct thread_input *)grab_object( new_input );
- list_add_tail( &new_input->queues, &queue->input_entry );
- new_input->cursor_count += queue->cursor_count;
- update_shm_thread_input( new_input );
- return 1;
- }
- /* allocate a hardware message and its data */
- static struct message *alloc_hardware_message( lparam_t info, struct hw_msg_source source,
- unsigned int time, data_size_t extra_len )
- {
- struct hardware_msg_data *msg_data;
- struct message *msg;
- if (!(msg = mem_alloc( sizeof(*msg) ))) return NULL;
- if (!(msg_data = mem_alloc( sizeof(*msg_data) + extra_len )))
- {
- free( msg );
- return NULL;
- }
- memset( msg, 0, sizeof(*msg) );
- msg->type = MSG_HARDWARE;
- msg->time = time;
- msg->data = msg_data;
- msg->data_size = sizeof(*msg_data) + extra_len;
- memset( msg_data, 0, sizeof(*msg_data) + extra_len );
- msg_data->info = info;
- msg_data->source = source;
- return msg;
- }
- static int update_desktop_cursor_pos( struct desktop *desktop, int x, int y )
- {
- int updated;
- x = max( min( x, desktop->cursor.clip.right - 1 ), desktop->cursor.clip.left );
- y = max( min( y, desktop->cursor.clip.bottom - 1 ), desktop->cursor.clip.top );
- updated = (desktop->cursor.x != x || desktop->cursor.y != y);
- desktop->cursor.x = x;
- desktop->cursor.y = y;
- desktop->cursor.last_change = get_tick_count();
- return updated;
- }
- /* set the cursor position and queue the corresponding mouse message */
- static void set_cursor_pos( struct desktop *desktop, int x, int y )
- {
- static const struct hw_msg_source source = { IMDT_UNAVAILABLE, IMO_SYSTEM };
- struct message *msg;
- if (current->process->rawinput_mouse &&
- current->process->rawinput_mouse->flags & RIDEV_NOLEGACY)
- {
- update_desktop_cursor_pos( desktop, x, y );
- return;
- }
- if (!(msg = alloc_hardware_message( 0, source, get_tick_count(), 0 ))) return;
- msg->msg = WM_MOUSEMOVE;
- msg->x = x;
- msg->y = y;
- queue_hardware_message( desktop, msg, 1 );
- }
- /* retrieve default position and time for synthesized messages */
- static void get_message_defaults( struct msg_queue *queue, int *x, int *y, unsigned int *time )
- {
- struct desktop *desktop = queue->input->desktop;
- *x = desktop->cursor.x;
- *y = desktop->cursor.y;
- *time = get_tick_count();
- }
- /* set the cursor clip rectangle */
- static void set_clip_rectangle( struct desktop *desktop, const rectangle_t *rect, int send_clip_msg )
- {
- rectangle_t top_rect;
- int x, y;
- get_top_window_rectangle( desktop, &top_rect );
- if (rect)
- {
- rectangle_t new_rect = *rect;
- if (new_rect.left < top_rect.left) new_rect.left = top_rect.left;
- if (new_rect.right > top_rect.right) new_rect.right = top_rect.right;
- if (new_rect.top < top_rect.top) new_rect.top = top_rect.top;
- if (new_rect.bottom > top_rect.bottom) new_rect.bottom = top_rect.bottom;
- if (new_rect.left > new_rect.right || new_rect.top > new_rect.bottom) new_rect = top_rect;
- desktop->cursor.clip = new_rect;
- }
- else desktop->cursor.clip = top_rect;
- if (desktop->cursor.clip_msg && send_clip_msg)
- post_desktop_message( desktop, desktop->cursor.clip_msg, rect != NULL, 0 );
- /* warp the mouse to be inside the clip rect */
- x = max( min( desktop->cursor.x, desktop->cursor.clip.right - 1 ), desktop->cursor.clip.left );
- y = max( min( desktop->cursor.y, desktop->cursor.clip.bottom - 1 ), desktop->cursor.clip.top );
- if (x != desktop->cursor.x || y != desktop->cursor.y) set_cursor_pos( desktop, x, y );
- }
- /* change the foreground input and reset the cursor clip rect */
- static void set_foreground_input( struct desktop *desktop, struct thread_input *input )
- {
- if (desktop->foreground_input == input) return;
- set_clip_rectangle( desktop, NULL, 1 );
- desktop->foreground_input = input;
- }
- /* get the hook table for a given thread */
- struct hook_table *get_queue_hooks( struct thread *thread )
- {
- if (!thread->queue) return NULL;
- return thread->queue->hooks;
- }
- /* set the hook table for a given thread, allocating the queue if needed */
- void set_queue_hooks( struct thread *thread, struct hook_table *hooks )
- {
- struct msg_queue *queue = thread->queue;
- if (!queue && !(queue = create_msg_queue( thread, NULL ))) return;
- if (queue->hooks) release_object( queue->hooks );
- queue->hooks = hooks;
- }
- /* check the queue status */
- static inline int is_signaled( struct msg_queue *queue )
- {
- return ((queue->wake_bits & queue->wake_mask) || (queue->changed_bits & queue->changed_mask));
- }
- /* synchronize the queue state with the shared memory */
- static inline void update_shm_queue_bits( struct msg_queue *queue )
- {
- shmlocal_t *shm;
- if (!queue->thread) return;
- if ((shm = queue->thread->shm))
- shm->queue_bits = queue->wake_bits;
- }
- /* set some queue bits */
- static inline void set_queue_bits( struct msg_queue *queue, unsigned int bits )
- {
- queue->wake_bits |= bits;
- queue->changed_bits |= bits;
- update_shm_queue_bits( queue );
- if (is_signaled( queue )) wake_up( &queue->obj, 0 );
- }
- /* clear some queue bits */
- static inline void clear_queue_bits( struct msg_queue *queue, unsigned int bits )
- {
- queue->wake_bits &= ~bits;
- queue->changed_bits &= ~bits;
- update_shm_queue_bits( queue );
- if (do_esync() && !is_signaled( queue ))
- esync_clear( queue->esync_fd );
- }
- /* check whether msg is a keyboard message */
- static inline int is_keyboard_msg( struct message *msg )
- {
- return (msg->msg >= WM_KEYFIRST && msg->msg <= WM_KEYLAST);
- }
- /* check if message is matched by the filter */
- static inline int check_msg_filter( unsigned int msg, unsigned int first, unsigned int last )
- {
- return (msg >= first && msg <= last);
- }
- /* check whether a message filter contains at least one potential hardware message */
- static inline int filter_contains_hw_range( unsigned int first, unsigned int last )
- {
- /* hardware message ranges are (in numerical order):
- * WM_NCMOUSEFIRST .. WM_NCMOUSELAST
- * WM_INPUT_DEVICE_CHANGE .. WM_KEYLAST
- * WM_MOUSEFIRST .. WM_MOUSELAST
- */
- if (last < WM_NCMOUSEFIRST) return 0;
- if (first > WM_NCMOUSELAST && last < WM_INPUT_DEVICE_CHANGE) return 0;
- if (first > WM_KEYLAST && last < WM_MOUSEFIRST) return 0;
- if (first > WM_MOUSELAST) return 0;
- return 1;
- }
- /* get the QS_* bit corresponding to a given hardware message */
- static inline int get_hardware_msg_bit( struct message *msg )
- {
- if (msg->msg == WM_INPUT_DEVICE_CHANGE || msg->msg == WM_INPUT) return QS_RAWINPUT;
- if (msg->msg == WM_MOUSEMOVE || msg->msg == WM_NCMOUSEMOVE) return QS_MOUSEMOVE;
- if (is_keyboard_msg( msg )) return QS_KEY;
- return QS_MOUSEBUTTON;
- }
- /* get the current thread queue, creating it if needed */
- static inline struct msg_queue *get_current_queue(void)
- {
- struct msg_queue *queue = current->queue;
- if (!queue) queue = create_msg_queue( current, NULL );
- return queue;
- }
- /* get a (pseudo-)unique id to tag hardware messages */
- static inline unsigned int get_unique_hw_id(void)
- {
- static unsigned int id;
- if (!++id) id = 1; /* avoid an id of 0 */
- return id;
- }
- /* get unique increasing id to tag post messages */
- static inline unsigned int get_unique_post_id(void)
- {
- static unsigned int id;
- if (!++id) id = 1;
- return id;
- }
- /* try to merge a message with the last in the list; return 1 if successful */
- static int merge_message( struct thread_input *input, const struct message *msg )
- {
- struct message *prev;
- struct list *ptr;
- if (msg->msg != WM_MOUSEMOVE) return 0;
- for (ptr = list_tail( &input->msg_list ); ptr; ptr = list_prev( &input->msg_list, ptr ))
- {
- prev = LIST_ENTRY( ptr, struct message, entry );
- if (prev->msg != WM_INPUT) break;
- }
- if (!ptr) return 0;
- if (prev->result) return 0;
- if (prev->win && msg->win && prev->win != msg->win) return 0;
- if (prev->msg != msg->msg) return 0;
- if (prev->type != msg->type) return 0;
- /* now we can merge it */
- prev->wparam = msg->wparam;
- prev->lparam = msg->lparam;
- prev->x = msg->x;
- prev->y = msg->y;
- prev->time = msg->time;
- if (msg->type == MSG_HARDWARE && prev->data && msg->data)
- {
- struct hardware_msg_data *prev_data = prev->data;
- struct hardware_msg_data *msg_data = msg->data;
- prev_data->info = msg_data->info;
- }
- list_remove( ptr );
- list_add_tail( &input->msg_list, ptr );
- return 1;
- }
- /* free a result structure */
- static void free_result( struct message_result *result )
- {
- if (result->timeout) remove_timeout_user( result->timeout );
- free( result->data );
- if (result->callback_msg) free_message( result->callback_msg );
- if (result->hardware_msg) free_message( result->hardware_msg );
- if (result->desktop) release_object( result->desktop );
- free( result );
- }
- /* remove the result from the sender list it is on */
- static inline void remove_result_from_sender( struct message_result *result )
- {
- assert( result->sender );
- list_remove( &result->sender_entry );
- result->sender = NULL;
- if (!result->receiver) free_result( result );
- }
- /* store the message result in the appropriate structure */
- static void store_message_result( struct message_result *res, lparam_t result, unsigned int error )
- {
- res->result = result;
- res->error = error;
- res->replied = 1;
- if (res->timeout)
- {
- remove_timeout_user( res->timeout );
- res->timeout = NULL;
- }
- if (res->hardware_msg)
- {
- if (!error && result) /* rejected by the hook */
- free_message( res->hardware_msg );
- else
- queue_hardware_message( res->desktop, res->hardware_msg, 0 );
- res->hardware_msg = NULL;
- }
- if (res->sender)
- {
- if (res->callback_msg)
- {
- /* queue the callback message in the sender queue */
- struct callback_msg_data *data = res->callback_msg->data;
- data->result = result;
- list_add_tail( &res->sender->msg_list[SEND_MESSAGE], &res->callback_msg->entry );
- set_queue_bits( res->sender, QS_SENDMESSAGE );
- res->callback_msg = NULL;
- remove_result_from_sender( res );
- }
- else
- {
- /* wake sender queue if waiting on this result */
- if (list_head(&res->sender->send_result) == &res->sender_entry)
- set_queue_bits( res->sender, QS_SMRESULT );
- }
- }
- else if (!res->receiver) free_result( res );
- }
- /* free a message when deleting a queue or window */
- static void free_message( struct message *msg )
- {
- struct message_result *result = msg->result;
- if (result)
- {
- result->msg = NULL;
- result->receiver = NULL;
- store_message_result( result, 0, STATUS_ACCESS_DENIED /*FIXME*/ );
- }
- free( msg->data );
- free( msg );
- }
- /* remove (and free) a message from a message list */
- static void remove_queue_message( struct msg_queue *queue, struct message *msg,
- enum message_kind kind )
- {
- list_remove( &msg->entry );
- switch(kind)
- {
- case SEND_MESSAGE:
- if (list_empty( &queue->msg_list[kind] )) clear_queue_bits( queue, QS_SENDMESSAGE );
- break;
- case POST_MESSAGE:
- if (list_empty( &queue->msg_list[kind] ) && !queue->quit_message)
- clear_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE );
- if (msg->msg == WM_HOTKEY && --queue->hotkey_count == 0)
- clear_queue_bits( queue, QS_HOTKEY );
- break;
- }
- free_message( msg );
- }
- /* message timed out without getting a reply */
- static void result_timeout( void *private )
- {
- struct message_result *result = private;
- assert( !result->replied );
- result->timeout = NULL;
- if (result->msg) /* not received yet */
- {
- struct message *msg = result->msg;
- result->msg = NULL;
- msg->result = NULL;
- remove_queue_message( result->receiver, msg, SEND_MESSAGE );
- result->receiver = NULL;
- }
- store_message_result( result, 0, STATUS_TIMEOUT );
- }
- /* allocate and fill a message result structure */
- static struct message_result *alloc_message_result( struct msg_queue *send_queue,
- struct msg_queue *recv_queue,
- struct message *msg, timeout_t timeout )
- {
- struct message_result *result = mem_alloc( sizeof(*result) );
- if (result)
- {
- result->msg = msg;
- result->sender = send_queue;
- result->receiver = recv_queue;
- result->replied = 0;
- result->data = NULL;
- result->data_size = 0;
- result->timeout = NULL;
- result->hardware_msg = NULL;
- result->desktop = NULL;
- result->callback_msg = NULL;
- if (msg->type == MSG_CALLBACK)
- {
- struct message *callback_msg = mem_alloc( sizeof(*callback_msg) );
- if (!callback_msg)
- {
- free( result );
- return NULL;
- }
- callback_msg->type = MSG_CALLBACK_RESULT;
- callback_msg->win = msg->win;
- callback_msg->msg = msg->msg;
- callback_msg->wparam = 0;
- callback_msg->lparam = 0;
- callback_msg->time = get_tick_count();
- callback_msg->result = NULL;
- /* steal the data from the original message */
- callback_msg->data = msg->data;
- callback_msg->data_size = msg->data_size;
- msg->data = NULL;
- msg->data_size = 0;
- result->callback_msg = callback_msg;
- list_add_head( &send_queue->callback_result, &result->sender_entry );
- }
- else if (send_queue)
- {
- list_add_head( &send_queue->send_result, &result->sender_entry );
- clear_queue_bits( send_queue, QS_SMRESULT );
- }
- if (timeout != TIMEOUT_INFINITE)
- result->timeout = add_timeout_user( timeout, result_timeout, result );
- }
- return result;
- }
- /* receive a message, removing it from the sent queue */
- static void receive_message( struct msg_queue *queue, struct message *msg,
- struct get_message_reply *reply )
- {
- struct message_result *result = msg->result;
- reply->total = msg->data_size;
- if (msg->data_size > get_reply_max_size())
- {
- set_error( STATUS_BUFFER_OVERFLOW );
- return;
- }
- reply->type = msg->type;
- reply->win = msg->win;
- reply->msg = msg->msg;
- reply->wparam = msg->wparam;
- reply->lparam = msg->lparam;
- reply->x = msg->x;
- reply->y = msg->y;
- reply->time = msg->time;
- if (msg->data) set_reply_data_ptr( msg->data, msg->data_size );
- list_remove( &msg->entry );
- /* put the result on the receiver result stack */
- if (result)
- {
- result->msg = NULL;
- result->recv_next = queue->recv_result;
- queue->recv_result = result;
- }
- free( msg );
- if (list_empty( &queue->msg_list[SEND_MESSAGE] )) clear_queue_bits( queue, QS_SENDMESSAGE );
- }
- /* set the result of the current received message */
- static void reply_message( struct msg_queue *queue, lparam_t result,
- unsigned int error, int remove, const void *data, data_size_t len )
- {
- struct message_result *res = queue->recv_result;
- if (remove)
- {
- queue->recv_result = res->recv_next;
- res->receiver = NULL;
- if (!res->sender && !res->hardware_msg) /* no one waiting for it */
- {
- free_result( res );
- return;
- }
- }
- if (!res->replied)
- {
- if (len && (res->data = memdup( data, len ))) res->data_size = len;
- store_message_result( res, result, error );
- }
- }
- static int match_window( user_handle_t win, user_handle_t msg_win )
- {
- if (!win) return 1;
- if (win == -1 || win == 1) return !msg_win;
- if (msg_win == win) return 1;
- return is_child_window( win, msg_win );
- }
- /* retrieve a posted message */
- static int get_posted_message( struct msg_queue *queue, unsigned int ignore_msg, user_handle_t win,
- unsigned int first, unsigned int last, unsigned int flags,
- struct get_message_reply *reply )
- {
- struct message *msg;
- /* check against the filters */
- LIST_FOR_EACH_ENTRY( msg, &queue->msg_list[POST_MESSAGE], struct message, entry )
- {
- if (!match_window( win, msg->win )) continue;
- if (!check_msg_filter( msg->msg, first, last )) continue;
- if (ignore_msg && (int)(msg->unique_id - ignore_msg) >= 0) continue;
- goto found; /* found one */
- }
- return 0;
- /* return it to the app */
- found:
- reply->total = msg->data_size;
- if (msg->data_size > get_reply_max_size())
- {
- set_error( STATUS_BUFFER_OVERFLOW );
- return 1;
- }
- reply->type = msg->type;
- reply->win = msg->win;
- reply->msg = msg->msg;
- reply->wparam = msg->wparam;
- reply->lparam = msg->lparam;
- reply->x = msg->x;
- reply->y = msg->y;
- reply->time = msg->time;
- if (flags & PM_REMOVE)
- {
- if (msg->data)
- {
- set_reply_data_ptr( msg->data, msg->data_size );
- msg->data = NULL;
- msg->data_size = 0;
- }
- remove_queue_message( queue, msg, POST_MESSAGE );
- }
- else if (msg->data) set_reply_data( msg->data, msg->data_size );
- return 1;
- }
- static int get_quit_message( struct msg_queue *queue, unsigned int flags,
- struct get_message_reply *reply )
- {
- if (queue->quit_message)
- {
- reply->total = 0;
- reply->type = MSG_POSTED;
- reply->win = 0;
- reply->msg = WM_QUIT;
- reply->wparam = queue->exit_code;
- reply->lparam = 0;
- get_message_defaults( queue, &reply->x, &reply->y, &reply->time );
- if (flags & PM_REMOVE)
- {
- queue->quit_message = 0;
- if (list_empty( &queue->msg_list[POST_MESSAGE] ))
- clear_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE );
- }
- return 1;
- }
- else
- return 0;
- }
- /* empty a message list and free all the messages */
- static void empty_msg_list( struct list *list )
- {
- struct list *ptr;
- while ((ptr = list_head( list )) != NULL)
- {
- struct message *msg = LIST_ENTRY( ptr, struct message, entry );
- list_remove( &msg->entry );
- free_message( msg );
- }
- }
- /* cleanup all pending results when deleting a queue */
- static void cleanup_results( struct msg_queue *queue )
- {
- struct list *entry;
- while ((entry = list_head( &queue->send_result )) != NULL)
- {
- remove_result_from_sender( LIST_ENTRY( entry, struct message_result, sender_entry ) );
- }
- while ((entry = list_head( &queue->callback_result )) != NULL)
- {
- remove_result_from_sender( LIST_ENTRY( entry, struct message_result, sender_entry ) );
- }
- while (queue->recv_result)
- reply_message( queue, 0, STATUS_ACCESS_DENIED /*FIXME*/, 1, NULL, 0 );
- }
- /* check if the thread owning the queue is hung (not checking for messages) */
- static int is_queue_hung( struct msg_queue *queue )
- {
- struct wait_queue_entry *entry;
- if (current_time - queue->last_get_msg <= 5 * TICKS_PER_SEC)
- return 0; /* less than 5 seconds since last get message -> not hung */
- LIST_FOR_EACH_ENTRY( entry, &queue->obj.wait_queue, struct wait_queue_entry, entry )
- {
- if (get_wait_queue_thread(entry)->queue == queue)
- return 0; /* thread is waiting on queue -> not hung */
- }
- if (do_esync() && queue->esync_in_msgwait)
- return 0; /* thread is waiting on queue in absentia -> not hung */
- return 1;
- }
- static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- struct process *process = get_wait_queue_thread(entry)->process;
- /* a thread can only wait on its own queue */
- if (get_wait_queue_thread(entry)->queue != queue)
- {
- set_error( STATUS_ACCESS_DENIED );
- return 0;
- }
- if (process->idle_event && !(queue->wake_mask & QS_SMRESULT)) set_event( process->idle_event );
- if (queue->fd && list_empty( &obj->wait_queue )) /* first on the queue */
- set_fd_events( queue->fd, POLLIN );
- add_queue( obj, entry );
- return 1;
- }
- static void msg_queue_remove_queue(struct object *obj, struct wait_queue_entry *entry )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- remove_queue( obj, entry );
- if (queue->fd && list_empty( &obj->wait_queue )) /* last on the queue is gone */
- set_fd_events( queue->fd, 0 );
- }
- static void msg_queue_dump( struct object *obj, int verbose )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- fprintf( stderr, "Msg queue bits=%x mask=%x\n",
- queue->wake_bits, queue->wake_mask );
- }
- static int msg_queue_signaled( struct object *obj, struct wait_queue_entry *entry )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- int ret = 0;
- if (queue->fd)
- {
- if ((ret = check_fd_events( queue->fd, POLLIN )))
- /* stop waiting on select() if we are signaled */
- set_fd_events( queue->fd, 0 );
- else if (!list_empty( &obj->wait_queue ))
- /* restart waiting on poll() if we are no longer signaled */
- set_fd_events( queue->fd, POLLIN );
- }
- return ret || is_signaled( queue );
- }
- static int msg_queue_get_esync_fd( struct object *obj, enum esync_type *type )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- *type = ESYNC_QUEUE;
- return queue->esync_fd;
- }
- static void msg_queue_satisfied( struct object *obj, struct wait_queue_entry *entry )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- queue->wake_mask = 0;
- queue->changed_mask = 0;
- }
- static void msg_queue_destroy( struct object *obj )
- {
- struct msg_queue *queue = (struct msg_queue *)obj;
- struct list *ptr;
- struct hotkey *hotkey, *hotkey2;
- int i;
- cleanup_results( queue );
- for (i = 0; i < NB_MSG_KINDS; i++) empty_msg_list( &queue->msg_list[i] );
- LIST_FOR_EACH_ENTRY_SAFE( hotkey, hotkey2, &queue->input->desktop->hotkeys, struct hotkey, entry )
- {
- if (hotkey->queue == queue)
- {
- list_remove( &hotkey->entry );
- free( hotkey );
- }
- }
- while ((ptr = list_head( &queue->pending_timers )))
- {
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- list_remove( &timer->entry );
- free( timer );
- }
- while ((ptr = list_head( &queue->expired_timers )))
- {
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- list_remove( &timer->entry );
- free( timer );
- }
- if (queue->timeout) remove_timeout_user( queue->timeout );
- if (queue->keystate_locked) queue->input->lock_count--;
- queue->input->cursor_count -= queue->cursor_count;
- list_remove( &queue->input_entry );
- release_object( queue->input );
- if (queue->hooks) release_object( queue->hooks );
- if (queue->fd) release_object( queue->fd );
- if (do_esync())
- close( queue->esync_fd );
- }
- static void msg_queue_poll_event( struct fd *fd, int event )
- {
- struct msg_queue *queue = get_fd_user( fd );
- assert( queue->obj.ops == &msg_queue_ops );
- if (event & (POLLERR | POLLHUP)) set_fd_events( fd, -1 );
- else set_fd_events( queue->fd, 0 );
- wake_up( &queue->obj, 0 );
- }
- static void thread_input_dump( struct object *obj, int verbose )
- {
- struct thread_input *input = (struct thread_input *)obj;
- fprintf( stderr, "Thread input focus=%08x capture=%08x active=%08x\n",
- input->focus, input->capture, input->active );
- }
- static void thread_input_destroy( struct object *obj )
- {
- struct thread_input *input = (struct thread_input *)obj;
- assert( list_empty(&input->queues) );
- empty_msg_list( &input->msg_list );
- if (input->desktop)
- {
- if (input->desktop->foreground_input == input) set_foreground_input( input->desktop, NULL );
- release_object( input->desktop );
- }
- }
- /* fix the thread input data when a window is destroyed */
- static inline void thread_input_cleanup_window( struct msg_queue *queue, user_handle_t window )
- {
- struct thread_input *input = queue->input;
- if (window == input->focus) input->focus = 0;
- if (window == input->capture) input->capture = 0;
- if (window == input->active) input->active = 0;
- if (window == input->menu_owner) input->menu_owner = 0;
- if (window == input->move_size) input->move_size = 0;
- if (window == input->caret) set_caret_window( input, 0 );
- update_shm_thread_input( input );
- }
- /* check if the specified window can be set in the input data of a given queue */
- static int check_queue_input_window( struct msg_queue *queue, user_handle_t window )
- {
- struct thread *thread;
- int ret = 0;
- if (!window) return 1; /* we can always clear the data */
- if ((thread = get_window_thread( window )))
- {
- ret = (queue->input == thread->queue->input);
- if (!ret) set_error( STATUS_ACCESS_DENIED );
- release_object( thread );
- }
- else set_error( STATUS_INVALID_HANDLE );
- return ret;
- }
- /* make sure the specified thread has a queue */
- int init_thread_queue( struct thread *thread )
- {
- if (thread->queue) return 1;
- return (create_msg_queue( thread, NULL ) != NULL);
- }
- /* attach two thread input data structures */
- int attach_thread_input( struct thread *thread_from, struct thread *thread_to )
- {
- struct desktop *desktop;
- struct thread_input *input;
- int ret;
- if (!thread_to->queue && !(thread_to->queue = create_msg_queue( thread_to, NULL ))) return 0;
- if (!(desktop = get_thread_desktop( thread_from, 0 ))) return 0;
- input = (struct thread_input *)grab_object( thread_to->queue->input );
- if (input->desktop != desktop)
- {
- set_error( STATUS_ACCESS_DENIED );
- release_object( input );
- release_object( desktop );
- return 0;
- }
- release_object( desktop );
- if (thread_from->queue)
- {
- if (!input->focus) input->focus = thread_from->queue->input->focus;
- if (!input->active) input->active = thread_from->queue->input->active;
- }
- ret = assign_thread_input( thread_from, input );
- if (ret)
- {
- memset( input->keystate, 0, sizeof(input->keystate) );
- memset( input->shadow_keystate, 0, sizeof(input->shadow_keystate) );
- }
- release_object( input );
- return ret;
- }
- /* detach two thread input data structures */
- void detach_thread_input( struct thread *thread_from )
- {
- struct thread *thread;
- struct thread_input *input, *old_input = thread_from->queue->input;
- if ((input = create_thread_input( thread_from )))
- {
- if (old_input->focus && (thread = get_window_thread( old_input->focus )))
- {
- if (thread == thread_from)
- {
- input->focus = old_input->focus;
- old_input->focus = 0;
- }
- release_object( thread );
- }
- if (old_input->active && (thread = get_window_thread( old_input->active )))
- {
- if (thread == thread_from)
- {
- input->active = old_input->active;
- old_input->active = 0;
- }
- release_object( thread );
- }
- assign_thread_input( thread_from, input );
- release_object( input );
- }
- }
- /* set the next timer to expire */
- static void set_next_timer( struct msg_queue *queue )
- {
- struct list *ptr;
- if (queue->timeout)
- {
- remove_timeout_user( queue->timeout );
- queue->timeout = NULL;
- }
- if ((ptr = list_head( &queue->pending_timers )))
- {
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- queue->timeout = add_timeout_user( timer->when, timer_callback, queue );
- }
- /* set/clear QS_TIMER bit */
- if (list_empty( &queue->expired_timers ))
- clear_queue_bits( queue, QS_TIMER );
- else
- set_queue_bits( queue, QS_TIMER );
- }
- /* find a timer from its window and id */
- static struct timer *find_timer( struct msg_queue *queue, user_handle_t win,
- unsigned int msg, lparam_t id )
- {
- struct list *ptr;
- /* we need to search both lists */
- LIST_FOR_EACH( ptr, &queue->pending_timers )
- {
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- if (timer->win == win && timer->msg == msg && timer->id == id) return timer;
- }
- LIST_FOR_EACH( ptr, &queue->expired_timers )
- {
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- if (timer->win == win && timer->msg == msg && timer->id == id) return timer;
- }
- return NULL;
- }
- /* callback for the next timer expiration */
- static void timer_callback( void *private )
- {
- struct msg_queue *queue = private;
- struct list *ptr;
- queue->timeout = NULL;
- /* move on to the next timer */
- ptr = list_head( &queue->pending_timers );
- list_remove( ptr );
- list_add_tail( &queue->expired_timers, ptr );
- set_next_timer( queue );
- }
- /* link a timer at its rightful place in the queue list */
- static void link_timer( struct msg_queue *queue, struct timer *timer )
- {
- struct list *ptr;
- for (ptr = queue->pending_timers.next; ptr != &queue->pending_timers; ptr = ptr->next)
- {
- struct timer *t = LIST_ENTRY( ptr, struct timer, entry );
- if (t->when >= timer->when) break;
- }
- list_add_before( ptr, &timer->entry );
- }
- /* remove a timer from the queue timer list and free it */
- static void free_timer( struct msg_queue *queue, struct timer *timer )
- {
- list_remove( &timer->entry );
- free( timer );
- set_next_timer( queue );
- }
- /* restart an expired timer */
- static void restart_timer( struct msg_queue *queue, struct timer *timer )
- {
- list_remove( &timer->entry );
- while (timer->when <= current_time) timer->when += (timeout_t)timer->rate * 10000;
- link_timer( queue, timer );
- set_next_timer( queue );
- }
- /* find an expired timer matching the filtering parameters */
- static struct timer *find_expired_timer( struct msg_queue *queue, user_handle_t win,
- unsigned int get_first, unsigned int get_last,
- int remove )
- {
- struct list *ptr;
- LIST_FOR_EACH( ptr, &queue->expired_timers )
- {
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- if (win && timer->win != win) continue;
- if (check_msg_filter( timer->msg, get_first, get_last ))
- {
- if (remove) restart_timer( queue, timer );
- return timer;
- }
- }
- return NULL;
- }
- /* add a timer */
- static struct timer *set_timer( struct msg_queue *queue, unsigned int rate )
- {
- struct timer *timer = mem_alloc( sizeof(*timer) );
- if (timer)
- {
- timer->rate = max( rate, 1 );
- timer->when = current_time + (timeout_t)timer->rate * 10000;
- link_timer( queue, timer );
- /* check if we replaced the next timer */
- if (list_head( &queue->pending_timers ) == &timer->entry) set_next_timer( queue );
- }
- return timer;
- }
- /* change the input key state for a given key */
- static void set_input_key_state( unsigned char *keystate, unsigned char key, int down )
- {
- if (down)
- {
- if (!(keystate[key] & 0x80)) keystate[key] ^= 0x01;
- keystate[key] |= down;
- }
- else keystate[key] &= ~0x80;
- }
- /* update the key state for a keyboard message */
- static void update_key_state( struct desktop *desktop, unsigned char *keystate,
- unsigned int msg, lparam_t wparam )
- {
- unsigned char key;
- int down = 0;
- switch (msg)
- {
- case WM_LBUTTONDOWN:
- down = (keystate == desktop->keystate) ? 0xc0 : 0x80;
- /* fall through */
- case WM_LBUTTONUP:
- set_input_key_state( keystate, VK_LBUTTON, down );
- break;
- case WM_MBUTTONDOWN:
- down = (keystate == desktop->keystate) ? 0xc0 : 0x80;
- /* fall through */
- case WM_MBUTTONUP:
- set_input_key_state( keystate, VK_MBUTTON, down );
- break;
- case WM_RBUTTONDOWN:
- down = (keystate == desktop->keystate) ? 0xc0 : 0x80;
- /* fall through */
- case WM_RBUTTONUP:
- set_input_key_state( keystate, VK_RBUTTON, down );
- break;
- case WM_XBUTTONDOWN:
- down = (keystate == desktop->keystate) ? 0xc0 : 0x80;
- /* fall through */
- case WM_XBUTTONUP:
- if (wparam >> 16 == XBUTTON1) set_input_key_state( keystate, VK_XBUTTON1, down );
- else if (wparam >> 16 == XBUTTON2) set_input_key_state( keystate, VK_XBUTTON2, down );
- break;
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- down = (keystate == desktop->keystate) ? 0xc0 : 0x80;
- /* fall through */
- case WM_KEYUP:
- case WM_SYSKEYUP:
- key = (unsigned char)wparam;
- set_input_key_state( keystate, key, down );
- switch(key)
- {
- case VK_LCONTROL:
- case VK_RCONTROL:
- down = (keystate[VK_LCONTROL] | keystate[VK_RCONTROL]) & 0x80;
- set_input_key_state( keystate, VK_CONTROL, down );
- break;
- case VK_LMENU:
- case VK_RMENU:
- down = (keystate[VK_LMENU] | keystate[VK_RMENU]) & 0x80;
- set_input_key_state( keystate, VK_MENU, down );
- break;
- case VK_LSHIFT:
- case VK_RSHIFT:
- down = (keystate[VK_LSHIFT] | keystate[VK_RSHIFT]) & 0x80;
- set_input_key_state( keystate, VK_SHIFT, down );
- break;
- }
- break;
- }
- }
- /* synchronizes the thread input key state with the desktop */
- static void synchronize_input_key_state( struct thread_input *input )
- {
- if (!input->lock_count)
- {
- unsigned char *shadow_keystate = input->shadow_keystate;
- unsigned char *keystate = input->keystate;
- unsigned int i;
- for (i = 0; i < 256; i++)
- {
- if (input->desktop->keystate[i] != shadow_keystate[i])
- {
- keystate[i] = input->desktop->keystate[i] & ~0x40;
- shadow_keystate[i] = input->desktop->keystate[i];
- }
- }
- }
- }
- /* update the desktop key state according to a mouse message flags */
- static void update_desktop_mouse_state( struct desktop *desktop, unsigned int flags,
- int x, int y, lparam_t wparam )
- {
- if (flags & MOUSEEVENTF_MOVE)
- update_desktop_cursor_pos( desktop, x, y );
- if (flags & MOUSEEVENTF_LEFTDOWN)
- update_key_state( desktop, desktop->keystate, WM_LBUTTONDOWN, wparam );
- if (flags & MOUSEEVENTF_LEFTUP)
- update_key_state( desktop, desktop->keystate, WM_LBUTTONUP, wparam );
- if (flags & MOUSEEVENTF_RIGHTDOWN)
- update_key_state( desktop, desktop->keystate, WM_RBUTTONDOWN, wparam );
- if (flags & MOUSEEVENTF_RIGHTUP)
- update_key_state( desktop, desktop->keystate, WM_RBUTTONUP, wparam );
- if (flags & MOUSEEVENTF_MIDDLEDOWN)
- update_key_state( desktop, desktop->keystate, WM_MBUTTONDOWN, wparam );
- if (flags & MOUSEEVENTF_MIDDLEUP)
- update_key_state( desktop, desktop->keystate, WM_MBUTTONUP, wparam );
- if (flags & MOUSEEVENTF_XDOWN)
- update_key_state( desktop, desktop->keystate, WM_XBUTTONDOWN, wparam );
- if (flags & MOUSEEVENTF_XUP)
- update_key_state( desktop, desktop->keystate, WM_XBUTTONUP, wparam );
- }
- /* update the thread input key state for a keyboard message */
- static void update_input_key_state( struct thread_input *input, const struct message *msg )
- {
- synchronize_input_key_state( input );
- update_key_state( input->desktop, input->keystate, msg->msg, msg->wparam );
- }
- /* release the hardware message currently being processed by the given thread */
- static void release_hardware_message( struct msg_queue *queue, unsigned int hw_id,
- int remove )
- {
- struct thread_input *input = queue->input;
- struct message *msg;
- LIST_FOR_EACH_ENTRY( msg, &input->msg_list, struct message, entry )
- {
- if (msg->unique_id == hw_id) break;
- }
- if (&msg->entry == &input->msg_list) return; /* not found */
- /* clear the queue bit for that message */
- if (remove)
- {
- struct message *other;
- int clr_bit;
- clr_bit = get_hardware_msg_bit( msg );
- LIST_FOR_EACH_ENTRY( other, &input->msg_list, struct message, entry )
- {
- if (other != msg && get_hardware_msg_bit( other ) == clr_bit)
- {
- clr_bit = 0;
- break;
- }
- }
- if (clr_bit) clear_queue_bits( queue, clr_bit );
- update_input_key_state( input, msg );
- list_remove( &msg->entry );
- free_message( msg );
- }
- }
- static int queue_hotkey_message( struct desktop *desktop, struct message *msg )
- {
- struct hotkey *hotkey;
- unsigned int modifiers = 0;
- if (msg->msg != WM_KEYDOWN) return 0;
- if (desktop->keystate[VK_MENU] & 0x80) modifiers |= MOD_ALT;
- if (desktop->keystate[VK_CONTROL] & 0x80) modifiers |= MOD_CONTROL;
- if (desktop->keystate[VK_SHIFT] & 0x80) modifiers |= MOD_SHIFT;
- if ((desktop->keystate[VK_LWIN] & 0x80) || (desktop->keystate[VK_RWIN] & 0x80)) modifiers |= MOD_WIN;
- LIST_FOR_EACH_ENTRY( hotkey, &desktop->hotkeys, struct hotkey, entry )
- {
- if (hotkey->vkey != msg->wparam) continue;
- if ((hotkey->flags & (MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN)) == modifiers) goto found;
- }
- return 0;
- found:
- msg->type = MSG_POSTED;
- msg->win = hotkey->win;
- msg->msg = WM_HOTKEY;
- msg->wparam = hotkey->id;
- msg->lparam = ((hotkey->vkey & 0xffff) << 16) | modifiers;
- msg->unique_id = get_unique_post_id();
- free( msg->data );
- msg->data = NULL;
- msg->data_size = 0;
- list_add_tail( &hotkey->queue->msg_list[POST_MESSAGE], &msg->entry );
- set_queue_bits( hotkey->queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE|QS_HOTKEY );
- hotkey->queue->hotkey_count++;
- return 1;
- }
- /* find the window that should receive a given hardware message */
- static user_handle_t find_hardware_message_window( struct desktop *desktop, struct thread_input *input,
- struct message *msg, unsigned int *msg_code,
- struct thread **thread )
- {
- user_handle_t win = 0;
- *thread = NULL;
- *msg_code = msg->msg;
- if (msg->msg == WM_INPUT)
- {
- if (!(win = msg->win) && input) win = input->focus;
- }
- else if (is_keyboard_msg( msg ))
- {
- if (input && !(win = input->focus))
- {
- win = input->active;
- if (*msg_code < WM_SYSKEYDOWN) *msg_code += WM_SYSKEYDOWN - WM_KEYDOWN;
- }
- }
- else if (!input || !(win = input->capture)) /* mouse message */
- {
- if (is_window_visible( msg->win ) && !is_window_transparent( msg->win )) win = msg->win;
- else win = shallow_window_from_point( desktop, msg->x, msg->y );
- *thread = window_thread_from_point( win, msg->x, msg->y );
- }
- if (!*thread)
- *thread = get_window_thread( win );
- return win;
- }
- static struct rawinput_device_entry *find_rawinput_device( struct process *process, unsigned short usage_page, unsigned short usage )
- {
- struct rawinput_device_entry *e;
- LIST_FOR_EACH_ENTRY( e, &process->rawinput_devices, struct rawinput_device_entry, entry )
- {
- if (e->device.usage_page != usage_page || e->device.usage != usage) continue;
- return e;
- }
- return NULL;
- }
- static void update_rawinput_device(const struct rawinput_device *device)
- {
- struct rawinput_device_entry *e;
- if (!(e = find_rawinput_device( current->process, device->usage_page, device->usage )))
- {
- if (!(e = mem_alloc( sizeof(*e) ))) return;
- list_add_tail( ¤t->process->rawinput_devices, &e->entry );
- }
- if (device->flags & RIDEV_REMOVE)
- {
- list_remove( &e->entry );
- free( e );
- return;
- }
- e->device = *device;
- e->device.target = get_user_full_handle( e->device.target );
- }
- /* queue a hardware message into a given thread input */
- static void queue_hardware_message( struct desktop *desktop, struct message *msg, int always_queue )
- {
- user_handle_t win;
- struct thread *thread;
- struct thread_input *input;
- unsigned int msg_code;
- update_key_state( desktop, desktop->keystate, msg->msg, msg->wparam );
- last_input_time = get_tick_count();
- if (shmglobal) shmglobal->last_input_time = last_input_time;
- if (msg->msg != WM_MOUSEMOVE) always_queue = 1;
- if (is_keyboard_msg( msg ))
- {
- if (queue_hotkey_message( desktop, msg )) return;
- if (desktop->keystate[VK_MENU] & 0x80) msg->lparam |= KF_ALTDOWN << 16;
- if (msg->wparam == VK_SHIFT || msg->wparam == VK_LSHIFT || msg->wparam == VK_RSHIFT)
- msg->lparam &= ~(KF_EXTENDED << 16);
- }
- else if (msg->msg != WM_INPUT)
- {
- if (msg->msg == WM_MOUSEMOVE)
- {
- if (update_desktop_cursor_pos( desktop, msg->x, msg->y )) always_queue = 1;
- }
- if (desktop->keystate[VK_LBUTTON] & 0x80) msg->wparam |= MK_LBUTTON;
- if (desktop->keystate[VK_MBUTTON] & 0x80) msg->wparam |= MK_MBUTTON;
- if (desktop->keystate[VK_RBUTTON] & 0x80) msg->wparam |= MK_RBUTTON;
- if (desktop->keystate[VK_SHIFT] & 0x80) msg->wparam |= MK_SHIFT;
- if (desktop->keystate[VK_CONTROL] & 0x80) msg->wparam |= MK_CONTROL;
- if (desktop->keystate[VK_XBUTTON1] & 0x80) msg->wparam |= MK_XBUTTON1;
- if (desktop->keystate[VK_XBUTTON2] & 0x80) msg->wparam |= MK_XBUTTON2;
- }
- msg->x = desktop->cursor.x;
- msg->y = desktop->cursor.y;
- if (msg->win && (thread = get_window_thread( msg->win )))
- {
- input = thread->queue->input;
- release_object( thread );
- }
- else input = desktop->foreground_input;
- win = find_hardware_message_window( desktop, input, msg, &msg_code, &thread );
- if (!win || !thread)
- {
- if (input) update_input_key_state( input, msg );
- free_message( msg );
- return;
- }
- input = thread->queue->input;
- if (win != desktop->cursor.win) always_queue = 1;
- desktop->cursor.win = win;
- if (!always_queue || merge_message( input, msg )) free_message( msg );
- else
- {
- msg->unique_id = 0; /* will be set once we return it to the app */
- /* lock the keystate on the first hardware message */
- if (!thread->queue->keystate_locked)
- {
- synchronize_input_key_state( input );
- input->lock_count++;
- thread->queue->keystate_locked = 1;
- }
- list_add_tail( &input->msg_list, &msg->entry );
- set_queue_bits( thread->queue, get_hardware_msg_bit(msg) );
- }
- release_object( thread );
- }
- /* send the low-level hook message for a given hardware message */
- static int send_hook_ll_message( struct desktop *desktop, struct message *hardware_msg,
- const hw_input_t *input, struct msg_queue *sender )
- {
- struct thread *hook_thread;
- struct msg_queue *queue;
- struct message *msg;
- timeout_t timeout = 2000 * -10000; /* FIXME: load from registry */
- int id = (input->type == HW_INPUT_MOUSE) ? WH_MOUSE_LL : WH_KEYBOARD_LL;
- if (!(hook_thread = get_first_global_hook( id ))) return 0;
- if (!(queue = hook_thread->queue)) return 0;
- if (is_queue_hung( queue )) return 0;
- if (!(msg = mem_alloc( sizeof(*msg) ))) return 0;
- msg->type = MSG_HOOK_LL;
- msg->win = 0;
- msg->msg = id;
- msg->wparam = hardware_msg->msg;
- msg->x = hardware_msg->x;
- msg->y = hardware_msg->y;
- msg->time = hardware_msg->time;
- msg->data_size = hardware_msg->data_size;
- msg->result = NULL;
- if (input->type == HW_INPUT_KEYBOARD)
- {
- unsigned short vkey = input->kbd.vkey;
- if (input->kbd.flags & KEYEVENTF_UNICODE) vkey = VK_PACKET;
- msg->lparam = (input->kbd.scan << 16) | vkey;
- }
- else msg->lparam = input->mouse.data << 16;
- if (!(msg->data = memdup( hardware_msg->data, hardware_msg->data_size )) ||
- !(msg->result = alloc_message_result( sender, queue, msg, timeout )))
- {
- free_message( msg );
- return 0;
- }
- msg->result->hardware_msg = hardware_msg;
- msg->result->desktop = (struct desktop *)grab_object( desktop );
- list_add_tail( &queue->msg_list[SEND_MESSAGE], &msg->entry );
- set_queue_bits( queue, QS_SENDMESSAGE );
- return 1;
- }
- struct rawinput_message
- {
- struct desktop *desktop;
- struct hw_msg_source source;
- unsigned int time;
- unsigned char usage_page;
- unsigned char usage;
- struct hardware_msg_data data;
- const void *extra;
- data_size_t extra_len;
- };
- static int queue_rawinput_message( struct process* process, void* user )
- {
- const struct rawinput_message* raw_msg = user;
- const struct rawinput_device_entry *entry;
- const struct rawinput_device *device = NULL;
- struct desktop *desktop = NULL;
- struct thread *thread = NULL, *foreground = NULL;
- struct message *msg;
- struct hardware_msg_data *msg_data;
- if (raw_msg->data.rawinput.type == RIM_TYPEMOUSE)
- device = process->rawinput_mouse;
- else if (raw_msg->data.rawinput.type == RIM_TYPEKEYBOARD)
- device = process->rawinput_kbd;
- else if ((entry = find_rawinput_device( process, raw_msg->usage_page, raw_msg->usage )))
- device = &entry->device;
- if (!device)
- goto done;
- if (!(desktop = get_desktop_obj( process, process->desktop, 0 )) ||
- (raw_msg->desktop && desktop != raw_msg->desktop))
- goto done;
- if (!(thread = get_window_thread( device->target ? device->target : desktop->foreground_input->active )) ||
- process != thread->process)
- goto done;
- /* FIXME: Implement RIDEV_INPUTSINK */
- if (!(foreground = get_window_thread( desktop->foreground_input->active )) ||
- thread->process != foreground->process)
- goto done;
- if (!(msg = alloc_hardware_message( raw_msg->data.info, raw_msg->source, raw_msg->time, raw_msg->extra_len )))
- goto done;
- msg_data = msg->data;
- msg->win = device->target;
- msg->msg = WM_INPUT;
- msg->wparam = RIM_INPUT;
- msg->lparam = 0;
- memcpy( msg_data, &raw_msg->data, sizeof(*msg_data) );
- if (raw_msg->extra_len && raw_msg->extra)
- memcpy( msg_data + 1, raw_msg->extra, raw_msg->extra_len );
- queue_hardware_message( desktop, msg, 0 );
- done:
- if (foreground) release_object( foreground );
- if (thread) release_object( thread );
- if (desktop) release_object( desktop );
- return 0;
- }
- /* queue a hardware message for a mouse event */
- static int queue_mouse_message( struct desktop *desktop, user_handle_t win, const hw_input_t *input,
- unsigned int origin, struct msg_queue *sender, unsigned int req_flags )
- {
- const struct rawinput_device *device;
- struct hardware_msg_data *msg_data;
- struct rawinput_message raw_msg;
- struct message *msg;
- unsigned int i, time, flags;
- struct hw_msg_source source = { IMDT_MOUSE, origin };
- int wait = 0, x, y;
- static const unsigned int messages[] =
- {
- WM_MOUSEMOVE, /* 0x0001 = MOUSEEVENTF_MOVE */
- WM_LBUTTONDOWN, /* 0x0002 = MOUSEEVENTF_LEFTDOWN */
- WM_LBUTTONUP, /* 0x0004 = MOUSEEVENTF_LEFTUP */
- WM_RBUTTONDOWN, /* 0x0008 = MOUSEEVENTF_RIGHTDOWN */
- WM_RBUTTONUP, /* 0x0010 = MOUSEEVENTF_RIGHTUP */
- WM_MBUTTONDOWN, /* 0x0020 = MOUSEEVENTF_MIDDLEDOWN */
- WM_MBUTTONUP, /* 0x0040 = MOUSEEVENTF_MIDDLEUP */
- WM_XBUTTONDOWN, /* 0x0080 = MOUSEEVENTF_XDOWN */
- WM_XBUTTONUP, /* 0x0100 = MOUSEEVENTF_XUP */
- 0, /* 0x0200 = unused */
- 0, /* 0x0400 = unused */
- WM_MOUSEWHEEL, /* 0x0800 = MOUSEEVENTF_WHEEL */
- WM_MOUSEHWHEEL /* 0x1000 = MOUSEEVENTF_HWHEEL */
- };
- desktop->cursor.last_change = get_tick_count();
- flags = input->mouse.flags;
- time = input->mouse.time;
- if (!time) time = desktop->cursor.last_change;
- if (flags & MOUSEEVENTF_MOVE)
- {
- if (flags & MOUSEEVENTF_ABSOLUTE)
- {
- x = input->mouse.x;
- y = input->mouse.y;
- if (flags & ~(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE) &&
- x == desktop->cursor.x && y == desktop->cursor.y)
- flags &= ~MOUSEEVENTF_MOVE;
- }
- else
- {
- x = desktop->cursor.x + input->mouse.x;
- y = desktop->cursor.y + input->mouse.y;
- }
- }
- else
- {
- x = desktop->cursor.x;
- y = desktop->cursor.y;
- }
- if (req_flags & SEND_HWMSG_RAWINPUT)
- {
- raw_msg.desktop = desktop;
- raw_msg.source = source;
- raw_msg.time = time;
- raw_msg.extra = NULL;
- raw_msg.extra_len = 0;
- msg_data = &raw_msg.data;
- msg_data->info = input->mouse.info;
- msg_data->flags = flags;
- msg_data->rawinput.type = RIM_TYPEMOUSE;
- msg_data->rawinput.mouse.x = input->mouse.x;
- msg_data->rawinput.mouse.y = input->mouse.y;
- msg_data->rawinput.mouse.data = input->mouse.data;
- if (req_flags == SEND_HWMSG_RAWINPUT)
- enum_processes( queue_rawinput_message, &raw_msg );
- else
- queue_rawinput_message( current->process, &raw_msg );
- }
- if (!(req_flags & SEND_HWMSG_WINDOW))
- return 0;
- if ((device = current->process->rawinput_mouse) && (device->flags & RIDEV_NOLEGACY))
- {
- update_desktop_mouse_state( desktop, flags, x, y, input->mouse.data << 16 );
- return 0;
- }
- for (i = 0; i < ARRAY_SIZE( messages ); i++)
- {
- if (!messages[i]) continue;
- if (!(flags & (1 << i))) continue;
- flags &= ~(1 << i);
- if (!(msg = alloc_hardware_message( input->mouse.info, source, time, 0 ))) return 0;
- msg_data = msg->data;
- msg->win = get_user_full_handle( win );
- msg->msg = messages[i];
- msg->wparam = input->mouse.data << 16;
- msg->lparam = 0;
- msg->x = x;
- msg->y = y;
- if (origin == IMO_INJECTED) msg_data->flags = LLMHF_INJECTED;
- /* specify a sender only when sending the last message */
- if (!(flags & ((1 << ARRAY_SIZE( messages )) - 1)))
- {
- if (!(wait = send_hook_ll_message( desktop, msg, input, sender )))
- queue_hardware_message( desktop, msg, 0 );
- }
- else if (!send_hook_ll_message( desktop, msg, input, NULL ))
- queue_hardware_message( desktop, msg, 0 );
- }
- return wait;
- }
- /* queue a hardware message for a keyboard event */
- static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, const hw_input_t *input,
- unsigned int origin, struct msg_queue *sender, unsigned int req_flags )
- {
- struct hw_msg_source source = { IMDT_KEYBOARD, origin };
- const struct rawinput_device *device;
- struct hardware_msg_data *msg_data;
- struct rawinput_message raw_msg;
- struct message *msg;
- unsigned char vkey = input->kbd.vkey;
- unsigned int message_code, time;
- int wait;
- if (!(time = input->kbd.time)) time = get_tick_count();
- if (!(input->kbd.flags & KEYEVENTF_UNICODE))
- {
- switch (vkey)
- {
- case VK_MENU:
- case VK_LMENU:
- case VK_RMENU:
- vkey = (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) ? VK_RMENU : VK_LMENU;
- break;
- case VK_CONTROL:
- case VK_LCONTROL:
- case VK_RCONTROL:
- vkey = (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) ? VK_RCONTROL : VK_LCONTROL;
- break;
- case VK_SHIFT:
- case VK_LSHIFT:
- case VK_RSHIFT:
- vkey = (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) ? VK_RSHIFT : VK_LSHIFT;
- break;
- }
- }
- message_code = (input->kbd.flags & KEYEVENTF_KEYUP) ? WM_KEYUP : WM_KEYDOWN;
- switch (vkey)
- {
- case VK_LMENU:
- case VK_RMENU:
- if (input->kbd.flags & KEYEVENTF_KEYUP)
- {
- /* send WM_SYSKEYUP if Alt still pressed and no other key in between */
- /* we use 0x02 as a flag to track if some other SYSKEYUP was sent already */
- if ((desktop->keystate[VK_MENU] & 0x82) != 0x82) break;
- message_code = WM_SYSKEYUP;
- desktop->keystate[VK_MENU] &= ~0x02;
- }
- else
- {
- /* send WM_SYSKEYDOWN for Alt except with Ctrl */
- if (desktop->keystate[VK_CONTROL] & 0x80) break;
- message_code = WM_SYSKEYDOWN;
- desktop->keystate[VK_MENU] |= 0x02;
- }
- break;
- case VK_LCONTROL:
- case VK_RCONTROL:
- /* send WM_SYSKEYUP on release if Alt still pressed */
- if (!(input->kbd.flags & KEYEVENTF_KEYUP)) break;
- if (!(desktop->keystate[VK_MENU] & 0x80)) break;
- message_code = WM_SYSKEYUP;
- desktop->keystate[VK_MENU] &= ~0x02;
- break;
- default:
- /* send WM_SYSKEY for Alt-anykey and for F10 */
- if (desktop->keystate[VK_CONTROL] & 0x80) break;
- if (!(desktop->keystate[VK_MENU] & 0x80)) break;
- /* fall through */
- case VK_F10:
- message_code = (input->kbd.flags & KEYEVENTF_KEYUP) ? WM_SYSKEYUP : WM_SYSKEYDOWN;
- desktop->keystate[VK_MENU] &= ~0x02;
- break;
- }
- if (req_flags & SEND_HWMSG_RAWINPUT)
- {
- raw_msg.desktop = desktop;
- raw_msg.source = source;
- raw_msg.time = time;
- raw_msg.extra = NULL;
- raw_msg.extra_len = 0;
- msg_data = &raw_msg.data;
- msg_data->info = input->kbd.info;
- msg_data->flags = input->kbd.flags;
- msg_data->rawinput.type = RIM_TYPEKEYBOARD;
- msg_data->rawinput.kbd.message = message_code;
- msg_data->rawinput.kbd.vkey = vkey;
- msg_data->rawinput.kbd.scan = input->kbd.scan;
- if (req_flags == SEND_HWMSG_RAWINPUT)
- enum_processes( queue_rawinput_message, &raw_msg );
- else
- queue_rawinput_message( current->process, &raw_msg );
- }
- if (!(req_flags & SEND_HWMSG_WINDOW))
- return 0;
- if ((device = current->process->rawinput_kbd) && (device->flags & RIDEV_NOLEGACY))
- return 0;
- if (!(msg = alloc_hardware_message( input->kbd.info, source, time, 0 ))) return 0;
- msg_data = msg->data;
- msg->win = get_user_full_handle( win );
- msg->msg = message_code;
- msg->lparam = (input->kbd.scan << 16) | 1u; /* repeat count */
- if (origin == IMO_INJECTED) msg_data->flags = LLKHF_INJECTED;
- if (input->kbd.flags & KEYEVENTF_UNICODE && !vkey)
- {
- msg->wparam = VK_PACKET;
- }
- else
- {
- unsigned int flags = 0;
- if (input->kbd.flags & KEYEVENTF_EXTENDEDKEY) flags |= KF_EXTENDED;
- /* FIXME: set KF_DLGMODE and KF_MENUMODE when needed */
- if (input->kbd.flags & KEYEVENTF_KEYUP) flags |= KF_REPEAT | KF_UP;
- else if (desktop->keystate[vkey] & 0x80) flags |= KF_REPEAT;
- msg->wparam = vkey;
- msg->lparam |= flags << 16;
- msg_data->flags |= (flags & (KF_EXTENDED | KF_ALTDOWN | KF_UP)) >> 8;
- }
- if (!(wait = send_hook_ll_message( desktop, msg, input, sender )))
- queue_hardware_message( desktop, msg, 1 );
- return wait;
- }
- /* queue a hardware message for a custom type of event */
- static void queue_custom_hardware_message( struct desktop *desktop, user_handle_t win,
- unsigned int origin, const hw_input_t *input )
- {
- struct hw_msg_source source = { IMDT_UNAVAILABLE, origin };
- struct message *msg;
- if (!(msg = alloc_hardware_message( 0, source, get_tick_count(), 0 ))) return;
- msg->win = get_user_full_handle( win );
- msg->msg = input->hw.msg;
- msg->wparam = 0;
- msg->lparam = input->hw.lparam;
- msg->x = desktop->cursor.x;
- msg->y = desktop->cursor.y;
- queue_hardware_message( desktop, msg, 1 );
- }
- /* queue a hardware message for an hid event */
- static void queue_hid_message( struct desktop *desktop, user_handle_t win, const hw_input_t *input,
- unsigned int origin, struct msg_queue *sender, unsigned int req_flags,
- const void *report, data_size_t report_len )
- {
- struct hw_msg_source source = { IMDT_UNAVAILABLE, origin };
- struct hardware_msg_data *msg_data;
- struct rawinput_message raw_msg;
- if (!(req_flags & SEND_HWMSG_RAWINPUT))
- return;
- raw_msg.desktop = NULL; /* send to all desktops */
- raw_msg.source = source;
- raw_msg.time = get_tick_count();
- raw_msg.usage_page = input->hid.usage_page;
- raw_msg.usage = input->hid.usage;
- raw_msg.extra = report;
- raw_msg.extra_len = report_len;
- msg_data = &raw_msg.data;
- msg_data->flags = 0;
- msg_data->rawinput.type = RIM_TYPEHID;
- msg_data->rawinput.hid.device = input->hid.device;
- msg_data->rawinput.hid.length = report_len;
- if (req_flags == SEND_HWMSG_RAWINPUT)
- enum_processes( queue_rawinput_message, &raw_msg );
- else
- queue_rawinput_message( current->process, &raw_msg );
- }
- /* check message filter for a hardware message */
- static int check_hw_message_filter( user_handle_t win, unsigned int msg_code,
- user_handle_t filter_win, unsigned int first, unsigned int last )
- {
- if (msg_code >= WM_KEYFIRST && msg_code <= WM_KEYLAST)
- {
- /* we can only test the window for a keyboard message since the
- * dest window for a mouse message depends on hittest */
- if (filter_win && win != filter_win && !is_child_window( filter_win, win ))
- return 0;
- /* the message code is final for a keyboard message, we can simply check it */
- return check_msg_filter( msg_code, first, last );
- }
- else /* mouse message */
- {
- /* we need to check all possible values that the message can have in the end */
- if (check_msg_filter( msg_code, first, last )) return 1;
- if (msg_code == WM_MOUSEWHEEL) return 0; /* no other possible value for this one */
- /* all other messages can become non-client messages */
- if (check_msg_filter( msg_code + (WM_NCMOUSEFIRST - WM_MOUSEFIRST), first, last )) return 1;
- /* clicks can become double-clicks or non-client double-clicks */
- if (msg_code == WM_LBUTTONDOWN || msg_code == WM_MBUTTONDOWN ||
- msg_code == WM_RBUTTONDOWN || msg_code == WM_XBUTTONDOWN)
- {
- if (check_msg_filter( msg_code + (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN), first, last )) return 1;
- if (check_msg_filter( msg_code + (WM_NCLBUTTONDBLCLK - WM_LBUTTONDOWN), first, last )) return 1;
- }
- return 0;
- }
- }
- /* find a hardware message for the given queue */
- static int get_hardware_message( struct thread *thread, unsigned int hw_id, user_handle_t filter_win,
- unsigned int first, unsigned int last, unsigned int flags,
- struct get_message_reply *reply )
- {
- struct thread_input *input = thread->queue->input;
- struct thread *win_thread;
- struct list *ptr;
- user_handle_t win;
- int clear_bits, got_one = 0;
- unsigned int msg_code;
- ptr = list_head( &input->msg_list );
- if (hw_id)
- {
- while (ptr)
- {
- struct message *msg = LIST_ENTRY( ptr, struct message, entry );
- if (msg->unique_id == hw_id) break;
- ptr = list_next( &input->msg_list, ptr );
- }
- if (!ptr) ptr = list_head( &input->msg_list );
- else ptr = list_next( &input->msg_list, ptr ); /* start from the next one */
- }
- if (ptr == list_head( &input->msg_list ))
- clear_bits = QS_INPUT;
- else
- clear_bits = 0; /* don't clear bits if we don't go through the whole list */
- while (ptr)
- {
- struct message *msg = LIST_ENTRY( ptr, struct message, entry );
- struct hardware_msg_data *data = msg->data;
- ptr = list_next( &input->msg_list, ptr );
- win = find_hardware_message_window( input->desktop, input, msg, &msg_code, &win_thread );
- if (!win || !win_thread)
- {
- /* no window at all, remove it */
- update_input_key_state( input, msg );
- list_remove( &msg->entry );
- free_message( msg );
- continue;
- }
- if (win_thread != thread)
- {
- if (win_thread->queue->input == input)
- {
- /* wake the other thread */
- set_queue_bits( win_thread->queue, get_hardware_msg_bit(msg) );
- got_one = 1;
- }
- else
- {
- /* for another thread input, drop it */
- update_input_key_state( input, msg );
- list_remove( &msg->entry );
- free_message( msg );
- }
- release_object( win_thread );
- continue;
- }
- release_object( win_thread );
- /* if we already got a message for another thread, or if it doesn't
- * match the filter we skip it */
- if (got_one || !check_hw_message_filter( win, msg_code, filter_win, first, last ))
- {
- clear_bits &= ~get_hardware_msg_bit( msg );
- continue;
- }
- /* now we can return it */
- if (!msg->unique_id) msg->unique_id = get_unique_hw_id();
- reply->type = MSG_HARDWARE;
- reply->win = win;
- reply->msg = msg_code;
- reply->wparam = msg->wparam;
- reply->lparam = msg->lparam;
- reply->x = msg->x;
- reply->y = msg->y;
- reply->time = msg->time;
- data->hw_id = msg->unique_id;
- set_reply_data( msg->data, msg->data_size );
- if (msg->msg == WM_INPUT && (flags & PM_REMOVE))
- release_hardware_message( current->queue, data->hw_id, 1 );
- return 1;
- }
- /* nothing found, clear the hardware queue bits */
- clear_queue_bits( thread->queue, clear_bits );
- return 0;
- }
- /* increment (or decrement if 'incr' is negative) the queue paint count */
- void inc_queue_paint_count( struct thread *thread, int incr )
- {
- struct msg_queue *queue = thread->queue;
- assert( queue );
- if ((queue->paint_count += incr) < 0) queue->paint_count = 0;
- if (queue->paint_count)
- set_queue_bits( queue, QS_PAINT );
- else
- clear_queue_bits( queue, QS_PAINT );
- }
- /* remove all messages and timers belonging to a certain window */
- void queue_cleanup_window( struct thread *thread, user_handle_t win )
- {
- struct msg_queue *queue = thread->queue;
- struct list *ptr;
- int i;
- if (!queue) return;
- /* remove timers */
- ptr = list_head( &queue->pending_timers );
- while (ptr)
- {
- struct list *next = list_next( &queue->pending_timers, ptr );
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- if (timer->win == win) free_timer( queue, timer );
- ptr = next;
- }
- ptr = list_head( &queue->expired_timers );
- while (ptr)
- {
- struct list *next = list_next( &queue->expired_timers, ptr );
- struct timer *timer = LIST_ENTRY( ptr, struct timer, entry );
- if (timer->win == win) free_timer( queue, timer );
- ptr = next;
- }
- /* remove messages */
- for (i = 0; i < NB_MSG_KINDS; i++)
- {
- struct list *ptr, *next;
- LIST_FOR_EACH_SAFE( ptr, next, &queue->msg_list[i] )
- {
- struct message *msg = LIST_ENTRY( ptr, struct message, entry );
- if (msg->win == win)
- {
- if (msg->msg == WM_QUIT && !queue->quit_message)
- {
- queue->quit_message = 1;
- queue->exit_code = msg->wparam;
- }
- remove_queue_message( queue, msg, i );
- }
- }
- }
- thread_input_cleanup_window( queue, win );
- }
- /* post a message to a window */
- void post_message( user_handle_t win, unsigned int message, lparam_t wparam, lparam_t lparam )
- {
- struct message *msg;
- struct thread *thread = get_window_thread( win );
- if (!thread) return;
- if (thread->queue && (msg = mem_alloc( sizeof(*msg) )))
- {
- msg->type = MSG_POSTED;
- msg->win = get_user_full_handle( win );
- msg->msg = message;
- msg->wparam = wparam;
- msg->lparam = lparam;
- msg->result = NULL;
- msg->data = NULL;
- msg->data_size = 0;
- msg->unique_id = get_unique_post_id();
- get_message_defaults( thread->queue, &msg->x, &msg->y, &msg->time );
- list_add_tail( &thread->queue->msg_list[POST_MESSAGE], &msg->entry );
- set_queue_bits( thread->queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE );
- if (message == WM_HOTKEY)
- {
- set_queue_bits( thread->queue, QS_HOTKEY );
- thread->queue->hotkey_count++;
- }
- }
- release_object( thread );
- }
- /* send a notify message to a window */
- void send_notify_message( user_handle_t win, unsigned int message, lparam_t wparam, lparam_t lparam )
- {
- struct message *msg;
- struct thread *thread = get_window_thread( win );
- if (!thread) return;
- if (thread->queue && (msg = mem_alloc( sizeof(*msg) )))
- {
- msg->type = MSG_NOTIFY;
- msg->win = get_user_full_handle( win );
- msg->msg = message;
- msg->wparam = wparam;
- msg->lparam = lparam;
- msg->result = NULL;
- msg->data = NULL;
- msg->data_size = 0;
- get_message_defaults( thread->queue, &msg->x, &msg->y, &msg->time );
- list_add_tail( &thread->queue->msg_list[SEND_MESSAGE], &msg->entry );
- set_queue_bits( thread->queue, QS_SENDMESSAGE );
- }
- release_object( thread );
- }
- /* post a win event */
- void post_win_event( struct thread *thread, unsigned int event,
- user_handle_t win, unsigned int object_id,
- unsigned int child_id, client_ptr_t hook_proc,
- const WCHAR *module, data_size_t module_size,
- user_handle_t hook)
- {
- struct message *msg;
- if (thread->queue && (msg = mem_alloc( sizeof(*msg) )))
- {
- struct winevent_msg_data *data;
- msg->type = MSG_WINEVENT;
- msg->win = get_user_full_handle( win );
- msg->msg = event;
- msg->wparam = object_id;
- msg->lparam = child_id;
- msg->time = get_tick_count();
- msg->result = NULL;
- if ((data = malloc( sizeof(*data) + module_size )))
- {
- data->hook = hook;
- data->tid = get_thread_id( current );
- data->hook_proc = hook_proc;
- memcpy( data + 1, module, module_size );
- msg->data = data;
- msg->data_size = sizeof(*data) + module_size;
- if (debug_level > 1)
- fprintf( stderr, "post_win_event: tid %04x event %04x win %08x object_id %d child_id %d\n",
- get_thread_id(thread), event, win, object_id, child_id );
- list_add_tail( &thread->queue->msg_list[SEND_MESSAGE], &msg->entry );
- set_queue_bits( thread->queue, QS_SENDMESSAGE );
- }
- else
- free( msg );
- }
- }
- /* free all hotkeys on a desktop, optionally filtering by window */
- void free_hotkeys( struct desktop *desktop, user_handle_t window )
- {
- struct hotkey *hotkey, *hotkey2;
- LIST_FOR_EACH_ENTRY_SAFE( hotkey, hotkey2, &desktop->hotkeys, struct hotkey, entry )
- {
- if (!window || hotkey->win == window)
- {
- list_remove( &hotkey->entry );
- free( hotkey );
- }
- }
- }
- /* check if the thread owning the window is hung */
- DECL_HANDLER(is_window_hung)
- {
- struct thread *thread;
- thread = get_window_thread( req->win );
- if (thread)
- {
- reply->is_hung = is_queue_hung( thread->queue );
- release_object( thread );
- }
- else reply->is_hung = 0;
- }
- /* get the message queue of the current thread */
- DECL_HANDLER(get_msg_queue)
- {
- struct msg_queue *queue = get_current_queue();
- reply->handle = 0;
- if (queue) reply->handle = alloc_handle( current->process, queue, SYNCHRONIZE, 0 );
- }
- /* set the file descriptor associated to the current thread queue */
- DECL_HANDLER(set_queue_fd)
- {
- struct msg_queue *queue = get_current_queue();
- struct file *file;
- int unix_fd;
- if (queue->fd) /* fd can only be set once */
- {
- set_error( STATUS_ACCESS_DENIED );
- return;
- }
- if (!(file = get_file_obj( current->process, req->handle, SYNCHRONIZE ))) return;
- if ((unix_fd = get_file_unix_fd( file )) != -1)
- {
- if ((unix_fd = dup( unix_fd )) != -1)
- queue->fd = create_anonymous_fd( &msg_queue_fd_ops, unix_fd, &queue->obj, 0 );
- else
- file_set_error();
- }
- release_object( file );
- }
- /* set the current message queue wakeup mask */
- DECL_HANDLER(set_queue_mask)
- {
- struct msg_queue *queue = get_current_queue();
- if (queue)
- {
- queue->wake_mask = req->wake_mask;
- queue->changed_mask = req->changed_mask;
- reply->wake_bits = queue->wake_bits;
- reply->changed_bits = queue->changed_bits;
- if (is_signaled( queue ))
- {
- /* if skip wait is set, do what would have been done in the subsequent wait */
- if (req->skip_wait) queue->wake_mask = queue->changed_mask = 0;
- else wake_up( &queue->obj, 0 );
- }
- }
- }
- /* get the current message queue status */
- DECL_HANDLER(get_queue_status)
- {
- struct msg_queue *queue = current->queue;
- if (queue)
- {
- reply->wake_bits = queue->wake_bits;
- reply->changed_bits = queue->changed_bits;
- queue->changed_bits &= ~req->clear_bits;
- if (do_esync() && !is_signaled( queue ))
- esync_clear( queue->esync_fd );
- }
- else reply->wake_bits = reply->changed_bits = 0;
- }
- /* send a message to a thread queue */
- DECL_HANDLER(send_message)
- {
- struct message *msg;
- struct msg_queue *send_queue = get_current_queue();
- struct msg_queue *recv_queue = NULL;
- struct thread *thread = NULL;
- if (!(thread = get_thread_from_id( req->id ))) return;
- if (!(recv_queue = thread->queue))
- {
- set_error( STATUS_INVALID_PARAMETER );
- release_object( thread );
- return;
- }
- if ((req->flags & SEND_MSG_ABORT_IF_HUNG) && is_queue_hung(recv_queue))
- {
- set_error( STATUS_TIMEOUT );
- release_object( thread );
- return;
- }
- if ((msg = mem_alloc( sizeof(*msg) )))
- {
- msg->type = req->type;
- msg->win = get_user_full_handle( req->win );
- msg->msg = req->msg;
- msg->wparam = req->wparam;
- msg->lparam = req->lparam;
- msg->result = NULL;
- msg->data = NULL;
- msg->data_size = get_req_data_size();
- get_message_defaults( recv_queue, &msg->x, &msg->y, &msg->time );
- if (msg->data_size && !(msg->data = memdup( get_req_data(), msg->data_size )))
- {
- free( msg );
- release_object( thread );
- return;
- }
- switch(msg->type)
- {
- case MSG_OTHER_PROCESS:
- case MSG_ASCII:
- case MSG_UNICODE:
- case MSG_CALLBACK:
- if (!(msg->result = alloc_message_result( send_queue, recv_queue, msg, req->timeout )))
- {
- free_message( msg );
- break;
- }
- /* fall through */
- case MSG_NOTIFY:
- list_add_tail( &recv_queue->msg_list[SEND_MESSAGE], &msg->entry );
- set_queue_bits( recv_queue, QS_SENDMESSAGE );
- break;
- case MSG_POSTED:
- msg->unique_id = get_unique_post_id();
- list_add_tail( &recv_queue->msg_list[POST_MESSAGE], &msg->entry );
- set_queue_bits( recv_queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE );
- if (msg->msg == WM_HOTKEY)
- {
- set_queue_bits( recv_queue, QS_HOTKEY );
- recv_queue->hotkey_count++;
- }
- break;
- case MSG_HARDWARE: /* should use send_hardware_message instead */
- case MSG_CALLBACK_RESULT: /* cannot send this one */
- case MSG_HOOK_LL: /* generated internally */
- default:
- set_error( STATUS_INVALID_PARAMETER );
- free( msg );
- break;
- }
- }
- release_object( thread );
- }
- /* send a hardware message to a thread queue */
- DECL_HANDLER(send_hardware_message)
- {
- struct thread *thread = NULL;
- struct desktop *desktop;
- unsigned int origin = (req->flags & SEND_HWMSG_INJECTED ? IMO_INJECTED : IMO_HARDWARE);
- struct msg_queue *sender = get_current_queue();
- data_size_t size = min( 256, get_reply_max_size() );
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- if (req->win)
- {
- if (!(thread = get_window_thread( req->win ))) return;
- if (desktop != thread->queue->input->desktop)
- {
- /* don't allow queuing events to a different desktop */
- release_object( desktop );
- return;
- }
- }
- reply->prev_x = desktop->cursor.x;
- reply->prev_y = desktop->cursor.y;
- switch (req->input.type)
- {
- case HW_INPUT_MOUSE:
- reply->wait = queue_mouse_message( desktop, req->win, &req->input, origin, sender, req->flags );
- break;
- case HW_INPUT_KEYBOARD:
- reply->wait = queue_keyboard_message( desktop, req->win, &req->input, origin, sender, req->flags );
- break;
- case HW_INPUT_HARDWARE:
- queue_custom_hardware_message( desktop, req->win, origin, &req->input );
- break;
- case HW_INPUT_HID:
- queue_hid_message( desktop, req->win, &req->input, origin, sender, req->flags, get_req_data(), get_req_data_size() );
- break;
- default:
- set_error( STATUS_INVALID_PARAMETER );
- }
- if (thread) release_object( thread );
- reply->new_x = desktop->cursor.x;
- reply->new_y = desktop->cursor.y;
- set_reply_data( desktop->keystate, size );
- release_object( desktop );
- }
- /* post a quit message to the current queue */
- DECL_HANDLER(post_quit_message)
- {
- struct msg_queue *queue = get_current_queue();
- if (!queue)
- return;
- queue->quit_message = 1;
- queue->exit_code = req->exit_code;
- set_queue_bits( queue, QS_POSTMESSAGE|QS_ALLPOSTMESSAGE );
- }
- /* get a message from the current queue */
- DECL_HANDLER(get_message)
- {
- struct timer *timer;
- struct list *ptr;
- struct msg_queue *queue = get_current_queue();
- user_handle_t get_win = get_user_full_handle( req->get_win );
- unsigned int filter = req->flags >> 16;
- reply->active_hooks = get_active_hooks();
- if (get_win && get_win != 1 && get_win != -1 && !get_user_object( get_win, USER_WINDOW ))
- {
- set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
- return;
- }
- if (!queue) return;
- queue->last_get_msg = current_time;
- if (!filter) filter = QS_ALLINPUT;
- /* no longer lock the keystate if we have processed all input */
- if (queue->keystate_locked && !(queue->wake_bits & QS_ALLINPUT))
- {
- queue->input->lock_count--;
- queue->keystate_locked = 0;
- }
- /* first check for sent messages */
- if ((ptr = list_head( &queue->msg_list[SEND_MESSAGE] )))
- {
- struct message *msg = LIST_ENTRY( ptr, struct message, entry );
- receive_message( queue, msg, reply );
- return;
- }
- /* clear changed bits so we can wait on them if we don't find a message */
- if (filter & QS_POSTMESSAGE)
- {
- queue->changed_bits &= ~(QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER);
- if (req->get_first == 0 && req->get_last == ~0U) queue->changed_bits &= ~QS_ALLPOSTMESSAGE;
- }
- if (filter & QS_INPUT) queue->changed_bits &= ~QS_INPUT;
- if (filter & QS_PAINT) queue->changed_bits &= ~QS_PAINT;
- /* then check for posted messages */
- if ((filter & QS_POSTMESSAGE) &&
- get_posted_message( queue, queue->ignore_post_msg, get_win, req->get_first, req->get_last, req->flags, reply ))
- return;
- if ((filter & QS_HOTKEY) && queue->hotkey_count &&
- req->get_first <= WM_HOTKEY && req->get_last >= WM_HOTKEY &&
- get_posted_message( queue, queue->ignore_post_msg, get_win, WM_HOTKEY, WM_HOTKEY, req->flags, reply ))
- return;
- /* only check for quit messages if not posted messages pending */
- if ((filter & QS_POSTMESSAGE) && get_quit_message( queue, req->flags, reply ))
- return;
- /* then check for any raw hardware message */
- if ((filter & QS_INPUT) &&
- filter_contains_hw_range( req->get_first, req->get_last ) &&
- get_hardware_message( current, req->hw_id, get_win, req->get_first, req->get_last, req->flags, reply ))
- goto found_msg;
- /* now check for WM_PAINT */
- if ((filter & QS_PAINT) &&
- queue->paint_count &&
- check_msg_filter( WM_PAINT, req->get_first, req->get_last ) &&
- (reply->win = find_window_to_repaint( get_win, current )))
- {
- reply->type = MSG_POSTED;
- reply->msg = WM_PAINT;
- reply->wparam = 0;
- reply->lparam = 0;
- get_message_defaults( queue, &reply->x, &reply->y, &reply->time );
- goto found_msg;
- }
- /* now check for timer */
- if ((filter & QS_TIMER) &&
- (timer = find_expired_timer( queue, get_win, req->get_first,
- req->get_last, (req->flags & PM_REMOVE) )))
- {
- reply->type = MSG_POSTED;
- reply->win = timer->win;
- reply->msg = timer->msg;
- reply->wparam = timer->id;
- reply->lparam = timer->lparam;
- get_message_defaults( queue, &reply->x, &reply->y, &reply->time );
- if (!(req->flags & PM_NOYIELD) && current->process->idle_event)
- set_event( current->process->idle_event );
- goto found_msg;
- }
- /* if we previously skipped posted messages then check again */
- if (queue->ignore_post_msg && (filter & QS_POSTMESSAGE) &&
- get_posted_message( queue, 0, get_win, req->get_first, req->get_last, req->flags, reply ))
- return;
- if (queue->ignore_post_msg && (filter & QS_HOTKEY) && queue->hotkey_count &&
- req->get_first <= WM_HOTKEY && req->get_last >= WM_HOTKEY &&
- get_posted_message( queue, 0, get_win, WM_HOTKEY, WM_HOTKEY, req->flags, reply ))
- return;
- if (get_win == -1 && current->process->idle_event) set_event( current->process->idle_event );
- queue->wake_mask = req->wake_mask;
- queue->changed_mask = req->changed_mask;
- set_error( STATUS_PENDING ); /* FIXME */
- return;
- found_msg:
- if (req->flags & PM_REMOVE)
- queue->ignore_post_msg = 0;
- else if (!queue->ignore_post_msg)
- queue->ignore_post_msg = get_unique_post_id();
- }
- /* reply to a sent message */
- DECL_HANDLER(reply_message)
- {
- if (!current->queue) set_error( STATUS_ACCESS_DENIED );
- else if (current->queue->recv_result)
- reply_message( current->queue, req->result, 0, req->remove,
- get_req_data(), get_req_data_size() );
- }
- /* accept the current hardware message */
- DECL_HANDLER(accept_hardware_message)
- {
- if (current->queue)
- {
- release_hardware_message( current->queue, req->hw_id, req->remove );
- if (req->remove) current->queue->ignore_post_msg = 0;
- }
- else
- set_error( STATUS_ACCESS_DENIED );
- }
- /* retrieve the reply for the last message sent */
- DECL_HANDLER(get_message_reply)
- {
- struct message_result *result;
- struct list *entry;
- struct msg_queue *queue = current->queue;
- if (queue)
- {
- set_error( STATUS_PENDING );
- reply->result = 0;
- if (!(entry = list_head( &queue->send_result ))) return; /* no reply ready */
- result = LIST_ENTRY( entry, struct message_result, sender_entry );
- if (result->replied || req->cancel)
- {
- if (result->replied)
- {
- reply->result = result->result;
- set_error( result->error );
- if (result->data)
- {
- data_size_t data_len = min( result->data_size, get_reply_max_size() );
- set_reply_data_ptr( result->data, data_len );
- result->data = NULL;
- result->data_size = 0;
- }
- }
- remove_result_from_sender( result );
- entry = list_head( &queue->send_result );
- if (!entry) clear_queue_bits( queue, QS_SMRESULT );
- else
- {
- result = LIST_ENTRY( entry, struct message_result, sender_entry );
- if (result->replied) set_queue_bits( queue, QS_SMRESULT );
- else clear_queue_bits( queue, QS_SMRESULT );
- }
- }
- }
- else set_error( STATUS_ACCESS_DENIED );
- }
- /* set a window timer */
- DECL_HANDLER(set_win_timer)
- {
- struct timer *timer;
- struct msg_queue *queue;
- struct thread *thread = NULL;
- user_handle_t win = 0;
- lparam_t id = req->id;
- if (req->win)
- {
- if (!(win = get_user_full_handle( req->win )) || !(thread = get_window_thread( win )))
- {
- set_error( STATUS_INVALID_HANDLE );
- return;
- }
- if (thread->process != current->process)
- {
- release_object( thread );
- set_error( STATUS_ACCESS_DENIED );
- return;
- }
- queue = thread->queue;
- /* remove it if it existed already */
- if ((timer = find_timer( queue, win, req->msg, id ))) free_timer( queue, timer );
- }
- else
- {
- queue = get_current_queue();
- /* look for a timer with this id */
- if (id && (timer = find_timer( queue, 0, req->msg, id )))
- {
- /* free and reuse id */
- free_timer( queue, timer );
- }
- else
- {
- lparam_t end_id = queue->next_timer_id;
- /* find a free id for it */
- while (1)
- {
- id = queue->next_timer_id;
- if (--queue->next_timer_id <= 0x100) queue->next_timer_id = 0x7fff;
- if (!find_timer( queue, 0, req->msg, id )) break;
- if (queue->next_timer_id == end_id)
- {
- set_win32_error( ERROR_NO_MORE_USER_HANDLES );
- return;
- }
- }
- }
- }
- if ((timer = set_timer( queue, req->rate )))
- {
- timer->win = win;
- timer->msg = req->msg;
- timer->id = id;
- timer->lparam = req->lparam;
- reply->id = id;
- }
- if (thread) release_object( thread );
- }
- /* kill a window timer */
- DECL_HANDLER(kill_win_timer)
- {
- struct timer *timer;
- struct thread *thread;
- user_handle_t win = 0;
- if (req->win)
- {
- if (!(win = get_user_full_handle( req->win )) || !(thread = get_window_thread( win )))
- {
- set_error( STATUS_INVALID_HANDLE );
- return;
- }
- if (thread->process != current->process)
- {
- release_object( thread );
- set_error( STATUS_ACCESS_DENIED );
- return;
- }
- }
- else thread = (struct thread *)grab_object( current );
- if (thread->queue && (timer = find_timer( thread->queue, win, req->msg, req->id )))
- free_timer( thread->queue, timer );
- else
- set_error( STATUS_INVALID_PARAMETER );
- release_object( thread );
- }
- DECL_HANDLER(register_hotkey)
- {
- struct desktop *desktop;
- user_handle_t win_handle = req->window;
- struct hotkey *hotkey;
- struct hotkey *new_hotkey = NULL;
- struct thread *thread;
- const int modifier_flags = MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN;
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- if (win_handle)
- {
- if (!(win_handle = get_valid_window_handle( win_handle )))
- {
- release_object( desktop );
- return;
- }
- thread = get_window_thread( win_handle );
- if (thread) release_object( thread );
- if (thread != current)
- {
- release_object( desktop );
- set_win32_error( ERROR_WINDOW_OF_OTHER_THREAD );
- return;
- }
- }
- LIST_FOR_EACH_ENTRY( hotkey, &desktop->hotkeys, struct hotkey, entry )
- {
- if (req->vkey == hotkey->vkey &&
- (req->flags & modifier_flags) == (hotkey->flags & modifier_flags))
- {
- release_object( desktop );
- set_win32_error( ERROR_HOTKEY_ALREADY_REGISTERED );
- return;
- }
- if (current->queue == hotkey->queue && win_handle == hotkey->win && req->id == hotkey->id)
- new_hotkey = hotkey;
- }
- if (new_hotkey)
- {
- reply->replaced = 1;
- reply->flags = new_hotkey->flags;
- reply->vkey = new_hotkey->vkey;
- }
- else
- {
- new_hotkey = mem_alloc( sizeof(*new_hotkey) );
- if (new_hotkey)
- {
- list_add_tail( &desktop->hotkeys, &new_hotkey->entry );
- new_hotkey->queue = current->queue;
- new_hotkey->win = win_handle;
- new_hotkey->id = req->id;
- }
- }
- if (new_hotkey)
- {
- new_hotkey->flags = req->flags;
- new_hotkey->vkey = req->vkey;
- }
- release_object( desktop );
- }
- DECL_HANDLER(unregister_hotkey)
- {
- struct desktop *desktop;
- user_handle_t win_handle = req->window;
- struct hotkey *hotkey;
- struct thread *thread;
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- if (win_handle)
- {
- if (!(win_handle = get_valid_window_handle( win_handle )))
- {
- release_object( desktop );
- return;
- }
- thread = get_window_thread( win_handle );
- if (thread) release_object( thread );
- if (thread != current)
- {
- release_object( desktop );
- set_win32_error( ERROR_WINDOW_OF_OTHER_THREAD );
- return;
- }
- }
- LIST_FOR_EACH_ENTRY( hotkey, &desktop->hotkeys, struct hotkey, entry )
- {
- if (current->queue == hotkey->queue && win_handle == hotkey->win && req->id == hotkey->id)
- goto found;
- }
- release_object( desktop );
- set_win32_error( ERROR_HOTKEY_NOT_REGISTERED );
- return;
- found:
- reply->flags = hotkey->flags;
- reply->vkey = hotkey->vkey;
- list_remove( &hotkey->entry );
- free( hotkey );
- release_object( desktop );
- }
- /* attach (or detach) thread inputs */
- DECL_HANDLER(attach_thread_input)
- {
- struct thread *thread_from = get_thread_from_id( req->tid_from );
- struct thread *thread_to = get_thread_from_id( req->tid_to );
- if (!thread_from || !thread_to)
- {
- if (thread_from) release_object( thread_from );
- if (thread_to) release_object( thread_to );
- return;
- }
- if (thread_from != thread_to)
- {
- if (req->attach)
- {
- if ((thread_to->queue || thread_to == current) &&
- (thread_from->queue || thread_from == current))
- attach_thread_input( thread_from, thread_to );
- else
- set_error( STATUS_INVALID_PARAMETER );
- }
- else
- {
- if (thread_from->queue && thread_to->queue &&
- thread_from->queue->input == thread_to->queue->input)
- detach_thread_input( thread_from );
- else
- set_error( STATUS_ACCESS_DENIED );
- }
- }
- else set_error( STATUS_ACCESS_DENIED );
- release_object( thread_from );
- release_object( thread_to );
- }
- /* get thread input data */
- DECL_HANDLER(get_thread_input)
- {
- struct thread *thread = NULL;
- struct desktop *desktop;
- struct thread_input *input;
- if (req->tid)
- {
- if (!(thread = get_thread_from_id( req->tid ))) return;
- if (!(desktop = get_thread_desktop( thread, 0 )))
- {
- release_object( thread );
- return;
- }
- input = thread->queue ? thread->queue->input : NULL;
- }
- else
- {
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- input = desktop->foreground_input; /* get the foreground thread info */
- }
- if (input)
- {
- reply->focus = input->focus;
- reply->capture = input->capture;
- reply->active = input->active;
- reply->menu_owner = input->menu_owner;
- reply->move_size = input->move_size;
- reply->caret = input->caret;
- reply->cursor = input->cursor;
- reply->show_count = input->cursor_count;
- reply->rect = input->caret_rect;
- }
- /* foreground window is active window of foreground thread */
- reply->foreground = desktop->foreground_input ? desktop->foreground_input->active : 0;
- if (thread) release_object( thread );
- release_object( desktop );
- }
- /* retrieve queue keyboard state for a given thread */
- DECL_HANDLER(get_key_state)
- {
- struct thread *thread;
- struct desktop *desktop;
- data_size_t size = min( 256, get_reply_max_size() );
- if (!req->tid) /* get global async key state */
- {
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- if (req->key >= 0)
- {
- reply->state = desktop->keystate[req->key & 0xff];
- desktop->keystate[req->key & 0xff] &= ~0x40;
- }
- set_reply_data( desktop->keystate, size );
- release_object( desktop );
- }
- else
- {
- unsigned char *keystate;
- if (!(thread = get_thread_from_id( req->tid ))) return;
- if (thread->queue)
- {
- if (req->key >= 0)
- {
- /* synchronize with desktop keystate, but _only_ if req->key is given */
- synchronize_input_key_state( thread->queue->input );
- reply->state = thread->queue->input->keystate[req->key & 0xff];
- }
- set_reply_data( thread->queue->input->keystate, size );
- release_object( thread );
- return;
- }
- release_object( thread );
- /* fallback to desktop keystate */
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- if (req->key >= 0) reply->state = desktop->keystate[req->key & 0xff] & ~0x40;
- if ((keystate = set_reply_data_size( size )))
- {
- unsigned int i;
- for (i = 0; i < size; i++) keystate[i] = desktop->keystate[i] & ~0x40;
- }
- release_object( desktop );
- }
- }
- /* set queue keyboard state for a given thread */
- DECL_HANDLER(set_key_state)
- {
- struct thread *thread;
- struct desktop *desktop;
- data_size_t size = min( 256, get_req_data_size() );
- if (!req->tid) /* set global async key state */
- {
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- memcpy( desktop->keystate, get_req_data(), size );
- release_object( desktop );
- }
- else
- {
- if (!(thread = get_thread_from_id( req->tid ))) return;
- if (thread->queue) memcpy( thread->queue->input->keystate, get_req_data(), size );
- if (req->async && (desktop = get_thread_desktop( thread, 0 )))
- {
- memcpy( desktop->keystate, get_req_data(), size );
- release_object( desktop );
- }
- release_object( thread );
- }
- }
- /* set the system foreground window */
- DECL_HANDLER(set_foreground_window)
- {
- struct thread *thread = NULL;
- struct desktop *desktop;
- struct msg_queue *queue = get_current_queue();
- if (!(desktop = get_thread_desktop( current, 0 ))) return;
- reply->previous = desktop->foreground_input ? desktop->foreground_input->active : 0;
- reply->send_msg_old = (reply->previous && desktop->foreground_input != queue->input);
- reply->send_msg_new = FALSE;
- if (is_valid_foreground_window( req->handle ) &&
- (thread = get_window_thread( req->handle )) &&
- thread->queue->input->desktop == desktop)
- {
- set_foreground_input( desktop, thread->queue->input );
- reply->send_msg_new = (desktop->foreground_input != queue->input);
- }
- else set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
- if (thread) release_object( thread );
- release_object( desktop );
- }
- /* set the current thread focus window */
- DECL_HANDLER(set_focus_window)
- {
- struct msg_queue *queue = get_current_queue();
- reply->previous = 0;
- if (queue && check_queue_input_window( queue, req->handle ))
- {
- reply->previous = queue->input->focus;
- queue->input->focus = get_user_full_handle( req->handle );
- update_shm_thread_input( queue->input );
- }
- }
- /* set the current thread active window */
- DECL_HANDLER(set_active_window)
- {
- struct msg_queue *queue = get_current_queue();
- reply->previous = 0;
- if (queue && check_queue_input_window( queue, req->handle ))
- {
- if (!req->handle || make_window_active( req->handle ))
- {
- reply->previous = queue->input->active;
- queue->input->active = get_user_full_handle( req->handle );
- update_shm_thread_input( queue->input );
- }
- else set_error( STATUS_INVALID_HANDLE );
- }
- }
- /* set the current thread capture window */
- DECL_HANDLER(set_capture_window)
- {
- struct msg_queue *queue = get_current_queue();
- reply->previous = reply->full_handle = 0;
- if (queue && check_queue_input_window( queue, req->handle ))
- {
- struct thread_input *input = queue->input;
- /* if in menu mode, reject all requests to change focus, except if the menu bit is set */
- if (input->menu_owner && !(req->flags & CAPTURE_MENU))
- {
- set_error(STATUS_ACCESS_DENIED);
- return;
- }
- reply->previous = input->capture;
- input->capture = get_user_full_handle( req->handle );
- input->menu_owner = (req->flags & CAPTURE_MENU) ? input->capture : 0;
- input->move_size = (req->flags & CAPTURE_MOVESIZE) ? input->capture : 0;
- update_shm_thread_input( input );
- reply->full_handle = input->capture;
- }
- }
- /* Set the current thread caret window */
- DECL_HANDLER(set_caret_window)
- {
- struct msg_queue *queue = get_current_queue();
- reply->previous = 0;
- if (queue && check_queue_input_window( queue, req->handle ))
- {
- struct thread_input *input = queue->input;
- reply->previous = input->caret;
- reply->old_rect = input->caret_rect;
- reply->old_hide = input->caret_hide;
- reply->old_state = input->caret_state;
- set_caret_window( input, get_user_full_handle(req->handle) );
- input->caret_rect.right = input->caret_rect.left + req->width;
- input->caret_rect.bottom = input->caret_rect.top + req->height;
- }
- }
- /* Set the current thread caret information */
- DECL_HANDLER(set_caret_info)
- {
- struct msg_queue *queue = get_current_queue();
- struct thread_input *input;
- if (!queue) return;
- input = queue->input;
- reply->full_handle = input->caret;
- reply->old_rect = input->caret_rect;
- reply->old_hide = input->caret_hide;
- reply->old_state = input->caret_state;
- if (req->handle && get_user_full_handle(req->handle) != input->caret)
- {
- set_error( STATUS_ACCESS_DENIED );
- return;
- }
- if (req->flags & SET_CARET_POS)
- {
- input->caret_rect.right += req->x - input->caret_rect.left;
- input->caret_rect.bottom += req->y - input->caret_rect.top;
- input->caret_rect.left = req->x;
- input->caret_rect.top = req->y;
- }
- if (req->flags & SET_CARET_HIDE)
- {
- input->caret_hide += req->hide;
- if (input->caret_hide < 0) input->caret_hide = 0;
- }
- if (req->flags & SET_CARET_STATE)
- {
- switch (req->state)
- {
- case CARET_STATE_OFF: input->caret_state = 0; break;
- case CARET_STATE_ON: input->caret_state = 1; break;
- case CARET_STATE_TOGGLE: input->caret_state = !input->caret_state; break;
- case CARET_STATE_ON_IF_MOVED:
- if (req->x != reply->old_rect.left || req->y != reply->old_rect.top) input->caret_state = 1;
- break;
- }
- }
- }
- /* get the time of the last input event */
- DECL_HANDLER(get_last_input_time)
- {
- reply->time = last_input_time;
- }
- /* set/get the current cursor */
- DECL_HANDLER(set_cursor)
- {
- struct msg_queue *queue = get_current_queue();
- struct thread_input *input;
- if (!queue) return;
- input = queue->input;
- reply->prev_handle = input->cursor;
- reply->prev_count = input->cursor_count;
- reply->prev_x = input->desktop->cursor.x;
- reply->prev_y = input->desktop->cursor.y;
- if (req->flags & SET_CURSOR_HANDLE)
- {
- if (req->handle && !get_user_object( req->handle, USER_CLIENT ))
- {
- set_win32_error( ERROR_INVALID_CURSOR_HANDLE );
- return;
- }
- input->cursor = req->handle;
- }
- if (req->flags & SET_CURSOR_COUNT)
- {
- queue->cursor_count += req->show_count;
- input->cursor_count += req->show_count;
- }
- if (req->flags & SET_CURSOR_POS)
- {
- set_cursor_pos( input->desktop, req->x, req->y );
- }
- if (req->flags & (SET_CURSOR_CLIP | SET_CURSOR_NOCLIP))
- {
- struct desktop *desktop = input->desktop;
- /* only the desktop owner can set the message */
- if (req->clip_msg && get_top_window_owner(desktop) == current->process)
- desktop->cursor.clip_msg = req->clip_msg;
- set_clip_rectangle( desktop, (req->flags & SET_CURSOR_NOCLIP) ? NULL : &req->clip, 0 );
- }
- reply->new_x = input->desktop->cursor.x;
- reply->new_y = input->desktop->cursor.y;
- reply->new_clip = input->desktop->cursor.clip;
- reply->last_change = input->desktop->cursor.last_change;
- }
- DECL_HANDLER(update_rawinput_devices)
- {
- const struct rawinput_device *devices = get_req_data();
- unsigned int device_count = get_req_data_size() / sizeof (*devices);
- const struct rawinput_device_entry *e;
- unsigned int i;
- for (i = 0; i < device_count; ++i)
- {
- update_rawinput_device(&devices[i]);
- }
- e = find_rawinput_device( current->process, 1, 2 );
- current->process->rawinput_mouse = e ? &e->device : NULL;
- e = find_rawinput_device( current->process, 1, 6 );
- current->process->rawinput_kbd = e ? &e->device : NULL;
- }
- DECL_HANDLER(get_rawinput_devices)
- {
- unsigned int device_count = list_count(¤t->process->rawinput_devices);
- struct rawinput_device *devices;
- struct rawinput_device_entry *e;
- unsigned int i;
- reply->device_count = device_count;
- if (get_reply_max_size() / sizeof (*devices) < device_count)
- return;
- if (!(devices = mem_alloc( device_count * sizeof (*devices) )))
- {
- set_error( STATUS_NO_MEMORY );
- return;
- }
- i = 0;
- LIST_FOR_EACH_ENTRY( e, ¤t->process->rawinput_devices, struct rawinput_device_entry, entry )
- devices[i++] = e->device;
- set_reply_data_ptr( devices, device_count * sizeof (*devices) );
- }
- DECL_HANDLER(esync_msgwait)
- {
- struct msg_queue *queue = get_current_queue();
- if (!queue) return;
- queue->esync_in_msgwait = req->in_msgwait;
- if (current->process->idle_event && !(queue->wake_mask & QS_SMRESULT))
- set_event( current->process->idle_event );
- }
|