]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/mou_vnc_ecos.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / mou_vnc_ecos.c
1 //==========================================================================
2 //
3 //      mou_vnc_ecos.c
4 //
5 //
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):    Chris Garry <cgarry@sweeneydesign.co.uk>
44 // Contributors:
45 // Date:         2003-08-22
46 // Purpose:
47 // Description:  Microwindows mouse driver for VNC server on eCos
48 //
49 //####DESCRIPTIONEND####
50 //
51 //========================================================================*/
52
53
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <unistd.h>
57 #include <errno.h>
58 #include <fcntl.h>
59 #include <math.h>
60 #include <sys/ioctl.h>
61 #include <pkgconf/vnc_server.h>  /* CYGDAT_VNC_SERVER_MOUSE_NAME */
62 #include "device.h"
63
64 static int vnc_Open(MOUSEDEVICE *pmd);
65 static void vnc_Close(void);
66 static int vnc_GetButtonInfo(void);
67 static void vnc_GetDefaultAccel(int *pscale,int *pthresh);
68 static int vnc_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb);
69
70 static int mouse_fd = -1;
71
72 /* Hack extern to used when hiding the mouse cursor
73  * There needs to be a better way to do this
74 */
75 extern SCREENDEVICE scrdev;
76
77 MOUSEDEVICE mousedev = {
78     vnc_Open,
79     vnc_Close,
80     vnc_GetButtonInfo,
81     vnc_GetDefaultAccel,
82     vnc_Read,
83     NULL
84 };
85
86
87 static int vnc_Open(MOUSEDEVICE *pmd)
88 {
89     mouse_fd = open(CYGDAT_VNC_SERVER_MOUSE_NAME, O_RDONLY | O_NONBLOCK);
90     if (mouse_fd < 0)
91     {
92         EPRINTF("Error %d opening VNC mouse\n", errno);
93         return -1;
94     }
95
96 //    GdHideCursor(&scrdev);
97     return mouse_fd;
98 }
99
100 static void vnc_Close(void)
101 {
102     /* Close the mouse device. */
103     if (mouse_fd >= 0)
104     {
105         close(mouse_fd);
106     }
107
108     mouse_fd = -1;
109 }
110
111 static int vnc_GetButtonInfo(void)
112 {
113         /* Get mouse buttons supported */
114     return (MWBUTTON_L + MWBUTTON_R);
115 }
116
117 static void vnc_GetDefaultAccel(int *pscale,int *pthresh)
118 {
119         /*
120          * Get default mouse acceleration settings
121          * Just return something inconspicuous for now.
122          */
123 //     diag_printf("Mouse: vnc_GetDefaultAccel()\n");
124         *pscale = 3;
125         *pthresh = 5;
126 }
127
128 static int vnc_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
129 {
130         /* Read a mouse event */
131     cyg_uint8 data[8];
132     int bytes_read;
133
134     bytes_read = read(mouse_fd, data, 8);
135
136     if (bytes_read != sizeof(data))
137     {
138         if (errno == EINTR || errno == EAGAIN)
139         {
140             return 0;
141         }
142         /*
143          * kernel driver bug: select returns read available,
144          * but read returns -1
145          * we return 0 here to avoid GsError above
146          */
147         /*return -1;*/
148
149         return 0;
150     }
151
152     *px = data[2]*256 + data[3];
153     *py = data[4]*256 + data[5];
154     *pb = 0;
155     if (data[1] & 0x01)
156     {
157         *pb += MWBUTTON_L;
158     }
159     if (data[1] & 0x04)
160     {
161         *pb += MWBUTTON_R;
162     }
163
164     *pz = 0;
165
166     return 2;
167
168 #if 0
169     if(! *pb )
170     {
171         return 1;         /* Don't have button data */
172     }
173     else
174     {
175         return 2;         /* Have full set of data */
176     }
177 #endif
178
179 }