2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: input.c,v 1.6 2003/05/18 17:16:17 ea Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Window classes
24 * FILE: subsys/win32k/ntuser/class.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
30 /* INCLUDES ******************************************************************/
32 #include <ddk/ntddk.h>
33 #include <win32k/win32k.h>
34 #include <win32k/userobj.h>
35 #include <include/class.h>
36 #include <include/error.h>
37 #include <include/winsta.h>
38 #include <include/msgqueue.h>
39 #include <ddk/ntddmou.h>
40 #include <include/mouse.h>
45 /* GLOBALS *******************************************************************/
47 static HANDLE MouseDeviceHandle
;
48 static HANDLE KeyboardThreadHandle
;
49 static CLIENT_ID KeyboardThreadId
;
50 static HANDLE KeyboardDeviceHandle
;
51 static KEVENT InputThreadsStart
;
52 static BOOLEAN InputThreadsRunning
= FALSE
;
54 /* FUNCTIONS *****************************************************************/
56 NTSTATUS STDCALL STATIC
57 KeyboardThreadMain(PVOID StartContext
)
59 UNICODE_STRING KeyboardDeviceName
;
60 OBJECT_ATTRIBUTES KeyboardObjectAttributes
;
64 RtlInitUnicodeStringFromLiteral(&KeyboardDeviceName
, L
"\\??\\Keyboard");
65 InitializeObjectAttributes(&KeyboardObjectAttributes
,
70 Status
= NtOpenFile(&KeyboardDeviceHandle
,
72 &KeyboardObjectAttributes
,
75 FILE_SYNCHRONOUS_IO_ALERT
);
76 if (!NT_SUCCESS(Status
))
78 DbgPrint("W32K: Failed to open keyboard.\n");
85 * Wait to start input.
87 Status
= KeWaitForSingleObject(&InputThreadsStart
,
93 * Receive and process keyboard input.
95 while (InputThreadsRunning
)
97 KEY_EVENT_RECORD KeyEvent
;
100 Status
= NtReadFile (KeyboardDeviceHandle
,
106 sizeof(KEY_EVENT_RECORD
),
109 if (Status
== STATUS_ALERTED
&& !InputThreadsRunning
)
113 if (!NT_SUCCESS(Status
))
115 DbgPrint("W32K: Failed to read from keyboard.\n");
120 * Post a keyboard message.
122 if (KeyEvent
.bKeyDown
)
124 /* FIXME: Bit 24 indicates if this is an extended key. */
125 lParam
= KeyEvent
.wRepeatCount
|
126 ((KeyEvent
.wVirtualScanCode
<< 16) & 0x00FF0000) | 0x40000000;
127 MsqPostKeyboardMessage(WM_KEYDOWN
, KeyEvent
.wVirtualKeyCode
,
132 /* FIXME: Bit 24 indicates if this is an extended key. */
133 lParam
= KeyEvent
.wRepeatCount
|
134 ((KeyEvent
.wVirtualScanCode
<< 16) & 0x00FF0000) | 0xC0000000;
135 MsqPostKeyboardMessage(WM_KEYUP
, KeyEvent
.wVirtualKeyCode
,
143 NtUserAcquireOrReleaseInputOwnership(BOOLEAN Release
)
145 if (Release
&& InputThreadsRunning
)
147 KeClearEvent(&InputThreadsStart
);
148 InputThreadsRunning
= FALSE
;
149 NtAlertThread(KeyboardThreadHandle
);
151 else if (!Release
&& !InputThreadsRunning
)
153 InputThreadsRunning
= TRUE
;
154 KeSetEvent(&InputThreadsStart
, IO_NO_INCREMENT
, FALSE
);
156 return(STATUS_SUCCESS
);
163 UNICODE_STRING MouseDeviceName
;
164 OBJECT_ATTRIBUTES MouseObjectAttributes
;
165 IO_STATUS_BLOCK Iosb
;
167 PFILE_OBJECT FileObject
;
168 GDI_INFORMATION GdiInfo
;
170 PIO_STACK_LOCATION StackPtr
;
172 KeInitializeEvent(&InputThreadsStart
, NotificationEvent
, FALSE
);
174 Status
= PsCreateSystemThread(&KeyboardThreadHandle
,
181 if (!NT_SUCCESS(Status
))
183 DbgPrint("W32K: Failed to create keyboard thread.\n");
187 * Connect to the mouse class driver.
189 RtlInitUnicodeStringFromLiteral(&MouseDeviceName
, L
"\\??\\MouseClass");
190 InitializeObjectAttributes(&MouseObjectAttributes
,
195 Status
= NtOpenFile(&MouseDeviceHandle
,
197 &MouseObjectAttributes
,
201 if (!NT_SUCCESS(Status
))
203 DbgPrint("W32K: Failed to open mouse.\n");
206 Status
= ObReferenceObjectByHandle(MouseDeviceHandle
,
207 FILE_READ_DATA
| FILE_WRITE_DATA
,
210 (PVOID
*) &FileObject
,
213 if (!NT_SUCCESS(Status
))
215 DbgPrint("W32K: Failed to reference mouse file object.\n");
218 KeInitializeEvent(&IoEvent
, FALSE
, NotificationEvent
);
219 GdiInfo
.CallBack
= MouseGDICallBack
;
220 Irp
= IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_MOUSE_CONNECT
,
221 FileObject
->DeviceObject
,
229 StackPtr
= IoGetNextIrpStackLocation(Irp
);
230 StackPtr
->FileObject
= FileObject
;
231 StackPtr
->DeviceObject
= FileObject
->DeviceObject
;
232 StackPtr
->Parameters
.DeviceIoControl
.InputBufferLength
= sizeof(GdiInfo
);
233 StackPtr
->Parameters
.DeviceIoControl
.OutputBufferLength
= 0;
235 Status
= IoCallDriver(FileObject
->DeviceObject
, Irp
);
236 if (Status
== STATUS_PENDING
)
238 KeWaitForSingleObject(&FileObject
->Event
, Executive
, KernelMode
, FALSE
,
240 Status
= Iosb
.Status
;
242 if (!NT_SUCCESS(Status
))
244 DbgPrint("W32K: Failed to connect to mouse driver.\n");
248 return(STATUS_SUCCESS
);
252 CleanupInputImp(VOID
)
254 return(STATUS_SUCCESS
);