2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Window manager core
9 #include <wm_internals.h>
10 #include <wm_messages.h>
15 extern tWindow *gpWM_RootWindow;
18 //! Window in which the mouse button was originally pressed
19 tWindow *gpWM_DownStartWindow[MAX_BUTTONS];
22 tWindow *WM_int_GetWindowAtPos(int X, int Y)
24 tWindow *win, *next_win, *ret;
26 next_win = gpWM_RootWindow;
32 for(win = ret->FirstChild; win; win = win->NextSibling)
34 if( !(win->Flags & WINFLAG_SHOW) ) continue ;
35 if( X < win->X || X >= win->X + win->W ) continue;
36 if( Y < win->Y || Y >= win->Y + win->H ) continue;
37 next_win = win; // Overwrite as we want the final rendered window
44 void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY)
46 tWindow *win, *newWin;
47 struct sWndMsg_MouseMove msg;
49 win = WM_int_GetWindowAtPos(OldX, OldY);
50 msg.X = NewX - win->X - win->BorderL;
51 msg.Y = NewY - win->Y - win->BorderT;
54 WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
56 // If the new coordinates are not in a new window
57 // NOTE: Should this handle crossing over a small window?
59 newWin = WM_int_GetWindowAtPos(NewX, NewY);
60 if(win == newWin) return;
62 // TODO: Send mouseup to match mousedown if the cursor moves out of a window?
65 msg.X = NewX - win->X - win->BorderL;
66 msg.Y = NewY - win->Y - win->BorderT;
69 WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
72 inline void WM_Input_int_SendBtnMsg(tWindow *Win, int X, int Y, int Index, int Pressed)
74 struct sWndMsg_MouseButton msg;
76 msg.X = X - Win->X - Win->BorderL;
77 msg.Y = Y - Win->Y - Win->BorderT;
79 msg.bPressed = !!Pressed;
81 WM_SendMessage(NULL, Win, WNDMSG_MOUSEBTN, sizeof(msg), &msg);
84 void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
88 win = WM_int_GetWindowAtPos(X, Y);
90 // Handle press of primary button to change focus
91 if( ButtonIndex == 0 && Pressed == 1 )
93 // _SysDebug("Gave focus to %p", win);
98 // Make sure that even if the mouse has moved out of the original window,
99 // mouse release messages reach the window.
100 if( !Pressed && ButtonIndex < MAX_BUTTONS && gpWM_DownStartWindow[ButtonIndex] != win )
102 WM_Input_int_SendBtnMsg(gpWM_DownStartWindow[ButtonIndex], X, Y, ButtonIndex, 0);
104 if( Pressed && ButtonIndex < MAX_BUTTONS )
106 gpWM_DownStartWindow[ButtonIndex] = win;
109 // Send Press/Release message
110 WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed);