Skip to content

Commit c83fde1

Browse files
authored
Show audio muted OSD image when audio volume value is 0 (MonitorControl#276)
1 parent 9e47ccf commit c83fde1

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

MonitorControl/Model/Display.swift

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import DDC
1010
import Foundation
1111
import os.log
1212

13+
private enum OSDImage: Int64 {
14+
case brightness = 1
15+
case audioSpeaker = 3
16+
case audioSpeakerMuted = 4
17+
}
18+
1319
class Display {
1420
internal let identifier: CGDirectDisplayID
1521
internal let name: String
@@ -48,37 +54,35 @@ class Display {
4854
return
4955
}
5056

51-
var osdImage: Int64!
57+
var osdImage: OSDImage
5258
switch command {
53-
case .brightness:
54-
osdImage = 1 // Brightness Image
5559
case .audioSpeakerVolume:
56-
osdImage = 3 // Speaker image
60+
osdImage = value > 0 ? .audioSpeaker : .audioSpeakerMuted
5761
case .audioMuteScreenBlank:
58-
osdImage = 4 // Mute image
62+
osdImage = .audioSpeakerMuted
5963
default:
60-
osdImage = 1
64+
osdImage = .brightness
6165
}
6266

67+
let filledChiclets: Int
68+
let totalChiclets: Int
69+
6370
if roundChiclet {
6471
let osdChiclet = OSDUtils.chiclet(fromValue: Float(value), maxValue: Float(maxValue))
65-
let filledChiclets = round(osdChiclet)
66-
67-
manager.showImage(osdImage,
68-
onDisplayID: self.identifier,
69-
priority: 0x1F4,
70-
msecUntilFade: 1000,
71-
filledChiclets: UInt32(filledChiclets),
72-
totalChiclets: UInt32(16),
73-
locked: false)
72+
73+
filledChiclets = Int(round(osdChiclet))
74+
totalChiclets = 16
7475
} else {
75-
manager.showImage(osdImage,
76-
onDisplayID: self.identifier,
77-
priority: 0x1F4,
78-
msecUntilFade: 1000,
79-
filledChiclets: UInt32(value),
80-
totalChiclets: UInt32(maxValue),
81-
locked: false)
76+
filledChiclets = value
77+
totalChiclets = maxValue
8278
}
79+
80+
manager.showImage(osdImage.rawValue,
81+
onDisplayID: self.identifier,
82+
priority: 0x1F4,
83+
msecUntilFade: 1000,
84+
filledChiclets: UInt32(filledChiclets),
85+
totalChiclets: UInt32(totalChiclets),
86+
locked: false)
8387
}
8488
}

0 commit comments

Comments
 (0)