991b74eebd0341bb0849ae94dd2788f4927d81c6
[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         tWindow *win, *newWin;
41         struct sWndMsg_MouseMove        msg;
42         
43         win = WM_int_GetWindowAtPos(OldX, OldY);
44         msg.X = NewX - win->X;
45         msg.Y = NewY - win->Y;
46         msg.dX = NewX - OldX;
47         msg.dY = NewY - OldY;
48         WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
49         
50         // If the new coordinates are not in a new window
51         // NOTE: Should this handle crossing over a small window?
52         // - Nah, no need
53         newWin = WM_int_GetWindowAtPos(NewX, NewY);
54         if(win == newWin)       return;
55
56         // TODO: Send mouseup to match mousedown if the cursor moves out of a window?
57
58         win = newWin;
59         msg.X = NewX - win->X;
60         msg.Y = NewY - win->Y;
61         msg.dX = NewX - OldX;
62         msg.dY = NewY - OldY;
63         WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
64 }
65
66 void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
67 {
68         tWindow *win = WM_int_GetWindowAtPos(X, Y);
69         struct sWndMsg_MouseButton      msg;    
70
71         // Send Press/Release message
72         msg.X = X - win->X;
73         msg.Y = Y - win->Y;
74         msg.Button = ButtonIndex;
75         msg.bPressed = !!Pressed;
76         
77         WM_SendMessage(NULL, win, WNDMSG_MOUSEBTN, sizeof(msg), &msg);
78 }
79

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