initmouse, readmouse, closemouse, moveto, getrect, drawgetrect,
menuhit, setcursor, enter – mouse control|
Mousectl *initmouse(char *file, Image *i)
int readmouse(Mousectl *mc)
void closemouse(Mousectl *mc)
void moveto(Mousectl *mc, Point pt)
void setcursor(Mousectl *mc, Cursor *c)
Rectangle getrect(int but, Mousectl *mc)
void drawgetrect(Rectangle r, int up)
int menuhit(int but, Mousectl *mc, Menu *menu, Screen *scr)
int enter(char *ask, char *buf, int len,
These functions access and control a mouse in a multi–threaded
environment. They use the message–passing Channel interface in
the threads library (see thread(2)); programs that wish a more
event–driven, single–threaded approach should use event(2). |
The state of the mouse is recorded in a structure, Mouse, defined
The routine initmouse returns a structure through which one may
access the mouse:
Once the Mousectl is set up, mouse motion will be reported by messages of type Mouse sent on the Channel Mousectl.c. Typically, a message will be sent every time a read of /dev/mouse succeeds, which is every time the state of the mouse changes.
When the window is resized, a message is sent on Mousectl.resizec. The actual value sent may be discarded; the receipt of the message tells the program that it should call getwindow (see graphics(2)) to reconnect to the window.
Readmouse updates the Mouse structure held in the Mousectl, blocking if the state has not changed since the last readmouse or message sent on the channel. It calls flushimage (see graphics(2)) before blocking, so any buffered graphics requests are displayed.
Closemouse closes the file descriptors associated with the mouse, kills the slave processes, and frees the Mousectl structure.
Moveto moves the mouse cursor on the display to the position specified by pt.
Setcursor sets the image of the cursor to that specified by c. If c is nil, the cursor is set to the default. The format of the cursor data is spelled out in <cursor.h> and described in graphics(2).
Getrect returns the dimensions of a rectangle swept by the user, using the mouse, in the manner rio(1) or sam(1) uses to create a new window. The but 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.
Getrect uses successive calls to drawgetrect to maintain the red rectangle showing the sweep–in–progress. The rectangle to be drawn is specified by rc and the up parameter says whether to draw (1) or erase (0) the rectangle.
Menuhit provides a simple menu mechanism. It uses a Menu structure
defined in <mouse.h>:
Enter is a multithreaded version of the eenter function described in event(2). Like menuhit, it has an optional scr argument to create a window. Keyboard input is read from the channel in the Keyboardctl *kc argument (see keyboard(2)).
graphics(2), draw(2), event(2), keyboard(2), thread(2).|