diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 43d9a0b0..f58a0716 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -251,6 +251,8 @@ 'autoclean_groups' : True, 'http_proxy' : '', 'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'], + 'background_image' : '', + 'background_alpha' : 0.0 }, }, 'layouts': { diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 968fe9cb..3b1063c7 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -360,6 +360,11 @@ 0.1 0.2 + + 1 + 0.1 + 0.01 + False 6 @@ -1434,6 +1439,12 @@ 2 + + + + + + True @@ -2860,7 +2871,7 @@ False False - 1 + 5 0 @@ -2928,7 +2939,108 @@ False True - 2 + 3 + + + + + True + False + + + True + False + Background Image: + + + False + True + 5 + 0 + + + + + True + False + Choose file + + + + False + True + end + 1 + + + + + False + True + 4 + + + + + True + False + + + True + False + Shade Background Image: + + + False + True + 5 + 0 + + + + + True + False + Transparent + + + False + True + 1 + + + + + True + True + background_image_shading_adjustment + 1 + + + + True + True + 2 + + + + + True + False + Opaque + + + False + True + end + 3 + + + + + False + True + 5 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index a198fc5c..f483924d 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -637,7 +637,11 @@ def on_palette_click(event, data, widget=widget): # Background shading widget = guiget('background_darkness_scale') widget.set_value(float(self.config['background_darkness'])) - + widget = guiget('background_image_file') + widget.set_filename(self.config['background_image']) + widget = guiget('background_image_shading_scale') + widget.set_value(float(self.config['background_alpha'])) + ## Scrolling tab # Scrollbar position widget = guiget('scrollbar_position_combobox') @@ -931,6 +935,15 @@ def on_scrollbar_position_combobox_changed(self, widget): self.config['scrollbar_position'] = value self.config.save() + def on_background_image_file_set(self,widget): + print(widget.get_filename()) + self.config['background_image'] = widget.get_filename() + self.config.save() + + def on_background_image_shading_scale_value_changed(self,widget): + self.config['background_alpha'] = widget.get_value() + self.config.save() + def on_darken_background_scale_value_changed(self, widget): """Background darkness setting changed""" value = widget.get_value() # This one is rounded according to the UI. diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 6acf4552..369aaa02 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -6,7 +6,7 @@ import os import signal import gi -from gi.repository import GLib, GObject, Pango, Gtk, Gdk +from gi.repository import GLib, GObject, Pango, Gtk, Gdk, GdkPixbuf gi.require_version('Vte', '2.91') # vte-0.38 (gnome-3.14) from gi.repository import Vte import subprocess @@ -136,6 +136,14 @@ def __init__(self): self.pending_on_vte_size_allocate = False self.vte = Vte.Terminal() + self.background_image = None + if self.config['background_image'] != '': + try: + self.background_image = GdkPixbuf.Pixbuf.new_from_file(self.config['background_image']) + except Exception: + pass + + self.background_alpha = self.config['background_alpha'] self.vte.set_allow_hyperlink(True) self.vte._draw_data = None if not hasattr(self.vte, "set_opacity") or \ @@ -147,7 +155,8 @@ def __init__(self): self.vte.show() - + self.vte.set_clear_background(False) + self.vte.connect("draw",self.background_draw) self.default_encoding = self.vte.get_encoding() self.update_url_matches() @@ -1126,8 +1135,23 @@ def on_drag_motion(self, widget, drag_context, x, y, _time, _data): widget.disconnect(connec) widget._draw_data = None + def background_draw(self, widget, cr): + if not self.background_image: + return(False) + over = self.bgcolor + over.alpha = self.background_alpha + rect = self.vte.get_allocation() + xratio = float(rect.width) / float(self.background_image.get_width()) + yratio = float(rect.height) / float(self.background_image.get_height()) + cr.save() + cr.scale(xratio,yratio) + Gdk.cairo_set_source_pixbuf(cr, self.background_image, 0, 0) + cr.paint() + Gdk.cairo_set_source_rgba(cr,over) + cr.paint() + cr.restore() + def on_draw(self, widget, context): - """Handle an expose event while dragging""" if not widget._draw_data: return(False)