Last active
August 11, 2020 23:16
-
-
Save vaibhav93/20500065786327e55c2f438a3922a7ae to your computer and use it in GitHub Desktop.
Adjust brightness when switching to chrome workspace in i3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import i3ipc | |
import os | |
SET_BRIGHTNESS = 'xbacklight -set ' | |
GET_BRIGHTNESS = 'xbacklight' | |
i3 = i3ipc.Connection() | |
class BrightnessController: | |
def __init__(self): | |
self.brightness_map = {} | |
# Subscribe to events | |
i3.on('workspace::focus', self.on_workspace_focus) | |
# Start main loop | |
i3.main() | |
def get_brightness(self): | |
return os.popen(GET_BRIGHTNESS).read() | |
def set_brightness(self,brightness): | |
os.system(SET_BRIGHTNESS + brightness) | |
# Define a callback to be called when you switch workspaces. | |
def on_workspace_focus(self, connection, e): | |
current_brightness = float(self.get_brightness()) | |
#print(current_brightness) | |
if e.old: | |
self.brightness_map[e.old.id] = str(current_brightness) | |
if e.current: | |
if e.current.id in self.brightness_map: | |
self.set_brightness(self.brightness_map[e.current.id]) | |
bc = BrightnessController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ python auto_brightness.py &
Each workspace can have its own brightness level which is set when moving out to other workspace. Upon return, old brightness is set.