2010-01-11 20:06:53 +00:00
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminator.py - class for the master Terminator singleton"""
|
|
|
|
|
2010-03-10 12:52:50 +00:00
|
|
|
import copy
|
2010-04-18 08:49:32 +00:00
|
|
|
import os
|
2016-12-11 04:46:02 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version('Vte', '2.91')
|
2020-04-17 16:50:46 +00:00
|
|
|
from gi.repository import Gtk, Gdk, Vte
|
2017-02-13 02:20:28 +00:00
|
|
|
from gi.repository.GLib import GError
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2018-04-24 18:22:10 +00:00
|
|
|
from . import borg
|
|
|
|
from .borg import Borg
|
|
|
|
from .config import Config
|
|
|
|
from .keybindings import Keybindings
|
|
|
|
from .util import dbg, err, enumerate_descendants
|
|
|
|
from .factory import Factory
|
|
|
|
from .version import APP_NAME, APP_VERSION
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2020-04-17 16:50:46 +00:00
|
|
|
try:
|
|
|
|
from gi.repository import GdkX11
|
|
|
|
except ImportError:
|
|
|
|
dbg("could not import X11 gir module")
|
|
|
|
|
|
|
|
|
2014-09-19 14:10:43 +00:00
|
|
|
def eventkey2gdkevent(eventkey): # FIXME FOR GTK3: is there a simpler way of casting from specific EventKey to generic (union) GdkEvent?
|
2015-11-28 18:53:57 +00:00
|
|
|
gdkevent = Gdk.Event.new(eventkey.type)
|
2014-09-19 14:10:43 +00:00
|
|
|
gdkevent.key.window = eventkey.window
|
|
|
|
gdkevent.key.send_event = eventkey.send_event
|
|
|
|
gdkevent.key.time = eventkey.time
|
|
|
|
gdkevent.key.state = eventkey.state
|
|
|
|
gdkevent.key.keyval = eventkey.keyval
|
|
|
|
gdkevent.key.length = eventkey.length
|
|
|
|
gdkevent.key.string = eventkey.string
|
|
|
|
gdkevent.key.hardware_keycode = eventkey.hardware_keycode
|
|
|
|
gdkevent.key.group = eventkey.group
|
|
|
|
gdkevent.key.is_modifier = eventkey.is_modifier
|
|
|
|
return gdkevent
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
class Terminator(Borg):
|
|
|
|
"""master object for the application"""
|
|
|
|
|
|
|
|
windows = None
|
2013-08-28 21:09:17 +00:00
|
|
|
launcher_windows = None
|
2010-01-11 20:06:53 +00:00
|
|
|
windowtitle = None
|
|
|
|
terminals = None
|
|
|
|
groups = None
|
|
|
|
config = None
|
|
|
|
keybindings = None
|
2016-12-08 02:22:59 +00:00
|
|
|
style_providers = None
|
2015-11-29 01:51:26 +00:00
|
|
|
last_focused_term = None
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2010-01-29 23:52:21 +00:00
|
|
|
origcwd = None
|
2011-08-25 21:10:04 +00:00
|
|
|
dbus_path = None
|
|
|
|
dbus_name = None
|
2010-03-19 22:16:08 +00:00
|
|
|
debug_address = None
|
2015-11-30 20:54:23 +00:00
|
|
|
ibus_running = None
|
2010-01-29 23:52:21 +00:00
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
doing_layout = None
|
2015-07-15 00:51:18 +00:00
|
|
|
layoutname = None
|
2013-10-31 17:50:21 +00:00
|
|
|
last_active_window = None
|
2017-02-21 21:07:18 +00:00
|
|
|
prelayout_windows = None
|
2010-02-17 19:57:05 +00:00
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
groupsend = None
|
|
|
|
groupsend_type = {'all':0, 'group':1, 'off':2}
|
|
|
|
|
2016-12-11 22:50:42 +00:00
|
|
|
cur_gtk_theme_name = None
|
|
|
|
gtk_settings = None
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
|
|
|
|
Borg.__init__(self, self.__class__.__name__)
|
|
|
|
self.prepare_attributes()
|
|
|
|
|
|
|
|
def prepare_attributes(self):
|
|
|
|
"""Initialise anything that isn't already"""
|
|
|
|
|
|
|
|
if not self.windows:
|
|
|
|
self.windows = []
|
2013-08-28 21:09:17 +00:00
|
|
|
if not self.launcher_windows:
|
|
|
|
self.launcher_windows = []
|
2010-01-11 20:06:53 +00:00
|
|
|
if not self.terminals:
|
|
|
|
self.terminals = []
|
|
|
|
if not self.groups:
|
|
|
|
self.groups = []
|
|
|
|
if not self.config:
|
|
|
|
self.config = Config()
|
2015-06-22 18:06:21 +00:00
|
|
|
if self.groupsend == None:
|
|
|
|
self.groupsend = self.groupsend_type[self.config['broadcast_default']]
|
2010-01-11 20:06:53 +00:00
|
|
|
if not self.keybindings:
|
|
|
|
self.keybindings = Keybindings()
|
|
|
|
self.keybindings.configure(self.config['keybindings'])
|
2016-12-08 02:22:59 +00:00
|
|
|
if not self.style_providers:
|
|
|
|
self.style_providers = []
|
2010-02-17 19:57:05 +00:00
|
|
|
if not self.doing_layout:
|
|
|
|
self.doing_layout = False
|
2016-12-11 22:50:42 +00:00
|
|
|
self.connect_signals()
|
|
|
|
|
|
|
|
def connect_signals(self):
|
|
|
|
"""Connect all the gtk signals"""
|
|
|
|
self.gtk_settings=Gtk.Settings().get_default()
|
|
|
|
self.gtk_settings.connect('notify::gtk-theme-name', self.on_gtk_theme_name_notify)
|
|
|
|
self.cur_gtk_theme_name = self.gtk_settings.get_property('gtk-theme-name')
|
2010-03-19 12:39:44 +00:00
|
|
|
|
2010-04-18 08:49:32 +00:00
|
|
|
def set_origcwd(self, cwd):
|
|
|
|
"""Store the original cwd our process inherits"""
|
|
|
|
if cwd == '/':
|
|
|
|
cwd = os.path.expanduser('~')
|
|
|
|
os.chdir(cwd)
|
|
|
|
self.origcwd = cwd
|
|
|
|
|
2011-08-25 21:10:04 +00:00
|
|
|
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
|
|
|
|
|
2012-10-30 00:11:24 +00:00
|
|
|
def get_windows(self):
|
|
|
|
"""Return a list of windows"""
|
|
|
|
return self.windows
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def register_window(self, window):
|
|
|
|
"""Register a new window widget"""
|
|
|
|
if window not in self.windows:
|
|
|
|
dbg('Terminator::register_window: registering %s:%s' % (id(window),
|
|
|
|
type(window)))
|
|
|
|
self.windows.append(window)
|
|
|
|
|
|
|
|
def deregister_window(self, window):
|
|
|
|
"""de-register a window widget"""
|
|
|
|
dbg('Terminator::deregister_window: de-registering %s:%s' %
|
|
|
|
(id(window), type(window)))
|
2010-01-29 23:37:25 +00:00
|
|
|
if window in self.windows:
|
|
|
|
self.windows.remove(window)
|
|
|
|
else:
|
|
|
|
err('%s is not in registered window list' % window)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
if len(self.windows) == 0:
|
|
|
|
# We have no windows left, we should exit
|
2010-01-28 13:41:44 +00:00
|
|
|
dbg('no windows remain, quitting')
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.main_quit()
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2013-08-28 21:09:17 +00:00
|
|
|
def register_launcher_window(self, window):
|
|
|
|
"""Register a new launcher window widget"""
|
|
|
|
if window not in self.launcher_windows:
|
|
|
|
dbg('Terminator::register_launcher_window: registering %s:%s' % (id(window),
|
|
|
|
type(window)))
|
|
|
|
self.launcher_windows.append(window)
|
|
|
|
|
|
|
|
def deregister_launcher_window(self, window):
|
|
|
|
"""de-register a launcher window widget"""
|
|
|
|
dbg('Terminator::deregister_launcher_window: de-registering %s:%s' %
|
|
|
|
(id(window), type(window)))
|
|
|
|
if window in self.launcher_windows:
|
|
|
|
self.launcher_windows.remove(window)
|
|
|
|
else:
|
|
|
|
err('%s is not in registered window list' % window)
|
|
|
|
|
|
|
|
if len(self.launcher_windows) == 0 and len(self.windows) == 0:
|
|
|
|
# We have no windows left, we should exit
|
|
|
|
dbg('no windows remain, quitting')
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.main_quit()
|
2013-08-28 21:09:17 +00:00
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def register_terminal(self, terminal):
|
|
|
|
"""Register a new terminal widget"""
|
|
|
|
if terminal not in self.terminals:
|
|
|
|
dbg('Terminator::register_terminal: registering %s:%s' %
|
|
|
|
(id(terminal), type(terminal)))
|
|
|
|
self.terminals.append(terminal)
|
|
|
|
|
|
|
|
def deregister_terminal(self, terminal):
|
|
|
|
"""De-register a terminal widget"""
|
|
|
|
dbg('Terminator::deregister_terminal: de-registering %s:%s' %
|
|
|
|
(id(terminal), type(terminal)))
|
|
|
|
self.terminals.remove(terminal)
|
|
|
|
|
|
|
|
if len(self.terminals) == 0:
|
2010-01-28 13:41:44 +00:00
|
|
|
dbg('no terminals remain, destroying all windows')
|
2010-01-11 20:06:53 +00:00
|
|
|
for window in self.windows:
|
|
|
|
window.destroy()
|
2008-07-08 18:38:51 +00:00
|
|
|
else:
|
2010-01-11 20:06:53 +00:00
|
|
|
dbg('Terminator::deregister_terminal: %d terminals remain' %
|
|
|
|
len(self.terminals))
|
|
|
|
|
2011-08-24 21:38:56 +00:00
|
|
|
def find_terminal_by_uuid(self, uuid):
|
|
|
|
"""Search our terminals for one matching the supplied UUID"""
|
|
|
|
dbg('searching self.terminals for: %s' % uuid)
|
|
|
|
for terminal in self.terminals:
|
|
|
|
dbg('checking: %s (%s)' % (terminal.uuid.urn, terminal))
|
|
|
|
if terminal.uuid.urn == uuid:
|
|
|
|
return terminal
|
|
|
|
return None
|
|
|
|
|
2017-02-21 21:07:18 +00:00
|
|
|
def find_window_by_uuid(self, uuid):
|
|
|
|
"""Search our terminals for one matching the supplied UUID"""
|
|
|
|
dbg('searching self.terminals for: %s' % uuid)
|
|
|
|
for window in self.windows:
|
|
|
|
dbg('checking: %s (%s)' % (window.uuid.urn, window))
|
|
|
|
if window.uuid.urn == uuid:
|
|
|
|
return window
|
|
|
|
return None
|
|
|
|
|
2015-12-02 19:57:59 +00:00
|
|
|
def new_window(self, cwd=None, profile=None):
|
2010-01-29 23:41:18 +00:00
|
|
|
"""Create a window with a Terminal in it"""
|
|
|
|
maker = Factory()
|
|
|
|
window = maker.make('Window')
|
|
|
|
terminal = maker.make('Terminal')
|
2010-07-03 15:16:50 +00:00
|
|
|
if cwd:
|
|
|
|
terminal.set_cwd(cwd)
|
2015-12-02 19:57:59 +00:00
|
|
|
if profile and self.config['always_split_with_profile']:
|
|
|
|
terminal.force_set_profile(None, profile)
|
2010-01-29 23:41:18 +00:00
|
|
|
window.add(terminal)
|
2010-05-15 18:07:07 +00:00
|
|
|
window.show(True)
|
2010-01-29 23:41:18 +00:00
|
|
|
terminal.spawn_child()
|
|
|
|
|
|
|
|
return(window, terminal)
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
def create_layout(self, layoutname):
|
|
|
|
"""Create all the parts necessary to satisfy the specified layout"""
|
|
|
|
layout = None
|
2010-02-02 00:39:41 +00:00
|
|
|
objects = {}
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
self.doing_layout = True
|
2017-02-04 03:13:24 +00:00
|
|
|
self.last_active_window = None
|
2017-02-21 21:07:18 +00:00
|
|
|
self.prelayout_windows = self.windows[:]
|
2010-02-17 19:57:05 +00:00
|
|
|
|
2010-03-10 12:52:50 +00:00
|
|
|
layout = copy.deepcopy(self.config.layout_get_config(layoutname))
|
2010-02-01 12:11:44 +00:00
|
|
|
if not layout:
|
|
|
|
# User specified a non-existent layout. default to one Terminal
|
|
|
|
err('layout %s not defined' % layout)
|
2011-08-24 19:00:51 +00:00
|
|
|
self.new_window()
|
|
|
|
return
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
# Wind the flat objects into a hierarchy
|
|
|
|
hierarchy = {}
|
|
|
|
count = 0
|
|
|
|
# Loop over the layout until we have consumed it, or hit 1000 loops.
|
|
|
|
# This is a stupid artificial limit, but it's safe.
|
|
|
|
while len(layout) > 0 and count < 1000:
|
|
|
|
count = count + 1
|
|
|
|
if count == 1000:
|
|
|
|
err('hit maximum loop boundary. THIS IS VERY LIKELY A BUG')
|
2018-04-24 18:22:10 +00:00
|
|
|
for obj in list(layout.keys()):
|
2010-02-02 00:39:41 +00:00
|
|
|
if layout[obj]['type'].lower() == 'window':
|
|
|
|
hierarchy[obj] = {}
|
|
|
|
hierarchy[obj]['type'] = 'Window'
|
|
|
|
hierarchy[obj]['children'] = {}
|
2010-02-27 13:55:38 +00:00
|
|
|
|
|
|
|
# Copy any additional keys
|
2018-04-24 18:22:10 +00:00
|
|
|
for objkey in list(layout[obj].keys()):
|
|
|
|
if layout[obj][objkey] != '' and objkey not in hierarchy[obj]:
|
2010-02-27 13:55:38 +00:00
|
|
|
hierarchy[obj][objkey] = layout[obj][objkey]
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
objects[obj] = hierarchy[obj]
|
|
|
|
del(layout[obj])
|
|
|
|
else:
|
|
|
|
# Now examine children to see if their parents exist yet
|
2018-04-24 18:22:10 +00:00
|
|
|
if 'parent' not in layout[obj]:
|
2010-02-02 00:39:41 +00:00
|
|
|
err('Invalid object: %s' % obj)
|
|
|
|
del(layout[obj])
|
|
|
|
continue
|
2018-04-24 18:22:10 +00:00
|
|
|
if layout[obj]['parent'] in objects:
|
2010-02-17 19:47:33 +00:00
|
|
|
# Our parent has been created, add ourselves
|
2010-02-02 00:39:41 +00:00
|
|
|
childobj = {}
|
|
|
|
childobj['type'] = layout[obj]['type']
|
|
|
|
childobj['children'] = {}
|
2010-02-17 19:47:33 +00:00
|
|
|
|
|
|
|
# Copy over any additional object keys
|
2018-04-24 18:22:10 +00:00
|
|
|
for objkey in list(layout[obj].keys()):
|
|
|
|
if objkey not in childobj:
|
2010-02-17 19:47:33 +00:00
|
|
|
childobj[objkey] = layout[obj][objkey]
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
objects[layout[obj]['parent']]['children'][obj] = childobj
|
|
|
|
objects[obj] = childobj
|
|
|
|
del(layout[obj])
|
|
|
|
|
|
|
|
layout = hierarchy
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
for windef in layout:
|
2010-02-02 00:39:41 +00:00
|
|
|
if layout[windef]['type'] != 'Window':
|
2010-02-01 12:11:44 +00:00
|
|
|
err('invalid layout format. %s' % layout)
|
|
|
|
raise(ValueError)
|
2010-06-15 14:19:05 +00:00
|
|
|
dbg('Creating a window')
|
2010-02-01 12:11:44 +00:00
|
|
|
window, terminal = self.new_window()
|
2018-04-24 18:22:10 +00:00
|
|
|
if 'position' in layout[windef]:
|
2010-02-27 13:55:38 +00:00
|
|
|
parts = layout[windef]['position'].split(':')
|
|
|
|
if len(parts) == 2:
|
|
|
|
window.move(int(parts[0]), int(parts[1]))
|
2018-04-24 18:22:10 +00:00
|
|
|
if 'size' in layout[windef]:
|
2010-02-27 14:18:08 +00:00
|
|
|
parts = layout[windef]['size']
|
2010-04-02 16:04:54 +00:00
|
|
|
winx = int(parts[0])
|
|
|
|
winy = int(parts[1])
|
|
|
|
if winx > 1 and winy > 1:
|
|
|
|
window.resize(winx, winy)
|
2018-04-24 18:22:10 +00:00
|
|
|
if 'title' in layout[windef]:
|
2013-06-20 17:48:22 +00:00
|
|
|
window.title.force_title(layout[windef]['title'])
|
2018-04-24 18:22:10 +00:00
|
|
|
if 'maximised' in layout[windef]:
|
2013-09-04 20:59:27 +00:00
|
|
|
if layout[windef]['maximised'] == 'True':
|
|
|
|
window.ismaximised = True
|
|
|
|
else:
|
|
|
|
window.ismaximised = False
|
|
|
|
window.set_maximised(window.ismaximised)
|
2018-04-24 18:22:10 +00:00
|
|
|
if 'fullscreen' in layout[windef]:
|
2013-09-04 20:59:27 +00:00
|
|
|
if layout[windef]['fullscreen'] == 'True':
|
|
|
|
window.isfullscreen = True
|
|
|
|
else:
|
|
|
|
window.isfullscreen = False
|
|
|
|
window.set_fullscreen(window.isfullscreen)
|
2013-09-02 14:54:07 +00:00
|
|
|
window.create_layout(layout[windef])
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2015-07-15 00:51:18 +00:00
|
|
|
self.layoutname = layoutname
|
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
def layout_done(self):
|
|
|
|
"""Layout operations have finished, record that fact"""
|
|
|
|
self.doing_layout = False
|
2013-12-18 17:06:59 +00:00
|
|
|
maker = Factory()
|
2010-02-17 19:57:05 +00:00
|
|
|
|
2013-12-18 17:06:59 +00:00
|
|
|
window_last_active_term_mapping = {}
|
2013-10-31 17:50:21 +00:00
|
|
|
for window in self.windows:
|
2013-12-18 17:06:59 +00:00
|
|
|
if window.is_child_notebook():
|
|
|
|
source = window.get_toplevel().get_children()[0]
|
|
|
|
else:
|
|
|
|
source = window
|
|
|
|
window_last_active_term_mapping[window] = copy.copy(source.last_active_term)
|
2013-10-31 17:50:21 +00:00
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
for terminal in self.terminals:
|
|
|
|
if not terminal.pid:
|
|
|
|
terminal.spawn_child()
|
|
|
|
|
2013-11-19 11:46:11 +00:00
|
|
|
for window in self.windows:
|
2020-06-16 00:02:12 +00:00
|
|
|
if not window.is_child_notebook():
|
2013-12-18 17:06:59 +00:00
|
|
|
# For windows without a notebook ensure Terminal is visible and focussed
|
|
|
|
if window_last_active_term_mapping[window]:
|
|
|
|
term = self.find_terminal_by_uuid(window_last_active_term_mapping[window].urn)
|
|
|
|
term.ensure_visible_and_focussed()
|
2017-02-21 21:07:18 +00:00
|
|
|
|
|
|
|
# Build list of new windows using prelayout list
|
|
|
|
new_win_list = []
|
2020-03-17 01:15:31 +00:00
|
|
|
if self.prelayout_windows:
|
|
|
|
for window in self.windows:
|
|
|
|
if window not in self.prelayout_windows:
|
|
|
|
new_win_list.append(window)
|
|
|
|
|
2017-02-21 21:07:18 +00:00
|
|
|
# Make sure all new windows get bumped to the top
|
|
|
|
for window in new_win_list:
|
|
|
|
window.show()
|
|
|
|
window.grab_focus()
|
|
|
|
try:
|
|
|
|
t = GdkX11.x11_get_server_time(window.get_window())
|
2020-06-03 15:50:03 +00:00
|
|
|
except (NameError,TypeError, AttributeError):
|
2017-02-21 21:07:18 +00:00
|
|
|
t = 0
|
|
|
|
window.get_window().focus(t)
|
|
|
|
|
|
|
|
# Awful workaround to be sure that the last focused window is actually the one focused.
|
|
|
|
# Don't ask, don't tell policy on this. Even this is not 100%
|
|
|
|
if self.last_active_window:
|
|
|
|
window = self.find_window_by_uuid(self.last_active_window.urn)
|
|
|
|
count = 0
|
|
|
|
while count < 1000 and Gtk.events_pending():
|
|
|
|
count += 1
|
|
|
|
Gtk.main_iteration_do(False)
|
2013-11-19 11:46:11 +00:00
|
|
|
window.show()
|
2017-02-21 21:07:18 +00:00
|
|
|
window.grab_focus()
|
|
|
|
try:
|
|
|
|
t = GdkX11.x11_get_server_time(window.get_window())
|
2020-06-03 15:50:03 +00:00
|
|
|
except (NameError,TypeError, AttributeError):
|
2017-02-21 21:07:18 +00:00
|
|
|
t = 0
|
|
|
|
window.get_window().focus(t)
|
|
|
|
|
|
|
|
self.prelayout_windows = None
|
2013-11-19 11:46:11 +00:00
|
|
|
|
2016-12-11 22:50:42 +00:00
|
|
|
def on_gtk_theme_name_notify(self, settings, prop):
|
|
|
|
"""Reconfigure if the gtk theme name changes"""
|
|
|
|
new_gtk_theme_name = settings.get_property(prop.name)
|
|
|
|
if new_gtk_theme_name != self.cur_gtk_theme_name:
|
|
|
|
self.cur_gtk_theme_name = new_gtk_theme_name
|
|
|
|
self.reconfigure()
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def reconfigure(self):
|
|
|
|
"""Update configuration for the whole application"""
|
|
|
|
|
2016-12-08 02:22:59 +00:00
|
|
|
if self.style_providers != []:
|
|
|
|
for style_provider in self.style_providers:
|
|
|
|
Gtk.StyleContext.remove_provider_for_screen(
|
|
|
|
Gdk.Screen.get_default(),
|
|
|
|
style_provider)
|
|
|
|
self.style_providers = []
|
2016-07-08 10:04:54 +00:00
|
|
|
|
2016-12-08 02:22:59 +00:00
|
|
|
# Force the window background to be transparent for newer versions of
|
|
|
|
# GTK3. We then have to fix all the widget backgrounds because the
|
|
|
|
# widgets theming may not render it's own background.
|
2016-07-08 10:04:54 +00:00
|
|
|
css = """
|
|
|
|
.terminator-terminal-window {
|
2016-12-08 17:31:42 +00:00
|
|
|
background-color: alpha(@theme_bg_color,0); }
|
2016-12-08 02:22:59 +00:00
|
|
|
|
2017-02-01 10:59:11 +00:00
|
|
|
.terminator-terminal-window .notebook.header,
|
|
|
|
.terminator-terminal-window notebook header {
|
2016-12-08 17:31:42 +00:00
|
|
|
background-color: @theme_bg_color; }
|
2016-12-08 02:22:59 +00:00
|
|
|
|
2016-12-10 14:14:06 +00:00
|
|
|
.terminator-terminal-window .pane-separator {
|
2016-12-08 17:31:42 +00:00
|
|
|
background-color: @theme_bg_color; }
|
2016-07-08 10:04:54 +00:00
|
|
|
|
2016-12-10 14:14:06 +00:00
|
|
|
.terminator-terminal-window .terminator-terminal-searchbar {
|
2016-12-08 17:31:42 +00:00
|
|
|
background-color: @theme_bg_color; }
|
2016-12-08 02:22:59 +00:00
|
|
|
"""
|
2016-12-09 23:47:11 +00:00
|
|
|
|
|
|
|
# Fix several themes that put a borders, corners, or backgrounds around
|
|
|
|
# viewports, making the titlebar look bad.
|
|
|
|
css += """
|
2017-02-01 10:59:11 +00:00
|
|
|
.terminator-terminal-window GtkViewport,
|
|
|
|
.terminator-terminal-window viewport {
|
2016-12-09 23:47:11 +00:00
|
|
|
border-width: 0px;
|
|
|
|
border-radius: 0px;
|
|
|
|
background-color: transparent; }
|
|
|
|
"""
|
|
|
|
|
2016-12-11 04:46:02 +00:00
|
|
|
# Add per profile snippets for setting the background of the HBox
|
|
|
|
template = """
|
|
|
|
.terminator-profile-%s {
|
|
|
|
background-color: alpha(%s, %s); }
|
|
|
|
"""
|
|
|
|
profiles = self.config.base.profiles
|
2018-04-24 18:22:10 +00:00
|
|
|
for profile in list(profiles.keys()):
|
2016-12-11 04:46:02 +00:00
|
|
|
if profiles[profile]['use_theme_colors']:
|
2016-12-11 21:25:37 +00:00
|
|
|
# Create a dummy window/vte and realise it so it has correct
|
|
|
|
# values to read from
|
|
|
|
tmp_win = Gtk.Window()
|
|
|
|
tmp_vte = Vte.Terminal()
|
|
|
|
tmp_win.add(tmp_vte)
|
|
|
|
tmp_win.realize()
|
|
|
|
bgcolor = tmp_vte.get_style_context().get_background_color(Gtk.StateType.NORMAL)
|
2016-12-11 04:46:02 +00:00
|
|
|
bgcolor = "#{0:02x}{1:02x}{2:02x}".format(int(bgcolor.red * 255),
|
|
|
|
int(bgcolor.green * 255),
|
|
|
|
int(bgcolor.blue * 255))
|
2016-12-11 21:25:37 +00:00
|
|
|
tmp_win.remove(tmp_vte)
|
|
|
|
del(tmp_vte)
|
|
|
|
del(tmp_win)
|
2016-12-11 04:46:02 +00:00
|
|
|
else:
|
|
|
|
bgcolor = Gdk.RGBA()
|
|
|
|
bgcolor = profiles[profile]['background_color']
|
|
|
|
if profiles[profile]['background_type'] == 'transparent':
|
|
|
|
bgalpha = profiles[profile]['background_darkness']
|
|
|
|
else:
|
|
|
|
bgalpha = "1"
|
|
|
|
|
|
|
|
munged_profile = "".join([c if c.isalnum() else "-" for c in profile])
|
|
|
|
css += template % (munged_profile, bgcolor, bgalpha)
|
|
|
|
|
2016-12-08 02:22:59 +00:00
|
|
|
style_provider = Gtk.CssProvider()
|
2018-04-24 18:22:10 +00:00
|
|
|
style_provider.load_from_data(css.encode('utf-8'))
|
2016-12-08 02:22:59 +00:00
|
|
|
self.style_providers.append(style_provider)
|
|
|
|
|
|
|
|
# Attempt to load some theme specific stylistic tweaks for appearances
|
2016-12-09 21:47:44 +00:00
|
|
|
usr_theme_dir = os.path.expanduser('~/.local/share/themes')
|
|
|
|
(head, _tail) = os.path.split(borg.__file__)
|
|
|
|
app_theme_dir = os.path.join(head, 'themes')
|
|
|
|
|
2016-12-11 22:50:42 +00:00
|
|
|
theme_name = self.gtk_settings.get_property('gtk-theme-name')
|
2016-12-10 15:35:25 +00:00
|
|
|
|
|
|
|
theme_part_list = ['terminator.css']
|
2016-12-12 11:27:56 +00:00
|
|
|
if self.config['extra_styling']: # checkbox_style - needs adding to prefs
|
2016-12-10 15:35:25 +00:00
|
|
|
theme_part_list.append('terminator_styling.css')
|
|
|
|
for theme_part_file in theme_part_list:
|
|
|
|
for theme_dir in [usr_theme_dir, app_theme_dir]:
|
|
|
|
path_to_theme_specific_css = os.path.join(theme_dir,
|
|
|
|
theme_name,
|
|
|
|
'gtk-3.0/apps',
|
|
|
|
theme_part_file)
|
|
|
|
if os.path.isfile(path_to_theme_specific_css):
|
|
|
|
style_provider = Gtk.CssProvider()
|
2017-02-13 02:20:28 +00:00
|
|
|
style_provider.connect('parsing-error', self.on_css_parsing_error)
|
|
|
|
try:
|
|
|
|
style_provider.load_from_path(path_to_theme_specific_css)
|
|
|
|
except GError:
|
|
|
|
# Hmmm. Should we try to provide GTK version specific files here on failure?
|
|
|
|
gtk_version_string = '.'.join([str(Gtk.get_major_version()),
|
|
|
|
str(Gtk.get_minor_version()),
|
|
|
|
str(Gtk.get_micro_version())])
|
|
|
|
err('Error(s) loading css from %s into Gtk %s' % (path_to_theme_specific_css,
|
|
|
|
gtk_version_string))
|
2016-12-10 15:35:25 +00:00
|
|
|
self.style_providers.append(style_provider)
|
|
|
|
break
|
2016-12-08 02:22:59 +00:00
|
|
|
|
2016-12-08 17:31:42 +00:00
|
|
|
# Size the GtkPaned splitter handle size.
|
2016-12-11 18:32:22 +00:00
|
|
|
css = ""
|
2018-04-24 18:22:10 +00:00
|
|
|
if self.config['handle_size'] in range(0, 21):
|
2016-12-11 18:32:22 +00:00
|
|
|
css += """
|
2020-06-21 15:44:26 +00:00
|
|
|
.terminator-terminal-window separator {
|
|
|
|
min-height: %spx;
|
|
|
|
min-width: %spx;
|
|
|
|
}
|
|
|
|
""" % (self.config['handle_size'],self.config['handle_size'])
|
2016-12-08 17:31:42 +00:00
|
|
|
style_provider = Gtk.CssProvider()
|
2018-04-24 18:22:10 +00:00
|
|
|
style_provider.load_from_data(css.encode('utf-8'))
|
2016-12-08 17:31:42 +00:00
|
|
|
self.style_providers.append(style_provider)
|
2016-12-08 02:22:59 +00:00
|
|
|
|
|
|
|
# Apply the providers, incrementing priority so they don't cancel out
|
|
|
|
# each other
|
2018-04-24 18:22:10 +00:00
|
|
|
for idx in range(0, len(self.style_providers)):
|
2016-12-08 02:22:59 +00:00
|
|
|
Gtk.StyleContext.add_provider_for_screen(
|
|
|
|
Gdk.Screen.get_default(),
|
|
|
|
self.style_providers[idx],
|
|
|
|
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION+idx)
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
# Cause all the terminals to reconfigure
|
|
|
|
for terminal in self.terminals:
|
|
|
|
terminal.reconfigure()
|
|
|
|
|
2010-02-07 22:32:55 +00:00
|
|
|
# Reparse our keybindings
|
|
|
|
self.keybindings.configure(self.config['keybindings'])
|
|
|
|
|
2010-04-01 22:15:42 +00:00
|
|
|
# Update tab position if appropriate
|
|
|
|
maker = Factory()
|
|
|
|
for window in self.windows:
|
|
|
|
child = window.get_child()
|
|
|
|
if maker.isinstance(child, 'Notebook'):
|
|
|
|
child.configure()
|
|
|
|
|
2017-02-13 02:20:28 +00:00
|
|
|
def on_css_parsing_error(self, provider, section, error, user_data=None):
|
|
|
|
"""Report CSS parsing issues"""
|
|
|
|
file_path = section.get_file().get_path()
|
|
|
|
line_no = section.get_end_line() +1
|
|
|
|
col_no = section.get_end_position() + 1
|
|
|
|
err('%s, at line %d, column %d, of file %s' % (error.message,
|
|
|
|
line_no, col_no,
|
|
|
|
file_path))
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def create_group(self, name):
|
|
|
|
"""Create a new group"""
|
|
|
|
if name not in self.groups:
|
|
|
|
dbg('Terminator::create_group: registering group %s' % name)
|
|
|
|
self.groups.append(name)
|
|
|
|
|
|
|
|
def closegroupedterms(self, group):
|
|
|
|
"""Close all terminals in a group"""
|
2013-07-15 16:34:43 +00:00
|
|
|
for terminal in self.terminals[:]:
|
2010-01-11 20:06:53 +00:00
|
|
|
if terminal.group == group:
|
|
|
|
terminal.close()
|
|
|
|
|
|
|
|
def group_hoover(self):
|
|
|
|
"""Clean out unused groups"""
|
|
|
|
|
|
|
|
if self.config['autoclean_groups']:
|
|
|
|
inuse = []
|
|
|
|
todestroy = []
|
|
|
|
|
|
|
|
for terminal in self.terminals:
|
|
|
|
if terminal.group:
|
|
|
|
if not terminal.group in inuse:
|
|
|
|
inuse.append(terminal.group)
|
|
|
|
|
|
|
|
for group in self.groups:
|
|
|
|
if not group in inuse:
|
|
|
|
todestroy.append(group)
|
|
|
|
|
|
|
|
dbg('Terminator::group_hoover: %d groups, hoovering %d' %
|
|
|
|
(len(self.groups), len(todestroy)))
|
|
|
|
for group in todestroy:
|
|
|
|
self.groups.remove(group)
|
|
|
|
|
|
|
|
def group_emit(self, terminal, group, type, event):
|
|
|
|
"""Emit to each terminal in a group"""
|
|
|
|
dbg('Terminator::group_emit: emitting a keystroke for group %s' %
|
|
|
|
group)
|
|
|
|
for term in self.terminals:
|
|
|
|
if term != terminal and term.group == group:
|
2014-09-19 14:10:43 +00:00
|
|
|
term.vte.emit(type, eventkey2gdkevent(event))
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
def all_emit(self, terminal, type, event):
|
|
|
|
"""Emit to all terminals"""
|
|
|
|
for term in self.terminals:
|
|
|
|
if term != terminal:
|
2014-09-19 14:10:43 +00:00
|
|
|
term.vte.emit(type, eventkey2gdkevent(event))
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
def do_enumerate(self, widget, pad):
|
|
|
|
"""Insert the number of each terminal in a group, into that terminal"""
|
|
|
|
if pad:
|
|
|
|
numstr = '%0'+str(len(str(len(self.terminals))))+'d'
|
2008-06-26 23:24:52 +00:00
|
|
|
else:
|
2010-01-11 20:06:53 +00:00
|
|
|
numstr = '%d'
|
|
|
|
|
2011-02-23 21:02:09 +00:00
|
|
|
terminals = []
|
|
|
|
for window in self.windows:
|
|
|
|
containers, win_terminals = enumerate_descendants(window)
|
|
|
|
terminals.extend(win_terminals)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
for term in self.get_target_terms(widget):
|
2011-02-23 21:02:09 +00:00
|
|
|
idx = terminals.index(term)
|
2010-01-11 20:06:53 +00:00
|
|
|
term.feed(numstr % (idx + 1))
|
|
|
|
|
2012-06-24 18:36:39 +00:00
|
|
|
def get_sibling_terms(self, widget):
|
|
|
|
termset = []
|
|
|
|
for term in self.terminals:
|
|
|
|
if term.group == widget.group:
|
|
|
|
termset.append(term)
|
|
|
|
return(termset)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def get_target_terms(self, widget):
|
|
|
|
"""Get the terminals we should currently be broadcasting to"""
|
|
|
|
if self.groupsend == self.groupsend_type['all']:
|
|
|
|
return(self.terminals)
|
|
|
|
elif self.groupsend == self.groupsend_type['group']:
|
2012-06-24 18:36:39 +00:00
|
|
|
if widget.group != None:
|
|
|
|
return(self.get_sibling_terms(widget))
|
|
|
|
return([widget])
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2010-04-02 15:45:32 +00:00
|
|
|
def get_focussed_terminal(self):
|
|
|
|
"""iterate over all the terminals to find which, if any, has focus"""
|
|
|
|
for terminal in self.terminals:
|
2015-03-02 12:16:09 +00:00
|
|
|
if terminal.has_focus():
|
2010-04-02 15:45:32 +00:00
|
|
|
return(terminal)
|
|
|
|
return(None)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def focus_changed(self, widget):
|
|
|
|
"""We just moved focus to a new terminal"""
|
|
|
|
for terminal in self.terminals:
|
2010-01-18 23:27:22 +00:00
|
|
|
terminal.titlebar.update(widget)
|
2010-01-11 20:06:53 +00:00
|
|
|
return
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2012-06-24 18:36:39 +00:00
|
|
|
def focus_left(self, widget):
|
|
|
|
self.last_focused_term=widget
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
def describe_layout(self):
|
|
|
|
"""Describe our current layout"""
|
2010-02-02 00:39:41 +00:00
|
|
|
layout = {}
|
|
|
|
count = 0
|
2010-02-01 12:11:44 +00:00
|
|
|
for window in self.windows:
|
2010-02-02 00:39:41 +00:00
|
|
|
parent = ''
|
2010-03-11 13:04:01 +00:00
|
|
|
count = window.describe_layout(count, parent, layout, 0)
|
2010-02-01 12:11:44 +00:00
|
|
|
|
|
|
|
return(layout)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|