From eb1866f25cd74c9cc015c99fc15d43100ae58ab7 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Sat, 9 Sep 2006 19:41:12 +0000 Subject: [PATCH] Implement GetLastInput base on bug 1753 patch by P43LOk, It did not catch the last input tick from keyboard or mouse. This code is not tested in reactos, but should work. See issue #1753 for more details. svn path=/trunk/; revision=24005 --- reactos/dll/win32/user32/windows/input.c | 5 +- reactos/include/reactos/win32k/ntuser.h | 6 + .../subsystems/win32/win32k/ntuser/input.c | 166 ++++++------------ reactos/tools/nci/w32ksvc.db | 1 + 4 files changed, 61 insertions(+), 117 deletions(-) diff --git a/reactos/dll/win32/user32/windows/input.c b/reactos/dll/win32/user32/windows/input.c index edf560529e4..fe8a9d25219 100644 --- a/reactos/dll/win32/user32/windows/input.c +++ b/reactos/dll/win32/user32/windows/input.c @@ -290,13 +290,12 @@ return (int)NtUserCallOneParam((DWORD) nTypeFlag, ONEPARAM_ROUTINE_GETKEYBOARDT /* - * @unimplemented + * @implemented */ BOOL STDCALL GetLastInputInfo(PLASTINPUTINFO plii) { - UNIMPLEMENTED; - return FALSE; + return NtUserGetLastInputInfo(plii); } diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index ca46d810e95..27d6a456331 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -1447,6 +1447,12 @@ NtUserRegisterHotKey(HWND hWnd, UINT fsModifiers, UINT vk); + +BOOL +NTAPI +NtUserGetLastInputInfo( + PLASTINPUTINFO plii); + DWORD NTAPI NtUserRegisterTasklist( diff --git a/reactos/subsystems/win32/win32k/ntuser/input.c b/reactos/subsystems/win32/win32k/ntuser/input.c index cf06fb5b636..bdcbcba5ddb 100644 --- a/reactos/subsystems/win32/win32k/ntuser/input.c +++ b/reactos/subsystems/win32/win32k/ntuser/input.c @@ -39,10 +39,6 @@ extern BYTE gQueueKeyStateTable[]; /* GLOBALS *******************************************************************/ -static HANDLE ScreenSaverThreadHandle; -static CLIENT_ID ScreenSaverThreadId; -static LARGE_INTEGER MouseInputCurrentTime; -static LARGE_INTEGER KeyboardInputCurrentTime; static HANDLE MouseDeviceHandle; static HANDLE MouseThreadHandle; @@ -57,6 +53,7 @@ PUSER_MESSAGE_QUEUE pmPrimitiveMessageQueue = 0; /* FUNCTIONS *****************************************************************/ ULONG FASTCALL IntSystemParametersInfo(UINT uiAction, UINT uiParam,PVOID pvParam, UINT fWinIni); +DWORD IntLastInputTick(BOOL LastInputTickSetGet); #define ClearMouseInput(mi) \ mi.dx = 0; \ @@ -71,6 +68,53 @@ IntSystemParametersInfo(UINT uiAction, UINT uiParam,PVOID pvParam, UINT fWinIni) IntMouseInput(&mi); \ ClearMouseInput(mi); + +DWORD IntLastInputTick(BOOL LastInputTickSetGet) +{ + static DWORD LastInputTick = 0; + if (LastInputTickSetGet == TRUE) + { + LARGE_INTEGER TickCount; + KeQueryTickCount(&TickCount); + LastInputTick = TickCount.u.LowPart; + } + return LastInputTick; +} + +BOOL +STDCALL +NtUserGetLastInputInfo(PLASTINPUTINFO plii) +{ + BOOL ret = TRUE; + + UserEnterShared(); + + _SEH_TRY + { + if (ProbeForReadUint(&plii->cbSize) != sizeof(LASTINPUTINFO)) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + ret = FALSE; + _SEH_LEAVE; + } + + ProbeForWrite(plii, sizeof(LASTINPUTINFO), sizeof(DWORD)); + + plii->dwTime = IntLastInputTick(FALSE); + } + _SEH_HANDLE + { + SetLastNtError(_SEH_GetExceptionCode()); + ret = FALSE; + } + _SEH_END; + + UserLeave(); + + return ret; +} + + VOID FASTCALL ProcessMouseInputData(PMOUSE_INPUT_DATA Data, ULONG InputCount) { @@ -155,101 +199,7 @@ ProcessMouseInputData(PMOUSE_INPUT_DATA Data, ULONG InputCount) SendMouseEvent(mi); } -VOID STDCALL -ScreenSaverThreadMain(PVOID StartContext) -{ - KEVENT Event; - LARGE_INTEGER Timeout; - LARGE_INTEGER DelayTimer; - LARGE_INTEGER CurrentTime; - LARGE_INTEGER DiffTimeMouse; - LARGE_INTEGER DiffTimeKeyboard; - UINT ScreenSaverTimeOut = 0; - BOOL nPreviousState = FALSE; - NTSTATUS Status; - BOOL FirstTime = TRUE; - return; - KeSetPriorityThread(&PsGetCurrentThread()->Tcb, - LOW_REALTIME_PRIORITY + 3); - - KeQuerySystemTime(&MouseInputCurrentTime); - KeQuerySystemTime(&KeyboardInputCurrentTime); - - DelayTimer.QuadPart = -10000000LL; /* 1 second timeout */ - - for(;;) - { - DPRINT("Screen Saver auto start Thread Waiting for start event\n"); - Status = KeWaitForSingleObject(&InputThreadsStart, - 0, - KernelMode, - TRUE, - NULL); - DPRINT("Screen Saver auto start Thread Starting...\n"); - while(InputThreadsRunning) - { - - IntSystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &ScreenSaverTimeOut, 0); - IntSystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &nPreviousState, 0); - - Timeout.QuadPart = ((LONGLONG)ScreenSaverTimeOut) * 10000000LL; - - KeInitializeEvent(&Event, NotificationEvent, FALSE); - Status = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, &DelayTimer); - - if(Status == STATUS_ALERTED && !InputThreadsRunning) - { - break; - } - if(!NT_SUCCESS(Status)) - { - DPRINT1("Win32K: Failed to read from Screen Saver auto thread.\n"); - return; //(Status); - } - - KeQuerySystemTime(&CurrentTime); - DiffTimeMouse.QuadPart = CurrentTime.QuadPart - MouseInputCurrentTime.QuadPart; - DiffTimeKeyboard.QuadPart = CurrentTime.QuadPart - KeyboardInputCurrentTime.QuadPart; - - if ( (DiffTimeMouse.QuadPart >= Timeout.QuadPart) && - (DiffTimeKeyboard.QuadPart >= Timeout.QuadPart) && - (nPreviousState == FALSE)) - { - BOOL nPreviousState = FALSE; - DPRINT("Keyboard and Mouse TimeOut Starting Screen Saver ...\n"); - DPRINT(" %I64d Keyboard Timeout Value\n",DiffTimeKeyboard.QuadPart); - DPRINT(" %I64d Mouse Timeout Value \n",DiffTimeMouse.QuadPart); - DPRINT(" %I64d TimeOut \n",DiffTimeMouse.QuadPart); - - if (FirstTime == FALSE) - { - CSR_API_MESSAGE Request; - CsrInit(); - Request.Type = MAKE_CSR_API(START_SCREEN_SAVER, CSR_GUI); - Request.Data.StartScreenSaver.Start = TRUE; - co_CsrNotifyScreenSaver(&Request ); - - IntSystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0); - } - else - { - FirstTime = FALSE; - } - } - - if ( (DiffTimeMouse.QuadPart < Timeout.QuadPart) && - (DiffTimeKeyboard.QuadPart < Timeout.QuadPart) && - (nPreviousState == TRUE)) - { - IntSystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0); - } - - - } - DPRINT("Screen Saver auto start Thread Stopped...\n"); - } -} VOID STDCALL @@ -325,9 +275,8 @@ MouseThreadMain(PVOID StartContext) DPRINT1("Win32K: Failed to read from mouse.\n"); return; //(Status); } - DPRINT("MouseEvent\n"); - - KeQuerySystemTime(&MouseInputCurrentTime); + DPRINT("MouseEvent\n"); + IntLastInputTick(TRUE); UserEnterExclusive(); @@ -637,7 +586,8 @@ KeyboardThreadMain(PVOID StartContext) return; //(Status); } - KeQuerySystemTime(&KeyboardInputCurrentTime); + /* Set LastInputTick */ + IntLastInputTick(TRUE); /* Update modifier state */ fsModifiers = IntKeyboardGetModifiers(&KeyInput); @@ -917,18 +867,6 @@ InitInputImpl(VOID) DPRINT1("Win32K: Failed to create mouse thread.\n"); } - Status = PsCreateSystemThread(&ScreenSaverThreadHandle, - THREAD_ALL_ACCESS, - NULL, - NULL, - &ScreenSaverThreadId, - ScreenSaverThreadMain, - NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Win32K: Failed to create ScreenSaver auto start thread.\n"); - } - return STATUS_SUCCESS; } diff --git a/reactos/tools/nci/w32ksvc.db b/reactos/tools/nci/w32ksvc.db index 823f9edf195..0f27f3fb5aa 100644 --- a/reactos/tools/nci/w32ksvc.db +++ b/reactos/tools/nci/w32ksvc.db @@ -390,6 +390,7 @@ NtUserGetKeyboardLayoutName 1 NtUserGetKeyboardState 1 NtUserGetKeyNameText 3 NtUserGetKeyState 1 +NtUserGetLastInputInfo 1 NtUserGetListBoxInfo 1 NtUserGetMenuBarInfo 4 NtUserGetMenuIndex 2