From: Mads <mad...@ya...> - 2005-10-23 18:37:48
|
Hi Arjan and Lennart > Arjan van IJzendoorn wrote: >=20 > > Hello Mads, > > > >> This leads me to the following question: How does one test if a dis= play > >> is available using WxHaskell? > > > > > > I don't know, but you might check the wxWidgets documentation first =20 > > to see whether this framework supports it. If not, there is no chance= =20 > > of finding a wxHaskell method that does it. I couldn't find one after= =20 > > quickly scanning the available classes. > > > > Alternatively, is there maybe an environment variable that tells you = =20 > > whether a display is available? >=20 > Usually the environment variable DISPLAY is set if a display is=20 > available. This is of course no guaranty that the display can actually=20 > be opened. I created the following function: -- WARNING: This function has only been tested on Linux (Debian). displayAvailable :: IO Bool displayAvailable =3D do isWindows <- isSet "SystemDrive" if isWindows then return True else isSet "DISPLAY" -- We are geussing it's Lin= ux. =20 where isSet environmentVariable =3D catch (do getEnv environmentVariable return True ) (\_ -> return False) However, it is not really cross-platform. It does work on Linux and maybe on MS Windows. It also assumes MS Windows always has a graphical display (is this true?). However shouldn't a cross platform solution be part of WxHaskell? Another problem with the solution is that if the DISPLAY variable is set, but the user is not allowed to use the display which the DISPLAY variable refers to, the function will return (IO True) even though it should not. This can happen after an su-command, if you have not done a "xhost localhost". Thank you both for the replies. /Mads Lindstr=F8m >=20 > Cheers, > Lennart >=20 > > > > Cheers, Arjan |