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->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 - win->BorderL;
53 msg.Y = NewY - win->Y - 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->X - win->BorderL;
68 msg.Y = NewY - win->Y - 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->X - Win->BorderL;
79 msg.Y = Y - Win->Y - 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);
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 void WM_Input_KeyDown(uint32_t Character, uint32_t Scancode)
117 struct sWndMsg_KeyAction msg;
119 WM_Hotkey_KeyDown(Scancode);
121 msg.KeySym = Scancode;
122 msg.UCS32 = Character;
123 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYDOWN, sizeof(msg), &msg);
126 void WM_Input_KeyFire(uint32_t Character, uint32_t Scancode)
128 struct sWndMsg_KeyAction msg;
130 // TODO: Properly translate into KeySyms and Unicode
132 msg.KeySym = Scancode;
133 msg.UCS32 = Character;
134 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYFIRE, sizeof(msg), &msg);
137 void WM_Input_KeyUp(uint32_t Character, uint32_t Scancode)
139 struct sWndMsg_KeyAction msg;
141 WM_Hotkey_KeyUp(Scancode);
143 msg.KeySym = Scancode;
144 msg.UCS32 = Character;
145 WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYUP, sizeof(msg), &msg);