christophgysin / pasystray

PulseAudio system tray
GNU Lesser General Public License v2.1
444 stars 43 forks source link

Fix activate event callbacks #166

Closed liskin closed 1 year ago

liskin commented 1 year ago

A bunch of fixes for activate callbacks being invoked without user interaction and conflicting with clicked callbacks since https://github.com/christophgysin/pasystray/pull/121:

Fix spurious "[menu_info] item activated: input (null)"

These would happen when descending into playback streams submenus. The fix is to ignore activation for anything that isn't a CHECK_MENU_ITEM.

(Also fixes related compile warning and debug logging.)

Improve logging in pulseaudio_action.c

Fix defaults being changed and streams moved without user interaction

Since we added callbacks for the activate signal of menu items, pulseaudio_set_default, pulseaudio_move_input_to_sink and pulseaudio_move_output_to_source were getting called without any user interaction whenever we invoked gtk_check_menu_item_set_active in response to events from pulseaudio.

This interferes with automatic switching of default sinks/sources in wireplumber (and maybe also pulseaudio):

  1. Disconnect bluetooth headphones.

  2. We're notified that the default sink changed to laptop built-in audio, and to reflect this in the menus, gtk_check_menu_item_set_active is invoked which triggers the activate signal callback. This results in an invocation of pulseaudio_set_default.

  3. Connect bluetooth headphones again.

  4. Nothing happens because we've called pulseaudio_set_default earlier and wireplumber now thinks the laptop built-in audio is the preferred device and doesn't auto-switch to BT headphones.

The fix is to block our activate callback when invoking gtk_check_menu_item_set_active.

Fix alt-click/right-click setting defaults in addition to muting

Alt-click and right-click was only meant to mute a sink/source, not set it as default, but since we added callbacks for the activate signal of menu items, these clicks did both. Also, left-click would set the default sink/source twice—probably harmless, but fixed here as well.

christophgysin commented 1 year ago

Thanks a lot @liskin!