Skip to content

Commit

Permalink
mac/touchbar: optimise time item update
Browse files Browse the repository at this point in the history
  • Loading branch information
Akemi committed Mar 18, 2024
1 parent d7cc5cd commit 9f68214
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions osdep/mac/touch_bar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ extension TouchBar {

class TouchBar: NSTouchBar, NSTouchBarDelegate {
var configs: [NSTouchBarItem.Identifier:Config] = [:]
var isPaused: Bool = false
var position: Double = 0
var duration: Double = 0
var isPaused: Bool = false { didSet { updatePlayButton() } }
var position: Double = 0 { didSet { updateTouchBarTimeItems() } }
var duration: Double = 0 { didSet { updateTouchBarTimeItems() } }
var rate: Double = 0

override init() {
Expand Down Expand Up @@ -304,14 +304,11 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate {
let newPosition = max(LibmpvHelper.mpvDoubleToDouble(property.data) ?? 0, 0)
if Int((floor(newPosition) - floor(position)) / rate) != 0 {
position = newPosition
updateTouchBarTimeItems()
}
case "duration" where property.format == MPV_FORMAT_DOUBLE:
duration = LibmpvHelper.mpvDoubleToDouble(property.data) ?? 0
updateTouchBarTimeItems()
case "pause" where property.format == MPV_FORMAT_FLAG:
isPaused = LibmpvHelper.mpvFlagToBool(property.data) ?? false
updatePlayButton()
case "speed" where property.format == MPV_FORMAT_DOUBLE:
rate = LibmpvHelper.mpvDoubleToDouble(property.data) ?? 1
default:
Expand Down

0 comments on commit 9f68214

Please sign in to comment.