1*426d2b71SDavid du Colombier.HTML "8½, the Plan 9 Window System 2219b2ee8SDavid du Colombier.TL 3219b2ee8SDavid du Colombier8½, the Plan 9 Window System 4219b2ee8SDavid du Colombier.AU 5219b2ee8SDavid du ColombierRob Pike 67dd7cddfSDavid du Colombierrob@plan9.bell-labs.com 7219b2ee8SDavid du Colombier.AB 8219b2ee8SDavid du Colombier.FS 9219b2ee8SDavid du ColombierOriginally appeared, in a slightly different form, in 10219b2ee8SDavid du Colombier.I 11219b2ee8SDavid du ColombierProc. of the Summer 1991 USENIX Conf., 12219b2ee8SDavid du Colombier.R 13219b2ee8SDavid du Colombierpp. 257-265, 147dd7cddfSDavid du ColombierNashville. 157dd7cddfSDavid du ColombierNote that 167dd7cddfSDavid du Colombier.CW 8½ 177dd7cddfSDavid du Colombierhas been replaced by 187dd7cddfSDavid du Colombier.CW rio 197dd7cddfSDavid du Colombier(see 207dd7cddfSDavid du Colombier.I rio (1)). 21219b2ee8SDavid du Colombier.FE 22219b2ee8SDavid du ColombierThe Plan 9 window system, 8½, is a modest-sized program of novel design. 23219b2ee8SDavid du ColombierIt provides textual I/O and bitmap graphic services to both 24219b2ee8SDavid du Colombierlocal and remote client programs by offering a multiplexed file service to those clients. 25219b2ee8SDavid du ColombierIt serves traditional UNIX files like 26219b2ee8SDavid du Colombier.CW /dev/tty 27219b2ee8SDavid du Colombieras well as more unusual ones that provide access to the mouse 28219b2ee8SDavid du Colombierand the raw screen. 29219b2ee8SDavid du ColombierBitmap graphics operations are provided by serving a file called 30219b2ee8SDavid du Colombier.CW /dev/bitblt 31219b2ee8SDavid du Colombierthat interprets client messages to perform raster operations. 32219b2ee8SDavid du ColombierThe file service that 8½ offers its clients is identical to that it uses for 33219b2ee8SDavid du Colombierits own implementation, so it is fundamentally no more than 34219b2ee8SDavid du Colombiera multiplexer. 35219b2ee8SDavid du ColombierThis architecture has some rewarding symmetries and can be implemented 36219b2ee8SDavid du Colombiercompactly. 37219b2ee8SDavid du Colombier.AE 38219b2ee8SDavid du Colombier.SH 39219b2ee8SDavid du ColombierIntroduction 40219b2ee8SDavid du Colombier.PP 41219b2ee8SDavid du ColombierIn 1989 I constructed a toy window system from only a few hundred 42219b2ee8SDavid du Colombierlines of source code using a custom language and an unusual architecture 43219b2ee8SDavid du Colombierinvolving concurrent processes [Pike89]. 44219b2ee8SDavid du ColombierAlthough that system was rudimentary at best, it demonstrated that 45219b2ee8SDavid du Colombierwindow systems are not inherently complicated. 46219b2ee8SDavid du ColombierThe following year, for the new Plan 9 distributed system [Pike92], I applied some of 47219b2ee8SDavid du Colombierthe lessons from that toy project to write, in C, 48219b2ee8SDavid du Colombiera production-quality window system 49219b2ee8SDavid du Colombiercalled 8½. 50219b2ee8SDavid du Colombier8½ provides, on black-and-white, grey-scale, or color displays, 51219b2ee8SDavid du Colombierthe services required of a modern window system, including 52219b2ee8SDavid du Colombierprogrammability and support for remote graphics. 53219b2ee8SDavid du ColombierThe entire system, including the default program that runs in the 54219b2ee8SDavid du Colombierwindow \(em the equivalent of 55219b2ee8SDavid du Colombier.CW xterm 56219b2ee8SDavid du Colombier[Far89] with `cutting and pasting' between windows \(em 57219b2ee8SDavid du Colombieris well under 90 kilobytes of text on a Motorola 68020 processor, about 58219b2ee8SDavid du Colombierhalf the size of the 59219b2ee8SDavid du Colombieroperating system 60219b2ee8SDavid du Colombierkernel that supports it and a tenth the size of the X server 61219b2ee8SDavid du Colombier[Sche86] 62219b2ee8SDavid du Colombier.I without 63219b2ee8SDavid du Colombier.CW xterm . 64219b2ee8SDavid du Colombier.PP 65219b2ee8SDavid du ColombierWhat makes 8½ so compact? Much of the saving comes from overall simplicity: 66219b2ee8SDavid du Colombier8½ has little graphical fanciness, a concise programming interface, and 67219b2ee8SDavid du Colombiera simple, fixed user interface. 68219b2ee8SDavid du Colombier8½ also makes some decisions by fiat 69219b2ee8SDavid du Colombier\(em three-button mouse, overlapping windows, built-in terminal program and 70219b2ee8SDavid du Colombierwindow manager, etc. \(em 71219b2ee8SDavid du Colombierrather than trying to appeal to all tastes. 72219b2ee8SDavid du ColombierAlthough compact, 8½ is not ascetic. 73219b2ee8SDavid du ColombierIt provides the fundamentals and 74219b2ee8SDavid du Colombierenough extras to make them comfortable to use. 75219b2ee8SDavid du ColombierThe most important contributor to its small size, though, is its 76219b2ee8SDavid du Colombieroverall design as a file server. 77219b2ee8SDavid du ColombierThis structure may be applicable to window systems 78219b2ee8SDavid du Colombieron traditional UNIX-like operating systems. 79219b2ee8SDavid du Colombier.PP 80219b2ee8SDavid du ColombierThe small size of 8½ does not reflect reduced functionality: 81219b2ee8SDavid du Colombier8½ provides service roughly equivalent to the X window system. 82219b2ee8SDavid du Colombier8½'s clients may of course be as complex as they choose, 83219b2ee8SDavid du Colombieralthough the tendency to mimic 8½'s design 84219b2ee8SDavid du Colombierand the clean programming interface means they 85219b2ee8SDavid du Colombierare not nearly as bloated as X applications. 86219b2ee8SDavid du Colombier.SH 87219b2ee8SDavid du ColombierUser's Model 88219b2ee8SDavid du Colombier.PP 89219b2ee8SDavid du Colombier8½ turns the single screen, mouse, and keyboard of the terminal 90219b2ee8SDavid du Colombier(in Plan 9 terminology) or workstation (in commercial terminology) into an array 91219b2ee8SDavid du Colombierof independent virtual terminals that may be textual terminals supporting a shell and 92219b2ee8SDavid du Colombierthe usual suite of tools 93219b2ee8SDavid du Colombieror graphical applications using the full power of the bitmap screen and mouse. 94219b2ee8SDavid du ColombierText is represented in UTF, an encoding of the Unicode Standard [Pike93]. 95219b2ee8SDavid du ColombierThe entire programming interface is provided through 96219b2ee8SDavid du Colombierreading and writing files in 97219b2ee8SDavid du Colombier.CW /dev . 98219b2ee8SDavid du Colombier.PP 99219b2ee8SDavid du ColombierPrimarily for reasons of history and familiarity, 100219b2ee8SDavid du Colombierthe general model and appearance of 8½ are similar to those of 101219b2ee8SDavid du Colombier.CW mux 102219b2ee8SDavid du Colombier[Pike88]. 103219b2ee8SDavid du ColombierThe right button has a short menu for controlling window creation, destruction, 104219b2ee8SDavid du Colombierand placement. 105219b2ee8SDavid du ColombierWhen a window is created, it runs the default shell, 106219b2ee8SDavid du Colombier.CW rc 107219b2ee8SDavid du Colombier[Duff90], with standard input 108219b2ee8SDavid du Colombierand output directed to the window and accessible through the file 109219b2ee8SDavid du Colombier.CW /dev/cons 110219b2ee8SDavid du Colombier(`console'), 111219b2ee8SDavid du Colombieranalogous to the 112219b2ee8SDavid du Colombier.CW /dev/tty 113219b2ee8SDavid du Colombierof UNIX. 114219b2ee8SDavid du ColombierThe name change represents a break with the past: Plan 9 does not provide a 115219b2ee8SDavid du ColombierTeletype-style model of terminals. 8½ provides the only way 116219b2ee8SDavid du Colombiermost users ever access Plan 9. 117219b2ee8SDavid du Colombier.PP 118219b2ee8SDavid du ColombierGraphical applications, 119219b2ee8SDavid du Colombierlike ordinary programs, 120219b2ee8SDavid du Colombiermay be run by typing their names 121219b2ee8SDavid du Colombierto the shell running in a window. 122219b2ee8SDavid du ColombierThis runs the application in the same window; 123219b2ee8SDavid du Colombierto run the application in a new window one may use an external program, 124219b2ee8SDavid du Colombier.CW window , 125219b2ee8SDavid du Colombierdescribed below. 126219b2ee8SDavid du ColombierFor graphical applications, the virtual terminal model 127219b2ee8SDavid du Colombieris extended somewhat to allow programs to perform graphical operations, 128219b2ee8SDavid du Colombieraccess the 129219b2ee8SDavid du Colombiermouse, and perform related functions by reading and writing files with 130219b2ee8SDavid du Colombiersuggestive names such as 131219b2ee8SDavid du Colombier.CW /dev/mouse 132219b2ee8SDavid du Colombierand 133219b2ee8SDavid du Colombier.CW /dev/window 134219b2ee8SDavid du Colombiermultiplexed per-window 135219b2ee8SDavid du Colombiermuch like 136219b2ee8SDavid du Colombier.CW /dev/cons . 137219b2ee8SDavid du ColombierThe implementation and semantics of these files, 138219b2ee8SDavid du Colombierdescribed below, is central to the structure of 8½. 139219b2ee8SDavid du Colombier.PP 140219b2ee8SDavid du ColombierThe default program that runs in a window is familiar to users of Blit terminals [Pike83]. 141219b2ee8SDavid du ColombierIt is very similar to that of 142219b2ee8SDavid du Colombier.CW mux 143219b2ee8SDavid du Colombier[Pike88], providing mouse-based editing of input and output text, 144219b2ee8SDavid du Colombierthe ability to scroll back to see earlier output, and so on. 145219b2ee8SDavid du ColombierIt also has a new feature, toggled by typing ESC, 146219b2ee8SDavid du Colombierthat enables the user to control when 147219b2ee8SDavid du Colombiertyped characters may be read by the shell or application, 148219b2ee8SDavid du Colombierinstead of (for example) after each newline. 149219b2ee8SDavid du ColombierThis feature makes the window program directly useful for many text-editing 150219b2ee8SDavid du Colombiertasks such as composing mail messages before sending them. 151219b2ee8SDavid du Colombier.SH 152219b2ee8SDavid du ColombierPlan 9 and 8½ 153219b2ee8SDavid du Colombier.PP 154219b2ee8SDavid du ColombierPlan 9 is a distributed system that provides support for UNIX-like applications 155219b2ee8SDavid du Colombierin an environment built from distinct CPU servers, file servers, and terminals 156219b2ee8SDavid du Colombierconnected by a variety of networks [Pike90]. 157219b2ee8SDavid du ColombierThe terminals are comparable to modest workstations that, once connected to a file 158219b2ee8SDavid du Colombierserver over a medium-bandwidth network such as Ethernet, are self-sufficient computers 159219b2ee8SDavid du Colombierrunning a full operating system. 160219b2ee8SDavid du ColombierUnlike workstations, however, their role is just to 161219b2ee8SDavid du Colombierprovide an affordable multiplexed user interface to the rest of the system: 162219b2ee8SDavid du Colombierthey run the window system and support simple interactive 163219b2ee8SDavid du Colombiertasks such as text editing. 164219b2ee8SDavid du ColombierThus they lie somewhere between workstations and X terminals in design, 165219b2ee8SDavid du Colombiercost, performance, and function. 166219b2ee8SDavid du Colombier(The terminals can be used 167219b2ee8SDavid du Colombierfor general computing, but in practice Plan 9 users do their 168219b2ee8SDavid du Colombiercomputing on the CPU servers.) 169219b2ee8SDavid du ColombierThe Plan 9 terminal software, including 8½, 170219b2ee8SDavid du Colombierwas developed on a 68020-based 171219b2ee8SDavid du Colombiermachine called a Gnot 172219b2ee8SDavid du Colombierand has been ported to 173219b2ee8SDavid du Colombierthe NeXTstation, 174219b2ee8SDavid du Colombierthe MIPS Magnum 3000, 175219b2ee8SDavid du ColombierSGI Indigos, 176219b2ee8SDavid du Colombierand Sun SPARCstations\(emall small workstations that we use as terminals\(emas 177219b2ee8SDavid du Colombierwell as PCs. 178219b2ee8SDavid du Colombier.PP 179219b2ee8SDavid du ColombierHeavy computations such as compilation, text processing, 180219b2ee8SDavid du Colombieror scientific calculation are done on the CPU servers, which are connected 181219b2ee8SDavid du Colombierto the file servers by high-bandwidth networks. 182219b2ee8SDavid du ColombierFor interactive work, 183219b2ee8SDavid du Colombierthese computations can access the terminal that instantiated them. 184219b2ee8SDavid du ColombierThe terminal and CPU server being used by a particular user are connected to the 185219b2ee8SDavid du Colombiersame file server, although over different networks; Plan 9 provides a view of the 186219b2ee8SDavid du Colombierfile server that is independent of location in the network. 187219b2ee8SDavid du Colombier.PP 188219b2ee8SDavid du ColombierThe components of Plan 9 are connected by a common protocol based on the sharing of files. 189219b2ee8SDavid du ColombierAll resources in the network are implemented as file servers; programs that wish to 190219b2ee8SDavid du Colombieraccess them connect to them over the network and communicate using ordinary file 191219b2ee8SDavid du Colombieroperations. 192219b2ee8SDavid du ColombierAn unusual aspect of Plan 9 is that the 193219b2ee8SDavid du Colombier.I 194219b2ee8SDavid du Colombiername space 195219b2ee8SDavid du Colombier.R 196219b2ee8SDavid du Colombierof a process, the set of files that can be accessed by name 197219b2ee8SDavid du Colombier(for example by an 198219b2ee8SDavid du Colombier.CW open 199219b2ee8SDavid du Colombiersystem call) is not global to all processes on a machine; distinct processes 200219b2ee8SDavid du Colombiermay have distinct name spaces. The system provides methods by which processes 201219b2ee8SDavid du Colombiermay change their name spaces, such as the ability to 202219b2ee8SDavid du Colombier.I mount 203219b2ee8SDavid du Colombiera service upon an existing directory, making the files of the service 204219b2ee8SDavid du Colombiervisible in the directory. 205219b2ee8SDavid du Colombier(This is a different operation from its 206219b2ee8SDavid du ColombierUNIX 207219b2ee8SDavid du Colombiernamesake.) 208219b2ee8SDavid du ColombierMultiple services may be mounted upon the same directory, 209219b2ee8SDavid du Colombierallowing the files from multiple services to be accessed in the same directory. 210219b2ee8SDavid du ColombierOptions to the 211219b2ee8SDavid du Colombier.CW mount 212219b2ee8SDavid du Colombiersystem call control the order of searching for files in such a 213219b2ee8SDavid du Colombier.I 214219b2ee8SDavid du Colombierunion directory. 215219b2ee8SDavid du Colombier.R 216219b2ee8SDavid du Colombier.PP 217219b2ee8SDavid du ColombierThe most obvious example of a network resource is a file server, where permanent 218219b2ee8SDavid du Colombierfiles reside. There are a number of unusual services, however, whose design in 219219b2ee8SDavid du Colombiera different environment would likely not be file-based. Many are described 220219b2ee8SDavid du Colombierelsewhere [Pike92]; some examples are the representation 221219b2ee8SDavid du Colombierof processes for debugging, 222219b2ee8SDavid du Colombiermuch like Killian's process files for the 8th edition [Kill84], 223219b2ee8SDavid du Colombierand the implementation of the name/value pairs of the 224219b2ee8SDavid du ColombierUNIX 225219b2ee8SDavid du Colombier.CW exec 226219b2ee8SDavid du Colombierenvironment as files. 227219b2ee8SDavid du ColombierUser processes may also implement a file service and make it available to clients 228219b2ee8SDavid du Colombierin the network, much like the `mounted streams' in the 9th Edition 229219b2ee8SDavid du Colombier[Pres90]. 230219b2ee8SDavid du ColombierA typical example is a program that interprets an externally-defined file system 231219b2ee8SDavid du Colombiersuch as that on a CD-ROM or a standard 232219b2ee8SDavid du ColombierUNIX 233219b2ee8SDavid du Colombiersystem and makes the contents available to Plan 9 programs. 234219b2ee8SDavid du ColombierThis design is used by all distributed applications in Plan 9, including 8½. 235219b2ee8SDavid du Colombier.PP 236219b2ee8SDavid du Colombier8½ serves a set of files in the conventional directory 237219b2ee8SDavid du Colombier.CW /dev 238219b2ee8SDavid du Colombierwith names like 239219b2ee8SDavid du Colombier.CW cons , 240219b2ee8SDavid du Colombier.CW mouse , 241219b2ee8SDavid du Colombierand 242219b2ee8SDavid du Colombier.CW screen . 243219b2ee8SDavid du ColombierClients of 8½ communicate with the window system by reading and writing 244219b2ee8SDavid du Colombierthese files. 245219b2ee8SDavid du ColombierFor example, a client program, such as a shell, 246219b2ee8SDavid du Colombiercan print text by writing its standard output, which is automatically 247219b2ee8SDavid du Colombierconnected to 248219b2ee8SDavid du Colombier.CW /dev/cons , 249219b2ee8SDavid du Colombieror it may open and write that file explicitly. 250219b2ee8SDavid du ColombierUnlike files served by a traditional file server, however, the instance of 251219b2ee8SDavid du Colombier.CW /dev/cons 252219b2ee8SDavid du Colombierserved in each window by 8½ is a distinct file; 253219b2ee8SDavid du Colombierthe per-process name spaces of Plan 9 allow 8½ to provide a unique 254219b2ee8SDavid du Colombier.CW /dev/cons 255219b2ee8SDavid du Colombierto each client. 256219b2ee8SDavid du ColombierThis mechanism is best illustrated by the creation of a new 8½ client. 257219b2ee8SDavid du Colombier.PP 258219b2ee8SDavid du ColombierWhen 8½ starts, it creates a full-duplex pipe to be the communication 259219b2ee8SDavid du Colombiermedium for the messages that implement the file service it will provide. 260219b2ee8SDavid du ColombierOne end will be shared by all the clients; the other end is held by 261219b2ee8SDavid du Colombier8½ to accept requests for I/O. 262219b2ee8SDavid du ColombierWhen a user makes a new window using the mouse, 263219b2ee8SDavid du Colombier8½ allocates the window data structures and forks a child process. 264219b2ee8SDavid du ColombierThe child's name space, 265219b2ee8SDavid du Colombierinitially shared with the parent, 266219b2ee8SDavid du Colombieris then duplicated 267219b2ee8SDavid du Colombierso that changes the child makes to its name space will not affect the parent. 268219b2ee8SDavid du ColombierThe child then attaches its end of the communication pipe, 269219b2ee8SDavid du Colombier.CW cfd , 270219b2ee8SDavid du Colombierto the directory 271219b2ee8SDavid du Colombier.CW /dev 272219b2ee8SDavid du Colombierby doing a 273219b2ee8SDavid du Colombier.CW mount 274219b2ee8SDavid du Colombiersystem call: 275219b2ee8SDavid du Colombier.P1 276219b2ee8SDavid du Colombiermount(cfd, "/dev", MBEFORE, buf) 277219b2ee8SDavid du Colombier.P2 278219b2ee8SDavid du ColombierThis call attaches the service associated with the file descriptor 279219b2ee8SDavid du Colombier.CW cfd 280219b2ee8SDavid du Colombier\(em the client end of the pipe \(em to the beginning of 281219b2ee8SDavid du Colombier.CW /dev 282219b2ee8SDavid du Colombierso that the files in the new service take priority over existing files 283219b2ee8SDavid du Colombierin the directory. 284219b2ee8SDavid du ColombierThis makes the new files 285219b2ee8SDavid du Colombier.CW cons , 286219b2ee8SDavid du Colombier.CW mouse , 287219b2ee8SDavid du Colombierand so on, 288219b2ee8SDavid du Colombieravailable in 289219b2ee8SDavid du Colombier.CW /dev 290219b2ee8SDavid du Colombierin a way that hides any files with the same names already in place. 291219b2ee8SDavid du ColombierThe argument 292219b2ee8SDavid du Colombier.CW buf 293219b2ee8SDavid du Colombieris a character string (null in this case), 294219b2ee8SDavid du Colombierdescribed below. 295219b2ee8SDavid du Colombier.PP 296219b2ee8SDavid du ColombierThe client process then closes file descriptors 0, 1, and 2 and opens 297219b2ee8SDavid du Colombier.CW /dev/cons 298219b2ee8SDavid du Colombierrepeatedly to connect the standard 299219b2ee8SDavid du Colombierinput, output, and error files to the window's 300219b2ee8SDavid du Colombier.CW /dev/cons . 301219b2ee8SDavid du ColombierIt then does an 302219b2ee8SDavid du Colombier.CW exec 303219b2ee8SDavid du Colombiersystem call to begin executing the shell in the window. 304219b2ee8SDavid du ColombierThis entire sequence, complete with error handling, is 33 lines of C. 305219b2ee8SDavid du Colombier.PP 306219b2ee8SDavid du ColombierThe view of these events from 8½'s end of the pipe is a sequence 307219b2ee8SDavid du Colombierof file protocol messages from the new client generated by the 308219b2ee8SDavid du Colombierintervening operating 309219b2ee8SDavid du Colombiersystem in response to the 310219b2ee8SDavid du Colombier.CW mount 311219b2ee8SDavid du Colombierand 312219b2ee8SDavid du Colombier.CW open 313219b2ee8SDavid du Colombiersystem calls executed by the client. 314219b2ee8SDavid du ColombierThe message generated by the 315219b2ee8SDavid du Colombier.CW mount 316219b2ee8SDavid du Colombierinforms 8½ that a new client has attached to the file service it provides; 317219b2ee8SDavid du Colombier8½'s response is a unique identifier kept by the operating system and 318219b2ee8SDavid du Colombierpassed in all messages generated by I/O on the files derived from that 319219b2ee8SDavid du Colombier.CW mount . 320219b2ee8SDavid du ColombierThis identifier is used by 8½ to distinguish the various clients so 321219b2ee8SDavid du Colombiereach sees a unique 322219b2ee8SDavid du Colombier.CW /dev/cons ; 323219b2ee8SDavid du Colombiermost servers do not need to make this distinction. 324219b2ee8SDavid du Colombier.PP 325219b2ee8SDavid du ColombierA process unrelated to 8½ may create windows by a variant of this mechanism. 326219b2ee8SDavid du ColombierWhen 8½ begins, it uses a Plan 9 service to `post' the client end of the 327219b2ee8SDavid du Colombiercommunication pipe in a public place. 328219b2ee8SDavid du ColombierA process may open that pipe and 329219b2ee8SDavid du Colombier.CW mount 330219b2ee8SDavid du Colombierit to attach to the window system, 331219b2ee8SDavid du Colombiermuch in the way an X client may connect to a 332219b2ee8SDavid du ColombierUNIX 333219b2ee8SDavid du Colombierdomain socket to the server bound to the file system. 334219b2ee8SDavid du ColombierThe final argument to 335219b2ee8SDavid du Colombier.CW mount 336219b2ee8SDavid du Colombieris passed through uninterpreted by the operating 337219b2ee8SDavid du Colombiersystem. 338219b2ee8SDavid du ColombierIt provides a way for the client and server to 339219b2ee8SDavid du Colombierexchange information at the time of the 340219b2ee8SDavid du Colombier.CW mount . 341219b2ee8SDavid du Colombier8½ interprets it as the dimensions of the window to be 342219b2ee8SDavid du Colombiercreated for the new client. (In the case above, the window has been 343219b2ee8SDavid du Colombiercreated by the time the mount occurs, and 344219b2ee8SDavid du Colombier.CW buf 345219b2ee8SDavid du Colombiercarries no information.) 346219b2ee8SDavid du ColombierWhen the 347219b2ee8SDavid du Colombier.CW mount 348219b2ee8SDavid du Colombierreturns, the process can open the files of the new window and begin I/O to 349219b2ee8SDavid du Colombieruse it. 350219b2ee8SDavid du Colombier.PP 351219b2ee8SDavid du ColombierBecause 8½'s interface is based on files, 352219b2ee8SDavid du Colombierstandard system utilities can be used to control its services. 353219b2ee8SDavid du ColombierFor example, 354219b2ee8SDavid du Colombierits method of creating windows externally is packaged in a 355219b2ee8SDavid du Colombier16-line shell script, called 356219b2ee8SDavid du Colombier.CW window , 357219b2ee8SDavid du Colombierthe core of which is just a 358219b2ee8SDavid du Colombier.CW mount 359219b2ee8SDavid du Colombieroperation that prefixes 8½'s directory to 360219b2ee8SDavid du Colombier.CW /dev 361219b2ee8SDavid du Colombierand runs a command passed on the argument line: 362219b2ee8SDavid du Colombier.P1 363219b2ee8SDavid du Colombiermount -b $'8½serv' /dev 364219b2ee8SDavid du Colombier$* < /dev/cons > /dev/cons >[2] /dev/cons & 365219b2ee8SDavid du Colombier.P2 366219b2ee8SDavid du ColombierThe 367219b2ee8SDavid du Colombier.CW window 368219b2ee8SDavid du Colombierprogram is typically employed by users to create their 369219b2ee8SDavid du Colombierinitial working environment when they boot the system, although 370219b2ee8SDavid du Colombierit has more general possibilities. 371219b2ee8SDavid du Colombier.PP 372219b2ee8SDavid du ColombierOther basic features of the system fall out naturally from the 373219b2ee8SDavid du Colombierfile-based model. 374219b2ee8SDavid du ColombierWhen the user deletes a window, 8½ sends the equivalent of a 375219b2ee8SDavid du ColombierUNIX 376219b2ee8SDavid du Colombiersignal to the process group \(em the clients \(em in the window, 377219b2ee8SDavid du Colombierremoves the window from the screen, and poisons the incoming connections 378219b2ee8SDavid du Colombierto the files that drive it. If a client ignores the signal and 379219b2ee8SDavid du Colombiercontinues to write to the window, it will get I/O errors. 380219b2ee8SDavid du ColombierIf, on the other hand, all the processes in a window exit spontaneously, 381219b2ee8SDavid du Colombierthey will automatically close all connections to the window. 382219b2ee8SDavid du Colombier8½ counts references to the window's files; when none are left, 383219b2ee8SDavid du Colombierit shuts down the window and removes it from the screen. 384219b2ee8SDavid du ColombierAs a different example, when the user hits the DEL key to generate an 385219b2ee8SDavid du Colombierinterrupt, 386219b2ee8SDavid du Colombier8½ writes a message to a special file, provided by Plan 9's 387219b2ee8SDavid du Colombierprocess control interface, that interrupts all the processes 388219b2ee8SDavid du Colombierin the window. 389219b2ee8SDavid du ColombierIn all these examples, the implementation works seamlessly 390219b2ee8SDavid du Colombieracross a network. 391219b2ee8SDavid du Colombier.PP 392219b2ee8SDavid du ColombierThere are two valuable side effects of implementing 393219b2ee8SDavid du Colombiera window system by multiplexing 394219b2ee8SDavid du Colombier.CW /dev/cons 395219b2ee8SDavid du Colombierand other such files. 396219b2ee8SDavid du ColombierFirst, the problem of giving a meaningful 397219b2ee8SDavid du Colombierinterpretation to the file 398219b2ee8SDavid du Colombier.CW /dev/cons 399219b2ee8SDavid du Colombier.CW /dev/tty ) ( 400219b2ee8SDavid du Colombierin each window is solved automatically. 401219b2ee8SDavid du ColombierTo provide 402219b2ee8SDavid du Colombier.CW /dev/cons 403219b2ee8SDavid du Colombieris the fundamental job of the window system, rather than just an awkward burden; 404219b2ee8SDavid du Colombierother systems must often make special and otherwise irrelevant arrangements for 405219b2ee8SDavid du Colombier.CW /dev/tty 406219b2ee8SDavid du Colombierto behave as expected in a window. 407219b2ee8SDavid du ColombierSecond, any program that can access the server, including a 408219b2ee8SDavid du Colombierprocess on a remote machine, can access the files using standard 409219b2ee8SDavid du Colombierread and write system calls to communicate with the window system, 410219b2ee8SDavid du Colombierand standard open and close calls to connect to it. 411219b2ee8SDavid du ColombierAgain, no special arrangements need to be made for remote processes to 412219b2ee8SDavid du Colombieruse all the graphics facilities of 8½. 413219b2ee8SDavid du Colombier.SH 414219b2ee8SDavid du ColombierGraphical input 415219b2ee8SDavid du Colombier.PP 416219b2ee8SDavid du ColombierOf course 8½ offers more than ASCII I/O to its clients. 417219b2ee8SDavid du ColombierThe state of the mouse may be discovered by reading the file 418219b2ee8SDavid du Colombier.CW /dev/mouse , 419219b2ee8SDavid du Colombierwhich returns a ten-byte message encoding the state 420219b2ee8SDavid du Colombierof the buttons and the position of the cursor. 421219b2ee8SDavid du ColombierIf the mouse has not moved since the last read of 422219b2ee8SDavid du Colombier.CW /dev/mouse , 423219b2ee8SDavid du Colombieror if the window associated with the instance of 424219b2ee8SDavid du Colombier.CW /dev/mouse 425219b2ee8SDavid du Colombieris not the `input focus', the read blocks. 426219b2ee8SDavid du Colombier.PP 427219b2ee8SDavid du ColombierThe format of the message is: 428219b2ee8SDavid du Colombier.DS 429219b2ee8SDavid du Colombier.CW 'm' 430219b2ee8SDavid du Colombier1 byte of button state 431219b2ee8SDavid du Colombier4 bytes of x, low byte first 432219b2ee8SDavid du Colombier4 bytes of y, low byte first 433219b2ee8SDavid du Colombier.DE 434219b2ee8SDavid du ColombierAs in all shared data structures in Plan 9, 435219b2ee8SDavid du Colombierthe order of every byte in the message is defined 436219b2ee8SDavid du Colombierso all clients can execute the same code to unpack the message 437219b2ee8SDavid du Colombierinto a local data structure. 438219b2ee8SDavid du Colombier.PP 439219b2ee8SDavid du ColombierFor keyboard input, clients can read 440219b2ee8SDavid du Colombier.CW /dev/cons 441219b2ee8SDavid du Colombieror, if they need character-at-a-time input, 442219b2ee8SDavid du Colombier.CW /dev/rcons 443219b2ee8SDavid du Colombier(`raw console'). 444219b2ee8SDavid du ColombierThere is no explicit event mechanism to help clients that need to read 445219b2ee8SDavid du Colombierfrom multiple sources. 446219b2ee8SDavid du ColombierInstead, a small (365 line) external 447219b2ee8SDavid du Colombiersupport library can be used. 448219b2ee8SDavid du ColombierIt attaches a process 449219b2ee8SDavid du Colombierto the various blocking input sources \(em mouse, keyboard, and perhaps 450219b2ee8SDavid du Colombiera third user-provided file descriptor \(em 451219b2ee8SDavid du Colombierand funnels their input into a single pipe from which may be read 452219b2ee8SDavid du Colombierthe various types of 453219b2ee8SDavid du Colombierevents in the traditional style. 454219b2ee8SDavid du ColombierThis package is a compromise. As discussed in a previous paper 455219b2ee8SDavid du Colombier[Pike89] I prefer 456219b2ee8SDavid du Colombierto free applications from event-based programming. Unfortunately, though, I see 457219b2ee8SDavid du Colombierno easy way to achieve this in single-threaded C programs, and am unwilling 458219b2ee8SDavid du Colombierto require all programmers to master concurrent programming. 459219b2ee8SDavid du ColombierIt should be noted, though, that even this compromise results in a small 460219b2ee8SDavid du Colombierand easily understood interface. An example program that uses it is 461219b2ee8SDavid du Colombiergiven near the end of the paper. 462219b2ee8SDavid du Colombier.SH 463219b2ee8SDavid du ColombierGraphical output 464219b2ee8SDavid du Colombier.PP 465219b2ee8SDavid du ColombierThe file 466219b2ee8SDavid du Colombier.CW /dev/screen 467219b2ee8SDavid du Colombiermay be read by any client to recover the contents of the entire screen, 468219b2ee8SDavid du Colombiersuch as for printing (see Figure 1). 469219b2ee8SDavid du ColombierSimilarly, 470219b2ee8SDavid du Colombier.CW /dev/window 471219b2ee8SDavid du Colombierholds the contents of the current window. 472219b2ee8SDavid du ColombierThese are read-only files. 473219b2ee8SDavid du Colombier.PP 474219b2ee8SDavid du ColombierTo perform graphics operations in their windows, client programs access 475219b2ee8SDavid du Colombier.CW /dev/bitblt . 476219b2ee8SDavid du ColombierIt implements a protocol that encodes bitmap graphics operations. 477219b2ee8SDavid du ColombierMost of the messages in the protocol (there are 23 messages in all, about 478219b2ee8SDavid du Colombierhalf to manage the multi-level fonts necessary for efficient handling 479219b2ee8SDavid du Colombierof Unicode characters) 480219b2ee8SDavid du Colombierare transmissions (via a write) 481219b2ee8SDavid du Colombierfrom the client to the window system to perform a graphical 482219b2ee8SDavid du Colombieroperation such as a 483219b2ee8SDavid du Colombier.CW bitblt 484219b2ee8SDavid du Colombier[PLR85] or character-drawing operation; a few include return information 485219b2ee8SDavid du Colombier(recovered via a read) to the client. 486219b2ee8SDavid du ColombierAs with 487219b2ee8SDavid du Colombier.CW /dev/mouse , 488219b2ee8SDavid du Colombierthe 489219b2ee8SDavid du Colombier.CW /dev/bitblt 490219b2ee8SDavid du Colombierprotocol is in a defined byte order. 491219b2ee8SDavid du ColombierHere, for example, is the layout of the 492219b2ee8SDavid du Colombier.CW bitblt 493219b2ee8SDavid du Colombiermessage: 494219b2ee8SDavid du Colombier.DS 495219b2ee8SDavid du Colombier.CW 'b' 496219b2ee8SDavid du Colombier2 bytes of destination id 497219b2ee8SDavid du Colombier2x4 bytes of destination point 498219b2ee8SDavid du Colombier2 bytes of source id 499219b2ee8SDavid du Colombier4x4 bytes of source rectangle 500219b2ee8SDavid du Colombier2 bytes of boolean function code 501219b2ee8SDavid du Colombier.DE 502219b2ee8SDavid du Colombier.KF 503*426d2b71SDavid du Colombier.ie h .html - <center><a href="8½.fig1.png"><img src="8½.fig1s.png"></a></center> 504*426d2b71SDavid du Colombier.el .BP fig1.ps 4.16 5.6 r 0 0 505219b2ee8SDavid du Colombier.EP 506219b2ee8SDavid du Colombier.IP 507219b2ee8SDavid du ColombierFigure 1. 508219b2ee8SDavid du ColombierA representative 8½ screen, running on a NeXTstation under Plan 9 509219b2ee8SDavid du Colombier(with no NeXT software). In the upper right, a program announces the 510219b2ee8SDavid du Colombierarrival of mail. In the top and left are a broswer for astronomical 511219b2ee8SDavid du Colombierdatabases and an image of a galaxy produced by the browser. 512219b2ee8SDavid du ColombierIn the lower left there is a screen editor, 513219b2ee8SDavid du Colombier.CW sam 514219b2ee8SDavid du Colombier[Pike87], 515219b2ee8SDavid du Colombierediting Japanese text encoded in UTF, 516219b2ee8SDavid du Colombierand in the lower right an 8½ running recursively and, inside that instantiation, 517219b2ee8SDavid du Colombiera previewer for 518219b2ee8SDavid du Colombier.CW troff 519219b2ee8SDavid du Colombieroutput. 520219b2ee8SDavid du ColombierUnderneath the faces is a small window running the command that 521219b2ee8SDavid du Colombierprints the screen by passing 522219b2ee8SDavid du Colombier.CW /dev/screen 523219b2ee8SDavid du Colombierto the bitmap printing utility. 524219b2ee8SDavid du Colombier.sp 525219b2ee8SDavid du Colombier.KE 526219b2ee8SDavid du Colombier.PP 527219b2ee8SDavid du ColombierThe message is trivially constructed from the 528219b2ee8SDavid du Colombier.CW bitblt 529219b2ee8SDavid du Colombiersubroutine in the library, defined as 530219b2ee8SDavid du Colombier.P1 531219b2ee8SDavid du Colombiervoid bitblt(Bitmap *dst, Point dp, 532219b2ee8SDavid du Colombier Bitmap *src, Rectangle sr, Fcode c). 533219b2ee8SDavid du Colombier.P2 534219b2ee8SDavid du Colombier.PP 535219b2ee8SDavid du ColombierThe `id' 536219b2ee8SDavid du Colombierfields in the message indicate another property of 8½: 537219b2ee8SDavid du Colombierthe clients do not store the actual data for any of their bitmaps locally. 538219b2ee8SDavid du ColombierInstead, the protocol provides a message to allocate a bitmap, to be 539219b2ee8SDavid du Colombierstored in the server, and returns to the client an integer identifier, 540219b2ee8SDavid du Colombiermuch like a 541219b2ee8SDavid du ColombierUNIX 542219b2ee8SDavid du Colombierfile descriptor, to be used in operations on that bitmap. 543219b2ee8SDavid du ColombierBitmap number 0 is conventionally the client's window, 544219b2ee8SDavid du Colombieranalogous to standard input for file I/O. 545219b2ee8SDavid du ColombierIn fact, no bitmap graphics operations are executed in the client at all; 546219b2ee8SDavid du Colombierthey are all performed on its behalf by the server. 547219b2ee8SDavid du ColombierAgain, using the standard remote file operations in Plan 9, 548219b2ee8SDavid du Colombierthis permits remote machines having no graphics capability, such 549219b2ee8SDavid du Colombieras the CPU server, 550219b2ee8SDavid du Colombierto run graphics applications. 551219b2ee8SDavid du ColombierAnalogous features of the original Andrew window system [Gos86] 552219b2ee8SDavid du Colombierand of X [Sche86] require more complex mechanisms. 553219b2ee8SDavid du Colombier.PP 554219b2ee8SDavid du ColombierNor does 8½ itself operate directly on bitmaps. 555219b2ee8SDavid du ColombierInstead, it calls another server to do its graphics operations for it, 556219b2ee8SDavid du Colombierusing an identical protocol. 557219b2ee8SDavid du ColombierThe operating system for the Plan 9 terminals contains an internal 558219b2ee8SDavid du Colombierserver that implements that protocol, exactly as does 8½, but for a single 559219b2ee8SDavid du Colombierclient. That server stores the actual bytes for the bitmaps 560219b2ee8SDavid du Colombierand implements the fundamental bitmap graphics operations. 561219b2ee8SDavid du ColombierThus the environment in which 8½ runs 562219b2ee8SDavid du Colombierhas exactly the structure it provides for its clients; 563219b2ee8SDavid du Colombier8½ reproduces the environment for its clients, 564219b2ee8SDavid du Colombiermultiplexing the interface to keep the clients separate. 565219b2ee8SDavid du Colombier.PP 566219b2ee8SDavid du ColombierThis idea of multiplexing by simulation is applicable to more 567219b2ee8SDavid du Colombierthan window systems, of course, and has some side effects. 568219b2ee8SDavid du ColombierSince 8½ simulates its own environment for its clients, it may run 569219b2ee8SDavid du Colombierin one of its own windows (see Figure 1). 570219b2ee8SDavid du ColombierA useful and common application of this 571219b2ee8SDavid du Colombiertechnique is to connect a window to a remote machine, such as a CPU 572219b2ee8SDavid du Colombierserver, and run the window system there so that each subwindow is automatically 573219b2ee8SDavid du Colombieron the remote machine. 574219b2ee8SDavid du ColombierIt is also a handy way to debug a new version of the window system 575219b2ee8SDavid du Colombieror to create an environment with, for example, a different default font. 576219b2ee8SDavid du Colombier.SH 577219b2ee8SDavid du ColombierImplementation 578219b2ee8SDavid du Colombier.PP 579219b2ee8SDavid du ColombierTo provide graphics to its clients, 8½ mostly just multiplexes and passes 580219b2ee8SDavid du Colombierthrough to its own server the clients' requests, occasionally rearranging 581219b2ee8SDavid du Colombierthe messages to maintain the fiction that the clients have unique screens 582219b2ee8SDavid du Colombier(windows). 583219b2ee8SDavid du ColombierTo manage the overlapping windows it uses the layers model, 584219b2ee8SDavid du Colombierwhich is handled by a separate library [Pike83a]. 585219b2ee8SDavid du ColombierThus it has little work to do and is a fairly simple program; 586219b2ee8SDavid du Colombierit is dominated by a couple of switch statements to interpret 587219b2ee8SDavid du Colombierthe bitmap and file server protocols. 588219b2ee8SDavid du ColombierThe built-in window program and its associated menus and text-management 589219b2ee8SDavid du Colombiersupport are responsible for most of the code. 590219b2ee8SDavid du Colombier.PP 591219b2ee8SDavid du ColombierThe operating system's server is also compact: 592219b2ee8SDavid du Colombierthe version for the 68020 processor, excluding the implementation 593219b2ee8SDavid du Colombierof a half dozen bitmap graphics operations, is 2295 lines of C 594219b2ee8SDavid du Colombier(again, about half dealing with fonts); 595219b2ee8SDavid du Colombierthe graphics operations are another 2214 lines. 596219b2ee8SDavid du Colombier.PP 597219b2ee8SDavid du Colombier8½ is structured as a set of communicating coroutines, 598219b2ee8SDavid du Colombiermuch as discussed in a 1989 paper [Pike89]. 599219b2ee8SDavid du ColombierOne coroutine manages the mouse, another the keyboard, and another 600219b2ee8SDavid du Colombieris instantiated to manage the state of each window and associated client. 601219b2ee8SDavid du ColombierWhen no coroutine wishes to run, 8½ reads the next file I/O request from 602219b2ee8SDavid du Colombierits clients, which arrive serially on the full-duplex communication pipe. 603219b2ee8SDavid du ColombierThus 8½ is entirely synchronous. 604219b2ee8SDavid du Colombier.PP 605219b2ee8SDavid du ColombierThe program source is small and compiles in about 10 seconds 606219b2ee8SDavid du Colombierin our Plan 9 environment. There are ten source files and 607219b2ee8SDavid du Colombierone 608219b2ee8SDavid du Colombier.CW makefile 609219b2ee8SDavid du Colombiertotaling 5100 lines. 610219b2ee8SDavid du ColombierThis includes the source for the window management process, 611219b2ee8SDavid du Colombierthe cut-and-paste terminal program, 612219b2ee8SDavid du Colombierthe window/file server itself, 613219b2ee8SDavid du Colombierand a small coroutine library 614219b2ee8SDavid du Colombier.CW proc.c ). ( 615219b2ee8SDavid du ColombierIt does not include the layer library 616219b2ee8SDavid du Colombier(another 1031 lines) 617219b2ee8SDavid du Colombieror the library to handle the cutting and pasting of text 618219b2ee8SDavid du Colombierdisplayed in a window (960 lines), 619219b2ee8SDavid du Colombieror the general graphics support library that manages all the 620219b2ee8SDavid du Colombiernon-drawing aspects of graphics \(em arithmetic on points and rectangles, 621219b2ee8SDavid du Colombiermemory management, error handling, clipping, \(em plus fonts, 622219b2ee8SDavid du Colombierevents, and non-primitive drawing operations such as circles and ellipses 623219b2ee8SDavid du Colombier(a final 3051 lines). 624219b2ee8SDavid du ColombierNot all the pieces of these libraries are used by 8½ itself; 625219b2ee8SDavid du Colombiera large part of the graphics library in particular is used only by clients. 626219b2ee8SDavid du ColombierThus it is somewhat unfair to 8½ just to sum these numbers, including 627219b2ee8SDavid du Colombierthe 4509 lines of support in the kernel, and arrive 628219b2ee8SDavid du Colombierat a total implementation size of 14651 lines of source to implement 629219b2ee8SDavid du Colombierall of 8½ from the lowest levels to the highest. 630219b2ee8SDavid du ColombierBut that number gives a fair measure of the complexity of the overall system. 631219b2ee8SDavid du Colombier.PP 632219b2ee8SDavid du ColombierThe implementation is also efficient. 633219b2ee8SDavid du Colombier8½'s performance is competitive to X windows'. 634219b2ee8SDavid du ColombierCompared using Dunwoody's and Linton's 635219b2ee8SDavid du Colombier.CW gbench 636219b2ee8SDavid du Colombierbenchmarks on the 68020, 637219b2ee8SDavid du Colombierdistributed with the ``X Test Suite'', 638219b2ee8SDavid du Colombiercircles and arcs are drawn about half as fast in 8½ as in 639219b2ee8SDavid du ColombierX11 release 4 compiled with 640219b2ee8SDavid du Colombier.CW gcc 641219b2ee8SDavid du Colombierfor equivalent hardware, 642219b2ee8SDavid du Colombierprobably because they are currently implemented in a user library 643219b2ee8SDavid du Colombierby calls to the 644219b2ee8SDavid du Colombier.CW point 645219b2ee8SDavid du Colombierprimitive. 646219b2ee8SDavid du ColombierLine drawing speed is about equal between the two systems. 647219b2ee8SDavid du ColombierUnicode text is drawn about the same speed by 8½ as ASCII text by 648219b2ee8SDavid du ColombierX, and 649219b2ee8SDavid du Colombierthe 650219b2ee8SDavid du Colombier.CW bitblt 651219b2ee8SDavid du Colombiertest is runs four times faster for 8½. 652219b2ee8SDavid du ColombierThese numbers vary enough to caution against drawing sweeping 653219b2ee8SDavid du Colombierconclusions, but they 654219b2ee8SDavid du Colombiersuggest that 8½'s architecture does not penalize its performance. 655219b2ee8SDavid du ColombierFinally, 8½ boots in under a second and creates a new window 656219b2ee8SDavid du Colombierapparently instantaneously. 657219b2ee8SDavid du Colombier.SH 658219b2ee8SDavid du ColombierAn example 659219b2ee8SDavid du Colombier.PP 660219b2ee8SDavid du ColombierHere is a complete program that runs under 8½. 661219b2ee8SDavid du ColombierIt prints the string 662*426d2b71SDavid du Colombier.CW \&"hello 663*426d2b71SDavid du Colombier.CW world" 664219b2ee8SDavid du Colombierwherever the left mouse button is depressed, and exits when the 665219b2ee8SDavid du Colombierright mouse button is depressed. 666219b2ee8SDavid du ColombierIt also prints the string in the center of its window, and maintains 667219b2ee8SDavid du Colombierthat string when the window is resized. 668219b2ee8SDavid du Colombier.P1 669219b2ee8SDavid du Colombier#include <u.h> 670219b2ee8SDavid du Colombier#include <libc.h> 671219b2ee8SDavid du Colombier#include <libg.h> 672219b2ee8SDavid du Colombier 673219b2ee8SDavid du Colombiervoid 674219b2ee8SDavid du Colombierereshaped(Rectangle r) 675219b2ee8SDavid du Colombier{ 676219b2ee8SDavid du Colombier Point p; 677219b2ee8SDavid du Colombier 678219b2ee8SDavid du Colombier screen.r = r; 679219b2ee8SDavid du Colombier bitblt(&screen, screen.r.min, &screen, r, Zero); /* clear */ 680219b2ee8SDavid du Colombier p.x = screen.r.min.x + Dx(screen.r)/2; 681219b2ee8SDavid du Colombier p.y = screen.r.min.y + Dy(screen.r)/2; 682219b2ee8SDavid du Colombier p = sub(p, div(strsize(font, "hello world"), 2)); 683219b2ee8SDavid du Colombier string(&screen, p, font, "hello world", S); 684219b2ee8SDavid du Colombier} 685219b2ee8SDavid du Colombier 686219b2ee8SDavid du Colombiermain(void) 687219b2ee8SDavid du Colombier{ 688219b2ee8SDavid du Colombier Mouse m; 689219b2ee8SDavid du Colombier 690219b2ee8SDavid du Colombier binit(0, 0, 0); /* initialize graphics library */ 691219b2ee8SDavid du Colombier einit(Emouse); /* initialize event library */ 692219b2ee8SDavid du Colombier ereshaped(screen.r); 693219b2ee8SDavid du Colombier for(;;){ 694219b2ee8SDavid du Colombier m = emouse(); 695219b2ee8SDavid du Colombier if(m.buttons & RIGHTB) 696219b2ee8SDavid du Colombier break; 697219b2ee8SDavid du Colombier if(m.buttons & LEFTB){ 698219b2ee8SDavid du Colombier string(&screen, m.xy, font, "hello world", S); 699219b2ee8SDavid du Colombier /* wait for release of button */ 700219b2ee8SDavid du Colombier do; while(emouse().buttons & LEFTB); 701219b2ee8SDavid du Colombier } 702219b2ee8SDavid du Colombier } 703219b2ee8SDavid du Colombier} 704219b2ee8SDavid du Colombier.P2 705219b2ee8SDavid du ColombierThe complete loaded binary is a little over 26K bytes on a 68020. 706219b2ee8SDavid du ColombierThis program should be compared to the similar ones in the excellent paper 707219b2ee8SDavid du Colombierby Rosenthal [Rose88]. 708219b2ee8SDavid du Colombier(The current program does more: it also employs the mouse.) 709219b2ee8SDavid du ColombierThe clumsiest part is 710219b2ee8SDavid du Colombier.CW ereshaped , 711219b2ee8SDavid du Colombiera function with a known name that is called from the event library 712219b2ee8SDavid du Colombierwhenever the window is 713219b2ee8SDavid du Colombierreshaped or moved, as is discovered inelegantly but adequately 714219b2ee8SDavid du Colombierby a special case of a mouse message. 715219b2ee8SDavid du Colombier(Simple so-called expose events are not events 716219b2ee8SDavid du Colombierat all in 8½; the layer library takes care of them transparently.) 717219b2ee8SDavid du ColombierThe lesson of this program, with deference to Rosenthal, is that if 718219b2ee8SDavid du Colombierthe window system is cleanly designed a toolkit should be unnecessary 719219b2ee8SDavid du Colombierfor simple tasks. 720219b2ee8SDavid du Colombier.SH 721219b2ee8SDavid du ColombierStatus 722219b2ee8SDavid du Colombier.PP 723219b2ee8SDavid du ColombierAs of 1992, 8½ is in regular daily use by almost all the 60 people in our 724219b2ee8SDavid du Colombierresearch center. Some of those people use it to access Plan 9 itself; others 725219b2ee8SDavid du Colombieruse it as a front end to remote 726219b2ee8SDavid du ColombierUNIX 727219b2ee8SDavid du Colombiersystems, much as one would use an X terminal. 728219b2ee8SDavid du Colombier.PP 729219b2ee8SDavid du ColombierSome things about 8½ may change. 730219b2ee8SDavid du ColombierIt would be nice if its capabilities were more easily accessible 731219b2ee8SDavid du Colombierfrom the shell. 732219b2ee8SDavid du ColombierA companion to this paper [Pike91] proposes one way to do this, 733219b2ee8SDavid du Colombierbut that does not include any graphics functionality. 734219b2ee8SDavid du ColombierPerhaps a textual version of the 735219b2ee8SDavid du Colombier.CW /dev/bitblt 736219b2ee8SDavid du Colombierfile is a way to proceed; that would allow, for example, 737219b2ee8SDavid du Colombier.CW awk 738219b2ee8SDavid du Colombierprograms to draw graphs directly. 739219b2ee8SDavid du Colombier.PP 740219b2ee8SDavid du ColombierCan this style of window system be built on other operating systems? 741219b2ee8SDavid du ColombierA major part of the design of 8½ depends on its structure as a file server. 742219b2ee8SDavid du ColombierIn principle this could be done for any system that supports user processes 743219b2ee8SDavid du Colombierthat serve files, such as any system running NFS or AFS [Sun89, Kaza87]. 744219b2ee8SDavid du ColombierOne requirement, however, is 8½'s need 745219b2ee8SDavid du Colombierto respond to its clients' requests out of order: 746219b2ee8SDavid du Colombierif one client reads 747219b2ee8SDavid du Colombier.CW /dev/cons 748219b2ee8SDavid du Colombierin a window with no characters to be read, 749219b2ee8SDavid du Colombierother clients should be able to perform I/O in their windows, or even 750219b2ee8SDavid du Colombierthe same window. 751219b2ee8SDavid du ColombierAnother constraint is that the 8½ files are like devices, 752219b2ee8SDavid du Colombierand must not be cached by the client. 753219b2ee8SDavid du ColombierNFS cannot honor these requirements; AFS may be able to. 754219b2ee8SDavid du ColombierOf course, other interprocess communication mechanisms such as sockets 755219b2ee8SDavid du Colombiercould be used as a basis for a window system. One may even argue that 756219b2ee8SDavid du ColombierX's model fits into this overall scheme. It may prove easy and worthwhile 757219b2ee8SDavid du Colombierto write a small 8½-like system for commercial 758219b2ee8SDavid du ColombierUNIX 759219b2ee8SDavid du Colombiersystems to demonstrate that its merits can be won in systems other than 760219b2ee8SDavid du ColombierPlan 9. 761219b2ee8SDavid du Colombier.SH 762219b2ee8SDavid du ColombierConclusion 763219b2ee8SDavid du Colombier.PP 764219b2ee8SDavid du ColombierIn conclusion, 8½ uses an unusual architecture in 765219b2ee8SDavid du Colombierconcert with the file-oriented interprocess communication of Plan 9 766219b2ee8SDavid du Colombierto provide network-based interactive graphics to client programs. 767219b2ee8SDavid du ColombierIt demonstrates that even production-quality window systems are not 768219b2ee8SDavid du Colombierinherently large or complicated 769219b2ee8SDavid du Colombierand may be simple to use and to program. 770219b2ee8SDavid du Colombier.SH 771219b2ee8SDavid du ColombierAcknowledgements 772219b2ee8SDavid du Colombier.PP 773219b2ee8SDavid du ColombierHelpful comments on early drafts of this paper were made by 774219b2ee8SDavid du ColombierDoug Blewett, 775219b2ee8SDavid du ColombierStu Feldman, 776219b2ee8SDavid du ColombierChris Fraser, 777219b2ee8SDavid du ColombierBrian Kernighan, 778219b2ee8SDavid du ColombierDennis Ritchie, 779219b2ee8SDavid du Colombierand Phil Winterbottom. 780219b2ee8SDavid du Colombier8½'s support for color was added by Howard Trickey. 781219b2ee8SDavid du ColombierMany of the ideas leading to 8½ were tried out in earlier, sometimes less 782219b2ee8SDavid du Colombiersuccessful, programs. I would like to thank those users who suffered 783219b2ee8SDavid du Colombierthrough some of my previous 7½ window systems. 784219b2ee8SDavid du Colombier.SH 785219b2ee8SDavid du ColombierReferences 786219b2ee8SDavid du Colombier.LP 787219b2ee8SDavid du Colombier[Duff90] Tom Duff, ``Rc - A Shell for Plan 9 and UNIX systems'', Proc. of the Summer 1990 UKUUG Conf., London, July, 1990, pp. 21-33, reprinted, in a different form, in this volume. 788219b2ee8SDavid du Colombier.LP 789219b2ee8SDavid du Colombier[Far89] Far too many people, XTERM(1), Massachusetts Institute of Technology, 1989. 790219b2ee8SDavid du Colombier.LP 791219b2ee8SDavid du Colombier[Gos86] James Gosling and David Rosenthal, 792219b2ee8SDavid du Colombier``A window manager for bitmapped displays and UNIX'', in Methodology of Window Management, edited by F.R.A. Hopgood et al., Springer, 1986. 793219b2ee8SDavid du Colombier.LP 794219b2ee8SDavid du Colombier[Kaza87] Mike Kazar, ``Synchronization and Caching issues in the Andrew File System'', Tech. Rept. CMU-ITC-058, Information Technology Center, Carnegie Mellon University, June, 1987. 795219b2ee8SDavid du Colombier.LP 796219b2ee8SDavid du Colombier[Kill84] Tom Killian, ``Processes as Files'', USENIX Summer Conf. Proc., Salt Lake City June, 1984. 797219b2ee8SDavid du Colombier.LP 798219b2ee8SDavid du Colombier[Pike83] Rob Pike, ``The Blit: A Multiplexed Graphics Terminal'', Bell Labs Tech. J., V63, #8, part 2, pp. 1607-1631. 799219b2ee8SDavid du Colombier.LP 800219b2ee8SDavid du Colombier[Pike83a] Rob Pike, ``Graphics in Overlapping Bitmap Layers'', Trans. on Graph., Vol 2, #2, 135-160, reprinted in Proc. SIGGRAPH '83, pp. 331-356. 801219b2ee8SDavid du Colombier.LP 802219b2ee8SDavid du Colombier[Pike87] Rob Pike, ``The Text Editor \f(CWsam\fP'', Softw. - Prac. and Exp., Nov 1987, Vol 17 #11, pp. 813-845, reprinted in this volume. 803219b2ee8SDavid du Colombier.LP 804219b2ee8SDavid du Colombier[Pike88] Rob Pike, ``Window Systems Should Be Transparent'', Comp. Sys., Summer 1988, Vol 1 #3, pp. 279-296. 805219b2ee8SDavid du Colombier.LP 806219b2ee8SDavid du Colombier[Pike89] Rob Pike, ``A Concurrent Window System'', Comp. Sys., Spring 1989, Vol 2 #2, pp. 133-153. 807219b2ee8SDavid du Colombier.LP 808219b2ee8SDavid du Colombier[Pike91] Rob Pike, ``A Minimalist Global User Interface'', USENIX Summer Conf. Proc., Nashville, June, 1991. 809219b2ee8SDavid du Colombier.LP 810219b2ee8SDavid du Colombier[Pike92] Rob Pike, Dave Presotto, Ken Thompson, Howard Trickey, and Phil Winterbottom, 811219b2ee8SDavid du ColombierOperating Systems Review 812219b2ee8SDavid du ColombierVol 27, #2, Apr 1993, pp. 72-76 813219b2ee8SDavid du Colombier(reprinted from Proceedings of the 5th ACM SIGOPS European Workshop, Mont Saint-Michel, 1992, Paper nº 34, and reprinted in this volume). 814219b2ee8SDavid du Colombier.LP 815219b2ee8SDavid du Colombier[Pike94] Rob Pike and Ken Thompson, ``Hello World or Καλημέρα κόσμε or \f(Jpこんにちは 世界\fP'', USENIX Winter Conf. Proc., San Diego, Jan, 1993, reprinted in this volume. 816219b2ee8SDavid du Colombier.LP 817219b2ee8SDavid du Colombier[PLR85] Rob Pike, Bart Locanthi and John Reiser, ``Hardware/Software Tradeoffs for Bitmap Graphics on the Blit'', Softw. - Prac. and Exp., Feb 1985, Vol 15 #2, pp. 131-152. 818219b2ee8SDavid du Colombier.LP 819219b2ee8SDavid du Colombier[Pres90] David L. Presotto and Dennis M. Ritchie, ``Interprocess Communication in the Ninth Edition Unix System'', Softw. - Prac. and Exp., June 1990, Vol 20 #S1, pp. S1/3-S1/17. 820219b2ee8SDavid du Colombier.LP 821219b2ee8SDavid du Colombier[Rose88] David Rosenthal, ``A Simple X11 Client Program -or- How hard can it really be to write ``Hello, World''?'', USENIX Winter Conf. Proc., Dallas, Jan, 1988, pp. 229-242. 822219b2ee8SDavid du Colombier.LP 823219b2ee8SDavid du Colombier[Sche86] Robert W. Scheifler and Jim Gettys, 824219b2ee8SDavid du Colombier``The X Window System'', 825219b2ee8SDavid du ColombierACM Trans. on Graph., Vol 5 #2, pp. 79-109. 826219b2ee8SDavid du Colombier.LP 827219b2ee8SDavid du Colombier[Sun89] Sun Microsystems, NFS: Network file system protocol specification, 828219b2ee8SDavid du ColombierRFC 1094, Network Information Center, SRI International, March, 1989. 829219b2ee8SDavid du Colombier.br 830