refactor(qtile): improve conditionals
This commit is contained in:
parent
654a7685a3
commit
e51e5e1cf9
1 changed files with 43 additions and 59 deletions
|
@ -17,6 +17,8 @@ from libqtile.lazy import lazy
|
||||||
from libqtile.utils import guess_terminal
|
from libqtile.utils import guess_terminal
|
||||||
|
|
||||||
|
|
||||||
|
LAPTOP = os.getenv("LAPTOP", False)
|
||||||
|
|
||||||
colors = [
|
colors = [
|
||||||
# panel background
|
# panel background
|
||||||
["#282c34", "#282c34"], # 0
|
["#282c34", "#282c34"], # 0
|
||||||
|
@ -87,6 +89,10 @@ def run_command(*args, **kwargs):
|
||||||
return os.popen(*args, **kwargs).read()
|
return os.popen(*args, **kwargs).read()
|
||||||
|
|
||||||
|
|
||||||
|
def optional_list(condition, lst):
|
||||||
|
return lst if condition else []
|
||||||
|
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
keys = [
|
keys = [
|
||||||
# Switch between windows
|
# Switch between windows
|
||||||
|
@ -335,15 +341,20 @@ keys = [
|
||||||
),
|
),
|
||||||
|
|
||||||
# Brightness
|
# Brightness
|
||||||
Key(
|
*optional_list(
|
||||||
[], "XF86MonBrightnessUp",
|
LAPTOP,
|
||||||
lazy.spawn("brightnessctl set +5%"),
|
[
|
||||||
desc="Increase brightness",
|
Key(
|
||||||
),
|
[], "XF86MonBrightnessUp",
|
||||||
Key(
|
lazy.spawn("brightnessctl set +5%"),
|
||||||
[], "XF86MonBrightnessDown",
|
desc="Increase brightness",
|
||||||
lazy.spawn("brightnessctl set 5%-"),
|
),
|
||||||
desc="Decrease brightness",
|
Key(
|
||||||
|
[], "XF86MonBrightnessDown",
|
||||||
|
lazy.spawn("brightnessctl set 5%-"),
|
||||||
|
desc="Decrease brightness",
|
||||||
|
)
|
||||||
|
]
|
||||||
),
|
),
|
||||||
|
|
||||||
# Application shortcuts
|
# Application shortcuts
|
||||||
|
@ -519,27 +530,28 @@ def init_widget_list(main=True, laptop=False):
|
||||||
),
|
),
|
||||||
widget.Sep(linewidth=0, padding=40, foreground=colors[2], background=colors[0]),
|
widget.Sep(linewidth=0, padding=40, foreground=colors[2], background=colors[0]),
|
||||||
widget.WindowName(foreground=colors[6], background=colors[0], padding=0),
|
widget.WindowName(foreground=colors[6], background=colors[0], padding=0),
|
||||||
*(
|
*optional_list(
|
||||||
|
main,
|
||||||
[
|
[
|
||||||
widget.Systray(background=colors[0], padding=5),
|
widget.Systray(background=colors[0], padding=5),
|
||||||
]
|
],
|
||||||
if main
|
|
||||||
else []
|
|
||||||
),
|
),
|
||||||
widget.Sep(linewidth=0, padding=6, foreground=colors[0], background=colors[0]),
|
widget.Sep(linewidth=0, padding=6, foreground=colors[0], background=colors[0]),
|
||||||
*create_powerline(
|
*create_powerline(
|
||||||
[
|
[
|
||||||
# Widgets only found on the main screen's powerline
|
# Widgets only found on the main screen's powerline
|
||||||
*(
|
*optional_list(
|
||||||
|
main,
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
*sum(
|
*sum(
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
*(
|
*optional_list(
|
||||||
[widget.Sep(linewidth=2, padding=3)]
|
i != 0,
|
||||||
if i != 0
|
[
|
||||||
else []
|
widget.Sep(linewidth=2, padding=3),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
widget.TextBox(text=f"{interface}:", padding=2),
|
widget.TextBox(text=f"{interface}:", padding=2),
|
||||||
widget.Net(
|
widget.Net(
|
||||||
|
@ -558,32 +570,18 @@ def init_widget_list(main=True, laptop=False):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
widget.TextBox(
|
widget.TextBox(text="", padding=0, fontsize=24),
|
||||||
text="",
|
widget.Memory(padding=5),
|
||||||
padding=0,
|
|
||||||
fontsize=24,
|
|
||||||
),
|
|
||||||
widget.Memory(
|
|
||||||
padding=5,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
widget.TextBox(
|
widget.TextBox(text=" Vol:", padding=0),
|
||||||
text=" Vol:",
|
widget.Volume(padding=5),
|
||||||
padding=0,
|
|
||||||
),
|
|
||||||
widget.Volume(
|
|
||||||
padding=5,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
*(
|
*optional_list(
|
||||||
|
laptop,
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
widget.TextBox(
|
widget.TextBox(text=" 🔆", padding=0, fontsize=14),
|
||||||
text=" 🔆",
|
|
||||||
padding=0,
|
|
||||||
fontsize=14,
|
|
||||||
),
|
|
||||||
widget.Backlight(
|
widget.Backlight(
|
||||||
backlight_name=(
|
backlight_name=(
|
||||||
run_command(
|
run_command(
|
||||||
|
@ -604,24 +602,14 @@ def init_widget_list(main=True, laptop=False):
|
||||||
padding=5,
|
padding=5,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
]
|
],
|
||||||
if laptop
|
|
||||||
else []
|
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
if main
|
|
||||||
else []
|
|
||||||
),
|
),
|
||||||
# Widgets found on the powerline of all screens
|
# Widgets found on the powerline of all screens
|
||||||
[
|
[
|
||||||
widget.CurrentLayoutIcon(
|
widget.CurrentLayoutIcon(padding=0, scale=0.7),
|
||||||
custom_icon_paths=[os.path.expanduser("~/.config/qtile/icons")],
|
widget.CurrentLayout(padding=5),
|
||||||
padding=0,
|
|
||||||
scale=0.7,
|
|
||||||
),
|
|
||||||
widget.CurrentLayout(
|
|
||||||
padding=5,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
widget.Clock(
|
widget.Clock(
|
||||||
|
@ -644,7 +632,7 @@ def init_widget_list(main=True, laptop=False):
|
||||||
screens = [
|
screens = [
|
||||||
Screen(
|
Screen(
|
||||||
bottom=bar.Bar(
|
bottom=bar.Bar(
|
||||||
init_widget_list(main=(i == 0), laptop=os.getenv("LAPTOP", False)),
|
init_widget_list(main=(i == 0), laptop=LAPTOP),
|
||||||
size=20,
|
size=20,
|
||||||
opacity=1.0,
|
opacity=1.0,
|
||||||
),
|
),
|
||||||
|
@ -652,11 +640,7 @@ screens = [
|
||||||
wallpaper_mode="fill",
|
wallpaper_mode="fill",
|
||||||
)
|
)
|
||||||
for i in range(
|
for i in range(
|
||||||
int(
|
int(run_command("xrandr --listmonitors | grep 'Monitors:' | awk {'print $2'}"))
|
||||||
os.popen(
|
|
||||||
"xrandr --listmonitors | grep 'Monitors:' | awk {'print $2'}"
|
|
||||||
).read()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue