Created
August 4, 2015 17:45
-
-
Save william-ml-leslie/ffe544b4e39971d83684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os, time | |
from subprocess import Popen, call | |
KEYBD = ("ephyr,,,xkbmodel=pc105,xkblayout=us," | |
"xkbvariant=dvorak,xkboptions=ctrl:nocaps") | |
USAGE = """ | |
Usage: %s options [command [arg...]] | |
options: | |
--help : display help and exit | |
--display <display> : value to bind DISPLAY to (default: :1.0) | |
default: ":1.0" | |
--title <title> : value to use as the window title. | |
default: "Xephyr interactive instance" | |
--name <name> : value to use as the window name. | |
default: "xephyr" | |
command: | |
A program and arguments which will be invoked with the | |
particular DISPLAY set. | |
default: x-terminal-emulator | |
Runs the command within a custom xephyr instance. If the command | |
is not provided, the configured x-terminal-emulator is started. | |
""" % (sys.argv[0],) | |
if any(h in sys.argv for h in ("--help", "-h")): | |
print USAGE | |
sys.exit(1) | |
options = { | |
"--display" : ":1.0", | |
"--title" : "Xephyr interactive instance", | |
"--name" : "xephyr" | |
} | |
argvcopy = iter(sys.argv[1:]) | |
command = [] | |
current_key = None | |
for x in argvcopy: | |
if current_key: | |
options[current_key] = x | |
current_key = None | |
elif x == "--": | |
command.extend(argvcopy) | |
elif x.startswith("--"): | |
if x not in options: | |
print USAGE | |
sys.exit(1) | |
current_key = x | |
else: | |
command.append(x) | |
command.extend(argvcopy) | |
xephyr = Popen(["Xephyr", "-keybd", KEYBD, "-ac", | |
"-br", options["--display"], | |
"-name", options["--name"], | |
"-title", options["--title"], | |
"-host-cursor", "-screen", "1600x880", "-zap", | |
"-no-host-grab"]) | |
time.sleep(0.5) | |
new_env = dict(os.environ) | |
new_env["DISPLAY"] = options["--display"] | |
metacity = Popen(["/usr/bin/metacity", "--sm-disable"], env=new_env) | |
if not command: | |
command = ["x-terminal-emulator"] | |
try: | |
res = call(command, env=new_env) | |
except KeyboardInterrupt: | |
res = 1 | |
metacity.terminate() | |
time.sleep(0.5) | |
xephyr.terminate() | |
sys.exit(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment