Skip to content

Detect Bluetooth speaker and truncate_title #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions modules/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,42 @@ def on_scroll(self, _, event):
def on_speaker_changed(self, *_):
if not self.audio.speaker:
return

self.progress_bar.value = self.audio.speaker.volume / 100
vol_high_icon = icons.vol_high
vol_medium_icon = icons.vol_medium
vol_mute_icon = icons.vol_mute
vol_off_icon = icons.vol_off

if "bluetooth" in self.audio.speaker.icon_name:
vol_high_icon = icons.bluetooth_connected
vol_medium_icon = icons.bluetooth
vol_mute_icon = icons.bluetooth_disconnected
vol_off_icon = icons.bluetooth_disconnected

if self.audio.speaker.muted:
self.vol_button.get_child().set_markup(icons.vol_off)
self.vol_button.get_child().set_markup(vol_off_icon)
self.progress_bar.remove_style_class("zero")
self.vol_label.remove_style_class("zero")
self.progress_bar.add_style_class("muted")
self.vol_label.add_style_class("muted")
self.set_tooltip_text("0%")
return
else:
self.vol_label.remove_style_class("zero")
self.progress_bar.remove_style_class("zero")
self.progress_bar.remove_style_class("muted")
self.vol_label.remove_style_class("muted")
self.set_tooltip_text(f"{round(self.audio.speaker.volume)}%")
self.progress_bar.value = self.audio.speaker.volume / 100
if self.audio.speaker.volume > 74:
self.vol_button.get_child().set_markup(icons.vol_high)
elif self.audio.speaker.volume > 0:
self.vol_button.get_child().set_markup(icons.vol_medium)
self.vol_button.get_child().set_markup(vol_high_icon)
elif self.audio.speaker.volume > 5:
self.vol_button.get_child().set_markup(vol_medium_icon)
else:
self.vol_button.get_child().set_markup(icons.vol_mute)
self.vol_button.get_child().set_markup(vol_mute_icon)
self.vol_label.add_style_class("zero")
self.progress_bar.add_style_class("zero")

class MicSmall(Box):
def __init__(self, **kwargs):
Expand Down
8 changes: 7 additions & 1 deletion modules/notch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
from fabric.widgets.image import Image
from utils.occlusion import check_occlusion

def truncate_title(title):
parts = title.rsplit(' - ', 1)
if len(parts) == 1:
parts = title.rsplit(' — ', 1)
return parts[0] if len(parts) > 1 else title

class Notch(Window):
def __init__(self, **kwargs):
Expand Down Expand Up @@ -85,8 +90,9 @@ def __init__(self, **kwargs):
h_expand=True,
h_align="fill",
formatter=FormattedString(
f"{{'Desktop' if not win_title or win_title == 'unknown' else truncate(win_title, 64)}}",
f"{{'Desktop' if not win_title or win_title == 'unknown' else truncate(truncate_title(win_title), 64)}}",
truncate=truncate,
truncate_title=truncate_title,
),
)

Expand Down