Skip to content

Commit

Permalink
Update pulsewidgets for single pulse server
Browse files Browse the repository at this point in the history
  • Loading branch information
elParaguayo committed Oct 1, 2023
1 parent 0e66223 commit cd86069
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
34 changes: 6 additions & 28 deletions qtile_extras/widget/pulse_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,10 @@ def __init__(self, **config):
_Volume.__init__(self, **config)
self._variable_defaults = {**defaults, **self._variable_defaults}

# We need a flag to ensure we only try to connect to the Pulse server once
self._connection_requested = False

def _configure(self, qtile, bar):
PulseVolume._configure(self, qtile, bar)
_Volume._configure(self, qtile, bar)

async def _config_async(self):
if not self._connection_requested:
self._connection_requested = True
await PulseVolume._config_async(self)

def update(self):
"""Modified version of PulseVolume.update to set variables."""
length = self.length

if not self.pulse.connected or not self.default_sink:
vol = -1
mute = False
else:
vol = self.get_volume()
mute = self.default_sink.mute
if vol != self.volume or mute != self.muted:
self.volume = vol
self.muted = mute
self.hidden = False
if length == self.length:
self.draw()
else:
self.bar.draw()

@expose_command()
def volume_up(self, value=None):
"""Increase volume."""
Expand All @@ -94,4 +67,9 @@ def volume_down(self, value=None):
"""Decrease volume."""
self.decrease_vol(value)

get_volume = PulseVolume.get_volume
def no_op(self):
pass

get_vals = _Volume.status_change
set_refresh_timer = no_op
refresh = no_op
9 changes: 5 additions & 4 deletions qtile_extras/widget/pulse_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from libqtile.command.base import expose_command
from libqtile.utils import create_task
from libqtile.widget.pulse_volume import PulseVolume as QPulseVolume
from libqtile.widget.pulse_volume import pulse

from qtile_extras.popup.menu import PopupMenuItem
from qtile_extras.widget.mixins import MenuMixin
Expand All @@ -43,16 +44,16 @@ def __init__(self, **config):
self.add_callbacks({"Button2": self.select_sink})

async def set_sink(self, sink):
if not self.pulse.connected:
if not pulse.pulse.connected:
return

await self.pulse.default_set(sink)
await pulse.pulse.default_set(sink)

async def show_sinks(self):
if not self.pulse.connected:
if not pulse.pulse.connected:
return

sinks = await self.pulse.sink_list()
sinks = await pulse.pulse.sink_list()
if not sinks:
return

Expand Down

0 comments on commit cd86069

Please sign in to comment.