Skip to content

Commit c1c7a49

Browse files
committed
Add an option to draw an image on the window
1 parent 0fcebc2 commit c1c7a49

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

terminatorlib/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
'always_on_top' : False,
100100
'hide_on_lose_focus' : False,
101101
'sticky' : False,
102+
'window_background_type' : 'transparent',
103+
'window_background_image' : '',
102104
'use_custom_url_handler': False,
103105
'custom_url_handler' : '',
104106
'disable_real_transparency' : False,
@@ -565,7 +567,7 @@ def defaults_to_configspec(self):
565567

566568
keytype = '%s(default=%s)' % (keytype, value)
567569

568-
if key == 'custom_url_handler':
570+
if key in ('custom_url_handler', 'window_background_image'):
569571
keytype = 'string(default="")'
570572

571573
section[key] = keytype

terminatorlib/terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,9 @@ def set_background_image(self,image):
191191
try:
192192
bg_pixbuf = GdkPixbuf.Pixbuf.new_from_file(image)
193193
self.background_image = Gdk.cairo_surface_create_from_pixbuf(bg_pixbuf, 1, None)
194-
self.vte.set_clear_background(False)
195194
self.vte.connect("draw", self.background_draw)
196195
except Exception as e:
197196
self.background_image = None
198-
self.vte.set_clear_background(True)
199197
err('error loading background image: %s, %s' % (type(e).__name__,e))
200198

201199
def get_vte(self):
@@ -720,6 +718,8 @@ def reconfigure(self, _widget=None):
720718
self.bgcolor = Gdk.RGBA()
721719
self.bgcolor.parse(self.config['background_color'])
722720

721+
self.vte.set_clear_background(False)
722+
723723
if self.config['background_type'] in ('transparent', 'image'):
724724
self.bgcolor.alpha = self.config['background_darkness']
725725
else:

terminatorlib/window.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
import uuid
88
import gi
9-
from gi.repository import GObject
9+
from gi.repository import GObject, GdkPixbuf, cairo
1010
from gi.repository import Gtk, Gdk
1111

1212
from .util import dbg, err, make_uuid, display_manager
@@ -155,6 +155,8 @@ def apply_config(self):
155155
skiptaskbar = self.config['hide_from_taskbar']
156156
alwaysontop = self.config['always_on_top']
157157
sticky = self.config['sticky']
158+
background_type = self.config['window_background_type']
159+
background_image_path = self.config['window_background_image']
158160

159161
if options:
160162
if options.maximise:
@@ -178,6 +180,11 @@ def apply_config(self):
178180
else:
179181
self.set_iconified(hidden)
180182

183+
if background_type == 'image' and background_image_path != '':
184+
self.set_background_image(background_image_path)
185+
else:
186+
self.background_image = None
187+
181188
def apply_icon(self, requested_icon):
182189
"""Set the window icon"""
183190
icon_theme = Gtk.IconTheme.get_default()
@@ -392,6 +399,16 @@ def set_real_transparency(self, value=True):
392399
visual = screen.get_rgba_visual()
393400
if visual:
394401
self.set_visual(visual)
402+
403+
def set_background_image(self, image):
404+
try:
405+
bg_pixbuf = GdkPixbuf.Pixbuf.new_from_file(image)
406+
self.background_image = Gdk.cairo_surface_create_from_pixbuf(bg_pixbuf, 1, None)
407+
self.connect("draw", self.background_draw)
408+
except Exception as e:
409+
self.background_image = None
410+
err('error loading background image: %s, %s' % (type(e).__name__,e))
411+
395412

396413
def show(self, startup=False):
397414
"""Undo the startup show request if started in hidden mode"""
@@ -968,6 +985,24 @@ def create_layout(self, layout):
968985
if 'last_active_window' in layout and layout['last_active_window'] == 'True':
969986
self.terminator.last_active_window = self.uuid
970987

988+
989+
def background_draw(self, window, cr):
990+
if self.background_image is None:
991+
return False
992+
993+
# save cairo context
994+
cr.save()
995+
# draw background image
996+
rect = window.get_allocation()
997+
xratio = float(rect.width) / float(self.background_image.get_width())
998+
yratio = float(rect.height) / float(self.background_image.get_height())
999+
cr.scale(xratio, yratio)
1000+
cr.set_source_surface(self.background_image)
1001+
cr.get_source().set_filter(cairo.Filter.FAST)
1002+
cr.paint()
1003+
# restore cairo context
1004+
cr.restore()
1005+
9711006
class WindowTitle(object):
9721007
"""Class to handle the setting of the window title"""
9731008

0 commit comments

Comments
 (0)