146 lines · 5.7 KB · Text
RawDownload
= wmclient:  makedrawcontext, window, snarfput, snarfget: window manager interface for Draw-based applications.     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;    }; The Wmclient module provides routines for making windows con‐trolled  by  wm(1)  containing  an image that can be drawn onwith the routines described in draw-image(2). Init should be called once to initialise the  internal  stateof wmclient. 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. Window creates a new window  through  ctxt  and  returns  it.Title  gives  a label that will be displayed in the title barof the window; buts determines which buttons are  created  inthe  titlebar, a bitwise combination of the constants Resize,Help, OK, and Hide.  If Plain is given, the window  is  givenno decoration at all. When a window, say w, is first created, its size has not beendetermined and its image is  not  yet  allocated.   W.reshapesets  the requested rectangle for the window, (and requests anew image for the window if it has already  been  made  visi‐ble), where r gives the requested rectangle of the new image,excluding window decoration, such as the title  bar  and  thewindow  border.   An  application can use w.screenr2imager tofind out the usable rectangle within screen rectangle sr whenwindow  decorations are taken into account.  W.imager2screenrconverts in the other direction.  W.screenr contains the cur‐rent rectangle of the screen containing the window. W.image  holds  the  window's image when it has been success‐fully created; w.ctxt holds the window  manager  context  forthe  window,  from  which  keyboard  and  mouse events can bereceived.  No such events will be received until w.startinputis  called,  with a list of devices (e.g.  ptr, kbd) to startinput for.  W.settitle sets the title that is  shown  on  thewindow's title bar; it can make the window's size (and there‐fore the window's image) change. W.ctl is a channel down which requests from the titlebar  aresent.   Messages  received  on  it should be processed by theapplication or passed to w.wmctl.  Requests are formatted  aswith quoted in string(2).  The messages include: exit   The  window  should  be closed.  W.wmctl will kill all       processes 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 mindx mindy       The user wishes to resize the window.  Mindx and mindy       give the minimum size acceptable for the window. help   The help button has been clicked. ok     The OK  button has been clicked. hide   The Hide button has been clicked.  W.wmctl will delete       the window, and an entry will be shown on the toolbar. In order to function correctly, an application should processnot only events from the title bar channel, but  also  eventsreceived from the window manager itself (via w.ctxt.ctl), andpointer and keyboard events received from the window  manager(via  top.ctxt.ptr  and  top.ctxt.kbd respectively).  Controlevents can be passed to w.wmctl; keyboard events can be  pro‐cessed by the application; pointer events should be passed tow.pointer for processing; if this returns zero, the  applica‐tion  should  process  the pointer event, otherwise the eventhas been consumed by the titlebar. When created, the window is not visible; w.onscreen makes  itvisible,  and  possibly chooses a position and a size for it.How specifies what sort of placement is required for the win‐dow; it can be one 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. 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/wmclient.b == see ALSOwm(1), tk(2)