changes.ms 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053
  1. .\"<-xtx-*> tbl changes.ms | troff -ms | lp -d stdout
  2. .FP palatino
  3. .ps 9
  4. .nr PS 9
  5. .vs 11
  6. .nr VS 11
  7. .nr dP 1
  8. .nr dV 1p
  9. .nr dT 4m
  10. .nr XT 4
  11. .TL
  12. System and Interface Changes to Inferno
  13. .AU
  14. C H Forsyth
  15. .br
  16. Vita Nuova
  17. .br
  18. forsyth@vitanuova.com
  19. .br
  20. 9 June 2003
  21. .SH
  22. Overview
  23. .LP
  24. This paper describes some of the changes made to Inferno
  25. interfaces as they stood in the published Third Edition manuals,
  26. to form the current Fourth Edition of the system,
  27. and the broad effects on internal and external interfaces.
  28. Changes include: extensions to the Limbo language;
  29. new instructions in Dis and the virtual machine; extra content
  30. in Dis object files; structure of the source tree; configuration of
  31. .CW emu ;
  32. replacement of the window system with changes to the client interface;
  33. commands renamed, replaced, and removed;
  34. revised support for network booting;
  35. 9P2000 becomes the basis for Styx;
  36. a graphics model offering alpha-blended compositing and general pixel structure;
  37. and improvements to Tk.
  38. .NH 1
  39. Limbo
  40. .LP
  41. Exceptions and fixed point have been added to the Limbo language.
  42. They are described in more detail in separate notes by John Firth,
  43. shortly to be available on the Vita Nuova web site
  44. .CW www.vitanuova.com .
  45. Channels can now be buffered.
  46. A form of polymorphism is now available in Limbo.
  47. .NH 2
  48. Exceptions
  49. .LP
  50. Discussion of exceptions will be restricted here to implications for existing source code.
  51. The most obvious changes are that
  52. .CW Sys->rescue ,
  53. .CW Sys->rescued ,
  54. .CW Sys->unrescue
  55. and
  56. .CW Sys->raise
  57. have vanished.
  58. Instead the exception handling is expressed using constructions in the Limbo language.
  59. Named exceptions can be declared and used (these are described in the note by Firth), and
  60. they are declared as part of the type of functions that raise them.
  61. There is also a general `failure' exception that effectively subsumes the old
  62. .CW Sys->rescue
  63. scheme, including run-time errors such as `out of memory' that can happen in almost any function.
  64. Unlike named exceptions a `failure' exception can be raised or caught by any function,
  65. and its value is a string.
  66. The
  67. .CW raise
  68. statement raises an exception.
  69. This is most obvious in commands that wish to produce an `exit status'.
  70. Instead of
  71. .P1
  72. sys->raise("fail:usage");
  73. .P2
  74. one must now write
  75. .P1
  76. raise "fail:usage";
  77. .P2
  78. (That is one of the more common source changes required to Third Edition Limbo commands,
  79. since that was the most common use of exceptions before.)
  80. A block can have an
  81. .CW exception
  82. handler:
  83. .P1
  84. {
  85. a := array[128] of byte;
  86. dosomething(a);
  87. } exception e {
  88. "out of memory:*" =>
  89. sys->print("i need more space: %s\en", e);
  90. "fail:*" =>
  91. sys->print("exit status: %s\en", e);
  92. "*" =>
  93. sys->print("unexpected error: %s\en", e);
  94. raise; # propagate it
  95. }
  96. .P2
  97. If an exception is raised during the execution of the block (including functions it calls),
  98. execution of the block is abandoned, and control transfers to the appropriate exception handler
  99. (which is outside the block).
  100. Because the compiler and run-time system know the scope of the exception,
  101. values such as
  102. .CW a
  103. above are correctly reclaimed on exit from the faulty block.
  104. Unhandled failures are propagated to callers; unhandled named exceptions (currently) become failures.
  105. .LP
  106. A process group can cause unhandled exceptions in any process in the group either to
  107. propagate to all members of the group, or to be propagated to the process group leader
  108. after destroying the other processes in the group.
  109. This makes it easier to program recovery from exceptions within a group of concurrent processes.
  110. For instance, if a process is expected to send to another on a channel, but fails unexpectedly instead
  111. (eg, because memory was exhausted),
  112. instead of leaving the intended recipient blocked on a receive operation, it can be sent
  113. an exception to notify it of the failure of the other process, allowing it to take appropriate recovery action.
  114. (This could sometimes be programmed using the
  115. .CW wait
  116. file of
  117. .I prog (3),
  118. but not always.)
  119. .LP
  120. Exception handling is intended for recovering from disaster.
  121. We still think it is better Limbo style
  122. to use tuples, channels and processes to make ordinary error handling explicit.
  123. The few attempts to use failure exceptions to achieve `pretty' but peculiar control flow have had exactly the usual
  124. effect of making the code hard to follow and error-prone.
  125. .NH 2
  126. Channels
  127. .LP
  128. Buffered channels have been added:
  129. .P1
  130. c := chan [N] of int;
  131. .P2
  132. where
  133. .I N
  134. is an integer value,
  135. creates a channel that will allow up to
  136. .I N
  137. integer values to be sent to it without an intervening receive without blocking the sender.
  138. If
  139. .I N
  140. is zero, the channel is unbuffered, equivalent to plain
  141. .CW "chan of int" ,
  142. and synchronises sender and receiver as before.
  143. .LP
  144. The restriction that a given channel value could not be sent to or received from in two
  145. .CW alt
  146. statements simultaneously has been removed.
  147. .NH 2
  148. Polymorphism
  149. .LP
  150. John Firth has implemented a form of parametric polymorphism in Limbo.
  151. It too will be described in a separate note.
  152. Currently we are still fussing over aspects of the constraint syntax
  153. and some other implications of the most general form, and since some aspects are
  154. therefore subject to change, including syntax, we have not yet published the details.
  155. We think it is possible to use the following subset without having to change the code later:
  156. .IP 1.
  157. Function declarations can be parametrised by one or more type variables:
  158. For example:
  159. .RS
  160. .P1
  161. reverse[T](l: list of T): list of T
  162. {
  163. rl: list of T;
  164. for(; l != nil; l = tl l)
  165. rl = hd l :: rl;
  166. return rl;
  167. }
  168. .P2
  169. Such a function can then be invoked on any compatible set of values.
  170. The function invocation does not specify the type (the compiler does type unification on the parameters).
  171. Thus the above can be used as:
  172. .P1
  173. l1: list of string;
  174. l2: list of ref Item;
  175. l3: list of list of string;
  176. l1 = reverse(l1);
  177. l2 = reverse(l2);
  178. l3 = reverse(l3);
  179. .P2
  180. .RE
  181. .IP 2.
  182. ADTs can also be parametrised:
  183. .P1
  184. Tree: adt[T] {
  185. v: T;
  186. l, r: cyclic ref Tree[T];
  187. };
  188. .P2
  189. allowing declaration of
  190. .CW "Tree[ref Item]"
  191. and
  192. .CW "Tree[string]"
  193. for instance.
  194. .IP 3.
  195. Values of the parametrised type can only be declared, assigned, passed as parameters, returned,
  196. or sent down channels.
  197. The only types that can be used as actual parameter types are reference types (ie,
  198. .CW ref " ADT,"
  199. .CW array ,
  200. .CW chan ,
  201. .CW list
  202. and
  203. .CW module ),
  204. and
  205. .CW string
  206. (which is a value type but is implemented using a reference).
  207. At some point we shall allow a function such as
  208. .CW reverse
  209. above to be invoked with any compatible type (not just reference types) but
  210. that requires changes to Dis and the virtual machine not yet made.
  211. .LP
  212. The formal type parameters can be further constrained by listing a set
  213. of operations that they must have (which currently implies the actual parameters
  214. must be ADT types with compatible operations).
  215. We are not completely happy with the current constraint syntax, and some other
  216. aspects of the scheme, and so that
  217. be described here later once we have settled it.
  218. .NH 1
  219. Dis and virtual machine
  220. .LP
  221. To make the Limbo changes and extensions some new operators were added to
  222. the virtual machine.
  223. (We also added a
  224. .CW casel
  225. operator to allow
  226. .CW case
  227. statements to work on
  228. .CW big
  229. values.)
  230. Modules that have exception handlers also have a (new) exception table,
  231. added to the Dis object format.
  232. Furthermore, we moved the import table used by the
  233. .CW load
  234. operator out of the Dis data space into the object format
  235. (which also makes it available for inspection by
  236. .CW wm/rt
  237. amongst others).
  238. .LP
  239. There is now an internal interface to set conditions under
  240. which modules must be signed to be loaded, and to check a signature on a module.
  241. Appropriate stubs are defined when module signing is not configured; if
  242. .I sign (3)
  243. is configured, however, it replaces them by ones that enforce its signing policy.
  244. .NH 1
  245. Window manager
  246. .LP
  247. The window manager
  248. .I wm (1)
  249. has been reimplemented by Roger Peppe.
  250. It now multiplexes pointer and keyboard input to applications,
  251. and manages windows on the display.
  252. .I Tk (2)
  253. no longer manages windows from inside the kernel.
  254. In some ways the structure is closer to that of
  255. .I mux (1)
  256. and more specifically the design described in Rob Pike's paper ``A Concurrent Window System''.
  257. It is possible to import and export window system environments between hosts.
  258. .LP
  259. This is one of the bigger causes of source file changes, although many of them
  260. can be done by global substitutions (eg, using
  261. .I acme (1)).
  262. Appendix A gives details.
  263. .CW Wmlib
  264. is no longer the application's interface to the window system.
  265. Instead that is done through a new
  266. .CW Tkclient
  267. module; see
  268. .I tkclient (2).
  269. (It uses a different
  270. .CW Wmlib
  271. as an auxiliary module,
  272. and also uses a new
  273. .CW Titlebar
  274. module to allow the look of the window decoration to be changed more easily).
  275. An application acquires a window by a call to
  276. .CW Tkclient->toplevel ;
  277. starts pointer or keyboard input if desired by calling
  278. .CW Tkclient->startinput ;
  279. and puts the window on screen (after sending it Tk configuration commands)
  280. using
  281. .CW Tkclient->onscreen .
  282. Nothing appears on screen until that is called (which amongst other things avoids the resizing on start up that afflicted
  283. the original scheme).
  284. .CW Onscreen
  285. gives it a connection to the window manager for pointer, keyboard and control input,
  286. with a separate channel for each.
  287. When it receives data from any of the channels
  288. (typically using
  289. .CW alt )
  290. it must pass it to Tk using calls to appropriate
  291. .CW Tkclient
  292. functions.
  293. .LP
  294. The toolbar used by the old
  295. .I wm
  296. is now provided by a separate program
  297. .CW wm/toolbar
  298. (see
  299. .I toolbar (1)),
  300. and it is
  301. .CW toolbar
  302. that interprets the
  303. .CW /lib/wmsetup
  304. file.
  305. .CW Wm
  306. invokes
  307. .CW wm/toolbar
  308. by default so most users will see no difference, but it does make it easier to develop alternative interfaces.
  309. More visible is that
  310. .CW wm/logon
  311. is now a
  312. .I client
  313. of the window manager, and must be invoked as follows:
  314. .P1
  315. wm/wm wm/logon
  316. .P2
  317. .LP
  318. Applications need not even use
  319. .I tk (2).
  320. There is an interface for
  321. .CW draw -only
  322. clients,
  323. .I wmclient (2).
  324. .NH 1
  325. Inferno source tree
  326. .LP
  327. The structure of the Inferno source tree has changed in the following ways.
  328. .NH 2
  329. Library source
  330. .LP
  331. The
  332. .CW image
  333. and
  334. .CW memimage
  335. directories have gone, replaced by
  336. .CW libdraw
  337. and
  338. .CW libmemdraw .
  339. The directories in the Inferno root that contain the source for libraries
  340. now
  341. always have names starting `\f5lib\f1':
  342. .CW libcrypt ,
  343. .CW libinterp ,
  344. .CW libkeyring ,
  345. .CW libmath ,
  346. etc.
  347. .NH 2
  348. Emu source
  349. .LP
  350. The
  351. .CW emu
  352. directory now contains a subdirectory structure similar to the
  353. .CW os
  354. kernels, and uses a similar configuration file (parts list) to say what goes in
  355. a given instance of
  356. .CW emu .
  357. This allows platform-dependent selection of drivers, libraries and even
  358. .CW #/
  359. (ie,
  360. .I root (3))
  361. contents to be done easily.
  362. .LP
  363. The top directory,
  364. .CW /emu ,
  365. contains:
  366. .CW mkfile
  367. that simply moves to the platform configured by
  368. .CW /mkconfig ,
  369. allowing builds in the Inferno root as before;
  370. a subdirectory
  371. .CW port
  372. containing portable code (including some code shared by several platforms, such as
  373. .CW devfs-posix.c );
  374. and a subdirectory for each hosting platform, distinguished by an upper-case initial letter.
  375. Current platforms include
  376. .CW FreeBSD ,
  377. .CW Irix ,
  378. .CW Linux ,
  379. .CW Nt
  380. (for all Windows platforms after 95),
  381. .CW Plan9 ,
  382. .CW Solaris ,
  383. and several others.
  384. .NH 2
  385. Emu configuration
  386. .LP
  387. Each platform-specific directory contains a configuration file with the
  388. same structure and indeed similar contents to the ones used for the native kernel.
  389. The default configuration file is called
  390. .CW emu .
  391. Another can be chosen, again in a similar way to the native kernel, by using
  392. .P1
  393. mk 'CONF=\fIcfile\fP'
  394. .P2
  395. where
  396. .I cfile
  397. is the name of the configuration file.
  398. The name of the resulting executable file contains the configuration file name but depends on the platform:
  399. it is \fIcfile\fP\f5.exe\fP on Windows, \f5o.\fP\fIcfile\fP on Unix systems, and \f58.\fP\fIcfile\fP on 386 Plan 9 systems.
  400. The configuration file format and contents is documented for all types of kernels by
  401. .I conf (10.6).
  402. .NH 2
  403. Tk source
  404. .LP
  405. The Tk implementation in
  406. .CW libtk
  407. has been made more modular.
  408. It allows a significantly different `style' to be implemented,
  409. and although that is by no means trivial to do, there is at least an interface to do it.
  410. We hope to change various aspects of the standard style further, but that has not yet been done.
  411. .NH 1
  412. Commands and modules
  413. .LP
  414. There are new commands and library modules, others have become obsolete and been removed,
  415. and a few existing ones have been given new names (typically when ones with similar function have been
  416. collected together).
  417. The biggest change has been to
  418. .I wm (1),
  419. which retains the same name but slightly different invocation and completely different
  420. implementation,
  421. as discussed above.
  422. Here I shall simply note the bigger changes, rather than discuss new functionality.
  423. .NH 2
  424. Renamed commands
  425. .LP
  426. As part of a mild reorganisation of the
  427. .CW /appl
  428. and
  429. .CW /dis
  430. trees, we have moved commands out of
  431. .CW /dis/lib
  432. so that it now contains only library modules except for a few commands left
  433. there temporarily for compatibility.
  434. Commands themselves have sometimes been shuffled to subdirectories,
  435. often copying seemingly better structure from Plan 9,
  436. so that authentication commands are
  437. .CW auth/ ...,
  438. naming service commands are
  439. .CW ndb/ ...,
  440. and
  441. IP-specific commands are
  442. .CW ip/ "... ."
  443. .LP
  444. One noticeable change is that
  445. .CW lib/cs
  446. is now
  447. .CW ndb/cs .
  448. More dramatically, the command
  449. .CW lib/srv
  450. (ie,
  451. .I srv (8))
  452. has been replaced by
  453. .I sh (1)
  454. scripts, all described by
  455. .I svc (8),
  456. that contain appropriate calls to
  457. .I listen (1)
  458. after setting up any locally-desired environment.
  459. .LP
  460. Other commands have also moved:
  461. .IP •
  462. .CW lib/plumber
  463. is now simply
  464. .CW plumber
  465. .IP •
  466. .CW lib/bootp
  467. and
  468. .CW lib/tfptd
  469. have become
  470. .CW ip/bootpd
  471. and
  472. .CW ip/tftpd ,
  473. documented in
  474. .I bootpd (8)
  475. .IP •
  476. .CW lib/virgild
  477. has become
  478. .CW ip/virgild
  479. (see
  480. .I virgild (8))
  481. .IP •
  482. .CW lib/chatsrv ,
  483. .CW lib/rdbgsrv
  484. and
  485. .CW cpuslave
  486. have moved to
  487. .CW auxi
  488. (ie,
  489. .CW /dis/auxi
  490. and
  491. .CW /appl/cmd/auxi)
  492. .IP •
  493. .CW csquery
  494. has become
  495. .CW ndb/csquery
  496. .NH 2
  497. New or newly-documented commands
  498. .IP •
  499. an authentication server (signer) can use
  500. .I keyfs (4)
  501. to store its keys securely in the encrypted file
  502. .CW /keydb/keys
  503. (instead of the unencrypted
  504. .CW /keydb/password ),
  505. and run
  506. .I keysrv (4)
  507. to offer secure change of password remotely.
  508. They are typically started, with other signing services, by
  509. .CW svc/auth
  510. described in
  511. .I svc (8).
  512. .IP •
  513. .CW /dis/auth
  514. and
  515. .CW /appl/cmd/auth
  516. contain commands related to authentication;
  517. they rely on
  518. .I keyfs (4)
  519. in most cases.
  520. The older ones that use
  521. .CW /keydb/passwd
  522. are still in
  523. .CW /dis/lib
  524. and
  525. .CW /appl/lib
  526. during the transition
  527. .IP •
  528. .I dns (8)
  529. has replaced the
  530. .CW lib/ipsrv
  531. implementation of
  532. .I srv (2);
  533. when used, it must be started before
  534. .CW ndb/cs .
  535. .I Srv (2)
  536. has reverted to being a hosted-only interface to the hosting system's native
  537. DNS resolver.
  538. It is automatically used by
  539. .I cs (8)
  540. if it cannot find
  541. .I dns (8),
  542. and
  543. .I dns (8)
  544. will also use it if available before consulting the DNS network.
  545. .IP •
  546. .I chgrp (1),
  547. .I cpuview (1),
  548. .I grid (1),
  549. .I 9660srv (4),
  550. .I cpuslave (4),
  551. .I dossrv (4),
  552. .I keyfs (4),
  553. .I keysrv (4),
  554. .I nsslave (4),
  555. .I palmsrv (4),
  556. .I registry (4),
  557. .I rioimport ,
  558. .I styxchat (1),
  559. .I styxlisten ,
  560. .I wmexport ,
  561. .I wmimport ,
  562. and
  563. .I uniq (1)
  564. are new
  565. .IP •
  566. the multiplayer games software previously in
  567. .CW /appl/games
  568. has been replaced by a related but significantly different system in
  569. .CW /appl/spree .
  570. (Also see
  571. .I spree (2)
  572. for supporting modules.)
  573. .IP •
  574. .I Registry (4)
  575. provides dynamic registration and location of services using sets of attributes/value pairs,
  576. through a name space.
  577. .I Registries (2)
  578. provides a convenient Limbo interface for registration and query.
  579. .NH 2
  580. Commands removed
  581. .IP •
  582. .CW lib/csget
  583. (see
  584. .I cs (8)
  585. for its replacement
  586. .CW csquery )
  587. .IP •
  588. the undocumented and obsolete commands
  589. .CW lib/isrv
  590. and
  591. .CW lib/istyxd
  592. have been removed, since either the
  593. .CW none
  594. authentication protocol, or the
  595. .CW -A
  596. option to
  597. .CW mount
  598. can be used if no authentication is needed
  599. .IP •
  600. .CW lib/srv
  601. has been replaced by
  602. .I svc (8)
  603. as mentioned above.
  604. .IP •
  605. .CW getenv
  606. and
  607. .CW setenv
  608. have been removed since the Shell provides alternatives
  609. .IP •
  610. .CW wm/license
  611. is no longer needed
  612. .NH 2
  613. New modules
  614. .LP
  615. There are library modules to support: registries and configuration files of attribute/value pairs;
  616. Internet address parsing and manipulation; management of windows and subwindows (used by
  617. .I wm (1)
  618. itself); timers; Styx; Styx servers; exception handling; memory
  619. and performance profiling; Freetype interface; parsing Palm databases; and navigating XML files (without reading them all into memory) and interpreting style sheets.
  620. .NH 1
  621. Styx
  622. .LP
  623. Styx was derived from the 9P protocol used by Plan 9 in 1995, with changes that reflected the requirements
  624. of the Inferno project of the time, mainly by removing features that were thought too closely tied to the Plan 9
  625. environment.
  626. Some 9P messages were removed, particularly those
  627. that incorporated details of the Plan 9 authentication methods;
  628. Styx moved authentication outside the file service protocol.
  629. Other changes eliminated file locking and append-only files.
  630. Some restrictions that 9P imposed were retained, however, such as limiting file names to 27 bytes.
  631. This last restriction is fine for synthetic network services, but
  632. has been troublesome when trying to access Unix and Windows systems, amongst others.
  633. .LP
  634. A recent revision of 9P adds support for much longer file names
  635. and takes the opportunity to improve other aspects of the protocol.
  636. It also removes details of authentication algorithms from the protocol.
  637. The Styx implementation now uses the new version of 9P as the default file service protocol.
  638. (It is possible that for interoperation with older Inferno systems the system will be able to
  639. interact with both old and new versions of Styx.)
  640. .NH 2
  641. Protocol changes
  642. .LP
  643. The messages
  644. .CW Tauth
  645. and
  646. .CW Tversion
  647. are new to Styx.
  648. .CW Tversion
  649. includes negotiation (at connection start) of the message size and protocol version;
  650. it also introduces a new session.
  651. .CW Tauth
  652. obtains access to a special authentication file if the server requires
  653. authentication within a Styx session.
  654. .CW Tclone
  655. has been replaced by a more elaborate form of
  656. .CW Twalk
  657. that allows zero to MAXWELEM (16) elements to be walked, perhaps to a new fid, in a single message,
  658. returning a sequence of qid values in
  659. .CW Rwalk .
  660. (A clone is simply a walk of a fid to a new fid with zero elements.)
  661. A walk of several elements can return partial results if the walk of the first element succeeds but
  662. subsequent ones fail.
  663. A partial walk leaves the state of the fids unchanged.
  664. .CW Ropen
  665. and
  666. .CW Rcreate
  667. return a suggested size for atomic I/O on the fid (0 means `not given').
  668. All strings are variable length, and consequently
  669. .CW Twstat
  670. and
  671. .CW Rstat
  672. data is variable length and formatted differently.
  673. Data returned from
  674. .CW Tread
  675. of a directory is similarly changed, because
  676. directory entries are not fixed length.
  677. .CW Tnop
  678. has gone.
  679. .LP
  680. Tags remain 16-bit integers, but fids and counts
  681. become 32-bit integers (mainly of interest to large systems),
  682. and qids have a different structure.
  683. Previously a qid was a pair of 32-bit integers, path and vers, where
  684. path had the top bit set for a directory.
  685. Now a qid is a triple: a 64-bit path, 32-bit vers, and 8-bit type.
  686. The type is defined to be the top 8 bits of the file's mode.
  687. The path does not have the top bit set for a directory, and indeed the
  688. path value is not interpreted by the protocol.
  689. There are now bits in the file mode for append-only and exclusive-use
  690. files (new for Inferno), and for authentication files (new for both Plan 9 and Inferno).
  691. The stat information includes the user name that last caused the file's mtime to be changed.
  692. All strings in the protocol are variable length: file names, attach names, user names, and error text.
  693. .LP
  694. The message format on the wire is significantly different.
  695. The message size is negotiated for a connection by
  696. .CW Tversion ,
  697. and messages can be large, allowing much more data to be sent in single
  698. .CW Twrite
  699. and
  700. .CW Rread
  701. messages.
  702. The header includes a 32-bit message size, making it easy to find message boundaries without
  703. parsing the contents.
  704. Strings are
  705. represented as a 16-bit size followed by the string's UTF-8 encoding (without zero byte).
  706. R-messages do not carry a copy of the fid from the T-message.
  707. Padding bytes have gone.
  708. The order of some fields has changed of course to match message parameter changes.
  709. .LP
  710. Authentication of the connection itself, and optionally
  711. establishing the keys for digesting and encryption,
  712. is done before the protocol starts, in both Inferno and Plan 9.
  713. Details will follow on the protocol for that, and Limbo interfaces.
  714. For now, it can be assumed that the old authentication messages can still be used,
  715. even after a more flexible protocol has been implemented.
  716. .CW Tauth
  717. can be used to authenticate particular accesses within such a session, but
  718. implies trust by the server that the client system will not cheat its users.
  719. (That trust is typically established by the connection level authentication which is needed
  720. anyway for link encryption, and thus for single-user clients further authentication
  721. seems extraneous in most cases.)
  722. Most Inferno services that run as file servers within a system (eg,
  723. .CW 9660srv )
  724. will, like Plan 9's, reply to
  725. .CW Tauth
  726. with an
  727. .CW Rerror
  728. stating ``authentication not required''.
  729. Access to them when exported is typically controlled as now by verifying the incoming connection.
  730. .NH 2
  731. Limbo interface changes
  732. .LP
  733. Because Limbo's interface to file service via
  734. .CW Sys
  735. and other modules uses Limbo
  736. .CW string
  737. for names, and that is inherently
  738. variable length, there are no interface changes required for that aspect of the protocol change,
  739. and consequently no source changes
  740. (in contrast to the introduction of 9P2000 in C implementations).
  741. Similarly the Inferno directory reading interfaces remain unchanged.
  742. .LP
  743. The `directory mode' bit previously called
  744. .CW CHDIR
  745. is now called
  746. .CW DMDIR .
  747. It is used
  748. .I only
  749. in
  750. .CW Dir.mode .
  751. .CW CHDIR
  752. is no longer defined, partly because it was used both
  753. in
  754. .CW Dir.mode
  755. and
  756. .CW Qid.path ,
  757. and the latter instances must change (discussed below).
  758. There are bits (new to Inferno) for
  759. .CW DMAPPEND
  760. (append-only file),
  761. .CW DMEXCL
  762. (exclusive-use file),
  763. and
  764. .CW DMAUTH
  765. (authentication file).
  766. The protocol can return the user name of the user that caused
  767. .CW mtime
  768. to be changed on a file; that is now available as
  769. .CW Dir.muid .
  770. .LP
  771. The structure of
  772. .CW Qid
  773. has changed.
  774. Previously a Qid had a 32-bit
  775. .CW path
  776. and a 32-bit version number,
  777. .CW vers .
  778. The top bit
  779. .CW CHDIR ) (
  780. of
  781. .CW path
  782. was set iff the Qid was that of a directory.
  783. The
  784. .CW path
  785. is now 64 bits (which is
  786. .CW big
  787. in Limbo and
  788. .CW vlong
  789. in the kernel), and there is no longer the convention that the top bit of
  790. .CW path
  791. must be 1 for a directory.
  792. Instead, there is a new, separate
  793. .CW type
  794. field (called
  795. .CW qtype
  796. in Limbo)
  797. that has the value of the top 8 bits of the file's mode.
  798. Each bit \f5DM\fIx\f1 in
  799. .CW Dir.mode ,
  800. has got a corresponding bit \f5QT\fIx\f1
  801. in
  802. .CW Qid.qtype :
  803. .CW QTDIR ,
  804. .CW QTAPPEND ,
  805. .CW QTEXCL
  806. and
  807. .CW QTAUTH .
  808. The bit
  809. .CW QTDIR
  810. .I must
  811. be set in the
  812. .CW Qid.qtype
  813. for a directory, and only then.
  814. There is an extra constant
  815. .CW QTFILE
  816. that is defined to be zero, and is used for clarity when neither
  817. .CW QTDIR
  818. nor
  819. .CW QTAUTH
  820. is set.
  821. .LP
  822. In Styx file servers, changes are required to reflect the slightly different set of message types
  823. and a few new parameters, but the main changes are:
  824. handling zero or more name elements at once in
  825. .CW Twalk
  826. and
  827. .CW Rwalk ;
  828. changing
  829. .CW CHDIR
  830. to
  831. .CW DMDIR
  832. in
  833. .CW Dir.mode
  834. (easy);
  835. the use of the new
  836. .CW Qid.qtype
  837. field
  838. and
  839. .CW QTDIR
  840. instead of
  841. .CW CHDIR
  842. in
  843. .CW Qid.path
  844. (a little more effort);
  845. and (typically) the insertion of casts to force
  846. .CW Qid.path
  847. to
  848. .CW int
  849. and thus ensure the use of 32-bit operations except where 64-bit paths really are needed
  850. (hardly ever in synthetic file servers).
  851. The new modules for use by file servers are discussed in the next section.
  852. .LP
  853. The revised definition of
  854. .CW Twstat
  855. in
  856. .I stat (5),
  857. and thus
  858. .CW sys->wstat ,
  859. provides for ``don't care'' values in
  860. .CW Dir
  861. that are tedious to provide directly; a new adt value
  862. .CW Sys->nulldir
  863. provides the right initial value for a
  864. .CW Dir
  865. which is then changed as needed for
  866. .CW wstat .
  867. .SH
  868. .I "Examples"
  869. .LP
  870. Create a directory:
  871. .P1
  872. \fIold:\f5
  873. fd := sys->create(name, Sys->OREAD, Sys->CHDIR | 8r777);
  874. \fInew:\f5
  875. fd := sys->create(name, Sys->OREAD, Sys->DMDIR | 8r777); # not CHDIR
  876. .P2
  877. .LP
  878. Make Qids
  879. for a file and a directory:
  880. .P1
  881. \fIold:\f5
  882. Qdir, Qdata: con iota;
  883. qd := Sys->Qid(Sys->CHDIR | Qdir, 0);
  884. qf := Sys->Qid(Qdata, 0);
  885. \fInew:\f5
  886. Qdir, Qdata: con iota;
  887. qd := Sys->Qid(big Qdir, 0, Sys->QTDIR);
  888. qf := Sys->Qid(big Qdata, 0, Sys->QTFILE);
  889. .P2
  890. .LP
  891. Test if a file is a directory:
  892. .P1
  893. \fIold:\f5
  894. isdir(d: Sys->Dir): int
  895. {
  896. return (d.mode & Sys->CHDIR) != 0;
  897. \fIOR:\f5
  898. return (d.qid.path & Sys->CHDIR) != 0;
  899. }
  900. \fInew:\f5
  901. isdir(d: Sys->Dir): int
  902. {
  903. return (d.mode & Sys->DMDIR) != 0;
  904. \fIOR:\f5
  905. return (d.qid.qtype & Sys->QTDIR) != 0;
  906. }
  907. .P2
  908. .LP
  909. If one wishes to have values
  910. .CW big
  911. only when required, one can write:
  912. .P1
  913. case int dir.qid.path {
  914. Qdir =>
  915. ...
  916. Qdata =>
  917. ...
  918. Qctl =>
  919. ...
  920. }
  921. .P2
  922. Of course with the Dis change mentioned above,
  923. .CW case
  924. can now be applied to
  925. .CW big
  926. values, so it is no longer necessary to add the cast (as it once was).
  927. Even so, 32-bit operations are faster when they suffice.
  928. .NH 2
  929. Styx protocol in Limbo: Styx and Styxservers
  930. .LP
  931. A new module
  932. .CW Styx ,
  933. defined by
  934. .CW styx.m ,
  935. provides access to the Styx protocol messages, as variants of pick adts
  936. .CW Tmsg
  937. and
  938. .CW Rmsg .
  939. (There was an old, undocumented
  940. .CW Styx
  941. module but this new interface is completely different.)
  942. It is used by several file servers, such as
  943. .CW dossrv ,
  944. .CW cdfs ,
  945. and the new
  946. .CW logfs .
  947. See the attached manual page.
  948. There are several implementations with the same signature, covering different
  949. combinations of old and new Inferno and old and new protocols, through
  950. the same interface.
  951. There are slight differences in the application code for old and new
  952. systems because of the changed
  953. type and structure of
  954. .CW Qid .
  955. The versions that talk the old protocol need to store some internal state,
  956. and are intended only to meet compatibility requirements during the transition.
  957. .LP
  958. Many file service applications, however, serve a simple name space,
  959. requiring more than can be done with
  960. .CW file2chan ,
  961. but wishing some help in handling the protocol details.
  962. Two new modules
  963. .CW Styxservers
  964. and
  965. .CW Nametree
  966. are provided to make such applications easier to write.
  967. They are closely related and thus both modules are defined by
  968. .CW styxservers.m .
  969. .LP
  970. .CW Styxservers
  971. provides help in handling fids and interpreting the Styx requests for navigating a
  972. name space, and provides a reasonable set of default actions,
  973. allowing the application to focus on implementing
  974. read and write access to the files in the name space.
  975. It uses
  976. .CW Styx
  977. to talk to the Styx client on a connection.
  978. It interacts with the application through a channel interface and
  979. the
  980. .CW Navigator
  981. adt to navigate an abstract
  982. representation of the application's name space.
  983. The module can be used on its own, with the application doing the work
  984. of replying to those queries itself, or it can get extra help in the common cases from
  985. .CW Nametree .
  986. .CW Nametree
  987. provides a
  988. .CW Tree
  989. adt and operations for the application to build an abstract representation of a name space
  990. and maintain it dynamically quite simply, and it exports the channel interface used by
  991. .CW Styxservers
  992. for navigation, thus connecting the two, but leaving the application in complete
  993. control of the name space contents viewed by Styx.
  994. See the manual pages
  995. .I styxservers (2)
  996. and
  997. .I styxservers-nametree (2),
  998. attached.
  999. The latter includes a short working example of combining the two modules.
  1000. .LP
  1001. The previous release of the system had a module
  1002. .CW Styxlib
  1003. that combined the functions of
  1004. .CW Styx
  1005. and
  1006. .CW Styxservers .
  1007. It remains for a time for transition, but newer applications should use either
  1008. .CW Styx
  1009. or
  1010. .CW Styxservers .
  1011. .LP
  1012. A new command
  1013. .I styxchat (8)
  1014. exchanges Styx messages with a server, reading a textual representation of T-messages
  1015. on standard input.
  1016. It can be helpful when testing a Styx server implementation.
  1017. (It was originally developed to test the
  1018. .CW Styx
  1019. module implementations in several configurations.)
  1020. See the attached manual page for details.
  1021. It also supports an option that allows it to act as a server,
  1022. printing T-messages as they are received from clients, and
  1023. reading R-messages in a textual form from standard input for replies.
  1024. .NH 2
  1025. Device driver changes
  1026. .LP
  1027. Most of the differences for most drivers are relatively minor
  1028. (in
  1029. .CW diff
  1030. terms).
  1031. .LP
  1032. Throughout the hosted and emulated kernels:
  1033. .IP \(bu
  1034. .CW Qid
  1035. now is the structure:
  1036. .RS
  1037. .P1
  1038. struct Qid {
  1039. vlong path;
  1040. ulong vers;
  1041. uchar type;
  1042. };
  1043. .P2
  1044. The
  1045. .CW type
  1046. field has values
  1047. .CW QTDIR ,
  1048. .CW QTFILE ,
  1049. .CW QTAPPEND ,
  1050. etc.
  1051. The test previously written
  1052. .P1
  1053. if(qid.path & CHDIR)
  1054. .P2
  1055. is now written
  1056. .P1
  1057. if(qid.type & QTDIR)
  1058. .P2
  1059. Because of that change, the various
  1060. .CW switch
  1061. statements in the drivers that previously read
  1062. .P1
  1063. switch(c->qid.path){
  1064. .P2
  1065. or
  1066. .P1
  1067. switch(c->qid.path & ~Sys->CHDIR){
  1068. .P2
  1069. now read
  1070. .P1
  1071. switch((ulong)c->qid.path){
  1072. .P2
  1073. to keep operations to 32 bits (except where otherwise required).
  1074. .RE
  1075. .IP \(bu
  1076. The first entry of a driver's
  1077. .CW Dirtab
  1078. .I must
  1079. be an entry for
  1080. \f5"."\fP,
  1081. if the driver uses
  1082. .CW devgen
  1083. to help implement
  1084. .I walk ,
  1085. .I stat ,
  1086. .I devdirread
  1087. or
  1088. .I open
  1089. operations.
  1090. .IP \(bu
  1091. Offsets passed to the driver's
  1092. .I read
  1093. and
  1094. .I write
  1095. entry points are
  1096. 64-bit
  1097. .CW vlong ,
  1098. not 32-bit
  1099. .CW ulong .
  1100. .IP \(bu
  1101. The
  1102. .I stat
  1103. entry point has an extra buffer size parameter:
  1104. .RS
  1105. .P1
  1106. int \fIxyz\f5stat(Chan *c, uchar *dp, int n)
  1107. .P2
  1108. It also returns an integer: the size of the result.
  1109. .CW Devstat
  1110. accepts the extra parameter and returns an appropriate result:
  1111. .P1
  1112. static int
  1113. \fIxyz\f5stat(Chan *c, uchar *dp, int n)
  1114. {
  1115. return devstat(c, dp, n, rtcdir, nelem(\fIxyz\f5dir), devgen);
  1116. }
  1117. .P2
  1118. .RE
  1119. .IP \(bu
  1120. The biggest change is to
  1121. .I walk .
  1122. It has the signature:
  1123. .RS
  1124. .P1
  1125. Walkqid *\fIxyz\f5walk(Chan *c, Chan *nc, char **names, int nname);
  1126. .P2
  1127. and it allows zero or more elements to be walked in a single call,
  1128. returning its result in a newly-allocated
  1129. .CW Walkqid
  1130. structure:
  1131. .P1
  1132. struct Walkqid {
  1133. Chan* clone;
  1134. int nqid;
  1135. Qid qid[1];
  1136. };
  1137. .P2
  1138. Note that the array
  1139. .CW Walkqid.qid
  1140. must actually hold up to
  1141. .I nname
  1142. Qids, and thus is allocated as follows:
  1143. .P1
  1144. wq = smalloc(sizeof(Walkqid)+(nname-1)*sizeof(Qid));
  1145. .P2
  1146. The driver must take care that the space is reclaimed if
  1147. .CW error
  1148. is called before its
  1149. .I walk
  1150. function returns, by using
  1151. .CW waserror
  1152. as required.
  1153. Fortunately,
  1154. .CW devwalk
  1155. looks after the details of
  1156. .I walk
  1157. and
  1158. .CW walkqid
  1159. for most drivers:
  1160. .P1
  1161. static Walkqid*
  1162. \fIxyz\f5walk(Chan* c, Chan *nc, char** name, int nname)
  1163. {
  1164. return devwalk(c, nc, name, nname, \fIxyz\f5dir,
  1165. nelem(\fIxyz\f5dir), devgen);
  1166. }
  1167. .P2
  1168. .RE
  1169. .IP \(bu
  1170. The
  1171. .I clone
  1172. entry point has gone, since cloning is seen by a driver as a particular form of call to its
  1173. .I walk
  1174. entry,
  1175. where the parameter values satisfy:
  1176. .RS
  1177. .P1
  1178. c != nc && nwname == 0
  1179. .P2
  1180. One difference is that a node can be cloned and walked in a single operation,
  1181. in other words
  1182. .CW nwname
  1183. can be non-zero,
  1184. and the incoming
  1185. .CW nc
  1186. is often nil and a new
  1187. .CW Chan
  1188. must be allocated.
  1189. Note that if the driver found it adequate to call
  1190. .CW devclone
  1191. previously, then
  1192. the new
  1193. .CW devwalk
  1194. will
  1195. generally look after it as well.
  1196. .CW Devclone
  1197. remains for use as a utility function for the few drivers that need to
  1198. clone a channel themselves,
  1199. in their
  1200. .I walk
  1201. operations or elsewhere.
  1202. .RE
  1203. .IP \(bu
  1204. The
  1205. .I detach
  1206. entry has been renamed
  1207. .I shutdown
  1208. (it was never the opposite of
  1209. .I attach ).
  1210. The stub
  1211. .CW devshutdown
  1212. can be used by devices that do not need it.
  1213. .LP
  1214. For drivers that serve a simple name space using the functions of
  1215. .CW dev.c
  1216. (described in
  1217. .I devattach (10.2)),
  1218. only a handful of simple changes are required.
  1219. Most are pointed out by the compilers as type clashes.
  1220. The main exception is the need for a
  1221. .CW Dirtab
  1222. to have its first entry be an entry for \f5"."\fP if the
  1223. .CW Dirtab
  1224. will be passed to
  1225. .CW devgen
  1226. via
  1227. .CW devwalk ,
  1228. .CW devstat
  1229. and
  1230. .CW devdirread .
  1231. .NH 1
  1232. Sys module changes
  1233. .LP
  1234. .NH 2
  1235. Sys: name change(s)
  1236. .LP
  1237. The name
  1238. .CW ERRLEN
  1239. has become
  1240. .CW ERRMAX
  1241. (since it is the limit to any error string, not its necessary length).
  1242. .CW NAMELEN
  1243. has been removed,
  1244. to allow each instance to be found (by compilation) and either removed
  1245. (where it was simply limiting the length of a file name), or replaced by
  1246. .CW NAMEMAX
  1247. where it was used as a buffer size to read in names such as
  1248. .CW /dev/sysname
  1249. or
  1250. .CW /dev/user .
  1251. .NH 2
  1252. Sys: file sizes
  1253. .LP
  1254. The Styx protocol has always supported 64-bit file sizes and file offsets.
  1255. The Inferno interface has not.
  1256. .CW Sys
  1257. has changed so that length and offset values become
  1258. .CW big ,
  1259. specifically:
  1260. file size
  1261. .CW Dir.length ,
  1262. the offset parameter to
  1263. .CW seek ,
  1264. and
  1265. .CW seek 's
  1266. result.
  1267. .LP
  1268. These and the Qid changes account for quite a few changes in
  1269. our own source tree.
  1270. Typically, applications did things like this:
  1271. .P1
  1272. \fIold:\f5
  1273. buf := array[d.length] of byte;
  1274. sys->seek(fd, 0, Sys->SEEKSTART);
  1275. off := sys->seek(fd, 0, Sys->SEEKRELA); rec := off + HDRLEN;
  1276. for(offset := 0; offset < d.length; offset += RECSIZE){
  1277. sys->seek(fd, offset, Sys->SEEKSTART);
  1278. ...
  1279. }
  1280. .P2
  1281. The compiler now objects in each case because
  1282. .CW big
  1283. values are now appearing where
  1284. .CW int
  1285. is required, or conversely.
  1286. In some cases it is obvious that adding a cast is correct;
  1287. in others it is worth considering whether the calculation should indeed
  1288. be
  1289. .CW big
  1290. because file sizes for instance can in practice exceed the range of a
  1291. signed integer without too much trouble today, especially when the `file'
  1292. is a storage device.
  1293. The case that some people like and some dislike is:
  1294. .P1
  1295. if(sys->seek(fd, big offset, Sys->SEEKSTART) < big 0) ...
  1296. .P2
  1297. where the
  1298. .CW "big 0"
  1299. is needed because
  1300. .CW sys->seek
  1301. is
  1302. .CW big ,
  1303. and there are no `usual arithmetic conversions' as in C.
  1304. (Given the tangle that several languages have made of such conversions, perhaps
  1305. being strict is correct.)
  1306. .NH 2
  1307. Sys: export
  1308. .LP
  1309. .CW Sys->export
  1310. now has the signature:
  1311. .P1
  1312. export: fn(c: ref Sys->FD, dir: string, flag: int): int;
  1313. .P2
  1314. allowing a directory
  1315. .I dir
  1316. other than \f5"/"\f1
  1317. to be exported.
  1318. It replaces the
  1319. .CW exportdir
  1320. function of (later) Third Edition.
  1321. .NH 2
  1322. Sys: Styx support
  1323. .LP
  1324. The revision of Styx has caused three calls to be added:
  1325. .P1
  1326. fauth: fn(fd: ref Sys->FD, aname: string): ref Sys->FD;
  1327. fversion: fn(fd: ref Sys->FD, msize: int, version: string): (int, string);
  1328. iounit: fn(fd: ref Sys->FD): int;
  1329. .P2
  1330. .CW Fversion
  1331. initialises a Styx session on connection
  1332. .I fd ,
  1333. sending the message size
  1334. .I msize
  1335. and protocol version string
  1336. .I version ;
  1337. it returns a tuple giving the message size and version returned by the Styx server.
  1338. It is rarely called directly; the
  1339. .CW mount
  1340. operation does it automatically on an uninitialised connection.
  1341. .LP
  1342. .CW Fauth
  1343. sends a Styx
  1344. .CW Tauth
  1345. message on connection
  1346. .I fd ,
  1347. and if successful, returns a file descriptor that
  1348. refers to an authentication file provided by the file server,
  1349. which may be read and written by
  1350. .CW Sys->read
  1351. and
  1352. .CW Sys->write
  1353. to implement the authentication protocol(s) supported by the server.
  1354. .CW Fauth
  1355. is needed only when the server requires authentication.
  1356. .LP
  1357. .CW Iounit
  1358. returns the `atomic IO unit' suggested for the file
  1359. .I fd
  1360. by its file server when it was opened.
  1361. .NH 2
  1362. Sys: mount
  1363. .LP
  1364. The
  1365. .CW mount
  1366. system call has acquired a second file descriptor parameter:
  1367. .P1
  1368. mount: fn(fd: ref Sys->FD, afd: ref Sys->FD, on: string,
  1369. flags: int, spec: string): int;
  1370. .P2
  1371. .I Afd
  1372. is nil if the file server is known not to require authentication within a Styx session.
  1373. (The connection might itself have been authenticated previously, for instance,
  1374. and most file servers such as
  1375. .CW dossrv ,
  1376. .CW ftpfs
  1377. and
  1378. .CW dbfs
  1379. are invoked to provide services to an already-authenticated user, and therefore
  1380. do not require authentication within a session.)
  1381. If the server does require authentication,
  1382. .I afd
  1383. refers to a file descriptor returned by a previous
  1384. .CW fauth
  1385. on connection
  1386. .I fd ,
  1387. on which an authentication protocol has subsequently been executed as required by the file server connected to
  1388. .I fd .
  1389. .NH 2
  1390. Sys: other new system calls
  1391. .LP
  1392. There are two more new system calls:
  1393. .P1
  1394. fd2path: fn(fd: ref Sys->FD): string;
  1395. werrstr: fn(s: string): int;
  1396. .P2
  1397. .CW Fd2path
  1398. returns the path name under which the file descriptor
  1399. .I fd
  1400. was originally opened (if known).
  1401. One result is that
  1402. .I workdir (2)
  1403. produces reasonable results for the name of the current directory
  1404. in the presence of mounts and binds.
  1405. .LP
  1406. .CW Werrstr
  1407. sets the per-process system error string to
  1408. .I s ,
  1409. to allow a Limbo function to save and restore an error string over
  1410. other system calls, to present a similar interface
  1411. as the system calls on errors, or to annotate the error from a system call
  1412. for its own caller.
  1413. .NH 2
  1414. Sys: directory reading
  1415. .LP
  1416. The
  1417. .I sys-dirread (2)
  1418. system call's signature has changed:
  1419. .P1
  1420. dirread: fn(fd: ref Sys->FD): (int, array of Sys->Dir);
  1421. .P2
  1422. Previously it accepted an array of
  1423. .CW Dir
  1424. to fill and returned a count;
  1425. now it returns a tuple containing the count and the array of values read.
  1426. The change was needed because the representation of directory entries
  1427. is now variable length, and it is difficult to limit the number returned
  1428. (it is possible, but all the methods have disadvantages).
  1429. .CW Dirread
  1430. still reads a directory incrementally, requesting a block of directory entries
  1431. of reasonable size from the file server, and unpacking them into the returned array.
  1432. Use
  1433. .I readdir (2)
  1434. to read whole directories at once.
  1435. .NH 1
  1436. Bufio
  1437. .LP
  1438. There are several changes to
  1439. .CW Bufio :
  1440. .P1
  1441. Iobuf: adt {
  1442. ...
  1443. seek: fn(b: self ref Iobuf, n: big, where: int): big;
  1444. offset: fn(b: self ref Iobuf): big;
  1445. };
  1446. # flush: fn(); # deleted
  1447. .P2
  1448. The module-level function
  1449. .CW Bufio->flush
  1450. has been removed
  1451. (\fInot\fP
  1452. .CW Iobuf.flush ),
  1453. to allow concurrent use of a single
  1454. .CW Bufio
  1455. instance; applications must
  1456. .CW close
  1457. or
  1458. .CW flush
  1459. each output file explicitly.
  1460. .LP
  1461. As a result of the change to 64-bit offsets for
  1462. .CW Sys->seek ,
  1463. .CW Iobuf.seek
  1464. also accepts and returns
  1465. .CW big
  1466. offsets.
  1467. .CW Iobuf.offset
  1468. is new, and returns the current file offset in bytes, taking account of any buffering.
  1469. .LP
  1470. .CW Iobuf.flush
  1471. has been extended to flush any data buffered on input files.
  1472. .NH 1
  1473. Draw
  1474. .LP
  1475. The graphics model represented by the
  1476. .I draw (3)
  1477. device and the
  1478. .CW Draw
  1479. module is significantly different, including support for a range of pixel formats,
  1480. and compositing in the drawing operations.
  1481. Most source code that uses Images
  1482. directly will require some changes, but the scope of them is limited: needing only extra
  1483. or different parameter values to individual operations, not radical restructuring.
  1484. The following changes affect most non-Tk graphics application code:
  1485. .IP \(bu
  1486. Pixels in an
  1487. .CW Image
  1488. can now be more than 8 bits and have a more flexible structure
  1489. (eg, several colour channels, and an optional alpha channel, of up to 8 bits each).
  1490. To support that, the old
  1491. .CW ldepth
  1492. field has gone, replaced by a channel descriptor
  1493. .CW chans
  1494. of type
  1495. .CW Chans ,
  1496. which describes the pixel structure, and an integer
  1497. .CW depth
  1498. field, which gives the total pixel size (depth) in bits.
  1499. .IP \(bu
  1500. The colour parameters are now 32-bit RGBA values
  1501. (red, green, blue and alpha components, 8-bit each, and big-endian
  1502. only when an
  1503. .CW int ).
  1504. .IP \(bu
  1505. The graphics subsystem supports Porter-Duff compositing,
  1506. combining a destination image with a source image (within an optional matte)
  1507. according to a compositing operator.
  1508. The interpretation of the old `mask' Image parameter to
  1509. .CW draw
  1510. and
  1511. .CW gendraw
  1512. has changed.
  1513. Previously it provided a simple binary mask;
  1514. it now provides a `matte', and its
  1515. alpha channel shapes the source image and adds partial transparencies.
  1516. If the matte parameter is nil, the source image is used unmodified.
  1517. If it lacks an alpha channel, one is computed from the matte image colour channels.
  1518. The drawing operations
  1519. .CW draw ,
  1520. .CW gendraw ,
  1521. .CW line ,
  1522. .CW text ,
  1523. and so on,
  1524. have all got variants
  1525. .CW drawop ,
  1526. .CW gendrawop ,
  1527. .CW lineop ,
  1528. .CW textop ,
  1529. and so on,
  1530. each taking an extra final parameter that specifies a Porter-Duff
  1531. compositing operator from a set predefined by
  1532. .CW Draw :
  1533. .CW SoverD ,
  1534. .CW SinD ,
  1535. .CW DatopS ,
  1536. and so on.
  1537. In each case,
  1538. .CW S
  1539. refers to the source image (within a matte, if provided), and
  1540. .CW D
  1541. refers to the destination image.
  1542. Most of them are useful only when either or both source or destination images have got
  1543. alpha channels (or a matte is used to shape the source).
  1544. The old function names without the
  1545. .CW op
  1546. suffix use the most common compositing operation
  1547. .CW Draw->SoverD ,
  1548. drawing the source image over the destination,
  1549. taking account of the shaping of the source and destination images by their alpha channels,
  1550. with the source further shaped by the optional matte.
  1551. Thus
  1552. .CW Image.draw
  1553. continues to do the `obvious' thing.
  1554. .IP \(bu
  1555. There are new colour map conversion functions.
  1556. .LP
  1557. The
  1558. .CW Chans
  1559. adt is the following:
  1560. .P1
  1561. Chans: adt
  1562. {
  1563. # interpret standard channel string
  1564. mk: fn(s: string): Chans;
  1565. # standard printable form
  1566. text: fn(c: self Chans): string;
  1567. # equality
  1568. eq: fn(c: self Chans, d: Chans): int;
  1569. # bits per pixel
  1570. depth: fn(c: self Chans): int;
  1571. };
  1572. .P2
  1573. Values are created by
  1574. .CW Chans.mk ,
  1575. which accepts a string that is a sequence of channel descriptors,
  1576. each being a letter representing a channel type followed by an integer giving the channel's size (depth, width) in bits.
  1577. The letters include:
  1578. .CW r ,
  1579. .CW g
  1580. and
  1581. .CW b
  1582. for red, green and blue;
  1583. .CW a
  1584. for alpha;
  1585. .CW k
  1586. (!) for greyscale; and
  1587. .CW x
  1588. for padding (``unspecified'', ``don't care'').
  1589. Thus
  1590. .CW Chans.mk("r8g8b8a8")
  1591. produces a descriptor for a 32-bit pixel with 8-bit colour and alpha components.
  1592. The same descriptor is used in the revised
  1593. .I image (6)
  1594. format, although the older image file format with ldepth only is still recognised.
  1595. Given a Chans value
  1596. .I c ,
  1597. \fIc\fP\f5.text()\fP returns such a descriptor for it as a string.
  1598. .LP
  1599. When
  1600. .CW newimage
  1601. previously was called with a specific value for
  1602. .CW ldepth ,
  1603. an appropriate
  1604. .CW Chans
  1605. value must replace it.
  1606. A few common variants are defined as constants of type
  1607. .CW Chans
  1608. in
  1609. .CW Draw .
  1610. (We extended the Limbo compiler last year to support the use of
  1611. .CW con
  1612. with adt and tuple constants with this use in mind.)
  1613. For example, the value
  1614. .CW Draw->CMAP8
  1615. is the descriptor for the 8-bit deep
  1616. .I rgbv
  1617. colour-mapped Image format previously used by Inferno.
  1618. The list of predefined channels includes:
  1619. .TS
  1620. center;
  1621. cfI cfI cfI cfI
  1622. n lf(CW) n lw(3i) .
  1623. Old ldepth Name Bit depth Description
  1624. 0 GREY1 1 single 1-bit deep greyscale channel
  1625. 1 GREY2 2 single 2-bit deep greyscale
  1626. 2 GREY4 4 single 4-bit deep greyscale
  1627. \- GREY8 8 single 8-bit deep greyscale
  1628. 3 CMAP8 8 single 8-bit deep \fIrgbv\f1 colour-mapped channel
  1629. \- RGB15 15 three channels RGB: r5g5b5
  1630. \- RGB16 16 three channels RGB: r5g6b5
  1631. \- RGB24 24 three channels RGB: r8g8b8
  1632. \- RGBA32 32 four channels: RGB and alpha: r8g8b8a8
  1633. .TE
  1634. .LP
  1635. The use of
  1636. .CW Chans
  1637. instead of
  1638. .CW ldepth
  1639. means that calls to
  1640. .CW Display.newimage
  1641. must be changed.
  1642. For instance:
  1643. .P1
  1644. \fI(old)\f5
  1645. buffer := display.newimage(r.inset(3), t.image.ldepth, 0, Draw->White);
  1646. .P2
  1647. becomes
  1648. .P1
  1649. \fI(new)\f5
  1650. buffer := display.newimage(r.inset(3), t.image.chans, 0, Draw->White);
  1651. .P2
  1652. There is an obvious difference: the
  1653. use of
  1654. .CW t.image.chans
  1655. instead of
  1656. .CW t.image.ldepth
  1657. to create a buffer Image with the same pixel structure as
  1658. .CW t .
  1659. There is, however, another difference.
  1660. The final colour parameter to
  1661. .CW newimage
  1662. is also different in structure: in the new graphics model, it is a 32-bit integer value giving RGBA
  1663. components,
  1664. not a colour map index, and the name
  1665. .CW Draw->White
  1666. has the value
  1667. .CW 16rFFFFFFFF
  1668. not
  1669. .CW 0 .
  1670. Because a symbolic name was used, however, the source need not change.
  1671. As another example,
  1672. .CW Draw->Palegreyblue
  1673. is
  1674. .CW "int 16r4993DDFF" .
  1675. Note the final
  1676. .CW FF
  1677. for the alpha component (creating a fully opaque colour).
  1678. When the top bit is set, the
  1679. .CW int
  1680. cast shown here is needed to force the otherwise
  1681. .CW big
  1682. value to 32 bits.
  1683. .LP
  1684. The values of colour components are now uniformly expressed as
  1685. intensity, so that a pixel with all zero colour components is black and
  1686. one with all colour components at maximum (all ones, full intensity)
  1687. is white.
  1688. The
  1689. .I rgbv
  1690. map has therefore been reversed.
  1691. Given a map index,
  1692. .CW Display.cmap2rgba
  1693. returns the 32-bit RGBA format used as a parameter in other calls.
  1694. All colour components are
  1695. .I linear
  1696. values, as required for compositing to work properly;
  1697. gamma correction is done as required by the display subsystem.
  1698. .LP
  1699. The colour components of a pixel with an alpha component are always
  1700. .I pre-multiplied
  1701. by the alpha value, following Porter and Duff, as further justified by Alvy Ray Smith and Jim Blinn.
  1702. ``Thus a 50% red is
  1703. .CW 16r7F00007F
  1704. not
  1705. .CW 16rFF00007F .''
  1706. The function
  1707. .CW Draw->setalpha
  1708. does the computation.
  1709. .LP
  1710. Because of the changes to colours and the replacement of simple masks by mattes, the Images
  1711. .CW Display.ones
  1712. and
  1713. .CW Display.zeros
  1714. are no longer defined.
  1715. Instead, when they were intended to represent colours, the new Images
  1716. .CW Display.black
  1717. and
  1718. .CW Display.white
  1719. provide the obvious colours.
  1720. When
  1721. .CW ones
  1722. and
  1723. .CW zeros
  1724. were used as masks, the new predefined Images
  1725. .CW Display.opaque
  1726. and
  1727. .CW Display.transparent
  1728. are used instead as constant mattes, with alpha channels (fully opaque and fully transparent, respectively).
  1729. As noted above, where
  1730. .CW Display.ones
  1731. was used as a mask parameter in drawing operations, one can
  1732. simply specify a nil Image as a matte (`no matte') instead.
  1733. (That has been allowed for quite some time and is in use but might not be widely known.)
  1734. .LP
  1735. For example, Charon allocated a mask using:
  1736. .P1
  1737. dpicmask = display.newimage(pic.r, 0, 0, Draw->White);
  1738. .P2
  1739. which becomes
  1740. .P1
  1741. dpicmask = display.newimage(pic.r, Draw->GREY1, 0, Draw->Opaque);
  1742. .P2
  1743. where
  1744. .CW GREY1
  1745. is a constant value of the
  1746. .CW Chans
  1747. adt type, predefined by Draw, for Images that have a single 1-bit deep grey channel (ie, a bitmap).
  1748. (Note that to form a fully-opaque matte,
  1749. .CW Draw->Opaque
  1750. was used for clarity, not
  1751. .CW Draw->White ;
  1752. .CW Draw->Transparent
  1753. could also be used, as the basis for building a matte with transparency.)
  1754. .LP
  1755. A small if obscure change is that
  1756. .CW Display.newwindow
  1757. has a new parameter:
  1758. .P1
  1759. newwindow: fn(screen: self ref Screen, r: Rect,
  1760. backing: int, color: int): ref Image;
  1761. .P2
  1762. The
  1763. .I backing
  1764. parameter should usually be
  1765. .CW Draw->Refbackup ,
  1766. except for windows allocated on an image that already has got backing store
  1767. assigned, for instance because it is an image on a screen on an existing window image, in which case it should be
  1768. .CW Draw->Refnone ,
  1769. because the parent window already provides the backing.
  1770. .LP
  1771. As a small but helpful change, the adt
  1772. .CW Draw->Pointer
  1773. has a new element
  1774. .CW msec
  1775. that reports a
  1776. relative time stamp in milliseconds.
  1777. .LP
  1778. The
  1779. .CW Draw->Context
  1780. content is significantly different, for the benefit of the new
  1781. window system implementation.
  1782. .NH 1
  1783. Tk module
  1784. .LP
  1785. There is a new function in
  1786. .CW Tk :
  1787. .P1
  1788. quote: fn(s: string): string;
  1789. .P2
  1790. .CW Quote
  1791. returns string
  1792. .I s
  1793. quoted according to Tk's `\f5{}\f1' quoting conventions.
  1794. It replaces
  1795. .CW Wmlib->tkquote .
  1796. .LP
  1797. There is a new widget type:
  1798. .I panel (9).
  1799. A panel instance can be packed and otherwise manipulated in the same way as any other Tk widget.
  1800. An image is associated with it by calling
  1801. .CW Tk->putimage
  1802. defined in
  1803. .I tk (2).
  1804. The associated images can be drawn on directly by the application, using all the operations provided by
  1805. .CW Draw .
  1806. The coordinates of the changed rectangle must be given to Tk
  1807. using the
  1808. .CW panel
  1809. widget command
  1810. .CW dirty ;
  1811. that part of the image will be redrawn if necessary at the next Tk
  1812. .CW update .
  1813. A panel has no default bindings.
  1814. See
  1815. .I panel (9)
  1816. for details.
  1817. .LP
  1818. For example,
  1819. .CW wm/coffee
  1820. now uses the following:
  1821. .P1
  1822. r := Rect((0, 0), (400, 300));
  1823. buffer := display.newimage(r, t.image.chans, 0, Draw->Black);
  1824. tk->cmd(t, "panel .f.p -bd 3 -relief flat");
  1825. tk->cmd(t, "pack .f.p -fill both -expand 1");
  1826. tk->cmd(t, "update");
  1827. org := buffer.r.min;
  1828. tk->putimage(t, ".f.p", buffer, nil);
  1829. .P2
  1830. When it has updated the
  1831. .CW buffer ,
  1832. it tells Tk:
  1833. .P1
  1834. tk->cmd(t, ".f.p dirty; update");
  1835. .P2
  1836. In this case the whole image is marked dirty, but
  1837. .CW dirty
  1838. can be given an optional rectangle parameter to restrict redrawing.
  1839. .LP
  1840. .CW Tk->putimage
  1841. and
  1842. .CW Tk->getimage
  1843. replace
  1844. .CW imageput
  1845. and
  1846. .CW imageget .
  1847. .NH 1
  1848. Selectfile, Tabs and Dialog
  1849. .LP
  1850. The functions
  1851. .CW filename ,
  1852. .CW mktabs
  1853. (and
  1854. .CW tabsctl ),
  1855. .CW dialog
  1856. and
  1857. .CW getstring
  1858. have been moved to separate new modules, to allow those aspects of the
  1859. user interface to be changed by replacing the implementations,
  1860. and to allow standard modules to be provided for picking colours (for instance).
  1861. .CW Selectfile
  1862. acquires
  1863. .CW filename ,
  1864. .CW Tabs
  1865. acquires the `tabs' Tk pseudo-widget, and
  1866. .CW Dialog
  1867. acquires
  1868. .CW dialog ,
  1869. which is renamed
  1870. .CW prompt ,
  1871. and
  1872. .CW getstring .
  1873. In cases where the functions took a
  1874. .CW Tk->Toplevel
  1875. as a parameter to specify a
  1876. .CW parent
  1877. window,
  1878. they now take a
  1879. .CW Draw->Context
  1880. and (parent)
  1881. .CW Image
  1882. parameter;
  1883. given a Toplevel
  1884. .CW t ,
  1885. use
  1886. .CW t.image .
  1887. See
  1888. .I dialog (2),
  1889. .I selectfile (2)
  1890. and
  1891. .I tabs (2).
  1892. .TL
  1893. Appendix A: Tk client conversion
  1894. .LP
  1895. .I Wm (1)
  1896. applications now have to feed their own pointer and keyboard
  1897. input to Tk. The window manager is now kept informed about the placement
  1898. of windows.
  1899. .LP
  1900. A Tk toplevel now holds a window manager context:
  1901. .P1
  1902. Wmcontext: adt
  1903. {
  1904. kbd: chan of int; # incoming characters from keyboard
  1905. ptr: chan of ref Pointer; # incoming stream of mouse positions
  1906. ctl: chan of string; # commands from wm to application
  1907. wctl: chan of string; # commands from application to wm
  1908. images: chan of ref Image; # exchange of images
  1909. connfd: ref Sys->FD; # connection control
  1910. ctxt: ref Context;
  1911. };
  1912. .P2
  1913. It contains some channels on which the window manager
  1914. sends information to the application, and a file
  1915. descriptor that can be used to write requests to the window
  1916. manager.
  1917. The channels used directly by the application are:
  1918. .RS
  1919. .IP \f(CWkbd\fP
  1920. characters typed by the user (pass them to
  1921. .CW Tk->pointer )
  1922. .IP \f(CWptr\fP
  1923. pointer events (pass them to
  1924. .CW Tk->keyboard )
  1925. .IP \f(CWctl\fP
  1926. application control requests.
  1927. Passing these to
  1928. .CW Tkclient->wmctl
  1929. will do the default action.
  1930. Requests starting with an exclamation mark
  1931. .CW ! ) (
  1932. can cause the application's image to change.
  1933. .RE
  1934. .LP
  1935. The toplevel also holds a channel
  1936. .CW wreq
  1937. on which it sends application
  1938. control requests; these have the same form as those
  1939. sent on
  1940. .CW Wmcontext.ctl ,
  1941. and can be forwarded to
  1942. .CW Tkclient->wmctl
  1943. in the same way.
  1944. .LP
  1945. Control requests currently understood by
  1946. .I wm (1)
  1947. are:
  1948. .RS
  1949. .IP "\f(CW!reshape \fItag\fP \fIreqid\fP \fIminx\fP \fIminy\fP \fImaxx\fP \fImaxy\fP [\fIhow\fP]\fR
  1950. .br
  1951. Reshape the window referenced by
  1952. .I tag ,
  1953. creating a new image if
  1954. .I tag
  1955. did not previously exist.
  1956. .I Reqid
  1957. is ignored.
  1958. .I How
  1959. can be one of:
  1960. .RS
  1961. .IP \f(CWplace\fP 15
  1962. .I Wm
  1963. attempts to find a suitable patch of screen real estate on which to place
  1964. the window; the size of the given rectangle
  1965. is taken to be the minimum size for that window.
  1966. .IP \f(CWexact\fP
  1967. Reshape to the exact rectangle requested.
  1968. This is the default if
  1969. .I how
  1970. is not given.
  1971. .IP \f(CWonscreen\fP
  1972. The given rectangle is adjusted so that it is no bigger than the available
  1973. screen space, and is entirely on screen.
  1974. .RE
  1975. .IP "\f(CWdelete \fItag\fP\fR
  1976. .br
  1977. Delete the image associated with
  1978. .I tag .
  1979. .IP "\f(CWraise\fP
  1980. .br
  1981. Raise the window
  1982. .IP "\f(CWlower\fP
  1983. .br
  1984. Lower the window
  1985. .IP "\f(CW!move \fItag\fP \fIreqid\fP \fIstartx\fP \fIstarty\fP\fR
  1986. .br
  1987. Request the user to move the window to a new place.
  1988. .I Startx
  1989. and
  1990. .I starty
  1991. are the coordinates of the pointer when the request was initiated.
  1992. .IP "\f(CW!size \fItag\fP\fR
  1993. .br
  1994. Request the user to resize the window.
  1995. .RE
  1996. .LP
  1997. To convert a typical Tk application, do the following.
  1998. .IP 1.
  1999. Use an editor to make the following changes:
  2000. .RS
  2001. .TS
  2002. cfI cfI
  2003. lf(CW) lf(CW) .
  2004. Old New
  2005. Wmlib Tkclient
  2006. wmlib tkclient
  2007. tkclient->titlebar tkclient->toplevel
  2008. tkclient->titlectl tkclient->wmctl
  2009. tkclient->taskbar tkclient->settitle
  2010. tk->imageput tk->putimage
  2011. tk->imageget tk->getimage
  2012. .TE
  2013. .RE
  2014. .IP 2.
  2015. Insert the following code at the top of the central
  2016. .CW alt
  2017. statement.
  2018. The names
  2019. .CW wmctl ' `
  2020. and
  2021. .CW top ` '
  2022. will need changing to the appropriate variables in the program:
  2023. .RS
  2024. .P1
  2025. s := <-top.ctxt.kbd =>
  2026. tk->keyboard(top, s);
  2027. s := <-top.ctxt.ptr =>
  2028. tk->pointer(top, *s);
  2029. s := <-top.ctxt.ctl or
  2030. s = <-top.wreq or
  2031. s = <-wmctl =>
  2032. tkclient->wmctl(top, s);
  2033. .P2
  2034. .RE
  2035. .IP 3.
  2036. Add the following just after the Tk configuration code and
  2037. before the main processing starts:
  2038. .RS
  2039. .P1
  2040. tkclient->onscreen(top, nil);
  2041. tkclient->startinput(top, "kbd"::"ptr"::nil);
  2042. .P2
  2043. This is possibly the easiest part to forget.
  2044. .RE
  2045. .LP
  2046. Be careful of cases where a blocking function is called
  2047. from the main loop that relies on keyboard/mouse input.
  2048. The easiest solution can be to spawn a thread to handle the
  2049. keyboard and mouse independently.