Skip to content

Commit 23c3d5d

Browse files
authored
Merge pull request #332 from Samillion/dev_timecodes_hitbox
fix: improve time codes hitbox and narrow window visibility
2 parents acf1ae5 + b99392d commit 23c3d5d

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

docs/USER_OPTS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Useful when adjusting font size or type, this will help you change the affected
199199
| time_codes_centered_height | 57 | time codes height position with portrait window |
200200
| tooltip_height_offset | 2 | tooltip height position offset |
201201
| tooltip_left_offset | 5 | if tooltip contains many characters, it is moved to the left by offset |
202-
| portrait_window_trigger | 930 | portrait window width trigger to move some elements |
202+
| portrait_window_trigger | 1000 | portrait window width trigger to move some elements |
203203
| hide_volume_bar_trigger | 1150 | hide volume bar trigger window width |
204204
| notitle_osc_h_offset | 25 | osc height offset if title above seekbar is disabled |
205205
| nochapter_osc_h_offset | 10 | osc height offset if chapter title is disabled or doesn't exist |

modernz.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ tooltip_height_offset=2
292292
# if tooltip contains many characters, it is moved to the left by offset
293293
tooltip_left_offset=5
294294
# portrait window width trigger to move some elements
295-
portrait_window_trigger=930
295+
portrait_window_trigger=1000
296296
# hide volume bar trigger window width
297297
hide_volume_bar_trigger=1150
298298
# osc height offset if title above seekbar is disabled

modernz.lua

+33-13
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ local user_opts = {
188188
time_codes_centered_height = 57, -- time codes height position with portrait window
189189
tooltip_height_offset = 2, -- tooltip height position offset
190190
tooltip_left_offset = 5, -- if tooltip contains many characters, it is moved to the left by offset
191-
portrait_window_trigger = 930, -- portrait window width trigger to move some elements
191+
portrait_window_trigger = 1000, -- portrait window width trigger to move some elements
192192
hide_volume_bar_trigger = 1150, -- hide volume bar trigger window width
193193
notitle_osc_h_offset = 25, -- osc height offset if title above seekbar is disabled
194194
nochapter_osc_h_offset = 10, -- osc height offset if chapter title is disabled or doesn't exist
@@ -506,6 +506,8 @@ local state = {
506506
sliderpos = 0,
507507
touchingprogressbar = false, -- if the mouse is touching the progress bar
508508
initialborder = mp.get_property("border"),
509+
playtime_hour_force_init = false, -- used to force request_init() once
510+
playtime_nohour_force_init = false, -- used to force request_init() once
509511
playingWhilstSeeking = false,
510512
playingWhilstSeekingWaitingForEnd = false,
511513
persistentprogresstoggle = user_opts.persistentprogress,
@@ -1828,22 +1830,30 @@ layouts["modern"] = function ()
18281830

18291831
-- Time codes
18301832
local remsec = mp.get_property_number("playtime-remaining", 0)
1831-
local possec = mp.get_property_number("playback-time", 0)
18321833
local dur = mp.get_property_number("duration", 0)
1833-
local show_hours = possec >= 3600 or user_opts.time_format ~= "dynamic"
1834+
local show_hours = mp.get_property_number("playback-time", 0) >= 3600 or user_opts.time_format ~= "dynamic"
18341835
local show_remhours = (state.tc_right_rem and remsec >= 3600) or (not state.tc_right_rem and dur >= 3600) or user_opts.time_format ~= "dynamic"
1835-
local tc_w_offset = (state.tc_ms and 60 or 0) + (show_hours and 20 or 0) + (show_remhours and 20 or 0)
18361836
local auto_hide_volbar = (audio_track and user_opts.volume_control) and osc_param.playresx < (user_opts.hide_volume_bar_trigger - outeroffset)
1837-
local narrow_vid_tc_y = osc_param.playresx < (user_opts.portrait_window_trigger - outeroffset - (playlist_button and 0 or 100) - (subtitle_track and 0 or 100) - (audio_track and 0 or 100))
18381837
local time_codes_x = 275
18391838
- (auto_hide_volbar and 75 or 0) -- window width with audio track and elements
18401839
- (audio_track and not user_opts.volume_control and 115 or 0) -- audio track with no elements
18411840
- (not audio_track and 160 or 0) -- no audio track or elements
18421841
- (subtitle_track and 0 or 45)
18431842
- (playlist_button and 0 or 45)
1844-
1843+
local time_codes_width = 80
1844+
+ (state.tc_ms and 50 or 0)
1845+
+ (state.tc_right_rem and 15 or 0)
1846+
+ (show_hours and 20 or 0)
1847+
+ (show_remhours and 20 or 0)
1848+
local narrow_win = osc_param.playresx < (
1849+
user_opts.portrait_window_trigger
1850+
- outeroffset
1851+
- (playlist_button and 0 or 100)
1852+
- (subtitle_track and 0 or 100)
1853+
- (audio_track and 0 or 100)
1854+
)
18451855
lo = add_layout("time_codes")
1846-
lo.geometry = {x = (narrow_vid_tc_y and refX or time_codes_x), y = refY - (narrow_vid_tc_y and user_opts.time_codes_centered_height or user_opts.time_codes_height), an = (narrow_vid_tc_y and 5 or 4), w = 90 + tc_w_offset, h = 15}
1856+
lo.geometry = {x = (narrow_win and refX or time_codes_x), y = refY - (narrow_win and user_opts.time_codes_centered_height or user_opts.time_codes_height), an = (narrow_win and 5 or 4), w = time_codes_width, h = user_opts.time_font_size}
18471857
lo.style = osc_styles.time
18481858

18491859
-- Fullscreen/Info/Pin/Screenshot/Loop/Speed
@@ -2786,6 +2796,21 @@ local function osc_init()
27862796
ne.content = function()
27872797
local playback_time = mp.get_property_number("playback-time", 0)
27882798

2799+
-- force request_init() once to update time codes width hitbox
2800+
-- run once when less than hour, once again if hour or more
2801+
-- since request_init() is expensive, this is a measure to call it when needed only
2802+
if user_opts.time_format ~= "fixed" and playback_time then
2803+
if playback_time >= 3600 and not state.playtime_hour_force_init then
2804+
request_init()
2805+
state.playtime_hour_force_init = true
2806+
state.playtime_nohour_force_init = false
2807+
elseif playback_time < 3600 and not state.playtime_nohour_force_init then
2808+
request_init()
2809+
state.playtime_hour_force_init = false
2810+
state.playtime_nohour_force_init = true
2811+
end
2812+
end
2813+
27892814
local duration = mp.get_property_number("duration", 0)
27902815
if duration <= 0 then return "--:--" end
27912816

@@ -3316,10 +3341,6 @@ mp.observe_property("chapter-list", "native", function(_, list)
33163341
update_duration_watch()
33173342
request_init()
33183343
end)
3319-
3320-
mp.observe_property("playback-time", "native", function(_, time)
3321-
request_tick()
3322-
end)
33233344
mp.observe_property("seeking", "native", function(_, seeking)
33243345
if user_opts.seek_resets_hidetimeout then
33253346
reset_timeout()
@@ -3330,7 +3351,6 @@ mp.observe_property("seeking", "native", function(_, seeking)
33303351
state.new_file_flag = false
33313352
end
33323353
end)
3333-
33343354
mp.observe_property("fullscreen", "bool", function(_, val)
33353355
state.fullscreen = val
33363356
state.marginsREQ = true
@@ -3353,10 +3373,10 @@ mp.observe_property("idle-active", "bool", function(_, val)
33533373
state.idle = val
33543374
request_tick()
33553375
end)
3356-
33573376
mp.observe_property("display-fps", "number", set_tick_delay)
33583377
mp.observe_property("demuxer-cache-state", "native", cache_state)
33593378
mp.observe_property("vo-configured", "bool", request_tick)
3379+
mp.observe_property("playback-time", "number", request_tick)
33603380
mp.observe_property("osd-dimensions", "native", function()
33613381
-- (we could use the value instead of re-querying it all the time, but then
33623382
-- we might have to worry about property update ordering)

0 commit comments

Comments
 (0)