-fix timerbug (abiword splash)
-misc

Somewhat works now (thanks to filip), but closing gui consoles makes ros go 100% cpu
Modified: branches/win32k rewrite attempt/win32k/docs/refs.txt
Modified: branches/win32k rewrite attempt/win32k/include/caret.h
Modified: branches/win32k rewrite attempt/win32k/include/msgqueue.h
Modified: branches/win32k rewrite attempt/win32k/include/userfuncs.h
Modified: branches/win32k rewrite attempt/win32k/include/window.h
Modified: branches/win32k rewrite attempt/win32k/main/dllmain.c
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/clipboard.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/csr.c
Modified: branches/win32k rewrite attempt/win32k/ntuser/cursoricon.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/handle.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/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/monitor.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/prop.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/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/docs/refs.txt
--- branches/win32k rewrite attempt/win32k/docs/refs.txt	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/docs/refs.txt	2005-08-04 16:32:18 UTC (rev 17044)
@@ -4,8 +4,7 @@
 window -> desktop
 window -> class
 
-window -> queue/thread_input ?????????
-thread -> queue/thread_input ?????????
+thread_input -> thread
 
 thread -> process
 process -> winsta
@@ -13,6 +12,10 @@
 desktop -> winsta
 winsta -> session
 
+NOTE: 	Message queue has 1:1 relationship with (w32)thread and need no ref. count.
+      	-If the (w32)thread is destroyed, so is the message queue.
+	-If the (w32)thread exist, so does the message queue.
+	So if you want the queue to hang around, you reference the thread instead.
 
 Above references create following dependencies:
 -----------------------------------------------
@@ -24,3 +27,34 @@
 thread -> desktop -> winsta -> session
 
 process -> winsta -> session
+
+
+
+NtUser/NtGdi/win32k syscalls
+----------------------------
+
+A process automatically establishes a connection to a window station and desktop
+when it first calls a USER32 or GDI32 function (other than the window station or 
+desktop functions). The process also get a Win32Proccess.
+
+A thread is automatically assigned a desktop when it first calls a USER32 or GDI32
+function (other than the window station or desktop functions). The thread also get
+a Win32Thread, a message queue and a thread input.  
+
+This means that when you are in a win32k syscall function (other than the window station
+or desktop functions) you can be 100% sure that the following exists:
+-the process WinSta
+-the win32process
+-the win32thread
+-the thread message queue
+-the thread input
+-the thread desktop
+-the process desktop (if there is such a thing)
+
+
+There is no need to validate any of these values, because they MUST EXIST!
+
+					!!!!!NOTE!!!!
+Reactos is currently wrong on the thread desktop, process desktop and process WinSta,
+since they can be NULL!!
+

Modified: branches/win32k rewrite attempt/win32k/include/caret.h
--- branches/win32k rewrite attempt/win32k/include/caret.h	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/include/caret.h	2005-08-04 16:32:18 UTC (rev 17044)
@@ -9,8 +9,6 @@
 BOOL FASTCALL
 UserSetCaretBlinkTime(UINT uMSeconds);
 
-BOOL FASTCALL
-UserSwitchCaretShowing(PVOID Info);
 
 VOID FASTCALL
 UserDrawCaret(HWND hWnd);

Modified: branches/win32k rewrite attempt/win32k/include/msgqueue.h
--- branches/win32k rewrite attempt/win32k/include/msgqueue.h	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/include/msgqueue.h	2005-08-04 16:32:18 UTC (rev 17044)
@@ -39,8 +39,39 @@
   LIST_ENTRY ListEntry;
 } USER_SENT_MESSAGE_NOTIFY, *PUSER_SENT_MESSAGE_NOTIFY;
 
+typedef struct _USER_THREAD_INPUT
+{
+#if 0   
+       struct desktop        *desktop;       /* desktop that this thread 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 */
+       struct list            msg_list;      /* list of hardware messages */
+       unsigned char          keystate[256]; /* state of each key */
+#endif
 
+  /* Current window with focus (ie. receives keyboard input) for this queue. */
+  HWND FocusWindow;
+  /* Current capture window for this queue. */
+  HWND CaptureWindow;
+  /* Current active window for this queue. */
+  HWND ActiveWindow;
+  /* Current menu owner window for this queue */
+  HWND MenuOwner;
+  /* Current move/size window for this queue */
+  HWND MoveSize;
+ /* Caret information for this queue */
+  THRDCARETINFO CaretInfo;
+   
+} USER_THREAD_INPUT, *PUSER_THREAD_INPUT;
 
+
 typedef struct _USER_MESSAGE_QUEUE
 {
   /* Reference counter, only access this variable with interlocked functions! */
@@ -73,24 +104,12 @@
   HANDLE NewMessagesHandle;
   /* Last time PeekMessage() was called. */
   ULONG LastMsgRead;
-  /* Current window with focus (ie. receives keyboard input) for this queue. */
-  HWND FocusWindow;
   /* True if a window needs painting. */
   BOOLEAN PaintPosted;
   /* Count of paints pending. */
   LONG PaintCount;
-  /* Current active window for this queue. */
-  HWND ActiveWindow;
-  /* Current capture window for this queue. */
-  HWND CaptureWindow;
-  /* Current move/size window for this queue */
-  HWND MoveSize;
-  /* Current menu owner window for this queue */
-  HWND MenuOwner;
   /* Identifes the menu state */
   BYTE MenuState;
-  /* Caret information for this queue */
-  PTHRDCARETINFO CaretInfo;
 
   /* Window hooks */
   PHOOKTABLE Hooks;
@@ -104,14 +123,15 @@
 
   /* extra message information */
   LPARAM ExtraInfo;
-
   /* messages that are currently dispatched by other threads */
   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;
+  
+  PUSER_THREAD_INPUT Input;
+  
 } USER_MESSAGE_QUEUE, *PUSER_MESSAGE_QUEUE;
 
 BOOL FASTCALL
@@ -144,8 +164,6 @@
 MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue);
 PUSER_MESSAGE_QUEUE FASTCALL
 MsqCreateMessageQueue(struct _ETHREAD *Thread);
-VOID FASTCALL
-MsqDestroyMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue);
 PUSER_MESSAGE_QUEUE FASTCALL
 MsqGetHardwareMessageQueue(VOID);
 NTSTATUS FASTCALL
@@ -198,8 +216,6 @@
 MsqInsertSystemMessage(MSG* Msg);
 BOOL FASTCALL
 MsqIsDblClk(LPMSG Msg, BOOL Remove);
-HWND FASTCALL
-MsqSetStateWindow(PUSER_MESSAGE_QUEUE MessageQueue, ULONG Type, HWND hWnd);
 
 inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue );
 inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
@@ -223,8 +239,6 @@
 #define IntReferenceMessageQueue(MsgQueue) \
   InterlockedIncrement(&(MsgQueue)->References)
 
-VOID FASTCALL
-IntDereferenceMessageQueue(PUSER_MESSAGE_QUEUE MsgQueue);
 
 
 #define IS_BTN_MESSAGE(message,code) \

Modified: branches/win32k rewrite attempt/win32k/include/userfuncs.h
--- branches/win32k rewrite attempt/win32k/include/userfuncs.h	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/include/userfuncs.h	2005-08-04 16:32:18 UTC (rev 17044)
@@ -111,6 +111,10 @@
 BOOL FASTCALL
 UserHideCaret(PWINDOW_OBJECT Wnd);
 
+BOOL FASTCALL
+UserSwitchCaretShowing(PTHRDCARETINFO Info);
+
+
 /************************* WINPOS.C ****************************/
 
 
@@ -188,10 +192,21 @@
 PMONITOR_OBJECT UserGetMonitorObject(HANDLE hCursor);
 
 
-/* msgqueue.c */
+/******************* MSGQUEUE.C ********************/
 
+VOID FASTCALL
+UserDereferenceQueue(PUSER_MESSAGE_QUEUE MsgQueue);
+
+VOID FASTCALL
+MsqDestroyMessageQueue(PW32THREAD WThread);
+
+HWND FASTCALL
+MsqSetStateWindow(PUSER_THREAD_INPUT Input, ULONG Type, HWND hWnd);
+
+inline PUSER_THREAD_INPUT FASTCALL UserGetCurrentInput();
+
 VOID FASTCALL 
-MsqRemoveWindowMessagesFromQueue(PWINDOW_OBJECT pWindow);
+MsqCleanupWindow(PWINDOW_OBJECT pWindow);
 
 inline BOOL FASTCALL
 UserMessageFilter(UINT Message, UINT FilterMin, UINT FilterMax);
@@ -218,6 +233,16 @@
    UINT Message
    );
 
+/**************************** NTUSER.C ************************/
+
+inline PVOID FASTCALL UserAlloc(SIZE_T bytes);
+inline PVOID FASTCALL UserAllocTag(SIZE_T bytes, ULONG tag);
+inline PVOID FASTCALL UserAllocZero(SIZE_T bytes);
+inline PVOID FASTCALL UserAllocZeroTag(SIZE_T bytes, ULONG tag);
+inline VOID FASTCALL UserFree(PVOID mem);
+
+
+
 /* windc.c */
 
 HDC FASTCALL

Modified: branches/win32k rewrite attempt/win32k/include/window.h
--- branches/win32k rewrite attempt/win32k/include/window.h	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/include/window.h	2005-08-04 16:32:18 UTC (rev 17044)
@@ -64,7 +64,7 @@
   /* Handle of the window region. */
   HANDLE WindowRegion;
   /* Lock to be held when manipulating (NC)UpdateRegion */
-  FAST_MUTEX UpdateLock;
+ // FAST_MUTEX UpdateLock;
   /* Pointer to the owning thread's message queue. */
   PUSER_MESSAGE_QUEUE MessageQueue;
   struct _WINDOW_OBJECT* FirstChild;

Modified: branches/win32k rewrite attempt/win32k/main/dllmain.c
--- branches/win32k rewrite attempt/win32k/main/dllmain.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/main/dllmain.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -47,6 +47,8 @@
     DPRINT("Enter Win32kProcessCallback\n");
     UserEnterExclusive();
     
+CHECKPOINT1;
+
     /* Get the Win32 Process */
     Win32Process = PsGetProcessWin32Process(Process);
     
@@ -71,7 +73,7 @@
       DPRINT("Creating W32 process PID:%d at IRQ level: %lu\n", Process->UniqueProcessId, KeGetCurrentIrql());
 
       InitializeListHead(&Win32Process->ClassListHead);
-      ExInitializeFastMutex(&Win32Process->ClassListLock);
+//      ExInitializeFastMutex(&Win32Process->ClassListLock);
 
       InitializeListHead(&Win32Process->MenuListHead);
       ExInitializeFastMutex(&Win32Process->MenuListLock);
@@ -139,6 +141,8 @@
     DPRINT("Enter Win32kThreadCallback\n");
     UserEnterExclusive();
 
+CHECKPOINT1;
+
     Process = Thread->ThreadsProcess;
     
     /* Get the Win32 Thread */
@@ -229,7 +233,6 @@
       Win32Thread->KeyboardLayout = W32kGetDefaultKeyLayout();
       Win32Thread->MessagePumpHookValue = 0;
       InitializeListHead(&Win32Thread->WindowListHead);
-      ExInitializeFastMutex(&Win32Thread->WindowListLock);
       InitializeListHead(&Win32Thread->W32CallbackListHead);
     }
   else
@@ -238,15 +241,26 @@
 
       Win32Thread->IsExiting = TRUE;
       HOOK_DestroyThreadHooks(Thread);
+CHECKPOINT1;     
       UnregisterThreadHotKeys(Thread);
+CHECKPOINT1;      
       DestroyThreadWindows(Thread);
+CHECKPOINT1;      
       IntBlockInput(Win32Thread, FALSE);
-      MsqDestroyMessageQueue(Win32Thread->MessageQueue);
+CHECKPOINT1;
+      /* all windows for this thread must de totally destroyed at this point. */
+      ASSERT(IsListEmpty(&Win32Thread->WindowListHead));
+      MsqDestroyMessageQueue(Win32Thread);
+CHECKPOINT1;      
       IntCleanupThreadCallbacks(Win32Thread);
+CHECKPOINT1;      
+       /* FIXME: having a thresd desktop is mandatory!! */
       if(Win32Thread->Desktop != NULL)
       {
+         CHECKPOINT1;
         ObDereferenceObject(Win32Thread->Desktop);
       }
+CHECKPOINT1;      
     }
 
   RETURN( STATUS_SUCCESS);
@@ -316,6 +330,7 @@
   BOOLEAN Result;
   W32_CALLOUT_DATA CalloutData;
 
+CHECKPOINT1;
   /*
    * Register user mode call interface
    * (system service table index = 1)
@@ -330,7 +345,7 @@
       DPRINT1("Adding system services failed!\n");
       return STATUS_UNSUCCESSFUL;
     }
-
+CHECKPOINT1;
     /*
      * Register Object Manager Callbacks
      */
@@ -342,14 +357,15 @@
     CalloutData.DesktopDelete = IntDesktopObjectDelete;
     CalloutData.W32ProcessCallout = Win32kProcessCallback;
     CalloutData.W32ThreadCallout = Win32kThreadCallback;
-    
+    CHECKPOINT1;
     /*
      * Register our per-process and per-thread structures.
      */
     PsEstablishWin32Callouts(&CalloutData);
-
+CHECKPOINT1;
   Status = IntUserCreateSharedSectionPool(48 * 1024 * 1024, /* 48 MB by default */
                                           &SessionSharedSectionPool);
+                                          CHECKPOINT1;
   if (!NT_SUCCESS(Status))
   {
     DPRINT1("Failed to initialize the shared section pool: Status 0x%x\n", Status);

Modified: branches/win32k rewrite attempt/win32k/ntuser/accelerator.c
--- branches/win32k rewrite attempt/win32k/ntuser/accelerator.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/accelerator.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -51,7 +51,7 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 /* FUNCTIONS *****************************************************************/
@@ -203,41 +203,36 @@
 
 BOOLEAN
 STDCALL
-NtUserDestroyAcceleratorTable(HACCEL Table)
+NtUserDestroyAcceleratorTable(HACCEL hAccel)
 {
-   PACCELERATOR_TABLE AcceleratorTable;
+   PACCELERATOR_TABLE Accel;
    DECLARE_RETURN(BOOLEAN);
    /* FIXME: If the handle table is from a call to LoadAcceleratorTable, decrement it's
       usage count (and return TRUE).
    FIXME: Destroy only tables created using CreateAcceleratorTable.
     */
 
-   DPRINT("Enter NtUserDestroyAcceleratorTable(Table %x)\n", Table);
+   DPRINT("Enter NtUserDestroyAcceleratorTable(Table %x)\n", Accel);
    UserEnterExclusive();
 
-   //FIXME
-   AcceleratorTable = UserGetAccelObject(Table);
+   Accel = UserGetAccelObject(hAccel);
 
-   if (!AcceleratorTable)
+   if (!Accel)
    {
       SetLastWin32Error(ERROR_INVALID_ACCEL_HANDLE);
       DPRINT1("E2\n");
       RETURN(FALSE);
    }
 
-//   ObmCloseHandle(WindowStation->HandleTable, Table);
-
-   if (AcceleratorTable->Table != NULL)
+   if (Accel->Table != NULL)
    {
-      ExFreePool(AcceleratorTable->Table);
+      ExFreePool(Accel->Table);
    }
 
-//   ObDereferenceObject(WindowStation);
-
    RETURN(TRUE);
 
 CLEANUP:
-   DPRINT("Leave NtUserDestroyAcceleratorTable(Table %x) = %i\n", Table,_ret_);
+   DPRINT("Leave NtUserDestroyAcceleratorTable(Table %x) = %i\n", Accel,_ret_);
    UserLeave();
    END_CLEANUP;
 }
@@ -443,7 +438,6 @@
    HACCEL Table,
    LPMSG Message)
 {
-   PWINSTATION_OBJECT WindowStation;
    PACCELERATOR_TABLE AcceleratorTable;
    ULONG i;
    DECLARE_RETURN(int);
@@ -490,7 +484,6 @@
                                   AcceleratorTable->Table[i].fVirt, AcceleratorTable->Table[i].key,
                                   AcceleratorTable->Table[i].cmd))
       {
-         ObDereferenceObject(WindowStation);
          DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
                 hWnd, Table, Message, 1);
          RETURN(1);

Modified: branches/win32k rewrite attempt/win32k/ntuser/caret.c
--- branches/win32k rewrite attempt/win32k/ntuser/caret.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/caret.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -11,7 +11,7 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 #define MIN_CARETBLINKRATE 100
@@ -35,19 +35,20 @@
 BOOL FASTCALL
 UserDestroyCaret(PW32THREAD Win32Thread /* unused param!!!*/)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_MESSAGE_QUEUE Queue;
 
-   ThreadQueue = UserGetCurrentQueue();
+   Queue = UserGetCurrentQueue();
 
-   if(!ThreadQueue || !ThreadQueue->CaretInfo)
+   //FIXME: can queue be NULL?
+   if(!Queue)
       return FALSE;
 
-   IntHideCaret(ThreadQueue->CaretInfo);
-   ThreadQueue->CaretInfo->Bitmap = (HBITMAP)0;
-   ThreadQueue->CaretInfo->hWnd = (HWND)0;
-   ThreadQueue->CaretInfo->Size.cx = ThreadQueue->CaretInfo->Size.cy = 0;
-   ThreadQueue->CaretInfo->Showing = 0;
-   ThreadQueue->CaretInfo->Visible = 0;
+   IntHideCaret(&Queue->Input->CaretInfo);
+   Queue->Input->CaretInfo.Bitmap = (HBITMAP)0;
+   Queue->Input->CaretInfo.hWnd = (HWND)0;
+   Queue->Input->CaretInfo.Size.cx = Queue->Input->CaretInfo.Size.cy = 0;
+   Queue->Input->CaretInfo.Showing = 0;
+   Queue->Input->CaretInfo.Visible = 0;
    return TRUE;
 }
 
@@ -162,20 +163,20 @@
 BOOL FASTCALL
 UserSetCaretPos(int X, int Y)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
+   
+   Input = UserGetCurrentInput();
 
-   ThreadQueue = UserGetCurrentQueue();
-
-   if(ThreadQueue->CaretInfo->hWnd)
+   if(Input->CaretInfo.hWnd)
    {
-      if(ThreadQueue->CaretInfo->Pos.x != X || ThreadQueue->CaretInfo->Pos.y != Y)
+      if(Input->CaretInfo.Pos.x != X || Input->CaretInfo.Pos.y != Y)
       {
-         IntHideCaret(ThreadQueue->CaretInfo);
-         ThreadQueue->CaretInfo->Showing = 0;
-         ThreadQueue->CaretInfo->Pos.x = X;
-         ThreadQueue->CaretInfo->Pos.y = Y;
-         IntSendMessage(ThreadQueue->CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
-         UserSetTimer(GetWnd(ThreadQueue->CaretInfo->hWnd), IDCARETTIMER, UserGetCaretBlinkTime(), NULL, TRUE);
+         IntHideCaret(&Input->CaretInfo);
+         Input->CaretInfo.Showing = 0;
+         Input->CaretInfo.Pos.x = X;
+         Input->CaretInfo.Pos.y = Y;
+         IntSendMessage(Input->CaretInfo.hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
+         UserSetTimer(GetWnd(Input->CaretInfo.hWnd), IDCARETTIMER, UserGetCaretBlinkTime(), NULL, TRUE);
       }
       return TRUE;
    }
@@ -184,17 +185,18 @@
 }
 
 BOOL FASTCALL
-UserSwitchCaretShowing(PVOID Info)
+UserSwitchCaretShowing(PTHRDCARETINFO Info)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   if(ThreadQueue->CaretInfo->hWnd)
+   if(Input->CaretInfo.hWnd)
    {
-      ThreadQueue->CaretInfo->Showing = (ThreadQueue->CaretInfo->Showing ? 0 : 1);
+      Input->CaretInfo.Showing = !Input->CaretInfo.Showing;
       //FIXME: internal. no SEH here!
-      MmCopyToCaller(Info, ThreadQueue->CaretInfo, sizeof(THRDCARETINFO));
+      MmCopyToCaller(Info, &Input->CaretInfo, sizeof(THRDCARETINFO));
+      //*Info = Input->CaretInfo;
       return TRUE;
    }
 
@@ -204,15 +206,15 @@
 VOID FASTCALL
 UserDrawCaret(HWND hWnd /* FIXME: Unused param?!?! */)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   if(ThreadQueue->CaretInfo->hWnd && ThreadQueue->CaretInfo->Visible &&
-         ThreadQueue->CaretInfo->Showing)
+   if(Input->CaretInfo.hWnd && Input->CaretInfo.Visible &&
+         Input->CaretInfo.Showing)
    {
-      IntSendMessage(ThreadQueue->CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
-      ThreadQueue->CaretInfo->Showing = 1;
+      IntSendMessage(Input->CaretInfo.hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
+      Input->CaretInfo.Showing = 1;
    }
 }
 
@@ -227,7 +229,7 @@
    int nHeight)
 {
    PWINDOW_OBJECT WindowObject;
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
    DECLARE_RETURN(BOOL);
 
    DPRINT("Enter NtUserCreateCaret\n");
@@ -246,28 +248,28 @@
       RETURN(FALSE);
    }
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   if (ThreadQueue->CaretInfo->Visible)
+   if (Input->CaretInfo.Visible)
    {
       UserKillTimer(WindowObject, IDCARETTIMER, TRUE);
-      IntHideCaret(ThreadQueue->CaretInfo);
+      IntHideCaret(&Input->CaretInfo);
    }
 
-   ThreadQueue->CaretInfo->hWnd = hWnd;
+   Input->CaretInfo.hWnd = hWnd;
    if(hBitmap)
    {
-      ThreadQueue->CaretInfo->Bitmap = hBitmap;
-      ThreadQueue->CaretInfo->Size.cx = ThreadQueue->CaretInfo->Size.cy = 0;
+      Input->CaretInfo.Bitmap = hBitmap;
+      Input->CaretInfo.Size.cx = Input->CaretInfo.Size.cy = 0;
    }
    else
    {
-      ThreadQueue->CaretInfo->Bitmap = (HBITMAP)0;
-      ThreadQueue->CaretInfo->Size.cx = nWidth;
-      ThreadQueue->CaretInfo->Size.cy = nHeight;
+      Input->CaretInfo.Bitmap = (HBITMAP)0;
+      Input->CaretInfo.Size.cx = nWidth;
+      Input->CaretInfo.Size.cy = nHeight;
    }
-   ThreadQueue->CaretInfo->Visible = 0;
-   ThreadQueue->CaretInfo->Showing = 0;
+   Input->CaretInfo.Visible = 0;
+   Input->CaretInfo.Showing = 0;
 
    RETURN(TRUE);
 
@@ -300,16 +302,16 @@
 NtUserGetCaretPos(
    LPPOINT lpPoint)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
    NTSTATUS Status;
    DECLARE_RETURN(BOOL);
 
    DPRINT("Enter NtUserGetCaretPos\n");
    UserEnterExclusive();
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   Status = MmCopyToCaller(lpPoint, &(ThreadQueue->CaretInfo->Pos), sizeof(POINT));
+   Status = MmCopyToCaller(lpPoint, &(Input->CaretInfo.Pos), sizeof(POINT));
    if(!NT_SUCCESS(Status))
    {
       SetLastNtError(Status);
@@ -331,7 +333,7 @@
    HWND hWnd)
 {
    PWINDOW_OBJECT WindowObject;
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
    DECLARE_RETURN(BOOL);
 
    DPRINT1("Enter NtUserHideCaret\n");
@@ -350,21 +352,21 @@
       RETURN(FALSE);
    }
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   if(ThreadQueue->CaretInfo->hWnd != hWnd)
+   if(Input->CaretInfo.hWnd != hWnd)
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       RETURN(FALSE);
    }
 
-   if(ThreadQueue->CaretInfo->Visible)
+   if(Input->CaretInfo.Visible)
    {
       UserKillTimer(WindowObject, IDCARETTIMER, TRUE);
 
-      IntHideCaret(ThreadQueue->CaretInfo);
-      ThreadQueue->CaretInfo->Visible = 0;
-      ThreadQueue->CaretInfo->Showing = 0;
+      IntHideCaret(&Input->CaretInfo);
+      Input->CaretInfo.Visible = 0;
+      Input->CaretInfo.Showing = 0;
    }
 
    RETURN(TRUE);
@@ -380,7 +382,7 @@
 BOOL FASTCALL
 UserHideCaret(PWINDOW_OBJECT Wnd)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
 
    ASSERT(Wnd);
 
@@ -390,22 +392,22 @@
       return(FALSE);
    }
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   if(ThreadQueue->CaretInfo->hWnd != GetHwnd(Wnd))
+   if(Input->CaretInfo.hWnd != GetHwnd(Wnd))
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       return(FALSE);
    }
 
-   if(ThreadQueue->CaretInfo->Visible)
+   if(Input->CaretInfo.Visible)
    {
       UserKillTimer(Wnd, IDCARETTIMER, TRUE);
 
       //FIXME: fix IntHideCaret vs. NtHideCaret vs. UserHideCaret mess
-      IntHideCaret(ThreadQueue->CaretInfo);
-      ThreadQueue->CaretInfo->Visible = 0;
-      ThreadQueue->CaretInfo->Showing = 0;
+      IntHideCaret(&Input->CaretInfo);
+      Input->CaretInfo.Visible = 0;
+      Input->CaretInfo.Showing = 0;
    }
 
    return(TRUE);
@@ -443,7 +445,7 @@
 BOOL FASTCALL
 UserShowCaret(PWINDOW_OBJECT Wnd)
 {
-   PUSER_MESSAGE_QUEUE ThreadQueue;
+   PUSER_THREAD_INPUT Input;
 
    ASSERT(Wnd);
 
@@ -453,20 +455,20 @@
       return(FALSE);
    }
 
-   ThreadQueue = UserGetCurrentQueue();
+   Input = UserGetCurrentInput();
 
-   if(ThreadQueue->CaretInfo->hWnd != GetHwnd(Wnd))
+   if(Input->CaretInfo.hWnd != GetHwnd(Wnd))
    {
       SetLastWin32Error(ERROR_ACCESS_DENIED);
       return(FALSE);
    }
 
-   if(!ThreadQueue->CaretInfo->Visible)
+   if(!Input->CaretInfo.Visible)
    {
-      ThreadQueue->CaretInfo->Visible = 1;
-      if(!ThreadQueue->CaretInfo->Showing)
+      Input->CaretInfo.Visible = 1;
+      if(!Input->CaretInfo.Showing)
       {
-         IntSendMessage(ThreadQueue->CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
+         IntSendMessage(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-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/class.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -30,7 +30,7 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 /* FUNCTIONS *****************************************************************/

Modified: branches/win32k rewrite attempt/win32k/ntuser/clipboard.c
--- branches/win32k rewrite attempt/win32k/ntuser/clipboard.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/clipboard.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -26,7 +26,7 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 #define CHECK_LOCK                                                      \

Modified: branches/win32k rewrite attempt/win32k/ntuser/csr.c
--- branches/win32k rewrite attempt/win32k/ntuser/csr.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/csr.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -9,7 +9,7 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 static HANDLE WindowsApiPort = NULL;

Modified: branches/win32k rewrite attempt/win32k/ntuser/cursoricon.c
--- branches/win32k rewrite attempt/win32k/ntuser/cursoricon.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/cursoricon.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -38,12 +38,11 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 static PAGED_LOOKASIDE_LIST ProcessLookasideList;
 static LIST_ENTRY CurIconList;
-//static FAST_MUTEX CurIconListLock;
 
 /* Look up the location of the cursor in the GDIDEVICE structure
  * when all we know is the window station object

Modified: branches/win32k rewrite attempt/win32k/ntuser/desktop.c
--- branches/win32k rewrite attempt/win32k/ntuser/desktop.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/desktop.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -31,12 +31,17 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 /* GLOBALS *******************************************************************/
 
 /* Currently active desktop */
+
+/*
+ FIXME: this is not global data. this belongs in the (inter)active window station
+ (current input desktop = interactive desktop = InputDesktop = active desktop on interactive winsta)
+*/
 PDESKTOP_OBJECT InputDesktop = NULL;
 HDESK InputDesktopHandle = NULL;
 HDC ScreenDeviceContext = NULL;

Modified: branches/win32k rewrite attempt/win32k/ntuser/focus.c
--- branches/win32k rewrite attempt/win32k/ntuser/focus.c	2005-08-04 12:41:42 UTC (rev 17043)
+++ branches/win32k rewrite attempt/win32k/ntuser/focus.c	2005-08-04 16:32:18 UTC (rev 17044)
@@ -21,21 +21,21 @@
 
 #include <w32k.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 PWINDOW_OBJECT FASTCALL
 UserGetCaptureWindow()
 {
    PUSER_MESSAGE_QUEUE ForegroundQueue = UserGetFocusMessageQueue();
-   return ForegroundQueue != NULL ? GetWnd(ForegroundQueue->CaptureWindow) : 0;
+   return ForegroundQueue != NULL ? GetWnd(ForegroundQueue->Input->CaptureWindow) : 0;
 }
 
 PWINDOW_OBJECT FASTCALL
 UserGetFocusWindow()
 {
    PUSER_MESSAGE_QUEUE ForegroundQueue = UserGetFocusMessageQueue();
-   return ForegroundQueue != NULL ? GetWnd(ForegroundQueue->FocusWindow) : 0;
+   return ForegroundQueue != NULL ? GetWnd(ForegroundQueue->Input->FocusWindow) : 0;
 }
 
 PWINDOW_OBJECT FASTCALL
@@ -43,7 +43,7 @@
 {
    PUSER_MESSAGE_QUEUE ThreadQueue;
    ThreadQueue = UserGetCurrentQueue();
-   return ThreadQueue != NULL ? GetWnd(ThreadQueue->FocusWindow) : 0;
+   return ThreadQueue != NULL ? GetWnd(ThreadQueue->Input->FocusWindow) : 0;
 }
 
 VOID FASTCALL
@@ -169,7 +169,7 @@
    if (PrevForegroundQueue != 0)
    {
       //FIXME uhm... focus er ikke samme som active window... er UserGetFocusMessageQueue riktig?
-      hWndPrev = PrevForegroundQueue->ActiveWindow;
+      hWndPrev = PrevForegroundQueue->Input->ActiveWindow;
    }
 
    if (hWndPrev == hWnd)
@@ -179,7 +179,7 @@
    }
 
    hWndFocusPrev = (PrevForegroundQueue == FocusWindow->MessageQueue
-                    ? FocusWindow->MessageQueue->FocusWindow : NULL);
+                    ? FocusWindow->MessageQueue->Input->FocusWindow : NULL);
 
    /* FIXME: Call hooks. */
 
@@ -189,11 +189,11 @@
    IntSetFocusMessageQueue(Window->MessageQueue);
    if (Window->MessageQueue)
    {
-      Window->MessageQueue->ActiveWindow = hWnd;
+      Window->MessageQueue->Input->ActiveWindow = hWnd;
    }
    if (FocusWindow->MessageQueue)
    {
-      FocusWindow->MessageQueue->FocusWindow = hWndFocus;
+      FocusWindow->MessageQueue->Input->FocusWindow = hWndFocus;
    }
 
    if (PrevForegroundQueue != Window->MessageQueue)
@@ -277,14 +277,14 @@
          //            return 0;
          //         else
          //         {
-         WndPrev = IntGetWindowObject(ThreadQueue->ActiveWindow);
+         WndPrev = IntGetWindowObject(ThreadQueue->Input->ActiveWindow);
          return( WndPrev ? WndPrev->Self : NULL );
 
          //         }
       }
    }
 
-   WndPrev = IntGetWindowObject(ThreadQueue->ActiveWindow);
+   WndPrev = IntGetWindowObject(ThreadQueue->Input->ActiveWindow);
    if (WndPrev == Wnd)
    {
       return WndPrev;
@@ -294,7 +294,7 @@
 
    /* FIXME: Call hooks. */
 
-   ThreadQueue->ActiveWindow = GetHwnd(Wnd);
+   ThreadQueue->Input->ActiveWindow = GetHwnd(Wnd);
 
    //FIXME!!! hva hvis prev active var invalid dvs. NULL?
    //FIXME!!! hva hvis Wnd er NULL?
@@ -315,13 +315,13 @@
    ThreadQueue = UserGetCurrentQueue();
    ASSERT(ThreadQueue != 0);
 
-   hWndPrev = ThreadQueue->FocusWindow;
+   hWndPrev = ThreadQueue->Input->FocusWindow;
    if (hWndPrev == GetHwnd(Wnd))
    {
       return GetWnd(hWndPrev);
    }
 
-   ThreadQueue->FocusWindow = GetHwnd(Wnd);
+   ThreadQueue->Input->FocusWindow = GetHwnd(Wnd);
 
    IntSendKillFocusMessages(GetWnd(hWndPrev), Wnd);
    IntSendSetFocusMessages(GetWnd(hWndPrev), Wnd);
@@ -357,8 +357,8 @@
 {
    PUSER_MESSAGE_QUEUE ForegroundQueue = UserGetFocusMessageQueue();
 
-   if (ForegroundQueue && ForegroundQueue->ActiveWindow)
-      return IntGetWindowObject(ForegroundQueue->ActiveWindow);
+   if (ForegroundQueue && ForegroundQueue->Input->ActiveWindow)
+      return IntGetWindowObject(ForegroundQueue->Input->ActiveWindow);
 
    return NULL;
 }
@@ -390,18 +390,18 @@
    PUSER_MESSAGE_QUEUE ThreadQueue;
 
    ThreadQueue = UserGetCurrentQueue();
-   if (ThreadQueue && ThreadQueue->ActiveWindow)
+   if (ThreadQueue && ThreadQueue->Input->ActiveWindow)
    {
       PWINDOW_OBJECT ActiveWnd;
 
-      if ((ActiveWnd = IntGetWindowObject(ThreadQueue->ActiveWindow)))
+      if ((ActiveWnd = IntGetWindowObject(ThreadQueue->Input->ActiveWindow)))
       {
          return ActiveWnd;
       }
       else
       {
          /* active hwnd not valid. set to NULL */
-         ThreadQueue->ActiveWindow = NULL;
+         ThreadQueue->Input->ActiveWindow = NULL;
       }
    }
    return NULL;
@@ -466,7 +466,7 @@
    UserEnterExclusive();
 
    ThreadQueue = UserGetCurrentQueue();//FIXME??? current??
-   RETURN(ThreadQueue ? ThreadQueue->CaptureWindow : 0);
+   RETURN(ThreadQueue ? ThreadQueue->Input->CaptureWindow : 0);
 
 CLEANUP:
    DPRINT("Leave NtUserGetCapture, ret=%i\n",_ret_);
@@ -496,17 +496,17 @@
          RETURN(NULL);
       }
    }
-   hWndPrev = MsqSetStateWindow(ThreadQueue, MSQ_STATE_CAPTURE, hWnd);
+   hWndPrev = MsqSetStateWindow(ThreadQueue->Input, MSQ_STATE_CAPTURE, hWnd);
 
    /* also remove other windows if not capturing anymore */
    if(hWnd == NULL)
    {
-      MsqSetStateWindow(ThreadQueue, MSQ_STATE_MENUOWNER, NULL);
-      MsqSetStateWindow(ThreadQueue, MSQ_STATE_MOVESIZE, NULL);
+      MsqSetStateWindow(ThreadQueue->Input, MSQ_STATE_MENUOWNER, NULL);
+      MsqSetStateWindow(ThreadQueue->Input, MSQ_STATE_MOVESIZE, NULL);
    }
 
    IntPostOrSendMessage(hWndPrev, WM_CAPTURECHANGED, 0, (LPARAM)hWnd);
-   ThreadQueue->CaptureWindow = hWnd;
+   ThreadQueue->Input->CaptureWindow = hWnd;
 
    RETURN(hWndPrev);
 
@@ -544,7 +544,7 @@
 
       if (Wnd->Style & (WS_MINIMIZE | WS_DISABLED))
       {
-         RETURN(ThreadQueue ? ThreadQueue->FocusWindow : 0);
[truncated at 1000 lines; 1198 more skipped]