问题
My question is: is there a way to set up a virtual display as default display on a linux server (so that all GUI application launched will be displayed on that display, if no counter indication is made)?
I tried using this: xvfb-run java -jar autoclick.jar
, which produces the following output :
searching graphic devices
is Headless:false
screen N°1 width:1600 height:900
just 1 robot click:
Magic button clicked !
and here's the autoclick code :
System.out.println("searching graphic devices");
System.out.println("is Headless:"+GraphicsEnvironment.isHeadless());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
int count = 1;
for(GraphicsDevice screen : ge.getScreenDevices())
{
System.out.println("screen N°"+count+" width:"+screen.getDisplayMode().getWidth()
+" height:"+screen.getDisplayMode().getHeight());
}
{... create a JFrame and add a JButton that closes the application and prints a message to the console when clicked}
System.out.println("just 1 robot click:");
try
{
robot = new Robot();
justOneClick(frame.getX()+100, frame.getY()+100);
}
catch(AWTException e)
{
e.printStackTrace();
}
To make it short, here are my 2 problems:
I still have to call xvfb-run every time i want to launch an application on the virtual display. Which means that applications that are not launched by me are not launched on the virtual display.
I can't launch another application on the display created by xvfb-run.
Sorry for my bad English syntax, and thank you for your time.
回答1:
Set up a virtual X server in the background with Xfvb, then set the DISPLAY variable accordingly:
Xvfb :1 -screen 0 1920x1080x24+32 -fbdir /var/tmp &
export DISPLAY=:1
java -jar autoclick.jar
java -jar autoclick.jar
java -jar autoclick.jar
(and again, and again, and again...)
Due to the DISPLAY variable, any application started in that terminal will use your virtual X server. I guess what xvfb-run does is set up a Xvfb, run the program, then immediately shuts down Xvfb again.
回答2:
Depending on your exact needs are, it may be possible to launch xnest using xvfb-run, then export the display created as your DISPLAY variable.
来源:https://stackoverflow.com/questions/36582594/a-virtual-display-for-ubuntu-server