2009-08-31 11:52:18 -04:00
|
|
|
#!@PYTHON@
|
2010-05-11 16:43:38 -04:00
|
|
|
# -*- mode: Python; indent-tabs-mode: nil; -*-
|
2009-02-23 14:52:49 -05:00
|
|
|
|
|
|
|
import atexit
|
2010-05-11 18:08:50 -04:00
|
|
|
import json
|
2009-02-23 14:52:49 -05:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import signal
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import tempfile
|
2009-04-13 11:58:05 -04:00
|
|
|
import termios
|
2009-02-23 14:52:49 -05:00
|
|
|
import time
|
2009-04-06 10:10:03 -04:00
|
|
|
import errno
|
2009-02-23 14:52:49 -05:00
|
|
|
|
2010-03-17 13:02:24 -04:00
|
|
|
def show_version(option, opt_str, value, parser):
|
|
|
|
print "GNOME Shell @VERSION@"
|
|
|
|
sys.exit()
|
|
|
|
|
2010-02-25 13:35:32 -05:00
|
|
|
def get_running_session_environs():
|
|
|
|
wanted_environment = ['DBUS_SESSION_BUS_ADDRESS', 'DISPLAY', 'XDG_DATA_DIRS',
|
|
|
|
'XAUTHORITY', 'XDG_SESSION_COOKIE', 'ORBIT_SOCKETDIR',
|
|
|
|
'SESSION_MANAGER']
|
|
|
|
num_re = re.compile('^[0-9]+$')
|
|
|
|
myuid = os.getuid()
|
|
|
|
if not os.path.isdir('/proc'):
|
|
|
|
return {}
|
|
|
|
for filename in os.listdir('/proc'):
|
|
|
|
if not num_re.match(filename):
|
|
|
|
continue
|
|
|
|
piddir = '/proc/' + filename
|
|
|
|
try:
|
|
|
|
stat = os.stat(piddir)
|
|
|
|
except OSError, e:
|
|
|
|
continue
|
|
|
|
if not stat.st_uid == myuid:
|
|
|
|
continue
|
|
|
|
try:
|
2010-04-24 09:41:03 -04:00
|
|
|
f = open(piddir + "/cmdline")
|
|
|
|
command = f.read()
|
|
|
|
f.close()
|
|
|
|
except IOError, e:
|
2010-02-25 13:35:32 -05:00
|
|
|
continue
|
2010-04-24 09:41:03 -04:00
|
|
|
# /proc/cmdline is separated and terminated by NULs
|
|
|
|
command = command.split("\x00")[0]
|
|
|
|
command = os.path.basename(command)
|
|
|
|
if command != 'gnome-session':
|
2010-02-25 13:35:32 -05:00
|
|
|
continue
|
|
|
|
try:
|
|
|
|
f = open(os.path.join(piddir, 'environ'))
|
|
|
|
except OSError, e:
|
|
|
|
continue
|
|
|
|
environ_data = f.read()
|
|
|
|
f.close()
|
|
|
|
# There's a trailing null at the last one, so remove the
|
|
|
|
# empty string
|
|
|
|
environs = environ_data.split('\0')[:-1]
|
|
|
|
# Rumor has it the presence of just FOO (instead of FOO=bar)
|
|
|
|
# represents a deleted environment variable
|
|
|
|
environs = filter(lambda x: '=' in x, environs)
|
|
|
|
# Turn it into a dictionary
|
|
|
|
environs = dict(map(lambda x: x.split('=', 1), environs))
|
|
|
|
result = {}
|
|
|
|
for key in wanted_environment:
|
|
|
|
if key in environs:
|
|
|
|
result[key] = environs[key]
|
|
|
|
return result
|
|
|
|
|
2009-02-23 14:52:49 -05:00
|
|
|
def start_xephyr():
|
|
|
|
tmpdir = tempfile.mkdtemp("", "gnome-shell.")
|
|
|
|
atexit.register(shutil.rmtree, tmpdir)
|
|
|
|
|
|
|
|
display = ":" + str(random.randint(10, 99))
|
|
|
|
xauth_file = os.path.join(tmpdir, "database")
|
|
|
|
|
|
|
|
# Create a random 128-bit 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
|
|
|
|
retcode = subprocess.call(["xauth",
|
|
|
|
"-f", xauth_file,
|
|
|
|
"add", display, "MIT-MAGIC-COOKIE-1", hexkey])
|
|
|
|
if retcode != 0:
|
|
|
|
raise RuntimeError("xauth failed")
|
|
|
|
|
|
|
|
# Launch Xephyr
|
2009-04-06 10:10:03 -04:00
|
|
|
try:
|
|
|
|
xephyr = subprocess.Popen(["Xephyr", display,
|
|
|
|
"-auth", xauth_file,
|
|
|
|
"-screen", options.geometry,
|
|
|
|
"-host-cursor"])
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno == errno.ENOENT:
|
|
|
|
print "Could not find Xephyr."
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
raise
|
2009-02-23 14:52:49 -05:00
|
|
|
os.environ['DISPLAY'] = display
|
|
|
|
os.environ['XAUTHORITY'] = xauth_file
|
|
|
|
|
|
|
|
# Wait for server to get going: LAME
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
# Start some windows in our session.
|
2009-11-12 15:17:35 -05:00
|
|
|
subprocess.Popen(["gnome-terminal"])
|
2009-02-23 14:52:49 -05:00
|
|
|
|
|
|
|
return xephyr;
|
|
|
|
|
|
|
|
GLXINFO_RE = re.compile(r"^(\S.*):\s*\n((?:^\s+.*\n)*)", re.MULTILINE)
|
|
|
|
|
|
|
|
def _get_glx_extensions():
|
|
|
|
"""Return a tuple of server, client, and effective GLX extensions"""
|
|
|
|
|
|
|
|
glxinfo = subprocess.Popen(["glxinfo"], stdout=subprocess.PIPE)
|
|
|
|
glxinfo_output = glxinfo.communicate()[0]
|
|
|
|
glxinfo.wait()
|
|
|
|
|
|
|
|
glxinfo_map = {}
|
|
|
|
for m in GLXINFO_RE.finditer(glxinfo_output):
|
|
|
|
glxinfo_map[m.group(1)] = m.group(2)
|
|
|
|
|
|
|
|
server_glx_extensions = set(re.split("\s*,\s*", glxinfo_map['server glx extensions'].strip()))
|
|
|
|
client_glx_extensions = set(re.split("\s*,\s*", glxinfo_map['client glx extensions'].strip()))
|
|
|
|
glx_extensions = set(re.split("\s*,\s*", glxinfo_map['GLX extensions'].strip()))
|
|
|
|
|
|
|
|
return (server_glx_extensions, client_glx_extensions, glx_extensions)
|
|
|
|
|
2010-05-11 18:08:50 -04:00
|
|
|
def start_shell(perf_output=None):
|
2009-03-11 09:59:02 -04:00
|
|
|
bin_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
|
|
if os.path.exists(os.path.join(bin_dir, 'gnome-shell.in')):
|
|
|
|
running_from_source_tree = True
|
|
|
|
top_dir = os.path.dirname(bin_dir)
|
2009-05-05 10:02:39 -04:00
|
|
|
plugin = os.path.join(top_dir, 'src', 'libgnome-shell.la')
|
2009-03-11 09:59:02 -04:00
|
|
|
typelib_dir = os.path.join(top_dir, "src")
|
|
|
|
js_dir = os.path.join(top_dir, "js")
|
|
|
|
data_dir = os.path.join(top_dir, "data")
|
|
|
|
else:
|
|
|
|
running_from_source_tree = False
|
2009-05-05 10:02:39 -04:00
|
|
|
plugin = 'libgnome-shell'
|
2009-03-11 09:59:02 -04:00
|
|
|
js_dir = os.path.join('@pkgdatadir@', 'js')
|
|
|
|
|
|
|
|
# Set up environment
|
|
|
|
env = dict(os.environ)
|
|
|
|
env.update({'GNOME_SHELL_JS' : '@GJS_JS_DIR@:@GJS_JS_NATIVE_DIR@:' + js_dir,
|
2009-07-31 17:40:46 -04:00
|
|
|
'PATH' : '@MUTTER_BIN_DIR@:' + os.environ.get('PATH', ''),
|
2009-03-11 09:59:02 -04:00
|
|
|
'GNOME_DISABLE_CRASH_DIALOG' : '1'})
|
|
|
|
|
|
|
|
if running_from_source_tree:
|
|
|
|
env.update({'GNOME_SHELL_DATADIR' : data_dir,
|
|
|
|
'GI_TYPELIB_PATH' : typelib_dir})
|
2009-02-23 14:52:49 -05:00
|
|
|
|
2009-06-30 17:29:40 -04:00
|
|
|
jhbuild_gconf_source = os.path.join('@sysconfdir@', 'gconf/2/path.jhbuild')
|
|
|
|
if os.path.exists(jhbuild_gconf_source):
|
|
|
|
env['GCONF_DEFAULT_SOURCE_PATH'] = jhbuild_gconf_source
|
|
|
|
|
2009-02-27 11:14:11 -05:00
|
|
|
# Work around Ubuntu xulrunner bug,
|
|
|
|
# http://bugzilla.gnome.org/show_bug.cgi?id=573413
|
|
|
|
pkgconfig = subprocess.Popen(['pkg-config', '--variable=sdkdir', 'mozilla-js'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
mozjs_sdkdir = pkgconfig.communicate()[0].strip()
|
|
|
|
pkgconfig.wait()
|
|
|
|
if pkgconfig.returncode == 0:
|
|
|
|
mozjs_libdir = re.sub('-(sdk|devel)', '', mozjs_sdkdir)
|
|
|
|
if os.path.exists(mozjs_libdir + '/libmozjs.so'):
|
2009-03-11 09:59:02 -04:00
|
|
|
env['LD_LIBRARY_PATH'] = os.environ.get('LD_LIBRARY_PATH', '') + ':' + mozjs_libdir
|
2009-02-24 14:59:32 -05:00
|
|
|
|
2009-05-21 15:22:44 -04:00
|
|
|
# Log everything to stderr (make stderr our "log file")
|
|
|
|
env['GJS_DEBUG_OUTPUT'] = 'stderr'
|
|
|
|
|
2009-02-24 14:59:32 -05:00
|
|
|
if not options.verbose:
|
|
|
|
# Unless verbose() is specified, only let gjs show errors and
|
|
|
|
# things that are explicitly logged via log() from javascript
|
|
|
|
env['GJS_DEBUG_TOPICS'] = 'JS ERROR;JS LOG'
|
|
|
|
|
2009-02-23 14:52:49 -05:00
|
|
|
if use_tfp:
|
|
|
|
# Decide if we need to set LIBGL_ALWAYS_INDIRECT=1 to get the
|
|
|
|
# texture_from_pixmap extension; we take having the extension
|
|
|
|
# be supported on both the client and server but not in the
|
|
|
|
# list of effective extensions as a signal of needing to force
|
|
|
|
# indirect rendering.
|
|
|
|
#
|
|
|
|
# Note that this check would give the wrong answer for Xephyr,
|
|
|
|
# but since we force !use_tfp there anyway, it doesn't matter.
|
|
|
|
(server_glx_extensions, client_glx_extensions, glx_extensions) = _get_glx_extensions()
|
|
|
|
|
|
|
|
if ("GLX_EXT_texture_from_pixmap" in server_glx_extensions and
|
|
|
|
"GLX_EXT_texture_from_pixmap" in client_glx_extensions and
|
|
|
|
(not "GLX_EXT_texture_from_pixmap" in glx_extensions)):
|
|
|
|
if options.verbose:
|
|
|
|
print "Forcing indirect GL"
|
2009-02-23 16:45:38 -05:00
|
|
|
# This is Mesa specific; the NVIDIA proprietary drivers
|
|
|
|
# drivers use __GL_FORCE_INDIRECT=1 instead. But we don't
|
|
|
|
# need to force indirect rendering for NVIDIA.
|
|
|
|
env['LIBGL_ALWAYS_INDIRECT'] = '1'
|
2009-02-23 14:52:49 -05:00
|
|
|
|
2010-05-09 13:42:35 -04:00
|
|
|
if options.perf is not None:
|
|
|
|
env['SHELL_PERF_MODULE'] = options.perf
|
|
|
|
|
2010-05-11 18:08:50 -04:00
|
|
|
if perf_output is not None:
|
|
|
|
env['SHELL_PERF_OUTPUT'] = perf_output
|
|
|
|
|
2009-02-23 14:52:49 -05:00
|
|
|
if options.debug:
|
|
|
|
debug_command = options.debug_command.split()
|
|
|
|
args = list(debug_command)
|
|
|
|
else:
|
|
|
|
args = []
|
|
|
|
|
2009-08-27 14:07:46 -04:00
|
|
|
args.extend(['mutter', '--mutter-plugins=' + plugin])
|
|
|
|
if options.replace:
|
|
|
|
args.append('--replace')
|
2009-02-23 14:52:49 -05:00
|
|
|
if options.sync:
|
|
|
|
args.append('--sync')
|
|
|
|
return subprocess.Popen(args, env=env)
|
|
|
|
|
2010-05-11 18:08:50 -04:00
|
|
|
def run_shell(perf_output=None):
|
2010-05-11 16:43:38 -04:00
|
|
|
if options.debug:
|
|
|
|
# Record initial terminal state so we can reset it to that
|
|
|
|
# later, in case we kill gdb at a bad time
|
|
|
|
termattrs = termios.tcgetattr(0);
|
|
|
|
|
|
|
|
normal_exit = False
|
|
|
|
|
|
|
|
if options.verbose:
|
|
|
|
print "Starting shell"
|
|
|
|
|
|
|
|
try:
|
|
|
|
shell = None
|
|
|
|
if options.xephyr:
|
|
|
|
xephyr = start_xephyr()
|
|
|
|
# This makes us not grab the org.gnome.Panel or
|
|
|
|
# org.freedesktop.Notifications D-Bus names
|
|
|
|
os.environ['GNOME_SHELL_NO_REPLACE'] = '1'
|
|
|
|
shell = start_shell()
|
|
|
|
else:
|
|
|
|
xephyr = None
|
2010-05-11 18:08:50 -04:00
|
|
|
shell = start_shell(perf_output=perf_output)
|
2010-05-11 16:43:38 -04:00
|
|
|
|
|
|
|
# Wait for shell to exit
|
|
|
|
if options.verbose:
|
|
|
|
print "Waiting for shell to exit"
|
|
|
|
shell.wait()
|
|
|
|
|
|
|
|
except KeyboardInterrupt, e:
|
|
|
|
try:
|
|
|
|
os.kill(shell.pid, signal.SIGKILL)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
shell.wait()
|
|
|
|
finally:
|
|
|
|
# Clean up Xephyr if it outlived the shell
|
|
|
|
if xephyr:
|
|
|
|
try:
|
|
|
|
os.kill(xephyr.pid, signal.SIGKILL)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if shell is None:
|
|
|
|
print "Failed to start shell"
|
|
|
|
elif shell.returncode == 0:
|
|
|
|
normal_exit = True
|
|
|
|
if options.verbose:
|
|
|
|
print "Shell exited normally"
|
|
|
|
elif shell.returncode < 0:
|
|
|
|
# Python has no mapping for strsignal; not worth using
|
|
|
|
# ctypes for this.
|
|
|
|
print "Shell killed with signal %d" % - shell.returncode
|
|
|
|
else:
|
|
|
|
# Normal reason here would be losing connection the X server
|
|
|
|
if options.verbose:
|
|
|
|
print "Shell exited with return code %d" % shell.returncode
|
|
|
|
|
|
|
|
if options.debug:
|
|
|
|
termios.tcsetattr(0, termios.TCSANOW, termattrs);
|
|
|
|
|
|
|
|
return normal_exit
|
|
|
|
|
2010-05-11 18:08:50 -04:00
|
|
|
def run_performance_test():
|
|
|
|
iters = options.perf_iters
|
|
|
|
if options.perf_warmup:
|
|
|
|
iters += 1
|
|
|
|
|
|
|
|
metric_summaries = {}
|
|
|
|
|
|
|
|
for i in xrange(0, iters):
|
|
|
|
# We create an empty temporary file that the shell will overwrite
|
|
|
|
# with the contents.
|
|
|
|
handle, output_file = tempfile.mkstemp(".json", "gnome-shell-perf.")
|
|
|
|
os.close(handle)
|
|
|
|
|
|
|
|
# Run the performance test and collect the output as JSON
|
|
|
|
normal_exit = False
|
|
|
|
try:
|
|
|
|
normal_exit = run_shell(perf_output=output_file)
|
|
|
|
finally:
|
|
|
|
if not normal_exit:
|
|
|
|
os.remove(output_file)
|
|
|
|
|
|
|
|
if not normal_exit:
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
f = open(output_file)
|
|
|
|
output = json.load(f)
|
|
|
|
f.close()
|
|
|
|
finally:
|
|
|
|
os.remove(output_file)
|
|
|
|
|
|
|
|
if options.perf_warmup and i == 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for metric, details in output.iteritems():
|
|
|
|
if not metric in metric_summaries:
|
|
|
|
summary = {}
|
|
|
|
summary['description'] = details['description']
|
|
|
|
summary['values'] = []
|
|
|
|
metric_summaries[metric] = summary
|
|
|
|
else:
|
|
|
|
summary = metric_summaries[metric]
|
|
|
|
|
|
|
|
summary['values'].append(details['value'])
|
|
|
|
|
|
|
|
for metric in sorted(metric_summaries.keys()):
|
|
|
|
summary = metric_summaries[metric]
|
|
|
|
print "#", summary['description']
|
|
|
|
print metric, ", ".join((str(x) for x in summary['values']))
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2009-08-27 14:19:42 -04:00
|
|
|
def restore_gnome():
|
|
|
|
# Do imports lazily to save time and memory
|
|
|
|
import gio
|
|
|
|
import gconf
|
|
|
|
|
|
|
|
# We don't want to start the new gnome-panel in the current
|
|
|
|
# directory; $HOME is better for stuff launched from it
|
|
|
|
os.chdir(os.path.expanduser("~"))
|
|
|
|
|
|
|
|
def launch_component(gconf_path):
|
|
|
|
client = gconf.client_get_default()
|
|
|
|
component = client.get_string(gconf_path)
|
|
|
|
|
|
|
|
if component == None or component == "":
|
|
|
|
return
|
|
|
|
|
|
|
|
# See gnome-session/gsm-util.c:gsm_util_find_desktop_file_for_app_name()
|
|
|
|
# The one difference is that we don't search the autostart directories,
|
|
|
|
# and just search normal application search path. (Gio doesnt' know
|
|
|
|
# how to search the autostart dirs, so we'd have to do that ourselves.)
|
|
|
|
appinfo = None
|
|
|
|
try:
|
|
|
|
appinfo = gio.unix.DesktopAppInfo(component + ".desktop")
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
appinfo = gio.unix.DesktopAppInfo("gnome-" + component + ".desktop")
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if appinfo:
|
|
|
|
appinfo.launch()
|
|
|
|
|
|
|
|
launch_component("/desktop/gnome/session/required_components/windowmanager")
|
|
|
|
launch_component("/desktop/gnome/session/required_components/panel")
|
2009-02-23 14:52:49 -05:00
|
|
|
|
|
|
|
# Main program
|
|
|
|
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option("-r", "--replace", action="store_true",
|
|
|
|
help="Replace the running metacity/gnome-panel")
|
|
|
|
parser.add_option("-g", "--debug", action="store_true",
|
|
|
|
help="Run under a debugger")
|
|
|
|
parser.add_option("", "--debug-command", metavar="COMMAND",
|
|
|
|
help="Command to use for debugging (defaults to 'gdb --args')")
|
|
|
|
parser.add_option("-v", "--verbose", action="store_true")
|
|
|
|
parser.add_option("", "--sync", action="store_true")
|
2010-05-09 13:42:35 -04:00
|
|
|
parser.add_option("", "--perf", metavar="PERF_MODULE",
|
|
|
|
help="Specify the name of a performance module to run")
|
2010-05-11 18:08:50 -04:00
|
|
|
parser.add_option("", "--perf-iters", type="int", metavar="ITERS",
|
|
|
|
help="Numbers of iterations of performance module to run",
|
|
|
|
default=1)
|
|
|
|
parser.add_option("", "--perf-warmup", action="store_true",
|
|
|
|
help="Run a dry run before performance tests")
|
2009-08-27 14:07:46 -04:00
|
|
|
parser.add_option("", "--xephyr", action="store_true",
|
|
|
|
help="Run a debugging instance inside Xephyr")
|
2009-02-23 14:52:49 -05:00
|
|
|
parser.add_option("", "--geometry", metavar="GEOMETRY",
|
|
|
|
help="Specify Xephyr screen geometry",
|
|
|
|
default="1024x768");
|
|
|
|
parser.add_option("-w", "--wide", action="store_true",
|
|
|
|
help="Use widescreen (1280x800) with Xephyr")
|
2009-11-12 18:18:34 -05:00
|
|
|
parser.add_option("", "--eval-file", metavar="EVAL_FILE",
|
|
|
|
help="Evaluate the contents of the given JavaScript file")
|
2009-10-25 18:53:10 -04:00
|
|
|
parser.add_option("", "--create-extension", action="store_true",
|
|
|
|
help="Create a new GNOME Shell extension")
|
2010-03-17 13:02:24 -04:00
|
|
|
parser.add_option("", "--version", action="callback", callback=show_version,
|
|
|
|
help="Display version and exit")
|
2009-02-23 14:52:49 -05:00
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if args:
|
|
|
|
parser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-10-25 18:53:10 -04:00
|
|
|
if options.create_extension:
|
|
|
|
import json
|
|
|
|
|
|
|
|
print
|
|
|
|
print '''Name should be a very short (ideally descriptive) string.
|
|
|
|
Examples are: "Click To Focus", "Adblock", "Shell Window Shrinker".
|
|
|
|
'''
|
|
|
|
name = raw_input('Name: ').strip()
|
|
|
|
print
|
|
|
|
print '''Description is a single-sentence explanation of what your extension does.
|
|
|
|
Examples are: "Make windows visible on click", "Block advertisement popups"
|
|
|
|
"Animate windows shrinking on minimize"
|
|
|
|
'''
|
|
|
|
description = raw_input('Description: ').strip()
|
|
|
|
underifier = re.compile('[^A-Za-z]')
|
|
|
|
sample_uuid = underifier.sub('_', name)
|
|
|
|
# TODO use evolution data server
|
|
|
|
hostname = subprocess.Popen(['hostname'], stdout=subprocess.PIPE).communicate()[0].strip()
|
|
|
|
sample_uuid = sample_uuid + '@' + hostname
|
|
|
|
|
|
|
|
print
|
|
|
|
print '''Uuid is a globally-unique identifier for your extension.
|
|
|
|
This should be in the format of an email address (foo.bar@extensions.example.com), but
|
|
|
|
need not be an actual email address, though it's a good idea to base the uuid on your
|
|
|
|
email address. For example, if your email address is janedoe@example.com, you might
|
|
|
|
use an extension title clicktofocus@janedoe.example.com.'''
|
|
|
|
uuid = raw_input('Uuid [%s]: ' % (sample_uuid, )).strip()
|
|
|
|
if uuid == '':
|
|
|
|
uuid = sample_uuid
|
|
|
|
|
2010-05-04 07:24:06 -04:00
|
|
|
extension_path = os.path.join(os.path.expanduser('~/.local'), 'share', 'gnome-shell', 'extensions', uuid)
|
2009-10-25 18:53:10 -04:00
|
|
|
if os.path.exists(extension_path):
|
|
|
|
print "Extension path %r already exists" % (extension_path, )
|
|
|
|
sys.exit(0)
|
|
|
|
os.makedirs(extension_path)
|
|
|
|
meta = { 'name': name,
|
|
|
|
'description': description,
|
|
|
|
'uuid': uuid }
|
|
|
|
f = open(os.path.join(extension_path, 'metadata.json'), 'w')
|
2009-12-18 14:22:51 -05:00
|
|
|
try:
|
|
|
|
json.dump(meta, f)
|
|
|
|
except AttributeError:
|
|
|
|
# For Python versions older than 2.6, try using the json-py module
|
|
|
|
f.write(json.write(meta) + '\n')
|
2009-10-25 18:53:10 -04:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
extensionjs_path = os.path.join(extension_path, 'extension.js')
|
|
|
|
f = open(extensionjs_path, 'w')
|
|
|
|
f.write('''// Sample extension code, makes clicking on the panel show a message
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
function _showHello() {
|
|
|
|
let text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });
|
|
|
|
let monitor = global.get_primary_monitor();
|
|
|
|
global.stage.add_actor(text);
|
|
|
|
text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2));
|
|
|
|
Mainloop.timeout_add(3000, function () { text.destroy(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put your extension initialization code here
|
|
|
|
function main() {
|
|
|
|
Main.panel.actor.reactive = true;
|
|
|
|
Main.panel.actor.connect('button-release-event', _showHello);
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
f = open(os.path.join(extension_path, 'stylesheet.css'), 'w')
|
|
|
|
f.write('''/* Example stylesheet */
|
|
|
|
.helloworld-label {
|
|
|
|
font-size: 36px;
|
|
|
|
font-weight: bold;
|
|
|
|
color: #ffffff;
|
|
|
|
background-color: rgba(10,10,10,0.7);
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
f.close()
|
|
|
|
|
2009-12-18 14:26:41 -05:00
|
|
|
subprocess.Popen(['gnome-open', extensionjs_path])
|
2009-10-25 18:53:10 -04:00
|
|
|
sys.exit(0)
|
|
|
|
|
2010-04-29 10:30:58 -04:00
|
|
|
# Handle ssh logins
|
|
|
|
if 'DISPLAY' not in os.environ:
|
|
|
|
running_env = get_running_session_environs()
|
|
|
|
os.environ.update(running_env)
|
|
|
|
|
2009-11-12 18:18:34 -05:00
|
|
|
if options.eval_file:
|
|
|
|
import dbus
|
|
|
|
|
|
|
|
f = open(options.eval_file)
|
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
session = dbus.SessionBus()
|
|
|
|
shell = session.get_object('org.gnome.Shell', '/org/gnome/Shell')
|
|
|
|
shell = dbus.Interface(shell, 'org.gnome.Shell')
|
|
|
|
result = shell.Eval(contents)
|
|
|
|
print result
|
|
|
|
sys.exit(0)
|
|
|
|
|
2009-02-23 14:52:49 -05:00
|
|
|
if options.debug_command:
|
|
|
|
options.debug = True
|
|
|
|
elif options.debug:
|
|
|
|
options.debug_command = "gdb --args"
|
|
|
|
|
|
|
|
if options.wide:
|
|
|
|
options.geometry = "1280x800"
|
|
|
|
|
|
|
|
# Figure out whether or not to use GL_EXT_texture_from_pixmap. By default
|
|
|
|
# we use it iff we aren't running Xephyr, but we allow the user to
|
|
|
|
# explicitly disable it.
|
|
|
|
# FIXME: Move this to ClutterGlxPixmap like
|
|
|
|
# CLUTTER_PIXMAP_TEXTURE_RECTANGLE=disable.
|
|
|
|
if 'GNOME_SHELL_DISABLE_TFP' in os.environ and \
|
|
|
|
os.environ['GNOME_SHELL_DISABLE_TFP'] != '':
|
|
|
|
use_tfp = False
|
|
|
|
else:
|
|
|
|
# tfp does not work correctly in Xephyr
|
2009-08-27 14:07:46 -04:00
|
|
|
use_tfp = not options.xephyr
|
2009-02-23 14:52:49 -05:00
|
|
|
|
Only respawn if gnome-shell exits abnormally
If Mutter exits with an exit status of 0, then that most likely
means that it was replaced by another window manager and we shoudln't
try to start the previous window manager and the panel.
(We don't actually know about the panel, but assume that if someone
is replacing us they know what they are doing.)
When Mutter exits with a signal, we know we want to restart.
When Mutter exits with a non-signal non-zero exit status, it's
ambiguous - we could be exiting because we lost the connection to
the X server, or because of a assertion failure in gnome-shell.
We assume the latter; if the X server is gone, all that will happen
is a bit of noise.
To know why Mutter exited accurately, we always wait() and
kill() the Mutter process, and then, if running in Xephyr, clean up
Xephyr afterwards. This has the nice side effect of exiting when
gnome-shell does and not forcing the user to close Xephyr manually.
http://bugzilla.gnome.org/show_bug.cgi?id=591171
2009-08-23 20:48:52 -04:00
|
|
|
# We only respawn the previous environment on abnormal exit;
|
|
|
|
# for a clean exit, we assume that gnome-shell was replaced with
|
|
|
|
# something else.
|
|
|
|
normal_exit = False
|
|
|
|
|
2009-02-23 14:52:49 -05:00
|
|
|
try:
|
2010-05-11 18:08:50 -04:00
|
|
|
if options.perf:
|
|
|
|
normal_exit = run_performance_test()
|
|
|
|
else:
|
|
|
|
normal_exit = run_shell()
|
2009-02-23 14:52:49 -05:00
|
|
|
finally:
|
2010-05-11 18:08:50 -04:00
|
|
|
if not options.xephyr and options.replace and (options.perf or not normal_exit):
|
2009-08-27 14:19:42 -04:00
|
|
|
restore_gnome()
|