@@ -985,21 +985,56 @@ def create_layout(self, layout):
985
985
if 'last_active_window' in layout and layout ['last_active_window' ] == 'True' :
986
986
self .terminator .last_active_window = self .uuid
987
987
988
-
988
+ # TODO this is almost identical to Terminal.background_draw.
989
+ # The two functions should be merged to avoid code duplication.
989
990
def background_draw (self , window , cr ):
990
991
if self .background_image is None :
991
992
return False
992
993
993
994
# save cairo context
994
995
cr .save ()
996
+
995
997
# 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
+
996
1002
rect = window .get_allocation ()
997
1003
xratio = float (rect .width ) / float (self .background_image .get_width ())
998
1004
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
999
1017
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 )
1001
1032
cr .get_source ().set_filter (cairo .Filter .FAST )
1033
+ if image_mode == 'tiling' :
1034
+ cr .get_source ().set_extend (cairo .Extend .REPEAT )
1035
+
1002
1036
cr .paint ()
1037
+
1003
1038
# restore cairo context
1004
1039
cr .restore ()
1005
1040
0 commit comments