X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin3_src%2FWM%2Fwm_input.c;h=66088f926e0a74d6b5598faa8a52cc3e8d179c50;hb=a644ed9dc9954091daf616dfe93ab2e2a920bf5d;hp=991b74eebd0341bb0849ae94dd2788f4927d81c6;hpb=5057414aefd4d2c869fc9937b48dfdd1910fb573;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 991b74ee..66088f92 100644 --- a/Usermode/Applications/axwin3_src/WM/wm_input.c +++ b/Usermode/Applications/axwin3_src/WM/wm_input.c @@ -9,9 +9,15 @@ #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) { @@ -63,17 +69,44 @@ void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY) 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; - // Send Press/Release message - msg.X = X - win->X; - msg.Y = Y - win->Y; - msg.Button = ButtonIndex; + msg.X = X - Win->X; + msg.Y = Y - Win->Y; + msg.Button = Index; msg.bPressed = !!Pressed; - WM_SendMessage(NULL, win, WNDMSG_MOUSEBTN, sizeof(msg), &msg); + 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); }