Skip to content

Commit

Permalink
Various Enhancements (MonitorControl#66)
Browse files Browse the repository at this point in the history
* Update to Swift 5.0 and run `swiftformat`.

* Refactor `MediaKeyTap` start/restart.

* Remove useless comments.

* Reorder files.

* Add German translation.

* Switch to Carthage.

* Use `DDC.swift`.

* Add `NSScreen` extension.

* Simplify menu layout.

* Hide the display’s built-in OSD.

* Fix launch at login helper.

* Fix `quitClicked` connection.

* Refactor build phases.

* Use `os_log` instead of `print`.

* Use more specific check for `minReplyDelay`.

* Add whitelist.
  • Loading branch information
reitermarkus authored and the0neyouseek committed May 7, 2019
1 parent 830878e commit 6e91c71
Show file tree
Hide file tree
Showing 45 changed files with 1,275 additions and 1,367 deletions.
70 changes: 2 additions & 68 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,69 +1,3 @@
Carthage

# Created by https://www.gitignore.io/api/macos,xcode,cocoapods

### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
# - Also handy if you have a large number of dependant pods
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE
Pods/

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
*.xcuserdatad
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0
5 changes: 5 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--indent 2
--ranges no-space
--self insert
--exponentcase lowercase
--exclude Carthage
3 changes: 2 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ disabled_rules:
- line_length
- function_body_length
- identifier_name
- trailing_comma
excluded:
- Pods
- Carthage
type_body_length: 500
file_length: 500
4 changes: 4 additions & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github "the0neyouseek/MediaKeyTap" "master"
github "reitermarkus/DDC.swift" "master"
github "rnine/AMCoreAudio"
github "shpakovski/MASPreferences"
4 changes: 4 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github "reitermarkus/DDC.swift" "9a6a249b4b222e67b1393eecd7ac9eb35dff34a9"
github "rnine/AMCoreAudio" "3.2.1"
github "shpakovski/MASPreferences" "1.3"
github "the0neyouseek/MediaKeyTap" "abfe09f53ccabb1aa14a0f4ab99cfb8812f41919"
15 changes: 15 additions & 0 deletions Extensions/CGDirectDisplayID+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Cocoa

extension CGDirectDisplayID {
public var vendorNumber: UInt32? {
return CGDisplayVendorNumber(self)
}

public var modelNumber: UInt32? {
return CGDisplayModelNumber(self)
}

public var serialNumber: UInt32? {
return CGDisplaySerialNumber(self)
}
}
33 changes: 33 additions & 0 deletions Extensions/EDID+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import DDC

extension EDID {
public func displayName() -> String? {
let descriptors = [self.descriptors.0, self.descriptors.1, self.descriptors.2, self.descriptors.3]

for descriptor in descriptors {
switch descriptor {
case let .displayName(name):
return name
default:
continue
}
}

return nil
}

public func serialNumber() -> String? {
let descriptors = [self.descriptors.0, self.descriptors.1, self.descriptors.2, self.descriptors.3]

for descriptor in descriptors {
switch descriptor {
case let .serialNumber(number):
return number
default:
continue
}
}

return String(self.serialNumber)
}
}
70 changes: 70 additions & 0 deletions Extensions/NSScreen+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Cocoa

extension NSScreen {
public var displayID: CGDirectDisplayID {
return (self.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID)!
}

public var vendorNumber: UInt32? {
switch self.displayID.vendorNumber {
case 0xFFFF_FFFF:
return nil
case let vendorNumber:
return vendorNumber
}
}

public var modelNumber: UInt32? {
switch self.displayID.modelNumber {
case 0xFFFF_FFFF:
return nil
case let modelNumber:
return modelNumber
}
}

public var serialNumber: UInt32? {
switch self.displayID.serialNumber {
case 0x0000_0000:
return nil
case let serialNumber:
return serialNumber
}
}

public var displayName: String? {
var servicePortIterator = io_iterator_t()

let status = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IODisplayConnect"), &servicePortIterator)
guard status == KERN_SUCCESS else {
return nil
}

defer {
assert(IOObjectRelease(servicePortIterator) == KERN_SUCCESS)
}

while case let object = IOIteratorNext(servicePortIterator), object != 0 {
let dict = (IODisplayCreateInfoDictionary(object, UInt32(kIODisplayOnlyPreferredName)).takeRetainedValue() as NSDictionary as? [String: AnyObject])!

if dict[kDisplayVendorID] as? UInt32 == self.vendorNumber,
dict[kDisplayProductID] as? UInt32 == self.modelNumber,
dict[kDisplaySerialNumber] as? UInt32 == self.serialNumber {
if let productName = dict["DisplayProductName"] as? [String: String],
let firstKey = Array(productName.keys).first {
return productName[firstKey]!
}
}
}

return nil
}

public var isBuiltin: Bool {
return CGDisplayIsBuiltin(self.displayID) != 0
}

public static func getByDisplayID(displayID: CGDirectDisplayID) -> NSScreen? {
return NSScreen.screens.first { $0.displayID == displayID }
}
}
Loading

0 comments on commit 6e91c71

Please sign in to comment.