1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 10:02:17 +00:00

console: respect the top margin shared script property

Console already respected the bottom margin to not overlap with the
bottom bar from the OSC, but it would still overlap with the window
decorations from the OSC.

Now everything is clipped above the top margin and no superfluous lines
are drawn.
This commit is contained in:
Christoph Heinrich 2022-09-02 22:24:36 +02:00 committed by sfan5
parent adb556bf15
commit fd91776207

View File

@ -64,7 +64,8 @@ local history = {}
local history_pos = 1
local log_buffer = {}
local key_bindings = {}
local global_margin_y = 0
local global_margin_top = 0
local global_margin_bottom = 0
local update_timer = nil
update_timer = mp.add_periodic_timer(0.05, function()
@ -84,9 +85,11 @@ utils.shared_script_property_observe("osc-margins", function(_, val)
for v in string.gmatch(val, "[^,]+") do
vals[#vals + 1] = tonumber(v)
end
global_margin_y = vals[4] -- bottom
global_margin_top = vals[3] -- top
global_margin_bottom = vals[4] -- bottom
else
global_margin_y = 0
global_margin_top = 0
global_margin_bottom = 0
end
update()
end)
@ -143,12 +146,16 @@ function update()
return
end
local coordinate_top = math.floor(global_margin_top * screeny + 0.5)
local clipping_coordinates = '0,' .. coordinate_top .. ',' ..
screenx .. ',' .. screeny
local ass = assdraw.ass_new()
local style = '{\\r' ..
'\\1a&H00&\\3a&H00&\\4a&H99&' ..
'\\1c&Heeeeee&\\3c&H111111&\\4c&H000000&' ..
'\\fn' .. opts.font .. '\\fs' .. opts.font_size ..
'\\bord1\\xshad0\\yshad1\\fsp0\\q1}'
'\\bord1\\xshad0\\yshad1\\fsp0\\q1' ..
'\\clip(' .. clipping_coordinates .. ')}'
-- Create the cursor glyph as an ASS drawing. ASS will draw the cursor
-- inline with the surrounding text, but it sets the advance to the width
-- of the drawing. So the cursor doesn't affect layout too much, make it as
@ -168,7 +175,10 @@ function update()
-- messages.
local log_ass = ''
local log_messages = #log_buffer
local log_max_lines = math.ceil(screeny / opts.font_size)
local screeny_factor = (1 - global_margin_top - global_margin_bottom)
-- subtract 1.5 to account for the input line
local log_max_lines = screeny * screeny_factor / opts.font_size - 1.5
log_max_lines = math.ceil(log_max_lines)
if log_max_lines < log_messages then
log_messages = log_max_lines
end
@ -178,7 +188,7 @@ function update()
ass:new_event()
ass:an(1)
ass:pos(2, screeny - 2 - global_margin_y * screeny)
ass:pos(2, screeny - 2 - global_margin_bottom * screeny)
ass:append(log_ass .. '\\N')
ass:append(style .. '> ' .. before_cur)
ass:append(cglyph)
@ -188,7 +198,7 @@ function update()
-- cursor appear in front of the text.
ass:new_event()
ass:an(1)
ass:pos(2, screeny - 2 - global_margin_y * screeny)
ass:pos(2, screeny - 2 - global_margin_bottom * screeny)
ass:append(style .. '{\\alpha&HFF&}> ' .. before_cur)
ass:append(cglyph)
ass:append(style .. '{\\alpha&HFF&}' .. after_cur)