| @@ -20,6 +20,7 @@ local opts = { · 19 unmodified lines |
| 20 | 20 | font = "", |
| 21 | 21 | font_size = 16, |
| 22 | 22 | border_size = 1, |
| 23 | + scale_with_window = "auto", |
| 23 | 24 | case_sensitive = true, |
| 24 | 25 | history_dedup = true, |
| 25 | 26 | font_hw_ratio = 'auto', |
| @@ -230,6 +231,30 @@ local function ass_escape(str) · 204 unmodified lines |
| 230 | 231 | return mp.command_native({'escape-ass', str}) |
| 231 | 232 | end |
| 232 | 233 | |
| 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 | + |
| 233 | 258 | local function calculate_max_log_lines() |
| 234 | 259 | if not mp.get_property_native('vo-configured') |
| 235 | 260 | or not mp.get_property_native('video-osd') then |
| @@ -239,8 +264,7 @@ local function calculate_max_log_lines() · 3 unmodified lines |
| 239 | 264 | select(2, mp.get_property('term-status-msg'):gsub('\\n', '')) |
| 240 | 265 | end |
| 241 | 266 | |
| 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()) |
| 244 | 268 | * (1 - global_margins.t - global_margins.b) |
| 245 | 269 | / opts.font_size |
| 246 | 270 | -- Subtract 1 for the input line and 1 for the newline |
| @@ -476,10 +500,7 @@ local function update() · 229 unmodified lines |
| 476 | 500 | return |
| 477 | 501 | end |
| 478 | 502 | |
| 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() |
| 483 | 504 | |
| 484 | 505 | local bottom_left_margin = 6 |
| 485 | 506 | |
| @@ -784,16 +805,16 @@ local function handle_enter() · 298 unmodified lines |
| 784 | 805 | end |
| 785 | 806 | |
| 786 | 807 | 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') |
| 790 | 812 | end |
| 791 | | − |
| 792 | | − local y = mp.get_property_native('mouse-pos').y - global_margins.t * height |
| 813 | + y = y - global_margins.t * height |
| 793 | 814 | -- Calculate how many lines could be printed without decreasing them for |
| 794 | 815 | -- 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 |
| 797 | 818 | local clicked_line = math.floor(y / height * max_lines + .5) |
| 798 | 819 | |
| 799 | 820 | local offset = first_match_to_print - 1 |