Skip to content

Commit

Permalink
Update Window.background_draw to match the newer version in Terminal
Browse files Browse the repository at this point in the history
Added these settings:
  - 'window_background_image_mode'
  - 'window_background_image_align_horiz'
  - 'window_background_image_align_vert'
  • Loading branch information
Vulcalien committed Oct 9, 2023
1 parent c1c7a49 commit 99249bb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions terminatorlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
'sticky' : False,
'window_background_type' : 'transparent',
'window_background_image' : '',
'window_background_image_mode' : 'stretch_and_fill',
'window_background_image_align_horiz' : 'center',
'window_background_image_align_vert' : 'middle',
'use_custom_url_handler': False,
'custom_url_handler' : '',
'disable_real_transparency' : False,
Expand Down
39 changes: 37 additions & 2 deletions terminatorlib/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,21 +985,56 @@ def create_layout(self, layout):
if 'last_active_window' in layout and layout['last_active_window'] == 'True':
self.terminator.last_active_window = self.uuid


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

# save cairo context
cr.save()

# draw background image
image_mode = self.config['window_background_image_mode']
image_align_horiz = self.config['window_background_image_align_horiz']
image_align_vert = self.config['window_background_image_align_vert']

rect = window.get_allocation()
xratio = float(rect.width) / float(self.background_image.get_width())
yratio = float(rect.height) / float(self.background_image.get_height())
if image_mode == 'stretch_and_fill':
# keep stretched ratios
xratio = xratio
yratio = yratio
elif image_mode == 'scale_and_fit':
ratio = min(xratio, yratio)
xratio = yratio = ratio
elif image_mode == 'scale_and_crop':
ratio = max(xratio, yratio)
xratio = yratio = ratio
else:
xratio = yratio = 1
cr.scale(xratio, yratio)
cr.set_source_surface(self.background_image)

xoffset = 0
yoffset = 0
if image_align_horiz == 'center':
xoffset = (rect.width / xratio - self.background_image.get_width()) / 2
elif image_align_horiz == 'right':
xoffset = rect.width / xratio - self.background_image.get_width()

if image_align_vert == 'middle':
yoffset = (rect.height / yratio - self.background_image.get_height()) / 2
elif image_align_vert == 'bottom':
yoffset = rect.height / yratio - self.background_image.get_height()

cr.set_source_surface(self.background_image, xoffset, yoffset)
cr.get_source().set_filter(cairo.Filter.FAST)
if image_mode == 'tiling':
cr.get_source().set_extend(cairo.Extend.REPEAT)

cr.paint()

# restore cairo context
cr.restore()

Expand Down

0 comments on commit 99249bb

Please sign in to comment.