2008-11-01 23:55:49 +00:00
|
|
|
from optparse import OptionParser
|
|
|
|
import os
|
2008-12-05 16:15:49 +00:00
|
|
|
import re
|
2008-11-01 23:55:49 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2008-12-05 16:15:49 +00:00
|
|
|
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)
|
|
|
|
|
2008-11-01 23:55:49 +00:00
|
|
|
class Launcher:
|
2009-02-05 15:35:23 +00:00
|
|
|
def __init__(self, use_tfp=True, accept_geometry=False):
|
|
|
|
self.use_tfp = use_tfp
|
2008-11-01 23:55:49 +00:00
|
|
|
|
|
|
|
# Figure out the path to the plugin when uninstalled
|
|
|
|
scripts_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
|
|
top_dir = os.path.dirname(scripts_dir)
|
|
|
|
self.plugin_dir = os.path.join(top_dir, "src")
|
|
|
|
self.js_dir = os.path.join(top_dir, "js")
|
2008-12-22 22:05:56 +00:00
|
|
|
self.data_dir = os.path.join(top_dir, "data")
|
2008-11-01 23:55:49 +00:00
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
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")
|
2009-02-13 19:40:52 +00:00
|
|
|
parser.add_option("" "--sync", action="store_true")
|
2009-02-05 15:35:23 +00:00
|
|
|
if accept_geometry:
|
|
|
|
parser.add_option("", "--geometry", metavar="GEOMETRY",
|
|
|
|
help="Specify screen geometry",
|
|
|
|
default="1024x768");
|
|
|
|
parser.add_option("-w", "--wide", action="store_true",
|
|
|
|
help="Use widescreen (1280x800)")
|
2008-11-01 23:55:49 +00:00
|
|
|
|
|
|
|
self.options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if args:
|
|
|
|
parser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if self.options.debug_command:
|
|
|
|
self.options.debug = True
|
|
|
|
self.debug_command = self.options.debug_command.split()
|
|
|
|
else:
|
|
|
|
self.debug_command = ["gdb", "--args"]
|
|
|
|
|
2009-02-05 21:52:04 +00:00
|
|
|
if accept_geometry and self.options.wide:
|
2009-02-05 15:35:23 +00:00
|
|
|
self.options.geometry = "1280x800"
|
2008-11-01 23:55:49 +00:00
|
|
|
|
|
|
|
def start_shell(self):
|
|
|
|
"""Starts gnome-shell. Returns a subprocess.Popen object"""
|
|
|
|
|
|
|
|
use_tfp = self.use_tfp
|
2008-12-05 16:15:49 +00:00
|
|
|
force_indirect = False
|
2008-11-29 21:11:31 +00:00
|
|
|
|
|
|
|
# Allow disabling usage of the EXT_texture_for_pixmap extension.
|
|
|
|
# FIXME: Move this to ClutterGlxPixmap like
|
|
|
|
# CLUTTER_PIXMAP_TEXTURE_RECTANGLE=disable.
|
2008-11-29 21:55:19 +00:00
|
|
|
if 'GNOME_SHELL_DISABLE_TFP' in os.environ and \
|
2008-11-29 21:44:19 +00:00
|
|
|
os.environ['GNOME_SHELL_DISABLE_TFP'] != '':
|
2008-11-29 21:11:31 +00:00
|
|
|
use_tfp = False
|
|
|
|
|
2008-11-01 23:55:49 +00:00
|
|
|
if use_tfp:
|
2008-12-05 16:15:49 +00:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# (The Xepyhr DRI support confuses this heuristic but we disable TFP in
|
|
|
|
# start-in-Xepyhr)
|
|
|
|
#
|
|
|
|
(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)):
|
|
|
|
|
|
|
|
force_indirect = True
|
2008-11-01 23:55:49 +00:00
|
|
|
|
|
|
|
# Now launch metacity-clutter with our plugin
|
|
|
|
env=dict(os.environ)
|
2008-12-22 22:05:56 +00:00
|
|
|
env.update({'GNOME_SHELL_JS' : self.js_dir,
|
|
|
|
'GNOME_SHELL_DATADIR' : self.data_dir,
|
|
|
|
'GI_TYPELIB_PATH' : self.plugin_dir,
|
2009-01-19 23:21:57 +00:00
|
|
|
'PATH' : os.environ.get('PATH', '') + ':' + self.plugin_dir,
|
2008-12-22 22:05:56 +00:00
|
|
|
'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH', '') + ':' + self.plugin_dir,
|
2008-11-06 15:10:57 +00:00
|
|
|
'GNOME_DISABLE_CRASH_DIALOG' : '1'})
|
2008-11-01 23:55:49 +00:00
|
|
|
|
2008-12-05 16:15:49 +00:00
|
|
|
if force_indirect:
|
|
|
|
if self.options.verbose:
|
|
|
|
print "Forcing indirect GL"
|
|
|
|
|
|
|
|
# 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.
|
2008-11-01 23:55:49 +00:00
|
|
|
env['LIBGL_ALWAYS_INDIRECT'] = '1'
|
|
|
|
|
|
|
|
if not self.options.verbose:
|
2008-11-02 03:27:11 +00:00
|
|
|
# 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'
|
2008-11-01 23:55:49 +00:00
|
|
|
|
|
|
|
if self.options.debug:
|
2008-11-02 03:03:00 +00:00
|
|
|
args = list(self.debug_command)
|
2008-11-01 23:55:49 +00:00
|
|
|
else:
|
|
|
|
args = []
|
|
|
|
|
|
|
|
plugin = os.path.join(self.plugin_dir, "libgnome-shell.la")
|
|
|
|
args.extend(['metacity', '--mutter-plugins=' + plugin, '--replace'])
|
2009-02-13 19:40:52 +00:00
|
|
|
if self.options.sync:
|
|
|
|
args.append('--sync')
|
2008-11-01 23:55:49 +00:00
|
|
|
return subprocess.Popen(args, env=env)
|
2008-11-04 22:40:52 +00:00
|
|
|
|
2009-02-05 15:35:23 +00:00
|
|
|
def is_verbose(self):
|
2008-11-04 22:40:52 +00:00
|
|
|
"""Returns whether the Launcher was started in verbose mode"""
|
|
|
|
return self.options.verbose
|
2008-11-01 23:55:49 +00:00
|
|
|
|
2009-02-05 15:35:23 +00:00
|
|
|
def get_geometry(self):
|
|
|
|
"""Returns the command-line specified geometry"""
|
|
|
|
return self.options.geometry
|