1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
<head>
<title>mouse(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>MOUSE(3)</b><td align=right><b>MOUSE(3)</b>
<tr><td width=20><td colspan=2>
<br>
<p><font size=+1><b>NAME </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
initmouse, readmouse, closemouse, moveto, cursorswitch, getrect,
drawgetrect, menuhit, setcursor – mouse control<br>
</table>
<p><font size=+1><b>SYNOPSIS </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>#include <u.h><br>
#include <libc.h><br>
#include <draw.h><br>
#include <thread.h><br>
#include <mouse.h><br>
#include <cursor.h><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>Mousectl *initmouse(char *file, Image *i)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>int readmouse(Mousectl *mc)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>int atomouse();<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void closemouse(Mousectl *mc)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void moveto(Mousectl *mc, Point pt)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void setcursor(Mousectl *mc, Cursor *c)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>Rectangle getrect(int but, Mousectl *mc)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void drawgetrect(Rectangle r, int up)<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>int menuhit(int but, Mousectl *mc, Menu *menu, Screen *scr)<br>
</font></tt>
</table>
<p><font size=+1><b>DESCRIPTION </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
These functions access and control a mouse in a multi-threaded
environment. They use the message-passing <tt><font size=+1>Channel</font></tt> interface in
the threads library (see <a href="../man3/thread.html"><i>thread</i>(3)</a>); programs that wish a more
event-driven, single-threaded approach should use <a href="../man3/event.html"><i>event</i>(3)</a>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
The state of the mouse is recorded in a structure, <tt><font size=+1>Mouse</font></tt>, defined
in <tt><font size=+1><mouse.h></font></tt>:<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>typedef struct Mouse Mouse;<br>
struct Mouse<br>
{<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
int buttons; /* bit array: LMR=124 */<br>
Point xy;<br>
ulong msec;<br>
</table>
};<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
</table>
The <tt><font size=+1>Point xy</font></tt> records the position of the cursor, <tt><font size=+1>buttons</font></tt> the state
of the buttons (three bits representing, from bit 0 up, the buttons
from left to right, 0 if the button is released, 1 if it is pressed),
and <tt><font size=+1>msec</font></tt>, a millisecond time stamp.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
The routine <tt><font size=+1>initmouse</font></tt> returns a structure through which one may
access the mouse:<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>typedef struct Mousectl Mousectl;<br>
struct Mousectl<br>
{<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
Mouse;<br>
Channel *c; /* chan(Mouse)[16] */<br>
Channel *resizec; /* chan(int)[2] */<br>
char *file;<br>
int mfd; /* to mouse file */<br>
int cfd; /* to cursor file */<br>
int pid; /* of slave proc */<br>
Image* image; /* of associated window/display */<br>
</table>
};<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
</table>
The arguments to <i>initmouse</i> are a <i>file</i> naming the device file connected
to the mouse and an <i>Image</i> (see <a href="../man3/draw.html"><i>draw</i>(3)</a>) on which the mouse will
be visible. Typically the file is nil, which requests the default
<tt><font size=+1>/dev/mouse</font></tt>; and the image is the window in which the program is
running, held in the variable <tt><font size=+1>screen</font></tt> after a call
to <i>initdraw</i>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Once the <tt><font size=+1>Mousectl</font></tt> is set up, mouse motion will be reported by
messages of type <tt><font size=+1>Mouse</font></tt> sent on the <tt><font size=+1>Channel Mousectl.c</font></tt>. Typically,
a message will be sent every time a read of <tt><font size=+1>/dev/mouse</font></tt> succeeds,
which is every time the state of the mouse changes.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
When the window is resized, a message is sent on <tt><font size=+1>Mousectl.resizec</font></tt>.
The actual value sent may be discarded; the receipt of the message
tells the program that it should call <tt><font size=+1>getwindow</font></tt> (see <a href="../man3/graphics.html"><i>graphics</i>(3)</a>)
to reconnect to the window.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Readmouse</i> updates the <tt><font size=+1>Mouse</font></tt> structure held in the <tt><font size=+1>Mousectl</font></tt>, blocking
if the state has not changed since the last <i>readmouse</i> or message
sent on the channel. It calls <tt><font size=+1>flushimage</font></tt> (see <a href="../man3/graphics.html"><i>graphics</i>(3)</a>) before
blocking, so any buffered graphics requests are displayed.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Closemouse</i> closes the file descriptors associated with the mouse,
kills the slave processes, and frees the <tt><font size=+1>Mousectl</font></tt> structure.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Moveto</i> moves the mouse cursor on the display to the position specified
by <i>pt</i>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Setcursor</i> sets the image of the cursor to that specified by <i>c</i>.
If <i>c</i> is nil, the cursor is set to the default. The format of the
cursor data is spelled out in <tt><font size=+1><cursor.h></font></tt> and described in <a href="../man3/graphics.html"><i>graphics</i>(3)</a>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Getrect</i> returns the dimensions of a rectangle swept by the user,
using the mouse, in the manner <a href="../man1/rio.html"><i>rio</i>(1)</a> or <a href="../man1/sam.html"><i>sam</i>(1)</a> uses to create
a new window. The <i>but</i> argument specifies which button the user
must press to sweep the window; any other button press cancels
the action. The returned rectangle is all zeros if the user
cancels.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Getrect</i> uses successive calls to <i>drawgetrect</i> to maintain the red
rectangle showing the sweep-in-progress. The rectangle to be drawn
is specified by <i>rc</i> and the <i>up</i> parameter says whether to draw (1)
or erase (0) the rectangle.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Menuhit</i> provides a simple menu mechanism. It uses a <tt><font size=+1>Menu</font></tt> structure
defined in <tt><font size=+1><mouse.h></font></tt>:<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>typedef struct Menu Menu;<br>
struct Menu<br>
{<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
char **item;<br>
char *(*gen)(int);<br>
int lasthit;<br>
</table>
};<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
</table>
<i>Menuhit</i> behaves the same as its namesake <i>emenuhit</i> described in
<a href="../man3/event.html"><i>event</i>(3)</a>, with two exceptions. First, it uses a <tt><font size=+1>Mousectl</font></tt> to access
the mouse rather than using the event interface; and second, it
creates the menu as a true window on the <tt><font size=+1>Screen</font></tt> <i>scr</i> (see <a href="../man3/window.html"><i>window</i>(3)</a>),
permitting the menu to be displayed in parallel
with other activities on the display. If <i>scr</i> is null, <i>menuhit</i>
behaves like <i>emenuhit</i>, creating backing store for the menu, writing
the menu directly on the display, and restoring the display when
the menu is removed.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</table>
<p><font size=+1><b>SOURCE </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>/usr/local/plan9/src/libdraw<br>
</font></tt>
</table>
<p><font size=+1><b>SEE ALSO </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<a href="../man3/graphics.html"><i>graphics</i>(3)</a>, <a href="../man3/draw.html"><i>draw</i>(3)</a>, <a href="../man3/event.html"><i>event</i>(3)</a>, <a href="../man3/keyboard.html"><i>keyboard</i>(3)</a>, <a href="../man3/thread.html"><i>thread</i>(3)</a>.<br>
</table>
<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>
|