Add macbook brightness
This commit is contained in:
parent
be8afa398d
commit
aa502f8d73
@ -1013,8 +1013,8 @@ addKeys conf@XConfig { modMask = modm } =
|
|||||||
, ((hyper .|. shiftMask, xK_q), spawn "toggle_mute_current_window.sh")
|
, ((hyper .|. shiftMask, xK_q), spawn "toggle_mute_current_window.sh")
|
||||||
, ((hctrl, xK_q), spawn "toggle_mute_current_window.sh only")
|
, ((hctrl, xK_q), spawn "toggle_mute_current_window.sh only")
|
||||||
|
|
||||||
, ((0, xF86XK_MonBrightnessUp), spawn "show_brightness.sh")
|
, ((0, xF86XK_MonBrightnessUp), spawn "brightness.sh 5")
|
||||||
, ((0, xF86XK_MonBrightnessDown), spawn "show_brightness.sh")
|
, ((0, xF86XK_MonBrightnessDown), spawn "brightness.sh -5")
|
||||||
|
|
||||||
] ++
|
] ++
|
||||||
|
|
||||||
|
3
dotfiles/lib/bin/brightness.sh
Executable file
3
dotfiles/lib/bin/brightness.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
volnoti-show $(sudo macbook_brightness.py -c "$@" -p)
|
75
dotfiles/lib/bin/macbook_brightness.py
Executable file
75
dotfiles/lib/bin/macbook_brightness.py
Executable file
@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class BrightnessManager(object):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_path(cls, path):
|
||||||
|
return cls(
|
||||||
|
set_brightness_filepath=os.path.join(path, "brightness"),
|
||||||
|
actual_brightness_filepath=os.path.join(path, "actual_brightness"),
|
||||||
|
max_brightness_filepath=os.path.join(path, "max_brightness"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, set_brightness_filepath, max_brightness_filepath, actual_brightness_filepath
|
||||||
|
):
|
||||||
|
self.set_brightness_filepath = set_brightness_filepath
|
||||||
|
self.max_brightness_filepath = max_brightness_filepath
|
||||||
|
self.actual_brightness_filepath = actual_brightness_filepath
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_brightness(self):
|
||||||
|
with open(self.actual_brightness_filepath) as fd:
|
||||||
|
return int(fd.read())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_brightness(self):
|
||||||
|
with open(self.max_brightness_filepath) as fd:
|
||||||
|
return int(fd.read())
|
||||||
|
|
||||||
|
@current_brightness.setter
|
||||||
|
def current_brightness(self, brightness):
|
||||||
|
with open(self.set_brightness_filepath, 'w') as fd:
|
||||||
|
fd.write(str(brightness))
|
||||||
|
|
||||||
|
def increment_by_proportion(self, proportion):
|
||||||
|
new_brightness = self.current_brightness + int(self.max_brightness * proportion)
|
||||||
|
new_brightness = min(new_brightness, self.max_brightness)
|
||||||
|
self.current_brightness = new_brightness
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_proportion(self):
|
||||||
|
return float(self.current_brightness) / self.max_brightness
|
||||||
|
|
||||||
|
|
||||||
|
IntelBrightnessManager = BrightnessManager.from_path(
|
||||||
|
"/sys/class/backlight/intel_backlight",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def build_parser():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Interact with macbook brightness',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--change", "-c",
|
||||||
|
help="Change volume by the given percentage",
|
||||||
|
default=0
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--print", "-p", dest="do_print",
|
||||||
|
action='store_true',
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = build_parser().parse_args()
|
||||||
|
IntelBrightnessManager.increment_by_proportion(float(args.change) / 100)
|
||||||
|
if args.do_print:
|
||||||
|
print(int(IntelBrightnessManager.current_proportion * 100))
|
@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
actual="$(cat /sys/class/backlight/intel_backlight/actual_brightness)"
|
|
||||||
max="$(cat /sys/class/backlight/intel_backlight/max_brightness)"
|
|
||||||
|
|
||||||
temp="$(( $actual * 100 ))"
|
|
||||||
percentage="$(( $temp/$max ))"
|
|
||||||
|
|
||||||
volnoti-show "$percentage"
|
|
Loading…
Reference in New Issue
Block a user