Skip to content

Commit f530b71

Browse files
feat(backdrops): startup on focus mode (#37)
1 parent 653ec67 commit f530b71

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

config/appearance.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ local backdrops = require('utils.backdrops')
33
local colors = require('colors.custom')
44

55
return {
6-
max_fps = 120,
6+
max_fps = 240,
77
front_end = 'WebGpu',
88
webgpu_power_preference = 'HighPerformance',
99
webgpu_preferred_adapter = gpu_adapters:pick_best(),
1010
-- webgpu_preferred_adapter = gpu_adapters:pick_manual('Dx12', 'IntegratedGpu'),
11+
-- webgpu_preferred_adapter = gpu_adapters:pick_manual('Gl', 'Other'),
1112

1213
-- cursor
13-
animation_fps = 120,
14+
animation_fps = 240,
1415
cursor_blink_ease_in = 'EaseOut',
1516
cursor_blink_ease_out = 'EaseOut',
1617
default_cursor_style = 'BlinkingBlock',
@@ -20,7 +21,7 @@ return {
2021
colors = colors,
2122

2223
-- background
23-
background = backdrops:create_opts(),
24+
background = backdrops:initial_options(),
2425

2526
-- scrollbar
2627
enable_scroll_bar = true,

utils/backdrops.lua

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ function BackDrops:set_focus(focus_color)
5454
end
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
}
7374
end
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
})
83115
end
@@ -102,6 +134,8 @@ function BackDrops:_set_focus_opt(window)
102134
window:set_config_overrides(opts)
103135
end
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
107141
function 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
127161
end
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())
138172
end
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())
149183
end
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())
162196
end
163197

164198
---Toggle the focus mode
165199
---@param window any WezTerm `Window` see: https://wezfurlong.org/wezterm/config/lua/window/index.html
166200
function 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)
174212
end
175213

176214
return BackDrops:init()

0 commit comments

Comments
 (0)