ReactOS 0.4.17-dev-806-gffa4164
input.c File Reference
#include <win32k.h>
Include dependency graph for input.c:

Go to the source code of this file.

Macros

#define LAST_RIT_EVENT_UPDATE_INTERVAL   1000UL
 

Functions

 DBG_DEFAULT_CHANNEL (UserInput)
 
static DWORD FASTCALL IntLastInputTick (BOOL bUpdate)
 
VOID FASTCALL DoTheScreenSaver (VOID)
 
static NTSTATUS NTAPI OpenInputDevice (PHANDLE pHandle, PFILE_OBJECT *ppObject, CONST WCHAR *pszDeviceName)
 
VOID NTAPI RawInputThreadMain (VOID)
 
NTSTATUS NTAPI InitInputImpl (VOID)
 
BOOL FASTCALL IntBlockInput (PTHREADINFO pti, BOOL BlockIt)
 
BOOL APIENTRY NtUserBlockInput (BOOL BlockIt)
 
BOOL FASTCALL IsRemoveAttachThread (PTHREADINFO pti)
 
NTSTATUS FASTCALL UserAttachThreadInput (PTHREADINFO ptiFrom, PTHREADINFO ptiTo, BOOL fAttach)
 
BOOL APIENTRY NtUserAttachThreadInput (IN DWORD idAttach, IN DWORD idAttachTo, IN BOOL fAttach)
 
UINT APIENTRY NtUserSendInput (UINT nInputs, LPINPUT pInput, INT cbSize)
 

Variables

PTHREADINFO ptiRawInput
 
PKTIMER MasterTimer = NULL
 
PATTACHINFO gpai = NULL
 
INT paiCount = 0
 
HANDLE ghKeyboardDevice = NULL
 
PINPUT_DEVICE_INFO gpInputDeviceInfo = NULL
 
PERESOURCE gpDeviceInfoListMutex = NULL
 
static DWORD LastInputTick = 0
 
static HANDLE ghMouseDevice
 

Macro Definition Documentation

◆ LAST_RIT_EVENT_UPDATE_INTERVAL

#define LAST_RIT_EVENT_UPDATE_INTERVAL   1000UL

Definition at line 17 of file input.c.

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserInput  )

◆ DoTheScreenSaver()

VOID FASTCALL DoTheScreenSaver ( VOID  )

Definition at line 66 of file input.c.

67{
68 DWORD Test, TO;
69
70 if (gspv.iScrSaverTimeout > 0) // Zero means Off.
71 {
74 TO = 1000 * gspv.iScrSaverTimeout;
75 if (Test > TO)
76 {
77 TRACE("Screensaver Message Start! Tick %lu Timeout %d \n", Test, gspv.iScrSaverTimeout);
78
79 if (ppiScrnSaver) // We are or we are not the screensaver, prevent reentry...
80 {
81 if (!(ppiScrnSaver->W32PF_flags & W32PF_IDLESCREENSAVER))
82 {
83 ppiScrnSaver->W32PF_flags |= W32PF_IDLESCREENSAVER;
84 ERR("Screensaver is Idle\n");
85 }
86 }
87 else
88 {
90 if (ForegroundQueue && ForegroundQueue->spwndActive)
92 else
94 }
95 }
96 }
97}
#define ERR(fmt,...)
Definition: precomp.h:57
#define EngGetTickCount32()
Definition: eng.h:43
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND hwndSAS
Definition: winsta.c:24
#define TRACE(s)
Definition: solgame.cpp:4
INT iScrSaverTimeout
Definition: sysparams.h:110
#define WM_LOGONNOTIFY
Definition: undocuser.h:39
#define LN_START_SCREENSAVE
Definition: undocuser.h:122
#define W32PF_IDLESCREENSAVER
Definition: win32.h:27
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1335
static DWORD LastInputTick
Definition: input.c:30
PPROCESSINFO ppiScrnSaver
Definition: main.c:30
BOOL FASTCALL UserPostMessage(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1395
SPIVALUES gspv
Definition: sysparams.c:17

Referenced by HungAppSysTimerProc().

◆ InitInputImpl()

NTSTATUS NTAPI InitInputImpl ( VOID  )

Definition at line 401 of file input.c.

402{
404 if (!MasterTimer)
405 {
406 ERR("Failed to allocate memory\n");
407 ASSERT(FALSE);
408 return STATUS_UNSUCCESSFUL;
409 }
411
412 return STATUS_SUCCESS;
413}
#define FALSE
Definition: types.h:117
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PKTIMER MasterTimer
Definition: input.c:23
#define USERTAG_SYSTEM
Definition: tags.h:282

Referenced by DriverEntry().

◆ IntBlockInput()

BOOL FASTCALL IntBlockInput ( PTHREADINFO  pti,
BOOL  BlockIt 
)

Definition at line 416 of file input.c.

417{
418 PTHREADINFO OldBlock;
419 ASSERT(pti);
420
421 if(!pti->rpdesk || ((pti->TIF_flags & TIF_INCLEANUP) && BlockIt))
422 {
423 /*
424 * Fail blocking if exiting the thread
425 */
426
427 return FALSE;
428 }
429
430 /*
431 * FIXME: Check access rights of the window station
432 * e.g. services running in the service window station cannot block input
433 */
434 if(!ThreadHasInputAccess(pti) ||
436 {
438 return FALSE;
439 }
440
441 ASSERT(pti->rpdesk);
442 OldBlock = pti->rpdesk->BlockInputThread;
443 if(OldBlock)
444 {
445 if(OldBlock != pti)
446 {
448 return FALSE;
449 }
450 pti->rpdesk->BlockInputThread = (BlockIt ? pti : NULL);
451 return OldBlock == NULL;
452 }
453
454 pti->rpdesk->BlockInputThread = (BlockIt ? pti : NULL);
455 return OldBlock == NULL;
456}
#define IntIsActiveDesktop(Desktop)
Definition: desktop.h:174
#define NULL
Definition: types.h:112
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define TIF_INCLEANUP
Definition: ntuser.h:266
FLONG TIF_flags
Definition: win32.h:96
struct _DESKTOP * rpdesk
Definition: win32.h:93
#define ThreadHasInputAccess(W32Thread)
Definition: input.h:66
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:21

Referenced by ExitThreadCallback(), and NtUserBlockInput().

◆ IntLastInputTick()

static DWORD FASTCALL IntLastInputTick ( BOOL  bUpdate)
static

Definition at line 41 of file input.c.

42{
43 if (bUpdate)
44 {
46 if (gpsi)
47 {
48 gpsi->dwLastRITEventTickCount = LastInputTick;
49 if (gpsi->dwLastRITEventTickCount - gpsi->dwLastSystemRITEventTickCountUpdate >
51 {
52 SharedUserData->LastSystemRITEventTickCount = LastInputTick;
53 gpsi->dwLastSystemRITEventTickCountUpdate = LastInputTick;
54 }
55 }
56 }
57 return LastInputTick;
58}
PSERVERINFO gpsi
Definition: imm.c:18
#define SharedUserData
#define LAST_RIT_EVENT_UPDATE_INTERVAL
Definition: input.c:17

Referenced by RawInputThreadMain().

◆ IsRemoveAttachThread()

BOOL FASTCALL IsRemoveAttachThread ( PTHREADINFO  pti)

Definition at line 478 of file input.c.

479{
481 PATTACHINFO pai;
482 BOOL Ret = TRUE;
483 PTHREADINFO ptiFrom = NULL, ptiTo = NULL;
484
485 do
486 {
487 if (!gpai) return TRUE;
488
489 pai = gpai; // Bottom of the list.
490
491 do
492 {
493 if (pai->pti2 == pti)
494 {
495 ptiFrom = pai->pti1;
496 ptiTo = pti;
497 break;
498 }
499 if (pai->pti1 == pti)
500 {
501 ptiFrom = pti;
502 ptiTo = pai->pti2;
503 break;
504 }
505 pai = pai->paiNext;
506
507 } while (pai);
508
509 if (!pai && !ptiFrom && !ptiTo) break;
510
511 Status = UserAttachThreadInput(ptiFrom, ptiTo, FALSE);
512 if (!NT_SUCCESS(Status)) Ret = FALSE;
513
514 } while (Ret);
515
516 return Ret;
517}
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:24
PTHREADINFO pti2
Definition: input.h:46
struct _ATTACHINFO * paiNext
Definition: input.h:44
PTHREADINFO pti1
Definition: input.h:45
PATTACHINFO gpai
Definition: input.c:24
NTSTATUS FASTCALL UserAttachThreadInput(PTHREADINFO ptiFrom, PTHREADINFO ptiTo, BOOL fAttach)
Definition: input.c:520

Referenced by ExitThreadCallback().

◆ NtUserAttachThreadInput()

BOOL APIENTRY NtUserAttachThreadInput ( IN DWORD  idAttach,
IN DWORD  idAttachTo,
IN BOOL  fAttach 
)

Definition at line 705 of file input.c.

709{
711 PTHREADINFO pti, ptiTo;
712 BOOL Ret = FALSE;
713
715 TRACE("Enter NtUserAttachThreadInput %s\n",(fAttach ? "TRUE" : "FALSE" ));
716
717 pti = IntTID2PTI(UlongToHandle(idAttach));
718 ptiTo = IntTID2PTI(UlongToHandle(idAttachTo));
719
720 if ( !pti || !ptiTo )
721 {
722 TRACE("AttachThreadInput pti or ptiTo NULL.\n");
724 goto Exit;
725 }
726
727 Status = UserAttachThreadInput( pti, ptiTo, fAttach);
728 if (!NT_SUCCESS(Status))
729 {
730 TRACE("AttachThreadInput Error Status 0x%x. \n",Status);
732 }
733 else Ret = TRUE;
734
735Exit:
736 TRACE("Leave NtUserAttachThreadInput, ret=%d\n",Ret);
737 UserLeave();
738 return Ret;
739}
#define UlongToHandle(ul)
Definition: basetsd.h:91
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
static void Exit(void)
Definition: sock.c:1330
PTHREADINFO FASTCALL IntTID2PTI(HANDLE id)
Definition: misc.c:41
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)

◆ NtUserBlockInput()

BOOL APIENTRY NtUserBlockInput ( BOOL  BlockIt)

Definition at line 460 of file input.c.

462{
463 BOOL ret;
464
465 TRACE("Enter NtUserBlockInput\n");
467
469
470 UserLeave();
471 TRACE("Leave NtUserBlockInput, ret=%i\n", ret);
472
473 return ret;
474}
return ret
Definition: mutex.c:147
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
BOOL FASTCALL IntBlockInput(PTHREADINFO pti, BOOL BlockIt)
Definition: input.c:416

Referenced by BlockInput().

◆ NtUserSendInput()

UINT APIENTRY NtUserSendInput ( UINT  nInputs,
LPINPUT  pInput,
INT  cbSize 
)

Definition at line 748 of file input.c.

752{
753 PTHREADINFO pti;
754 UINT uRet = 0;
755
756 TRACE("Enter NtUserSendInput\n");
758
760 ASSERT(pti);
761
762 if (!pti->rpdesk)
763 {
764 goto cleanup;
765 }
766
767 if (!nInputs || !pInput || cbSize != sizeof(INPUT))
768 {
770 goto cleanup;
771 }
772
773 /*
774 * FIXME: Check access rights of the window station
775 * e.g. services running in the service window station cannot block input
776 */
777 if (!ThreadHasInputAccess(pti) ||
779 {
781 goto cleanup;
782 }
783
784 while (nInputs--)
785 {
786 INPUT SafeInput;
788
789 Status = MmCopyFromCaller(&SafeInput, pInput++, sizeof(INPUT));
790 if (!NT_SUCCESS(Status))
791 {
793 goto cleanup;
794 }
795
796 switch (SafeInput.type)
797 {
798 case INPUT_MOUSE:
799 if (UserSendMouseInput(&SafeInput.mi, TRUE))
800 uRet++;
801 break;
802 case INPUT_KEYBOARD:
803 if (UserSendKeyboardInput(&SafeInput.ki, TRUE))
804 uRet++;
805 break;
806 case INPUT_HARDWARE:
807 FIXME("INPUT_HARDWARE not supported!\n");
808 break;
809 default:
810 ERR("SendInput(): Invalid input type: 0x%x\n", SafeInput.type);
811 break;
812 }
813 }
814
815cleanup:
816 TRACE("Leave NtUserSendInput, ret=%u\n", uRet);
817 UserLeave();
818 return uRet;
819}
#define FIXME(fmt,...)
Definition: precomp.h:53
static void cleanup(void)
Definition: main.c:1335
unsigned int UINT
Definition: sysinfo.c:13
#define MmCopyFromCaller
Definition: polytest.cpp:29
KEYBDINPUT ki
Definition: winable.h:62
DWORD type
Definition: winable.h:59
MOUSEINPUT mi
Definition: winable.h:61
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:30
BOOL NTAPI UserSendKeyboardInput(KEYBDINPUT *pKbdInput, BOOL bInjected)
Definition: keyboard.c:1333
BOOL NTAPI UserSendMouseInput(MOUSEINPUT *pMouseInput, BOOL bInjected)
Definition: mouse.c:168
#define INPUT_HARDWARE
Definition: winable.h:11
#define INPUT_KEYBOARD
Definition: winable.h:10
#define INPUT_MOUSE
Definition: winable.h:9

Referenced by keybd_event(), mouse_event(), and SendInput().

◆ OpenInputDevice()

static NTSTATUS NTAPI OpenInputDevice ( PHANDLE  pHandle,
PFILE_OBJECT ppObject,
CONST WCHAR pszDeviceName 
)
static

Definition at line 106 of file input.c.

107{
112
113 RtlInitUnicodeString(&DeviceName, pszDeviceName);
114
116 &DeviceName,
118 NULL,
119 NULL);
120
121 Status = ZwOpenFile(pHandle,
124 &Iosb,
125 0,
126 0);
127 if (NT_SUCCESS(Status) && ppObject)
128 {
131 }
132
133 return Status;
134}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
return Iosb
Definition: create.c:4403
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
#define KernelMode
Definition: asm.h:38
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:493
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281

Referenced by RawInputThreadMain().

◆ RawInputThreadMain()

VOID NTAPI RawInputThreadMain ( VOID  )

Definition at line 142 of file input.c.

143{
144 NTSTATUS MouStatus = STATUS_UNSUCCESSFUL, KbdStatus = STATUS_UNSUCCESSFUL, Status;
145 IO_STATUS_BLOCK MouIosb, KbdIosb;
146 PFILE_OBJECT pKbdDevice = NULL, pMouDevice = NULL;
148 //LARGE_INTEGER WaitTimeout;
149 PVOID WaitObjects[4], pSignaledObject = NULL;
151 ULONG cWaitObjects = 0, cMaxWaitObjects = 2;
152 MOUSE_INPUT_DATA MouseInput;
153 KEYBOARD_INPUT_DATA KeyInput;
155 HWINSTA hWinSta;
158
159 RtlZeroMemory(&Mouse, sizeof(Mouse));
160 Mouse.DeviceType = RIM_TYPEMOUSE;
161 RtlInitUnicodeString(&Mouse.DeviceName, L"\\Device\\PointerClass0");
162 Mouse.Mouse.Attributes.NumberOfButtons = 2;
163
165 Keyboard.DeviceType = RIM_TYPEKEYBOARD;
166 RtlInitUnicodeString(&Keyboard.DeviceName, L"\\Device\\KeyboardClass0");
167
168 ByteOffset.QuadPart = (LONGLONG)0;
169 //WaitTimeout.QuadPart = (LONGLONG)(-10000000);
170
174
175 TRACE("Raw Input Thread %p\n", ptiRawInput);
176
179
181 0,
182 NULL,
185 UserMode,
186 (PHANDLE)&hWinSta);
187 if (NT_SUCCESS(Status))
188 {
190 }
191 else
192 {
193 ASSERT(FALSE);
194 /* Failed to open the interactive winsta! What now? */
195 }
196
201
204 UserLeave();
205
208
210 for (;;)
211 {
212 if (!ghMouseDevice)
213 {
214 /* Check if mouse device already exists */
215 Status = OpenInputDevice(&ghMouseDevice, &pMouDevice, Mouse.DeviceName.Buffer);
216 if (NT_SUCCESS(Status))
217 {
218 ++cMaxWaitObjects;
219 TRACE("Mouse connected!\n");
220 Mouse.pNextDeviceInfo = gpInputDeviceInfo;
222 }
223 }
224 if (!ghKeyboardDevice)
225 {
226 /* Check if keyboard device already exists */
227 Status = OpenInputDevice(&ghKeyboardDevice, &pKbdDevice, Keyboard.DeviceName.Buffer);
228 if (NT_SUCCESS(Status))
229 {
230 ++cMaxWaitObjects;
231 TRACE("Keyboard connected!\n");
232 Keyboard.pNextDeviceInfo = gpInputDeviceInfo;
234 // Get and load keyboard attributes.
236 Keyboard.Keyboard.Attributes = gKeyboardInfo;
238 // Register the Window hotkey.
240 // Register the Window Snap hotkey.
245 // Register the debug hotkeys.
247 UserLeave();
248 }
249 }
250
251 /* Reset WaitHandles array */
252 cWaitObjects = 0;
253 WaitObjects[cWaitObjects++] = ShutdownEvent;
254 WaitObjects[cWaitObjects++] = MasterTimer;
255
256 if (ghMouseDevice)
257 {
258 /* Try to read from mouse if previous reading is not pending */
259 if (MouStatus != STATUS_PENDING)
260 {
261 MouStatus = ZwReadFile(ghMouseDevice,
262 NULL,
263 NULL,
264 NULL,
265 &MouIosb,
266 &MouseInput,
267 sizeof(MOUSE_INPUT_DATA),
268 &ByteOffset,
269 NULL);
270 }
271
272 if (MouStatus == STATUS_PENDING)
273 WaitObjects[cWaitObjects++] = &pMouDevice->Event;
274 }
275
277 {
278 /* Try to read from keyboard if previous reading is not pending */
279 if (KbdStatus != STATUS_PENDING)
280 {
281 KbdStatus = ZwReadFile(ghKeyboardDevice,
282 NULL,
283 NULL,
284 NULL,
285 &KbdIosb,
286 &KeyInput,
287 sizeof(KEYBOARD_INPUT_DATA),
288 &ByteOffset,
289 NULL);
290
291 }
292 if (KbdStatus == STATUS_PENDING)
293 WaitObjects[cWaitObjects++] = &pKbdDevice->Event;
294 }
295
296 /* If all objects are pending, wait for them */
297 if (cWaitObjects == cMaxWaitObjects)
298 {
299 Status = KeWaitForMultipleObjects(cWaitObjects,
300 WaitObjects,
301 WaitAny,
304 TRUE,
305 NULL,//&WaitTimeout,
307
308 if ((Status >= STATUS_WAIT_0) &&
309 (Status < (STATUS_WAIT_0 + (LONG)cWaitObjects)))
310 {
311 /* Some device has finished reading */
312 pSignaledObject = WaitObjects[Status - STATUS_WAIT_0];
313
314 /* Check if it is mouse or keyboard and update status */
315 if ((MouStatus == STATUS_PENDING) &&
316 (pSignaledObject == &pMouDevice->Event))
317 {
318 MouStatus = MouIosb.Status;
319 }
320 else if ((KbdStatus == STATUS_PENDING) &&
321 (pSignaledObject == &pKbdDevice->Event))
322 {
323 KbdStatus = KbdIosb.Status;
324 }
325 else if (pSignaledObject == MasterTimer)
326 {
328 }
329 else if (pSignaledObject == ShutdownEvent)
330 {
331 break;
332 }
333 else ASSERT(FALSE);
334 }
335 }
336
337 /* Have we successed reading from mouse? */
338 if (NT_SUCCESS(MouStatus) && MouStatus != STATUS_PENDING)
339 {
340 TRACE("MouseEvent\n");
341
342 /* Set LastInputTick */
344
345 /* Process data */
347 UserProcessMouseInput(&MouseInput);
348 UserLeave();
349 }
350 else if (MouStatus != STATUS_PENDING)
351 ERR("Failed to read from mouse: %x.\n", MouStatus);
352
353 /* Have we successed reading from keyboard? */
354 if (NT_SUCCESS(KbdStatus) && KbdStatus != STATUS_PENDING)
355 {
356 TRACE("KeyboardEvent: %s %04x\n",
357 (KeyInput.Flags & KEY_BREAK) ? "up" : "down",
358 KeyInput.MakeCode);
359
360 /* Set LastInputTick */
362
363 /* Process data */
365 UserProcessKeyboardInput(&KeyInput);
366 UserLeave();
367 }
368 else if (KbdStatus != STATUS_PENDING)
369 ERR("Failed to read from keyboard: %x.\n", KbdStatus);
370 }
371
372 if (ghMouseDevice)
373 {
376 ObDereferenceObject(pMouDevice);
378 }
379
381 {
384 ObDereferenceObject(pKbdDevice);
386 }
387
389
390 ERR("Raw Input Thread Exit!\n");
391}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static HANDLE ShutdownEvent
Definition: dcomlaunch.c:28
#define L(x)
Definition: resources.c:13
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:732
_Must_inspect_result_ _In_ WAIT_TYPE _In_opt_ PLARGE_INTEGER _In_opt_ PKWAIT_BLOCK WaitBlockArray
Definition: fsrtlfuncs.h:1153
#define IDHK_SNAP_LEFT
Definition: hotkey.h:20
#define IDHK_WINKEY
Definition: hotkey.h:16
#define IDHK_SNAP_UP
Definition: hotkey.h:22
#define IDHK_SNAP_DOWN
Definition: hotkey.h:23
#define IDHK_SNAP_RIGHT
Definition: hotkey.h:21
@ Keyboard
Definition: i8042prt.h:115
@ Mouse
Definition: i8042prt.h:116
#define PWND_BOTTOM
Definition: ntuser.h:773
struct _THREADINFO * GetW32ThreadInfo(VOID)
Definition: misc.c:806
#define TIF_SYSTEMTHREAD
Definition: ntuser.h:268
#define LOW_REALTIME_PRIORITY
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define UserMode
Definition: asm.h:39
NTSYSAPI NTSTATUS NTAPI ZwCancelIoFile(_In_ HANDLE FileHandle, _Out_ PIO_STATUS_BLOCK IoStatusBlock)
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define KEY_BREAK
Definition: ntddkbd.h:71
@ WaitAny
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_WAIT_0
Definition: ntstatus.h:330
PWINSTATION_OBJECT InputWindowStation
Definition: winsta.c:21
BOOL FASTCALL UserSetProcessWindowStation(HWINSTA hWindowStation)
Definition: winsta.c:1614
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3406
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2764
long LONG
Definition: pedump.c:60
NTSTATUS NTAPI PoRequestShutdownEvent(OUT PVOID *Event)
Definition: poshtdwn.c:384
struct _CLIENTINFO * pClientInfo
Definition: win32.h:95
#define STATUS_PENDING
Definition: telnetd.h:14
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1300
int64_t LONGLONG
Definition: typedefs.h:68
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
BOOL FASTCALL UserRegisterHotKey(PWND pWnd, int id, UINT fsModifiers, UINT vk)
Definition: hotkey.c:447
VOID FASTCALL SetDebugHotKeys(VOID)
Definition: hotkey.c:46
static NTSTATUS NTAPI OpenInputDevice(PHANDLE pHandle, PFILE_OBJECT *ppObject, CONST WCHAR *pszDeviceName)
Definition: input.c:106
static HANDLE ghMouseDevice
Definition: input.c:31
HANDLE ghKeyboardDevice
Definition: input.c:26
PTHREADINFO ptiRawInput
Definition: input.c:22
static DWORD FASTCALL IntLastInputTick(BOOL bUpdate)
Definition: input.c:41
PINPUT_DEVICE_INFO gpInputDeviceInfo
Definition: input.c:27
PERESOURCE gpDeviceInfoListMutex
Definition: input.c:28
KEYBOARD_ATTRIBUTES gKeyboardInfo
Definition: keyboard.c:17
VOID NTAPI UserProcessKeyboardInput(PKEYBOARD_INPUT_DATA pKeyInput)
Definition: keyboard.c:1414
VOID NTAPI UserProcessMouseInput(PMOUSE_INPUT_DATA pMouseInputData)
Definition: mouse.c:40
VOID NTAPI UserInitKeyboard(HANDLE hKeyboardDevice)
Definition: keyboard.c:178
VOID FASTCALL ProcessTimers(VOID)
Definition: timer.c:452
VOID FASTCALL StartTheTimers(VOID)
Definition: timer.c:374
#define MOD_WIN
Definition: winuser.h:2686
#define VK_UP
Definition: winuser.h:2261
#define VK_LEFT
Definition: winuser.h:2260
#define VK_RIGHT
Definition: winuser.h:2262
#define VK_DOWN
Definition: winuser.h:2263
* PFILE_OBJECT
Definition: iotypes.h:1998
@ UserRequest
Definition: ketypes.h:473
#define ObDereferenceObject
Definition: obfuncs.h:203
#define NT_ASSERT
Definition: rtlfuncs.h:3327

Referenced by UserSystemThreadProc().

◆ UserAttachThreadInput()

NTSTATUS FASTCALL UserAttachThreadInput ( PTHREADINFO  ptiFrom,
PTHREADINFO  ptiTo,
BOOL  fAttach 
)

Definition at line 520 of file input.c.

521{
522 MSG msg;
523 PATTACHINFO pai;
524 PCURICON_OBJECT CurIcon;
525
526 /* Can not be the same thread. */
527 if (ptiFrom == ptiTo) return STATUS_INVALID_PARAMETER;
528
529 /* Do not attach to system threads or between different desktops. */
530 if (ptiFrom->TIF_flags & TIF_DONTATTACHQUEUE ||
532 ptiFrom->rpdesk != ptiTo->rpdesk)
534
535 /* MSDN Note:
536 Keyboard and mouse events received by both threads are processed by the thread specified by the idAttachTo.
537 */
538
539 /* If Attach set, allocate and link. */
540 if (fAttach)
541 {
543 if (!pai) return STATUS_NO_MEMORY;
544
545 pai->paiNext = gpai;
546 pai->pti1 = ptiFrom;
547 pai->pti2 = ptiTo;
548 gpai = pai;
549 paiCount++;
550 ERR("Attach Allocated! ptiFrom 0x%p ptiTo 0x%p paiCount %d\n",ptiFrom,ptiTo,paiCount);
551
552 if (ptiTo->MessageQueue != ptiFrom->MessageQueue)
553 {
554
555 ptiTo->MessageQueue->iCursorLevel -= ptiFrom->iCursorLevel;
556
557 if (ptiFrom->MessageQueue == gpqForeground)
558 {
559 ERR("ptiFrom is Foreground\n");
560 ptiTo->MessageQueue->spwndActive = ptiFrom->MessageQueue->spwndActive;
561 ptiTo->MessageQueue->spwndFocus = ptiFrom->MessageQueue->spwndFocus;
562 ptiTo->MessageQueue->spwndCapture = ptiFrom->MessageQueue->spwndCapture;
563 ptiTo->MessageQueue->QF_flags ^= ((ptiTo->MessageQueue->QF_flags ^ ptiFrom->MessageQueue->QF_flags) & QF_CAPTURELOCKED);
564 RtlCopyMemory(&ptiTo->MessageQueue->CaretInfo,
565 &ptiFrom->MessageQueue->CaretInfo,
566 sizeof(ptiTo->MessageQueue->CaretInfo));
569 gptiForeground = ptiTo;
570 }
571 else
572 {
573 ERR("ptiFrom NOT Foreground\n");
574 if ( ptiTo->MessageQueue->spwndActive == 0 )
575 ptiTo->MessageQueue->spwndActive = ptiFrom->MessageQueue->spwndActive;
576 if ( ptiTo->MessageQueue->spwndFocus == 0 )
577 ptiTo->MessageQueue->spwndFocus = ptiFrom->MessageQueue->spwndFocus;
578 }
579
580 CurIcon = ptiFrom->MessageQueue->CursorObject;
581
582 MsqDestroyMessageQueue(ptiFrom);
583
584 if (CurIcon)
585 {
586 // Could be global. Keep it above the water line!
587 UserReferenceObject(CurIcon);
588 }
589
590 if (CurIcon && UserObjectInDestroy(UserHMGetHandle(CurIcon)))
591 {
592 UserDereferenceObject(CurIcon);
593 CurIcon = NULL;
594 }
595
596 ptiFrom->MessageQueue = ptiTo->MessageQueue;
597
598 // Pass cursor From if To is null. Pass test_SetCursor parent_id == current pti ID.
599 if (CurIcon && ptiTo->MessageQueue->CursorObject == NULL)
600 {
601 ERR("ptiTo receiving ptiFrom Cursor\n");
602 ptiTo->MessageQueue->CursorObject = CurIcon;
603 }
604
605 ptiFrom->MessageQueue->cThreads++;
606 ERR("ptiTo S Share count %u\n", ptiFrom->MessageQueue->cThreads);
607
609 }
610 else
611 {
612 ERR("Attach Threads are already associated!\n");
613 }
614 }
615 else /* If clear, unlink and free it. */
616 {
617 BOOL Hit = FALSE;
618 PATTACHINFO *ppai;
619
620 if (!gpai) return STATUS_INVALID_PARAMETER;
621
622 /* Search list and free if found or return false. */
623 ppai = &gpai;
624 while (*ppai != NULL)
625 {
626 if ( (*ppai)->pti2 == ptiTo && (*ppai)->pti1 == ptiFrom )
627 {
628 pai = *ppai;
629 /* Remove it from the list */
630 *ppai = (*ppai)->paiNext;
632 paiCount--;
633 Hit = TRUE;
634 break;
635 }
636 ppai = &((*ppai)->paiNext);
637 }
638
639 if (!Hit) return STATUS_INVALID_PARAMETER;
640
641 ERR("Attach Free! ptiFrom 0x%p ptiTo 0x%p paiCount %d\n",ptiFrom,ptiTo,paiCount);
642
643 if (ptiTo->MessageQueue == ptiFrom->MessageQueue)
644 {
645 PWND spwndActive = ptiTo->MessageQueue->spwndActive;
646 PWND spwndFocus = ptiTo->MessageQueue->spwndFocus;
647
648 if (gptiForeground == ptiFrom)
649 {
650 ERR("ptiTo is now pti FG.\n");
651 // MessageQueue foreground is set so switch threads.
652 gptiForeground = ptiTo;
653 }
654 ptiTo->MessageQueue->cThreads--;
655 ERR("ptiTo E Share count %u\n", ptiTo->MessageQueue->cThreads);
656 ASSERT(ptiTo->MessageQueue->cThreads >= 1);
657
659
660 ptiFrom->MessageQueue = MsqCreateMessageQueue(ptiFrom);
661
662 if (spwndActive)
663 {
664 if (spwndActive->head.pti == ptiFrom)
665 {
666 ptiFrom->MessageQueue->spwndActive = spwndActive;
667 ptiTo->MessageQueue->spwndActive = 0;
668 }
669 }
670 if (spwndFocus)
671 {
672 if (spwndFocus->head.pti == ptiFrom)
673 {
674 ptiFrom->MessageQueue->spwndFocus = spwndFocus;
675 ptiTo->MessageQueue->spwndFocus = 0;
676 }
677 }
678 ptiTo->MessageQueue->iCursorLevel -= ptiFrom->iCursorLevel;
679 }
680 else
681 {
682 ERR("Detaching Threads are not associated!\n");
683 }
684 }
685 /* Note that key state, which can be ascertained by calls to the GetKeyState
686 or GetKeyboardState function, is reset after a call to AttachThreadInput.
687 ATM which one?
688 */
689 RtlCopyMemory(ptiTo->MessageQueue->afKeyState, gafAsyncKeyState, sizeof(gafAsyncKeyState));
690
691 ptiTo->MessageQueue->msgDblClk.message = 0;
692
693 /* Generate mouse move message */
694 msg.message = WM_MOUSEMOVE;
695 msg.wParam = UserGetMouseButtonsState();
696 msg.lParam = MAKELPARAM(gpsi->ptCursor.x, gpsi->ptCursor.y);
697 msg.pt = gpsi->ptCursor;
699
700 return STATUS_SUCCESS;
701}
#define msg(x)
Definition: auth_time.c:54
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
PTHREADINFO gptiForeground
Definition: focus.c:15
#define PagedPool
Definition: env_spec_w32.h:308
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
#define TIF_DONTATTACHQUEUE
Definition: ntuser.h:272
#define UserHMGetHandle(obj)
Definition: ntuser.h:233
VOID FASTCALL co_MsqInsertMouseMessage(MSG *Msg, DWORD flags, ULONG_PTR dwExtraInfo, BOOL Hook)
Definition: msgqueue.c:580
VOID FASTCALL MsqDestroyMessageQueue(_In_ PTHREADINFO pti)
Definition: msgqueue.c:2423
PUSER_MESSAGE_QUEUE FASTCALL MsqCreateMessageQueue(PTHREADINFO pti)
Definition: msgqueue.c:2396
#define QF_CAPTURELOCKED
Definition: msgqueue.h:111
#define IntReferenceMessageQueue(MsgQueue)
Definition: msgqueue.h:217
#define IntDereferenceMessageQueue(MsgQueue)
Definition: msgqueue.h:220
INT iCursorLevel
Definition: win32.h:128
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:90
Definition: ntuser.h:698
THRDESKHEAD head
Definition: ntuser.h:699
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
VOID FASTCALL IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue)
Definition: desktop.c:1347
INT paiCount
Definition: input.c:25
WORD FASTCALL UserGetMouseButtonsState(VOID)
Definition: mouse.c:22
BYTE gafAsyncKeyState[256 *2/8]
Definition: keyboard.c:13
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:647
BOOL FASTCALL UserObjectInDestroy(HANDLE h)
Definition: object.c:707
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:754
#define USERTAG_ATTACHINFO
Definition: tags.h:197
#define MAKELPARAM(l, h)
Definition: winuser.h:4116
#define WM_MOUSEMOVE
Definition: winuser.h:1803

Referenced by co_IntSetParent(), co_UserCreateWindowEx(), co_UserDestroyWindow(), IntCreateWindow(), IntProcessOwnerSwap(), IsRemoveAttachThread(), and NtUserAttachThreadInput().

Variable Documentation

◆ ghKeyboardDevice

HANDLE ghKeyboardDevice = NULL

Definition at line 26 of file input.c.

Referenced by ProcessKeyEvent(), and RawInputThreadMain().

◆ ghMouseDevice

HANDLE ghMouseDevice
static

Definition at line 31 of file input.c.

Referenced by RawInputThreadMain().

◆ gpai

PATTACHINFO gpai = NULL

Definition at line 24 of file input.c.

Referenced by IsRemoveAttachThread(), and UserAttachThreadInput().

◆ gpDeviceInfoListMutex

PERESOURCE gpDeviceInfoListMutex = NULL

◆ gpInputDeviceInfo

PINPUT_DEVICE_INFO gpInputDeviceInfo = NULL

◆ LastInputTick

DWORD LastInputTick = 0
static

Definition at line 30 of file input.c.

Referenced by DoTheScreenSaver(), and IntLastInputTick().

◆ MasterTimer

PKTIMER MasterTimer = NULL

Definition at line 23 of file input.c.

Referenced by InitInputImpl(), IntSetTimer(), ProcessTimers(), and RawInputThreadMain().

◆ paiCount

INT paiCount = 0

Definition at line 25 of file input.c.

Referenced by UserAttachThreadInput().

◆ ptiRawInput

PTHREADINFO ptiRawInput

Definition at line 22 of file input.c.

Referenced by IntSetTimer(), and RawInputThreadMain().