add music layer and widget
This commit is contained in:
parent
fac7a898bd
commit
c2753de7aa
|
@ -0,0 +1,214 @@
|
|||
from libqtile.config import Screen
|
||||
from libqtile import bar, widget
|
||||
from enum import Enum
|
||||
import my_globals
|
||||
import os
|
||||
from screeninfo import get_monitors
|
||||
|
||||
|
||||
def get_screens():
|
||||
screen_count = len(get_monitors())
|
||||
screens = []
|
||||
for s in range(screen_count):
|
||||
screens.append(
|
||||
Screen(
|
||||
top=bar.Bar(
|
||||
_get_bar_contents(
|
||||
primary=True if s == 0 else False,
|
||||
),
|
||||
18,
|
||||
background=my_globals.colors["bg"],
|
||||
)
|
||||
)
|
||||
)
|
||||
return screens
|
||||
|
||||
|
||||
def get_defaults():
|
||||
return dict(
|
||||
font="CaskaydiaCove Nerd Font",
|
||||
fontsize=14,
|
||||
padding=6,
|
||||
)
|
||||
|
||||
|
||||
class _PowerLineDirection(Enum):
|
||||
LEFT = 0
|
||||
RIGHT = 1
|
||||
|
||||
|
||||
class _Accent(Enum):
|
||||
A = my_globals.colors["accent-dark"]
|
||||
B = my_globals.colors["bg-light"]
|
||||
|
||||
|
||||
def _get_powerline_arrow(direction: _PowerLineDirection, accent: _Accent, end=False):
|
||||
text = ""
|
||||
if direction is _PowerLineDirection.RIGHT:
|
||||
text = ""
|
||||
|
||||
bg = _Accent.B.value
|
||||
if end:
|
||||
bg = my_globals.colors["bg"]
|
||||
elif accent is _Accent.B:
|
||||
bg = _Accent.A.value
|
||||
|
||||
return widget.TextBox(
|
||||
font="CaskaydiaCove Nerd Font Mono",
|
||||
text=text,
|
||||
foreground=accent.value,
|
||||
background=bg,
|
||||
fontsize=22,
|
||||
padding=0,
|
||||
markup=False,
|
||||
max_chars=1,
|
||||
)
|
||||
|
||||
|
||||
_net = widget.TextBox(
|
||||
**get_defaults(),
|
||||
background=my_globals.colors["accent-dark"],
|
||||
foreground=my_globals.colors["on-accent-dark"],
|
||||
text="",
|
||||
)
|
||||
|
||||
_netgraph = widget.NetGraph(
|
||||
**get_defaults(),
|
||||
type="linefill",
|
||||
border_width=0,
|
||||
graph_color=my_globals.colors["on-accent-dark"],
|
||||
fill_color=my_globals.colors["on-accent-dark"],
|
||||
background=my_globals.colors["accent-dark"],
|
||||
)
|
||||
|
||||
|
||||
_cpu = widget.TextBox(
|
||||
**get_defaults(),
|
||||
background=my_globals.colors["accent-dark"],
|
||||
foreground=my_globals.colors["on-accent-dark"],
|
||||
text="",
|
||||
)
|
||||
|
||||
_cpu_graph = widget.CPUGraph(
|
||||
**get_defaults(),
|
||||
type="linefill",
|
||||
border_width=0,
|
||||
graph_color=my_globals.colors["on-accent-dark"],
|
||||
fill_color=my_globals.colors["on-accent-dark"],
|
||||
background=my_globals.colors["accent-dark"],
|
||||
)
|
||||
|
||||
|
||||
_weather = widget.OpenWeather(
|
||||
**get_defaults(),
|
||||
background=_Accent.A.value,
|
||||
location="Hamburg",
|
||||
foreground=my_globals.colors["on-accent-dark"],
|
||||
format="{icon} {main_temp}°{units_temperature} {weather_details}",
|
||||
)
|
||||
|
||||
_tray = widget.Systray(
|
||||
**get_defaults(),
|
||||
background=_Accent.A.value,
|
||||
foreground=my_globals.colors["on-accent-light"],
|
||||
)
|
||||
|
||||
_groups = widget.GroupBox(
|
||||
**get_defaults(),
|
||||
highlight_method="line",
|
||||
hide_unused=True,
|
||||
borderwidth=my_globals.border_width,
|
||||
background=my_globals.colors["bg-light"],
|
||||
this_screen_border=my_globals.colors["accent-dark"],
|
||||
this_current_screen_border=my_globals.colors["accent-light"],
|
||||
other_screen_border=my_globals.colors["accent-dark"],
|
||||
other_current_screen_border=my_globals.colors["accent-light"],
|
||||
active=my_globals.colors["on-bg"],
|
||||
inactive=my_globals.colors["on-bg"],
|
||||
urgent_border=my_globals.colors["warning"],
|
||||
urgent_text=my_globals.colors["warning"],
|
||||
urgent_alert_method="line",
|
||||
highlight_color=[
|
||||
my_globals.colors["bg-light"],
|
||||
my_globals.colors["bg-light"],
|
||||
],
|
||||
)
|
||||
|
||||
_window_name = widget.WindowName(
|
||||
**get_defaults(),
|
||||
for_current_screen=True,
|
||||
)
|
||||
|
||||
_clock = widget.Clock(
|
||||
**get_defaults(),
|
||||
format="%d.%m.%y %H:%M:%S",
|
||||
background=my_globals.colors["accent-dark"],
|
||||
foreground=my_globals.colors["on-accent-dark"],
|
||||
)
|
||||
|
||||
_updates = widget.CheckUpdates(
|
||||
**get_defaults(),
|
||||
update_interval=3600,
|
||||
distro="Debian",
|
||||
display_format=" {updates} updates",
|
||||
no_update_string=" " + os.getlogin() + "@" + os.uname()[1],
|
||||
)
|
||||
|
||||
_volume = widget.Volume(
|
||||
**get_defaults(),
|
||||
background=my_globals.colors["bg-light"],
|
||||
volume_app="pavucontrol",
|
||||
fmt="蓼 {}",
|
||||
)
|
||||
|
||||
_music = widget.GenPollText(
|
||||
**get_defaults(),
|
||||
)
|
||||
|
||||
_chords = widget.Chord(
|
||||
**get_defaults(),
|
||||
background=my_globals.colors["bg-light"],
|
||||
)
|
||||
|
||||
|
||||
def _get_current_layout():
|
||||
return widget.CurrentLayout(
|
||||
**get_defaults(), background=my_globals.colors["bg-light"], fmt=" {}"
|
||||
)
|
||||
|
||||
|
||||
def _get_bar_contents(primary=False):
|
||||
l = [
|
||||
_get_powerline_arrow(_PowerLineDirection.LEFT, _Accent.A),
|
||||
_chords,
|
||||
_get_current_layout(),
|
||||
_groups,
|
||||
_get_powerline_arrow(
|
||||
_PowerLineDirection.LEFT,
|
||||
_Accent.B,
|
||||
end=True,
|
||||
),
|
||||
_window_name,
|
||||
widget.Spacer(**get_defaults(), length=bar.STRETCH),
|
||||
_updates,
|
||||
_get_powerline_arrow(
|
||||
_PowerLineDirection.RIGHT,
|
||||
_Accent.B,
|
||||
end=True,
|
||||
),
|
||||
_volume,
|
||||
_music,
|
||||
_get_powerline_arrow(_PowerLineDirection.RIGHT, _Accent.A),
|
||||
_clock,
|
||||
_weather,
|
||||
]
|
||||
if primary:
|
||||
l.insert(0, _tray)
|
||||
else:
|
||||
l = [
|
||||
_net,
|
||||
_netgraph,
|
||||
_cpu,
|
||||
_cpu_graph,
|
||||
] + l
|
||||
return l
|
|
@ -0,0 +1,12 @@
|
|||
import subprocess
|
||||
|
||||
|
||||
def get_currently_playing():
|
||||
output = subprocess.run(
|
||||
["playerctl", "metadata", "--format", r"{{artist}} - {{title}}"],
|
||||
stdout=subprocess.PIPE,
|
||||
).stdout.decode("utf-8")
|
||||
return output
|
||||
|
||||
|
||||
print(get_currently_playing())
|
|
@ -1,3 +1,4 @@
|
|||
import subprocess
|
||||
from libqtile.lazy import lazy
|
||||
|
||||
|
||||
|
@ -6,3 +7,17 @@ def set_all_float_windows_to_non_floating_mode(qtile):
|
|||
for window in qtile.current_group.windows:
|
||||
if window.floating:
|
||||
window.cmd_disable_floating()
|
||||
|
||||
|
||||
def get_currently_playing():
|
||||
output: str = (
|
||||
subprocess.run(
|
||||
["playerctl", "metadata", "--format", r"{{artist}} - {{title}}"],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
.stdout.decode("utf-8")
|
||||
.strip()
|
||||
)
|
||||
if output[0] == "-":
|
||||
return ""
|
||||
return output
|
||||
|
|
24
my_keys.py
24
my_keys.py
|
@ -1,12 +1,29 @@
|
|||
from libqtile.config import Key
|
||||
from libqtile.config import Key, KeyChord
|
||||
from libqtile.lazy import lazy
|
||||
|
||||
import my_functions
|
||||
import my_globals
|
||||
|
||||
mod, terminal = my_globals.mod, my_globals.terminal
|
||||
|
||||
_mediaChord = KeyChord(
|
||||
[mod],
|
||||
"m",
|
||||
[
|
||||
Key([], "j", lazy.spawn("pactl set-sink-volume 0 -10%")),
|
||||
Key(["shift"], "j", lazy.spawn("playerctl volume 0.1-")),
|
||||
Key([], "k", lazy.spawn("pactl set-sink-volume 0 +10%")),
|
||||
Key(["shift"], "k", lazy.spawn("playerctl volume 0.1+")),
|
||||
Key([], "m", lazy.spawn("pactl set-sink-mute 0 toggle")),
|
||||
Key([], "space", lazy.spawn("playerctl play-pause")),
|
||||
Key([], "l", lazy.spawn("playerctl next")),
|
||||
Key([], "h", lazy.spawn("playerctl previous")),
|
||||
],
|
||||
mode=" media",
|
||||
)
|
||||
|
||||
|
||||
def get_defaults():
|
||||
mod, terminal = my_globals.mod, my_globals.terminal
|
||||
return [
|
||||
# A list of available commands that can be bound to keys can be found
|
||||
# at https://docs.qtile.org/en/latest/manual/config/lazy.html
|
||||
|
@ -88,5 +105,4 @@ def get_defaults():
|
|||
),
|
||||
desc="rofi",
|
||||
),
|
||||
]
|
||||
|
||||
] + [_mediaChord]
|
||||
|
|
|
@ -2,6 +2,7 @@ from libqtile.config import Screen
|
|||
from libqtile import bar, widget
|
||||
from enum import Enum
|
||||
import my_globals
|
||||
import my_functions
|
||||
import os
|
||||
from screeninfo import get_monitors
|
||||
|
||||
|
@ -151,7 +152,7 @@ _updates = widget.CheckUpdates(
|
|||
update_interval=3600,
|
||||
distro="Debian",
|
||||
display_format=" {updates} updates",
|
||||
no_update_string=os.uname()[2] + " " + os.getlogin() + "@" + os.uname()[1],
|
||||
no_update_string=" " + os.getlogin() + "@" + os.uname()[1],
|
||||
)
|
||||
|
||||
_volume = widget.Volume(
|
||||
|
@ -161,6 +162,18 @@ _volume = widget.Volume(
|
|||
fmt="蓼 {}",
|
||||
)
|
||||
|
||||
_music = widget.GenPollText(
|
||||
**get_defaults(),
|
||||
update_interval=5,
|
||||
background=_Accent.B.value,
|
||||
func=my_functions.get_currently_playing,
|
||||
)
|
||||
|
||||
_chords = widget.Chord(
|
||||
**get_defaults(),
|
||||
background=my_globals.colors["bg-light"],
|
||||
)
|
||||
|
||||
|
||||
def _get_current_layout():
|
||||
return widget.CurrentLayout(
|
||||
|
@ -168,18 +181,10 @@ def _get_current_layout():
|
|||
)
|
||||
|
||||
|
||||
_mpris = widget.Mpris2(
|
||||
**get_defaults(),
|
||||
display_metadata=[
|
||||
"xesam:title",
|
||||
"xesam:artist",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def _get_bar_contents(primary=False):
|
||||
l = [
|
||||
_get_powerline_arrow(_PowerLineDirection.LEFT, _Accent.A),
|
||||
_chords,
|
||||
_get_current_layout(),
|
||||
_groups,
|
||||
_get_powerline_arrow(
|
||||
|
@ -196,7 +201,7 @@ def _get_bar_contents(primary=False):
|
|||
end=True,
|
||||
),
|
||||
_volume,
|
||||
_mpris,
|
||||
_music,
|
||||
_get_powerline_arrow(_PowerLineDirection.RIGHT, _Accent.A),
|
||||
_clock,
|
||||
_weather,
|
||||
|
|
2
setup.sh
2
setup.sh
|
@ -3,7 +3,7 @@
|
|||
sudo apt install xserver-xorg xinit
|
||||
sudo apt install libpangocairo-1.0-0
|
||||
sudo apt install python3-pip python3-xcffib python3-cairocffi
|
||||
sudo apt install rofi kitty xosd-bin flameshot xfce4-power-manager apt-show-versions python3-screeninfo
|
||||
sudo apt install rofi kitty xosd-bin flameshot xfce4-power-manager apt-show-versions python3-screeninfo pulseaudio-utils playerctl
|
||||
|
||||
sudo pip install qtile dbus-next
|
||||
|
||||
|
|
Loading…
Reference in New Issue