Skip to content

Commit e8a53f2

Browse files
ScorpionDevthe0neyouseek
authored andcommitted
Changed mute command from '0 speaker volume' to 'true' mute (0x8D) (MonitorControl#96)
* Changed mute command from '0 speaker volume' to 'true' mute (0x8D) * swiftformat changes Swiftformat does this by itself so I figured might as well commit it
1 parent 75432c0 commit e8a53f2

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

MonitorControl/Display.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Display {
2121
self.name = name
2222
self.isEnabled = isEnabled
2323
self.ddc = DDC(for: identifier)
24+
self.isMuted = self.getValue(for: .audioMuteScreenBlank) == 1
2425
}
2526

2627
// On some displays, the display's OSD overlaps the macOS OSD,
@@ -35,22 +36,32 @@ class Display {
3536
}
3637
}
3738

38-
func mute() {
39+
func mute(forceVolume: Int? = nil) {
3940
var value = 0
40-
if self.isMuted {
41-
value = self.getValue(for: DDC.Command.audioSpeakerVolume)
41+
42+
if self.isMuted, forceVolume == nil || forceVolume! > 0 {
43+
value = forceVolume ?? self.getValue(for: .audioSpeakerVolume)
44+
self.saveValue(value, for: .audioSpeakerVolume)
45+
4246
self.isMuted = false
43-
} else {
47+
} else if !self.isMuted, forceVolume == nil || forceVolume == 0 {
4448
self.isMuted = true
4549
}
4650

4751
DispatchQueue.global(qos: .userInitiated).async {
48-
guard self.ddc?.write(command: .audioSpeakerVolume, value: UInt16(value), errorRecoveryWaitTime: self.hideOsd ? 0 : nil) == true else {
52+
let muteValue = self.isMuted ? 1 : 2
53+
guard self.ddc?.write(command: .audioMuteScreenBlank, value: UInt16(muteValue), errorRecoveryWaitTime: self.hideOsd ? 0 : nil) == true else {
54+
self.setVolume(to: value)
4955
return
5056
}
5157

52-
self.hideDisplayOsd()
53-
self.showOsd(command: .audioSpeakerVolume, value: value)
58+
if forceVolume == nil || forceVolume == 0 {
59+
self.hideDisplayOsd()
60+
self.showOsd(command: .audioSpeakerVolume, value: value)
61+
self.playVolumeChangedSound()
62+
}
63+
64+
self.saveValue(muteValue, for: .audioMuteScreenBlank)
5465
}
5566

5667
if let slider = volumeSliderHandler?.slider {
@@ -59,8 +70,11 @@ class Display {
5970
}
6071

6172
func setVolume(to value: Int) {
62-
if value > 0 {
63-
self.isMuted = false
73+
if value > 0, self.isMuted {
74+
self.mute(forceVolume: value)
75+
} else if value == 0 {
76+
self.mute(forceVolume: 0)
77+
return
6478
}
6579

6680
DispatchQueue.global(qos: .userInitiated).async {

MonitorControl/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.5.2</string>
2121
<key>CFBundleVersion</key>
22-
<string>515</string>
22+
<string>516</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

MonitorControlHelper/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.5.2</string>
2121
<key>CFBundleVersion</key>
22-
<string>515</string>
22+
<string>516</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSBackgroundOnly</key>

0 commit comments

Comments
 (0)