From d8a5dbb367a568b8fefc59f6bbc8e5db2cfdd19b Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 12 Apr 2019 07:05:43 +0100 Subject: [PATCH] moved displays to settings file --- .gitignore | 3 ++- brightness.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 75ec3f0..7af18e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode/* \ No newline at end of file +.vscode/* +settings.json diff --git a/brightness.py b/brightness.py index ac67c2a..7d263f9 100755 --- a/brightness.py +++ b/brightness.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import os, sys, string, subprocess +import os, sys, string, subprocess, json def main(): cmd = "xrandr --verbose | grep {} -A 5 | grep Brightness | cut -f 2 -d ' '".format(display()) @@ -13,12 +13,22 @@ def main(): os.system("xrandr --output {} --brightness {}".format(display(), brightness)) def display(): - cmd = "xdotool getmouselocation --shell | head -n -3 | sed 's/[^0-9]*//g'" + cmd = "xdotool getmouselocation --shell | head -n -3 | cut -d'=' -f2-" cmd = subprocess.getoutput(cmd) + + #print(getDisplay()['display0']); if int(cmd) < 2560: - return "DisplayPort-0" - return "DisplayPort-1" + return getDisplay()['display1'] + return getDisplay()['display0'] + +def getDisplay(): + root_dir = os.path.dirname(os.path.realpath(__file__)) + json_path = os.path.join(root_dir, 'settings.json') + with open(json_path, 'r') as json_data: + settings = json.load(json_data) + json_data.close() + return settings if len(sys.argv) <= 1: print("Usage: {} [+|-]".format(sys.argv[0]))