Usermode/axwin2 - Added full mouse/cursor support (no input yet though :)
[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 #define JOY_IOCTL_GETSETAXISLIMIT       6
9 #define JOY_IOCTL_GETSETAXISPOSITION    7
10
11 // === CODE ===
12 int Input_Init(void)
13 {
14         struct {
15                  int    Num, Value;
16         }       num_value;
17
18         // Open mouse for RW
19         giMouseFD = open(gsMouseDevice, 3);
20
21         // Set mouse limits
22         num_value.Num = 0;
23         num_value.Value = giScreenWidth;
24         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
25         num_value.Value = giScreenWidth/2;
26         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
27
28         num_value.Num = 1;
29         num_value.Value = giScreenHeight;
30         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
31         num_value.Value = giScreenHeight/2;
32         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
33
34         return 0;
35 }
36
37 void Input_FillSelect(int *nfds, fd_set *set)
38 {
39         if(*nfds < giTerminalFD)        *nfds = giTerminalFD;
40         if(*nfds < giMouseFD)   *nfds = giMouseFD;
41         FD_SET(giTerminalFD, set);
42         FD_SET(giMouseFD, set);
43 }
44
45 void Input_HandleSelect(fd_set *set)
46 {
47         if(FD_ISSET(giTerminalFD, set))
48         {
49                 uint32_t        codepoint;
50                 if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
51                 {
52                         // oops, error
53                 }
54                 // TODO: pass on to message handler
55                 _SysDebug("Keypress 0x%x", codepoint);
56         }
57
58         if(FD_ISSET(giMouseFD, set))
59         {
60                 struct sMouseInfo {
61                         uint16_t        NAxies;
62                         uint16_t        NButtons;
63                         struct sMouseAxis {
64                                  int16_t        MinValue;
65                                  int16_t        MaxValue;
66                                  int16_t        CurValue;
67                                 uint16_t        CursorPos;
68                         }       Axies[2];
69                         uint8_t Buttons[3];
70                 }       mouseinfo;
71         
72                 seek(giMouseFD, 0, SEEK_SET);
73                 if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) )
74                 {
75                         // Not a 3 button mouse, oops
76                         return ;
77                 }
78
79 //              _SysDebug("sizeof(uint16_t) = %i, sizeof(int16_t) = %i",
80 //                      sizeof(uint16_t), sizeof(int16_t));
81 //              _SysDebug("NAxies=%i,NButtons=%i", mouseinfo.NAxies, mouseinfo.NButtons);
82 //              _SysDebug("offsetof(Axies[0].MinValue) = %i", offsetof(struct sMouseInfo, Axies[0].MinValue));
83 //              _SysDebug("[0] = {MinValue=%i,MaxValue=%i,CurValue=%i}",
84 //                      mouseinfo.Axies[0].MinValue, mouseinfo.Axies[0].MaxValue,
85 //                      mouseinfo.Axies[0].CurValue
86 //                      );
87                 // Handle movement
88                 Video_SetCursorPos( mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos );
89 //              _SysDebug("Cursor to %i,%i", mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos);
90         }
91 }

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