diff --git a/nwg_panel/modules/controls.py b/nwg_panel/modules/controls.py index cd99dcd9..c87e9cc8 100644 --- a/nwg_panel/modules/controls.py +++ b/nwg_panel/modules/controls.py @@ -275,7 +275,7 @@ def __init__(self, position, alignment, settings, width, monitor=None, icons_pat check_key(settings, "output-switcher", False) self.sinks = [] - if is_command("pactl") and settings["output-switcher"]: + if is_command("pamixer") and settings["output-switcher"]: self.sinks = list_sinks() self.connect("show", self.refresh_sinks) @@ -362,7 +362,7 @@ def __init__(self, position, alignment, settings, width, monitor=None, icons_pat self.vol_scale.connect("value-changed", self.set_vol) inner_hbox.pack_start(self.vol_scale, True, True, 5) - if is_command("pactl") and settings["output-switcher"]: + if is_command("pamixer") and settings["output-switcher"]: pactl_eb = Gtk.EventBox() image = Gtk.Image() pactl_eb.add(image) @@ -374,7 +374,7 @@ def __init__(self, position, alignment, settings, width, monitor=None, icons_pat add_sep = True - if is_command("pactl") and settings["output-switcher"]: + if is_command("pamixer") and settings["output-switcher"]: self.sink_box = SinkBox() pactl_eb.connect('button-press-event', self.sink_box.switch_visibility) v_box.pack_start(self.sink_box, False, False, 0) diff --git a/nwg_panel/tools.py b/nwg_panel/tools.py index 143c7e8c..73722483 100644 --- a/nwg_panel/tools.py +++ b/nwg_panel/tools.py @@ -312,26 +312,24 @@ def is_command(cmd): def get_volume(): vol = 0 muted = False - try: - vol = int(cmd2string("pamixer --get-volume")) - except Exception as e: - eprint(e) - - try: - muted = subprocess.check_output("pamixer --get-mute", shell=True).decode( - "utf-8").strip() == "true" - except subprocess.CalledProcessError: - # the command above returns the 'disabled` status w/ CalledProcessError, exit status 1 - pass + if is_command("pamixer"): + try: + vol = int(cmd2string("pamixer --get-volume")) + except Exception as e: + eprint(e) + + try: + muted = subprocess.check_output("pamixer --get-mute", shell=True).decode( + "utf-8").strip() == "true" + except subprocess.CalledProcessError: + # the command above returns the 'disabled` status w/ CalledProcessError, exit status 1 + pass + else: + eprint("Required 'pamixer' command not found") return vol, muted -def get_scontrol(): - result = cmd2string("amixer scontrols") - return result.split()[3].split(",")[0][1:-1] - - def list_sinks(): sinks = [] if is_command("pamixer"): @@ -346,38 +344,29 @@ def list_sinks(): sinks.append({"name": name, "desc": desc}) except Exception as e: eprint(e) + else: + eprint("Required 'pamixer' command not found") return sinks def toggle_mute(*args): - vol, muted = get_volume() - if muted: - subprocess.call("pamixer -u".split()) + if is_command("pamixer"): + vol, muted = get_volume() + if muted: + subprocess.call("pamixer -u".split()) + else: + subprocess.call("pamixer -m".split()) else: - subprocess.call("pamixer -m".split()) + eprint("Required 'pamixer' command not found") def set_volume(slider): - percent = slider.get_value() - if nwg_panel.common.dependencies["pyalsa"]: - mixer = alsamixer.Mixer() - mixer.attach() - mixer.load() - try: - element = alsamixer.Element(mixer, nwg_panel.common.defaults["master"]) - max_vol = element.get_volume_range()[1] - element.set_volume_all(int(percent * max_vol / 100)) - except Exception as e: - eprint(e) - del mixer + percent = int(slider.get_value()) + if is_command("pamixer"): + subprocess.call("pamixer --set-volume {}".format(percent).split()) else: - c = "amixer sset {}".format(nwg_panel.common.defaults["master"]) - cmd = "{} {}% /dev/null 2>&1".format(c, percent) - try: - subprocess.call(cmd.split()) - except Exception as e: - eprint(e) + eprint("Required 'pamixer' command not found") def get_brightness():