1 /* $Id: mouse.h,v 1.1 2003/07/31 01:35:51 fredette Exp $ */
2 
3 /* tme/generic/mouse.h - header file for generic mouse support: */
4 
5 /*
6  * Copyright (c) 2003 Matt Fredette
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Matt Fredette.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _TME_GENERIC_MOUSE_H
37 #define _TME_GENERIC_MOUSE_H
38 
39 #include <tme/common.h>
40 _TME_RCSID("$Id: mouse.h,v 1.1 2003/07/31 01:35:51 fredette Exp $");
41 
42 /* includes: */
43 #include <tme/element.h>
44 
45 /* macros: */
46 
47 /* modifiers: */
48 #define TME_MOUSE_BUTTON_0		TME_BIT(0)
49 #define TME_MOUSE_BUTTON_1		TME_BIT(1)
50 #define TME_MOUSE_BUTTON_2		TME_BIT(2)
51 #define TME_MOUSE_BUTTON_3		TME_BIT(3)
52 #define TME_MOUSE_BUTTON_4		TME_BIT(4)
53 
54 /* units: */
55 #define TME_MOUSE_UNITS_UNKNOWN		(0)
56 
57 /* mouse controls: */
58 #define TME_MOUSE_CTRL_OK_READ		TME_BIT(0)
59 
60 /* the undefined event time: */
61 #define TME_MOUSE_EVENT_TIME_UNDEF		(0)
62 
63 /* this evaluates to nonzero iff a buffer is empty: */
64 #define tme_mouse_buffer_is_empty(b)		\
65   ((b)->tme_mouse_buffer_head			\
66    == ((b)->tme_mouse_buffer_tail))
67 
68 /* this evaluates to nonzero iff a buffer is full: */
69 #define tme_mouse_buffer_is_full(b)		\
70   ((((b)->tme_mouse_buffer_head + 1)		\
71     & ((b)->tme_mouse_buffer_size - 1))		\
72    == (b)->tme_mouse_buffer_tail)
73 
74 /* types: */
75 
76 /* a mouse event: */
77 struct tme_mouse_event {
78 
79   /* the button mask: */
80   unsigned int tme_mouse_event_buttons;
81 
82   /* the X and Y deltas, and the units they are in: */
83   int tme_mouse_event_delta_x;
84   int tme_mouse_event_delta_y;
85   unsigned int tme_mouse_event_delta_units;
86 
87   /* the time of the event: */
88   tme_uint32_t tme_mouse_event_time;
89 };
90 
91 /* a mouse buffer.  it is assumed that the user provides locking: */
92 struct tme_mouse_buffer {
93 
94   /* the buffer size.  this must always be a power of two: */
95   unsigned int tme_mouse_buffer_size;
96 
97   /* the head and tail pointers: */
98   unsigned int tme_mouse_buffer_head;
99   unsigned int tme_mouse_buffer_tail;
100 
101   /* the buffered events: */
102   struct tme_mouse_event *tme_mouse_buffer_events;
103 };
104 
105 /* a mouse connection: */
106 struct tme_mouse_connection {
107 
108   /* the generic connection side: */
109   struct tme_connection tme_mouse_connection;
110 
111   /* this is called when control lines change: */
112   int (*tme_mouse_connection_ctrl) _TME_P((struct tme_mouse_connection *,
113 					      unsigned int));
114 
115   /* this is called to read an event: */
116   int (*tme_mouse_connection_read) _TME_P((struct tme_mouse_connection *,
117 					   struct tme_mouse_event *,
118 					   unsigned int));
119 };
120 
121 /* prototypes: */
122 struct tme_mouse_buffer *tme_mouse_buffer_new _TME_P((unsigned int));
123 void tme_mouse_buffer_destroy _TME_P((struct tme_mouse_buffer *));
124 int tme_mouse_buffer_copyin _TME_P((struct tme_mouse_buffer *,
125 				    _tme_const struct tme_mouse_event *));
126 int tme_mouse_buffer_copyout _TME_P((struct tme_mouse_buffer *,
127 				     struct tme_mouse_event *,
128 				     unsigned int));
129 
130 #endif /* !_TME_GENERIC_MOUSE_H */
131