History

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.

Guido Cella committed 2 years ago

Commit e00d8dc1 parent fbf86953 files · +41 −13Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/console-scale-with-window.rst +1 −0
  2. DOCS/man/console.rst +6 −0
  3. player/lua/console.lua +34 −13
DOCS/interface-changes/console-scale-with-window.rst+1−0
@@ -0,0 +1 @@
1+add `console-scale_with_window` script-opt
DOCS/man/console.rst+6−0
@@ -164,6 +164,12 @@ Configurable Options · 163 unmodified lines
164164
165165 Set the font border size used for the REPL and the console.
166166
167+``scale_with_window``
168+ Default: ``auto``
169+
170+ Whether to scale the console with the window height. Can be ``yes``, ``no``,
171+ or ``auto``, which follows the value of ``--osd-scale-by-window``.
172+
167173 ``case_sensitive``
168174 Default: no on Windows, yes on other platforms.
169175
player/lua/console.lua+34−13
@@ -20,6 +20,7 @@ local opts = { · 19 unmodified lines
2020 font = "",
2121 font_size = 16,
2222 border_size = 1,
23+ scale_with_window = "auto",
2324 case_sensitive = true,
2425 history_dedup = true,
2526 font_hw_ratio = 'auto',
@@ -230,6 +231,30 @@ local function ass_escape(str) · 204 unmodified lines
230231 return mp.command_native({'escape-ass', str})
231232 end
232233
234+local function should_scale()
235+ return opts.scale_with_window == "yes" or
236+ (opts.scale_with_window == "auto" and mp.get_property_native("osd-scale-by-window"))
237+end
238+
239+local function get_scaled_osd_dimensions()
240+ local w, h, aspect = mp.get_osd_size()
241+
242+ if w == 0 then
243+ return 0, 0
244+ end
245+
246+ if should_scale() then
247+ h = 720
248+ w = 720 * aspect
249+ end
250+
251+ local scale = mp.get_property_native('display-hidpi-scale')
252+ w = w / scale
253+ h = h / scale
254+
255+ return w, h
256+end
257+
233258 local function calculate_max_log_lines()
234259 if not mp.get_property_native('vo-configured')
235260 or not mp.get_property_native('video-osd') then
@@ -239,8 +264,7 @@ local function calculate_max_log_lines() · 3 unmodified lines
239264 select(2, mp.get_property('term-status-msg'):gsub('\\n', ''))
240265 end
241266
242− return math.floor(mp.get_property_native('osd-height')
243− / mp.get_property_native('display-hidpi-scale', 1)
267+ return math.floor(select(2, get_scaled_osd_dimensions())
244268 * (1 - global_margins.t - global_margins.b)
245269 / opts.font_size
246270 -- Subtract 1 for the input line and 1 for the newline
@@ -476,10 +500,7 @@ local function update() · 229 unmodified lines
476500 return
477501 end
478502
479− local screenx, screeny = mp.get_osd_size()
480− local dpi_scale = mp.get_property_native('display-hidpi-scale', 1)
481− screenx = screenx / dpi_scale
482− screeny = screeny / dpi_scale
503+ local screenx, screeny = get_scaled_osd_dimensions()
483504
484505 local bottom_left_margin = 6
485506
@@ -784,16 +805,16 @@ local function handle_enter() · 298 unmodified lines
784805 end
785806
786807 local function determine_hovered_item()
787− local height = mp.get_property_native('osd-height')
788− if height == 0 then
789− return
808+ local height = select(2, get_scaled_osd_dimensions())
809+ local y = mp.get_property_native('mouse-pos').y
810+ if should_scale() then
811+ y = y * 720 / mp.get_property_native('osd-height')
790812 end
791−
792− local y = mp.get_property_native('mouse-pos').y - global_margins.t * height
813+ y = y - global_margins.t * height
793814 -- Calculate how many lines could be printed without decreasing them for
794815 -- the input line and OSC.
795− local max_lines = height / mp.get_property_native('display-hidpi-scale')
796− / opts.font_size
816+ local max_lines = height / mp.get_property_native('display-hidpi-scale', 1)
817+ / opts.font_size
797818 local clicked_line = math.floor(y / height * max_lines + .5)
798819
799820 local offset = first_match_to_print - 1

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t