-revert some prev. changes (using wthread instead of queue) bcause filip didnt like it
-misc queue/thread-input changes
Modified: branches/win32k rewrite attempt/win32k/include/caret.h
Modified: branches/win32k rewrite attempt/win32k/include/desktop.h
Modified: branches/win32k rewrite attempt/win32k/include/focus.h
Modified: branches/win32k rewrite attempt/win32k/include/input.h
Modified: branches/win32k rewrite attempt/win32k/include/msgqueue.h
Modified: branches/win32k rewrite attempt/win32k/include/ntuser.h
Modified: branches/win32k rewrite attempt/win32k/include/timer.h
Modified: branches/win32k rewrite attempt/win32k/include/userfuncs.h
Modified: branches/win32k rewrite attempt/win32k/include/win32.h
Modified: branches/win32k rewrite attempt/win32k/include/win32k.h
Modified: branches/win32k rewrite attempt/win32k/include/window.h
Modified: branches/win32k rewrite attempt/win32k/ntuser/accelerator.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/caret.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/class.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/desktop.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/focus.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/guicheck.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/hook.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/hotkey.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/input.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/keyboard.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/menu.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/message.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/misc.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/msgqueue.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/ntuser.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/painting.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/scrollbar.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/stubs.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/timer.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/vis.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/windc.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/window.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/winpos.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/winsta.c

Modified: branches/win32k rewrite attempt/win32k/include/caret.h
--- branches/win32k rewrite attempt/win32k/include/caret.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/caret.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -3,16 +3,8 @@
 
 #define IDCARETTIMER (0xffff)
 
-BOOL FASTCALL
-UserDestroyCaret(PW32THREAD Win32Thread);
 
-BOOL FASTCALL
-UserSetCaretBlinkTime(UINT uMSeconds);
 
-
-VOID FASTCALL
-UserDrawCaret(HWND hWnd);
-
 #endif /* _WIN32K_CARET_H */
 
 /* EOF */

Modified: branches/win32k rewrite attempt/win32k/include/desktop.h
--- branches/win32k rewrite attempt/win32k/include/desktop.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/desktop.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -16,7 +16,7 @@
     /* Pointer to the associated window station. */
     struct _WINSTATION_OBJECT *WindowStation;
     /* Pointer to the active queue. */
-    PW32THREAD ActiveWThread;
+    PUSER_MESSAGE_QUEUE ActiveQueue;
     /* Rectangle of the work area */
     RECT WorkArea;
     /* Handle of the desktop window. */
@@ -40,78 +40,7 @@
   HWND hWnd;
 } SHELL_HOOK_WINDOW, *PSHELL_HOOK_WINDOW;
 
-NTSTATUS FASTCALL
-InitDesktopImpl(VOID);
 
-NTSTATUS FASTCALL
-CleanupDesktopImpl(VOID);
-                       
-NTSTATUS STDCALL
-IntDesktopObjectCreate(PVOID ObjectBody,
-		       PVOID Parent,
-		       PWSTR RemainingPath,
-		       struct _OBJECT_ATTRIBUTES* ObjectAttributes);
-
-VOID STDCALL
-IntDesktopObjectDelete(PVOID DeletedObject);
-
-VOID FASTCALL
-IntGetDesktopWorkArea(PDESKTOP_OBJECT Desktop, PRECT Rect);
-
-LRESULT CALLBACK
-IntDesktopWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
-HDC FASTCALL
-IntGetScreenDC(VOID);
-
-PWINDOW_OBJECT FASTCALL
-UserGetDesktopWindow (VOID);
-
-HWND FASTCALL
-IntGetCurrentThreadDesktopWindow(VOID);
-
-PW32THREAD FASTCALL
-UserGetFocusThread(VOID);
-
-VOID FASTCALL
-IntSetFocusThread(PW32THREAD Thread);
-
-PDESKTOP_OBJECT FASTCALL
-UserGetActiveDesktop(VOID);
-
-NTSTATUS FASTCALL
-UserShowDesktop(PDESKTOP_OBJECT Desktop, ULONG Width, ULONG Height);
-
-NTSTATUS FASTCALL
-IntHideDesktop(PDESKTOP_OBJECT Desktop);
-
-HDESK FASTCALL
-IntGetDesktopObjectHandle(PDESKTOP_OBJECT DesktopObject);
-
-NTSTATUS FASTCALL
-IntValidateDesktopHandle(
-   HDESK Desktop,
-   KPROCESSOR_MODE AccessMode,
-   ACCESS_MASK DesiredAccess,
-   PDESKTOP_OBJECT *Object);
-
-NTSTATUS FASTCALL
-IntParseDesktopPath(PEPROCESS Process,
-                    PUNICODE_STRING DesktopPath,
-                    HWINSTA *hWinSta,
-                    HDESK *hDesktop);
-
-BOOL FASTCALL
-IntDesktopUpdatePerUserSettings(BOOL bEnable);
-
-BOOL IntRegisterShellHookWindow(HWND hWnd);
-BOOL IntDeRegisterShellHookWindow(HWND hWnd);
-
-VOID IntShellHookNotify(WPARAM Message, LPARAM lParam);
-
-#define IntIsActiveDesktop(Desktop) \
-  ((Desktop)->WindowStation->ActiveDesktop == (Desktop))
-
 #endif /* _WIN32K_DESKTOP_H */
 
 /* EOF */

Modified: branches/win32k rewrite attempt/win32k/include/focus.h
--- branches/win32k rewrite attempt/win32k/include/focus.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/focus.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -1,27 +1,5 @@
 #ifndef _WIN32K_FOCUS_H
 #define _WIN32K_FOCUS_H
 
-/*
- * These functions take the window handles from current message queue.
- */
-PWINDOW_OBJECT FASTCALL
-UserGetCaptureWindow();
-PWINDOW_OBJECT FASTCALL
-UserGetFocusWindow();
 
-
-
-/*
- * These functions take the window handles from current thread queue.
- */
-PWINDOW_OBJECT FASTCALL
-UserGetThreadFocusWindow();
-
-BOOL FASTCALL
-IntMouseActivateWindow(PWINDOW_OBJECT Window);
-BOOL FASTCALL
-IntSetForegroundWindow(PWINDOW_OBJECT Window);
-PWINDOW_OBJECT FASTCALL
-IntSetActiveWindow(PWINDOW_OBJECT Window);
-
 #endif /* _WIN32K_FOCUS_H */

Modified: branches/win32k rewrite attempt/win32k/include/input.h
--- branches/win32k rewrite attempt/win32k/include/input.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/input.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -1,21 +1,5 @@
 #ifndef _WIN32K_INPUT_H
 #define _WIN32K_INPUT_H
 
-#include <internal/kbd.h>
 
-NTSTATUS FASTCALL
-InitInputImpl(VOID);
-NTSTATUS FASTCALL
-InitKeyboardImpl(VOID);
-PW32THREAD W32kGetPrimitiveWThread(VOID);
-VOID W32kUnregisterPrimitiveWThread(VOID);
-PKBDTABLES W32kGetDefaultKeyLayout(VOID);
-VOID FASTCALL W32kKeyProcessMessage(LPMSG Msg, PKBDTABLES KeyLayout, BYTE Prefix);
-BOOL FASTCALL IntBlockInput(PW32THREAD W32Thread, BOOL BlockIt);
-BOOL FASTCALL IntMouseInput(MOUSEINPUT *mi);
-BOOL FASTCALL IntKeyboardInput(KEYBDINPUT *ki);
-
-#define ThreadHasInputAccess(W32Thread) \
-  (TRUE)
-
 #endif /* _WIN32K_INPUT_H */

Modified: branches/win32k rewrite attempt/win32k/include/msgqueue.h
--- branches/win32k rewrite attempt/win32k/include/msgqueue.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/msgqueue.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -1,7 +1,6 @@
 #ifndef _WIN32K_MSGQUEUE_H
 #define _WIN32K_MSGQUEUE_H
 
-#include "caret.h"
 #include "hook.h"
 
 #define MSQ_HUNG        5000
@@ -54,26 +53,40 @@
        int                    caret_state;   /* caret on/off state */
        struct list            msg_list;      /* list of hardware messages */
        unsigned char          keystate[256]; /* state of each key */
+       
+       typedef struct _THRDCARETINFO
+       {
+         HWND hWnd;
+         HBITMAP Bitmap;
+         POINT Pos;
+         SIZE Size;
+         BYTE Visible;
+         BYTE Showing;
+} THRDCARETINFO, *PTHRDCARETINFO;
 #endif
 
+  LONG RefCount;
   /* Current window with focus (ie. receives keyboard input) for this queue. */
-  HWND FocusWindow;
+  HWND hFocusWindow;
   /* Current capture window for this queue. */
-  HWND CaptureWindow;
+  HWND hCaptureWindow;
   /* Current active window for this queue. */
-  HWND ActiveWindow;
+  HWND hActiveWindow;
   /* Current menu owner window for this queue */
-  HWND MenuOwner;
+  HWND hMenuOwner;
   /* Current move/size window for this queue */
-  HWND MoveSize;
+  HWND hMoveSize;
  /* Caret information for this queue */
   THRDCARETINFO CaretInfo;
+  /* Desktop that the message queue is attached to */
+  struct _DESKTOP_OBJECT* Desktop;
    
 } USER_THREAD_INPUT, *PUSER_THREAD_INPUT;
 
 
 typedef struct _USER_MESSAGE_QUEUE
 {
+  PUSER_THREAD_INPUT Input;
   /* Queue of messages sent to the queue. */
   LIST_ENTRY SentMessagesListHead;
   /* Queue of messages posted to the queue. */
@@ -109,11 +122,12 @@
   PHOOKTABLE Hooks;
 
   /* queue state tracking */
-  WORD WakeMask;
-  WORD WakeBits;
-//  WORD QueueBits;
-  WORD ChangedBits;
-  WORD ChangedMask;
+  /* wake mask for current queue content */
+  WORD QueueMask;
+  WORD QueueBits;
+  /* wake mask for queue content changes */ 
+  WORD ChangesMask;
+  WORD ChangesBits;  
 
   /* extra message information */
   LPARAM ExtraInfo;
@@ -121,8 +135,6 @@
   LIST_ENTRY DispatchingMessagesHead;
   /* messages that are currently dispatched by this message queue, required for cleanup */
   LIST_ENTRY LocalDispatchingMessagesHead;
-  /* Desktop that the message queue is attached to */
-  struct _DESKTOP_OBJECT *Desktop;
   
   
 } USER_MESSAGE_QUEUE, *PUSER_MESSAGE_QUEUE;

Modified: branches/win32k rewrite attempt/win32k/include/ntuser.h
--- branches/win32k rewrite attempt/win32k/include/ntuser.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/ntuser.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -41,9 +41,13 @@
 #define UserEnterExclusive() \
 { \
   /* DPRINT1("try lock, %s, %i (%i)\n",__FILE__,__LINE__, _locked);*/ \
-   ASSERT(UserLock.Owner != KeGetCurrentThread()); \
+   if (UserLock.Owner == KeGetCurrentThread()){ \
+      DPRINT1("file %s, line %i\n",_file, _line); \
+      ASSERT(FALSE); \
+   }  \
    UUserEnterExclusive(); \
    ASSERT(InterlockedIncrement(&_locked) == 1 /*> 0*/); \
+   _file = __FILE__; _line = __LINE__; \
   /* DPRINT("got lock, %s, %i (%i)\n",__FILE__,__LINE__, _locked);*/ \
 }
 
@@ -51,7 +55,11 @@
 { \
    ASSERT(InterlockedDecrement(&_locked) == 0/*>= 0*/); \
    /*DPRINT("unlock, %s, %i (%i)\n",__FILE__,__LINE__, _locked);*/ \
-   ASSERT(UserLock.Owner == KeGetCurrentThread()); \
+   if (UserLock.Owner != KeGetCurrentThread()) { \
+     DPRINT1("file %s, line %i\n",_file, _line); \
+     ASSERT(FALSE); \
+   } \
+   _file = __FILE__; _line = __LINE__; \
    UUserLeave(); \
 }
  

Modified: branches/win32k rewrite attempt/win32k/include/timer.h
--- branches/win32k rewrite attempt/win32k/include/timer.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/timer.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -7,7 +7,7 @@
    LIST_ENTRY     ListEntry;
    LARGE_INTEGER  ExpiryTime;
    PWINDOW_OBJECT  Wnd;
-   PW32THREAD      WThread;
+   PUSER_MESSAGE_QUEUE Queue;
    UINT_PTR       IDEvent;
    UINT           Period;
    TIMERPROC      TimerFunc;

Modified: branches/win32k rewrite attempt/win32k/include/userfuncs.h
--- branches/win32k rewrite attempt/win32k/include/userfuncs.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/userfuncs.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -1,6 +1,9 @@
 #ifndef _WIN32K_USERFUNCS_H
 #define _WIN32K_USERFUNCS_H
 
+
+#define QUEUE_2_WTHREAD(queue) CONTAINING_RECORD(queue, W32THREAD, Queue)
+
 /*************** KEYBOARD.C ******************/
 
 DWORD FASTCALL 
@@ -31,9 +34,80 @@
 
 inline PDESKTOP_OBJECT FASTCALL UserGetCurrentDesktop();
 
+NTSTATUS FASTCALL
+InitDesktopImpl(VOID);
 
+NTSTATUS FASTCALL
+CleanupDesktopImpl(VOID);
+                       
+NTSTATUS STDCALL
+IntDesktopObjectCreate(PVOID ObjectBody,
+             PVOID Parent,
+             PWSTR RemainingPath,
+             struct _OBJECT_ATTRIBUTES* ObjectAttributes);
 
+VOID STDCALL
+IntDesktopObjectDelete(PVOID DeletedObject);
 
+VOID FASTCALL
+IntGetDesktopWorkArea(PDESKTOP_OBJECT Desktop, PRECT Rect);
+
+LRESULT CALLBACK
+IntDesktopWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+HDC FASTCALL
+IntGetScreenDC(VOID);
+
+PWINDOW_OBJECT FASTCALL
+UserGetDesktopWindow (VOID);
+
+HWND FASTCALL
+IntGetCurrentThreadDesktopWindow(VOID);
+
+PUSER_MESSAGE_QUEUE FASTCALL
+UserGetFocusQueue(VOID);
+
+VOID FASTCALL
+IntSetFocusQueue(PUSER_MESSAGE_QUEUE Thread);
+
+PDESKTOP_OBJECT FASTCALL
+UserGetActiveDesktop(VOID);
+
+NTSTATUS FASTCALL
+UserShowDesktop(PDESKTOP_OBJECT Desktop, ULONG Width, ULONG Height);
+
+NTSTATUS FASTCALL
+IntHideDesktop(PDESKTOP_OBJECT Desktop);
+
+HDESK FASTCALL
+IntGetDesktopObjectHandle(PDESKTOP_OBJECT DesktopObject);
+
+NTSTATUS FASTCALL
+IntValidateDesktopHandle(
+   HDESK Desktop,
+   KPROCESSOR_MODE AccessMode,
+   ACCESS_MASK DesiredAccess,
+   PDESKTOP_OBJECT *Object);
+
+NTSTATUS FASTCALL
+IntParseDesktopPath(PEPROCESS Process,
+                    PUNICODE_STRING DesktopPath,
+                    HWINSTA *hWinSta,
+                    HDESK *hDesktop);
+
+BOOL FASTCALL
+IntDesktopUpdatePerUserSettings(BOOL bEnable);
+
+BOOL IntRegisterShellHookWindow(HWND hWnd);
+BOOL IntDeRegisterShellHookWindow(HWND hWnd);
+
+VOID IntShellHookNotify(WPARAM Message, LPARAM lParam);
+
+#define IntIsActiveDesktop(Desktop) \
+  ((Desktop)->WindowStation->ActiveDesktop == (Desktop))
+
+
+
 /************************* ACCELERATOR.C ***********************/
 
 inline PACCELERATOR_TABLE FASTCALL UserGetAccelObject(HACCEL hCursor);
@@ -46,13 +120,56 @@
 ULONG FASTCALL 
 UserGetSystemMetrics(ULONG Index);
 
-/* input.h */
+/******************** INPUT.C ********************************/
+
+#include <internal/kbd.h>
+
+BOOLEAN attach_thread_input( PW32THREAD thread_from, PW32THREAD thread_to );
+PUSER_THREAD_INPUT create_thread_input( PW32THREAD thread );
+inline VOID FASTCALL UserDereferenceInput(PUSER_THREAD_INPUT Input);
+
+NTSTATUS FASTCALL
+InitInputImpl(VOID);
+NTSTATUS FASTCALL
+InitKeyboardImpl(VOID);
+PUSER_MESSAGE_QUEUE W32kGetPrimitiveQueue(VOID);
+VOID W32kUnregisterPrimitiveQueue(VOID);
+PKBDTABLES W32kGetDefaultKeyLayout(VOID);
+VOID FASTCALL W32kKeyProcessMessage(LPMSG Msg, PKBDTABLES KeyLayout, BYTE Prefix);
+BOOL FASTCALL IntBlockInput(PW32THREAD W32Thread, BOOL BlockIt);
+BOOL FASTCALL IntMouseInput(MOUSEINPUT *mi);
+BOOL FASTCALL IntKeyboardInput(KEYBDINPUT *ki);
+
+#define ThreadHasInputAccess(W32Thread) \
+  (TRUE)
+
 NTSTATUS FASTCALL 
 UserAcquireOrReleaseInputOwnership(BOOLEAN Release);
 
 /******************** FOCUS.C ********************************/
 
+/*
+ * These functions take the window handles from current message queue.
+ */
 PWINDOW_OBJECT FASTCALL
+UserGetCaptureWindow();
+PWINDOW_OBJECT FASTCALL
+UserGetFocusWindow();
+
+/*
+ * These functions take the window handles from current thread queue.
+ */
+PWINDOW_OBJECT FASTCALL
+UserGetThreadFocusWindow();
+
+BOOL FASTCALL
+IntMouseActivateWindow(PWINDOW_OBJECT Window);
+BOOL FASTCALL
+IntSetForegroundWindow(PWINDOW_OBJECT Window);
+PWINDOW_OBJECT FASTCALL
+IntSetActiveWindow(PWINDOW_OBJECT Window);
+
+PWINDOW_OBJECT FASTCALL
 UserGetForegroundWindow(VOID);
 
 PWINDOW_OBJECT FASTCALL
@@ -171,7 +288,15 @@
 BOOL FASTCALL
 UserSwitchCaretShowing(PTHRDCARETINFO Info);
 
+BOOL FASTCALL
+UserDestroyCaret(PW32THREAD Win32Thread);
 
+BOOL FASTCALL
+UserSetCaretBlinkTime(UINT uMSeconds);
+
+VOID FASTCALL
+UserDrawCaret(HWND hWnd);
+
 /************************* WINPOS.C ****************************/
 
 
@@ -265,7 +390,6 @@
 HWND FASTCALL
 MsqSetStateWindow(PUSER_THREAD_INPUT Input, ULONG Type, HWND hWnd);
 
-inline PUSER_THREAD_INPUT FASTCALL UserGetCurrentInput();
 
 VOID FASTCALL 
 MsqCleanupWindow(PWINDOW_OBJECT pWindow);
@@ -281,7 +405,7 @@
 
 PTIMER_ENTRY FASTCALL
 UserFindExpiredTimer(   
-   PW32THREAD W32Thread,
+   PUSER_MESSAGE_QUEUE MessageQueue,
    PWINDOW_OBJECT Wnd OPTIONAL, 
    UINT MsgFilterMin, 
    UINT MsgFilterMax,
@@ -407,7 +531,7 @@
 MsqKillTimer(PUSER_MESSAGE_QUEUE MessageQueue, HWND Wnd,
              UINT_PTR IDEvent, UINT Msg);
 BOOLEAN FASTCALL
-MsqGetTimerMessage(PW32THREAD W32Thread,
+MsqGetTimerMessage(PUSER_MESSAGE_QUEUE Queue,
                    HWND WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
                    MSG *Msg, BOOLEAN Restart);
 BOOLEAN FASTCALL
@@ -451,8 +575,7 @@
 UserGetWindowDC(PWINDOW_OBJECT Wnd);
 
 /* div */
-#define UserGetCurrentQueue() \
-((PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->Queue)
+#define UserGetCurrentQueue() (&PsGetWin32Thread()->Queue)
 
 
 

Modified: branches/win32k rewrite attempt/win32k/include/win32.h
--- branches/win32k rewrite attempt/win32k/include/win32.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/win32.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -5,8 +5,7 @@
 
 typedef struct _W32THREAD
 {
-  struct _USER_MESSAGE_QUEUE* Queue;
-  struct _USER_THREAD_INPUT* Input;
+  USER_MESSAGE_QUEUE Queue;
   LIST_ENTRY WindowListHead;
   LIST_ENTRY W32CallbackListHead;
   struct _KBDTABLES* KeyboardLayout;

Modified: branches/win32k rewrite attempt/win32k/include/win32k.h
--- branches/win32k rewrite attempt/win32k/include/win32k.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/win32k.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -9,6 +9,7 @@
 /* INCLUDES ******************************************************************/
 
 /* Internal Win32k Headers */
+#include <include/msgqueue.h>
 #include <include/win32.h>
 #include <include/ssec.h>
 #include <include/accelerator.h>
@@ -36,7 +37,6 @@
 #include <include/menu.h>
 #include <include/monitor.h>
 #include <include/mouse.h>
-#include <include/msgqueue.h>
 #include <include/object.h>
 #include <include/paint.h>
 #include <include/palette.h>

Modified: branches/win32k rewrite attempt/win32k/include/window.h
--- branches/win32k rewrite attempt/win32k/include/window.h	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/include/window.h	2005-08-15 01:19:24 UTC (rev 17392)
@@ -53,7 +53,7 @@
   /* Position of the window's client area. */
   RECT ClientRect;
   /* Handle for the window. */
-  HANDLE Self;
+  HWND hSelf;
   /* Window flags. */
   ULONG Flags;
   /* Window menu handle or window id */
@@ -74,7 +74,7 @@
   /* Handle to the parent window. */
   struct _WINDOW_OBJECT* ParentWnd;
   /* Handle to the owner window. */
-  HANDLE Owner;
+  HWND hOwner;
   /* DC Entries (DCE) */
   PDCE Dce;
   /* Property list head.*/
@@ -86,8 +86,11 @@
   BOOL Unicode;
   WNDPROC WndProcA;
   WNDPROC WndProcW;
-  /* owner thread */
+  /* owner queue/thread */
+  union {
+  PUSER_MESSAGE_QUEUE Queue;
   PW32THREAD WThread;
+   };
   HWND hWndLastPopup; /* handle to last active popup window (wine doesn't use pointer, for unk. reason)*/
   PINTERNALPOS InternalPos;
   ULONG Status;
@@ -130,7 +133,7 @@
    (WndObj->W32Thread->Thread->Tcb.Win32Thread == W32Thread))
 #endif
 
-#define IntWndBelongsToThread(WndObj, _W32Thread) ((WndObj)->WThread == (_W32Thread))
+#define IntWndBelongsToThread(WndObj, _W32Thread) (QUEUE_2_WTHREAD((WndObj)->Queue) == (_W32Thread))
 
 
 #define IntGetWndThreadId(WndObj) \

Modified: branches/win32k rewrite attempt/win32k/ntuser/accelerator.c
--- branches/win32k rewrite attempt/win32k/ntuser/accelerator.c	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/ntuser/accelerator.c	2005-08-15 01:19:24 UTC (rev 17392)
@@ -273,11 +273,11 @@
          DPRINT("found accel for virt_key %04x (scan %04x)\n",
                 wParam, 0xff & HIWORD(lParam));
 
-         DPRINT("NtUserGetKeyState(VK_SHIFT) = 0x%x\n",
+         DPRINT("UserGetKeyState(VK_SHIFT) = 0x%x\n",
                 UserGetKeyState(VK_SHIFT));
-         DPRINT("NtUserGetKeyState(VK_CONTROL) = 0x%x\n",
+         DPRINT("UserGetKeyState(VK_CONTROL) = 0x%x\n",
                 UserGetKeyState(VK_CONTROL));
-         DPRINT("NtUserGetKeyState(VK_MENU) = 0x%x\n",
+         DPRINT("UserGetKeyState(VK_MENU) = 0x%x\n",
                 UserGetKeyState(VK_MENU));
 
          if (UserGetKeyState(VK_SHIFT) & 0x8000)

Modified: branches/win32k rewrite attempt/win32k/ntuser/caret.c
--- branches/win32k rewrite attempt/win32k/ntuser/caret.c	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/ntuser/caret.c	2005-08-15 01:19:24 UTC (rev 17392)
@@ -43,12 +43,13 @@
    if(!W32Thread)
       return FALSE;
 
-   IntHideCaret(&W32Thread->Input->CaretInfo);
-   W32Thread->Input->CaretInfo.Bitmap = (HBITMAP)0;
-   W32Thread->Input->CaretInfo.hWnd = (HWND)0;
-   W32Thread->Input->CaretInfo.Size.cx = W32Thread->Input->CaretInfo.Size.cy = 0;
-   W32Thread->Input->CaretInfo.Showing = 0;
-   W32Thread->Input->CaretInfo.Visible = 0;
+   IntHideCaret(&W32Thread->Queue.Input->CaretInfo);
+   RtlZeroMemory(&W32Thread->Queue.Input->CaretInfo, sizeof(THRDCARETINFO));
+//   W32Thread->Queue.Input->CaretInfo.Bitmap = (HBITMAP)0;
+//   W32Thread->Queue.Input->CaretInfo.hWnd = (HWND)0;
+//   W32Thread->Queue.Input->CaretInfo.Size.cx = W32Thread->Queue.Input->CaretInfo.Size.cy = 0;
+//   W32Thread->Queue.Input->CaretInfo.Showing = 0;
+//   W32Thread->Queue.Input->CaretInfo.Visible = 0;
    return TRUE;
 }
 
@@ -165,7 +166,7 @@
 {
    PUSER_THREAD_INPUT Input;
    
-   Input = UserGetCurrentInput();
+   Input = UserGetCurrentQueue()->Input;
 
    if(Input->CaretInfo.hWnd)
    {
@@ -189,7 +190,7 @@
 {
    PUSER_THREAD_INPUT Input;
 
-   Input = UserGetCurrentInput();
+   Input = UserGetCurrentQueue()->Input;
 
    if(Input->CaretInfo.hWnd)
    {
@@ -208,7 +209,7 @@
 {
    PUSER_THREAD_INPUT Input;
 
-   Input = UserGetCurrentInput();
+   Input = UserGetCurrentQueue()->Input;
 
    if(Input->CaretInfo.hWnd && Input->CaretInfo.Visible &&
          Input->CaretInfo.Showing)
@@ -242,13 +243,13 @@
       RETURN(FALSE);
    }
 
-   if(WindowObject->WThread != PsGetWin32Thread())
+   if(WindowObject->Queue != UserGetCurrentQueue())
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       RETURN(FALSE);
    }
 
-   Input = UserGetCurrentInput();
+   Input = UserGetCurrentQueue()->Input;
 
    if (Input->CaretInfo.Visible)
    {
@@ -309,7 +310,7 @@
    DPRINT("Enter NtUserGetCaretPos\n");
    UserEnterExclusive();
 
-   Input = UserGetCurrentInput();
+   Input = UserGetCurrentQueue()->Input;
 
    Status = MmCopyToCaller(lpPoint, &(Input->CaretInfo.Pos), sizeof(POINT));
    if(!NT_SUCCESS(Status))
@@ -333,10 +334,10 @@
    HWND hWnd)
 {
    PWINDOW_OBJECT WindowObject;
-   PUSER_THREAD_INPUT Input;
+   PUSER_MESSAGE_QUEUE Queue;
    DECLARE_RETURN(BOOL);
 
-   DPRINT1("Enter NtUserHideCaret\n");
+   DPRINT("Enter NtUserHideCaret\n");
    UserEnterExclusive();
 
    WindowObject = IntGetWindowObject(hWnd);
@@ -346,33 +347,33 @@
       RETURN(FALSE);
    }
 
-   if(WindowObject->WThread != PsGetWin32Thread())
+   Queue = UserGetCurrentQueue();
+
+   if(WindowObject->Queue != Queue)
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       RETURN(FALSE);
    }
 
-   Input = UserGetCurrentInput();
-
-   if(Input->CaretInfo.hWnd != hWnd)
+   if(Queue->Input->CaretInfo.hWnd != hWnd)
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       RETURN(FALSE);
    }
 
-   if(Input->CaretInfo.Visible)
+   if(Queue->Input->CaretInfo.Visible)
    {
       UserKillTimer(WindowObject, IDCARETTIMER, TRUE);
 
-      IntHideCaret(&Input->CaretInfo);
-      Input->CaretInfo.Visible = 0;
-      Input->CaretInfo.Showing = 0;
+      IntHideCaret(&Queue->Input->CaretInfo);
+      Queue->Input->CaretInfo.Visible = 0;
+      Queue->Input->CaretInfo.Showing = 0;
    }
 
    RETURN(TRUE);
 
 CLEANUP:
-   DPRINT1("Leave NtUserHideCaret, ret=%i\n",_ret_);
+   DPRINT("Leave NtUserHideCaret, ret=%i\n",_ret_);
    UserLeave();
    END_CLEANUP;
 }
@@ -382,32 +383,32 @@
 BOOL FASTCALL
 UserHideCaret(PWINDOW_OBJECT Wnd)
 {
-   PUSER_THREAD_INPUT Input;
-
+   PUSER_MESSAGE_QUEUE Queue;
+   
    ASSERT(Wnd);
 
-   if(Wnd->WThread != PsGetWin32Thread())
+   Queue = UserGetCurrentQueue();
+   
+   if(Wnd->Queue != Queue)
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       return(FALSE);
    }
 
-   Input = UserGetCurrentInput();
-
-   if(Input->CaretInfo.hWnd != GetHwnd(Wnd))
+   if(Queue->Input->CaretInfo.hWnd != GetHwnd(Wnd))
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       return(FALSE);
    }
 
-   if(Input->CaretInfo.Visible)
+   if(Queue->Input->CaretInfo.Visible)
    {
       UserKillTimer(Wnd, IDCARETTIMER, TRUE);
 
       //FIXME: fix IntHideCaret vs. NtHideCaret vs. UserHideCaret mess
-      IntHideCaret(&Input->CaretInfo);
-      Input->CaretInfo.Visible = 0;
-      Input->CaretInfo.Showing = 0;
+      IntHideCaret(&Queue->Input->CaretInfo);
+      Queue->Input->CaretInfo.Visible = 0;
+      Queue->Input->CaretInfo.Showing = 0;
    }
 
    return(TRUE);
@@ -445,30 +446,30 @@
 BOOL FASTCALL
 UserShowCaret(PWINDOW_OBJECT Wnd)
 {
-   PUSER_THREAD_INPUT Input;
+   PUSER_MESSAGE_QUEUE Queue;
 
    ASSERT(Wnd);
 
-   if(Wnd->WThread != PsGetWin32Thread())
+   Queue = UserGetCurrentQueue();
+
+   if(Wnd->Queue != Queue)
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       return(FALSE);
    }
 
-   Input = UserGetCurrentInput();
-
-   if(Input->CaretInfo.hWnd != GetHwnd(Wnd))
+   if(Queue->Input->CaretInfo.hWnd != GetHwnd(Wnd))
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       return(FALSE);
    }
 
-   if(!Input->CaretInfo.Visible)
+   if(!Queue->Input->CaretInfo.Visible)
    {
-      Input->CaretInfo.Visible = 1;
-      if(!Input->CaretInfo.Showing)
+      Queue->Input->CaretInfo.Visible = 1;
+      if(!Queue->Input->CaretInfo.Showing)
       {
-         IntSendMessage(Input->CaretInfo.hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
+         IntSendMessage(Queue->Input->CaretInfo.hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
       }
       UserSetTimer(Wnd, IDCARETTIMER, UserGetCaretBlinkTime(), NULL, TRUE);
    }

Modified: branches/win32k rewrite attempt/win32k/ntuser/class.c
--- branches/win32k rewrite attempt/win32k/ntuser/class.c	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/ntuser/class.c	2005-08-15 01:19:24 UTC (rev 17392)
@@ -430,7 +430,7 @@
 
    DPRINT("Enter NtUserRegisterClassExWOW\n");
    UserEnterExclusive();
-   CHECKPOINT;
+
    if (!lpwcx)
    {
       SetLastWin32Error(ERROR_INVALID_PARAMETER);
@@ -507,7 +507,7 @@
 
    if ((int)Offset >= 0)
    {
-      DPRINT("GetClassLong(%x, %d)\n", WindowObject->Self, Offset);
+      DPRINT("GetClassLong(%x, %d)\n", WindowObject->hSelf, Offset);
       if ((Offset + sizeof(LONG)) > WindowObject->Class->cbClsExtra)
       {
          SetLastWin32Error(ERROR_INVALID_PARAMETER);
@@ -594,7 +594,7 @@
 
    if ((int)Offset >= 0)
    {
-      DPRINT("SetClassLong(%x, %d, %x)\n", WindowObject->Self, Offset, dwNewLong);
+      DPRINT("SetClassLong(%x, %d, %x)\n", WindowObject->hSelf, Offset, dwNewLong);
       if ((Offset + sizeof(LONG)) > WindowObject->Class->cbClsExtra)
       {
          SetLastWin32Error(ERROR_INVALID_PARAMETER);
@@ -625,7 +625,7 @@
 
          if ((!Owner) && (!Parent))
          {
-            IntShellHookNotify(HSHELL_REDRAW, (LPARAM) WindowObject->Self);
+            IntShellHookNotify(HSHELL_REDRAW, (LPARAM) WindowObject->hSelf);
          }
 
          break;

Modified: branches/win32k rewrite attempt/win32k/ntuser/desktop.c
--- branches/win32k rewrite attempt/win32k/ntuser/desktop.c	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/ntuser/desktop.c	2005-08-15 01:19:24 UTC (rev 17392)
@@ -427,8 +427,8 @@
    return Ret;
 }
 
-PW32THREAD FASTCALL
-UserGetFocusThread(VOID)
+PUSER_MESSAGE_QUEUE FASTCALL
+UserGetFocusQueue(VOID)
 {
    PDESKTOP_OBJECT pdo = UserGetActiveDesktop();
    if (!pdo)
@@ -436,43 +436,41 @@
       DPRINT("No active desktop\n");
       return(NULL);
    }
-   return pdo->ActiveWThread;
+   return pdo->ActiveQueue;
 }
 
 VOID FASTCALL
-IntSetFocusThread(PW32THREAD NewThread)
+IntSetFocusQueue(PUSER_MESSAGE_QUEUE NewQueue)
 {
-   PW32THREAD Old;
+   PUSER_MESSAGE_QUEUE OldQueue;
    PDESKTOP_OBJECT pdo = UserGetActiveDesktop();
    if (!pdo)
    {
       DPRINT("No active desktop\n");
       return;
    }
-   if(NewThread)
+   if(NewQueue)
    {
       //FIXME: move to thread?
-      if(NewThread->Queue->Desktop != NULL)
+      if(NewQueue->Input->Desktop != NULL)
       {
          DPRINT("Message Queue already attached to another desktop!\n");
          return;
       }
       
       //IntReferenceMessageQueue(NewQueue);
-      //InterlockedExchange((LONG*)&NewQueue->Desktop, (LONG)pdo);
       
       //FIXME: move to thread?
-      NewThread->Queue->Desktop = pdo;
+      NewQueue->Input->Desktop = pdo;
       
    }
    
-//   Old = (PUSER_MESSAGE_QUEUE)InterlockedExchange((LONG*)&pdo->ActiveMessageQueue, (LONG)NewQueue);
-   Old = pdo->ActiveWThread;
+   OldQueue = pdo->ActiveQueue;
    
-   if (Old)
-      Old->Queue->Desktop = NULL;
+   if (OldQueue)
+      OldQueue->Input->Desktop = NULL;
    
-   pdo->ActiveWThread = NewThread;
+   pdo->ActiveQueue = NewQueue;
    
 //   if(Old != NULL)
 //   {
@@ -870,7 +868,7 @@
    IntGetDesktopWorkArea(DesktopObject, NULL);
 
    /* Initialize some local (to win32k) desktop state. */
-   DesktopObject->ActiveWThread = NULL;
+   DesktopObject->ActiveQueue = NULL;
 
    Status = ObInsertObject(
                (PVOID)DesktopObject,

Modified: branches/win32k rewrite attempt/win32k/ntuser/focus.c
--- branches/win32k rewrite attempt/win32k/ntuser/focus.c	2005-08-15 01:16:58 UTC (rev 17391)
+++ branches/win32k rewrite attempt/win32k/ntuser/focus.c	2005-08-15 01:19:24 UTC (rev 17392)
@@ -27,23 +27,22 @@
 PWINDOW_OBJECT FASTCALL
 UserGetCaptureWindow()
 {
-   PW32THREAD ForegroundW32Thread = UserGetFocusThread();
-   return ForegroundW32Thread ? GetWnd(ForegroundW32Thread->Input->CaptureWindow) : 0;
+   PUSER_MESSAGE_QUEUE ForegroundQueue = UserGetFocusQueue();
+   return ForegroundQueue ? GetWnd(ForegroundQueue->Input->hCaptureWindow) : 0;
 }
 
 PWINDOW_OBJECT FASTCALL
 UserGetFocusWindow()
 {
-   PW32THREAD ForegroundW32Thread = UserGetFocusThread();
-   return ForegroundW32Thread ? GetWnd(ForegroundW32Thread->Input->FocusWindow) : 0;
+   PUSER_MESSAGE_QUEUE ForegroundQueue = UserGetFocusQueue();
+   return ForegroundQueue ? GetWnd(ForegroundQueue->Input->hFocusWindow) : 0;
 }
 
 PWINDOW_OBJECT FASTCALL
 UserGetThreadFocusWindow()
 {
-   PW32THREAD W32Thread;
-   W32Thread = PsGetWin32Thread();
-   return W32Thread ? GetWnd(W32Thread->Input->FocusWindow) : 0;
+   PUSER_MESSAGE_QUEUE Queue = UserGetCurrentQueue();
+   return Queue ? GetWnd(Queue->Input->hFocusWindow) : 0;
 }
 
 VOID FASTCALL
@@ -126,14 +125,14 @@
 
    for(Child = Root->FirstChild; Child; Child = Child->NextSibling)
    {
-      OwnerWnd = IntGetWindowObject(Child->Owner);
+      OwnerWnd = IntGetWindowObject(Child->hOwner);
 
       if(!OwnerWnd)
          continue;
 
       if(OwnerWnd == Owner)
       {
-         Ret = Child->Self;
+         Ret = Child->hSelf;
          return Ret;
       }
    }
@@ -144,11 +143,11 @@
 STATIC BOOL FASTCALL
 IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWindow, BOOL MouseActivate)
 {
-   HWND hWnd = Window->Self;
+   HWND hWnd = Window->hSelf;
    HWND hWndPrev = NULL;
-   HWND hWndFocus = FocusWindow->Self;
+   HWND hWndFocus = FocusWindow->hSelf;
    HWND hWndFocusPrev = NULL;
-   PW32THREAD PrevForegroundW32Thread;
+   PUSER_MESSAGE_QUEUE PrevForegroundQueue;
 
[truncated at 1000 lines; 3274 more skipped]