File: event.3

package info (click to toggle)
9term 1.6.6-5
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 2,340 kB
  • ctags: 2,035
  • sloc: ansic: 17,308; makefile: 220; sh: 178
file content (288 lines) | stat: -rw-r--r-- 5,872 bytes parent folder | download | duplicates (17)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
.de F
.B
.if !"\\$1"" \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6
..
.de L
.B
.if !"\\$1"" \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6
..
.de FR
.BR "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de LR
.BR "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de CW
.ft B
..
.\" This is gross but it avoids relying on internal implementation details
.\" of the -man macros.
.de TF
.IP "" \w'\fB\\$1\ \ \fP'u
.PD0
..
.de EX
.CW
.nf
..
.de EE
.fi
..
.\" delete above this point if your system has F, L, FR, LR, CW and TF macros
.TH EVENT 3G
.SH NAME
event, einit, estart, etimer, eread, emouse, ekbd, ecanread, ecanmouse, ecankbd, ereshaped, getrect, menuhit, Event, Mouse, Menu \- graphics events
.SH SYNOPSIS
.nf
.B
#include <libc.h>
.B
#include <libg.h>
.PP
.ta \w'\fLunsigned long 'u
.PP
.B
void	einit(ulong keys)
.PP
.B
unsigned long	event(Event *e)
.PP
.B
Mouse	emouse(void)
.PP
.B
int	ekbd(void)
.PP
.B
int	ecanmouse(void)
.PP
.B
int	ecankbd(void)
.PP
.B
unsigned long	estart(ulong key, int fd, int n)
.PP
.B
unsigned long	etimer(ulong key, int n)
.PP
.B
unsigned long	eread(ulong keys, Event *e)
.PP
.B
int	ecanread(ulong keys)
.PP
.B
void	ereshaped(Rectangle r)
.PP
.B
Rectangle	getrect(int but, Mouse *m)
.PP
.B
int	menuhit(int but, Mouse *m, Menu *menu)
.PP
.ft L
enum{
	Emouse = 1,
	Ekeyboard = 2,
}
.ft P
.fi
.SH DESCRIPTION
These routines provide an interface to multiple sources of input.
To use them,
.I einit
must be called.
If the argument to
.I enit
has the
.B Emouse
and
.B Ekeyboard
bits set,
the mouse and keyboard events will be enabled;
in this case,
.IR xtbinit
(see
.IR graphics (3))
must have already been called.
The user must provide a function called
.IR ereshaped ,
which will be called whenever the window in which the process
is running has been reshaped; the argument will be the Rectangle
for the new window shape, including the border.
.PP
As characters are typed on the keyboard, they are read by the
event mechanism and put in a queue.
.I Ekbd
returns the next character from the queue, blocking until the
queue is non-empty.
The characters are read by the event mechanism from the keyboard
so they are available as soon as they are typed.
.PP
When the mouse moves or a mouse button is depressed or released,
a new mouse event is queued by the event mechanism.
.I Emouse
returns the next mouse event from the queue, blocking until the
queue is non-empty.
.I Emouse
returns a
.B Mouse
structure:
.IP
.EX
.ta 6n +\w'unsigned long 'u
struct Mouse
{
	int	buttons;
	Point	xy;
	unsigned long msec;
};
.EE
.PP
.B Buttons
is a bit field;
.B buttons&1
is set when the left mouse button is depressed,
.B buttons&2
when the middle button is depressed,
and
.B buttons&4
when the right button is depressed.
The current mouse position is always returned in
.BR xy .
.BR Msec
is the time stamp of the mouse event in units of milliseconds.
.PP
.I Ecankbd
and
.I ecanmouse
return non-zero when there are keyboard or mouse events to available
to be read.
.PP
.I Estart
can be used to register additional file descriptors.
It takes as arguments the file descriptor to register,
the maximum length of an event message on that descriptor,
and a key to be used in accessing the event.
The key must be a power of 2 and must not confilict with any previous keys.
If a zero key is given, one which is not used will be chosen and returned.
.B
Ekeyboard
and
.B Emouse
are the mouse and keyboard event keys.
.PP
.I Etimer
starts a repeating timer with a period of n milliseconds (default 1 second).
Only one timer can be started.
Extra timer events are not queued and the timer channel has no associated data.
.PP
.I Eread
waits for the next event specified by the mask
.B keys
of event keys submitted to estart.
It fills in the appropriate field of the argument
.B Event
structure, which looks like:
.IP
.EX
struct Event
{
	int	kbdc;
	Mouse	mouse;
	int	n;
	uchar	data[EMAXMSG];
}
.EE
.PP
.B Data
is an array which is large enough to hold a plan 9 protocol message.
.I Eread
returns the key for the event which was chosen.
For example, if a mouse event was read,
.I Emouse
will be returned.
.PP
.I Event
waits for the next event of any kind.
The return is the same as for
.IR eread .
.PP
As described in
.IR graphics (3),
the graphics functions are buffered.
.IR Event ,
.IR eread ,
.IR emouse ,
and
.I ekbd
all cause a buffer flush unless there is an event of the
appropriate type ready to return.
.PP
.I Getrect
is used to prompt the user to sweep a rectangle.
It should be called with
.I m
holding the mouse event that triggered the
.I getrect
(or, if none, a
.B Mouse
with
.B buttons
set to 7).
It changes to the sweep cursor,
waits for the buttons to all go up,
and then waits for button number
.I but
to be depressed, marking the initial corner.
If another button is depressed instead,
.I getrect
returns a rectangle
with zero for both x-coordinates, after
waiting for all the buttons to be released.
Otherwise,
.I getrect
continually draws the swept rectangle
until the button is released again, and returns the swept rectangle.
The mouse structure pointed to by
.I m
will contain the final mouse event.
.PP
.I Menuhit
displays a menu and returns a seleced menu item number.
It should be called with
.I m
holding the mouse event that triggered the
.I menuhit .
A
.B Menu
is a structure:
.IP
.EX
struct Menu
{
	char	**item;
	char	*(*gen)(int);
	int	lasthit;
}
.EE
.PP
If
.B item
is nonzero, it should be a null-terminated array of the character strings
to be displayed as menu items.
Otherwise,
.B gen
should be a function that, given an item number, returns the character
string for that item, or zero if the number is past the end of the list.
Items are numbered starting at zero.
.I Menuhit
waits until
.I but
is released, and then returns the number of the selection,
or \(mi1 for no selection.
The
.I m
argument is filled in with the final mouse event.
.SH "SEE ALSO"
.IR graphics (3).