@@ -54,8 +54,9 @@ function BackDrops:set_focus(focus_color)
5454end
5555
5656--- Create the `background` options with the current image
57+ --- @private
5758--- @return table
58- function BackDrops :create_opts ()
59+ function BackDrops :_create_opts ()
5960 return {
6061 {
6162 source = { File = self .files [self .current_idx ] },
@@ -72,12 +73,43 @@ function BackDrops:create_opts()
7273 }
7374end
7475
76+ --- Create the `background` options for focus mode
77+ --- @private
78+ --- @return table
79+ function BackDrops :_create_focus_opts ()
80+ return {
81+ {
82+ source = { Color = self .focus_color },
83+ height = ' 120%' ,
84+ width = ' 120%' ,
85+ vertical_offset = ' -10%' ,
86+ horizontal_offset = ' -10%' ,
87+ opacity = 1 ,
88+ },
89+ }
90+ end
91+
92+ --- Set the initial options for `background`
93+ --- @param focus_on boolean ? focus mode on or off
94+ function BackDrops :initial_options (focus_on )
95+ focus_on = focus_on or false
96+ assert (type (focus_on ) == ' boolean' , ' BackDrops:initial_options - Expected a boolean' )
97+
98+ self .focus_on = focus_on
99+ if focus_on then
100+ return self :_create_focus_opts ()
101+ end
102+
103+ return self :_create_opts ()
104+ end
105+
75106--- Override the current window options for background
76107--- @private
77108--- @param window any WezTerm Window see : https : //wezfurlong.org /wezterm /config /lua /window /index.html
78- function BackDrops :_set_opt (window )
109+ --- @param background_opts table background option
110+ function BackDrops :_set_opt (window , background_opts )
79111 window :set_config_overrides ({
80- background = self : create_opts () ,
112+ background = background_opts ,
81113 enable_tab_bar = window :effective_config ().enable_tab_bar ,
82114 })
83115end
@@ -102,6 +134,8 @@ function BackDrops:_set_focus_opt(window)
102134 window :set_config_overrides (opts )
103135end
104136
137+
138+
105139--- Convert the `files` array to a table of `InputSelector` choices
106140--- see: https://wezfurlong.org/wezterm/config/lua/keyassignment/InputSelector.html
107141function BackDrops :choices ()
@@ -122,7 +156,7 @@ function BackDrops:random(window)
122156 self .current_idx = math.random (# self .files )
123157
124158 if window ~= nil then
125- self :_set_opt (window )
159+ self :_set_opt (window , self : _create_opts () )
126160 end
127161end
128162
@@ -134,7 +168,7 @@ function BackDrops:cycle_forward(window)
134168 else
135169 self .current_idx = self .current_idx + 1
136170 end
137- self :_set_opt (window )
171+ self :_set_opt (window , self : _create_opts () )
138172end
139173
140174--- Cycle the loaded `files` and select the previous background
@@ -145,7 +179,7 @@ function BackDrops:cycle_back(window)
145179 else
146180 self .current_idx = self .current_idx - 1
147181 end
148- self :_set_opt (window )
182+ self :_set_opt (window , self : _create_opts () )
149183end
150184
151185--- Set a specific background from the `files` array
@@ -158,19 +192,23 @@ function BackDrops:set_img(window, idx)
158192 end
159193
160194 self .current_idx = idx
161- self :_set_opt (window )
195+ self :_set_opt (window , self : _create_opts () )
162196end
163197
164198--- Toggle the focus mode
165199--- @param window any WezTerm ` Window` see : https : //wezfurlong.org /wezterm /config /lua /window /index.html
166200function BackDrops :toggle_focus (window )
201+ local background_opts
202+
167203 if self .focus_on then
168- self :set_img ( window , self . current_idx )
204+ background_opts = self :_create_opts ( )
169205 self .focus_on = false
170206 else
171- self :_set_focus_opt ( window )
207+ background_opts = self :_create_focus_opts ( )
172208 self .focus_on = true
173209 end
210+
211+ self :_set_opt (window , background_opts )
174212end
175213
176214return BackDrops :init ()
0 commit comments