2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Window manager core
9 #include <wm_internals.h>
10 #include <wm_messages.h>
11 #include <wm_hotkeys.h>
16 extern tWindow *gpWM_RootWindow;
17 extern 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 = NULL;
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->RealX || X >= win->RealX + win->RealW ) continue;
38 if( Y < win->RealY || Y >= win->RealY + win->RealH ) 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->RealX - win->BorderL;
53 msg.Y = NewY - win->RealY - win->BorderT;
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->RealX - win->BorderL;
68 msg.Y = NewY - win->RealY - win->BorderT;
71 WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
74 void WM_Input_int_SendBtnMsg(tWindow *Win, int X, int Y, int Index, int Pressed)
76 struct sWndMsg_MouseButton msg;
78 msg.X = X - Win->RealX - Win->BorderL;
79 msg.Y = Y - Win->RealY - Win->BorderT;
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);
97 tWindow *tmpwin = win;
100 WM_RaiseWindow(tmpwin);
101 tmpwin = tmpwin->Parent;
105 // Make sure that even if the mouse has moved out of the original window,
106 // mouse release messages reach the window.
107 if( !Pressed && ButtonIndex < MAX_BUTTONS && gpWM_DownStartWindow[ButtonIndex] != win )
109 WM_Input_int_SendBtnMsg(gpWM_DownStartWindow[ButtonIndex], X, Y, ButtonIndex, 0);
111 if( Pressed && ButtonIndex < MAX_BUTTONS )
113 gpWM_DownStartWindow[ButtonIndex] = win;
116 // Send Press/Release message
117 WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed);
120 void WM_Input_KeyDown(uint32_t Character, uint32_t Scancode)
122 struct sWndMsg_KeyAction msg;
124 WM_Hotkey_KeyDown(Scancode);
126 msg.KeySym = Scancode;
127 msg.UCS32 = Character;
128 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYDOWN, sizeof(msg), &msg);
131 void WM_Input_KeyFire(uint32_t Character, uint32_t Scancode)
133 struct sWndMsg_KeyAction msg;
135 // TODO: Properly translate into KeySyms and Unicode
137 msg.KeySym = Scancode;
138 msg.UCS32 = Character;
139 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYFIRE, sizeof(msg), &msg);
142 void WM_Input_KeyUp(uint32_t Character, uint32_t Scancode)
144 struct sWndMsg_KeyAction msg;
146 WM_Hotkey_KeyUp(Scancode);
148 msg.KeySym = Scancode;
149 msg.UCS32 = Character;
150 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYUP, sizeof(msg), &msg);