Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!clyde!watmath!watdragon!jmsellens From: jmsellens@watdragon.waterloo.edu (John M. Sellens) Newsgroups: comp.windows.x Subject: Re: X V10 XOpenDisplay - should it assume hostname:0?? Message-ID: <3688@watdragon.waterloo.edu> Date: Tue, 6-Oct-87 00:01:16 EDT Article-I.D.: watdrago.3688 Posted: Tue Oct 6 00:01:16 1987 Date-Received: Fri, 9-Oct-87 05:14:49 EDT Reply-To: jmsellens@watdragon.waterloo.edu (John M. Sellens) Organization: U. of Waterloo, Ontario Lines: 99 I (John Sellens) originally asked: > Currently, it seems that the X V10.4 XOpenDisplay requires > either an argument or an environment variable, and if both of > of them are missing, or if a display number is not given, > then XOpenDisplay will fail. My question is: isn't it > reasonable for it to assume the current host and display 0 > if either or both are missing? > Jim Gettys answered: > Not really; there are people who run more than server from a single > machine. This was true for VS100's, and is true today for some > VAXstation II/GPX machines (dual headed) ... > > It is more than slightly irritating if other people's mistakes pop > up windows on your display. ... It seemed best to return an error > rather than blindly continue. and Paul Raveling added: > In my opinion this is eminently reasonable. I'd rather have Xlib > take a reasonable default than to have to code the defaulting into > each client we write. > > We haven't, to my knowledge, had that sort of threat yet in using > X in our corner of ISI. In our environment the benefits of this > defaulting would outweigh the risks. > > BTW, I'm using a two-headed Bobcat; others on our project have > private single-headed Bobcats at this time. So - I figured what the heck, and added it to our copy of Xlib anyway. It seems to work, so I thought that I would throw it out into the net in case anyone else was interested. Just a couple of trivial changes to Xlib/XDisplayName.c, the revised version of which is included here in all it's splendor - the changes are marked with #ifdef waterloo. John John Sellens -- Logic Programming and Artificial Intelligence Group {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdragon!jmsellens jmsellens@dragon.waterloo.{edu,CDN} jsellens@watmta.BITNET jmsellens%dragon@waterloo.csnet /* $Header: XDisplayName.c,v 10.1 86/11/19 18:17:19 jg Rel $ */ /* XDisplayName.c */ /* * Returns the name of the display XOpenDisplay would use. This is better * than just printing the "display" variable in a program because that * could be NULL and/or there could be an environment variable set. * This makes it easier for programmers to provide meaningful error * messages. * * * For example, this is used in XOpenDisplay() as * strncpy( displaybuf, XDisplayName( display ), sizeof(displaybuf) ); * if ( *displaybuf == '\0' ) return( NULL ); * This check is actually unnecessary because the next thing is an index() * call looking for a ':' which will fail and we'll return(NULL). */ /* Written at Waterloo - JMSellens */ #include #ifdef waterloo #include /* for MAXHOSTNAMELEN */ #endif char *getenv(); char * XDisplayName( display ) char *display; { #ifdef waterloo /* has to be static since we return it */ static char hname[MAXHOSTNAMELEN+5]; /* xtra space for :0 */ #endif char *d; if ( display != (char *)NULL && *display != '\0' ) return( display ); if ( (d = getenv( "DISPLAY" )) != (char *)NULL ) return( d ); #ifdef waterloo /* This causes XOpenDisplay to assume the current host for display if no other guess is available - Jim Gettys said it would be a bad thing and lead to more people popping windows on your terminal by accident - JMS Oct 5/87 */ if ( gethostname(hname,sizeof(hname))==0 ) { (void) strcat( hname, ":0" ); return( hname ); } #endif return( "" ); }