From b0a7410dfdee09c87c31565e11b3b79f51e69d4d Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 1 Feb 2021 20:39:31 +0100 Subject: [PATCH] automated screen detection --- qtile/.config/qtile/Bars.py | 7 ++++++- qtile/.config/qtile/Screens.py | 34 +++++++++++++++++++++++++++++++--- qtile/.config/qtile/defines.py | 2 ++ qtile/.config/qtile/test.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 qtile/.config/qtile/test.py diff --git a/qtile/.config/qtile/Bars.py b/qtile/.config/qtile/Bars.py index db9649f..8d7aa1d 100644 --- a/qtile/.config/qtile/Bars.py +++ b/qtile/.config/qtile/Bars.py @@ -33,13 +33,18 @@ laptop_bar = bar.Bar([ *end_widgets(blue_color,main_bar_height,main_bar_fontsize), ],main_bar_height) -#left bar left_bar = bar.Bar([ *Left_widgets(secondary_bar_height,secondary_bar_fontsize), *volume_widget(base_color,blue_color,secondary_bar_height,secondary_bar_fontsize), *end_widgets(blue_color,secondary_bar_height,secondary_bar_fontsize) ],secondary_bar_height) +secondary_bar = bar.Bar([ + *Left_widgets(secondary_bar_height,secondary_bar_fontsize), + *volume_widget(base_color,blue_color,secondary_bar_height,secondary_bar_fontsize), + *end_widgets(blue_color,secondary_bar_height,secondary_bar_fontsize) +],secondary_bar_height) + top_bar = bar.Bar([ *Left_widgets(secondary_bar_height,secondary_bar_fontsize), *volume_widget(base_color,blue_color,secondary_bar_height,secondary_bar_fontsize), diff --git a/qtile/.config/qtile/Screens.py b/qtile/.config/qtile/Screens.py index 2fd94dd..5fd0107 100644 --- a/qtile/.config/qtile/Screens.py +++ b/qtile/.config/qtile/Screens.py @@ -1,10 +1,38 @@ +import subprocess +import re +import numpy as np + from libqtile.config import Screen -from Bars import top_bar, left_bar, main_bar,laptop_bar +from Bars import top_bar, left_bar, main_bar,laptop_bar, secondary_bar +from defines import main_screen_res, top_screen_res screens = [ # Screen(bottom=top_bar), # Screen(top=left_bar), # Screen(top=main_bar), - Screen(top=laptop_bar) -] \ No newline at end of file + # Screen(top=laptop_bar) +] + + +cmd = ['xrandr'] +p = subprocess.Popen(cmd, stdout=subprocess.PIPE) +resolution_string, junk = p.communicate() +p.stdout.close() +screen_resolutions = [np.array(screen_res.split('x')).astype(np.int) for screen_res in re.findall('[0-9]+x[0-9]+(?=[^\\\\n]*\*)',str(resolution_string))] +number_of_screens = len(screen_resolutions) +max_width = max(screen_resolutions, key=lambda res: res[0])[0] +defined_main_window = False +for width, height in screen_resolutions: + if width == main_screen_res[0] and height == main_screen_res[1]: + screens.append(Screen(top=main_bar)) + defined_main_window = True + elif width == top_screen_res[0] and height == top_screen_res[1]: + screens.append(Screen(bottom=top_bar)) + elif width < height: + screens.append(Screen(top=left_bar)) + elif width == max_width and not defined_main_window: + screens.append(Screen(top=laptop_bar)) + defined_main_window = True + else: + screens.append(Screen(top=secondary_bar)) \ No newline at end of file diff --git a/qtile/.config/qtile/defines.py b/qtile/.config/qtile/defines.py index 1208d5f..37b786c 100644 --- a/qtile/.config/qtile/defines.py +++ b/qtile/.config/qtile/defines.py @@ -3,6 +3,8 @@ focus_color = '#bd93f9' border_width = 2 mod = 'mod4' hotkey_file='/home/paul/Hotkeys' +main_screen_res = [3840,1440] +top_screen_res = [1440,780] #region colors light_foreground_color = ['#f8f8f2','#f8f8f2'] diff --git a/qtile/.config/qtile/test.py b/qtile/.config/qtile/test.py new file mode 100644 index 0000000..3b05375 --- /dev/null +++ b/qtile/.config/qtile/test.py @@ -0,0 +1,29 @@ +# This is a test file for anything. +screens = [] +main_screen_res = [3840,1440] +top_screen_res = [1440,780] + +import subprocess +import re +import numpy as np + +cmd = ['xrandr'] +p = subprocess.Popen(cmd, stdout=subprocess.PIPE) +resolution_string, junk = p.communicate() +p.stdout.close() +screen_resolutions = [np.array(screen_res.split('x')).astype(np.int) for screen_res in re.findall('[0-9]+x[0-9]+(?=[^\\\\n]*\*)',str(resolution_string))] +number_of_screens = len(screen_resolutions) +max_width = max(screen_resolutions, key=lambda res: res[0])[0] +defined_main_window = False +for width, height in screen_resolutions: + if width == main_screen_res[0] and height == main_screen_res[1]: + screens+=['main_screen'] + defined_main_window = True + elif width == top_screen_res[0] and height == top_screen_res[1]: + screens+=['top_screen'] + elif width == max_width and not defined_main_window: + screens+=['laptop_screen'] + defined_main_window = True + else: + screens+=['peripheral_screen'] +print(screens) \ No newline at end of file