include "tkclient.m"; tkclient := load Tkclient Tkclient->PATH; Resize, Hide, Help, OK, Plain: con 1 << iota; Appl: con Resize | Hide; init: fn(); makedrawcontext: fn(): ref Draw->Context; toplevel: fn(ctxt: ref Draw->Context, topconfig: string, title: string, buts: int): (ref Tk->Toplevel, chan of string); onscreen: fn(top: ref Tk->Toplevel, how: string); startinput: fn(top: ref Tk->Toplevel, devs: list of string); wmctl: fn(top: ref Tk->Toplevel, request: string): string; settitle: fn(top: ref Tk->Toplevel, name: string): string; handler: fn(top: ref Tk->Toplevel, stop: chan of int); snarfput: fn(buf: string); snarfget: fn(): string;
Init should be called once to initialise the internal state of tkclient.
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.
Toplevel creates a new window through ctxt. Topconfig gives a list of frame(9) options that are applied to the new tk window, as described in tk(2). 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. Toplevel returns a tuple, say (top, ctl), where top is the newly created top level tk window, and ctl is a channel down which requests from the title bar are sent. Messages received on ctl should be processed by the application or passed to the wmctl function. 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 from the Tk toplevel wreq channel, those received from the window manager itself (via top.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 wmctl; pointer and keyboard events should be passed to their respective functions in tk(2).
When created, the window is not visible and will not receive pointer or keyboard events. 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
Startinput informs the window manager that the window is ready to the event types specified in devs. Currently understood are kbd for keyboard events, and ptr for pointer events.
The simplest well-behaved wm (1) client will therefore contain:
(top, ctl) := tkclient->toplevel(ctxt, nil, "My Program", Tkclient->Appl); # ... populate the window with tk widgets tkclient->startinput(top, "ptr" :: "kbd" :: nil); tkclient->onscreen(top, nil); for(;;){ alt{ s := <-ctl or s = <-top.ctxt.ctl or s = <-top.wreq => tkclient->wmctl(top, s); p := <-top.ctxt.ptr => tk->pointer(top, *p); c := <-top.ctxt.kbd => tk->keyboard(top, c); } }
Settitle changes the name displayed in the title bar and the window's name when it is in the task bar.
Snarfget and snarfput retrieve and replace the contents of the window manager's snarf buffer.
TKCLIENT(2 ) | Rev: Thu Feb 15 14:43:27 GMT 2007 |