audio.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2019 Frédéric Pierret <frederic.pierret@qubes-os.org>
  5. #
  6. # This library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 2.1 of the License, or (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  18. #
  19. import qubes.config
  20. import qubes.ext
  21. class AUDIO(qubes.ext.Extension):
  22. # pylint: disable=too-few-public-methods
  23. # property-del <=> property-reset-to-default
  24. @qubes.ext.handler('property-del:audiovm')
  25. def on_property_del(self, subject, event, name, oldvalue=None):
  26. newvalue = getattr(subject, 'audiovm', None)
  27. self.on_property_set(subject, event, name, newvalue, oldvalue)
  28. @qubes.ext.handler('property-set:audiovm')
  29. def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
  30. # pylint: disable=unused-argument,no-self-use
  31. # Clean other 'audiovm-XXX' tags.
  32. # pulseaudio agent (module-vchan-sink) can connect to only one domain
  33. tags_list = list(subject.tags)
  34. for tag in tags_list:
  35. if 'audiovm-' in tag:
  36. subject.tags.remove(tag)
  37. if newvalue:
  38. audiovm = 'audiovm-' + newvalue.name
  39. subject.tags.add(audiovm)
  40. @qubes.ext.handler('domain-qdb-create')
  41. def on_domain_qdb_create(self, vm, event):
  42. # pylint: disable=unused-argument,no-self-use
  43. # Add AudioVM Xen ID for gui-agent
  44. if getattr(vm, 'audiovm', None):
  45. if vm != vm.audiovm:
  46. vm.untrusted_qdb.write('/qubes-audio-domain-xid',
  47. str(vm.audiovm.xid))
  48. @qubes.ext.handler('property-set:default_audiovm', system=True)
  49. def on_property_set_default_audiovm(self, app, event, name, newvalue,
  50. oldvalue=None):
  51. # pylint: disable=unused-argument,no-self-use
  52. for vm in app.domains:
  53. if hasattr(vm, 'audiovm') and vm.property_is_default('audiovm'):
  54. vm.fire_event('property-set:audiovm',
  55. name='audiovm', newvalue=newvalue,
  56. oldvalue=oldvalue)