Difference between revisions of "Running program in separate X display"

From ArchWiki
Jump to: navigation, search
Line 26: Line 26:
 
   
 
   
 
  #main execution line with automatic full path retrieval.
 
  #main execution line with automatic full path retrieval.
  xinit `which $*` -- $NEWDISP &
+
  xinit `which $*` -- $NEWDISP -nolisten tcp -br &
 
   
 
   
 
  #then we set useful parameters
 
  #then we set useful parameters
Line 44: Line 44:
 
  xrun appname
 
  xrun appname
  
--[[User:Psycho zs|Psycho zs]] 17:03, 1 October 2010 (EDT)
+
=== Advanced script ===
 +
 
 +
This script utilizes zenity to show error and info:
 +
 
 +
#!/bin/bash
 +
 +
#test if file exists, otherwise exit
 +
which $* 2> /dev/null
 +
if [ "$?" != "0" ] ; then
 +
echo "No such executable!"
 +
zenity --error --text="No such executable!"
 +
exit 127
 +
fi
 +
 +
# use this vt
 +
LVT=`fgconsole --next-available`
 +
#LVT=7
 +
 +
echo "Will launch \"$*\" on tty$LVT..."
 +
zenity --question --title "Launch?" --text="Will launch \"$*\" on tty$LVT. Continue?" || exit 1
 +
 +
# use this display number
 +
NEWDISP=":10"
 +
 +
# this flag is used for indicating unaccessible or broken DRI.
 +
# it is set, for example, when using fglrx+compiz-manager
 +
# Some games will refuse to start if it is set.
 +
# unsetting it should not do any harm, and can be useful.
 +
unset LIBGL_ALWAYS_INDIRECT
 +
 +
#main execution line with automatic full path retrieval.
 +
xinit `which $*` -- $NEWDISP vt$LVT -nolisten tcp -br &
 +
 +
#then we set useful parameters
 +
DISPLAY=$NEWDISP
 +
sleep 1s
 +
 +
# disable non-linear mouse acceleration
 +
xset m 1 0
 +
# disable hard-coded default 10m screensaver
 +
xset s 0 0
 +
 
 +
 
 +
--[[User:Psycho zs|Psycho zs]] 06:54, 3 October 2010 (EDT)

Revision as of 10:54, 3 October 2010

It may often be handy to run some program in separate X display. I.e. 3D games for gaining performance, or making alt+tab-style switching possible with ctrl+alt+[F7-F12].

The simplest way would be:

xinit appname -- :10

But if you have ~/.xinitrc in place, you should use full path to app to override it. Also there can be some environment variables and X options to pass. So the smart way would be to pack it all into a wrapper:

#!/bin/bash

#test if file exists, otherwise exit
which $* 2> /dev/null
if [ "$?" != "0" ] ; then
echo "No such executable"
exit 127
fi

# use this display number
NEWDISP=":10"

# this flag is used for indicating unaccessible or broken DRI.
# it is set, for example, when using fglrx+compiz-manager
# Some games will refuse to start if it is set.
# unsetting it should not do any harm, and can be useful.
unset LIBGL_ALWAYS_INDIRECT

#main execution line with automatic full path retrieval.
xinit `which $*` -- $NEWDISP -nolisten tcp -br &

#then we set useful parameters
DISPLAY=$NEWDISP
sleep 1s

# disable annoying non-linear mouse acceleration
xset m 1 0
# disable hard-coded default 10m screensaver
xset s 0 0

General principle: set variables before xinit line, and xset parameters after.

Save it as /usr/bin/xrun

After that launching app in separate X display should be as easy as typing

xrun appname

Advanced script

This script utilizes zenity to show error and info:

#!/bin/bash

#test if file exists, otherwise exit
which $* 2> /dev/null 
if [ "$?" != "0" ] ; then
echo "No such executable!"
zenity --error --text="No such executable!"
exit 127
fi

# use this vt
LVT=`fgconsole --next-available`
#LVT=7

echo "Will launch \"$*\" on tty$LVT..."
zenity --question --title "Launch?" --text="Will launch \"$*\" on tty$LVT. Continue?" || exit 1

# use this display number
NEWDISP=":10" 

# this flag is used for indicating unaccessible or broken DRI. 
# it is set, for example, when using fglrx+compiz-manager
# Some games will refuse to start if it is set.
# unsetting it should not do any harm, and can be useful.
unset LIBGL_ALWAYS_INDIRECT

#main execution line with automatic full path retrieval.
xinit `which $*` -- $NEWDISP vt$LVT -nolisten tcp -br &

#then we set useful parameters
DISPLAY=$NEWDISP
sleep 1s

# disable non-linear mouse acceleration
xset m 1 0
# disable hard-coded default 10m screensaver
xset s 0 0


--Psycho zs 06:54, 3 October 2010 (EDT)