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 which will recieve the next keyboard event
19 tWindow *gpWM_FocusedWindow;
20 //! Window in which the mouse button was originally pressed
21 tWindow *gpWM_DownStartWindow[MAX_BUTTONS];
24 tWindow *WM_int_GetWindowAtPos(int X, int Y)
26 tWindow *win, *next_win, *ret;
28 next_win = gpWM_RootWindow;
34 for(win = ret->FirstChild; win; win = win->NextSibling)
36 if( !(win->Flags & WINFLAG_SHOW) ) continue ;
37 if( X < win->X || X >= win->X + win->W ) continue;
38 if( Y < win->Y || Y >= win->Y + win->H ) continue;
39 next_win = win; // Overwrite as we want the final rendered window
46 void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY)
48 tWindow *win, *newWin;
49 struct sWndMsg_MouseMove msg;
51 win = WM_int_GetWindowAtPos(OldX, OldY);
52 msg.X = NewX - win->X;
53 msg.Y = NewY - win->Y;
56 WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
58 // If the new coordinates are not in a new window
59 // NOTE: Should this handle crossing over a small window?
61 newWin = WM_int_GetWindowAtPos(NewX, NewY);
62 if(win == newWin) return;
64 // TODO: Send mouseup to match mousedown if the cursor moves out of a window?
67 msg.X = NewX - win->X;
68 msg.Y = NewY - win->Y;
71 WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
74 inline void WM_Input_int_SendBtnMsg(tWindow *Win, int X, int Y, int Index, int Pressed)
76 struct sWndMsg_MouseButton msg;
81 msg.bPressed = !!Pressed;
83 WM_SendMessage(NULL, Win, WNDMSG_MOUSEBTN, sizeof(msg), &msg);
86 void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
90 win = WM_int_GetWindowAtPos(X, Y);
92 // Handle press of primary button to change focus
93 if( ButtonIndex == 0 && Pressed == 1 )
95 _SysDebug("Gave focus to %p", win);
100 // Make sure that even if the mouse has moved out of the original window,
101 // mouse release messages reach the window.
102 if( !Pressed && ButtonIndex < MAX_BUTTONS && gpWM_DownStartWindow[ButtonIndex] != win )
104 WM_Input_int_SendBtnMsg(gpWM_DownStartWindow[ButtonIndex], X, Y, ButtonIndex, 0);
106 if( Pressed && ButtonIndex < MAX_BUTTONS )
108 gpWM_DownStartWindow[ButtonIndex] = win;
111 // Send Press/Release message
112 WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed);
115 // --- Manipulation Functions ---
116 void WM_GiveFocus(tWindow *Destination)
118 struct sWndMsg_Bool _msg;
120 if( gpWM_FocusedWindow == Destination )
124 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_FOCUS, sizeof(_msg), &_msg);
126 WM_SendMessage(NULL, Destination, WNDMSG_FOCUS, sizeof(_msg), &_msg);
128 gpWM_FocusedWindow = Destination;