gui.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. # Copyright (C) 2019 Frédéric Pierret <frederic.pierret@qubes-os.org>
  9. #
  10. # This library is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU Lesser General Public
  12. # License as published by the Free Software Foundation; either
  13. # version 2.1 of the License, or (at your option) any later version.
  14. #
  15. # This library is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. # Lesser General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Lesser General Public
  21. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  22. #
  23. import qubes.config
  24. import qubes.ext
  25. class GUI(qubes.ext.Extension):
  26. # pylint: disable=too-few-public-methods
  27. # TODO put this somewhere...
  28. @staticmethod
  29. def send_gui_mode(vm):
  30. vm.run_service('qubes.SetGuiMode',
  31. input=('SEAMLESS'
  32. if vm.features.get('gui-seamless', False)
  33. else 'FULLSCREEN'))
  34. # property-del <=> property-reset-to-default
  35. @qubes.ext.handler('property-del:guivm')
  36. def on_property_del(self, subject, event, name, oldvalue=None):
  37. newvalue = getattr(subject, 'guivm', None)
  38. self.on_property_set(subject, event, name, newvalue, oldvalue)
  39. @qubes.ext.handler('property-set:guivm')
  40. def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
  41. # pylint: disable=unused-argument,no-self-use
  42. # Clean other 'guivm-XXX' tags.
  43. # gui-daemon can connect to only one domain
  44. tags_list = list(subject.tags)
  45. for tag in tags_list:
  46. if 'guivm-' in tag:
  47. subject.tags.remove(tag)
  48. if newvalue:
  49. guivm = 'guivm-' + newvalue.name
  50. subject.tags.add(guivm)
  51. @qubes.ext.handler('domain-qdb-create')
  52. def on_domain_qdb_create(self, vm, event):
  53. # pylint: disable=unused-argument,no-self-use
  54. for feature in ('gui-videoram-overhead', 'gui-videoram-min'):
  55. try:
  56. vm.untrusted_qdb.write(
  57. '/qubes-{}'.format(feature),
  58. vm.features.check_with_template_and_adminvm(
  59. feature))
  60. except KeyError:
  61. pass
  62. # Add GuiVM Xen ID for gui-daemon
  63. if getattr(vm, 'guivm', None):
  64. if vm != vm.guivm:
  65. vm.untrusted_qdb.write('/qubes-gui-domain-xid',
  66. str(vm.guivm.xid))
  67. # Add keyboard layout from that of GuiVM
  68. kbd_layout = vm.guivm.features.get('keyboard-layout', None)
  69. if kbd_layout:
  70. vm.untrusted_qdb.write('/keyboard-layout', kbd_layout)
  71. # Set GuiVM prefix
  72. guivm_windows_prefix = vm.features.get('guivm-windows-prefix', 'GuiVM')
  73. if vm.features.get('service.guivm-gui-agent', None):
  74. vm.untrusted_qdb.write('/guivm-windows-prefix',
  75. guivm_windows_prefix)
  76. @qubes.ext.handler('property-set:default_guivm', system=True)
  77. def on_property_set_default_guivm(self, app, event, name, newvalue,
  78. oldvalue=None):
  79. # pylint: disable=unused-argument,no-self-use
  80. for vm in app.domains:
  81. if hasattr(vm, 'guivm') and vm.property_is_default('guivm'):
  82. vm.fire_event('property-set:guivm',
  83. name='guivm', newvalue=newvalue,
  84. oldvalue=oldvalue)