gui.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. try:
  57. if vm.guivm is not None:
  58. if str(vm.name) != str(vm.guivm.name):
  59. vm.untrusted_qdb.write('/qubes-gui-domain-xid',
  60. str(vm.guivm.xid))
  61. except AttributeError:
  62. vm.untrusted_qdb.write('/qubes-gui-domain-xid', '')
  63. # Add keyboard layout from that of GuiVM
  64. try:
  65. kbd_layout = vm.guivm.features['keyboard-layout']
  66. vm.untrusted_qdb.write('/keyboard-layout', kbd_layout)
  67. except AttributeError:
  68. vm.untrusted_qdb.write('/keyboard-layout', '')