gui.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2010-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
  5. # Copyright (C) 2013-2016 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. # Copyright (C) 2014-2018 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2.1 of the License, or (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. # Lesser General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Lesser General Public
  20. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  21. #
  22. import qubes.config
  23. import qubes.ext
  24. class GUI(qubes.ext.Extension):
  25. # pylint: disable=too-few-public-methods
  26. # TODO put this somewhere...
  27. @staticmethod
  28. def send_gui_mode(vm):
  29. vm.run_service('qubes.SetGuiMode',
  30. input=('SEAMLESS'
  31. if vm.features.get('gui-seamless', False)
  32. else 'FULLSCREEN'))
  33. @qubes.ext.handler('property-set:guivm')
  34. def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
  35. # Clean other 'guivm-XXX' tags.
  36. # gui-daemon can connect to only one domain
  37. tags_list = list(subject.tags)
  38. for tag in tags_list:
  39. if 'guivm-' in tag:
  40. subject.tags.remove(tag)
  41. guivm = 'guivm-' + newvalue.name
  42. subject.tags.add(guivm)
  43. @qubes.ext.handler('domain-qdb-create')
  44. def on_domain_qdb_create(self, vm, event):
  45. # pylint: disable=unused-argument,no-self-use
  46. for feature in ('gui-videoram-overhead', 'gui-videoram-min'):
  47. try:
  48. vm.untrusted_qdb.write(
  49. '/qubes-{}'.format(feature),
  50. vm.features.check_with_template_and_adminvm(
  51. feature))
  52. except KeyError:
  53. pass
  54. # Add GuiVM Xen ID for gui-daemon
  55. try:
  56. if vm.guivm is not None:
  57. if str(vm.name) != str(vm.guivm.name):
  58. vm.untrusted_qdb.write('/qubes-gui-domain-xid',
  59. str(vm.guivm.xid))
  60. except AttributeError:
  61. vm.untrusted_qdb.write('/qubes-gui-domain-xid', '')