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,
Mousectl *mc, Keyboardctl *kc, Screen *scr)
These functions access and control a mouse in a multi-threaded environment.
They use the message-passing
interface in the threads library
programs that wish a more event-driven, single-threaded approach should use
The state of the mouse is recorded in a structure,
typedef struct Mouse Mouse;
int buttons; /* bit array: LMR=124 */
records the position of the cursor,
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),
a millisecond time stamp.
returns a structure through which one may access the mouse:
typedef struct Mousectl Mousectl;
Channel *c; /* chan(Mouse) */
Channel *resizec; /* chan(int) */
int mfd; /* to mouse file */
int cfd; /* to cursor file */
int pid; /* of slave proc */
Image* image; /* of associated window/display */
The arguments to
naming the device file connected to the mouse and an
on which the mouse will be visible.
Typically the file is
which requests the default
and the image is the window in which the program is running, held in the variable
after a call to
is set up,
mouse motion will be reported by messages of type
sent on the
Typically, a message will be sent every time a read of
succeeds, which is every time the state of the mouse changes.
When the window is resized, a message is sent on
The actual value sent may be discarded; the receipt of the message
tells the program that it should call
to reconnect to the window.
structure held in the
blocking if the state has not changed since the last
or message sent on the channel.
before blocking, so any buffered graphics requests are displayed.
closes the file descriptors associated with the mouse, kills the slave processes,
and frees the
moves the mouse cursor on the display to the position specified by
sets the image of the cursor to that specified by
is nil, the cursor is set to the default.
The format of the cursor data is spelled out in
and described in
returns the dimensions of a rectangle swept by the user, using the mouse,
in the manner
uses to create a new window.
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.
uses successive calls to
to maintain the red rectangle showing the sweep-in-progress.
The rectangle to be drawn is specified by
parameter says whether to draw (1) or erase (0) the rectangle.
provides a simple menu mechanism.
It uses a
structure defined in
typedef struct Menu Menu;
behaves the same as its namesake
with two exceptions.
First, it uses a
to access the mouse rather than using the event interface;
it creates the menu as a true window on the
permitting the menu to be displayed in parallel with other activities on the display.
creating backing store for the menu, writing the menu directly on the display, and
restoring the display when the menu is removed.
is a multithreded version of the
function described in
it has a optional
argument to create a window. Keyboard input is read from the channel in the