8f51703a2741613251f605c88df2104999bc1e2a
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / wm_input.c
1 /*
2  * Acess2 Window Manager v3
3  * - By John Hodge (thePowersGang)
4  *
5  * wm.c
6  * - Window manager core
7  */
8 #include <common.h>
9 #include <wm_internals.h>
10 #include <wm_messages.h>
11
12 // === IMPORTS ===
13 extern tWindow  *gpWM_RootWindow;
14
15 // === CODE ===
16 tWindow *WM_int_GetWindowAtPos(int X, int Y)
17 {
18         tWindow *win, *next_win, *ret;
19         
20         next_win = gpWM_RootWindow;
21
22         while(next_win)
23         {
24                 ret = next_win;
25                 next_win = NULL;
26                 for(win = ret->FirstChild; win; win = win->NextSibling)
27                 {
28                         if( !(win->Flags & WINFLAG_SHOW) )      continue ;
29                         if( X < win->X || X >= win->X + win->W )        continue;
30                         if( Y < win->Y || Y >= win->Y + win->H )        continue;
31                         next_win = win; // Overwrite as we want the final rendered window
32                 }
33         }
34         
35         return ret;
36 }
37
38 void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY)
39 {
40         // TODO: Mouse motion events
41         // TODO: Send mouseup to match mousedown if the cursor moves out of a window?
42 }
43
44 void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
45 {
46         tWindow *win = WM_int_GetWindowAtPos(X, Y);
47         struct sWndMsg_MouseButton      msg;    
48
49         // Send Press/Release message
50         msg.X = X - win->X;
51         msg.Y = Y - win->Y;
52         msg.Button = ButtonIndex;
53         msg.bPressed = !!Pressed;
54         
55         WM_SendMessage(NULL, win, WNDMSG_MOUSEBTN, sizeof(msg), &msg);
56 }
57

UCC git Repository :: git.ucc.asn.au