From 43d56123cc2b4b7cf1d5e01020c1f5725593c40a Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 27 Oct 2024 07:09:18 +0100 Subject: [PATCH 1/2] console.lua: add scale_with_window script-opt If this is set to yes or auto and --osd-scale-by-window is true, console scales with the window height like everything else in mpv. Defaults to auto. --- .../console-scale-with-window.rst | 1 + DOCS/man/console.rst | 6 +++ player/lua/console.lua | 47 ++++++++++++++----- 3 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 DOCS/interface-changes/console-scale-with-window.rst diff --git a/DOCS/interface-changes/console-scale-with-window.rst b/DOCS/interface-changes/console-scale-with-window.rst new file mode 100644 index 0000000000000..5f2826bfe014c --- /dev/null +++ b/DOCS/interface-changes/console-scale-with-window.rst @@ -0,0 +1 @@ +add `console-scale_with_window` script-opt diff --git a/DOCS/man/console.rst b/DOCS/man/console.rst index 6fc11568fb6b2..b0c3989f44136 100644 --- a/DOCS/man/console.rst +++ b/DOCS/man/console.rst @@ -152,6 +152,12 @@ Configurable Options Set the font border size used for the REPL and the console. +``scale_with_window`` + Default: ``auto`` + + Whether to scale the console with the window height. Can be ``yes``, ``no``, + or ``auto``, which follows the value of ``--osd-scale-by-window``. + ``case_sensitive`` Default: no on Windows, yes on other platforms. diff --git a/player/lua/console.lua b/player/lua/console.lua index 8576364341f9e..a19aa1147090a 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -20,6 +20,7 @@ local opts = { font = "", font_size = 16, border_size = 1, + scale_with_window = "auto", case_sensitive = true, history_dedup = true, font_hw_ratio = 'auto', @@ -230,6 +231,30 @@ local function ass_escape(str) return mp.command_native({'escape-ass', str}) end +local function should_scale() + return opts.scale_with_window == "yes" or + (opts.scale_with_window == "auto" and mp.get_property_native("osd-scale-by-window")) +end + +local function get_scaled_osd_dimensions() + local w, h, aspect = mp.get_osd_size() + + if w == 0 then + return 0, 0 + end + + if should_scale() then + h = 720 + w = 720 * aspect + end + + local scale = mp.get_property_native('display-hidpi-scale') + w = w / scale + h = h / scale + + return w, h +end + local function calculate_max_log_lines() if not mp.get_property_native('vo-configured') or not mp.get_property_native('video-osd') then @@ -239,8 +264,7 @@ local function calculate_max_log_lines() select(2, mp.get_property('term-status-msg'):gsub('\\n', '')) end - return math.floor(mp.get_property_native('osd-height') - / mp.get_property_native('display-hidpi-scale', 1) + return math.floor(select(2, get_scaled_osd_dimensions()) * (1 - global_margins.t - global_margins.b) / opts.font_size -- Subtract 1 for the input line and 1 for the newline @@ -474,10 +498,7 @@ local function update() return end - local screenx, screeny = mp.get_osd_size() - local dpi_scale = mp.get_property_native('display-hidpi-scale', 1) - screenx = screenx / dpi_scale - screeny = screeny / dpi_scale + local screenx, screeny = get_scaled_osd_dimensions() local bottom_left_margin = 6 @@ -782,16 +803,16 @@ local function handle_enter() end local function determine_hovered_item() - local height = mp.get_property_native('osd-height') - if height == 0 then - return + local height = select(2, get_scaled_osd_dimensions()) + local y = mp.get_property_native('mouse-pos').y + if should_scale() then + y = y * 720 / mp.get_property_native('osd-height') end - - local y = mp.get_property_native('mouse-pos').y - global_margins.t * height + y = y - global_margins.t * height -- Calculate how many lines could be printed without decreasing them for -- the input line and OSC. - local max_lines = height / mp.get_property_native('display-hidpi-scale') - / opts.font_size + local max_lines = height / mp.get_property_native('display-hidpi-scale', 1) + / opts.font_size local clicked_line = math.floor(y / height * max_lines + .5) local offset = first_match_to_print - 1 From 6a053e36c5e9e30f0b30a3d4ff1eda60865acb74 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 27 Oct 2024 20:10:33 +0100 Subject: [PATCH 2/2] console.lua: increase the font and border size Make the console easier to read because the current default is too small. See for example https://github.com/mpv-player/mpv/discussions/14903#discussioncomment-10794701 or https://github.com/mpv-player/mpv/pull/15036#discussion_r1794178379 or https://github.com/mpv-player/mpv/pull/15145#issuecomment-2428762898 or https://github.com/mpv-player/mpv/pull/15031#issuecomment-2402289600. This also prevents libass from decreasing performance by printing many lines. --- DOCS/man/console.rst | 4 ++-- player/lua/console.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DOCS/man/console.rst b/DOCS/man/console.rst index b0c3989f44136..8f9e0e244b1ee 100644 --- a/DOCS/man/console.rst +++ b/DOCS/man/console.rst @@ -142,13 +142,13 @@ Configurable Options aligned correctly. ``font_size`` - Default: 16 + Default: 24 Set the font size used for the REPL and the console. This will be multiplied by ``display-hidpi-scale``. ``border_size`` - Default: 1 + Default: 1.5 Set the font border size used for the REPL and the console. diff --git a/player/lua/console.lua b/player/lua/console.lua index a19aa1147090a..68b58ebbe0dd9 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -18,8 +18,8 @@ local assdraw = require 'mp.assdraw' -- Default options local opts = { font = "", - font_size = 16, - border_size = 1, + font_size = 24, + border_size = 1.5, scale_with_window = "auto", case_sensitive = true, history_dedup = true,