Wha-?
Only on the local machine?
I beg of you - don't do that. First off, determining that the X server is running on the local machine is a hard problem. Secondly, why limit me at all? If I set my DISPLAY to "othermachine:8", why should that bother you? The X protocol handles this just fine!
Proof that it's a hard problem: one machine at work doesn't have X loaded locally at all. But I use DISPLAYs of machine:2, machine:7, and localhost:10.0 (and others, but that's all I've got at this moment in time). None of them are "local" per se. The first two are VNC servers (different users). The X server is really running on that machine, but they're never visible on the monitor attached to the machine. The first one is only visible on my home computer (3000km away). The second is one I share with another coworker (we can both be on the phone and on VNC seeing the same screen). The third is my SSH tunnel which means the X server is actually physically at home, even though it says "localhost". (Which is faster, the VNC server or the SSH tunnel, depends on what I'm doing, so I have both, and use each when appropriate.) "machine:0" doesn't exist on this machine.
Even using ":0" as the local display can be problematic since I can put VNC server on that port as long as the local X server isn't loaded. Or I can have two local X servers on two different monitors - thus one of them could be :1 (or :0.1, depending). Detecting this is a waste of time. If the user gives you a DISPLAY, use it. If they don't, don't. That's as smart as I would ever want my software to be. Anything else, and you're trying to outsmart me, when I'm merely using the X protocol to the fullest advantage I can. Remember: the user may know more about X than you do. Let them use that knowledge, and let your APIs deal with that.
| [reply] |
Thank you for the repeated feedback. I will certainly take these additional insightful cmts into account!
| [reply] |
In that case, it's dead simple:
use Sys::Hostname;
sub run_with_gui { # returns boolean
defined $ENV{'DISPLAY'} or return 0;
my( $display ) = $ENV{'DISPLAY'} =~ /(.*):/;
$display eq '' || $display eq hostname()
}
| [reply] [d/l] |