Created
July 16, 2014 11:52
-
-
Save fourdollars/96713d984288beb215b0 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env python | |
# -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- | |
# | |
# Copyright (C) 2014 Shih-Yuan Lee (FourDollars) <sylee@canonical.com> | |
# | |
# 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 <http://www.gnu.org/licenses/>. | |
import argparse | |
import subprocess | |
import syslog | |
CMD='/usr/lib/unity-settings-daemon/usd-backlight-helper.orig' | |
def set_brightness(brightness): | |
maximum = int(subprocess.check_output([CMD, '--get-max-brightness']).strip()) | |
step = maximum / 100 | |
delta = maximum - step * 100 | |
pseudo = brightness * step + delta | |
subprocess.call([CMD, '--set-brightness', str(pseudo)]) | |
syslog.syslog("Set %d" % pseudo) | |
def get_max_brightness(): | |
print("100") | |
syslog.syslog("Max 100") | |
def get_brightness(): | |
maximum = int(subprocess.check_output([CMD, '--get-max-brightness']).strip()) | |
step = maximum / 100 | |
delta = maximum - step * 100 | |
brightness = int(subprocess.check_output([CMD, '--get-brightness']).strip()) | |
pseudo = (brightness - delta) / step | |
print("%d" % pseudo) | |
syslog.syslog("Get %d" % pseudo) | |
def main(): | |
""" | |
Usage: | |
fake-backlight-helper [OPTION...] | |
FAKE Settings Daemon Backlight Helper | |
Help Options: | |
-h, --help Show help options | |
Application Options: | |
--set-brightness Set the current brightness | |
--get-brightness Get the current brightness | |
--get-max-brightness Get the number of brightness levels supported | |
""" | |
parser = argparse.ArgumentParser(description="FAKE Settings Daemon Backlight Helper") | |
parser.add_argument("--get-brightness", help="Get the current brightness", action="store_true") | |
parser.add_argument("--get-max-brightness", help="Get the number of brightness levels supported", action="store_true") | |
parser.add_argument("--set-brightness", help="Set the current brightness", type=int) | |
args = parser.parse_args() | |
if args.get_max_brightness: | |
get_max_brightness() | |
elif args.get_brightness: | |
get_brightness() | |
elif args.set_brightness is not None: | |
set_brightness(args.set_brightness) | |
else: | |
parser.print_help() | |
if __name__ == '__main__': | |
main() | |
# vim:fileencodings=utf-8:expandtab:tabstop=4:shiftwidth=4:softtabstop=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment