Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions iina/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class MainWindowController: PlayerWindowController {
/** Views that will show/hide when cursor moving in/out the window. */
var fadeableViews: [NSView] = []

var keepControlBar: Bool = false

// Left and right arrow buttons

/** The maximum pressure recorded when clicking on the arrow buttons. */
Expand Down Expand Up @@ -1823,26 +1825,29 @@ class MainWindowController: PlayerWindowController {
guard pipStatus == .notInPIP || animationState == .hidden else {
return
}
// Don't hide UI when auto hide control bar is disabled
guard force || Preference.bool(for: .enableControlBarAutoHide) else { return }
let viewsToHide: [NSView]

if force || Preference.bool(for: .enableControlBarAutoHide) || currentControlBar == nil {
self.keepControlBar = false
viewsToHide = fadeableViews
} else {
self.keepControlBar = true
viewsToHide = fadeableViews.filter { $0 != currentControlBar }
}

animationState = .willHide
player.refreshSyncUITimer()
fadeableViews.forEach { (v) in
v.isHidden = false
}
viewsToHide.forEach { $0.isHidden = false }
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = UIAnimationDuration
fadeableViews.forEach { (v) in
v.animator().alphaValue = 0
}
viewsToHide.forEach { $0.animator().alphaValue = 0 }
if !self.fsState.isFullscreen {
titleTextField?.animator().alphaValue = 0
}
}) {
// if no interrupt then hide animation
if self.animationState == .willHide {
self.fadeableViews.forEach { (v) in
viewsToHide.forEach { (v) in
if let btn = v as? NSButton, self.standardWindowButtons.contains(btn) {
v.alphaValue = 1e-100
} else {
Expand All @@ -1854,22 +1859,30 @@ class MainWindowController: PlayerWindowController {
}
}

func showUI() {
func showUI(onlyControlBar: Bool = false) {
if player.disableUI { return }
animationState = .willShow
fadeableViews.forEach { (v) in
v.isHidden = false

let viewsToShow: [NSView]
if onlyControlBar {
if let cb = currentControlBar {
viewsToShow = [cb]
} else {
return
}
} else {
viewsToShow = fadeableViews
}

animationState = .willShow
viewsToShow.forEach { $0.isHidden = false }
// The OSC may not have been updated while it was hidden to avoid wasting energy. Make sure it
// is up to date.
player.refreshSyncUITimer()
standardWindowButtons.forEach { $0.isEnabled = true }
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = UIAnimationDuration
fadeableViews.forEach { (v) in
v.animator().alphaValue = 1
}
if !fsState.isFullscreen {
viewsToShow.forEach { $0.animator().alphaValue = 1 }
if !fsState.isFullscreen && !onlyControlBar {
titleTextField?.animator().alphaValue = 1
}
}) {
Expand Down Expand Up @@ -2780,7 +2793,7 @@ class MainWindowController: PlayerWindowController {
func isUITimerNeeded() -> Bool {
let isShowingFadeableViews = animationState == .shown || animationState == .willShow
let isShowingOSD = osdAnimationState == .shown || osdAnimationState == .willShow
return isShowingFadeableViews || isShowingOSD
return isShowingFadeableViews || isShowingOSD || self.keepControlBar
}

override func updatePlayTime(withDuration duration: Bool, andProgressBar: Bool) {
Expand Down
4 changes: 2 additions & 2 deletions iina/PlayerWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ class PlayerWindowController: NSWindowController, NSWindowDelegate {
// For auto-hiding to work, need to update the timer.
player.mainWindow.updateTimer()
} else {
// The user wants the UI to be always visible, need to show it explicitly.
player.mainWindow.showUI()
// User wants the Control Bar to always be visible, need to show it explicitly.
player.mainWindow.showUI(onlyControlBar: true)
}
}

Expand Down