AxWin2 - Added mouse support (well, it now reads the mouse state)
[tpg/acess2.git] / Usermode / Applications / axwin2_src / WM / input.c
1 /*
2  * Acess GUI (AxWin) Version 2
3  * By John Hodge (thePowersGang)
4  */
5 #include "common.h"
6 #include <acess/sys.h>
7
8 // === CODE ===
9 int Input_Init(void)
10 {
11         struct {
12                  int    Num, Value;
13         }       num_value;
14         giMouseFD = open(gsMouseDevice, 3);
15
16         num_value.Num = 0;
17         num_value.Value = giScreenWidth;
18         ioctl(giMouseFD, 6, &num_value);
19
20         num_value.Num = 1;
21         num_value.Value = giScreenHeight;
22         ioctl(giMouseFD, 6, &num_value);
23
24         return 0;
25 }
26
27 void Input_FillSelect(int *nfds, fd_set *set)
28 {
29         if(*nfds < giTerminalFD)        *nfds = giTerminalFD;
30         if(*nfds < giMouseFD)   *nfds = giMouseFD;
31         FD_SET(giTerminalFD, set);
32         FD_SET(giMouseFD, set);
33 }
34
35 void Input_HandleSelect(fd_set *set)
36 {
37         if(FD_ISSET(giTerminalFD, set))
38         {
39                 uint32_t        codepoint;
40                 if( read(giTerminalFD, sizeof(codepoint), &codepoint) != sizeof(codepoint) )
41                 {
42                         // oops, error
43                 }
44                 // TODO: pass on to message handler
45                 _SysDebug("Keypress 0x%x", codepoint);
46         }
47
48         if(FD_ISSET(giMouseFD, set))
49         {
50                 struct sMouseInfo {
51                         uint16_t        NAxies, NButtons;
52                         struct sMouseAxis {
53                                  int16_t        MinValue, MaxValue;
54                                  int16_t        CurValue;
55                                 uint16_t        CursorPos;
56                         }       Axies[2];
57                         uint8_t Buttons[3];
58                 }       mouseinfo;
59         
60                 _SysDebug("Cursor event");
61
62                 seek(giMouseFD, 0, SEEK_SET);   
63                 if( read(giMouseFD, sizeof(mouseinfo), &mouseinfo) != sizeof(mouseinfo) )
64                 {
65                         // Not a 3 button mouse, oops
66                         return ;
67                 }
68                 
69                 // Handle movement
70 //              Video_SetCursorPos( mouseinfo.Axies[0], mouseinfo.Axies[1] );
71                 _SysDebug("Cursor to %i,%i\n", mouseinfo.Axies[0], mouseinfo.Axies[1]);
72         }
73 }

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