Usermode - Switched to the POSIX read()/write() argument order
[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
15         // Open mouse for RW
16         giMouseFD = open(gsMouseDevice, 3);
17
18         // Set mouse limits
19         num_value.Num = 0;
20         num_value.Value = giScreenWidth;
21         ioctl(giMouseFD, 6, &num_value);
22
23         num_value.Num = 1;
24         num_value.Value = giScreenHeight;
25         ioctl(giMouseFD, 6, &num_value);
26
27         return 0;
28 }
29
30 void Input_FillSelect(int *nfds, fd_set *set)
31 {
32         if(*nfds < giTerminalFD)        *nfds = giTerminalFD;
33         if(*nfds < giMouseFD)   *nfds = giMouseFD;
34         FD_SET(giTerminalFD, set);
35         FD_SET(giMouseFD, set);
36 }
37
38 void Input_HandleSelect(fd_set *set)
39 {
40         if(FD_ISSET(giTerminalFD, set))
41         {
42                 uint32_t        codepoint;
43                 if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
44                 {
45                         // oops, error
46                 }
47                 // TODO: pass on to message handler
48                 _SysDebug("Keypress 0x%x", codepoint);
49         }
50
51         if(FD_ISSET(giMouseFD, set))
52         {
53                 struct sMouseInfo {
54                         uint16_t        NAxies, NButtons;
55                         struct sMouseAxis {
56                                  int16_t        MinValue, MaxValue;
57                                  int16_t        CurValue;
58                                 uint16_t        CursorPos;
59                         }       Axies[2];
60                         uint8_t Buttons[3];
61                 }       mouseinfo;
62         
63                 _SysDebug("Cursor event");
64
65                 seek(giMouseFD, 0, SEEK_SET);   
66                 if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) )
67                 {
68                         // Not a 3 button mouse, oops
69                         return ;
70                 }
71                 
72                 // Handle movement
73 //              Video_SetCursorPos( mouseinfo.Axies[0], mouseinfo.Axies[1] );
74                 _SysDebug("Cursor to %i,%i\n", mouseinfo.Axies[0], mouseinfo.Axies[1]);
75         }
76 }

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