File: Tutorial

package info (click to toggle)
twin 0.4.0-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,804 kB
  • ctags: 23,904
  • sloc: ansic: 61,860; cpp: 1,023; makefile: 777; sh: 552; lex: 302; yacc: 231
file content (864 lines) | stat: -rw-r--r-- 39,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864

			TTTTT   W   W   III   NN  N
			  T     W W W    I    N N N
			  T      W W    III   N  NN


		   Twin - a Textmode WINdow environment


				TUTORIAL


		  updated to version 0.4.0, 31 Jul 2001
	      

	     Author: Massimiliano Ghilardi <max@linuz.sns.it>


0. Index

		       These are the topics discussed:
	0. Index
	1. Concepts
	2. Supported displays
	   2.1. Emulated terminal
	3. Configuring and Compiling twin
	   3.1 System Requirements
	4. Installing and Starting twin
	5. The Twin UI (User Interface): how to use it
	6. External programs
	   6.1. Security Statement on Sockets
	7. Transparent Compression
	8. Attach/Detach
	9. Installing vga.pcf.gz
	10. Greetings

1. Concepts

   Twin creates, draws and manages windows inside a text display.
   It implements in text mode the same concepts that X11 does in graphics:

   a. draw on some kind of screen (tipically a computer monitor).
   b. allow multiple windows to coexist on the same screen,
      and draw independently on each of them.
   c. talk to external programs (even on other machines) so that
      the programs receive keystrokes, mouse movements, etc.
      and can send back drawing commands.

   There are anyway important differences, beyond the trivial one
   that `twin' works in text mode and X11 servers work in graphics:
   
   a. Each window has an associated menu. Many windows can share
      the same menu, and twin always show the menu associated
      to the currently focused window.
   b. In `twin', window borders are part of each window, and can be
      (partially) customized by the external program that draws in it.
      Things that you can't tailor in this way are:
      buttons position and look, scrollbars position and look,
      as they are under control of twin builtin window manager
      (see the sample system.twinrc to learn how to customize the
      window manager look-n-feel).
   c. In `twin', windows are not just plain rectangules where programs
      can draw. They can contain other windows and/or `gadgets' (small
      icons you can select, like the buttons you can find in many GUIs)
      and they can contain lines longer that the window width and/or more
      lines than the window height, letting the user scroll them.
   d. Twin implements virtual screens. Each virtual screen has very big
      sizes in both directions (something like 64K character cells),
      and you can scroll them by holding LEFT or MIDDLE mouse buttons
      and moving the mouse to one of the screen borders. Also, you can
      switch to the next virtual screen by clicking on the arrows
      at the top-right of its menu bar.
   e. Twin has a built-in window manager,
      which needs to do a slightly different work than a typical
      X11 window manager: it does window focus changes, window drags
      and resizes, virtual screen changes, menu activity and dispatches
      keystrokes and mouse events to the focused window.
      With the help of a built-in `scroller' it also implements
      virtual screen scrolling and window contents scrolling
      (when you drag the scrollbar or hit the scrollbar buttons).
   f. Twin has a built-in terminal emulator, so you don't have to start
      any program equivalent to xterm in order to run `normal' tty programs.
      Anyway, an external terminal emulator `twterm' is included among
      the clients distributed with twin, in case you really need it.
      Note anyway that `twterm' _needs_ the built-in terminal emulator code
      to be loaded into twin, and twin is capable to auto-load such code
      if needed.


2. Supported displays

   Twin runs perfectly on the linux console, inside itself, in a twin terminal
   and on X11: it opens a window and draws in it, does _not_ run inside an
   xterm or similar.
   It can also run on generic text terminals (ttys) using the termcap/ncurses
   driver, but it will work far from optimal: it will have problems with mouse
   (only xterm and derivatives have a standard to report mouse, but only report
   click/release, not drags) and keyboard (each terminal sends different codes
   for special keys: F1-F12, Pause, ...)

   Currently, twin is tested on Linux (i386, PowerPC, Alpha, Sparc)
   and on FreeBSD; SunOS porting is in progress.
   I had yet no chance to test it on other systems.
   
   Twin will not be able to take advantage of special features of non-Linux
   system consoles until someone adds to twin the necessary code for them.
   
   Twin can write to textmode terminals in different ways:
   a: on _local_ Linux console: special devices /dev/vcsa* have the same layout
      as VGA textmode framebuffer. Using them allows twin to display _any_
      ASCII char, from 0 to 255.
   b: on any Linux terminal: even writing on standard output, just like any
      `normal' textmode program, twin can take advantage of extra features
      of the Linux terminal.
      This doesn't allow displaying certain special characters, but it should
      not be a big problem. It is also a little slower than (a) but again,
      no big problem.
   c: on any termcap or ncurses compatible terminal: this is the most generic
      driver, and is quite limited. Twin writes on standard output, but due to
      the broad-targeted code cannot take advantage of any extra features of
      the actual terminal it runs on. Yet this allows to display on such a
      large variety of terminals to be actually useful.
   When choosing a method to display on ttys, twin will use (a) if available,
   else fallback on (b) if available, else fallback on (c).
   
   2.1. Emulated terminals
   
	The built-in terminal emulator behaves as a linux console.
	
	Implementing it on something different than a linux console
	is a little hard, as it would have to translate keyboard sequences:
	
	For example, when you hit <F5>, a linux console sends ESC [ [ 5
	while xterm and derivatives send ESC [ 1 5 ~.
	Having twin correctly running in an xterm also means that each time
	it receives ESC [ 1 5 ~	it must translate it into ESC [ [ 5.
	But what should it do when it receives ESC [ 1 alone?
	Translate to ESC [ [, sent the data without translations,
	or wait for more data? There's no easy answer.


3. Configuring and Compiling twin

   3.1 System Requirements

	To compile twin you need the following programs installed
	on your system:
	
	GNU bash	either version 1.14.7 or later, or any bash 2.x.x
	
	GNU make	it should always work unless it's really prehistorical
			
	an ANSI C compiler
   
   Once you have the necessary programs listed above, you can start:
   
   First, you might want to edit the file `makerules' to change
   the install directory, tweak compiler flags (enable debugging), etc.
   If you are trying to compile on non-Linux systems, you would do better
   reading the file README.porting now, for useful tips and warnings.
   
   Then type `./configure' to automatically configure twin for your system.
   
   AUTOMATIC CONFIGURATION SHOULD ALWAYS SUFFICE;
   YOU SHOULD NEVER NEED TO MANUALLY CONFIGURE TWIN.
   Yet, if you really know what you are doing, you can manually tweak the
   autogenerated configuration with one of `make config', `make menuconfig'
   (uses "dialog"), `./configure [OPTIONS]' or `scripts/Configure [OPTIONS]'.
   See the `Configure' help file for details.
   
   Once you have done with configuration, you are ready to compile:
   just type `make'.
   
   Watch the compilation proceed, and, if everything goes fine,
   you get what follows:
   - `twin_real', the main program, in the server/ subdirectory;
   - various libraries (libT*), in libs/libT*/ subdirectories;
   - various clients (twcat, twterm, ...) in the clients/ subdirectory.
   
   In case you get errors during compilation and you really can't solve
   the problem by your own, you can e-mail me at <max@linuz.sns.it>
   sending an _EXACT_ copy of what `make' printed and also specifying
   your operating system (uname -a), and I'll try to help you.

   If you have a fast computer and some spare time, you could help me a little
   and try to compile every source file under every possible configuration.
   This is not as huge as it may seem, and it's easy to do: just type
   `make Torture'.
   In case you get compile errors, please report them to me,
   specifying your OS name (type `uname -a'), and the compile command
   that failed, including the EXACT error messages.
   
   
4. Installing and Starting twin

   If you want to install twin on your system,
   make sure that the `prefix' variable set in `makerules' is correct,
   considering that when you will type `make install'
   the various parts of twin will be placed as follows:
   `twin' and the other programs (twterm, etc.) will go in $prefix/bin,
   modules will go in $prefix/lib/twin/modules,
   libTw.so* will go in $prefix/lib.

   Once twin compiled fine, to actually install it,
   type the following command as root:
   
   make install
   
   WARNING (1):
   since twin has not been extensively tested against vulnerabilities,
   it will *NOT* be installed suid-root or sgid-tty by default.
   In order for the terminal emulator to work, you may need to give
   such privileges to twin, but remember that you do so at your own risk!

   WARNING (2):
   on most systems, after the installation it is necessary to run `ldconfig'
   or `ldconfig <some parameter>' as root before programs can find libTw.so*
   shared libraries.

   WARNING (3):
   if you compiled some code as modules, twin will look for them only in
   $prefix/lib/twin/modules so it may not find the modules until you install
   them.
   To make debugging easier, if you compile with $libdir set to empty value
   (i.e. make libdir= ) then twin will look for modules in the current
   directory. In this way `make install' is not necessary in order to use
   modules.
   
   In any case, you cannot mix modules from a certain version
   with a `twin' executable of a different version.

   If you compiled some display driver as module, twin will NOT autoprobe
   for it and you will need to use `twin -hw=<display>' to load and use
   a modularized display driver.
   
   After twin is installed, to start it just type
   
     twin
   
   If you did not install twin yet, you can go to the directory where
   you compiled twin, then run:
   
     cd server/
     ./twin_real

   If you want, you can specify the display to use
   instead of letting twin autoprobe; the syntax is:
   
     twin [-hw=<display>[,options]] [-hw=<display>[,options]] ...
     
   where <display> is one of:
   
        X[@<XDISPLAY>]     or    X11[@<XDISPLAY>]
	twin[@<TWDISPLAY>]
	tty[@<tty device>]
	ggi[@<libggi target>]
	
   for an explanation of the available display methods and their options,
   see paragraph 8. below about `twattach' and `twdisplay': they have
   exactly the same syntax as twin for the argument `-hw=<display>[,options]'

   You can also start twin in the background without display with
   
     twin -nohw
   

5. The Twin UI (User Interface): how to use it

   Since the user interface of twin is quite customizable, this part
   cannot cover every possible setup you might create. For this reason,
   what is described here is the default setup, that you get if you do NOT
   start tweaking your own ~/.twinrc file. To learn the syntax of ~/.twinrc,
   look at the sample configuration `system.twinrc' distributed with twin.
   
   
   When twin comes up, you will have a blue screen (or window) with a
   white menu bar on the top saying "Hit PAUSE or Mouse Right Button for Menu"
   
   To activate the menu (this is the default menu) do what the writing says:
   either hit the `PAUSE' key or hold down the right mouse button and move
   the mouse on one of the words of the menu bar. A menu window will appear.
   Choose the line you want, then release the right button if you were holding
   it, or hit the `RETURN' key otherwise.
   If you feel slightly offended by reading something so trivial and obvious,
   well, I feel quite stupid too writing it, but I must start from somewhere ;)
   
   Each word in the menu just appeared is a `menuitem'. The "" menuitem lets
   you pop up some utility windows, including a Clock, the Options window,
   the Buttons window, the Display window and the About window.
   The "File" menuitem lets you Quit twin, Suspend or Detach it, Execute
   arbitrary shell commands and, if the builtin terminal emulator code
   is loaded, open a New Terminal window.
   The "Edit" menuitem is just a standard entry but it's not usable here.
   The "Modules" menuitem lets you insert/remove modules from the running twin:
   you can "Run Twin Term" to insert the terminal emulator module,
   you can "Stop Twin Term" to kill all terminal windows and unload the module;
   you can "Run Socket Server" to insert the support code for running external
   programs, you can "Stop Socket Server" to remove that code and kill all
   external programs.
   The "Window" menuitem is common to all menus and lets you do several
   operations on windows (explained immediately below)
   
   Ok, enough boring stuff for now... let's jump to something else.

   Each window has its own menu, so opening a new window will give you
   a new menu while the previous gets inaccessible. When you start without
   windows, you are presented the default menu described above.
   Anyway, all menus share a common part: the "Window" menuitem, which
   lets you do basic operations with all windows --
   Move, Resize, Scroll, Center, Maximize, UnFocus, cycle through windows
   (Next), and also lets you open the Window List.
   You can open the Window List also by middle-cliking on the desktop,
   in any area with no windows at all.
   A side effect of opening the Window List is that its menu
   is the default one, so you can get it back. Anyway you can get back
   the default menu also by left-clicking on the screen background, in an area
   with no windows: this un-focuses all windows and, when no window is focused,
   you _always_ get the default menu.
   Clicking with left mouse button or hitting keyboard `Return' on
   a window name of the Window List will focus and Center the corresponding
   window.
   
   Other not-so-obvious things you can do from the Default menu are:
   "Full Screen" to maximize the current window to full-screen,
   RollUp to collapse a window to its title bar only, and back to normal size,
   Refresh to redraw the whole display in case it gets garbled,
   Raise/Lower to move the focused window to top/bottom of windows stack,
   and also unfocus if moving it to bottom of stack.
   
   You can use the menus even without a mouse: The `Pause' key opens the menu
   (to change it, edit your ~/.twinrc, or, if you disabled support for
   ~/.twinrc parser, edit server/hotkey.h and recompile)
   then you can transverse the menu with arrow keys, hit `Return'
   to select an entry in a menuitem or `Escape' to close the menu.
   Choosing Menu -> Window -> Move lets you move the focused window with
   arrows, Resize lets you resize it (still with arrows),
   while Scroll lets you scroll it: use arrows for one-line scrolls and
   Insert,Delete,PageUp,PageDown for one-page scrolls.
   There is a small problem now: if twin intercepts the `Pause' key,
   how can you have your programs receive it? This is what "Send Hotkey"
   is for: it sends a `Pause' key event to the focused window.

   Now, the next argument: Focusing and Freezing.
   
   Even if it comes quite natural to most people to press the left mouse button
   on the lower-right corner of windows to resize them, a thing you probably
   don't know is that if _while holding the left button_ you also press
   the middle or right button, the window will `freeze', i.e. it doesn't resize
   anymore when you move the mouse, but will istantly resize when you release
   the middle or right button. Also, while the window is `frozen', the virtual
   screen doesn't scroll. The same `freeze' technique can be used while
   dragging a window (to drag a window, press left button on window title).

   Downside:
   `Freezing' does not work if twin displays on X, you have a two-button mouse
   and you configured the X server with Option "Emulate3Buttons".
   That's a limit of your mouse / X server combination.

   Other maybe not-so-obvious things are:
   the button on top-left of each window, drawn as "[]", is the CLOSE button;
   the button on top-right, drawn as two up-down arrows, is the TOP/BACK button:
     click on it in the top window and it will become the last window;
     click on it in a window behind other windows, at it will become
     the top window;
   the button next to top-right, drawn as "><", is the ROLLUP button:
     click on it and it will collapse the window to its title bar;
     click on it again and it will restore the window to its normal size;
   the scrollbars are quite intuitive: click on the arrows near the lower-right
   corner to scroll the window contents one line (or row) at time;
   drag the `tab' (the solid white bar) to quickly scroll the window;
   click on the space before or after the `tab' to scroll the window contents
   one page at time.
   Twin splits the concepts of top window and focused window:
   left-clicking on a window will focus it, so that keypresses
   will go to that window, but you will need to click
   on the window's TOP/BACK button to have it become the top window. Clicking
   on the window's TOP/BACK button again will Lower and UnFocus the window.
   
   Twin also implements cut-n-paste, in the same way as linux console, xterm,
   and other terminals: you select some text by moving the mouse with
   the left button pressed and paste by clicking with the middle button.
   
   Again, you can tailor (almost) any of the above features to your tastes
   by editing your own ~/.twinrc configuration file. The file system.twinrc
   distributed with twin is a well commented sample configuration you can
   start from.
   
6. External programs

   If you have `twin' correctly installed and running (and eventually you
   loaded the Socket Server module) you can run an external program
   by typing its name, just as you do with X11 clients.
   If twin is not installed yet, you will need to set LD_LIBRARY_PATH to the
   directory where libTw.so.2 is: something like
	export LD_LIBRARY_PATH=<twin-top-dir>/lib
   should work.
   Also, if you don't start external programs from within a twin terminal
   window, you will need to set the display. Type
	echo $TWDISPLAY
   inside a twin terminal, then
	export TWDISPLAY=:<the-value-you-got>
   before running your external programs. To run external programs from
   another machine, using TCP sockets, do something like
	export TWDISPLAY=<host-name>:<the-value-you-got>
   In the last case, you will also need to authorize your clients to talk
   to twin. The authorization method currently used is similar to Xauthority:
   the file .TwinAuth in your home directory holds some magic data that
   clients use to answer the challenge received from twin. If that data
   is wrong or the file doesn't exist, clients can connect to twin only
   using the unix socket (TWDISPLAY=:<something>) so they must run
   on the same machine as twin; remote programs won't be able to connect.

   The external programs (clients) distributed with twin are:
   
	twattach  - utility to attach/detach twin from displays
	twdisplay - advanced utility to attach/detach twin from displays
	twcat     - twin-aware version of `cat'
	twclip    - a wannabe utility to manage clipboard.
	            For now, it's little more than test.
	twevent   - report twin events, like xev (X11) and mev (console/gpm)
	twmapscrn - twin equivalent of Linux console tool `mapscrn'
		    NOTE: when started from Linux console, twin will already
		    load the current consolemap translation, so using twmapscrn
		    is often not necessary.
		    
	twsendmsg - utility to send messages to running libTw clients. Options:
	    -h, -help           display this help and exit
	    -V, -version        output version information and exit
	    -control            send a MSG_USER_CONTROL message (default)
	    -clientmsg          send a MSG_USER_CLIENTMSG message
	    [-code=]<Code>      set the message code (default is open (2))
	    [-data=]<Data>      set the message data
	   Currently known codes for control messages are:
	    quit (0), restart (1), open (2)\n",
	
	twsetroot - customize twin background (see clients/README.twsetroot)
	twsysmon  - a system resources monitor (works on Linux only)
	twterm    - create remote twin terminal windows. Known options:
	    -h, -help		display this help and exit
	    -V, -version	output version information and exit
	    -t <title>		set window title
				(you will need to enclose <title> in quotes
				if it contains spaces or other special chars)
	    -e <command>	run <command> instead of user's shell
				(must be last option) 
	twthreadtest - a stupid demo to test libTw with threads.


   The `twterm' client and the builtin terminal emulator deserve a few extra
   explanations. They implement a linux terminal, so applications running
   inside them will see TERM=linux, but also support two different mouse
   reporting protocols: the first is the classical xterm-style reporting
   (enabled with ESC [?1000h and disabled with ESC [?1000l ) which is only
   capable to report mouse buttons hit/release and the window position where
   they happened; furthermore, it is limited to a 255x255 window.
   The second is an enhanced version which can also report mouse drags and has
   14 bits data for window width and height. It is enabled with ESC [?9h and
   disabled with ESC [?9l . Also, they support xterm-style escape sequence
   to change window title.
   
   Since most programs running inside a linux terminal don't expect to be able
   to use the mouse with xterm-style protocol, various tricks may be needed in
   order to have mouse functionality with applications running in a twin
   terminal. Here are some:
   
   Midnight Commander `mc': start with `mc -x'
   Other applications: you can try to set TERM=xterm and hope to fool them.



   The use of `twsendmsg' might not be obvious, so a few details can help:
   
   every twin client creates a message port inside twin, which is used to
   receive messages. These include keyboard and mouse events, window size
   changes, menu activity, and some other things. Anyway, not all messages
   are generated by the server. It is possible to create a message from
   a client and send it to another client. This makes possible, for example,
   to send a message to `twterm' saying "please open a shell window".
   To send exactly this message, one can use `twsendmsg' in the following way:
	twsendmsg "twterm" open
   ("Remote Twin Term" is the name of the message port created by `twterm',
   while "Builtin" is the name of the message port builtin into twin)
   Of course it is possible to start arbitrary commands with `twsendmsg',
   not just the user's shell:
	twsendmsg "Builtin" open "pine someone@somewhere.net"

   A last note: the message port must already exist to be able
   to send messages to it, so
	twsendmsg "twterm" [...]
   works only if there is at least one `twterm' running.
   Sending messages to "Builtin Twin Term", the message port of the builtin
   terminal emulator, would work too, but only if the terminal emulator code
   (term.so) is already loaded into twin. Sending messages to "Builtin"
   instead always works, and it can auto-load term.so if needed.
   
   You can send also other kinds of messages. A (useless?) example is
	twsendmsg "Builtin" quit
   which causes twin to exit, as if Menu -> File -> Quit was selected.
   
   6.1. Security Statement on Sockets:
   
	As said above,
	the authorization method currently used is similar to Xauthority:
	the file .TwinAuth in your home directory holds some magic data that
	clients use to answer the challenge received from twin. If that data
	is wrong or the file doesn't exist, clients can connect to twin only
	using the unix socket (TWDISPLAY=:<something>) so they must run
	on the same machine as twin; remote programs won't be able to connect.
	
	Also, the unix socket is set to permissions 600, so only the owner can
	connect to it (at least on Linux it works this way).
	
	The `challenge' is actually an MD5 checksum verification: server sends
	256 bytes of random data; client does MD5 of that data + .TwinAuth and
	sends MD5 back. If server agrees on MD5, it grants connection.
	This challenge method has an important feature:
	The contents of your .TwinAuth is NEVER transmitted through any socket.
	So, unless your home directory resides on an NFS filesystem, you can
	be sure that noone will be able to find the data contained in your
	.TwinAuth by spying the network between twin and the clients you start.
	On the other hand, the connection between twin and clients is NOT
	encrypted, so it is easy to find out what you type and what you see
	in the client windows by spying the network as above.


7. Transparent Compression

   Twin and libTw transparently support gzip compressed sockets
   by using the library `zlib'. If the connection between twin
   and the remote programs you want to run is slow,
   you may benefit from compression.
   
   To allow compression, you need zlib installed on your system,
   then ensure `./configure' found it: among the zillion of messages,
   it should also print a line like
   
   [...]
   checking for deflate in -lz... yes
   [...]
   
   finally compile twin and libTw.

   To actually use compression, append ",gz"
   to your $TWDISPLAY like in these examples:

      export TWDISPLAY=:0,gz
      export TWDISPLAY=myhost.somewhere.net:5,gz
      
   
8. Attach/Detach

   Twin can run without a display at all, can attach or detach from a display
   on the fly, and can also run with multiple simultaneous displays.
   
   There are various ways to temporarily close a display used by twin:
   
   1) select `Suspend' from the `File' entry of the default menu.
      This is equivalent to the normal Unix job control associated to CTRL-Z:
      twin shuts down all its displays and returns to the shell it was started
      from. To resume twin, just type `fg' (or send a SIGCONT to it).
      This may not work if you used 2) below, because that detaches twin
      from the job control mechanism used by shells.
      
   2) select `Detach' from the `File' entry of the default menu.
      WARNING: Be sure the Socket Server can be started before doing this!
               Otherwise you will not be able to talk to twin at all!
      In this case, twin shuts down all its displays and detaches
      (by forking in the background) from the shell it was started from,
      but keeps running as a daemon (with no display).
   
   3) run `twdetach' (more explanations below for this, but in this case
      it is equivalent to selecting `Detach' from the default menu).
   
   4) select `Display' from the `' entry of the default menu,
      watch the `Display' window pop up, choose a display from the list
      and click on `Remove'.
      
   There are two ways to have twin attach to a display
   (or to ONE MORE display, as twin can use multiple simultaneous displays):
   `twattach' and `twdisplay'.

   Let's start with `twattach':
   
      Basically, you run twattach specifying which display you want *twin*
      to attach to.
      Twin then tries to start that display by its own,
      while twattach's only work is to report all messages generated by twin
      during the attach (if you run twattach with the option `-q' (quiet),
      then twattach has nothing to do at all).
   
   Instead `twdisplay' works differently:
   
      You run twdisplay specifying which display you want *twdisplay* to use.
      
      Twdisplay tries to start that display, reporting any generated message.
      If the display succeeds in starting up, twdisplay connects to twin,
      registers itself as a special display, and then works as an intermediate
      layer between the display it started and twin:
      twdisplay sends to twin the events generated by the display,
      and when it receives draw requests from twin, it calls the appropriate
      functions of the display to keep it up-to-date.
      
   The two different programs have different advantages and disadvantages:
               
	       
   twattach:   advantages:  fast, efficient, extremely lightweight.
            disadvantages:  completely relies on twin to be able to use
	                    the display. For example, twin running on a host
			    cannot connect to `gpm' running on another,
			    and attaching twin to itself causes a deadlock.
   
   twdisplay:  advantages:  starts up the display by its own.
                            This means that if you have twin running on a host,
			    you can use twdisplay to attach twin to the console
			    of another host, WITH mouse support (gpm).
			    Also protects twdisplay from bugs, quirks and
			    limitations in display drivers and libraries
			    needed by them: libgpm can connect only ONCE
			    to A SINGLE gpm, libX11 calls exit() when
			    receives fatal errors from X server, etc.
			    Using `twdisplay' to attach twin to itself works!
            disadvantages:  eats more CPU and memory. Not really a problem
	    		    these days.
	    
	    
    Examples:
      
      $ twattach -hw=X
      tell the default twin (corresponding to $TWDISPLAY)
      to attach to the default X server (corresponding to $DISPLAY)

      $ twdetach -hw=X
      tell the default twin
      to detach ONE display attached to the default X server

      $ twdetach -twin@:5
      tell the twin corresponding to :5 to detach from ALL its displays
      and keep running in the background (same as using `Detach' from menu)

      $ twattach -twin@<some twin display> -hw=X@<some X display>
      tell twin correspinding to <some twin display>
      (for example :5, or myhost.somewhere.net:2)
      to attach to the X server corresponding to <some X display>
      The programs `twattach', `twin', and the X server do not need
      to run on the same host as long as they have the permissions
      to talk each other (see below for an explanation about how
      the file .TwinAuth is used for authorization control)
      
      $ twattach -twin@:5 -hw=tty
      tell twin :5 to attach to the same tty device you are running
      `twattach' on. For this to work, both `twattach' and `twin' must
      be running on the same host.

      $ twdisplay -twin@myhost.somewhere.net:1 -hw=tty
      attach twin at myhost.somewhere.net:1 to the tty device you are running
      `twdisplay' on. Since it is actually twdisplay that attaches to the tty,
      while twin just talks to twdisplay using a socket, `twdisplay' and `twin'
      may even be running on different hosts.

      $ twattach -twin@myhost.somewhere.net:1 -hw=tty@-
      tell twin at myhost.somewhere.net:1 to attach to its own controlling tty.
      This does not work if that twin has already detached from its tty,
      but you will be told that in case it happens.

      $ twdetach -twin@myhost.somewhere.net:1 -hw=tty@-
      tell twin at myhost.somewhere.net:1 to detach from its own controlling
      tty (supposing it was being used as a display)

      $ twattach -twin@:5 -hw=tty@<some tty device>,TERM=<terminal type>
      tell twin to attach to <some tty device>.
      In this case you must make sure no program is reading/writing
      on <some tty device> (for example you might run `sleep 365d' on it)
      or things will go BADLY wrong.

      WARNING:
        twin has no way to detect if the tty you specified is really
	a supported terminal. If you attach twin to an unsupported terminal,
	things might go BADLY wrong.

      $ twdisplay -twin@myhost.somewhere.net:1 -hw=twin@yourhost:3,gz
      attach twin running on myhost.somewhere.net:1
      to another twin running on yourhost:3 and display on it.
      The final ",gz" means that the connection between `twdisplay'
      and the second `twin' will be compressed.
      
      $ twattach -twin@<some twin display> -hw=ggi
      tell twin to fire up libggi and display on it.
      
      

    The most general syntax of twattach is:
      twattach [-a|-d] [-v|-q] [-s|-x] [-twin@<TWDISPLAY>] -hw=<display>[,options]

    The most general syntax of twdisplay is:
      twdisplay [-v|-q] [-s|-x] [-twin@<TWDISPLAY>] -hw=<display>[,options]

    switches have the following meaning:
      -a	: send attach command (default)
      -d	: send detach command (same as running `twdetach [args ...]')
      -v	: be verbose and display all messages generated by twin
	          while trying to attach (default)
      -q	: be quiet and display no messages
      -s, -share: allow multiple simultaneous displays (default)
      -x, -excl : request an eclusive display - detach all others

    if you do not specify `-twin@<TWDISPLAY>', the default $TWDISPLAY will
    be used.
      
    known displays are:
      
      -hw=X[@<XDISPLAY>]     or    -hw=X11[@<XDISPLAY>]
      -hw=twin[@<TWDISPLAY>]
      -hw=tty[@<tty device>]
      -hw=ggi[@<libggi target>]
	
    and known display options are:
      
      all displays : ",noinput" to start the display as view-only;
			keyboard and mouse activity on that display
			will be ignored.
		   : ",slow" to tell twin the display is slow and output
			to it should be buffered and chunked together as much
			as possible (this is on by default for -hw=X11)
		  
      -hw=X  or
      -hw=X11	: ",font=<fontname>" to choose your favourite X11 font
		        (default: vga).
		: ",charset=<name>" to inform the driver about the codepage
		        corresponding to the used font (default: autodetected).
		: ",drag" to allow using XCopyArea as redrawing speedup.
			This is off by default as on many X servers XCopyArea
			is actually slower than a normal redraw.
			Your mileage may vary.
      
      -hw=twin	: ",gz" to enable gzip compression on the connecting socket.
      
      -hw=tty	: ",stdout" to draw on stdout even if /dev/vcsa* is available.
		: ",termcap" to use termcap/ncurses interface even if other
			methods are available.
		: ",colorbug" use with termcap interface, if terminal does not
			reset colors to white on black using ESC [ m
			(or the appropriate sequence for the terminal).
		: ",xterm" to force xterm-style mouse in case it is not
			autodetected.
		: ",TERM=<terminal>" to specify the terminal type.
		: ",charset=<name>" to inform the driver of the codepage
		        used by the terminal (default: IBM437).

      -hw=ggi	: no options, use the zillion of libggi environment variables
		  to control libggi behaviour.



    A common situation is the following:
      
    You have a detached twin, whose TWDISPLAY is :2,
    running on a host (say plato.alter.net),
    you are sitting at the console of another host (say globe.alter.net)
    and you want to attach twin on the console of globe.alter.net.
    How?

    Attaching twin to the X server of globe.alter.net is easy, just run
    this command on globe
    $ twattach -twin@plato.alter.net:2 -hw=X@globe.alter.net:0
    
    or alternatively,
    $ twdisplay -twin@plato.alter.net:2 -hw=X@globe.alter.net:0

    (this requires you have the same .TwinAuth on both hosts
    and that the X server on globe accepts the connection attempt,
    either due to `xhost +plato.alter.net' or by having a suitable
    .Xauthority on both hosts)
      
    But attaching twin (running on plato) to the console of globe is another
    matter, since that twin has no way to reach the tty devices on globe.
    The easiest way is to use `twdisplay', running this command on globe
    console:
    
    $ twdisplay -twin@plato.alter.net:2 -hw=tty

    There are ways to solve the problem without `twdisplay', but they
    are both more complex and less functional, as they either require
    using telnet or ssh from globe to plato (and thus losing the mouse)
    or starting a SECOND twin, this time on globe console, and attaching
    the first twin on it.
    
    
   To avoid accidental problems, or to protect your twin session in a hostile
   environment, twin also implements exclusive displays:
   An exclusive display can be started only if there aren't already exclusive
   display running, it detaches all other displays while it starts, and forbids
   any other display to be attached as long as it is running.
   Twdetach is unable to detach an exclusive display: the only way to quit it
   is the Display window inside twin (killing the `twdisplay' process that
   requested the exclusive display works too).
   
   To request an exclusive display, you must add the option `-x' to twdisplay
   command line. Example:
   
   $ twattach -x -twin@:0 -hw=tty
   
   Exclusive displays can be started directly by twin, exactly in the same way:
   
   $ twin -x -hw=tty
   
   Of course, when specifying `-x', twin can only start one display.


   Summary of twin options:
     -h, -help               display this help and exit
     -V, -version            output version information and exit
     -secure                 forbid starting external programs
     -x                      start display as exclusive
     -nohw                   start in background without display
     -hw=<display>[,options] start with the given display (multiple -hw=... allowed)


9. Installing fonts

    a. X11:
    
    If you want to install the supplied vga.pcf.gz file, for use under X,
    you should do something like this (details are system dependant):

    copy fonts/vga.pcf.gz from the distribution to a misc fonts directory,
    I used /usr/X11R6/lib/X11/fonts/misc on my system.
    Run `mkfontdir' as root on the directory used.
    Run `xset fp rehash'.
    Use the command 'xlsfonts | grep vga' to see if the font has been
    registered correctly.

    This should fix some problems with twin displaying strange fonts under X,
    since if twin cannot find the `vga' font, it will fallback on `fixed',
    which has different encoding and thus completely different pseudo-graphical
    characters, and makes twin look really ugly.

    b. VGA text display:
    
    To use twin on a VGA or better text display, you can use the supplied
    VGA font `fonts/9x16' by typing a command like `setfont fonts/9x19' or
    `loadfont fonts/9x19' (again, details are system dependant).
    
    The VGA font `font/vgafont.raw' is included too, but was specifically
    tweaked for the old configuration option `Use alternate font' which
    has been removed in favour of Unicode support, and now it is only useful
    if you write an ad-hoc ~/.twinrc.
    
    As side note, if you are going to use twin on a VGA text display,
    I strongly suggest to set your VGA card to something better than
    the default 80x25. Some of the ways to do this are:
    using SVGATextMode;
    using the card BIOS;
    compiling framebuffer support in your linux kernel.
    

10. Greetings

    I hope you will like using twin as I liked writing it.
    Have fun...
   
   
    Massimiliano Ghilardi
    <max@linuz.sns.it>