Skip to content

Commit

Permalink
Close support subtitle visibility, #4235
Browse files Browse the repository at this point in the history
This commit will:
- Add a Hide Subtitles/Show Subtitles item to the Subtitles menu
- Add a Hide Second Subtitles/Show Second Subtitles item to the
  Subtitles menu
- Add buttons for controlling visibility of subtitles to the SUBTITLES
  tab of the Quick Settings Panel
- Add a key binding mapping v to cycle sub-visibility
- Add a key binding mapping Alt-v to cycle secondary-sub-visibility
- Add a new OSD messages Subtitles Hidden and Subtitles Visible
- Add a new OSD messages Second Subtitles Hidden and Second Subtitles
  Visible
- Add secondary-sub-visibility to watch-later-options
- Add logging of watch-later-options

These changes add a graphical user interface for the mpv features that
control subtitle visibility.
  • Loading branch information
low-batt authored and lhc70000 committed Jun 5, 2024
1 parent b5e29eb commit bc8f2fe
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 42 deletions.
2 changes: 2 additions & 0 deletions iina/AppData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@ extension Notification.Name {
static let iinaPlayerShutdown = Notification.Name("iinaPlayerShutdown")
static let iinaPlaySliderLoopKnobChanged = Notification.Name("iinaPlaySliderLoopKnobChanged")
static let iinaLogoutCompleted = Notification.Name("iinaLoggedOutOfSubtitleProvider")
static let iinaSecondSubVisibilityChanged = Notification.Name("iinaSecondSubVisibilityChanged")
static let iinaSubVisibilityChanged = Notification.Name("iinaSubVisibilityChanged")
}
1 change: 1 addition & 0 deletions iina/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"quicksetting.hwdec" = "Hardware Decoding";
"quicksetting.deinterlace" = "Deinterlace";
"quicksetting.hdr" = "HDR";
"quicksetting.hide" = "Hide";

// OSDMessage.swift
"osd.pause" = "Pause";
Expand Down
80 changes: 49 additions & 31 deletions iina/Base.lproj/QuickSettingViewController.xib

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions iina/MPVController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1233,17 +1233,15 @@ not applying FFmpeg 9599 workaround

case MPVOption.Subtitles.subVisibility:
if let visible = UnsafePointer<Bool>(OpaquePointer(property.data))?.pointee {
if player.info.isSubVisible != visible {
player.info.isSubVisible = visible
player.sendOSD(visible ? .subVisible : .subHidden)
DispatchQueue.main.async {
self.player.subVisibilityChanged(visible)
}
}

case MPVOption.Subtitles.secondarySubVisibility:
if let visible = UnsafePointer<Bool>(OpaquePointer(property.data))?.pointee {
if player.info.isSecondSubVisible != visible {
player.info.isSecondSubVisible = visible
player.sendOSD(visible ? .secondSubVisible : .secondSubHidden)
DispatchQueue.main.async {
self.player.secondSubVisibilityChanged(visible)
}
}

Expand Down
24 changes: 20 additions & 4 deletions iina/PlayerCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1130,12 +1130,14 @@ class PlayerCore: NSObject {
}
}

func toggleSubVisibility() {
mpv.setFlag(MPVOption.Subtitles.subVisibility, !info.isSubVisible)
func toggleSubVisibility(_ set: Bool? = nil) {
let newState = set ?? !info.isSubVisible
mpv.setFlag(MPVOption.Subtitles.subVisibility, newState)
}

func toggleSecondSubVisibility() {
mpv.setFlag(MPVOption.Subtitles.secondarySubVisibility, !info.isSecondSubVisible)
func toggleSecondSubVisibility(_ set: Bool? = nil) {
let newState = set ?? !info.isSecondSubVisible
mpv.setFlag(MPVOption.Subtitles.secondarySubVisibility, newState)
}

func loadExternalSubFile(_ url: URL, delay: Bool = false) {
Expand Down Expand Up @@ -1821,13 +1823,27 @@ class PlayerCore: NSObject {
postNotification(.iinaSIDChanged)
}

func secondSubVisibilityChanged(_ visible: Bool) {
guard info.isSecondSubVisible != visible else { return }
info.isSecondSubVisible = visible
sendOSD(visible ? .secondSubVisible : .secondSubHidden)
postNotification(.iinaSecondSubVisibilityChanged)
}

func sidChanged() {
guard !isShuttingDown, !isShutdown else { return }
info.sid = Int(mpv.getInt(MPVOption.TrackSelection.sid))
postNotification(.iinaSIDChanged)
sendOSD(.track(info.currentTrack(.sub) ?? .noneSubTrack))
}

func subVisibilityChanged(_ visible: Bool) {
guard info.isSubVisible != visible else { return }
info.isSubVisible = visible
sendOSD(visible ? .subVisible : .subHidden)
postNotification(.iinaSubVisibilityChanged)
}

func trackListChanged() {
// No need to process track list changes if playback is being stopped. Must not process track
// list changes if mpv is terminating as accessing mpv once shutdown has been initiated can
Expand Down
16 changes: 15 additions & 1 deletion iina/QuickSettingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
@IBOutlet weak var audioDelaySliderConstraint: NSLayoutConstraint!
@IBOutlet weak var customAudioDelayTextField: NSTextField!


@IBOutlet weak var hideSwitch: NSSwitch!
@IBOutlet weak var secHideSwitch: NSSwitch!
@IBOutlet weak var subLoadSementedControl: NSSegmentedControl!
@IBOutlet weak var subDelaySlider: NSSlider!
@IBOutlet weak var subDelaySliderIndicator: NSTextField!
Expand Down Expand Up @@ -223,6 +224,8 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
self.subTableView.reloadData()
self.secSubTableView.reloadData()
}
observe(.iinaSecondSubVisibilityChanged) { [unowned self] _ in secHideSwitch.state = player.info.isSecondSubVisible ? .on : .off }
observe(.iinaSubVisibilityChanged) { [unowned self] _ in hideSwitch.state = player.info.isSubVisible ? .on : .off }
}

// MARK: - Right to Left Constraints
Expand Down Expand Up @@ -384,6 +387,9 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
}

private func updateSubTabControl() {
hideSwitch.state = player.info.isSubVisible ? .on : .off
secHideSwitch.state = player.info.isSecondSubVisible ? .on : .off

if let currSub = player.info.currentTrack(.sub) {
// FIXME: CollorWells cannot be disable?
let enableTextSettings = !(currSub.isAssSub || currSub.isImageSub)
Expand Down Expand Up @@ -826,6 +832,14 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab

// MARK: Sub tab

@IBAction func hideSubAction(_ sender: NSSwitch) {
player.toggleSubVisibility()
}

@IBAction func hideSecSubAction(_ sender: NSSwitch) {
player.toggleSecondSubVisibility()
}

@IBAction func loadExternalSubAction(_ sender: NSSegmentedControl) {
if sender.selectedSegment == 0 {
let currentDir = player.info.currentURL?.deletingLastPathComponent()
Expand Down
1 change: 1 addition & 0 deletions iina/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"quicksetting.hwdec" = "Hardware Decoding";
"quicksetting.deinterlace" = "Deinterlace";
"quicksetting.hdr" = "HDR";
"quicksetting.hide" = "Hide";

// OSDMessage.swift
"osd.pause" = "Pause";
Expand Down

0 comments on commit bc8f2fe

Please sign in to comment.