diff --git a/remotinator b/remotinator index 81843407..7b04b0b9 100755 --- a/remotinator +++ b/remotinator @@ -30,6 +30,7 @@ APP_VERSION='1.0' COMMANDS={ 'hsplit': ['terminal_hsplit', 'Split the current terminal horizontally'], 'vsplit': ['terminal_vsplit', 'Split the current terminal vertically'], + 'terminals': ['get_terminals', 'Get a list of all terminals'], } if __name__ == '__main__': @@ -50,6 +51,10 @@ if __name__ == '__main__': err("Unknown command: %s" % command) sys.exit(1) + if not os.environ.has_key('TERMINATOR_UUID'): + err("$TERMINATOR_UUID is not set. Are you definitely running inside Terminator?") + sys.exit(1) + func = getattr(ipc, COMMANDS[command][0]) func(os.environ['TERMINATOR_UUID']) diff --git a/terminator b/terminator index 41e78905..1fd95ccd 100755 --- a/terminator +++ b/terminator @@ -46,6 +46,8 @@ from terminatorlib.version import APP_NAME, APP_VERSION from terminatorlib.util import dbg, err if __name__ == '__main__': + dbus_service = None + dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION)) OPTIONS = terminatorlib.optionparse.parse_options() @@ -61,7 +63,7 @@ if __name__ == '__main__': raise ImportError from terminatorlib import ipc try: - ipc.DBusService() + dbus_service = ipc.DBusService() except ipc.DBusException: dbg('Unable to become master process, requesting a new window') ipc.new_window(OPTIONS.layout) @@ -73,6 +75,7 @@ if __name__ == '__main__': MAKER = Factory() TERMINATOR = Terminator() TERMINATOR.set_origcwd(ORIGCWD) + TERMINATOR.set_dbus_data(dbus_service) TERMINATOR.reconfigure() try: dbg('Creating a terminal with layout: %s' % OPTIONS.layout) diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index aad1ab9b..d413be84 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -30,6 +30,7 @@ except: class DBusService(Borg, dbus.service.Object): """DBus Server class. This is implemented as a Borg""" bus_name = None + bus_path = None terminator = None def __init__(self): @@ -52,6 +53,8 @@ class DBusService(Borg, dbus.service.Object): "Couldn't get DBus name %s: Name exists" % BUS_NAME) self.bus_name = dbus.service.BusName(BUS_NAME, bus=dbus.SessionBus()) + if not self.bus_path: + self.bus_path = BUS_PATH if not self.terminator: self.terminator = Terminator() @@ -65,12 +68,12 @@ class DBusService(Borg, dbus.service.Object): @dbus.service.method(BUS_NAME) def terminal_hsplit(self, uuid=None): """Split a terminal horizontally, by UUID""" - self.terminal_split(uuid, True) + return self.terminal_split(uuid, True) @dbus.service.method(BUS_NAME) def terminal_vsplit(self, uuid=None): """Split a terminal vertically, by UUID""" - self.terminal_split(uuid, False) + return self.terminal_split(uuid, False) def terminal_split(self, uuid, horiz): """Split a terminal horizontally or vertically, by UUID""" @@ -85,6 +88,11 @@ class DBusService(Borg, dbus.service.Object): else: terminal.key_split_vert() + @dbus.service.method(BUS_NAME) + def get_terminals(self, uuid): + """Return a list of all the terminals""" + return [x.uuid.urn for x in self.terminator.terminals] + def with_proxy(func): """Decorator function to connect to the session dbus bus""" dbg('dbus client call: %s' % func.func_name) @@ -107,5 +115,10 @@ def terminal_hsplit(session, uuid): @with_proxy def terminal_vsplit(session, uuid): """Call the dbus method to vertically split a terminal""" - session.terminal_vsplit(uuid) + print session.terminal_vsplit(uuid) + +@with_proxy +def get_terminals(session, uuid): + """Call the dbus method to return a list of all terminals""" + print '\n'.join(session.get_terminals(uuid)) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index b41b4ba6..c33efc24 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1203,9 +1203,15 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) except AttributeError: pass + envv = [] + envv.append('TERMINATOR_UUID=%s' % self.uuid.urn) + if self.terminator.dbus_name: + envv.append('TERMINATOR_DBUS_NAME=%s' % self.terminator.dbus_name) + if self.terminator.dbus_path: + envv.append('TERMINATOR_DBUS_PATH=%s' % self.terminator.dbus_path) + dbg('Forking shell: "%s" with args: %s' % (shell, args)) - self.pid = self.vte.fork_command(command=shell, argv=args, - envv=['TERMINATOR_UUID=%s' % self.uuid.urn], + self.pid = self.vte.fork_command(command=shell, argv=args, envv=envv, loglastlog=login, logwtmp=update_records, logutmp=update_records, diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 8a343501..8ec97f11 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -26,6 +26,8 @@ class Terminator(Borg): keybindings = None origcwd = None + dbus_path = None + dbus_name = None pid_cwd = None gnome_client = None debug_address = None @@ -71,6 +73,12 @@ class Terminator(Borg): os.chdir(cwd) self.origcwd = cwd + def set_dbus_data(self, dbus_service): + """Store the DBus bus details, if they are available""" + if dbus_service: + self.dbus_name = dbus_service.bus_name.get_name() + self.dbus_path = dbus_service.bus_path + def attempt_gnome_client(self): """Attempt to find a GNOME Session to register with""" try: