🔧 Preferences WIP

- All prefs pane GUI are done #2
- Now to build the functions behind...

Signed-off-by: Guillaume Broder <iamnotheoneyouseek@gmail.com>
This commit is contained in:
Guillaume Broder 2018-01-07 19:31:31 +01:00
parent 68afdda765
commit e45fb6e705
No known key found for this signature in database
GPG key ID: 66FB02D063D9E08F
24 changed files with 954 additions and 25 deletions

View file

@ -3,7 +3,5 @@ disabled_rules:
- function_body_length
excluded:
- Pods
type_body_length:
- warning: 500
file_length:
- warning: 500
type_body_length: 500
file_length: 500

View file

@ -14,6 +14,11 @@
56754EB41D9A4016007BCDC5 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 56754EB21D9A4016007BCDC5 /* MainMenu.xib */; };
9A19D3B73485870616B6D4E0 /* Pods_MonitorControl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 398F482D5C8816B29F16AAEB /* Pods_MonitorControl.framework */; };
F03A8DF21FFBAA6F0034DC27 /* Display.swift in Sources */ = {isa = PBXBuildFile; fileRef = F03A8DF11FFBAA6F0034DC27 /* Display.swift */; };
F0445D3820023E710025AE82 /* MainPrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0445D3720023E710025AE82 /* MainPrefsViewController.swift */; };
F0445D3D200254FA0025AE82 /* KeysPrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0445D3B200254FA0025AE82 /* KeysPrefsViewController.swift */; };
F0445D40200259C10025AE82 /* DisplayPrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0445D3F200259C10025AE82 /* DisplayPrefsViewController.swift */; };
F0445D41200282E60025AE82 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F0445D43200282E60025AE82 /* Main.storyboard */; };
F0445D4D200294AB0025AE82 /* ButtonCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0445D4C200294AB0025AE82 /* ButtonCellView.swift */; };
F091C9B31F6EA6110096FD65 /* SliderHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F091C9B21F6EA6110096FD65 /* SliderHandler.swift */; };
F091C9B81F6EA79B0096FD65 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = F091C9B71F6EA79B0096FD65 /* Utils.swift */; };
F0A987E81F77B40E009B603D /* OSD.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F0A987D61F77B290009B603D /* OSD.framework */; };
@ -36,13 +41,20 @@
56754EB31D9A4016007BCDC5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
56754EB51D9A4016007BCDC5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F03A8DF11FFBAA6F0034DC27 /* Display.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Display.swift; sourceTree = "<group>"; };
F0445D3720023E710025AE82 /* MainPrefsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainPrefsViewController.swift; sourceTree = "<group>"; };
F0445D3B200254FA0025AE82 /* KeysPrefsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeysPrefsViewController.swift; sourceTree = "<group>"; };
F0445D3F200259C10025AE82 /* DisplayPrefsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayPrefsViewController.swift; sourceTree = "<group>"; };
F0445D42200282E60025AE82 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
F0445D45200282EB0025AE82 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Main.strings; sourceTree = "<group>"; };
F0445D47200282F80025AE82 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
F0445D49200285690025AE82 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/MainMenu.strings; sourceTree = "<group>"; };
F0445D4B2002856C0025AE82 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/MainMenu.strings; sourceTree = "<group>"; };
F0445D4C200294AB0025AE82 /* ButtonCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonCellView.swift; sourceTree = "<group>"; };
F091C9B21F6EA6110096FD65 /* SliderHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderHandler.swift; sourceTree = "<group>"; };
F091C9B71F6EA79B0096FD65 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
F091C9B91F6EB43B0096FD65 /* fr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = fr; path = fr.lproj/MainMenu.strings; sourceTree = "<group>"; };
F091C9C21F6EB8660096FD65 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
F091C9C31F6EB8720096FD65 /* fr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
F091C9C41F6EBA5A0096FD65 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
F0A987D51F77A823009B603D /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = en; path = en.lproj/MainMenu.strings; sourceTree = "<group>"; };
F0A987D61F77B290009B603D /* OSD.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = OSD.framework; sourceTree = "<group>"; };
F0A987DA1F77B404009B603D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/MainMenu.strings; sourceTree = "<group>"; };
F0A987DC1F77B404009B603D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -108,10 +120,12 @@
children = (
56754EAE1D9A4016007BCDC5 /* AppDelegate.swift */,
F091C9B71F6EA79B0096FD65 /* Utils.swift */,
F0445D43200282E60025AE82 /* Main.storyboard */,
56754EB21D9A4016007BCDC5 /* MainMenu.xib */,
F0445D3620023D5B0025AE82 /* Prefs */,
F091C9B41F6EA6180096FD65 /* Objects */,
F091C9C41F6EBA5A0096FD65 /* Bridging-Header.h */,
56754EB01D9A4016007BCDC5 /* Assets.xcassets */,
56754EB21D9A4016007BCDC5 /* MainMenu.xib */,
F091C9C11F6EB8660096FD65 /* Localizable.strings */,
56754EB51D9A4016007BCDC5 /* Info.plist */,
);
@ -127,9 +141,20 @@
name = Pods;
sourceTree = "<group>";
};
F0445D3620023D5B0025AE82 /* Prefs */ = {
isa = PBXGroup;
children = (
F0445D3720023E710025AE82 /* MainPrefsViewController.swift */,
F0445D3B200254FA0025AE82 /* KeysPrefsViewController.swift */,
F0445D3F200259C10025AE82 /* DisplayPrefsViewController.swift */,
);
path = Prefs;
sourceTree = "<group>";
};
F091C9B41F6EA6180096FD65 /* Objects */ = {
isa = PBXGroup;
children = (
F0445D4C200294AB0025AE82 /* ButtonCellView.swift */,
F091C9B21F6EA6110096FD65 /* SliderHandler.swift */,
F03A8DF11FFBAA6F0034DC27 /* Display.swift */,
);
@ -236,6 +261,7 @@
buildActionMask = 2147483647;
files = (
56754EB11D9A4016007BCDC5 /* Assets.xcassets in Resources */,
F0445D41200282E60025AE82 /* Main.storyboard in Resources */,
F0EB972F1F6ED7C800686D2A /* Localizable.strings in Resources */,
55359E3B1E2737EC002671BC /* ddcctl.sh in Resources */,
56754EB41D9A4016007BCDC5 /* MainMenu.xib in Resources */,
@ -267,10 +293,12 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-MonitorControl/Pods-MonitorControl-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/MASPreferences/MASPreferences.framework",
"${BUILT_PRODUCTS_DIR}/MediaKeyTap/MediaKeyTap.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MASPreferences.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MediaKeyTap.framework",
);
runOnlyForDeploymentPostprocessing = 0;
@ -317,11 +345,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F0445D40200259C10025AE82 /* DisplayPrefsViewController.swift in Sources */,
F03A8DF21FFBAA6F0034DC27 /* Display.swift in Sources */,
F091C9B31F6EA6110096FD65 /* SliderHandler.swift in Sources */,
56754EAF1D9A4016007BCDC5 /* AppDelegate.swift in Sources */,
55359E391E2737EC002671BC /* DDC.c in Sources */,
F0445D3820023E710025AE82 /* MainPrefsViewController.swift in Sources */,
F0445D3D200254FA0025AE82 /* KeysPrefsViewController.swift in Sources */,
F091C9B81F6EA79B0096FD65 /* Utils.swift in Sources */,
F0445D4D200294AB0025AE82 /* ButtonCellView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -332,12 +364,22 @@
isa = PBXVariantGroup;
children = (
56754EB31D9A4016007BCDC5 /* Base */,
F091C9B91F6EB43B0096FD65 /* fr */,
F0A987D51F77A823009B603D /* en */,
F0445D49200285690025AE82 /* en */,
F0445D4B2002856C0025AE82 /* fr */,
);
name = MainMenu.xib;
sourceTree = "<group>";
};
F0445D43200282E60025AE82 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
F0445D42200282E60025AE82 /* Base */,
F0445D45200282EB0025AE82 /* fr */,
F0445D47200282F80025AE82 /* en */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
F091C9C11F6EB8660096FD65 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (

View file

@ -10,6 +10,7 @@
import Cocoa
import Foundation
import MediaKeyTap
import MASPreferences
var app: AppDelegate! = nil
let prefs = UserDefaults.standard
@ -33,14 +34,25 @@ class AppDelegate: NSObject, NSApplicationDelegate, MediaKeyTapDelegate {
let step = 100/16
var mediaKeyTap: MediaKeyTap?
var prefsController: NSWindowController?
func applicationDidFinishLaunching(_ aNotification: Notification) {
app = self
mediaKeyTap = MediaKeyTap.init(delegate: self, forKeys: [.brightnessUp, .brightnessDown, .mute, .volumeUp, .volumeDown], observeBuiltIn: false)
let storyboard: NSStoryboard = NSStoryboard.init(name: NSStoryboard.Name(rawValue: "Main"), bundle: Bundle.main)
prefsController = MASPreferencesWindowController(viewControllers:
[
storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "MainPrefsVC")),
storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "KeysPrefsVC")),
storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "DisplayPrefsVC"))
],
title: NSLocalizedString("Preferences", comment: "Shown in Preferences window"))
statusItem.image = NSImage.init(named: NSImage.Name(rawValue: "status"))
statusItem.menu = statusMenu
setDefaultPrefs()
Utils.acquirePrivileges()
CGDisplayRegisterReconfigurationCallback({_, _, _ in app.updateDisplays()}, nil)
@ -56,6 +68,24 @@ class AppDelegate: NSObject, NSApplicationDelegate, MediaKeyTapDelegate {
NSApplication.shared.terminate(self)
}
@IBAction func prefsClicked(_ sender: AnyObject) {
if let prefsController = prefsController {
prefsController.showWindow(sender)
prefsController.window?.makeKeyAndOrderFront(sender)
}
}
/// Set the default prefs of the app
func setDefaultPrefs() {
let prefs = UserDefaults.standard
if !prefs.bool(forKey: Utils.PrefKeys.appAlreadyLaunched.rawValue) {
prefs.set(true, forKey: Utils.PrefKeys.appAlreadyLaunched.rawValue)
prefs.set(false, forKey: Utils.PrefKeys.startAtLogin.rawValue)
prefs.set(true, forKey: Utils.PrefKeys.startWhenExternal.rawValue)
}
}
// MARK: - Menu
func clearDisplays() {
@ -92,7 +122,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, MediaKeyTapDelegate {
let name = Utils.getDisplayName(forEdid: edid)
let serial = Utils.getDisplaySerial(forEdid: edid)
let display = Display(identifier: id, name: name, serial: serial, isBuiltIn: false)
let display = Display(identifier: id, name: name, serial: serial, isEnabled: true)
displays.append(display)
let monitorSubMenu = NSMenu()

View file

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Keyboard-32.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Keyboard-64.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Keyboard-96.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -0,0 +1,379 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Main Prefs View Controller-->
<scene sceneID="Bdy-Ug-m8G">
<objects>
<viewController storyboardIdentifier="MainPrefsVC" id="HNb-aq-vnV" customClass="MainPrefsViewController" customModule="MonitorControl" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="iuQ-z6-BGz">
<rect key="frame" x="0.0" y="0.0" width="400" height="117"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8KQ-j9-ddv">
<rect key="frame" x="18" y="68" width="364" height="29"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="General" id="ocE-Cc-2bi">
<font key="font" metaFont="systemBold" size="24"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dZG-M6-fsQ">
<rect key="frame" x="18" y="42" width="364" height="18"/>
<buttonCell key="cell" type="check" title="Start MonitorControl at Login" bezelStyle="regularSquare" imagePosition="left" inset="2" id="UTh-SV-vAQ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="startAtLoginClicked:" target="HNb-aq-vnV" id="OrA-9Y-N8S"/>
</connections>
</button>
<button hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nnZ-LS-lOW">
<rect key="frame" x="18" y="-16" width="364" height="18"/>
<buttonCell key="cell" type="check" title="Check for updates automatically" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="SCJ-AY-phi">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="K3V-Ub-wAA">
<rect key="frame" x="14" y="-52" width="152" height="32"/>
<buttonCell key="cell" type="push" title="Check for updates" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Vi8-Ye-W28">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fds-MD-5OJ">
<rect key="frame" x="168" y="-43" width="78" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Last check: " id="I3I-EP-Ev8">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="71u-hm-uYt">
<rect key="frame" x="18" y="18" width="364" height="18"/>
<buttonCell key="cell" type="check" title="Start when plugged to an external monitor" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="WJp-aA-2Af">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="startWhenExternalClicked:" target="HNb-aq-vnV" id="BT0-Ff-bx9"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="fds-MD-5OJ" firstAttribute="centerY" secondItem="K3V-Ub-wAA" secondAttribute="centerY" id="2RB-zz-fOU"/>
<constraint firstItem="nnZ-LS-lOW" firstAttribute="top" secondItem="71u-hm-uYt" secondAttribute="bottom" constant="20" id="5IO-Jv-9ZU"/>
<constraint firstItem="dZG-M6-fsQ" firstAttribute="leading" secondItem="iuQ-z6-BGz" secondAttribute="leading" constant="20" id="8QT-EO-uBJ"/>
<constraint firstItem="K3V-Ub-wAA" firstAttribute="top" secondItem="nnZ-LS-lOW" secondAttribute="bottom" constant="10" id="9DT-6C-dQo"/>
<constraint firstItem="8KQ-j9-ddv" firstAttribute="top" secondItem="iuQ-z6-BGz" secondAttribute="top" constant="20" id="Fwh-JQ-1Cx"/>
<constraint firstItem="K3V-Ub-wAA" firstAttribute="leading" secondItem="iuQ-z6-BGz" secondAttribute="leading" constant="20" id="RWW-67-dGr"/>
<constraint firstItem="71u-hm-uYt" firstAttribute="top" secondItem="dZG-M6-fsQ" secondAttribute="bottom" constant="10" id="Xmr-XF-7lE"/>
<constraint firstAttribute="trailing" secondItem="dZG-M6-fsQ" secondAttribute="trailing" constant="20" id="c5h-vI-6Dg"/>
<constraint firstItem="dZG-M6-fsQ" firstAttribute="top" secondItem="8KQ-j9-ddv" secondAttribute="bottom" constant="10" id="dPJ-ev-Y3O"/>
<constraint firstItem="8KQ-j9-ddv" firstAttribute="leading" secondItem="iuQ-z6-BGz" secondAttribute="leading" constant="20" id="ii0-uV-Ylg"/>
<constraint firstItem="71u-hm-uYt" firstAttribute="leading" secondItem="iuQ-z6-BGz" secondAttribute="leading" constant="20" id="jsn-2a-Hse"/>
<constraint firstAttribute="trailing" secondItem="nnZ-LS-lOW" secondAttribute="trailing" constant="20" id="kgN-1K-yxh"/>
<constraint firstItem="nnZ-LS-lOW" firstAttribute="leading" secondItem="iuQ-z6-BGz" secondAttribute="leading" constant="20" id="kqS-g2-YV5"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="fds-MD-5OJ" secondAttribute="trailing" constant="20" id="mfJ-HC-8ie"/>
<constraint firstAttribute="trailing" secondItem="8KQ-j9-ddv" secondAttribute="trailing" constant="20" id="qVn-hz-dRV"/>
<constraint firstAttribute="trailing" secondItem="71u-hm-uYt" secondAttribute="trailing" constant="20" id="sIC-PJ-9gQ"/>
<constraint firstItem="fds-MD-5OJ" firstAttribute="leading" secondItem="K3V-Ub-wAA" secondAttribute="trailing" constant="10" id="xuV-jB-am4"/>
</constraints>
</view>
<connections>
<outlet property="startAtLogin" destination="dZG-M6-fsQ" id="Rwg-dp-vIj"/>
<outlet property="startWhenExternal" destination="71u-hm-uYt" id="l02-Xi-74S"/>
</connections>
</viewController>
<customObject id="ALN-AB-CU5" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="116" y="172.5"/>
</scene>
<!--Keys Prefs View Controller-->
<scene sceneID="DmR-ia-4qL">
<objects>
<viewController storyboardIdentifier="KeysPrefsVC" id="MHy-Dv-i5A" customClass="KeysPrefsViewController" customModule="MonitorControl" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="nfK-n0-xN4">
<rect key="frame" x="0.0" y="0.0" width="400" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fUf-UM-yW3">
<rect key="frame" x="85" y="48" width="196" height="26"/>
<popUpButtonCell key="cell" type="push" title="Both Brightness &amp; Volume" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Vr4-xb-B4o" id="DkZ-as-YDS">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="Hqj-cU-ZyP">
<items>
<menuItem title="Both Brightness &amp; Volume" state="on" id="Vr4-xb-B4o">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Brightness only" tag="1" id="hjz-0c-rvK">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Volume only" tag="2" id="NLP-dU-Dam">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="listenForChanged:" target="MHy-Dv-i5A" id="ANw-zX-wOu"/>
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jFY-ug-0KQ">
<rect key="frame" x="18" y="53" width="61" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Listen for" id="Vh8-06-U3K">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AeW-b4-XNc">
<rect key="frame" x="84" y="17" width="182" height="26"/>
<popUpButtonCell key="cell" type="push" title="Native Mac Keys" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="AiH-h3-2w5" id="xAv-cc-EOX">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="q3o-tj-rLn">
<items>
<menuItem title="Native Mac Keys" state="on" id="AiH-h3-2w5">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Function Keys (F1, F2...)" tag="1" id="dQm-ww-uhA">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="listenOnChanged:" target="MHy-Dv-i5A" id="ryx-Jd-IbM"/>
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="VNO-n0-6Y1">
<rect key="frame" x="18" y="22" width="60" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Listen on" id="C3e-V0-Tn0">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Uti-Vm-YwB">
<rect key="frame" x="18" y="80" width="364" height="29"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Keys" id="Dcz-GG-1li">
<font key="font" metaFont="systemBold" size="24"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="AeW-b4-XNc" firstAttribute="centerY" secondItem="VNO-n0-6Y1" secondAttribute="centerY" id="4rl-y3-iUl"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="AeW-b4-XNc" secondAttribute="trailing" constant="20" id="CXx-3J-bgf"/>
<constraint firstItem="fUf-UM-yW3" firstAttribute="centerY" secondItem="jFY-ug-0KQ" secondAttribute="centerY" id="FA2-Mh-LBe"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="fUf-UM-yW3" secondAttribute="trailing" constant="20" id="GBB-mP-L7K"/>
<constraint firstItem="VNO-n0-6Y1" firstAttribute="leading" secondItem="nfK-n0-xN4" secondAttribute="leading" constant="20" id="KSb-DY-Ysk"/>
<constraint firstItem="Uti-Vm-YwB" firstAttribute="leading" secondItem="nfK-n0-xN4" secondAttribute="leading" constant="20" id="Mfl-NR-mVk"/>
<constraint firstItem="Uti-Vm-YwB" firstAttribute="top" secondItem="nfK-n0-xN4" secondAttribute="top" constant="20" id="ReX-zz-skV"/>
<constraint firstItem="fUf-UM-yW3" firstAttribute="leading" secondItem="jFY-ug-0KQ" secondAttribute="trailing" constant="10" id="Tic-nC-Oax"/>
<constraint firstItem="AeW-b4-XNc" firstAttribute="top" secondItem="fUf-UM-yW3" secondAttribute="bottom" constant="10" id="Zd8-nU-IPw"/>
<constraint firstAttribute="trailing" secondItem="Uti-Vm-YwB" secondAttribute="trailing" constant="20" id="ctI-eo-jEw"/>
<constraint firstItem="AeW-b4-XNc" firstAttribute="leading" secondItem="VNO-n0-6Y1" secondAttribute="trailing" constant="10" id="dkl-ho-D2N"/>
<constraint firstItem="jFY-ug-0KQ" firstAttribute="top" secondItem="Uti-Vm-YwB" secondAttribute="bottom" constant="10" id="t7Y-Pv-HlI"/>
<constraint firstItem="jFY-ug-0KQ" firstAttribute="leading" secondItem="nfK-n0-xN4" secondAttribute="leading" constant="20" id="xCB-fT-tMo"/>
</constraints>
</view>
<connections>
<outlet property="listenFor" destination="fUf-UM-yW3" id="tgS-jF-nte"/>
<outlet property="listenOn" destination="AeW-b4-XNc" id="dqX-if-8ib"/>
</connections>
</viewController>
<customObject id="hVj-0D-6XC" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="618" y="178.5"/>
</scene>
<!--Display Prefs View Controller-->
<scene sceneID="kdt-oj-Qke">
<objects>
<viewController storyboardIdentifier="DisplayPrefsVC" id="NAx-6T-ZPc" customClass="DisplayPrefsViewController" customModule="MonitorControl" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="EBf-qN-KaN">
<rect key="frame" x="0.0" y="0.0" width="400" height="240"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uXD-ZY-N3H">
<rect key="frame" x="18" y="191" width="364" height="29"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Display" id="ExD-7P-6XI">
<font key="font" metaFont="systemBold" size="24"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="B5k-we-kuP">
<rect key="frame" x="20" y="20" width="360" height="137"/>
<clipView key="contentView" id="4ot-Jo-X5O">
<rect key="frame" x="1" y="23" width="358" height="113"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" rowSizeStyle="automatic" headerView="ckY-Px-mJn" viewBased="YES" id="dyo-uY-pMe">
<rect key="frame" x="0.0" y="0.0" width="358" height="113"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="" width="49" minWidth="40" maxWidth="1000" id="8U8-ec-Zbv">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Enabled">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<customCell key="dataCell" alignment="left" id="Dzg-gO-DMd"/>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="Fzp-05-e2y" customClass="ButtonCellView" customModule="MonitorControl" customModuleProvider="target">
<rect key="frame" x="1" y="1" width="49" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OJu-lv-bAA">
<rect key="frame" x="0.0" y="0.0" width="49" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="overlaps" state="on" inset="2" id="EjF-JQ-tUb">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="buttonToggled:" target="Fzp-05-e2y" id="sNo-1W-2Dw"/>
</connections>
</button>
</subviews>
<connections>
<outlet property="button" destination="OJu-lv-bAA" id="Mlq-Sp-j03"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="" width="186" minWidth="40" maxWidth="1000" id="CHc-s5-4MN">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Display Name">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="2gr-xG-Byx">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="iYj-Ud-yGU">
<rect key="frame" x="53" y="1" width="186" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qsc-jC-vJQ">
<rect key="frame" x="0.0" y="0.0" width="186" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="aSw-3H-uNa">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="qsc-jC-vJQ" id="q3A-ci-C4X"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="" width="114" minWidth="10" maxWidth="3.4028234663852886e+38" id="dgp-q7-cBK">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Display Id">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="as0-t3-Aub">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="vw4-Us-VHk">
<rect key="frame" x="242" y="1" width="114" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="z5b-Gr-EmC">
<rect key="frame" x="0.0" y="0.0" width="114" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="cnb-Li-1lE">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="z5b-Gr-EmC" id="dGr-mQ-Nbm"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>
<outlet property="dataSource" destination="NAx-6T-ZPc" id="QTF-WU-oAy"/>
<outlet property="delegate" destination="NAx-6T-ZPc" id="VNm-H1-xFG"/>
</connections>
</tableView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="UHx-W7-xSv">
<rect key="frame" x="-100" y="-100" width="358" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="HBR-36-UaL">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<tableHeaderView key="headerView" id="ckY-Px-mJn">
<rect key="frame" x="0.0" y="0.0" width="358" height="23"/>
<autoresizingMask key="autoresizingMask"/>
</tableHeaderView>
</scrollView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Y48-gQ-uJi">
<rect key="frame" x="18" y="165" width="364" height="18"/>
<buttonCell key="cell" type="check" title="Change Brightness/Volume for all screens" bezelStyle="regularSquare" imagePosition="left" inset="2" id="0Z7-PQ-Bl8">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="allScreensTouched:" target="NAx-6T-ZPc" id="Dds-RT-coJ"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="Y48-gQ-uJi" secondAttribute="trailing" constant="20" id="24u-jX-VqD"/>
<constraint firstItem="Y48-gQ-uJi" firstAttribute="leading" secondItem="EBf-qN-KaN" secondAttribute="leading" constant="20" id="Ct2-ah-W0a"/>
<constraint firstAttribute="trailing" secondItem="uXD-ZY-N3H" secondAttribute="trailing" constant="20" id="Qwk-xy-tL4"/>
<constraint firstAttribute="trailing" secondItem="B5k-we-kuP" secondAttribute="trailing" constant="20" id="SgW-60-zGH"/>
<constraint firstItem="Y48-gQ-uJi" firstAttribute="top" secondItem="uXD-ZY-N3H" secondAttribute="bottom" constant="10" id="WSd-oq-oD7"/>
<constraint firstItem="B5k-we-kuP" firstAttribute="top" secondItem="Y48-gQ-uJi" secondAttribute="bottom" constant="10" id="YIT-MK-KKw"/>
<constraint firstAttribute="bottom" secondItem="B5k-we-kuP" secondAttribute="bottom" constant="20" id="dfj-cp-Rh1"/>
<constraint firstItem="uXD-ZY-N3H" firstAttribute="top" secondItem="EBf-qN-KaN" secondAttribute="top" constant="20" id="jAo-pS-Y7d"/>
<constraint firstItem="B5k-we-kuP" firstAttribute="leading" secondItem="EBf-qN-KaN" secondAttribute="leading" constant="20" id="uZk-3q-LOM"/>
<constraint firstItem="uXD-ZY-N3H" firstAttribute="leading" secondItem="EBf-qN-KaN" secondAttribute="leading" constant="20" id="wi7-HQ-h6O"/>
</constraints>
</view>
<connections>
<outlet property="allScreens" destination="Y48-gQ-uJi" id="TDW-HZ-0vl"/>
<outlet property="displayList" destination="dyo-uY-pMe" id="gDj-Sn-kDj"/>
</connections>
</viewController>
<customObject id="34q-0u-YTQ" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1116" y="234"/>
</scene>
</scenes>
</document>

View file

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13196" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13196"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@ -22,6 +21,12 @@
<menu id="lCi-vw-mwp">
<items>
<menuItem isSeparatorItem="YES" id="F5R-GH-0ZO"/>
<menuItem title="Preferences..." id="SOS-eZ-uU5">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="prefsClicked:" target="Voe-Tx-rLC" id="sSU-RG-py2"/>
</connections>
</menuItem>
<menuItem title="Quit" id="JTa-2I-AsI">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
@ -29,7 +34,7 @@
</connections>
</menuItem>
</items>
<point key="canvasLocation" x="-87.5" y="66.5"/>
<point key="canvasLocation" x="-348" y="-499"/>
</menu>
</objects>
</document>

View file

@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<string>1.1.1</string>
<key>CFBundleVersion</key>
<string>20</string>
<string>32</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>

View file

@ -0,0 +1,35 @@
//
// ButtonCellView.swift
// MonitorControl
//
// Created by Guillaume BRODER on 07/01/2018.
// Copyright © 2018 Mathew Kurian. All rights reserved.
//
import Cocoa
class ButtonCellView: NSTableCellView {
@IBOutlet var button: NSButton!
var display: Display?
let prefs = UserDefaults.standard
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
}
@IBAction func buttonToggled(_ sender: NSButton) {
if let display = display {
switch sender.state {
case .on:
prefs.set(true, forKey: "\(display.identifier)-state")
case .off:
prefs.set(true, forKey: "\(display.identifier)-state")
default:
break
}
// TODO: Toggle enabled display state
print("Toggle enabled display state -> \(sender.state)")
}
}
}

View file

@ -3,7 +3,7 @@
// MonitorControl
//
// Created by Guillaume BRODER on 02/01/2018.
// Copyright © 2018 Mathew Kurian. All rights reserved.
// MIT Licensed.
//
import Cocoa
@ -13,5 +13,5 @@ struct Display {
var identifier: CGDirectDisplayID
var name: String
var serial: String
var isBuiltIn: Bool = false
var isEnabled: Bool = true
}

View file

@ -0,0 +1,123 @@
//
// DisplayPrefsViewController.swift
// MonitorControl
//
// Created by Guillaume BRODER on 07/01/2018.
// MIT Licensed.
//
import Cocoa
import MASPreferences
class DisplayPrefsViewController: NSViewController, MASPreferencesViewController, NSTableViewDataSource, NSTableViewDelegate {
var viewIdentifier: String = "Display"
var toolbarItemLabel: String? = NSLocalizedString("Display", comment: "Shown in the main prefs window")
var toolbarItemImage: NSImage? = NSImage.init(named: .computer)
let prefs = UserDefaults.standard
var displays: [Display] = []
enum DisplayCell: String {
case checkbox
case name
case identifier
}
@IBOutlet var allScreens: NSButton!
@IBOutlet var displayList: NSTableView!
override func viewDidLoad() {
super.viewDidLoad()
allScreens.state = prefs.bool(forKey: Utils.PrefKeys.allScreens.rawValue) ? .on : .off
loadDisplayList()
}
@IBAction func allScreensTouched(_ sender: NSButton) {
switch sender.state {
case .on:
prefs.set(true, forKey: Utils.PrefKeys.allScreens.rawValue)
case .off:
prefs.set(false, forKey: Utils.PrefKeys.allScreens.rawValue)
default: break
}
// TODO: Toggle allScreens state
print("Toggle allScreens state -> \(sender.state)")
}
// MARK: - Table datasource
func loadDisplayList() {
for screen in NSScreen.screens {
if let id = screen.deviceDescription[NSDeviceDescriptionKey.init("NSScreenNumber")] as? CGDirectDisplayID {
// Is Built In Screen (e.g. MBP/iMac Screen)
if CGDisplayIsBuiltin(id) != 0 {
let display = Display(identifier: id, name: "Mac built-in Display", serial: "", isEnabled: false)
displays.append(display)
continue
}
// Does screen support EDID ?
var edid = EDID()
if !EDIDTest(id, &edid) {
continue
}
let name = Utils.getDisplayName(forEdid: edid)
let serial = Utils.getDisplaySerial(forEdid: edid)
var isEnabled = true
if let enabled = prefs.object(forKey: "\(id)-state") as? Bool {
isEnabled = enabled
}
let display = Display(identifier: id, name: name, serial: serial, isEnabled: isEnabled)
displays.append(display)
}
}
displayList.reloadData()
}
func numberOfRows(in tableView: NSTableView) -> Int {
return displays.count
}
// MARK: - Table delegate
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
var cellType = DisplayCell.checkbox
var checked = false
var text = ""
let display = displays[row]
if tableColumn == tableView.tableColumns[0] {
// Checkbox
checked = display.isEnabled
} else if tableColumn == tableView.tableColumns[1] {
// Name
text = display.name
cellType = DisplayCell.name
} else if tableColumn == tableView.tableColumns[2] {
// Identifier
text = "\(display.identifier)"
cellType = DisplayCell.identifier
}
if cellType == DisplayCell.checkbox {
if let cell = tableView.makeView(withIdentifier: (tableColumn?.identifier)!, owner: nil) as? ButtonCellView {
cell.button.state = checked ? .on : .off
cell.display = display
if display.name == "Mac built-in Display" {
cell.button.isEnabled = false
}
return cell
}
} else {
if let cell = tableView.makeView(withIdentifier: (tableColumn?.identifier)!, owner: nil) as? NSTableCellView {
cell.textField?.stringValue = text
return cell
}
}
return nil
}
}

View file

@ -0,0 +1,40 @@
//
// KeysPrefsViewController.swift
// MonitorControl
//
// Created by Guillaume BRODER on 07/01/2018.
// MIT Licensed.
//
import Cocoa
import MASPreferences
class KeysPrefsViewController: NSViewController, MASPreferencesViewController {
var viewIdentifier: String = "Keys"
var toolbarItemLabel: String? = NSLocalizedString("Keys", comment: "Shown in the main prefs window")
var toolbarItemImage: NSImage? = NSImage.init(named: NSImage.Name.init("KeyboardPref"))
let prefs = UserDefaults.standard
@IBOutlet var listenFor: NSPopUpButton!
@IBOutlet var listenOn: NSPopUpButton!
override func viewDidLoad() {
super.viewDidLoad()
listenFor.selectItem(at: prefs.integer(forKey: Utils.PrefKeys.listenFor.rawValue))
listenOn.selectItem(at: prefs.integer(forKey: Utils.PrefKeys.listenOn.rawValue))
}
@IBAction func listenForChanged(_ sender: NSPopUpButton) {
prefs.set(sender.selectedTag(), forKey: Utils.PrefKeys.listenFor.rawValue)
// TODO: Toggle keys listened for state
print("Toggle keys listened for state state -> \(sender.selectedItem?.title ?? "")")
}
@IBAction func listenOnChanged(_ sender: NSPopUpButton) {
prefs.set(sender.selectedTag(), forKey: Utils.PrefKeys.listenOn.rawValue)
// TODO: Toggle keys listened on state
print("Toggle keys listened on state state -> \(sender.selectedItem?.title ?? "")")
}
}

View file

@ -0,0 +1,52 @@
//
// MainPrefsViewController.swift
// MonitorControl
//
// Created by Guillaume BRODER on 07/01/2018.
// MIT Licensed.
//
import Cocoa
import MASPreferences
class MainPrefsViewController: NSViewController, MASPreferencesViewController {
var viewIdentifier: String = "Main"
var toolbarItemLabel: String? = NSLocalizedString("General", comment: "Shown in the main prefs window")
var toolbarItemImage: NSImage? = NSImage.init(named: .preferencesGeneral)
let prefs = UserDefaults.standard
@IBOutlet var startAtLogin: NSButton!
@IBOutlet var startWhenExternal: NSButton!
override func viewDidLoad() {
super.viewDidLoad()
startAtLogin.state = prefs.bool(forKey: Utils.PrefKeys.startAtLogin.rawValue) ? .on : .off
startWhenExternal.state = prefs.bool(forKey: Utils.PrefKeys.startWhenExternal.rawValue) ? .on : .off
}
@IBAction func startAtLoginClicked(_ sender: NSButton) {
switch sender.state {
case .on:
prefs.set(true, forKey: Utils.PrefKeys.startAtLogin.rawValue)
case .off:
prefs.set(false, forKey: Utils.PrefKeys.startAtLogin.rawValue)
default: break
}
// TODO: Toggle start at login state
print("Toggle start at login state -> \(sender.state)")
}
@IBAction func startWhenExternalClicked(_ sender: NSButton) {
switch sender.state {
case .on:
prefs.set(true, forKey: Utils.PrefKeys.startWhenExternal.rawValue)
case .off:
prefs.set(false, forKey: Utils.PrefKeys.startWhenExternal.rawValue)
default: break
}
// TODO: Toggle start when external plugged in state
print("Toggle start when external plugged in state -> \(sender.state)")
}
}

View file

@ -147,4 +147,25 @@ class Utils: NSObject {
return getDescriptorString(edid, 0xFF) ?? NSLocalizedString("Unknown", comment: "")
}
/// UserDefault Keys for the app prefs
enum PrefKeys: String {
/// Was the app launched once
case appAlreadyLaunched
/// Does the app start at Login
case startAtLogin
/// Does the app start when plugged to an external monitor
case startWhenExternal
/// Keys listened for (Brightness/Volume)
case listenFor
/// Keys listened on (mac or functions)
case listenOn
/// Change Brightness/Volume for all screens
case allScreens
}
}

View file

@ -22,6 +22,9 @@
/* Shown in menu */
"Volume" = "Volume";
/* Shown in Preferences window */
"Preferences" = "Preferences";
/* Shown in the alert dialog */
"Ok" = "Ok";
@ -30,3 +33,9 @@
/* Shown in the alert dialog */
"You need to enable MonitorControl in System Preferences > Security and Privacy > Accessibility for the keyboard shortcuts to work" = "You need to enable MonitorControl in System Preferences > Security and Privacy > Accessibility for the keyboard shortcuts to work";
/* Shown in the main prefs window */
"General" = "General";
/* Shown in the main prefs window */
"Keys" = "Keys";

View file

@ -0,0 +1,72 @@
/* Class = "NSButtonCell"; title = "Change Brightness/Volume for all screens"; ObjectID = "0Z7-PQ-Bl8"; */
"0Z7-PQ-Bl8.title" = "Change Brightness/Volume for all screens";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "2gr-xG-Byx"; */
"2gr-xG-Byx.title" = "Text Cell";
/* Class = "NSTableColumn"; headerCell.title = "Enabled"; ObjectID = "8U8-ec-Zbv"; */
"8U8-ec-Zbv.headerCell.title" = "Enabled";
/* Class = "NSMenuItem"; title = "Native Mac Keys"; ObjectID = "AiH-h3-2w5"; */
"AiH-h3-2w5.title" = "Native Mac Keys";
/* Class = "NSTextFieldCell"; title = "Listen on"; ObjectID = "C3e-V0-Tn0"; */
"C3e-V0-Tn0.title" = "Listen on";
/* Class = "NSTableColumn"; headerCell.title = "Display Name"; ObjectID = "CHc-s5-4MN"; */
"CHc-s5-4MN.headerCell.title" = "Display Name";
/* Class = "NSTextFieldCell"; title = "Keys"; ObjectID = "Dcz-GG-1li"; */
"Dcz-GG-1li.title" = "Keys";
/* Class = "NSTextFieldCell"; title = "Display"; ObjectID = "ExD-7P-6XI"; */
"ExD-7P-6XI.title" = "Display";
/* Class = "NSTextFieldCell"; title = "Last check: "; ObjectID = "I3I-EP-Ev8"; */
"I3I-EP-Ev8.title" = "Last check: ";
/* Class = "NSMenuItem"; title = "Volume only"; ObjectID = "NLP-dU-Dam"; */
"NLP-dU-Dam.title" = "Volume only";
/* Class = "NSButtonCell"; title = "Check for updates automatically"; ObjectID = "SCJ-AY-phi"; */
"SCJ-AY-phi.title" = "Check for updates automatically";
/* Class = "NSButtonCell"; title = "Start MonitorControl at Login"; ObjectID = "UTh-SV-vAQ"; */
"UTh-SV-vAQ.title" = "Start MonitorControl at Login";
/* Class = "NSTextFieldCell"; title = "Listen for"; ObjectID = "Vh8-06-U3K"; */
"Vh8-06-U3K.title" = "Listen for";
/* Class = "NSButtonCell"; title = "Check for updates"; ObjectID = "Vi8-Ye-W28"; */
"Vi8-Ye-W28.title" = "Check for updates";
/* Class = "NSMenuItem"; title = "Both Brightness & Volume"; ObjectID = "Vr4-xb-B4o"; */
"Vr4-xb-B4o.title" = "Both Brightness & Volume";
/* Class = "NSButtonCell"; title = "Start when plugged to an external monitor"; ObjectID = "WJp-aA-2Af"; */
"WJp-aA-2Af.title" = "Start when plugged to an external monitor";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "Xje-0J-NNJ"; */
"Xje-0J-NNJ.title" = "Text Cell";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "as0-t3-Aub"; */
"as0-t3-Aub.title" = "Text Cell";
/* Class = "NSTextFieldCell"; title = "Table View Cell"; ObjectID = "cUg-j2-8gt"; */
"cUg-j2-8gt.title" = "Table View Cell";
/* Class = "NSMenuItem"; title = "Function Keys (F1, F2...)"; ObjectID = "dQm-ww-uhA"; */
"dQm-ww-uhA.title" = "Function Keys (F1, F2...)";
/* Class = "NSTableColumn"; headerCell.title = "Display Id"; ObjectID = "dgp-q7-cBK"; */
"dgp-q7-cBK.headerCell.title" = "Display Id";
/* Class = "NSMenuItem"; title = "Brightness only"; ObjectID = "hjz-0c-rvK"; */
"hjz-0c-rvK.title" = "Brightness only";
/* Class = "NSTextFieldCell"; title = "Table View Cell"; ObjectID = "ldv-hu-9Hl"; */
"ldv-hu-9Hl.title" = "Table View Cell";
/* Class = "NSTextFieldCell"; title = "General"; ObjectID = "ocE-Cc-2bi"; */
"ocE-Cc-2bi.title" = "General";

View file

@ -1,3 +1,6 @@
/* Class = "NSMenuItem"; title = "Quit"; ObjectID = "JTa-2I-AsI"; */
"JTa-2I-AsI.title" = "Quit";
/* Class = "NSMenuItem"; title = "Preferences..."; ObjectID = "SOS-eZ-uU5"; */
"SOS-eZ-uU5.title" = "Preferences...";

View file

@ -22,6 +22,9 @@
/* Shown in menu */
"Volume" = "Volume";
/* Shown in Preferences window */
"Preferences" = "Préférences";
/* Shown in the alert dialog */
"Ok" = "Ok";
@ -30,3 +33,9 @@
/* Shown in the alert dialog */
"You need to enable MonitorControl in System Preferences > Security and Privacy > Accessibility for the keyboard shortcuts to work" = "Vous devez activer MonitorControl dans Préférences Système > Sécurité et confidentialité > Accessibilité pour que les raccourcis clavier fonctionnes";
/* Shown in the main prefs window */
"General" = "Général";
/* Shown in the main prefs window */
"Keys" = "Touches";

View file

@ -0,0 +1,72 @@
/* Class = "NSButtonCell"; title = "Change Brightness/Volume for all screens"; ObjectID = "0Z7-PQ-Bl8"; */
"0Z7-PQ-Bl8.title" = "Modifier Luminosité/Volume pour tout les écrans";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "2gr-xG-Byx"; */
"2gr-xG-Byx.title" = "Text Cell";
/* Class = "NSTableColumn"; headerCell.title = "Enabled"; ObjectID = "8U8-ec-Zbv"; */
"8U8-ec-Zbv.headerCell.title" = "Activé";
/* Class = "NSMenuItem"; title = "Native Mac Keys"; ObjectID = "AiH-h3-2w5"; */
"AiH-h3-2w5.title" = "Touches macOS Native";
/* Class = "NSTextFieldCell"; title = "Listen on"; ObjectID = "C3e-V0-Tn0"; */
"C3e-V0-Tn0.title" = "Écouter sur";
/* Class = "NSTableColumn"; headerCell.title = "Display Name"; ObjectID = "CHc-s5-4MN"; */
"CHc-s5-4MN.headerCell.title" = "Nom de l'écran";
/* Class = "NSTextFieldCell"; title = "Keys"; ObjectID = "Dcz-GG-1li"; */
"Dcz-GG-1li.title" = "Touches";
/* Class = "NSTextFieldCell"; title = "Display"; ObjectID = "ExD-7P-6XI"; */
"ExD-7P-6XI.title" = "Écrans";
/* Class = "NSTextFieldCell"; title = "Last check: "; ObjectID = "I3I-EP-Ev8"; */
"I3I-EP-Ev8.title" = "Dernière vérification: ";
/* Class = "NSMenuItem"; title = "Volume only"; ObjectID = "NLP-dU-Dam"; */
"NLP-dU-Dam.title" = "Volume uniquement";
/* Class = "NSButtonCell"; title = "Check for updates automatically"; ObjectID = "SCJ-AY-phi"; */
"SCJ-AY-phi.title" = "Vérifier les màj automatiquement";
/* Class = "NSButtonCell"; title = "Start MonitorControl at Login"; ObjectID = "UTh-SV-vAQ"; */
"UTh-SV-vAQ.title" = "Lancer MonitorControl au démarrage";
/* Class = "NSTextFieldCell"; title = "Listen for"; ObjectID = "Vh8-06-U3K"; */
"Vh8-06-U3K.title" = "Écouter pour";
/* Class = "NSButtonCell"; title = "Check for updates"; ObjectID = "Vi8-Ye-W28"; */
"Vi8-Ye-W28.title" = "Vérifier les mis à jour";
/* Class = "NSMenuItem"; title = "Both Brightness & Volume"; ObjectID = "Vr4-xb-B4o"; */
"Vr4-xb-B4o.title" = "Luminosité & Volume";
/* Class = "NSButtonCell"; title = "Start when plugged to an external monitor"; ObjectID = "WJp-aA-2Af"; */
"WJp-aA-2Af.title" = "Lancer quand branché à un écran externe";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "Xje-0J-NNJ"; */
"Xje-0J-NNJ.title" = "Text Cell";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "as0-t3-Aub"; */
"as0-t3-Aub.title" = "Text Cell";
/* Class = "NSTextFieldCell"; title = "Table View Cell"; ObjectID = "cUg-j2-8gt"; */
"cUg-j2-8gt.title" = "Table View Cell";
/* Class = "NSMenuItem"; title = "Function Keys (F1, F2...)"; ObjectID = "dQm-ww-uhA"; */
"dQm-ww-uhA.title" = "Touches de fonctions (F1, F2...)";
/* Class = "NSTableColumn"; headerCell.title = "Display Id"; ObjectID = "dgp-q7-cBK"; */
"dgp-q7-cBK.headerCell.title" = "Identifiant";
/* Class = "NSMenuItem"; title = "Brightness only"; ObjectID = "hjz-0c-rvK"; */
"hjz-0c-rvK.title" = "Luminosité uniquement";
/* Class = "NSTextFieldCell"; title = "Table View Cell"; ObjectID = "ldv-hu-9Hl"; */
"ldv-hu-9Hl.title" = "Table View Cell";
/* Class = "NSTextFieldCell"; title = "General"; ObjectID = "ocE-Cc-2bi"; */
"ocE-Cc-2bi.title" = "Général";

View file

@ -1,3 +1,6 @@
/* Class = "NSMenuItem"; title = "Quit"; ObjectID = "JTa-2I-AsI"; */
"JTa-2I-AsI.title" = "Quitter";
/* Class = "NSMenuItem"; title = "Preferences..."; ObjectID = "SOS-eZ-uU5"; */
"SOS-eZ-uU5.title" = "Préférences...";

View file

@ -1,10 +1,11 @@
# Podfile
plateform :osx, '10.11'
platform :osx, '10.11'
target 'MonitorControl' do
use_frameworks!
use_frameworks!
pod 'MediaKeyTap', :git => 'https://github.com/the0neyouseek/MediaKeyTap.git'
pod 'MediaKeyTap', :git => 'https://github.com/the0neyouseek/MediaKeyTap.git'
pod 'MASPreferences'
end

View file

@ -1,12 +1,24 @@
PODS:
- MediaKeyTap (1.0.0)
- MASPreferences (1.3)
- MediaKeyTap (2.1.0)
DEPENDENCIES:
- MediaKeyTap
- MASPreferences
- MediaKeyTap (from `https://github.com/the0neyouseek/MediaKeyTap.git`)
EXTERNAL SOURCES:
MediaKeyTap:
:git: https://github.com/the0neyouseek/MediaKeyTap.git
CHECKOUT OPTIONS:
MediaKeyTap:
:commit: d02f865ea962d5811375ddd047525baf409fb2b0
:git: https://github.com/the0neyouseek/MediaKeyTap.git
SPEC CHECKSUMS:
MediaKeyTap: 92764246d2ce8bf4446c2457e8b180e0b88926a1
MASPreferences: c08b8622dd17b47da87669e741efd7c92e970e8c
MediaKeyTap: b652877e9ae2d52ca4f5310fa5152945ad3f0798
PODFILE CHECKSUM: 11c0e07cdb4651a81ff3269f5d50664df18716d4
PODFILE CHECKSUM: 3404918793c88a6c1f56a30e54cf0d9afb0cfffb
COCOAPODS: 1.3.1