Skip to content

Commit

Permalink
Add basic support for macOS's accessibility Inverted Colors
Browse files Browse the repository at this point in the history
  • Loading branch information
glouel committed Dec 2, 2024
1 parent 18b794f commit b8296b5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Aerial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3249,15 +3249,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.5.2beta1;
CURRENT_PROJECT_VERSION = 3.5.2beta2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Old stuff/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 3.5.2beta1;
MARKETING_VERSION = 3.5.2beta2;
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3278,15 +3278,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.5.2beta1;
CURRENT_PROJECT_VERSION = 3.5.2beta2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Old stuff/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 3.5.2beta1;
MARKETING_VERSION = 3.5.2beta2;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
24 changes: 20 additions & 4 deletions Aerial/Source/Models/Extensions/AVPlayerItem+vibrance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import AVKit
extension AVPlayerItem {
func setVibrance(_ value: Double) {
var useValue = PrefsVideos.globalVibrance

if value != 0 {
useValue = value
}

guard useValue != 0 else {
return
}

if #available(OSX 10.14, *) {
debugLog("Applying vibrance of \(useValue)")
let filter = CIFilter(name: "CIVibrance")!
Expand All @@ -28,10 +28,26 @@ extension AVPlayerItem {
filter.setValue(source, forKey: kCIInputImageKey)
filter.setValue(useValue, forKey: kCIInputAmountKey)
let output = filter.outputImage

request.finish(with: output!, context: nil)
})
}
}

func setColorInvert() {
if #available(OSX 10.14, *) {
debugLog("Applying color invert")

if let filter = CIFilter(name: "CIColorInvert") {
self.videoComposition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: { request in
let source = request.sourceImage.clampedToExtent()
filter.setValue(source, forKey: kCIInputImageKey)
let output = filter.outputImage

request.finish(with: output!, context: nil)
})
}
}
}

}
4 changes: 4 additions & 0 deletions Aerial/Source/Models/Prefs/PrefsAdvanced.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct PrefsAdvanced {
@SimpleStorage(key: "favorOrientation", defaultValue: true)
static var favorOrientation: Bool

// Invert colors
@SimpleStorage(key: "invertColors", defaultValue: false)
static var invertColors: Bool

// Debug mode
@SimpleStorage(key: "debugMode", defaultValue: false)
static var debugMode: Bool
Expand Down
7 changes: 7 additions & 0 deletions Aerial/Source/Views/AerialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
if let value = PrefsVideos.vibrance[video.id], !video.isHDR() {
item.setVibrance(value)
}
if PrefsAdvanced.invertColors {
item.setColorInvert()
}

player.replaceCurrentItem(with: item)
debugLog("🖼️ \(self.description) streaming video (not fully available offline) : \(video.url)")
Expand Down Expand Up @@ -863,6 +866,10 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
let value = PrefsVideos.vibrance[video.id] ?? 0
localitem.setVibrance(value)
}
if PrefsAdvanced.invertColors {
localitem.setColorInvert()
}

DispatchQueue.global(qos: .default).async { [self] in
player.replaceCurrentItem(with: localitem)
debugLog("🖼️ \(self.description) playing video (OFFLINE MODE) : \(localurl)")
Expand Down
7 changes: 7 additions & 0 deletions Resources/MainUI/Settings panels/AdvancedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class AdvancedViewController: NSViewController {
@IBOutlet var menu4KHDR: NSMenuItem!

@IBOutlet var videoFadesPopup: NSPopUpButton!

@IBOutlet weak var invertColorsCheckbox: NSButton!

@IBOutlet var rightArrowSkipCheckbox: NSButton!
@IBOutlet var muteSoundCheckbox: NSButton!

Expand Down Expand Up @@ -85,6 +88,7 @@ class AdvancedViewController: NSViewController {
rightArrowSkipCheckbox.state = .off
}

invertColorsCheckbox.state = PrefsAdvanced.invertColors ? .on : .off
highQualityTextCheckbox.state = PrefsInfo.highQualityTextRendering ? .on : .off

muteSoundCheckbox.state = PrefsAdvanced.muteSound ? .on : .off
Expand Down Expand Up @@ -186,6 +190,9 @@ class AdvancedViewController: NSViewController {
}
}

@IBAction func invertColorsCheckboxClick(_ sender: NSButton) {
PrefsAdvanced.invertColors = sender.state == .on
}
@IBAction func videoFadesPopupChange(_ sender: NSPopUpButton) {
PrefsVideos.fadeMode = FadeMode(rawValue: sender.indexOfSelectedItem)!
}
Expand Down
36 changes: 24 additions & 12 deletions Resources/MainUI/Settings panels/AdvancedViewController.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22152" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="23094" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22152"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23094"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="System colors introduced in macOS 10.14" minToolsVersion="10.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -14,6 +13,7 @@
<outlet property="debugCheckbox" destination="Jfm-Hl-4bN" id="XiF-WF-NLg"/>
<outlet property="favorOrientationCheckbox" destination="oe5-rQ-KJu" id="P2e-TZ-j6f"/>
<outlet property="highQualityTextCheckbox" destination="aZ7-cT-Z3Y" id="Oz0-Fk-ATM"/>
<outlet property="invertColorsCheckbox" destination="NT3-XE-JxM" id="t3F-Ud-BCz"/>
<outlet property="languageLabel" destination="xFh-dw-fup" id="ng0-cZ-hbk"/>
<outlet property="languagePopup" destination="39U-7I-fEm" id="X38-8k-EEi"/>
<outlet property="launchSetupAgain" destination="vYi-Hf-cI5" id="yqJ-SP-aSk"/>
Expand All @@ -39,10 +39,10 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="811" height="530"/>
<rect key="frame" x="0.0" y="0.0" width="811" height="715"/>
<subviews>
<box boxType="custom" borderType="none" borderWidth="0.0" title="Box" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yjL-IP-0lB">
<rect key="frame" x="0.0" y="477" width="811" height="53"/>
<rect key="frame" x="0.0" y="662" width="811" height="53"/>
<view key="contentView" id="dCt-bT-aI2">
<rect key="frame" x="0.0" y="0.0" width="811" height="53"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -80,13 +80,13 @@
</constraints>
</box>
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6Ha-9D-VMf">
<rect key="frame" x="0.0" y="0.0" width="811" height="478"/>
<rect key="frame" x="0.0" y="0.0" width="811" height="663"/>
<clipView key="contentView" id="EPP-mS-BQX">
<rect key="frame" x="1" y="1" width="809" height="476"/>
<rect key="frame" x="1" y="1" width="809" height="661"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="TLS-nM-OqY">
<rect key="frame" x="0.0" y="-134" width="809" height="610"/>
<rect key="frame" x="0.0" y="51" width="809" height="610"/>
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XOJ-kW-rZe">
<rect key="frame" x="227" y="519" width="85" height="17"/>
Expand Down Expand Up @@ -388,6 +388,16 @@
<action selector="muteAllMacOSSoundsClick:" target="-2" id="tPN-2g-idV"/>
</connections>
</button>
<button toolTip="Enable this if you are using inverted colors in macOS accessibility settings" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NT3-XE-JxM">
<rect key="frame" x="494" y="566" width="105" height="22"/>
<buttonCell key="cell" type="check" title="Invert colors" bezelStyle="regularSquare" imagePosition="left" controlSize="large" inset="2" id="lwf-FQ-mER">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="invertColorsCheckboxClick:" target="-2" id="aya-Dl-Uti"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="xqc-uN-D8Z" firstAttribute="centerX" secondItem="c2Y-BQ-Mg9" secondAttribute="centerX" id="18W-Sd-zDg"/>
Expand All @@ -397,6 +407,7 @@
<constraint firstItem="lzR-yN-m5b" firstAttribute="top" secondItem="Jfm-Hl-4bN" secondAttribute="bottom" constant="20" symbolic="YES" id="5R9-xG-J2v"/>
<constraint firstItem="oe5-rQ-KJu" firstAttribute="top" secondItem="4zW-Lf-b41" secondAttribute="bottom" constant="20" id="6W7-eK-3i7"/>
<constraint firstItem="tVO-Se-9Jo" firstAttribute="leading" secondItem="iIR-49-5le" secondAttribute="trailing" constant="8" symbolic="YES" id="8TE-Oa-fJN"/>
<constraint firstItem="NT3-XE-JxM" firstAttribute="leading" secondItem="8lj-ap-GSr" secondAttribute="trailing" constant="20" id="8YE-Mk-MW1"/>
<constraint firstItem="Dka-WL-c4U" firstAttribute="leading" secondItem="Jfm-Hl-4bN" secondAttribute="trailing" constant="54" id="8n9-hA-Z8p"/>
<constraint firstItem="4zW-Lf-b41" firstAttribute="top" secondItem="aZ7-cT-Z3Y" secondAttribute="bottom" constant="20" id="AS5-tg-40M"/>
<constraint firstItem="ueZ-L1-tKm" firstAttribute="leading" secondItem="XVw-x2-MRK" secondAttribute="trailing" constant="8" symbolic="YES" id="AYE-8M-CZS"/>
Expand Down Expand Up @@ -436,6 +447,7 @@
<constraint firstItem="8lj-ap-GSr" firstAttribute="leading" secondItem="tVO-Se-9Jo" secondAttribute="trailing" constant="12" id="oHW-az-0fH"/>
<constraint firstAttribute="trailing" secondItem="LK9-Dp-4je" secondAttribute="trailing" constant="20" symbolic="YES" id="onr-sK-a8L"/>
<constraint firstItem="LK9-Dp-4je" firstAttribute="leading" secondItem="TLS-nM-OqY" secondAttribute="leading" constant="20" symbolic="YES" id="pOS-5p-vmq"/>
<constraint firstItem="NT3-XE-JxM" firstAttribute="firstBaseline" secondItem="iIR-49-5le" secondAttribute="firstBaseline" id="q8I-Tk-0kw"/>
<constraint firstItem="oe5-rQ-KJu" firstAttribute="leading" secondItem="4zW-Lf-b41" secondAttribute="leading" id="qPY-ht-VCC"/>
<constraint firstItem="vYi-Hf-cI5" firstAttribute="firstBaseline" secondItem="lzR-yN-m5b" secondAttribute="firstBaseline" id="upu-g3-3Ld"/>
<constraint firstItem="lzR-yN-m5b" firstAttribute="leading" secondItem="Jfm-Hl-4bN" secondAttribute="leading" id="wZl-Er-mrV"/>
Expand All @@ -450,11 +462,11 @@
</constraints>
</clipView>
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="lDZ-9J-IhM">
<rect key="frame" x="1" y="461" width="809" height="16"/>
<rect key="frame" x="1" y="646" width="809" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="0.89552238805970152" horizontal="NO" id="68Y-fx-VNM">
<rect key="frame" x="794" y="1" width="16" height="476"/>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="68Y-fx-VNM">
<rect key="frame" x="794" y="1" width="16" height="661"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand All @@ -470,7 +482,7 @@
<constraint firstItem="6Ha-9D-VMf" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="52" id="x9a-eL-C0V"/>
<constraint firstAttribute="bottom" secondItem="6Ha-9D-VMf" secondAttribute="bottom" id="yNI-0k-oeK"/>
</constraints>
<point key="canvasLocation" x="-92.5" y="372"/>
<point key="canvasLocation" x="-92.5" y="279.5"/>
</customView>
<viewController id="d0b-m7-AaQ" userLabel="Popover View Controller">
<connections>
Expand Down

0 comments on commit b8296b5

Please sign in to comment.