Skip to content

Commit

Permalink
配置更新
Browse files Browse the repository at this point in the history
  • Loading branch information
dyphire committed Feb 6, 2024
1 parent 93e9dd3 commit 5ae3a2b
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 118 deletions.
21 changes: 13 additions & 8 deletions archive/scripts/open_dialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,23 @@ end

-- open for clipboard
local function import_clipboard(type)
local clip = get_clipboard()
local meta = utils.file_info(clip)
local clip = get_clipboard():gsub("^[\'\"]", ""):gsub("[\'\"]$", "")
if clip ~= '' then
if clip:find('^%a[%w.+-]-://') then
mp.commandv('loadfile', clip)
elseif meta.is_dir then
open_folder(clip)
elseif meta.is_file then
open_files(clip, type, 1, true)
else
mp.osd_message('Clipboard is not a valid URL or file path')
msg.warn('Clipboard is not a valid URL or file path')
local meta = utils.file_info(clip)
if not meta then
mp.osd_message('Clipboard is not a valid URL or file path')
msg.warn('Clipboard is not a valid URL or file path')
elseif meta.is_dir then
open_folder(clip)
elseif meta.is_file then
open_files(clip, type, 1, true)
else
mp.osd_message('Clipboard is not a valid URL or file path')
msg.warn('Clipboard is not a valid URL or file path')
end
end
else
mp.osd_message('Clipboard is empty')
Expand Down
3 changes: 2 additions & 1 deletion scripts/subtitle-lines.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
-- subtitle-lines 1.0.0 - 2023-Oct-22
-- subtitle-lines 1.1.0 - 2024-Feb-02
-- https://github.com/christoph-heinrich/mpv-subtitle-lines
--
-- List and search subtitle lines of the selected subtitle track.
--
-- Usage:
-- add bindings to input.conf:
-- Ctrl+f script-binding subtitle_lines/list_subtitles
-- Ctrl+F script-binding subtitle_lines/list_secondary_subtitles

local mp = require 'mp'
local utils = require 'mp.utils'
Expand Down
4 changes: 2 additions & 2 deletions scripts/uosc/elements/Button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Button:init(id, props)
end

function Button:on_coordinates() self.font_size = round((self.by - self.ay) * 0.7) end
function Button:handle_cursor_down()
function Button:handle_cursor_click()
-- We delay the callback to next tick, otherwise we are risking race
-- conditions as we are in the middle of event dispatching.
-- For example, handler might add a menu to the end of the element stack, and that
Expand All @@ -34,7 +34,7 @@ end
function Button:render()
local visibility = self:get_visibility()
if visibility <= 0 then return end
cursor:zone('primary_down', self, function() self:handle_cursor_down() end)
cursor:zone('primary_click', self, function() self:handle_cursor_click() end)

local ass = assdraw.ass_new()
local is_hover = self.proximity_raw == 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/uosc/elements/Speed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function Speed:render()
self:handle_cursor_down()
cursor:once('primary_up', function() self:handle_cursor_up() end)
end)
cursor:zone('secondary_down', self, function() mp.set_property_native('speed', 1) end)
cursor:zone('secondary_click', self, function() mp.set_property_native('speed', 1) end)
cursor:zone('wheel_down', self, function() self:handle_wheel_down() end)
cursor:zone('wheel_up', self, function() self:handle_wheel_up() end)

Expand Down
43 changes: 33 additions & 10 deletions scripts/uosc/elements/TopBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function TopBarButton:init(id, props)
self.command = props.command
end

function TopBarButton:handle_cursor_down()
function TopBarButton:handle_click()
mp.command(type(self.command) == 'function' and self.command() or self.command)
end

Expand All @@ -29,7 +29,7 @@ function TopBarButton:render()
if self.proximity_raw == 0 then
ass:rect(self.ax, self.ay, self.bx, self.by, {color = self.background, opacity = visibility})
end
cursor:zone('primary_down', self, function() self:handle_cursor_down() end)
cursor:zone('primary_click', self, function() self:handle_click() end)

local width, height = self.bx - self.ax, self.by - self.ay
local icon_size = math.min(width, height) * 0.5
Expand Down Expand Up @@ -199,6 +199,7 @@ function TopBar:render()
if state.title or state.has_playlist then
local bg_margin = math.floor((self.size - self.font_size) / 4)
local padding = self.font_size / 2
local spacing = 1
local title_ax = self.ax + bg_margin
local title_ay = self.ay + bg_margin
local max_bx = self.title_bx - self.spacing
Expand Down Expand Up @@ -226,7 +227,7 @@ function TopBar:render()
title_ax = rect.bx + bg_margin

-- Click action
cursor:zone('primary_down', rect, function() mp.command('script-binding uosc/playlist') end)
cursor:zone('primary_click', rect, function() mp.command('script-binding uosc/playlist') end)
end

-- Skip rendering titles if there's not enough horizontal space
Expand All @@ -248,14 +249,14 @@ function TopBar:render()
local title_rect = {ax = title_ax, ay = title_ay, bx = bx, by = by}

if options.top_bar_alt_title_place == 'toggle' then
cursor:zone('primary_down', title_rect, function() self:toggle_title() end)
cursor:zone('primary_click', title_rect, function() self:toggle_title() end)
end

ass:rect(title_rect.ax, title_rect.ay, title_rect.bx, title_rect.by, {
color = bg, opacity = visibility * config.opacity.title, radius = state.radius,
})
ass:txt(title_ax + padding, self.ay + (self.size / 2), 4, main_title, opts)
title_ay = by + 1
title_ay = by + spacing
end

-- Alt title
Expand All @@ -277,14 +278,19 @@ function TopBar:render()
color = bg, opacity = visibility * config.opacity.title, radius = state.radius,
})
ass:txt(title_ax + padding, title_ay + height / 2, 4, self.alt_title, opts)
title_ay = by + 1
title_ay = by + spacing
end

-- Subtitle: current chapter
-- Current chapter
if state.current_chapter then
local padding_half = round(padding / 2)
local font_size = self.font_size * 0.8
local height = font_size * 1.3
local text = '' .. state.current_chapter.index .. ': ' .. state.current_chapter.title
local next_chapter = state.chapters[state.current_chapter.index + 1]
local chapter_end = next_chapter and next_chapter.time or state.duration or 0
local remaining_time = (state.time and state.time or 0) - chapter_end
local remaining_human = format_time(remaining_time, math.abs(remaining_time))
local opts = {
size = font_size,
italic = true,
Expand All @@ -294,21 +300,38 @@ function TopBar:render()
border_color = bg,
opacity = visibility * 0.8,
}
local remaining_width = timestamp_width(remaining_human, opts)
local remaining_box_width = remaining_width + padding_half * 2

-- Title
local rect = {
ax = title_ax,
ay = title_ay,
bx = round(math.min(max_bx, title_ax + text_width(text, opts) + padding * 2)),
bx = round(math.min(
max_bx - remaining_box_width - spacing,
title_ax + text_width(text, opts) + padding * 2
)),
by = title_ay + height,
}
opts.clip = string.format('\\clip(%d, %d, %d, %d)', title_ax, title_ay, rect.bx, rect.by)
ass:rect(rect.ax, rect.ay, rect.bx, rect.by, {
color = bg, opacity = visibility * config.opacity.title, radius = state.radius,
})
ass:txt(rect.ax + padding, rect.ay + height / 2, 4, text, opts)
title_ay = rect.by + 1

-- Click action
cursor:zone('primary_down', rect, function() mp.command('script-binding uosc/chapters') end)
cursor:zone('primary_click', rect, function() mp.command('script-binding uosc/chapters') end)

-- Time
rect.ax = rect.bx + spacing
rect.bx = rect.ax + remaining_box_width
opts.clip = nil
ass:rect(rect.ax, rect.ay, rect.bx, rect.by, {
color = bg, opacity = visibility * config.opacity.title, radius = state.radius,
})
ass:txt(rect.ax + padding_half, rect.ay + height / 2, 4, remaining_human, opts)

title_ay = rect.by + spacing
end
end
self.title_by = title_ay - 1
Expand Down
2 changes: 1 addition & 1 deletion scripts/uosc/elements/Updater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function Updater:render()
local y = round(button_rect.ay + (button_rect.by - button_rect.ay) / 2)
ass:icon(x, y, icon_size * 0.8, 'close', {color = bg})

cursor:zone('primary_down', button_rect, function() self:destroy() end)
cursor:zone('primary_click', button_rect, function() self:destroy() end)
end

return ass
Expand Down
4 changes: 2 additions & 2 deletions scripts/uosc/elements/Volume.lua
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ function Volume:render()
if visibility <= 0 then return end

-- Reset volume on secondary click
cursor:zone('secondary_down', self, function()
cursor:zone('secondary_click', self, function()
mp.set_property_native('mute', false)
mp.set_property_native('volume', 100)
end)

-- Mute button
local mute_rect = {ax = self.ax, ay = self.mute_ay, bx = self.bx, by = self.by}
cursor:zone('primary_down', mute_rect, function() mp.commandv('cycle', 'mute') end)
cursor:zone('primary_click', mute_rect, function() mp.commandv('cycle', 'mute') end)
local ass = assdraw.ass_new()
local width_half = (mute_rect.bx - mute_rect.ax) / 2
local height_half = (mute_rect.by - mute_rect.ay) / 2
Expand Down
Loading

0 comments on commit 5ae3a2b

Please sign in to comment.