6
6
import time
7
7
import uuid
8
8
import gi
9
- from gi .repository import GObject
9
+ from gi .repository import GObject , GdkPixbuf , cairo
10
10
from gi .repository import Gtk , Gdk
11
11
12
12
from .util import dbg , err , make_uuid , display_manager
@@ -155,6 +155,8 @@ def apply_config(self):
155
155
skiptaskbar = self .config ['hide_from_taskbar' ]
156
156
alwaysontop = self .config ['always_on_top' ]
157
157
sticky = self .config ['sticky' ]
158
+ background_type = self .config ['window_background_type' ]
159
+ background_image_path = self .config ['window_background_image' ]
158
160
159
161
if options :
160
162
if options .maximise :
@@ -178,6 +180,11 @@ def apply_config(self):
178
180
else :
179
181
self .set_iconified (hidden )
180
182
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
+
181
188
def apply_icon (self , requested_icon ):
182
189
"""Set the window icon"""
183
190
icon_theme = Gtk .IconTheme .get_default ()
@@ -392,6 +399,16 @@ def set_real_transparency(self, value=True):
392
399
visual = screen .get_rgba_visual ()
393
400
if visual :
394
401
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
+
395
412
396
413
def show (self , startup = False ):
397
414
"""Undo the startup show request if started in hidden mode"""
@@ -968,6 +985,24 @@ def create_layout(self, layout):
968
985
if 'last_active_window' in layout and layout ['last_active_window' ] == 'True' :
969
986
self .terminator .last_active_window = self .uuid
970
987
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
+
971
1006
class WindowTitle (object ):
972
1007
"""Class to handle the setting of the window title"""
973
1008
0 commit comments