gui.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. # Legacy value for setting keyboard layout
  72. xkb_keymap = \
  73. 'xkb_keymap {\x0a\x09xkb_keycodes { include ' \
  74. '"evdev"\x09};\x0a\x09xkb_types { include ' \
  75. '"complete"\x09};\x0a\x09xkb_compat { include ' \
  76. '"complete"\x09};\x0a\x09xkb_symbols { include ' \
  77. '"pc+%s+inet(evdev)"\x09};\x0a\x09xkb_geometry ' \
  78. '{ include "pc(pc105)"\x09};\x0a};' % kbd_layout
  79. vm.untrusted_qdb.write('/qubes-keyboard', xkb_keymap)
  80. # Set GuiVM prefix
  81. guivm_windows_prefix = vm.features.get('guivm-windows-prefix', 'GuiVM')
  82. if vm.features.get('service.guivm-gui-agent', None):
  83. vm.untrusted_qdb.write('/guivm-windows-prefix',
  84. guivm_windows_prefix)
  85. @qubes.ext.handler('property-set:default_guivm', system=True)
  86. def on_property_set_default_guivm(self, app, event, name, newvalue,
  87. oldvalue=None):
  88. # pylint: disable=unused-argument,no-self-use
  89. for vm in app.domains:
  90. if hasattr(vm, 'guivm') and vm.property_is_default('guivm'):
  91. vm.fire_event('property-set:guivm',
  92. name='guivm', newvalue=newvalue,
  93. oldvalue=oldvalue)