forked from nikitabobko/AeroSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's unbelievably stupid that I need a 3rd party library for such a simple task... Oh, Apple...
- Loading branch information
1 parent
125e9b9
commit 24e1f08
Showing
14 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import AppKit | ||
import Common | ||
import ISSoundAdditions | ||
|
||
struct VolumeCommand: Command { | ||
let args: VolumeCmdArgs | ||
|
||
func run(_ env: CmdEnv, _ io: CmdIo) -> Bool { | ||
check(Thread.current.isMainThread) | ||
switch args.action.val { | ||
case .up: | ||
Sound.output.increaseVolume(by: 0.0625, autoMuteUnmute: true) | ||
case .down: | ||
Sound.output.decreaseVolume(by: 0.0625, autoMuteUnmute: true) | ||
case .muteToggle: | ||
Sound.output.isMuted.toggle() | ||
case .muteOn: | ||
Sound.output.isMuted = true | ||
case .muteOff: | ||
Sound.output.isMuted = false | ||
case .set(let int): | ||
Sound.output.setVolume(Float(int) / 100, autoMuteUnmute: true) | ||
} | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public struct VolumeCmdArgs: CmdArgs { | ||
public let rawArgs: EquatableNoop<[String]> | ||
public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } | ||
public static let parser: CmdParser<Self> = cmdParser( | ||
kind: .volume, | ||
allowInConfig: true, | ||
help: volume_help_generated, | ||
options: [:], | ||
arguments: [newArgParser(\.action, parseVolumeAction, mandatoryArgPlaceholder: VolumeAction.argsUnion)] | ||
) | ||
|
||
public var windowId: UInt32? | ||
public var workspaceName: WorkspaceName? | ||
|
||
public var action: Lateinit<VolumeAction> = .uninitialized | ||
} | ||
|
||
public enum VolumeAction: Equatable { | ||
case up, down, muteToggle, muteOn, muteOff | ||
case set(Int) | ||
|
||
static let argsUnion: String = "(up|down|mute-toggle|mute-on|mute-off|set)" | ||
} | ||
|
||
func parseVolumeAction(arg: String, nextArgs: inout [String]) -> Parsed<VolumeAction> { | ||
switch arg { | ||
case "up": return .success(.up) | ||
case "down": return .success(.down) | ||
case "mute-toggle": return .success(.muteToggle) | ||
case "mute-off": return .success(.muteOff) | ||
case "mute-on": return .success(.muteOn) | ||
case "set": | ||
guard let arg = nextArgs.nextNonFlagOrNil() else { return .failure("set argument must be followed by <number>") } | ||
guard let int = Int(arg) else { return .failure("Can't parse number '\(arg)'") } | ||
if !(0 ... 100).contains(int) { return .failure("\(int) must be in range from 0 to 100") } | ||
return .success(.set(int)) | ||
default: | ||
return .failure("Unknown argument '\(arg)'. Possible values: \(VolumeAction.argsUnion)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
= aerospace-volume(1) | ||
include::util/man-attributes.adoc[] | ||
// tag::purpose[] | ||
:manpurpose: Manipulate volume | ||
// end::purpose[] | ||
:manname: aerospace-volume | ||
|
||
// =========================================================== Synopsis | ||
== Synopsis | ||
[verse] | ||
// tag::synopsis[] | ||
aerospace volume [-h|--help] (up|down) | ||
aerospace volume [-h|--help] (mute-toggle|mute-off|mute-on) | ||
aerospace volume [-h|--help] set <number> | ||
|
||
// end::synopsis[] | ||
|
||
// =========================================================== Description | ||
== Description | ||
|
||
// tag::body[] | ||
{manpurpose} | ||
|
||
// =========================================================== Options | ||
include::./util/conditional-options-header.adoc[] | ||
|
||
-h, --help:: Print help | ||
|
||
// =========================================================== Arguments | ||
include::./util/conditional-arguments-header.adoc[] | ||
|
||
(up|down):: Increase or decrease the volume | ||
(mute-toggle|mute-on|mute-off):: Toggle/On/Off mute | ||
set <number>:: Set volume to the exact value on scale from 0 to 100 | ||
|
||
// end::body[] | ||
|
||
// =========================================================== Footer | ||
include::util/man-footer.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 InerziaSoft - Massimo and Alessio Moiso. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |