summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2022-09-02 22:24:36 +0200
committersfan5 <sfan5@live.de>2022-10-28 13:04:32 +0200
commitfd91776207cd6b8d82e09765e0c6e2ec5e23d881 (patch)
treeac801eedcb44f28090cebb88ea52b3373b3fd721 /player/lua
parentadb556bf15e9b09afce6c9cb0a0911c53cf27feb (diff)
downloadmpv-fd91776207cd6b8d82e09765e0c6e2ec5e23d881.tar.bz2
mpv-fd91776207cd6b8d82e09765e0c6e2ec5e23d881.tar.xz
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.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/console.lua24
1 files changed, 17 insertions, 7 deletions
diff --git a/player/lua/console.lua b/player/lua/console.lua
index f9397e06f5..3377380e8d 100644
--- a/player/lua/console.lua
+++ b/player/lua/console.lua
@@ -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)