aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalina_brightness_bullshit.lua47
-rw-r--r--init.lua1
2 files changed, 48 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>.
+
+
+-- 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')