Page 1 of 1

Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 12:13 pm
by CharlesV
The following method turns on auto switch for newly connected bluetooth devices under XFCE. I have been using this in several MX23 xfce machines, just worked with a gent to fix his too and he recommended we add it.

It is so useful, I have had it working since MX23 ( different fix for MX21 ) and would like to request it to be added to the pipewire config. If for some reason we cannot, then possibly added to MX Tweak.

-- To get auto switch working on bluetooth in XFCE with pipewire,
Modify:

Code: Select all

/usr/share/pipewire/pipewire-pulse.conf

And under the group of:

Code: Select all

  content.exec:

Add this line:

Code: Select all

    { path = "pactl" args = "load-module module-switch-on-connect" }

Restart the computer and bluetooth devices should now automatically switch to a bluetooth device when connected.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 12:51 pm
by dolphin_oracle
CharlesV wrote: Tue Jan 02, 2024 12:13 pm The following method turns on auto switch for newly connected bluetooth devices under XFCE. I have been using this in several MX23 xfce machines, just worked with a gent to fix his too and he recommended we add it.

It is so useful, I have had it working since MX23 ( different fix for MX21 ) and would like to request it to be added to the pipewire config. If for some reason we cannot, then possibly added to MX Tweak.

-- To get auto switch working on bluetooth in XFCE with pipewire,
Modify:

Code: Select all

/usr/share/pipewire/pipewire-pulse.conf

And under the group of:

Code: Select all

  content.exec:

Add this line:

Code: Select all

    { path = "pactl" args = "load-module module-switch-on-connect" }

Restart the computer and bluetooth devices should now automatically switch to a bluetooth device when connected.
to survive updates, probably put a copy of that .conf file under /etc/pipewire or ~/.config/pipewire.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 1:28 pm
by CharlesV
Good call.. and thank you !

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 1:37 pm
by dolphin_oracle
will make the change tonight on my machine and see how it behaves.

does this only work for bluetooth, or also for other connections? thinking mostly about hdmi connections, but also usb headsets and such.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 1:47 pm
by CharlesV
dolphin_oracle wrote: Tue Jan 02, 2024 1:37 pm will make the change tonight on my machine and see how it behaves.

does this only work for bluetooth, or also for other connections? thinking mostly about hdmi connections, but also usb headsets and such.
I have only used it on bluetooth, and dont have any monitors with with speakers to try it on. I found this and the same fix for pulse audio that I used in MX 21 here:

MX 23 - Pipewire
https://alexandra-zaharia.github.io/pos ... -in-linux/
( scroll down a bit )

and
MX 21 - Pulseaudio
https://alexandra-zaharia.github.io/pos ... lly-linux/

Been so long since I did them I totally forgot until the latest post I worked on.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 4:18 pm
by m_pav
Not that it makes any difference in function, but shouldn't the line to add into pipewire.conf follow the conventions already used?

{ path = "/usr/bin/pactl" args = "load-module module-switch-on-connect" }
instead of
{ path = "pactl" args = "load-module module-switch-on-connect" }

and I agree with DO
dolphin_oracle wrote: Tue Jan 02, 2024 12:51 pm to survive updates, probably put a copy of that .conf file under /etc/pipewire or ~/.config/pipewire.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 5:02 pm
by Stevo
None of the commented-out examples already in the file use the full /usr/bin path, though.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 6:46 pm
by AVLinux
@dolphin_oracle

Would it be better as an auxiliary package instead of part of pipewire-setup-mx? Supposing it was a separate package called something like 'pipewire-bluetooth-mx' and instead of placing the conf files in /usr/share/pipewire where they could get overwritten it could place the modified conf file directly into /etc/pipewire where it would be safe.. People with bluetooth devices could install it and people without could just have the stock PipeWire setup in case the auto switch does unwanted things with normal Audio devices..?

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 7:56 pm
by Stevo
AVLinux wrote: Tue Jan 02, 2024 6:46 pm @dolphin_oracle

Would it be better as an auxiliary package instead of part of pipewire-setup-mx? Supposing it was a separate package called something like 'pipewire-bluetooth-mx' and instead of placing the conf files in /usr/share/pipewire where they could get overwritten it could place the modified conf file directly into /etc/pipewire where it would be safe.. People with bluetooth devices could install it and people without could just have the stock PipeWire setup in case the auto switch does unwanted things with normal Audio devices..?
If we wanted to make it opt-in, or default with an opt-out, I'd vote for having the setting in MX Tweak.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 8:21 pm
by dolphin_oracle
I need to think about it. I'm inclined to make a switch for it.

FWIW, this affects all connected audio devices, not just bluetooth ones. its quit irritating when pluggin in a microphone to have all your audio switch to the mic, even the output. I'm going to guess that it might be similar for other types of connections, maybe even HDMI audio, although I haven't tested that.

does work though.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 9:43 pm
by AVLinux
dolphin_oracle wrote: Tue Jan 02, 2024 8:21 pm
FWIW, this affects all connected audio devices, not just bluetooth ones. its quit irritating when pluggin in a microphone to have all your audio switch to the mic, even the output. I'm going to guess that it might be similar for other types of connections, maybe even HDMI audio, although I haven't tested that.
Eeegads!

That gives me cold sweats in a Studio context... :confused:

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 10:57 pm
by CharlesV
dolphin_oracle wrote: Tue Jan 02, 2024 8:21 pm I need to think about it. I'm inclined to make a switch for it.

FWIW, this affects all connected audio devices, not just bluetooth ones. its quit irritating when pluggin in a microphone to have all your audio switch to the mic, even the output. I'm going to guess that it might be similar for other types of connections, maybe even HDMI audio, although I haven't tested that.

does work though.
Makes sense that it is setup to switch any audio device... but I think I would agree with you about making a switch for it.

The plus side is behaving like that it would be excellent for plugging in an hdmi, connecting a bluetooth speaker.. those seem very 'normal' to me ...

But at the risk of messing people up with other devices, like what your describing, or heavy audio connections... a switch to turn that feature off would be good.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 11:03 pm
by CharlesV
Maybe we can learn something from how KDE does this?

I will fire up a KDE test machine tomorrow and see if I can find out how that happens. My understanding is that KDE auto switches to bluetooth when it connects but obviously xfce does not.

Re: Request addition to pipewire config - auto switch

Posted: Tue Jan 02, 2024 11:22 pm
by Stevo
I can confirm that MX 21 and 23 KDE do switch automatically, and if I connect yet another BT earphone or speaker on top of the existing, they switch to the new one. And switch back if that new device is disconnected.

I wonder if this has come up on the XFCE forums yet, or if another XFCE distro has addressed this annoyance.

Re: Request addition to pipewire config - auto switch

Posted: Wed Jan 03, 2024 10:06 am
by CharlesV
In my search before when mx23 was in beta stages, I found several places complaining about it, but only that link I posted had 'the fix' (and on the Arch website.)

In looking around this am I found a few more sites complaining about it, but not a lot and no mention of it on the xfce forum that I could find.

Re: Request addition to pipewire config - auto switch

Posted: Wed Jan 03, 2024 7:03 pm
by CharlesV
You all probably already know this, but I compared MX 23 KDE and XFCE pipewire configs (identical ) , yet the KDE version works perfectly switching to a connected bluetooth device.

I tried work through configs etc and I cannot see anything that is different that would do this. Yet... it does ;-/

Re: Request addition to pipewire config - auto switch

Posted: Wed Jan 03, 2024 7:19 pm
by dolphin_oracle
CharlesV wrote: Wed Jan 03, 2024 7:03 pm You all probably already know this, but I compared MX 23 KDE and XFCE pipewire configs (identical ) , yet the KDE version works perfectly switching to a connected bluetooth device.

I tried work through configs etc and I cannot see anything that is different that would do this. Yet... it does ;-/
unlike Xfce, KDE itself has a daemon that manages connections. gnome probably does too.

Re: Request addition to pipewire config - auto switch

Posted: Wed Jan 03, 2024 7:34 pm
by CharlesV
dolphin_oracle wrote: Wed Jan 03, 2024 7:19 pm
CharlesV wrote: Wed Jan 03, 2024 7:03 pm You all probably already know this, but I compared MX 23 KDE and XFCE pipewire configs (identical ) , yet the KDE version works perfectly switching to a connected bluetooth device.

I tried work through configs etc and I cannot see anything that is different that would do this. Yet... it does ;-/
unlike Xfce, KDE itself has a daemon that manages connections. gnome probably does too.
That would make sense.

Re: Request addition to pipewire config - auto switch

Posted: Sun Apr 07, 2024 8:59 am
by mxUs3r
Posting the updated version of the solution as in "/usr/share/pipewire/pipewire-pulse.conf" I was unable to find "content.exec" part, it could be the config file structure update or something, not sure.

I am referring to "by CharlesV ยป Tue Jan 02, 2024 5:13 pm" post here

including the point of the post/note above, your changes to survive the update, instead of edit the file "/usr/share/pipewire/pipewire-pulse.conf" - you just:

1. Create the folder "pipewire" (if does not exist) in "~/.config" folder of the current user:

Code: Select all

mkdir ~/.config/pipewire
2. copy "pipewire-pulse.conf" file from "/usr/share/pipewire" folder into "~/.config/pipewire" folder:

Code: Select all

sudo cp /usr/share/pipewire/pipewire-pulse.conf ~/.config/pipewire/
(you can copy all config files from there if you want)

3. Change ownership of the file:

Code: Select all

sudo chown USER:USER ~/.config/pipewire/pipewire-pulse.conf
(replace USER:USER with your actual username!)

4. Open the file in your favourite text editor:

Code: Select all

vim ~/.config/pipewire/pipewire-pulse.conf
5. Find the blocks

Code: Select all

context.exec =
and

Code: Select all

pulse.cmd =
(they are one on top of the other actually)

6. Add two lines of code to each block accordingly, to make like this:

Code: Select all

context.exec = [
    #{ path = "pactl"        args = "load-module module-always-sink" }
    #{ path = "pactl"        args = "upload-sample my-sample.wav my-sample" }
    #{ path = "/usr/bin/sh"  args = "~/.config/pipewire/default.pw" }
    { path = "pactl"         args = "load-module module-switch-on-connect" }
]
and

Code: Select all

pulse.cmd = [
    { cmd = "load-module" args = "module-always-sink" flags = [ ] }
    #{ cmd = "load-module" args = "module-switch-on-connect" }
    #{ cmd = "load-module" args = "module-gsettings" flags = [ nofail ] }
    { cmd = "load-module" args = "module-switch-on-connect" }
]
(Pay attention to those two last lines in each block)

7. Reboot and try, it works for me.

I posted different approach in my post (https://www.forum.mxlinux.org/viewtopic.php?t=73504), before I sorted the problem like this one.
you can check that post if you want, but I think this method is better way to solve it =)

Worth mentioning that if you want those changes system wide, if you have multiple users for example, then you can do these steps
into "/etc/pipewire" instead of "~/.config/pipewire"
(in that case ignore the step 3. as no ownership changes needed here).

Re: Request addition to pipewire config - auto switch

Posted: Sun Apr 07, 2024 11:11 am
by CharlesV
@mxUs3r Nicely done! I shall have to give this a try on my next build (or before maybe!)

Re: Request addition to pipewire config - auto switch

Posted: Sun Apr 28, 2024 5:55 pm
by wbrells
Thanks for all the comments, but my MX 23 system does not have a /usr/share/pipewire/ directory so I can't test any of the above suggestions. Do I need to install one of the pipewire packages from the Enabled Repos? Would the appropriate package be pipewire-setup-mx (version 23.12.04) or would one of the other package(s) be better?

Thanks, Wayne

Re: Request addition to pipewire config - auto switch

Posted: Sun Apr 28, 2024 7:16 pm
by Charlie Brown
I guess you posted in the wrong thread (and you meant this: viewtopic.php?p=774234#p774234 ). Normally pipewire is ootb and that path is also present ootb. And it seems you installed Pulseaudio and that removed Pipewire automatically.

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 7:50 am
by wbrells
I certainly did not specifically install Pulseaudio in place of Pipewire. I've looked at both the default kernel for MX 23.2 (Debian 64 bit) and the 6.6.11-1~mx23ahs kernel that I'm currently using, and both of them seem to use Pulseaudio. Is there a particular kernel for 23.2 that uses Pipewire? If not, should I install it (how)?

Thanks, Wayne

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 8:06 am
by Charlie Brown

Code: Select all

sudo apt update ; sudo apt reinstall gstreamer1.0-pipewire gstreamer1.0-pulseaudio libcanberra-pulse libpipewire-0.3-0 libpipewire-0.3-modules libpulse-mainloop-glib0 libpulse0 libpulsedsp libsox-fmt-pulse libwireplumber-0.4-0 pipewire-alsa pipewire-bin pipewire-jack pipewire-pulse pipewire-setup-mx pipewire pulseaudio-utils wireplumber xfce4-pulseaudio-plugin -y

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 8:08 am
by dolphin_oracle
posting quick-system-info will clear this up. pipewire uses the same tools as pulseaudio, and provides a pulseaudio server compatibility.

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 8:08 am
by Charlie Brown
QSI is on the other thread :)

Code: Select all

Audio:     Device-1: Intel driver: snd_hda_intel v: kernel alternate: snd_sof_pci_intel_tgl 
           bus-ID: 00:1f.3 chip-ID: 8086:54c8 class-ID: 0403 
           Sound Server-1: ALSA v: k6.6.11-amd64 running: yes 
           Sound Server-2: PulseAudio v: 16.1 running: yes 

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 9:09 am
by wbrells
Does the above audio 'snippet' from my QSI listing indicate that pipewire is NOT installed and that the above commands can be used to install it? If so, it seems odd that pipewire is not automatically included (so it seems) in any of the MX 23.2 kernels...

Wayne

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 9:14 am
by dolphin_oracle
wbrells wrote: Mon Apr 29, 2024 9:09 am Does the above audio 'snippet' from my QSI listing indicate that pipewire is NOT installed and that the above commands can be used to install it? If so, it seems odd that pipewire is not automatically included (so it seems) in any of the MX 23.2 kernels...

Wayne
yes.

pipewire is the defualt on all official mx 23 releases. so somewhere along the way some package install on your part probably installed pulseaudio, which removed pipewire.

also, pipewire is not part of the kernel. its a stand alone sound server.

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 9:41 am
by wbrells
Thanks very much for the info - I had no idea that pipewire was NOT included in the kernel!

I'm not sure what program/package I may have installed that removed pipewire. This problem may have arisen because I did an in-place update from MX 21.3 to MX 23.2 rather than a fresh install of 23.2. (The in-place update saved me a HUGE amount of time and except perhaps for pipewire does not seem to have caused any problems.)

In any case, I will reinstall pipewire via the instructions above and report the results.

Thanks again for all your help,

Wayne

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 10:00 am
by dolphin_oracle
ah an in place upgrade would not have pipewire.

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 10:04 am
by wbrells
Well, it appears that PipeWire is now installed and running:

Code: Select all

Audio:     Device-1: Intel driver: snd_hda_intel v: kernel alternate: snd_sof_pci_intel_tgl 
           bus-ID: 00:1f.3 chip-ID: 8086:54c8 class-ID: 0403 
           Sound Server-1: ALSA v: k6.6.11-amd64 running: yes 
           Sound Server-2: PulseAudio v: 16.1 running: no 
           Sound Server-3: PipeWire v: 1.0.0 running: yes 
However, the MX Select Sound app still only shows PCH as the current default sound card and no other options are shown. Perhaps I need to modify /usr/share/pipewire/pipewire-pulse.conf per an earlier comment in order for Bluetooth audio to show up as a sound option and for my paired Bluetooth headset to start working?

Thanks once more, Wayne

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 10:09 am
by dolphin_oracle
I choose mine out of the pavucontrol or the xfce volume plugin.

if its not showing up, you may need to play around with the audio profiles in the bluetooth manager.

Re: Request addition to pipewire config - auto switch

Posted: Mon Apr 29, 2024 11:03 am
by wbrells
I'm very confused! My Mpow H17 Bluetooth headset is connected, paired, and shows up in the Volume Control:

Image

I hear a 'beep' when I click on the volume slider for that device. However, even with pipewire installed and apparently running, I can't change the default sound card to anything other than PCH... I tried the modification to pipewire-pulse.conf suggested in an earlier comment, but that didn't do anything! It would really be helpful if someone could suggest how I can change the default sound card to something other than PCH...

Wayne

Re: Request addition to pipewire config - auto switch

Posted: Sun May 12, 2024 11:00 am
by MXLinuxKDE
Charlie Brown wrote: Mon Apr 29, 2024 8:06 am

Code: Select all

sudo apt update ; sudo apt reinstall gstreamer1.0-pipewire gstreamer1.0-pulseaudio libcanberra-pulse libpipewire-0.3-0 libpipewire-0.3-modules libpulse-mainloop-glib0 libpulse0 libpulsedsp libsox-fmt-pulse libwireplumber-0.4-0 pipewire-alsa pipewire-bin pipewire-jack pipewire-pulse pipewire-setup-mx pipewire pulseaudio-utils wireplumber xfce4-pulseaudio-plugin -y
Hi, I had the same problem and was about to open a new thread :rolleyes: ,
the bluetooth was not communicating with any devices, despite recognising them (although as soon as I installed the operating system from scratch a few days ago, everything was working).

With your command and a reboot, the problem seems to be solved. :crossfingers:

Re: Request addition to pipewire config - auto switch

Posted: Sun May 12, 2024 11:04 am
by Eadwine Rose
@MXLinuxKDE Please post in English, you are on an English forum.

Re: Request addition to pipewire config - auto switch

Posted: Sun May 12, 2024 11:05 am
by MXLinuxKDE
Eadwine Rose wrote: Sun May 12, 2024 11:04 am @MXLinuxKDE Please post in English, you are on an English forum.
Sorry, I just realised, and immediately translated

Re: Request addition to pipewire config - auto switch

Posted: Sun May 12, 2024 1:02 pm
by Charlie Brown
MXLinuxKDE wrote: Sun May 12, 2024 11:00 am... With your command and a reboot, the problem seems to be solved.
Glad to hear that and thank you for the feedback :)