Skip to content

Commit

Permalink
update & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hooke007 committed Oct 11, 2022
1 parent 925934c commit 2b90581
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 362 deletions.
13 changes: 11 additions & 2 deletions portable_config/script-opts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@
# 外置脚本 #
############

##⇘⇘fontconfig 自动加载字体

script-opts-append = auto_load_fonts-compatible_mode=no # 是否启用兼容模式,默认 no
script-opts-append = auto_load_fonts-compatible_dir=~~/.fonts
# 兼容模式目录,默认 主设置目录的".fonts"文件夹



##⇘⇘图形化上下文菜单 [组]
##滤镜/着色器条目示例(这部分的实现很粗糙,可能存在语法冲突):
## **B是显示在按钮左侧的文本
Expand Down Expand Up @@ -499,11 +507,12 @@
script-opts-append = uosc-font_scale=1 # 字体缩放率,默认 1
script-opts-append = uosc-font_bold=no # 仅使用字体的Bold字重,默认 no
script-opts-append = uosc-text_border=1.2 # 控件元素的边框,默认 1.2
script-opts-append = uosc-pause_on_click_shorter_than=0 # 鼠标左键点击画面的时间短于此值时才允许触发暂停,以毫秒为单位。0 即禁用,默认 0
script-opts-append = uosc-click_threshold=0 # 鼠标左键点击画面的时间短于此值时才执行命令(根据 --input-doubleclick-time 过滤双击),以毫秒为单位。0 即禁用,默认 0
script-opts-append = uosc-click_command=cycle pause; script-binding uosc/flash-pause-indicator
script-opts-append = uosc-flash_duration=1000 # 由 flash-{element} 命令使用的一闪持续时间,以毫秒为单位,默认 1000
script-opts-append = uosc-proximity_in=40 # 元素完全淡入/淡出的距离,以像素为单位,默认 40 120
script-opts-append = uosc-proximity_out=120
script-opts-append = uosc-foreground=FFFFFF # # 元素的颜色代码,形式为 RRGGBB ,示例即默认值
script-opts-append = uosc-foreground=FFFFFF # 元素的颜色代码,形式为 RRGGBB ,示例即默认值
script-opts-append = uosc-foreground_text=000000
script-opts-append = uosc-background=000000
script-opts-append = uosc-background_text=FFFFFF
Expand Down
5 changes: 3 additions & 2 deletions portable_config/script-opts/uosc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ font_scale=1
font_bold=no
# 控件元素的边框,默认 1.2
text_border=1.2
# 鼠标左键点击画面的时间短于此值时才允许触发暂停,以毫秒为单位。0 即禁用,默认 0
pause_on_click_shorter_than=0
# 鼠标左键点击画面的时间短于此值时才执行命令(根据 --input-doubleclick-time 过滤双击),以毫秒为单位。0 即禁用,默认 0
click_threshold=0
click_command=cycle pause; script-binding uosc/flash-pause-indicator
# 由 flash-{element} 命令使用的一闪持续时间,以毫秒为单位,默认 1000
flash_duration=1000
# 元素完全淡入/淡出的距离,以像素为单位,默认 40 120
Expand Down
112 changes: 72 additions & 40 deletions portable_config/scripts/uosc.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
--[[
SOURCE_ https://github.com/tomasklaen/uosc/commit/93bb49edceb8412f62b1303e769f32651bbb8203
SOURCE_ https://github.com/tomasklaen/uosc/commit/2fb5ff69a81e12f565f603cc0f29983235fce2ff
极简主义设计驱动的多功能界面脚本,兼容 thumbfast 新缩略图引擎
]]--

local uosc_version = '4.2.0'
local uosc_version = '4.3.0'

local assdraw = require('mp.assdraw')
local opt = require('mp.options')
Expand Down Expand Up @@ -211,7 +211,8 @@ local defaults = {
font_scale = 1,
font_bold = false,
text_border = 1.2,
pause_on_click_shorter_than = 0,
click_threshold = 0,
click_command = 'cycle pause; script-binding uosc/flash-pause-indicator',
flash_duration = 1000,
proximity_in = 40,
proximity_out = 120,
Expand Down Expand Up @@ -311,11 +312,16 @@ local config = {
local by_id = {}

for line in io.lines(input_conf_path) do
local key, command, title = string.match(line, '%s*([%S]+)%s+(.-)%s+#!%s*(.-)%s*$')
if not key then
key, command, title = string.match(line, '%s*([%S]+)%s+(.-)%s+#menu:%s*(.-)%s*$')
local key, command, comment = string.match(line, '%s*([%S]+)%s+(.-)%s+#%s*(.-)%s*$')
local title = ''
if comment then
local comments = split(comment, '#')
local titles = itable_filter(comments, function(v, i) return v:match('^!') or v:match('^menu:') end)
if titles and #titles > 0 then
title = titles[1]:match('^!%s*(.*)%s*') or titles[1]:match('^menu:%s*(.*)%s*')
end
end
if key then
if title ~= '' then
local is_dummy = key:sub(1, 1) == '#'
local submenu_id = ''
local target_menu = main_menu
Expand Down Expand Up @@ -459,6 +465,7 @@ local state = {
hidpi_scale = 1,
}
local thumbnail = {width = 0, height = 0, disabled = false}
local external = {} -- Properties set by external scripts

--[[ HELPERS ]]

Expand Down Expand Up @@ -2551,12 +2558,14 @@ function CycleButton:init(id, props)
self.current_state_index = 1
self.on_click = function()
local new_state = self.states[self.current_state_index + 1] or self.states[1]
if is_state_prop then
local new_value = new_state.value
if itable_index_of({'yes', 'no'}, new_state.value) then new_value = new_value == 'yes' end
local new_value = new_state.value
if self.owner then
mp.commandv('script-message-to', self.owner, 'set', self.prop, new_value)
elseif is_state_prop then
if itable_index_of({'yes', 'no'}, new_value) then new_value = new_value == 'yes' end
set_state(self.prop, new_value)
else
mp.set_property(self.prop, new_state.value)
mp.set_property(self.prop, new_value)
end
end

Expand All @@ -2569,9 +2578,14 @@ function CycleButton:init(id, props)
request_render()
end

-- Built in state props
if is_state_prop then
local prop_parts = split(self.prop, '@')
if #prop_parts == 2 then -- External prop with a script owner
self.prop, self.owner = prop_parts[1], prop_parts[2]
self['on_external_prop_' .. self.prop] = function(_, value) self.handle_change(self.prop, value) end
self.handle_change(self.prop, external[self.prop])
elseif is_state_prop then -- uosc's state props
self['on_prop_' .. self.prop] = function(self, value) self.handle_change(self.prop, value) end
self.handle_change(self.prop, state[self.prop])
else
mp.observe_property(self.prop, 'string', self.handle_change)
end
Expand Down Expand Up @@ -2810,7 +2824,9 @@ end

---@param fast? boolean
function Timeline:set_from_cursor(fast)
mp.commandv('seek', self:get_time_at_x(cursor.x), fast and 'absolute+keyframes' or 'absolute+exact')
if state.time and state.duration then
mp.commandv('seek', self:get_time_at_x(cursor.x), fast and 'absolute+keyframes' or 'absolute+exact')
end
end
function Timeline:clear_thumbnail() mp.commandv('script-message-to', 'thumbfast', 'clear') end

Expand All @@ -2824,7 +2840,10 @@ function Timeline:on_prop_border() self:update_dimensions() end
function Timeline:on_prop_fullormaxed() self:update_dimensions() end
function Timeline:on_display() self:update_dimensions() end
function Timeline:on_mouse_leave() self:clear_thumbnail() end
function Timeline:on_global_mbtn_left_up() self.pressed = false end
function Timeline:on_global_mbtn_left_up()
self.pressed = false
self:clear_thumbnail()
end
function Timeline:on_global_mouse_leave()
self.pressed = false
self:clear_thumbnail()
Expand Down Expand Up @@ -3038,7 +3057,7 @@ function Timeline:render()
local thumb_y = round(tooltip_anchor.ay * scale_y - thumb_y_margin - thumb_height)
local ax, ay = (thumb_x - border) / scale_x, (thumb_y - border) / scale_y
local bx, by = (thumb_x + thumb_width + border) / scale_x, (thumb_y + thumb_height + border) / scale_y
ass:rect(ax, ay, bx, by, {color = bg, border = 1, border_color = fg, border_opacity = 0.1, radius = 2})
ass:rect(ax, ay, bx, by, {color = bg, border = 1, border_color = fg, border_opacity = 0.08, radius = 2})
mp.commandv('script-message-to', 'thumbfast', 'thumb', hovered_seconds, thumb_x, thumb_y)
tooltip_anchor.ax, tooltip_anchor.bx, tooltip_anchor.ay = ax, bx, ay
end
Expand Down Expand Up @@ -3222,12 +3241,12 @@ function TopBar:render()
local font_size = self.font_size * 0.8
local height = font_size * 1.5
local text = '' .. state.current_chapter.index .. ': ' .. state.current_chapter.title
local ax, by = title_ax + padding / 2, title_ay + height
local by = title_ay + height
local bx = math.min(max_bx, title_ax + text_width_estimate(text, font_size) + padding * 2)
ass:rect(ax, title_ay, bx, by, {
ass:rect(title_ax, title_ay, bx, by, {
color = bg, opacity = visibility * options.top_bar_title_opacity, radius = 2,
})
ass:txt(ax + padding, title_ay + height / 2, 4, '{\\i1}' .. text .. '{\\i0}', {
ass:txt(title_ax + padding, title_ay + height / 2, 4, '{\\i1}' .. text .. '{\\i0}', {
size = font_size, wrap = 2, color = bgt, border = 1, border_color = bg, opacity = visibility * 0.8,
clip = string.format('\\clip(%d, %d, %d, %d)', title_ax, title_ay, bx, by),
})
Expand Down Expand Up @@ -3434,7 +3453,9 @@ function Controls:register_badge_updater(badge, element)
return count
end
else
if prop:sub(1, 1) == '@' then prop, is_external_prop = prop:sub(2), true end
local parts = split(prop, '@')
-- Support both new `prop@owner` and old `@prop` syntaxes
if #parts > 1 then prop, is_external_prop = parts[1] ~= '' and parts[1] or parts[2], true end
serializer = function(value) return value and (type(value) == 'table' and #value or tostring(value)) or nil end
end

Expand Down Expand Up @@ -4233,21 +4254,29 @@ function observe_display_fps(name, fps)
end
end

--[[ HOOKS]]
function select_current_chapter()
local current_chapter
if state.time and state.chapters then
_, current_chapter = itable_find(state.chapters, function(c) return state.time >= c.time end, true)
end
set_state('current_chapter', current_chapter)
end

--[[ HOOKS ]]

-- Mouse movement key binds
if options.pause_on_click_shorter_than > 0 then
-- Cycles pause when click is shorter than `options.pause_on_click_shorter_than`
-- Click detection
if options.click_threshold > 0 then
-- Executes custom command for clicks shorter than `options.click_threshold`
-- while filtering out double clicks.
local duration_seconds = options.pause_on_click_shorter_than / 1000
local duration_seconds = options.click_threshold / 1000
local last_click = 0
mp.add_key_binding('mbtn_left', 'uosc_mouse', function(tab)
if tab.event == 'up' then
local delta = mp.get_time() - last_click
-- in windowed mode the up event comes shortly after the down event, ignore
if delta > 0.01 and delta < duration_seconds then
last_click = 0
mp.command('cycle pause')
mp.command(options.click_command)
end
else
last_click = mp.get_time()
Expand All @@ -4256,7 +4285,7 @@ if options.pause_on_click_shorter_than > 0 then
mp.observe_property('mouse-pos', 'native', function(_, mouse)
if mouse.hover and mp.get_time() - last_click < duration_seconds then
last_click = 0
mp.command('cycle pause')
mp.command(options.click_command)
end
end)
end
Expand All @@ -4270,7 +4299,7 @@ end)
mp.observe_property('osc', 'bool', function(_, value) if value == true then mp.set_property('osc', 'no') end end)
function update_title(title_template)
if title_template:sub(-6) == ' - mpv' then title_template = title_template:sub(1, -7) end
set_state('title', mp.command_native({'expand-text', title_template}))
set_state('title', ass_escape(mp.command_native({'expand-text', title_template})))
end
mp.register_event('file-loaded', function()
set_state('path', normalize_path(mp.get_property_native('path')))
Expand All @@ -4283,10 +4312,17 @@ mp.register_event('end-file', function(event)
handle_file_end()
end
end)
mp.observe_property('title', 'string', function(_, title)
-- Don't change title if there is currently none
if state.title then update_title(title) end
end)
do
local hot_keywords = {'time', 'percent'}
local timer = mp.add_periodic_timer(0.9, function() update_title(mp.get_property_native('title')) end)
timer:kill()
mp.observe_property('title', 'string', function(_, title)
update_title(title)
-- Enable periodic updates for templates with hot variables
local is_hot = itable_find(hot_keywords, function(var) return string.find(title or '', var) ~= nil end)
if is_hot then timer:resume() else timer:kill() end
end)
end
mp.observe_property('playback-time', 'number', create_state_setter('time', function()
-- Create a file-end event that triggers right before file ends
file_end_timer:kill()
Expand All @@ -4302,13 +4338,7 @@ mp.observe_property('playback-time', 'number', create_state_setter('time', funct
end

update_human_times()

-- Select current chapter
local current_chapter
if state.time and state.chapters then
_, current_chapter = itable_find(state.chapters, function(c) return state.time >= c.time end, true)
end
set_state('current_chapter', current_chapter)
select_current_chapter()
end))
mp.observe_property('duration', 'number', create_state_setter('duration', update_human_times))
mp.observe_property('speed', 'number', create_state_setter('speed', update_human_times))
Expand Down Expand Up @@ -4342,6 +4372,7 @@ mp.observe_property('chapter-list', 'native', function(_, chapters)
set_state('chapters', chapters)
set_state('chapter_ranges', chapter_ranges)
set_state('has_chapter', #chapters > 0)
select_current_chapter()
Elements:trigger('dispositions')
end)
mp.observe_property('border', 'bool', create_state_setter('border'))
Expand Down Expand Up @@ -4791,7 +4822,8 @@ mp.register_script_message('thumbfast-info', function(json)
end
end)
mp.register_script_message('set', function(name, value)
Elements:trigger('external_prop_' .. name, utils.parse_json(value))
external[name] = value
Elements:trigger('external_prop_' .. name, value)
end)
mp.register_script_message('toggle-elements', function(elements) Elements:toggle(split(elements, ' *, *')) end)
mp.register_script_message('flash-elements', function(elements) Elements:flash(split(elements, ' *, *')) end)
Loading

0 comments on commit 2b90581

Please sign in to comment.