Skip to content

Instantly share code, notes, and snippets.

@vaibhav93
Last active August 11, 2020 23:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vaibhav93/20500065786327e55c2f438a3922a7ae to your computer and use it in GitHub Desktop.
Save vaibhav93/20500065786327e55c2f438a3922a7ae to your computer and use it in GitHub Desktop.
Adjust brightness when switching to chrome workspace in i3
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()
@vaibhav93
Copy link
Author

vaibhav93 commented Apr 27, 2019

$ 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.

@orhun
Copy link

orhun commented Aug 11, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment