aboutsummaryrefslogtreecommitdiff
path: root/man/man3/event.html
blob: 87cff2fd4d85f489d45955ebd3b0a86fd83e0445 (plain)
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<head>
<title>event(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>EVENT(3)</b><td align=right><b>EVENT(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>

    event, einit, estart, estartfn, etimer, eread, emouse, ekbd, ecanread,
    ecanmouse, ecankbd, ereadmouse, eatomouse, eresized, egetrect,
    edrawgetrect, emenuhit, emoveto, esetcursor, Event, Mouse, Menu
    &ndash; graphics events<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>


<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &nbsp;&nbsp;&nbsp;&lt;u.h&gt;<br>
    #include &nbsp;&nbsp;&nbsp;&lt;libc.h&gt;<br>
    #include &nbsp;&nbsp;&nbsp;&lt;draw.h&gt;<br>
    #include &nbsp;&nbsp;&nbsp;&lt;event.h&gt;<br>
    #include &nbsp;&nbsp;&nbsp;&lt;cursor.h&gt;<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;einit(ulong keys)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>ulong &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event(Event *e)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Mouse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;emouse(void)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ekbd(void)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ecanmouse(void)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ecankbd(void)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ereadmouse(Mouse *m)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eatomouse(Mouse *m, char *buf, int n)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>ulong &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;estart(ulong key, int fd, int n)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>ulong &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;estartfn(int id, ulong key, int fd, int n,<br>
     
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            int (*fn)(Event*, uchar*, int))<br>
            
            <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
            
        </table>
        
    </table>
    </font></tt>
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            
            
        </table>
        
    </table>
    <tt><font size=+1>ulong &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etimer(ulong key, int n)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>ulong &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eread(ulong keys, Event *e)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ecanread(ulong keys)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eresized(int new)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Rectangle egetrect(int but, Mouse *m)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edrawgetrect(Rectangle r, int up)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;emenuhit(int but, Mouse *m, Menu *menu)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;emoveto(Point p)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;esetcursor(Cursor *c)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>extern Mouse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*mouse<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>enum{<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            Emouse = 1,<br>
            Ekeyboard = 2,<br>
            
        </table>
        
    </table>
    };<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </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 routines provide an interface to multiple sources of input
    for unthreaded programs. Threaded programs (see <a href="../man3/thread.html"><i>thread</i>(3)</a>) should
    instead use the threaded mouse and keyboard interface described
    in <a href="../man3/mouse.html"><i>mouse</i>(3)</a> and <a href="../man3/keyboard.html"><i>keyboard</i>(3)</a>. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Einit</i> must be called first. If the argument to <i>einit</i> has the <tt><font size=+1>Emouse</font></tt>
    and <tt><font size=+1>Ekeyboard</font></tt> bits set, the mouse and keyboard events will be
    enabled; in this case, <i>initdraw</i> (see <a href="../man3/graphics.html"><i>graphics</i>(3)</a>) must have already
    been called. The user must provide a function called <i>eresized</i>
    to be called whenever the window in which the process
    is running has been resized; the argument <i>new</i> is a flag specifying
    whether the program must call <i>getwindow</i> (see <a href="../man3/graphics.html"><i>graphics</i>(3)</a>) to re-establish
    a connection to its window. After resizing (and perhaps calling
    <i>getwindow</i>), the global variable <tt><font size=+1>screen</font></tt> will be updated to point
    to the new window&#8217;s <tt><font size=+1>Image</font></tt> structure. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    As characters are typed on the keyboard, they are read by the
    event mechanism and put in a queue. <i>Ekbd</i> returns the next rune
    from the queue, blocking until the queue is non-empty. The characters
    are read in raw mode, so they are available as soon as a complete
    rune is typed. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    When the mouse moves or a mouse button is pressed or released,
    a new mouse event is queued by the event mechanism. <i>Emouse</i> returns
    the next mouse event from the queue, blocking until the queue
    is non-empty. <i>Emouse</i> returns a <tt><font size=+1>Mouse</font></tt> structure:<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>struct Mouse<br>
        {<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            int &nbsp;&nbsp;&nbsp;&nbsp;buttons;<br>
            Point xy;<br>
            ulong msec;<br>
            
        </table>
        };<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    <tt><font size=+1>Buttons&amp;1</font></tt> is set when the left mouse button is pressed, <tt><font size=+1>buttons&amp;2</font></tt>
    when the middle button is pressed, and <tt><font size=+1>buttons&amp;4</font></tt> when the right
    button is pressed. The current mouse position is always returned
    in <tt><font size=+1>xy</font></tt>. <tt><font size=+1>Msec</font></tt> is a time stamp in units of milliseconds. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Ecankbd</i> and <i>ecanmouse</i> return non-zero when there are keyboard
    or mouse events available to be read. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Ereadmouse</i> reads the next mouse event from the file descriptor
    connected to the mouse, converts the textual data into a <tt><font size=+1>Mouse</font></tt>
    structure by calling <i>eatomouse</i> with the buffer and count from
    the read call, and returns the number of bytes read, or &ndash;1 for
    an error. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Estart</i> can be used to register additional file descriptors to
    scan for input. 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 conflict with any previous keys. If a zero
    key is given, a key will be allocated and returned. <i>Estartfn</i> is
    similar to <i>estart</i>, but processes the data received by calling
    <i>fn</i> before returning the event to the user. The function <i>fn</i> is
    called with the <tt><font size=+1>id</font></tt> of the event; it should return <tt><font size=+1>id</font></tt> if the event
    is to be passed to the user, <tt><font size=+1>0</font></tt> if it is to be ignored. The variable
    <tt><font size=+1>Event.v
    </font></tt>can be used by <i>fn</i> to attach an arbitrary data item to the returned
    <tt><font size=+1>Event</font></tt> structure. <tt><font size=+1>&nbsp;&nbsp;&nbsp;Ekeyboard</font></tt> and <tt><font size=+1>Emouse</font></tt> are the keyboard and mouse
    event keys. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Etimer</i> starts a repeating timer with a period of <i>n</i> milliseconds;
    it returns the timer event key, or zero if it fails. Only one
    timer can be started. Extra timer events are not queued and the
    timer channel has no associated data. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Eread</i> waits for the next event specified by the mask <i>keys</i> of event
    keys submitted to <i>estart</i>. It fills in the appropriate field of
    the argument <tt><font size=+1>Event</font></tt> structure, which looks like:<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>struct Event<br>
        {<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            int &nbsp;&nbsp;&nbsp;&nbsp;kbdc;<br>
            Mouse mouse;<br>
            int &nbsp;&nbsp;&nbsp;&nbsp;n;<br>
            void &nbsp;&nbsp;&nbsp;*v;<br>
            uchar data[EMAXMSG];<br>
            
        </table>
        };<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    <tt><font size=+1>Data</font></tt> is an array which is large enough to hold a 9P message. <i>Eread</i>
    returns the key for the event which was chosen. For example, if
    a mouse event was read, <tt><font size=+1>Emouse</font></tt> will be returned. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Event</i> waits for the next event of any kind. The return is the
    same as for <i>eread</i>. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    As described in <a href="../man3/graphics.html"><i>graphics</i>(3)</a>, the graphics functions are buffered.
    <i>Event</i>, <i>eread</i>, <i>emouse</i>, and <i>ekbd</i> all cause a buffer flush unless
    there is an event of the appropriate type already queued. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Ecanread</i> checks whether a call to <tt><font size=+1>eread(keys)</font></tt> would block, returning
    0 if it would, 1 if it would not. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Getrect</i> prompts the user to sweep a rectangle. It should be called
    with <i>m</i> holding the mouse event that triggered the <i>egetrect</i> (or,
    if none, a <tt><font size=+1>Mouse</font></tt> with <tt><font size=+1>buttons</font></tt> set to 7). It changes to the sweep
    cursor, waits for the buttons all to be released, and then waits
    for button number <i>but</i> to be pressed, marking the initial
    corner. If another button is pressed instead, <i>egetrect</i> returns
    a rectangle with zero for both corners, after waiting for all
    the buttons to be released. Otherwise, <i>egetrect</i> continually draws
    the swept rectangle until the button is released again, and returns
    the swept rectangle. The mouse structure pointed to by <i>m</i> will
    contain the final mouse event. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Egetrect</i> uses successive calls to <i>edrawgetrect</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>Emenuhit</i> displays a menu and returns a selected menu item number.
    It should be called with <i>m</i> holding the mouse event that triggered
    the <i>emenuhit</i>; it will call <i>emouse</i> to update it. A <tt><font size=+1>Menu</font></tt> is a structure:<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>struct Menu<br>
        {<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            char &nbsp;&nbsp;&nbsp;**item;<br>
            char &nbsp;&nbsp;&nbsp;*(*gen)(int);<br>
            int &nbsp;&nbsp;&nbsp;&nbsp;lasthit;<br>
            
        </table>
        };<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    If <tt><font size=+1>item</font></tt> is nonzero, it should be a null-terminated array of the
    character strings to be displayed as menu items. Otherwise, <tt><font size=+1>gen</font></tt>
    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
    </i>waits until <i>but</i> is released, and then returns the number of the
    selection, or &ndash;1 for no selection. The <i>m</i> argument is filled in
    with the final mouse event. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Emoveto</i> moves the mouse cursor to the position <tt><font size=+1>p</font></tt> on the screen.
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Esetcursor</i> changes the cursor image to that described by the <tt><font size=+1>Cursor</font></tt>
    <i>c</i> (see <a href="../man3/mouse.html"><i>mouse</i>(3)</a>). If <tt><font size=+1>c</font></tt> is nil, it restores the image to the default
    arrow.<br>
    
</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="../man1/rio.html"><i>rio</i>(1)</a>, <a href="../man3/graphics.html"><i>graphics</i>(3)</a>, <a href="../man3/plumb.html"><i>plumb</i>(3)</a>, <a href="../man3/draw.html"><i>draw</i>(3)</a><br>
    
</table>
<p><font size=+1><b>BUGS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Etimer</i> and <i>estart</i> are unimplemented.<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>