From 72c660e74a8d32e547c07ff2190b81263b0ab78f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 16 Oct 2019 20:37:31 +0200 Subject: Add brightness correction for OS X 10.15 Catalina Since upgrading to 10.15 Catalina, when my external monitor is plugged in and I wake up my machine, for some unexplained reason the internal display resets to maximum brightness. Fix Catalina's nonsense on wake by resetting to the brightness from before sleep. --- catalina_brightness_bullshit.lua | 47 ++++++++++++++++++++++++++++++++++++++++ init.lua | 1 + 2 files changed, 48 insertions(+) create mode 100644 catalina_brightness_bullshit.lua diff --git a/catalina_brightness_bullshit.lua b/catalina_brightness_bullshit.lua new file mode 100644 index 0000000..17d5bde --- /dev/null +++ b/catalina_brightness_bullshit.lua @@ -0,0 +1,47 @@ +-- When an external monitor is connected, saves internal screen brightness when +-- locking the screen or sleeping. Restores the saved brightness level on +-- unlock or wake. Fixes OS X 10.15 Catalina's bullshit where unlocking my +-- machine caused the internal screen's brightness to be reset to the maximum. + +-- Copyright (c) 2019 Teddy Wing +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + + +-- Default brightness to 50%. +cbb_brightness = 50 + +cbb_logger = hs.logger.new('catalina_brightness_bullshit', 'debug') + +cbb_wake_watcher = hs.caffeinate.watcher.new(function(event_type) + -- Only run if the external monitor is connected. + if hs.screen.primaryScreen():name() ~= 'G247HL' then + cbb_logger:d('no external monitor') + + return + end + + if event_type == hs.caffeinate.watcher.screensDidLock + or event_type == hs.caffeinate.watcher.screensDidSleep then + cbb_brightness = hs.brightness.get() + + cbb_logger:d('saved brightness: ', cbb_brightness) + elseif event_type == hs.caffeinate.watcher.screensDidUnlock + or event_type == hs.caffeinate.watcher.screensDidWake then + hs.brightness.set(cbb_brightness) + + cbb_logger:d('restored brightness: ', cbb_brightness) + end +end) +cbb_wake_watcher:start() diff --git a/init.lua b/init.lua index a8203eb..7a65cd8 100644 --- a/init.lua +++ b/init.lua @@ -18,6 +18,7 @@ require("hs.ipc") require('application_switch') +require('catalina_brightness_bullshit') require('gdrive_mouseover_item') require('mouse') require('terminal_tab_hotkeys') -- cgit v1.2.3