Skip to content
Merged
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
19 changes: 19 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ tooltip > * {
background-color: var(--shadow);
transition: all 0.1s ease;
}
.VolumeWidget {
margin: 20px;
}
#button-bar-vol {
padding-left: 4px;
padding-right: 4px;
min-width: 28px;
min-height: 28px;
margin-top: 4px;
border-radius: 16px;
background-color: var(--shadow);
transition: all 0.1s ease;
}
#button-volume {
background-color: var(--shadow);
color: var(--shadow);
border: solid 0px var(--primary);
transition: all 0.1s ease;
}

#button-bar-label {
color: var(--primary);
Expand Down
83 changes: 82 additions & 1 deletion modules/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,84 @@
import modules.data as data
from modules.battery import Battery

from fabric.widgets.overlay import Overlay
from fabric.widgets.eventbox import EventBox
from fabric.widgets.circularprogressbar import CircularProgressBar
from fabric.audio.service import Audio

class VolumeWidget(Box):
def __init__(self, **kwargs):
super().__init__(name="button-bar-vol", **kwargs)
self.audio = Audio()

self.progress_bar = CircularProgressBar(
name="button-volume", pie=False, size=30, line_width=3,
)
self.ico = icons.vol_high
self.vollabel = Label(name="button-bar-label", markup=icons.vol_high)

self.volbutton = Button(
on_clicked=self.toggle_mute,
child=self.vollabel
)
self.event_box = EventBox(
# name="button-bar-vol",
events="scroll",
child=Overlay(
child=self.progress_bar,
overlays=self.volbutton
),
)

self.audio.connect("notify::speaker", self.on_speaker_changed)
self.event_box.connect("scroll-event", self.on_scroll)
self.add(self.event_box)

# self.button.connect("button", self.on_clicked)

#thanks https://github.com/rubiin/HyDePanel/blob/master/widgets/volume.python.py

def toggle_mute(self, event):
current_stream = self.audio.speaker
if current_stream:
current_stream.muted = not current_stream.muted
self.volbutton.get_child().set_markup(icons.vol_off) if current_stream.muted else self.on_speaker_changed()

#def Mute():
#self.audio.speaker += 2,

def on_scroll(self, _, event):
match event.direction:
case 0:
self.audio.speaker.volume += 2
case 1:
self.audio.speaker.volume -= 2
if self.audio.speaker.volume > 60:
self.volbutton.get_child().set_markup(icons.vol_high)
elif self.audio.speaker.volume > 30:
self.volbutton.get_child().set_markup(icons.vol_medium)
elif self.audio.speaker.volume < 30:
self.volbutton.get_child().set_markup(icons.vol_mute)


return

def on_speaker_changed(self, *_):
if not self.audio.speaker:
return
self.progress_bar.value = self.audio.speaker.volume / 100
self.audio.speaker.bind(
"volume", "value", self.progress_bar, lambda _, v: v / 100
)
if self.audio.speaker.volume > 60:
self.volbutton.get_child().set_markup(icons.vol_high)
elif self.audio.speaker.volume > 30:
self.volbutton.get_child().set_markup(icons.vol_medium)
elif self.audio.speaker.volume < 30:
self.volbutton.get_child().set_markup(icons.vol_mute)
return


class Bar(Window):
def __init__(self, **kwargs):
super().__init__(
Expand Down Expand Up @@ -99,6 +177,8 @@ def __init__(self, **kwargs):
)
)


self.volume = VolumeWidget()
self.bar_inner = CenterBox(
name="bar-inner",
orientation="h",
Expand All @@ -119,7 +199,8 @@ def __init__(self, **kwargs):
spacing=4,
orientation="h",
children=[
self.battery,
self.volume,
# self.battery,
self.button_color,
self.systray,
self.button_config,
Expand Down