139 lines · 5.0 KB · Text
RawDownload
= tkclient: makedrawcontext, toplevel, onscreen, startinput, wmctl, settitle, handler, snarfput, snarfget: window manager interface for Tk applications.     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; The Tkclient module provides routines for making windows con‐trolled by wm(1) containing tk(2) widgets. Init should be called once to initialise the  internal  stateof tkclient. Makedrawcontext  establishes  an  initial connection with thewindow manager, creating a new Draw context suitable for cre‐ating  new  windows. It is only necessary to call this if theapplication has not already been provided with a context. Toplevel creates a new window through ctxt.  Topconfig  givesa  list  of  frame(9)  options that are applied to the new tkwindow, as described in tk(2).  Title gives a label that willbe  displayed in the title bar of the window; buts determineswhich buttons are created in the titlebar, a bitwise combina‐tion  of  the constants Resize, Help, OK, and Hide.  If Plainis given, the window is given no decoration at all.  Toplevelreturns  a tuple, say (top, ctl), where top is the newly cre‐ated top level tk window, and ctl is  a  channel  down  whichrequests  from  the title bar are sent.  Messages received onctl should be processed by the application or passed  to  thewmctl  function.  Requests  are  formatted  as with quoted instring(2).  The messages include: exit   The window should be closed.  Wmctl will kill all pro‐       cesses in the current process group. !move x y       The user has started to try to drag the window.  X and       y give the location of the initial pointer click. !size  The user wishes to resize the window. help   The help button has been clicked. ok     The OK  button has been clicked. hide   The Hide button has been clicked.  The window will  be       deleted, and an entry shown on the toolbar. In order to function correctly, an application should processnot only events from the title bar channel, but  also  eventsfrom  the  Tk  toplevel wreq channel, those received from thewindow manager itself (via  top.ctxt.ctl),  and  pointer  andkeyboard   events  received  from  the  window  manager  (viatop.ctxt.ptr and top.ctxt.kbd respectively).  Control  eventscan be passed to wmctl; pointer and keyboard events should bepassed to their respective functions in tk(2). When created, the window is not visible and will not  receivepointer  or  keyboard events.  Onscreen makes it visible, andpossibly chooses a position and a size for it.  How specifieswhat  sort of placement is required for the window; it can beone of place  tries to choose a suitable place on  the  screen  with       respect to other windows; it may size the window as it       feels appropriate. This the default (if how is nil). onscreen       tries to keep the position and size the same as speci‐       fied  on  the window, adjusting them only to bring the       window fully on screen, and making sure that the  win‐       dow is no bigger than the entire display. exact  does  not change the specified size or position of the       window unless absolutely necessary. Startinput informs the window  manager  that  the  window  isready to the event types specified in devs.  Currently under‐stood are kbd  for  keyboard  events,  and  ptr  for  pointerevents. The  simplest  well-behaved wm (1) client will therefore con‐tain:      (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  thewindow's name when it is in the task bar. Snarfget  and  snarfput  retrieve and replace the contents ofthe window manager's snarf buffer. == files/chan/snarf       snarf buffer maintained by wm(1) /chan/wm       channel for interaction with wm(1) == source/appl/lib/tkclient.b == see ALSOwm(1), tk(2)