File tree Expand file tree Collapse file tree
modules/home/programs/graphical/bars/sketchybar/dynamic-island-sketchybar Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -204,6 +204,8 @@ local monitorResolution = monitorHelpers.resolveMonitorResolution({
204204 logWarn = logWarn ,
205205})
206206local calculateMargin = monitorHelpers .calculateMargin (monitorResolution )
207+ local calculateIslandWidth = monitorHelpers .calculateIslandWidth (monitorResolution )
208+ local calculateVisibleMargin = monitorHelpers .calculateVisibleMargin (monitorResolution )
207209local barColor = get (" colors.black" , " 0xff000000" )
208210local display = get (" main.display" , " main" )
209211local fontFamily = get (" main.font" , " SF Pro" )
@@ -449,6 +451,8 @@ local baseCtx = {
449451 colorTransparent = colorTransparent ,
450452 monitorResolution = monitorResolution ,
451453 calculateMargin = calculateMargin ,
454+ calculateVisibleMargin = calculateVisibleMargin ,
455+ calculateIslandWidth = calculateIslandWidth ,
452456 squishAmount = squishAmount ,
453457 defaultHeight = defaultHeight ,
454458 defaultWidth = defaultWidth ,
Original file line number Diff line number Diff line change @@ -212,7 +212,51 @@ local function makeMarginCalculator(monitorResolution)
212212 end
213213end
214214
215+ local function makeIslandWidthCalculator (monitorResolution )
216+ local safeResolution = tonumber (monitorResolution ) or 0
217+ if safeResolution < 0 then
218+ safeResolution = 0
219+ end
220+
221+ if safeResolution <= 0 then
222+ return function (width )
223+ return 0
224+ end
225+ end
226+
227+ local maxHalf = math.floor (safeResolution / 2 )
228+
229+ return function (width )
230+ if maxHalf <= 0 then
231+ return 0
232+ end
233+
234+ local halfWidth = asPositiveInteger (width )
235+ if halfWidth == nil then
236+ return 0
237+ end
238+
239+ halfWidth = clamp (halfWidth , 1 , maxHalf )
240+ return halfWidth * 2
241+ end
242+ end
243+
244+ local function makeVisibleMarginCalculator (monitorResolution )
245+ local halfMarginCalculator = makeMarginCalculator (monitorResolution )
246+
247+ return function (visibleWidth )
248+ local width = tonumber (visibleWidth ) or 0
249+ if width <= 0 then
250+ return 0
251+ end
252+
253+ return halfMarginCalculator (math.floor (width / 2 ))
254+ end
255+ end
256+
215257return {
216258 calculateMargin = makeMarginCalculator ,
259+ calculateIslandWidth = makeIslandWidthCalculator ,
260+ calculateVisibleMargin = makeVisibleMarginCalculator ,
217261 resolveMonitorResolution = resolveMonitorResolution ,
218262}
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ return function(ctx, options)
2424 local getIcon = options .getIcon
2525
2626 local maxExpandWidth = ctx .asNumber (ctx .get (" islands." .. name .. " .maxExpandWidth" , " 130" ), 130 )
27+ local maxExpandWidthPx = ctx .calculateIslandWidth (maxExpandWidth )
2728 local expandHeight = ctx .asNumber (ctx .get (" islands." .. name .. " .expandHeight" , " 65" ), 65 )
2829 local cornerRadius = ctx .asNumber (ctx .get (" islands." .. name .. " .cornerRadius" , " 12" ), 12 )
2930 local expandMargin = ctx .calculateMargin (maxExpandWidth )
@@ -151,7 +152,7 @@ return function(ctx, options)
151152 })
152153 end )
153154
154- local barWidth = math.floor ((percent / 100 ) * (maxExpandWidth * 2 - 20 ) + 0.5 )
155+ local barWidth = math.floor ((percent / 100 ) * (maxExpandWidthPx - 20 ) + 0.5 )
155156 ctx .Sbar .animate (" tanh" , 15 , function ()
156157 barItem :set ({
157158 width = barWidth ,
Original file line number Diff line number Diff line change @@ -9,13 +9,14 @@ return function(ctx)
99 local resultSeparator = " |||"
1010
1111 local maxExpandWidth = ctx .asNumber (ctx .get (" islands.music.info.maxExpandWidth" , " 190" ), 190 )
12+ local maxExpandWidthPx = ctx .calculateIslandWidth (maxExpandWidth )
1213 local expandHeight = ctx .asNumber (ctx .get (" islands.music.info.expandHeight" , " 100" ), 100 )
1314 local cornerRad = ctx .asNumber (ctx .get (" islands.music.info.cornerRadius" , " 19" ), 19 )
1415 local expandMargin = ctx .calculateMargin (maxExpandWidth )
1516 local imageScale = 0.15
1617 local imageYOffset = - 10
1718 local artSlotWidth = 118
18- local textWidth = math.max (120 , maxExpandWidth * 2 - artSlotWidth - 28 )
19+ local textWidth = math.max (120 , maxExpandWidthPx - artSlotWidth - 28 )
1920 local contentYOffset = - 12
2021 local maxArtworkRetryAttempts = 4
2122 local artworkRetryDelaySeconds = 0.6
You can’t perform that action at this time.
0 commit comments