gnome-shell/scripts/start-in-Xephyr

60 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
import os
import random
import shutil
import signal
import subprocess
import sys
import tempfile
import time
from launcher import Launcher
launcher = Launcher()
# GL_EXT_texture_from_pixmap doesn't work in Xepyhr
launcher.set_use_tfp(False)
# Temporary directory to hold our X credentials
tmpdir = tempfile.mkdtemp("", "gnome-shell.")
try:
display = ":" + str(random.randint(10, 99))
xauth_file = os.path.join(tmpdir, "database")
# Create a random 128-byte key and format it as hex
f = open("/dev/urandom", "r")
key = f.read(16)
f.close()
hexkey = "".join(("%02x" % ord(byte) for byte in key))
# Store that in an xauthority file as the key for connecting to our Xephyr
os.environ['XAUTHORITY'] = xauth_file
retcode = subprocess.call(["xauth", "add", display, "MIT-MAGIC-COOKIE-1", hexkey])
if retcode != 0:
raise RuntimeError("xauth failed")
# Launch Xephyr
xephyr = subprocess.Popen(["Xephyr", display, "-screen", "800x600", "-host-cursor"])
os.environ['DISPLAY'] = display
# Wait for server to get going: LAME
time.sleep(1)
# Start xterm to have some window in our session
subprocess.Popen(["xterm"])
subprocess.Popen(["xlogo"])
subprocess.Popen(["xeyes"])
# Now launch metacity-clutter with our plugin
shell = launcher.start_shell()
# Wait for Xephyr to exit
try:
retcode = xephyr.wait()
except KeyboardInterrupt, e:
os.kill(xephyr.pid, signal.SIGKILL)
finally:
shutil.rmtree(tmpdir)