Merge pull request #389 from TheBigS/add-new-get-focused-terminal-dbus-cmd

Added new get_focused_terminal dbus command which returns uuid of current focused terminal
This commit is contained in:
Matt Rose 2021-04-12 17:39:24 -04:00 committed by GitHub
commit c042ca1674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View File

@ -41,6 +41,7 @@ COMMANDS={
'hsplit': [True, _('Split the current terminal horizontally')], 'hsplit': [True, _('Split the current terminal horizontally')],
'vsplit': [True, _('Split the current terminal vertically')], 'vsplit': [True, _('Split the current terminal vertically')],
'get_terminals': [False, _('Get a list of all terminals')], 'get_terminals': [False, _('Get a list of all terminals')],
'get_focused_terminal': [False, _('Get the uuid of the current focused terminal')],
'get_window': [True, _('Get the UUID of a parent window')], 'get_window': [True, _('Get the UUID of a parent window')],
'get_window_title': [True, _('Get the title of a parent window')], 'get_window_title': [True, _('Get the title of a parent window')],
'get_tab': [True, _('Get the UUID of a parent tab')], 'get_tab': [True, _('Get the UUID of a parent tab')],
@ -88,9 +89,9 @@ if __name__ == '__main__':
if uuid_required: if uuid_required:
uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID')) uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID'))
if uuid: if uuid:
func(uuid, options) print(str(func(uuid, options)))
else: else:
err("$TERMINATOR_UUID is not set, or passed as an option.") err("$TERMINATOR_UUID is not set, or passed as an option.")
sys.exit(1) sys.exit(1)
else: else:
func(options) print(str(func(options)))

View File

@ -150,6 +150,13 @@ class DBusService(Borg, dbus.service.Object):
"""Return a list of all the terminals""" """Return a list of all the terminals"""
return [x.uuid.urn for x in self.terminator.terminals] return [x.uuid.urn for x in self.terminator.terminals]
@dbus.service.method(BUS_NAME)
def get_focused_terminal(self):
"""Returns the uuid of the currently focused terminal"""
if self.terminator.last_focused_term:
return self.terminator.last_focused_term.uuid.urn
return None
@dbus.service.method(BUS_NAME) @dbus.service.method(BUS_NAME)
def get_window(self, uuid=None): def get_window(self, uuid=None):
"""Return the UUID of the parent window of a given terminal""" """Return the UUID of the parent window of a given terminal"""
@ -217,7 +224,7 @@ def with_proxy(func):
"Remotinator can't connect to terminator. " + "Remotinator can't connect to terminator. " +
"May be terminator is not running.") "May be terminator is not running.")
func(proxy, *args, **argd) return func(proxy, *args, **argd)
return _exec return _exec
@with_proxy @with_proxy
@ -259,6 +266,11 @@ def get_terminals(session, options):
"""Call the dbus method to return a list of all terminals""" """Call the dbus method to return a list of all terminals"""
print('\n'.join(session.get_terminals())) print('\n'.join(session.get_terminals()))
@with_proxy
def get_focused_terminal(session, options):
"""Call the dbus method to return the currently focused terminal"""
return session.get_focused_terminal()
@with_proxy @with_proxy
def get_window(session, uuid, options): def get_window(session, uuid, options):
"""Call the dbus method to return the toplevel tab for a terminal""" """Call the dbus method to return the toplevel tab for a terminal"""