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

Showing the changes to player/lua/console.lua (1 of 3 files). Show all

Unified · Split

player/lua/console.lua+34−13
@@ -20,6 +20,7 @@ local opts = { · 19 unmodified lines
20 font = "",20 font = "",
21 font_size = 16,21 font_size = 16,
22 border_size = 1,22 border_size = 1,
23 scale_with_window = "auto",
23 case_sensitive = true,24 case_sensitive = true,
24 history_dedup = true,25 history_dedup = true,
25 font_hw_ratio = 'auto',26 font_hw_ratio = 'auto',
@@ -230,6 +231,30 @@ local function ass_escape(str) · 204 unmodified lines
230 return mp.command_native({'escape-ass', str})231 return mp.command_native({'escape-ass', str})
231end232end
232 233
234local 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"))
237end
238
239local 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
256end
257
233local function calculate_max_log_lines()258local function calculate_max_log_lines()
234 if not mp.get_property_native('vo-configured')259 if not mp.get_property_native('vo-configured')
235 or not mp.get_property_native('video-osd') then260 or not mp.get_property_native('video-osd') then
@@ -239,8 +264,7 @@ local function calculate_max_log_lines() · 3 unmodified lines
239 select(2, mp.get_property('term-status-msg'):gsub('\\n', ''))264 select(2, mp.get_property('term-status-msg'):gsub('\\n', ''))
240 end265 end
241 266
242 return math.floor(mp.get_property_native('osd-height')267 return math.floor(select(2, get_scaled_osd_dimensions())
243 / mp.get_property_native('display-hidpi-scale', 1)
244 * (1 - global_margins.t - global_margins.b)268 * (1 - global_margins.t - global_margins.b)
245 / opts.font_size269 / opts.font_size
246 -- Subtract 1 for the input line and 1 for the newline270 -- Subtract 1 for the input line and 1 for the newline
@@ -476,10 +500,7 @@ local function update() · 229 unmodified lines
476 return500 return
477 end501 end
478 502
479 local screenx, screeny = mp.get_osd_size()503 local screenx, screeny = get_scaled_osd_dimensions()
480 local dpi_scale = mp.get_property_native('display-hidpi-scale', 1)
481 screenx = screenx / dpi_scale
482 screeny = screeny / dpi_scale
483 504
484 local bottom_left_margin = 6505 local bottom_left_margin = 6
485 506
@@ -784,16 +805,16 @@ local function handle_enter() · 298 unmodified lines
784end805end
785 806
786local function determine_hovered_item()807local function determine_hovered_item()
787 local height = mp.get_property_native('osd-height')808 local height = select(2, get_scaled_osd_dimensions())
788 if height == 0 then809 local y = mp.get_property_native('mouse-pos').y
789 return810 if should_scale() then
811 y = y * 720 / mp.get_property_native('osd-height')
790 end812 end
791 813 y = y - global_margins.t * height
792 local y = mp.get_property_native('mouse-pos').y - global_margins.t * height
793 -- Calculate how many lines could be printed without decreasing them for814 -- Calculate how many lines could be printed without decreasing them for
794 -- the input line and OSC.815 -- the input line and OSC.
795 local max_lines = height / mp.get_property_native('display-hidpi-scale')816 local max_lines = height / mp.get_property_native('display-hidpi-scale', 1)
796 / opts.font_size817 / opts.font_size
797 local clicked_line = math.floor(y / height * max_lines + .5)818 local clicked_line = math.floor(y / height * max_lines + .5)
798 819
799 local offset = first_match_to_print - 1820 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