• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: X11 Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: X11 Question


  • Subject: Re: X11 Question
  • From: Drew Mccormack <email@hidden>
  • Date: Thu, 25 Aug 2005 09:03:01 +0200
  • Resent-date: Thu, 25 Aug 2005 09:06:41 +0200
  • Resent-from: Drew Mccormack <email@hidden>
  • Resent-message-id: <email@hidden>
  • Resent-to: email@hidden



On Aug 25, 2005, at 8:46 AM, Nathan Brazil wrote:

Hi.  I am writing a X11 application launcher that does the following:

1. Launch X11 if it is not already launched
2. Set the DISPLAY environment variable
3. Set some other environment variables
4. Launch the X11 application

All is well, except for step 2, where I need to figure out the user's X11 display (:0, :1, etc.). I see that if I do a grep for X11, one of the X11 instances will tell me the the display on the command-line it was started with, but that seems inelegant to me.

Is there a better way?
I don't know of any nice way to do it. I use the following code, which looks at the lock files generated to see if a user already has a DISPLAY, and if not, what the next display number is that will be assigned. It assumes X11 assigns displays in a certain order, and there is no guarantee it won't break in future.

int GetDisplayNumber() {
    int i;
    NSFileManager *fm = [NSFileManager defaultManager];

// Try to find existing lock file
for ( i = 0; i < 20; ++i ) {
NSString *lockFilePath = [NSString stringWithFormat:@"/tmp/.X %d-lock", i];
if ( [fm fileExistsAtPath:lockFilePath] ) {
NSDictionary *fattrs = [fm fileAttributesAtPath:lockFilePath traverseLink:YES];
if ( [[fattrs fileOwnerAccountName] isEqualToString:NSUserName()] ) return i;
}
}


// Take number of next available lock file
for ( i = 0; i < 20; ++i ) {
NSString *lockFilePath = [NSString stringWithFormat:@"/tmp/.X %d-lock", i];
if ( ![fm fileExistsAtPath:lockFilePath] ) return i;
}


    return -1;
}


Drew


--------------------------------------------------------- Drew McCormack

www.maniacalextent.com


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Prev by Date: Re: X11 Question
  • Next by Date: Change Budle Identifier, then lost defaults
  • Previous by thread: Re: X11 Question
  • Next by thread: Change Budle Identifier, then lost defaults
  • Index(es):
    • Date
    • Thread