gui.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. # pylint: disable=unused-argument,no-self-use
  36. # Clean other 'guivm-XXX' tags.
  37. # gui-daemon can connect to only one domain
  38. tags_list = list(subject.tags)
  39. for tag in tags_list:
  40. if 'guivm-' in tag:
  41. subject.tags.remove(tag)
  42. guivm = 'guivm-' + newvalue.name
  43. subject.tags.add(guivm)
  44. @qubes.ext.handler('domain-qdb-create')
  45. def on_domain_qdb_create(self, vm, event):
  46. # pylint: disable=unused-argument,no-self-use
  47. for feature in ('gui-videoram-overhead', 'gui-videoram-min'):
  48. try:
  49. vm.untrusted_qdb.write(
  50. '/qubes-{}'.format(feature),
  51. vm.features.check_with_template_and_adminvm(
  52. feature))
  53. except KeyError:
  54. pass
  55. # Add GuiVM Xen ID for gui-daemon
  56. if getattr(vm, 'guivm', None):
  57. if vm != vm.guivm:
  58. vm.untrusted_qdb.write('/qubes-gui-domain-xid',
  59. str(vm.guivm.xid))
  60. # Add keyboard layout from that of GuiVM
  61. kbd_layout = vm.guivm.features.get('keyboard-layout', None)
  62. if kbd_layout:
  63. vm.untrusted_qdb.write('/keyboard-layout', kbd_layout)