include "sys.m"; include "draw.m"; include "wmsrv.m"; wmsrv := load Wmsrv Wmsrv->PATH; Client, Window: import wmsrv; init: fn(): (chan of (string, chan of (string, ref Draw->Wmcontext)), chan of (ref Client, chan of string), chan of (ref Client, array of byte, Sys->Rwrite)); find: fn(p: Draw->Point): ref Client; top: fn(): ref Client; Window: adt { tag: string; r: Rect; img: ref Image; }; Client: adt { kbd: chan of int; ptr: chan of ref Draw->Pointer; ctl: chan of string; stop: chan of int; images: chan of (ref Draw->Point, ref Draw->Image, chan of int); flags: int; wins: list of ref Window; znext: cyclic ref Client; id: int; window: fn(c: self ref Client, tag: string): ref Window; contains: fn(c: self ref Client, p: Draw->Point): int; setimage: fn(c: self ref Client, tag: string, i: ref Draw->Image): int; setorigin:fn(c: self ref Client, tag: string, o: Draw->Point): int; top: fn(c: self ref Client); bottom: fn(c: self ref Client); remove: fn(w: self ref Client); };
A Client, say c, holds some channels directly equivalent to their Wmcontext namesakes: c.kbd c.ptr, and c.ctl. The behaviour of c.images is described below. Wmsrv starts a new process to mediate interaction between the window manager and its clients; sending a value on c.stop causes this process to exit. C.wins gives the list of all the windows associated with this client; c.flags is not used by wmsrv: it may be used to store arbitrary information; c.id holds a unique identifier for the client; it will be no larger than the largest number of clients that have simultaneously existed; c.znext links clients together by window depth (see top, below).
Init must be called before any other wmsrv function to initialise the wmsrv module. It creates the virtual file /chan/wm, and returns a tuple of channels, say (wm, join, rq). Wm is the channel that should be passed to prospective clients in the Draw->Context structure; communication on this channel is used to establish a new client connection. Join is used to receive notifications of new clients arriving. The tuple received on this channel, say (c, rc) holds the new client, and a channel on which a reply should be sent acknowledging the new client. If the string sent is non-empty, it represents an error message that will be returned to the client, and the client will not be allowed to join. c.ptr, c.kbd, and c.ctl are all direct equivalents of their Wmcontext namesakes; the behaviour of c.images is described below. Rq is used to receive requests made by clients to the window manager by writing to the file /chan/wm. The tuple received on rq, say (c, data, reply) holds the client that is making the request, the data that has been sent, and a channel that can be used (as described in sys-file2chan(2)) to return a reply to the request, The request is conventionally formatted as a utf8-encoded string, holding a list of tokens quoted as described in quoted in string(2).
If the first character of a window-manager request is an exclamation mark (!), it should be a request to change the image of a client's window (or create a new window). In this case, the first three tokens should be the name of the command (starting with an exclamation mark), the tag of the window to which the request refers, and a tag used by clients to match requests to replies. If such a request is allowed to succeed, then clients expect that a new image will be sent to them. The images channel in a client is used to do this (normally accessed through the setimage and setorigin methods, see below). Sending a tuple, say (o, i, rc) on images buffers an image to be returned to the client. If o is non-nil, the request will change the physical origin of i to o, otherwise i gives a new image (its logical origin must match its physical origin). Only one such request is allowed to be outstanding at any one time; the channel passed in rc will yield the value -1 if the image from a previous request has not yet been consumed, in which case the current request should be caused to fail.
Wmsrv can maintain a record of the current windows and their stacking order relative to one other. Top returns a pointer to the client at the top of the stack; the other clients can be accessed, in stacking order, via their znext references. Find finds the top client that has a window containing the point p. Wmsrv provides various Client methods that may be used to help implement a window manager's interface:
WMSRV(2 ) | Rev: Thu Feb 15 14:43:27 GMT 2007 |