include "tk.m"; include "wmclient.m"; wmclient := load Wmclient Wmclient->PATH; Resize, Hide, Help, OK, Plain: con 1 << iota; Appl: con Resize | Hide; init: fn(); makedrawcontext: fn(): ref Draw->Context; window: fn(ctxt: ref Draw->Context, title: string, buts: int): ref Window; snarfput: fn(buf: string); snarfget: fn(): string; Window: adt{ display: ref Draw->Display; r: Draw->Rect; # full rectangle of window, including titlebar. image: ref Draw->Image; screenr: Draw->Rect; ctxt: ref Draw->Wmcontext; focused: int; ctl: chan of string; startinput: fn(w: self ref Window, devs: list of string); wmctl: fn(w: self ref Window, request: string): string; settitle: fn(w: self ref Window, name: string): string; reshape: fn(w: self ref Window, r: Draw->Rect); onscreen: fn(w: self ref Window, how: string); screenr2imager: fn(w: self ref Window, sr: Draw->Rect): Draw->Rect; imager2screenr: fn(w: self ref Window, ir: Draw->Rect): Draw->Rect; pointer: fn(w: self ref Window, p: Draw->Pointer): int; };
Init should be called once to initialise the internal state of wmclient.
Makedrawcontext establishes an initial connection with the window manager, creating a new Draw context suitable for creating new windows. It is only necessary to call this if the application has not already been provided with a context.
Window creates a new window through ctxt and returns it. Title gives a label that will be displayed in the title bar of the window; buts determines which buttons are created in the titlebar, a bitwise combination of the constants Resize, Help, OK, and Hide. If Plain is given, the window is given no decoration at all.
When a window, say w, is first created, its size has not been determined and its image is not yet allocated. W.reshape sets the requested rectangle for the window, (and requests a new image for the window if it has already been made visible), where r gives the requested rectangle of the new image, excluding window decoration, such as the title bar and the window border. An application can use w.screenr2imager to find out the usable rectangle within screen rectangle sr when window decorations are taken into account. W.imager2screenr converts in the other direction. W.screenr contains the current rectangle of the screen containing the window.
W.image holds the window's image when it has been successfully created; w.ctxt holds the window manager context for the window, from which keyboard and mouse events can be received. No such events will be received until w.startinput is called, with a list of devices (e.g. ptr, kbd) to start input for. W.settitle sets the title that is shown on the window's title bar; it can make the window's size (and therefore the window's image) change.
W.ctl is a channel down which requests from the titlebar are sent. Messages received on it should be processed by the application or passed to w.wmctl. Requests are formatted as with quoted in string(2). The messages include:
In order to function correctly, an application should process not only events from the title bar channel, but also events received from the window manager itself (via w.ctxt.ctl), and pointer and keyboard events received from the window manager (via top.ctxt.ptr and top.ctxt.kbd respectively). Control events can be passed to w.wmctl; keyboard events can be processed by the application; pointer events should be passed to w.pointer for processing; if this returns zero, the application should process the pointer event, otherwise the event has been consumed by the titlebar.
When created, the window is not visible; w.onscreen makes it visible, and possibly chooses a position and a size for it. How specifies what sort of placement is required for the window; it can be one of
Snarfget and snarfput retrieve and replace the contents of the window manager's snarf buffer.
WMCLIENT(2 ) | Rev: Tue Mar 31 02:42:39 GMT 2015 |