Skip to content

Commit 99249bb

Browse files
committed
Update Window.background_draw to match the newer version in Terminal
Added these settings: - 'window_background_image_mode' - 'window_background_image_align_horiz' - 'window_background_image_align_vert'
1 parent c1c7a49 commit 99249bb

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

terminatorlib/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
'sticky' : False,
102102
'window_background_type' : 'transparent',
103103
'window_background_image' : '',
104+
'window_background_image_mode' : 'stretch_and_fill',
105+
'window_background_image_align_horiz' : 'center',
106+
'window_background_image_align_vert' : 'middle',
104107
'use_custom_url_handler': False,
105108
'custom_url_handler' : '',
106109
'disable_real_transparency' : False,

terminatorlib/window.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,21 +985,56 @@ def create_layout(self, layout):
985985
if 'last_active_window' in layout and layout['last_active_window'] == 'True':
986986
self.terminator.last_active_window = self.uuid
987987

988-
988+
# TODO this is almost identical to Terminal.background_draw.
989+
# The two functions should be merged to avoid code duplication.
989990
def background_draw(self, window, cr):
990991
if self.background_image is None:
991992
return False
992993

993994
# save cairo context
994995
cr.save()
996+
995997
# draw background image
998+
image_mode = self.config['window_background_image_mode']
999+
image_align_horiz = self.config['window_background_image_align_horiz']
1000+
image_align_vert = self.config['window_background_image_align_vert']
1001+
9961002
rect = window.get_allocation()
9971003
xratio = float(rect.width) / float(self.background_image.get_width())
9981004
yratio = float(rect.height) / float(self.background_image.get_height())
1005+
if image_mode == 'stretch_and_fill':
1006+
# keep stretched ratios
1007+
xratio = xratio
1008+
yratio = yratio
1009+
elif image_mode == 'scale_and_fit':
1010+
ratio = min(xratio, yratio)
1011+
xratio = yratio = ratio
1012+
elif image_mode == 'scale_and_crop':
1013+
ratio = max(xratio, yratio)
1014+
xratio = yratio = ratio
1015+
else:
1016+
xratio = yratio = 1
9991017
cr.scale(xratio, yratio)
1000-
cr.set_source_surface(self.background_image)
1018+
1019+
xoffset = 0
1020+
yoffset = 0
1021+
if image_align_horiz == 'center':
1022+
xoffset = (rect.width / xratio - self.background_image.get_width()) / 2
1023+
elif image_align_horiz == 'right':
1024+
xoffset = rect.width / xratio - self.background_image.get_width()
1025+
1026+
if image_align_vert == 'middle':
1027+
yoffset = (rect.height / yratio - self.background_image.get_height()) / 2
1028+
elif image_align_vert == 'bottom':
1029+
yoffset = rect.height / yratio - self.background_image.get_height()
1030+
1031+
cr.set_source_surface(self.background_image, xoffset, yoffset)
10011032
cr.get_source().set_filter(cairo.Filter.FAST)
1033+
if image_mode == 'tiling':
1034+
cr.get_source().set_extend(cairo.Extend.REPEAT)
1035+
10021036
cr.paint()
1037+
10031038
# restore cairo context
10041039
cr.restore()
10051040

0 commit comments

Comments
 (0)