1. finally fixed handling the WM_MOUSEMOVE messages, credits go to Royce :)

2. Now passing cursor's hotspot position to SetPointerShape

svn path=/trunk/; revision=5874
This commit is contained in:
Thomas Bluemel 2003-08-26 19:26:02 +00:00
parent d239b6fbb7
commit 51b70de9b7
3 changed files with 57 additions and 91 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: mouse.c,v 1.35 2003/08/26 00:33:53 weiden Exp $ /* $Id: mouse.c,v 1.36 2003/08/26 19:26:02 weiden Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* PURPOSE: Mouse * PURPOSE: Mouse
@ -311,7 +311,7 @@ MouseMoveCursor(LONG X, LONG Y)
Msg.time = TickCount; Msg.time = TickCount;
Msg.pt.x = X; Msg.pt.x = X;
Msg.pt.y = Y; Msg.pt.y = Y;
MsqInsertSystemMessage(&Msg); MsqInsertSystemMessage(&Msg, TRUE);
/* move cursor */ /* move cursor */
CurInfo->x = X; CurInfo->x = X;
CurInfo->y = Y; CurInfo->y = Y;
@ -413,7 +413,7 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount)
if ((0 != Data[i].LastX) || (0 != Data[i].LastY)) if ((0 != Data[i].LastX) || (0 != Data[i].LastY))
{ {
MsqInsertSystemMessage(&Msg); MsqInsertSystemMessage(&Msg, FALSE);
MouseMoveAdded = TRUE; MouseMoveAdded = TRUE;
} }
@ -449,7 +449,7 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount)
Msg.message = WM_RBUTTONUP; Msg.message = WM_RBUTTONUP;
} }
MsqInsertSystemMessage(&Msg); MsqInsertSystemMessage(&Msg, FALSE);
} }
} }
@ -467,7 +467,7 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount)
Msg.pt.y = CurInfo->y; Msg.pt.y = CurInfo->y;
Msg.time = TickCount; Msg.time = TickCount;
Msg.lParam = MAKELPARAM(CurInfo->x, CurInfo->y); Msg.lParam = MAKELPARAM(CurInfo->x, CurInfo->y);
MsqInsertSystemMessage(&Msg); MsqInsertSystemMessage(&Msg, TRUE);
} }
if (!CurInfo->SafetySwitch && !CurInfo->SafetySwitch2 && if (!CurInfo->SafetySwitch && !CurInfo->SafetySwitch2 &&
@ -532,7 +532,8 @@ EnableMouse(HDC hDisplayDC)
CurInfo); CurInfo);
PointerStatus = SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, PointerStatus = SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL,
0, 0, SysCursor->hx,
SysCursor->hy,
CurInfo->x, CurInfo->x,
CurInfo->y, CurInfo->y,
&MouseRect, &MouseRect,

View file

@ -128,7 +128,7 @@ IntSendMessage(HWND hWnd,
VOID STDCALL VOID STDCALL
MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
VOID FASTCALL VOID FASTCALL
MsqInsertSystemMessage(MSG* Msg); MsqInsertSystemMessage(MSG* Msg, BOOL RemMouseMoveMsg);
inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue ); inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue );
inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits ); inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: msgqueue.c,v 1.19 2003/08/26 00:06:16 weiden Exp $ /* $Id: msgqueue.c,v 1.20 2003/08/26 19:26:02 weiden Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -48,6 +48,7 @@ static MSG SystemMessageQueue[SYSTEM_MESSAGE_QUEUE_SIZE];
static ULONG SystemMessageQueueHead = 0; static ULONG SystemMessageQueueHead = 0;
static ULONG SystemMessageQueueTail = 0; static ULONG SystemMessageQueueTail = 0;
static ULONG SystemMessageQueueCount = 0; static ULONG SystemMessageQueueCount = 0;
static ULONG SystemMessageQueueMouseMove = -1;
static KSPIN_LOCK SystemMessageQueueLock; static KSPIN_LOCK SystemMessageQueueLock;
static ULONG HardwareMessageQueueStamp = 0; static ULONG HardwareMessageQueueStamp = 0;
@ -124,69 +125,26 @@ MsqInitializeImpl(VOID)
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
ULONG FASTCALL
MsgFindSystemMouseMoveMessage()
{
LPMSG Msg, Msg2;
ULONG QueuePos;
if(SystemMessageQueueCount > 0)
{
QueuePos = SystemMessageQueueTail;
while(QueuePos >= SystemMessageQueueHead)
{
Msg = &SystemMessageQueue[QueuePos];
if(Msg->message == WM_MOUSEMOVE)
{
if(SystemMessageQueueHead == QueuePos)
return QueuePos;
/* if there is one of the following messages after a
WM_MOUSEMOVE message then skip it */
Msg2 = &SystemMessageQueue[QueuePos - 1];
switch(Msg2->message)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
#if 0
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
#endif
break;
default:
return QueuePos;
}
}
QueuePos--;
}
}
return (ULONG)-1;
}
VOID FASTCALL VOID FASTCALL
MsqInsertSystemMessage(MSG* Msg) MsqInsertSystemMessage(MSG* Msg, BOOL RemMouseMoveMsg)
{ {
KIRQL OldIrql; KIRQL OldIrql;
ULONG mmov = (ULONG)-1; ULONG mmov = (ULONG)-1;
KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql); KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql);
/* only insert WM_MOUSEMOVE messages if not already in system message queue */ /* only insert WM_MOUSEMOVE messages if not already in system message queue */
//if(Msg->message == WM_MOUSEMOVE) if((Msg->message == WM_MOUSEMOVE) && RemMouseMoveMsg)
// mmov = MsgFindSystemMouseMoveMessage(); mmov = SystemMessageQueueMouseMove;
if(mmov != (ULONG)-1) if(mmov != (ULONG)-1)
{ {
/* insert message at the queue head */ /* insert message at the queue head */
while(mmov > SystemMessageQueueHead) while (mmov != SystemMessageQueueHead )
{ {
SystemMessageQueue[mmov] = SystemMessageQueue[mmov - 1]; ULONG prev = mmov ? mmov - 1 : SYSTEM_MESSAGE_QUEUE_SIZE - 1;
mmov--; SystemMessageQueue[mmov] = SystemMessageQueue[prev];
mmov = prev;
} }
SystemMessageQueue[SystemMessageQueueHead] = *Msg; SystemMessageQueue[SystemMessageQueueHead] = *Msg;
} }
@ -198,7 +156,9 @@ MsqInsertSystemMessage(MSG* Msg)
return; return;
} }
SystemMessageQueue[SystemMessageQueueTail] = *Msg; SystemMessageQueue[SystemMessageQueueTail] = *Msg;
SystemMessageQueueTail = if(Msg->message == WM_MOUSEMOVE)
SystemMessageQueueMouseMove = SystemMessageQueueTail;
SystemMessageQueueTail =
(SystemMessageQueueTail + 1) % SYSTEM_MESSAGE_QUEUE_SIZE; (SystemMessageQueueTail + 1) % SYSTEM_MESSAGE_QUEUE_SIZE;
SystemMessageQueueCount++; SystemMessageQueueCount++;
} }
@ -208,7 +168,7 @@ MsqInsertSystemMessage(MSG* Msg)
BOOL STATIC STDCALL BOOL STATIC STDCALL
MsqTranslateMouseMessage(HWND hWnd, UINT FilterLow, UINT FilterHigh, MsqTranslateMouseMessage(HWND hWnd, UINT FilterLow, UINT FilterHigh,
PUSER_MESSAGE Message, BOOL Remove, PUSER_MESSAGE Message, BOOL Remove,
PWINDOW_OBJECT ScopeWin, PUSHORT HitTest, PWINDOW_OBJECT ScopeWin, PUSHORT HitTest,
PPOINT ScreenPoint, PBOOL MouseClick) PPOINT ScreenPoint, PBOOL MouseClick)
{ {
@ -230,14 +190,14 @@ MsqTranslateMouseMessage(HWND hWnd, UINT FilterLow, UINT FilterHigh,
{ {
*HitTest = HTCLIENT; *HitTest = HTCLIENT;
} }
if (Window == NULL) if (Window == NULL)
{ {
ExFreePool(Message); ExFreePool(Message);
return(FALSE); return(FALSE);
} }
if (Window->MessageQueue != PsGetWin32Thread()->MessageQueue) if (Window->MessageQueue != PsGetWin32Thread()->MessageQueue)
{ {
ExAcquireFastMutex(&Window->MessageQueue->Lock); ExAcquireFastMutex(&Window->MessageQueue->Lock);
InsertTailList(&Window->MessageQueue->HardwareMessagesListHead, InsertTailList(&Window->MessageQueue->HardwareMessagesListHead,
&Message->ListEntry); &Message->ListEntry);
@ -246,7 +206,7 @@ MsqTranslateMouseMessage(HWND hWnd, UINT FilterLow, UINT FilterHigh,
return(FALSE); return(FALSE);
} }
if (hWnd != NULL && Window->Self != hWnd && if (hWnd != NULL && Window->Self != hWnd &&
!IntIsChildWindow(hWnd, Window->Self)) !IntIsChildWindow(hWnd, Window->Self))
{ {
return(FALSE); return(FALSE);
@ -317,7 +277,7 @@ MsqTranslateMouseMessage(HWND hWnd, UINT FilterLow, UINT FilterHigh,
} }
BOOL STDCALL BOOL STDCALL
MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
UINT FilterLow, UINT FilterHigh, BOOL Remove, UINT FilterLow, UINT FilterHigh, BOOL Remove,
PUSER_MESSAGE* Message) PUSER_MESSAGE* Message)
{ {
@ -337,14 +297,14 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
CurrentEntry = MessageQueue->HardwareMessagesListHead.Flink; CurrentEntry = MessageQueue->HardwareMessagesListHead.Flink;
while (CurrentEntry != &MessageQueue->HardwareMessagesListHead) while (CurrentEntry != &MessageQueue->HardwareMessagesListHead)
{ {
PUSER_MESSAGE Current = PUSER_MESSAGE Current =
CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, ListEntry); CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, ListEntry);
CurrentEntry = CurrentEntry->Flink; CurrentEntry = CurrentEntry->Flink;
if (Current->Msg.message >= WM_MOUSEFIRST && if (Current->Msg.message >= WM_MOUSEFIRST &&
Current->Msg.message <= WM_MOUSELAST) Current->Msg.message <= WM_MOUSELAST)
{ {
Accept = MsqTranslateMouseMessage(hWnd, FilterLow, FilterHigh, Accept = MsqTranslateMouseMessage(hWnd, FilterLow, FilterHigh,
Current, Remove, Current, Remove,
DesktopWindow, &HitTest, DesktopWindow, &HitTest,
&ScreenPoint, &MouseClick); &ScreenPoint, &MouseClick);
if (Accept) if (Accept)
@ -367,12 +327,12 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
/* Transfer all messages from the DPC accessible queue to the main queue. */ /* Transfer all messages from the DPC accessible queue to the main queue. */
KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql); KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql);
while (SystemMessageQueueCount > 0) while (SystemMessageQueueCount > 0)
{ {
PUSER_MESSAGE UserMsg; PUSER_MESSAGE UserMsg;
MSG Msg; MSG Msg;
Msg = SystemMessageQueue[SystemMessageQueueHead]; Msg = SystemMessageQueue[SystemMessageQueueHead];
SystemMessageQueueHead = SystemMessageQueueHead =
(SystemMessageQueueHead + 1) % SYSTEM_MESSAGE_QUEUE_SIZE; (SystemMessageQueueHead + 1) % SYSTEM_MESSAGE_QUEUE_SIZE;
SystemMessageQueueCount--; SystemMessageQueueCount--;
KeReleaseSpinLock(&SystemMessageQueueLock, OldIrql); KeReleaseSpinLock(&SystemMessageQueueLock, OldIrql);
@ -381,6 +341,11 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
InsertTailList(&HardwareMessageQueueHead, &UserMsg->ListEntry); InsertTailList(&HardwareMessageQueueHead, &UserMsg->ListEntry);
KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql); KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql);
} }
/*
* we could set this to -1 conditionally if we find one, but
* this is more efficient and just as effective.
*/
SystemMessageQueueMouseMove = -1;
KeReleaseSpinLock(&SystemMessageQueueLock, OldIrql); KeReleaseSpinLock(&SystemMessageQueueLock, OldIrql);
HardwareMessageQueueStamp++; HardwareMessageQueueStamp++;
@ -388,11 +353,11 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
CurrentEntry = HardwareMessageQueueHead.Flink; CurrentEntry = HardwareMessageQueueHead.Flink;
while (CurrentEntry != &HardwareMessageQueueHead) while (CurrentEntry != &HardwareMessageQueueHead)
{ {
PUSER_MESSAGE Current = PUSER_MESSAGE Current =
CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, ListEntry); CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, ListEntry);
CurrentEntry = CurrentEntry->Flink; CurrentEntry = CurrentEntry->Flink;
RemoveEntryList(&Current->ListEntry); RemoveEntryList(&Current->ListEntry);
if (Current->Msg.message >= WM_MOUSEFIRST && if (Current->Msg.message >= WM_MOUSEFIRST &&
Current->Msg.message <= WM_MOUSELAST) Current->Msg.message <= WM_MOUSELAST)
{ {
ActiveStamp = HardwareMessageQueueStamp; ActiveStamp = HardwareMessageQueueStamp;
@ -414,7 +379,7 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
} }
KeReleaseSpinLock(&SystemMessageQueueLock, OldIrql); KeReleaseSpinLock(&SystemMessageQueueLock, OldIrql);
/* /*
If we aren't removing the message then add it to the private If we aren't removing the message then add it to the private
queue. queue.
*/ */
@ -434,7 +399,7 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
CurrentEntry = HardwareMessageQueueHead.Flink; CurrentEntry = HardwareMessageQueueHead.Flink;
continue; continue;
} }
} }
} }
/* Check if the system message queue is now empty. */ /* Check if the system message queue is now empty. */
KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql); KeAcquireSpinLock(&SystemMessageQueueLock, &OldIrql);
@ -472,7 +437,7 @@ MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
Msg.wParam = wParam; Msg.wParam = wParam;
Msg.lParam = lParam; Msg.lParam = lParam;
/* FIXME: Initialize time and point. */ /* FIXME: Initialize time and point. */
Message = MsqCreateMessage(&Msg); Message = MsqCreateMessage(&Msg);
MsqPostMessage(FocusMessageQueue, Message); MsqPostMessage(FocusMessageQueue, Message);
} }
@ -493,15 +458,15 @@ PUSER_MESSAGE FASTCALL
MsqCreateMessage(LPMSG Msg) MsqCreateMessage(LPMSG Msg)
{ {
PUSER_MESSAGE Message; PUSER_MESSAGE Message;
Message = ExAllocateFromPagedLookasideList(&MessageLookasideList); Message = ExAllocateFromPagedLookasideList(&MessageLookasideList);
if (!Message) if (!Message)
{ {
return NULL; return NULL;
} }
MsqInitializeMessage(Message, Msg); MsqInitializeMessage(Message, Msg);
return Message; return Message;
} }
@ -521,7 +486,7 @@ MsqDispatchSentNotifyMessages(PUSER_MESSAGE_QUEUE MessageQueue)
{ {
ExAcquireFastMutex(&MessageQueue->Lock); ExAcquireFastMutex(&MessageQueue->Lock);
ListEntry = RemoveHeadList(&MessageQueue->SentMessagesListHead); ListEntry = RemoveHeadList(&MessageQueue->SentMessagesListHead);
Message = CONTAINING_RECORD(ListEntry, USER_SENT_MESSAGE_NOTIFY, Message = CONTAINING_RECORD(ListEntry, USER_SENT_MESSAGE_NOTIFY,
ListEntry); ListEntry);
ExReleaseFastMutex(&MessageQueue->Lock); ExReleaseFastMutex(&MessageQueue->Lock);
@ -579,9 +544,9 @@ MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue)
/* Notify the sender if they specified a callback. */ /* Notify the sender if they specified a callback. */
if (Message->CompletionCallback != NULL) if (Message->CompletionCallback != NULL)
{ {
NotifyMessage = ExAllocatePool(NonPagedPool, NotifyMessage = ExAllocatePool(NonPagedPool,
sizeof(USER_SENT_MESSAGE_NOTIFY)); sizeof(USER_SENT_MESSAGE_NOTIFY));
NotifyMessage->CompletionCallback = NotifyMessage->CompletionCallback =
Message->CompletionCallback; Message->CompletionCallback;
NotifyMessage->CompletionCallbackContext = NotifyMessage->CompletionCallbackContext =
Message->CompletionCallbackContext; Message->CompletionCallbackContext;
@ -600,7 +565,7 @@ MsqSendNotifyMessage(PUSER_MESSAGE_QUEUE MessageQueue,
PUSER_SENT_MESSAGE_NOTIFY NotifyMessage) PUSER_SENT_MESSAGE_NOTIFY NotifyMessage)
{ {
ExAcquireFastMutex(&MessageQueue->Lock); ExAcquireFastMutex(&MessageQueue->Lock);
InsertTailList(&MessageQueue->NotifyMessagesListHead, InsertTailList(&MessageQueue->NotifyMessagesListHead,
&NotifyMessage->ListEntry); &NotifyMessage->ListEntry);
KeSetEvent(&MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE); KeSetEvent(&MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
ExReleaseFastMutex(&MessageQueue->Lock); ExReleaseFastMutex(&MessageQueue->Lock);
@ -655,13 +620,13 @@ MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
MsgFilterLow, MsgFilterHigh, MsgFilterLow, MsgFilterHigh,
Remove, Message)); Remove, Message));
} }
ExAcquireFastMutex(&MessageQueue->Lock); ExAcquireFastMutex(&MessageQueue->Lock);
CurrentEntry = MessageQueue->PostedMessagesListHead.Flink; CurrentEntry = MessageQueue->PostedMessagesListHead.Flink;
ListHead = &MessageQueue->PostedMessagesListHead; ListHead = &MessageQueue->PostedMessagesListHead;
while (CurrentEntry != ListHead) while (CurrentEntry != ListHead)
{ {
CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE,
ListEntry); ListEntry);
if ((Wnd == 0 || Wnd == CurrentMessage->Msg.hwnd) && if ((Wnd == 0 || Wnd == CurrentMessage->Msg.hwnd) &&
((MsgFilterLow == 0 && MsgFilterHigh == 0) || ((MsgFilterLow == 0 && MsgFilterHigh == 0) ||
@ -715,11 +680,11 @@ MsqFreeMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue)
{ {
PLIST_ENTRY CurrentEntry; PLIST_ENTRY CurrentEntry;
PUSER_MESSAGE CurrentMessage; PUSER_MESSAGE CurrentMessage;
CurrentEntry = MessageQueue->PostedMessagesListHead.Flink; CurrentEntry = MessageQueue->PostedMessagesListHead.Flink;
while (CurrentEntry != &MessageQueue->PostedMessagesListHead) while (CurrentEntry != &MessageQueue->PostedMessagesListHead)
{ {
CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE, CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE,
ListEntry); ListEntry);
CurrentEntry = CurrentEntry->Flink; CurrentEntry = CurrentEntry->Flink;
MsqDestroyMessage(CurrentMessage); MsqDestroyMessage(CurrentMessage);
@ -731,15 +696,15 @@ MsqCreateMessageQueue(VOID)
{ {
PUSER_MESSAGE_QUEUE MessageQueue; PUSER_MESSAGE_QUEUE MessageQueue;
MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePool(PagedPool, MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePool(PagedPool,
sizeof(USER_MESSAGE_QUEUE)); sizeof(USER_MESSAGE_QUEUE));
if (!MessageQueue) if (!MessageQueue)
{ {
return NULL; return NULL;
} }
MsqInitializeMessageQueue(MessageQueue); MsqInitializeMessageQueue(MessageQueue);
return MessageQueue; return MessageQueue;
} }