X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin3_src%2FWM%2Fwm_input.c;h=f15d25a7ec1768d29d1ae9dcd06afffd32d7a561;hb=2f16fec349eabb42f5e23ea2b821f149fa6b767e;hp=c2ebb9e61e7a3199d3e9005d42db676e6b41784f;hpb=5b6ff5b0698142d4f17a693c0d340df10b375926;p=tpg%2Facess2.git diff --git a/Usermode/Applications/axwin3_src/WM/wm_input.c b/Usermode/Applications/axwin3_src/WM/wm_input.c index c2ebb9e6..f15d25a7 100644 --- a/Usermode/Applications/axwin3_src/WM/wm_input.c +++ b/Usermode/Applications/axwin3_src/WM/wm_input.c @@ -7,10 +7,17 @@ */ #include #include +#include + +#define MAX_BUTTONS 3 // === IMPORTS === extern tWindow *gpWM_RootWindow; +// === GLOBALS === +//! Window in which the mouse button was originally pressed +tWindow *gpWM_DownStartWindow[MAX_BUTTONS]; + // === CODE === tWindow *WM_int_GetWindowAtPos(int X, int Y) { @@ -36,14 +43,70 @@ tWindow *WM_int_GetWindowAtPos(int X, int Y) void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY) { - // TODO: Mouse motion events + tWindow *win, *newWin; + struct sWndMsg_MouseMove msg; + + win = WM_int_GetWindowAtPos(OldX, OldY); + msg.X = NewX - win->X - win->BorderL; + msg.Y = NewY - win->Y - win->BorderT; + msg.dX = NewX - OldX; + msg.dY = NewY - OldY; + WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg); + + // If the new coordinates are not in a new window + // NOTE: Should this handle crossing over a small window? + // - Nah, no need + newWin = WM_int_GetWindowAtPos(NewX, NewY); + if(win == newWin) return; + // TODO: Send mouseup to match mousedown if the cursor moves out of a window? + + win = newWin; + msg.X = NewX - win->X - win->BorderL; + msg.Y = NewY - win->Y - win->BorderT; + msg.dX = NewX - OldX; + msg.dY = NewY - OldY; + WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg); } -void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed) +inline void WM_Input_int_SendBtnMsg(tWindow *Win, int X, int Y, int Index, int Pressed) { -// tWindow *win = WM_int_GetWindowAtPos(X, Y); + struct sWndMsg_MouseButton msg; + + msg.X = X - Win->X - Win->BorderL; + msg.Y = Y - Win->Y - Win->BorderT; + msg.Button = Index; + msg.bPressed = !!Pressed; + WM_SendMessage(NULL, Win, WNDMSG_MOUSEBTN, sizeof(msg), &msg); +} + +void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed) +{ + tWindow *win; + + win = WM_int_GetWindowAtPos(X, Y); + + // Handle press of primary button to change focus + if( ButtonIndex == 0 && Pressed == 1 ) + { +// _SysDebug("Gave focus to %p", win); + WM_FocusWindow(win); + WM_RaiseWindow(win); + } + + // Make sure that even if the mouse has moved out of the original window, + // mouse release messages reach the window. + if( !Pressed && ButtonIndex < MAX_BUTTONS && gpWM_DownStartWindow[ButtonIndex] != win ) + { + WM_Input_int_SendBtnMsg(gpWM_DownStartWindow[ButtonIndex], X, Y, ButtonIndex, 0); + } + if( Pressed && ButtonIndex < MAX_BUTTONS ) + { + gpWM_DownStartWindow[ButtonIndex] = win; + } + // Send Press/Release message + WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed); }