display.rc
author Claus Gittinger <cg@exept.de>
Fri, 27 Jun 1997 18:47:33 +0200
changeset 227 73b33f3bfc72
parent 218 563d4f4446d8
child 228 f800de5df0c4
permissions -rw-r--r--
*** empty log message ***

"*
 * $Header$
 *
 * ST/X startup configuration file:
 *
 * 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.
 *"

"*
 * 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:[
    Image addReader:rdr suffix:'xbm'.
    Image addReader:rdr suffix:'bm'.
].
rdr := Smalltalk at:#TIFFReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'tif'.
    Image addReader:rdr suffix:'tiff'.
].
rdr := Smalltalk at:#GIFReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'gif'.
].

"/ 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:[
    Image addReader:rdr suffix:'im8'.
    Image addReader:rdr suffix:'icon'.
].

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

rdr := Smalltalk at:#WindowsIconReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'bmp' mimeType:'image/x-MS-bmp'.
    Image addReader:rdr suffix:'ico'.
].

rdr := Smalltalk at:#JPEGReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'jpg' mimeType:'image/jpeg'.
    Image addReader:rdr suffix:'jpeg'.
].

rdr := Smalltalk at:#PBMReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'ppm' mimeType:'image/x-portable-pixmap'.
    Image addReader:rdr suffix:'pbm' mimeType:'image/x-portable-bitmap'.
    Image addReader:rdr suffix:'pgm' mimeType:'image/x-portable-graymap'.
    Image addReader:rdr suffix:'pnm' mimeType:'image/x-portable-anymap'.
].

rdr := Smalltalk at:#ST80FormReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'form'.
].

rdr := Smalltalk at:#FaceReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'face'.
].

rdr := Smalltalk at:#XPMReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'xpm' mimeType:'image/x-xpixmap'.
    Image addReader:rdr suffix:'pm'.
].

rdr := Smalltalk at:#PCXReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'pcx' mimeType:'image/x-pcx'.
].

rdr := Smalltalk at:#TargaReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'tga' mimeType:'image/x-targa'.
].

rdr := Smalltalk at:#XWDReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'xwd' mimeType:'image/x-xwindowdump'.
].

rdr := Smalltalk at:#BlitImageReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'48x48x1'.
].

rdr := Smalltalk at:#IrisRGBReader ifAbsent:nil.
rdr notNil ifTrue:[
    Image addReader:rdr suffix:'rgb' mimeType:'image/x-rgb'.
].

"/ experimanetal and not yet delivered

"/ rdr := Smalltalk at:#PNGReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/     Image addReader:rdr suffix:'png' mimeType:'image/x-png'.
"/ ].

"/ rdr := Smalltalk at:#PCDReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/     Image addReader:rdr suffix:'pcd' mimeType:'image/x-photo-cd'.
"/ ].

"/ rdr := Smalltalk at:#CMURasterReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/     Image addReader:rdr suffix:'ras' mimeType:'image/x-cmu-raster'.
"/ ].

"/ movie formats - experimanetal and not yet complete

"/ rdr := Smalltalk at:#FLIMovieReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/     Image addReader:rdr suffix:'fli'.
"/ ].

"/ rdr := Smalltalk at:#AVIMovieReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/    Image addReader:rdr suffix:'avi' mimeType:'video/x-msvideo'.
"/ ].

"/ rdr := Smalltalk at:#QuickTimeMovieReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/    Image addReader:rdr suffix:'qt' mimeType:'video/quicktime'.
"/    Image addReader:rdr suffix:'mov'.
"/    Image addReader:rdr suffix:'moov'.
"/ ].

"/ rdr := Smalltalk at:#MPEG2MovieReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/    Image addReader:rdr suffix:'mpg2' mimeType:'video/x-mpeg2'.
"/    Image addReader:rdr suffix:'mpv2'.
"/    Image addReader:rdr suffix:'mp2v'.
"/ ].

"/ rdr := Smalltalk at:#MPEGMovieReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/    Image addReader:rdr suffix:'mpeg' mimeType:'video/mpeg'.
"/    Image addReader:rdr suffix:'mpg'.
"/    Image addReader:rdr suffix:'mpe'.
"/    Image addReader:rdr suffix:'mpv'.
"/    Image addReader:rdr suffix:'vbs'.
"/    Image addReader:rdr suffix:'mpegv'.
"/ ].

"/ rdr := Smalltalk at:#SGIMovieReader ifAbsent:nil.
"/ rdr notNil ifTrue:[
"/    Image addReader:rdr suffix:'movie' mimeType:'video/x-sgi-movie'.
"/ ].

!

"*
 * 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 size > 0 ifTrue:[
    idx := arguments indexOf:'-display'.
    idx ~~ 0 ifTrue:[
	displayVar := arguments at:idx + 1.
	arguments removeAtIndex:idx+1.
	arguments removeAtIndex:idx.
    ].
].
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:[
	'display.rc [warning]: cannot determine display I am running on' errorPrintCR.
    ] 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:[
	    |serverVendor|
	    serverVendor := Display serverVendor.

	    serverVendor = 'The XFree86 Project, Inc'
	    ifTrue:[
		displayType := 'xfree'
	    ].
	    serverVendor = 'Silicon Graphics'
	    ifTrue:[
		displayType := 'iris'
	    ].
	    serverVendor = 'International Business Machines'
	    ifTrue:[
		displayType := 'aix'
	    ].
	].

	"
	 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:[
	"Default for supportsDeepIcons is false.
	 Set default value only when ImageDisplayName changes
	 and d_displayType is called.
	"
	Display supportsDeepIcons:false.
	Smalltalk isStandAloneApp ifFalse:[
	    ('display.rc [info]: trying display setup ''d_' , displayType , '.rc'' ...') infoPrintCR.
	].
	Smalltalk fileIn:('d_' , displayType , '.rc')
    ].
    Smalltalk at:#'_ImageDisplayName' put:displayType
]
!

"*
 * now, this is a nice one:
 *
 * if the image was saved on a different type of display, ask
 * user, if he/she'd like to have the style changed.
 *"
|depthChange colorChange greyChange reconfigure|

depthChange := false.
colorChange := false.
greyChange := false.

(Smalltalk includesKey:#'_ImageDisplayDepth') ifTrue:[
    depthChange := ((Smalltalk at:#'_ImageDisplayDepth') ~~ Display depth)
].
(Smalltalk includesKey:#'_ImageDisplayHasColor') ifTrue:[
    colorChange := ((Smalltalk at:#'_ImageDisplayHasColors') ~~ Display hasColors)
].
(Smalltalk includesKey:#'_ImageDisplayHasGreyscales') ifTrue:[
    greyChange := ((Smalltalk at:#'_ImageDisplayHasGreyscales') ~~ Display hasGreyscales)
].
(depthChange or:[colorChange or:[greyChange]]) ifTrue:[
    reconfigure := self confirm:'Display capabilities have changed

Do you want to reconfigure the view style ?'.

    reconfigure ifTrue:[
	Display knownViews do:[:aView |
	    aView notNil ifTrue:[
		aView reinitStyle.
	    ]
	].
    ].
].

Smalltalk at:#'_ImageDisplayDepth' put:Display depth.
Smalltalk at:#'_ImageDisplayHasColors' put:Display hasColors.
Smalltalk at:#'_ImageDisplayHasGreyscales' put:Display hasGreyscales.
!

"*
 * 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 = 'win32') ifTrue:[
	(Number readFromString:((OperatingSystem getSystemInfo) at:#release) onError:0)
	>= 4.0 ifTrue:[
	    View defaultStyle:#'mswindows3' 
	] ifFalse:[
	    View defaultStyle:#'mswindows' 
	]
    ].
    View defaultStyle isNil ifTrue:[
	Display hasGreyscales ifTrue:[
	    View defaultStyle:#iris
	] ifFalse:[
	    View defaultStyle:#normal
	]
    ].
    'display.rc [info]: no style set - default to ' infoPrint.
    View defaultStyle infoPrintCR
]
!