display.rc
author Claus Gittinger <cg@exept.de>
Tue, 27 Feb 1996 19:28:39 +0100
changeset 86 7cb0bbfd6431
parent 84 06f58dd9b0ae
child 87 e243ea13b62c
permissions -rw-r--r--
*** empty log message ***

"*
 * $Header$
 *
 * DONT add site specific things here - use your own d_xxx.rc file instead
 * where xxx stands for your displays hostname(s)
 *
 * display related configuration:
 *   first do some common setup, then try to find a
 *   display specific initialization file.
 *"

"*
 * key bindings common to all display types
 * use event monitor, to see what the Xserver sends us;
 * put display-specific stuff into a d_hostName.rc file.
 *"
|map|

map := Display keyboardMap.

map bindValue:#UserInterrupt  to:#Ctrlc.    "interrupt window process"
map bindValue:#FlushInput     to:#CtrlX.    "flush typeahead input"
map bindValue:#DestroyView    to:#CmdCtrlX. "to destroy dead views"
map bindValue:#DestroyTopView to:#CmdCtrlx. "to destroy dead views"

map bindValue:#DoIt       to:#Cmdd.         "i.e. Cmd-d / Alt-d (sometimes Meta-d)"
map bindValue:#InspectIt  to:#Cmdi.         "evaluate & inspect result"
map bindValue:#PrintIt    to:#Cmdp.         "evaluate and paste result"

map bindValue:#Copy       to:#Cmdc.         "copy selection to buffer"
map bindValue:#Cut        to:#Cmdx.         "cut selection into buffer"
map bindValue:#Paste      to:#Cmdv.         "paste buffer or external selection"
map bindValue:#Replace    to:#Cmdr.         "same as paste"
map bindValue:#Find       to:#Cmds.         "open searchbox"
map bindValue:#FindNext   to:#Cmdf.         "search fwd for last searchpattern or selection"
map bindValue:#FindPrev   to:#Cmdb.         "search bwd for last searchpattern or selection"
map bindValue:#SelectAll  to:#CmdA.         "that is Alt-shift-a"
map bindValue:#GotoLine   to:#Cmdg.
map bindValue:#SelectWord to:#Cmdw.         "select word under cursor"

map bindValue:#Accept     to:#Cmda.
map bindValue:#Explain    to:#Cmde.
map bindValue:#Explain    to:#Cmdh.

map bindValue:#DeleteLine to:#Ctrlx.

map bindValue:#NextPage     to:#Next.    "typically labelled PageDown on keyboard"
map bindValue:#PreviousPage to:#Prior.   "typically labelled PageUp on keyboard"

map bindValue:#PreviousPage to:#Ctrlb.   "vi behavior"
map bindValue:#NextPage     to:#Ctrlf.   "vi behavior"
map bindValue:#HalfPageUp   to:#Ctrlu.
map bindValue:#HalfPageDown to:#Ctrld.

map bindValue:#BeginOfText  to:#Home.    "some prefer to bind #BeginOfLine to #Home"
map bindValue:#EndOfText    to:#End.     "some prefer to bind #EndOfLine to #End"
map bindValue:#BeginOfLine  to:#Ctrla.
map bindValue:#EndOfLine    to:#Ctrle.
map bindValue:#NextWord     to:#Ctrlw.

map bindValue:#ScrollUp     to:#CtrlCursorUp.    
map bindValue:#ScrollDown   to:#CtrlCursorDown.    

map bindValue:#SearchMatchingParent  to:#Ctrlm.
map bindValue:#SelectMatchingParents to:#Cmdm.

map bindValue:#SelectToEnd           to:#CtrlE.   "that is ctrl-shift-e"
map bindValue:#SelectFromBeginning   to:#CtrlA.   "that is ctrl-shift-a"
map bindValue:#ExpandSelectionByLine to:#Ctrll.   "try multiple Ctrl-l's ..."


"Notice:
  Cmd-CursorLeft/Right and Alt-CursorLeft/Right
  are also used by some winmdowmanagers (fvwm)
  if this is the case on your system, either
  change the following to use different keys,
  or change the windowmanagers configuration file
  (usr/lib/X11/xxxwm/*rc).
  The above is the reason that the following defines Ctrl-xxx
  as an alternative (mwm in the INDY also uses the alt-sequences)
"
map bindValue:#FocusNext     to:#CmdCursorRight.   "experimental"
map bindValue:#FocusPrevious to:#CmdCursorLeft.    "experimental"
map bindValue:#FocusNext     to:#AltCursorRight.   "experimental"
map bindValue:#FocusPrevious to:#AltCursorLeft.    "experimental"
map bindValue:#FocusNext     to:#CtrlCursorRight.  "experimental"
map bindValue:#FocusPrevious to:#CtrlCursorLeft.   "experimental"
map bindValue:#FocusNext     to:#CtrlTab.	   "experimental"

"/ cannot do this: otherwise tab character is lost ...
"/ map bindValue:#FilenameCompletion to:#Tab.

"
 * on some german keyboards, the x-server does NOT correctly
 * xlate characters ....
 *"
"
map bindValue:$[ to:#'Alt['.
map bindValue:$] to:#'Alt]'.
map bindValue:${ to:#'Alt{'.
map bindValue:$} to:#'Alt}'.
map bindValue:$\ to:#'Alt\'.
map bindValue:$| to:#'Alt|'.
"

"*
 * international characters - map to iso8859 values
 *"
map bindValue:(Character value:16rFC) to:#udiaeresis.
map bindValue:(Character value:16rE4) to:#adiaeresis.
map bindValue:(Character value:16rF6) to:#odiaeresis.
map bindValue:(Character value:16rDC) to:#Udiaeresis.
map bindValue:(Character value:16rC4) to:#Adiaeresis.
map bindValue:(Character value:16rD6) to:#Odiaeresis.
map bindValue:(Character value:16rDF) to:#ssharp.

"*
 * need more here (french ...)
 *"

"*
 * misc characters (if your keyboard supports them)
 *"
map bindValue:(Character value:16rA7) to:#section.
map bindValue:(Character value:16rB0) to:#degree.
map bindValue:(Character value:16rB2) to:#twosuperior.
map bindValue:(Character value:16rB3) to:#threesuperior.
map bindValue:(Character value:16rB5) to:#mu.


"*
 * numeric keypad - binding to normal numeric keys
 *"
"/ map bindValue:$0 to:#'KP_Insert'.
"/ map bindValue:$1 to:#'KP_End'.
"/ map bindValue:$2 to:#'KP_Down'.
"/ map bindValue:$3 to:#'KP_Next'.
"/ map bindValue:$4 to:#'KP_Left'.
"/ map bindValue:$5 to:#'KP_Begin'.
"/ map bindValue:$6 to:#'KP_Right'.
"/ map bindValue:$7 to:#'KP_Home'.
"/ map bindValue:$8 to:#'KP_Up'.
"/ map bindValue:$9 to:#'KP_Prior'.
"/ map bindValue:#Retrun to:#'KP_Enter'.
"/ map bindValue:#Backspace to:#'KP_Delete'.
!


"*
 * mouse-button translation
 *
 * (allowed are #select #menu and #paste)
 *
 * the following line puts paste onto the right button (as in xterm):
 *"
"/ Screen buttonTranslation:#(select #menu #paste).

"*
 * while that one puts the pop-up menu both on the middle and right buttons:
 *"
"/ Screen buttonTranslation:#(select #menu #menu).
Screen buttonTranslation:#(1 2 2).

"*
 * lefthanders can use:
 *"
"/ Screen buttonTranslation:#(#menu #menu #select).
!

"*
 * define extensions for image files (i.e. extension-to-readerClass
 * mappings). Some of the readers are autoloaded (see patches file).
 * Moved this from code to here (from Image-class), for more flexibility
 * actually since this is not display- but host specific (naming conventions)
 * it should be moved into the host.rc or h_xxx.rc file
 *
 * Some readers are optional and therefore, only installed if the
 * corresponding Smalltalk class is nonNil; not accessing it as global,
 * but via a SMalltalk>>at: message - this avoids warning messages
 * during startup, if classes are missing and the globals are undefined.
 *"
|formats rdr|

formats := Image fileFormats.
rdr := Smalltalk at:#XBMReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.xbm'  put:rdr.
    formats at:'.bm'   put:rdr.
].
rdr := Smalltalk at:#TIFFReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.tiff' put:rdr.
    formats at:'.tif'  put:rdr.
    formats at:'.TIF'  put:rdr.
].
rdr := Smalltalk at:#GIFReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.gif'  put:rdr.
    formats at:'.GIF'  put:rdr.
].

"/ still to come ...
"/ formats at:'.img'  put:IMGReader.
"/ formats at:'.IMG'  put:IMGReader.
"/ formats at:'.mac'  put:MacPaintReader. 

rdr := Smalltalk at:#SunRasterReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.im8'  put:rdr.
    formats at:'.icon' put:rdr.
].

"/ still to come ...
"/ formats at:'.g3'   put:G3FileReader.   

rdr := Smalltalk at:#WindowsIconReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.bmp'  put:rdr.
    formats at:'.ico'  put:rdr.
    formats at:'.BMP'  put:rdr.
    formats at:'.ICO'  put:rdr.
].

rdr := Smalltalk at:#JPEGReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.JPG'  put:rdr.
    formats at:'.jpg'  put:rdr.
    formats at:'.jpeg' put:rdr.
].

rdr := Smalltalk at:#PBMReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.ppm'  put:rdr.
    formats at:'.pbm'  put:rdr.
    formats at:'.pgm'  put:rdr.
].

rdr := Smalltalk at:#ST80FormReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.form' put:rdr.
].

rdr := Smalltalk at:#FaceReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.face' put:rdr.
].

rdr := Smalltalk at:#XPMReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.pm'   put:rdr.
    formats at:'.xpm'  put:rdr.
].

rdr := Smalltalk at:#PCXReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.pcx'  put:rdr.
    formats at:'.PCX'  put:rdr.
].

rdr := Smalltalk at:#TargaReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.tga'  put:rdr.
    formats at:'.TGA'  put:rdr.
].

rdr := Smalltalk at:#XWDReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'.xwd'  put:rdr.
].

rdr := Smalltalk at:#BlitImageReader ifAbsent:nil.
rdr notNil ifTrue:[
    formats at:'48x48x1'  put:rdr.
]
!

"*
 * find out, on what type of display we run
 * (boy, they should have added this to the x-protocol)
 *
 * look for a file named 'd_<displayname>.rc' and file it in
 *"

|arguments displayVar display displayType s idx|

"find display name from environment or -display argument"

arguments := Smalltalk commandLineArguments.
arguments notNil ifTrue:[
    idx := arguments indexOf:'-display'.
    idx ~~ 0 ifTrue:[
        displayVar := arguments at:idx + 1.
    ].
].
displayVar isNil ifTrue:[
    displayVar := OperatingSystem getEnvironment:'DISPLAY'.
].
display := displayVar.

displayVar notNil ifTrue:[
    ((displayVar startsWith:':0') 
    or:[(displayVar startsWith:'unix:')
    or:[displayVar startsWith:'shm:']]) ifTrue:[
	"running on a local display"
	display := OperatingSystem getHostName.
    ] ifFalse:[
	(displayVar endsWith:':0') ifTrue:[
	    display := displayVar copyTo:(displayVar size - 2)
	] ifFalse:[
	    (displayVar endsWith:':0.0') ifTrue:[
		display := displayVar copyTo:(displayVar size - 4)
	    ]
	]
    ].
    display isNil ifTrue:[
	'cannot determine display I am running on' errorPrintNL.
    ] ifFalse:[
	"
	 if there is a corresponding file d_<displayName>.rc ...
	 thats the one to take.
	"
	s := Smalltalk systemFileStreamFor:('d_' , display , '.rc').
	s notNil ifTrue:[
	    displayType := display.
	    s close.
	].

	"
	 if the X-server gives some info,
	 take that as a base
	"
	displayType isNil ifTrue:[
	    Display serverVendor = 'International Business Machines'
	    ifTrue:[
		displayType := 'aix'
	    ].
	    Display serverVendor = 'Silicon Graphics'
	    ifTrue:[
		displayType := 'iris'
	    ].
	].

	"
	 otherwise ...
	"
	displayType isNil ifTrue:[
	    "
	     just an example - stuff can also be hardwired here ...
	    "
	    display notNil ifTrue:[
		(display startsWith:'clam') ifTrue:[
		    displayType := 'next'
		].
		(display startsWith:'porty') ifTrue:[
		    displayType := 'portable'
		].
		(display startsWith:'blue') ifTrue:[
		    displayType := 'iris'
		].
		(display startsWith:'sun') ifTrue:[
		    displayType := 'sun'
		].
		(display startsWith:'hp') ifTrue:[
		    displayType := 'hpux'
		].
		"
		 if, in your organization, the display type can
		 be deduced from the hostname,
		 use something like:
		"
"/                (display startsWith:'slsv') ifTrue:[
"/                    "all those machines at SEL are suns"
"/                    displayType := 'sun'
"/                ].
"/                (display startsWith:'frxt') ifTrue:[
"/                    "all those machines at AEG are xterminals"
"/                    displayType := 'xterminal'
"/                ].
"/                (display startsWith:'frlx') ifTrue:[
"/                    "all those machines at AEG are linux boxes with olwm"
"/                    displayType := 'linux_olwm'
"/                ].
	    ].
	].
    ].

    "
     final fallback: take OperatingSystem if we are running a local
     connection.
     the used name is one of:
	d_next.rc
	d_iris.rc
	etc.
    "
    displayType isNil ifTrue:[
	"use type of machine smalltalk is running on as default ..."

	(displayVar startsWith:':0') ifTrue:[
	    displayType := OperatingSystem getSystemType.
	] ifFalse:[
	    (displayVar startsWith:(OperatingSystem getHostName , ':0')) ifTrue:[
		displayType := OperatingSystem getSystemType.
	    ]
	]
    ]
].

"now, if the above mess found something, we have it in displayType;
 fileIn d_<displayType>.rc"

displayType notNil ifTrue:[
    (Smalltalk at:#'_ImageDisplayName') ~= displayType ifTrue:[
	Smalltalk isStandAloneApp ifFalse:[
	    ('trying display setup d_' , displayType , '.rc ...') errorPrintNL.
	].
	Smalltalk fileIn:('d_' , displayType , '.rc')
    ].
    Smalltalk at:#'_ImageDisplayName' put:displayType
]
!

"*
 * set a default style, if not been set by rc-file
 * this is set according the system we are running on.
 * Notice: normally, the below is not needed, since the style
 *         is always set by the d_xxx.rc file.
 *         Except, when the d_xxx.rc is not present.
 *"
|type|

View defaultStyle isNil ifTrue:[
    type := OperatingSystem getSystemType.
    type = 'sunos' ifTrue:[
	View defaultStyle:#openwin
    ].
    type = 'next' ifTrue:[
	View defaultStyle:#next
    ].
    type = 'iris' ifTrue:[
	View defaultStyle:#iris
    ].
    type = 'linux' ifTrue:[
	View defaultStyle:#iris 
    ].
    type = 'hpux' ifTrue:[
	View defaultStyle:#'motif' 
    ].
    type = 'ultrix' ifTrue:[
	View defaultStyle:#'motif_dec2' 
    ].
    type = 'os2' ifTrue:[
	View defaultStyle:#'os2' 
    ].
    (type = 'mswindows' or:[type = 'nt']) ifTrue:[
	View defaultStyle:#'mswindows' 
    ].
    type = 'win95' ifTrue:[
	View defaultStyle:#'mswindows3' 
    ].
    View defaultStyle isNil ifTrue:[
	Display hasGreyscales ifTrue:[
	    View defaultStyle:#iris
	] ifFalse:[
	    View defaultStyle:#normal
	]
    ].
    'no style set in display.rc - default to ' errorPrint.
    View defaultStyle errorPrintNL
]
!