Skip to content

Commit a73afc0

Browse files
committed
Constrain thumbnail within the window
Don't let the thumbnail go out of view near left or right edge. Before, the thumbnail might be partially hidden if the window was particularly small. Doesn't happen much on the built-in OSCs, topbar and bottombar were the worst (albeit barely) offenders.
1 parent fb64f9b commit a73afc0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/options.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ local thumbnailer_options = {
6464
-- Alpha: 0 - fully opaque, 255 - transparent
6565
background_alpha = 80,
6666

67+
-- Keep thumbnail on the screen near left or right side
68+
constrain_to_screen = true,
69+
6770
-- The maximum dimensions of the thumbnails (pixels)
6871
thumbnail_width = 200,
6972
thumbnail_height = 200,

src/patched_osc.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ function display_thumbnail(pos, value, ass)
116116
target_position = duration * (value / 100)
117117

118118
local msx, msy = get_virt_scale_factor()
119+
local osd_w, osd_h = mp.get_osd_size()
120+
119121
local thumb_size = Thumbnailer.state.thumbnail_size
120122
local thumb_path, thumb_index, closest_index = Thumbnailer:get_thumbnail_path(target_position)
121123

@@ -147,6 +149,18 @@ function display_thumbnail(pos, value, ass)
147149
local ass_h = thumb_size.h * msy
148150
local y_offset = get_thumbnail_y_offset(thumb_size, 1)
149151

152+
-- Constrain thumbnail display to window
153+
-- (ie. don't let it go off-screen left/right)
154+
if thumbnailer_options.constrain_to_screen and osd_w > (ass_w + pad.l + pad.r)/msx then
155+
local padded_left = (pad.l + (ass_w / 2))
156+
local padded_right = (pad.r + (ass_w / 2))
157+
if pos.x - padded_left < 0 then
158+
pos.x = padded_left
159+
elseif pos.x + padded_right > osd_w*msx then
160+
pos.x = osd_w*msx - padded_right
161+
end
162+
end
163+
150164
local text_h = 30 * msy
151165
local bg_h = ass_h + (display_progress and text_h or 0)
152166
local bg_left = pos.x - ass_w/2

0 commit comments

Comments
 (0)