gui.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2010-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2013-2016 Marek Marczykowski-Górecki
  8. # <marmarek@invisiblethingslab.com>
  9. # Copyright (C) 2014-2016 Wojtek Porczyk <woju@invisiblethingslab.com>
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. #
  25. import os
  26. import subprocess
  27. import qubes.config
  28. import qubes.ext
  29. class GUI(qubes.ext.Extension):
  30. @qubes.ext.handler('domain-start', 'domain-cmd-pre-start')
  31. def start_guid(self, vm, start_guid, preparing_dvm=False,
  32. extra_guid_args=None, **kwargs):
  33. '''Launch gui daemon.
  34. GUI daemon securely displays windows from domain.
  35. ''' # pylint: disable=no-self-use,unused-argument
  36. if not start_guid or preparing_dvm \
  37. or not os.path.exists('/var/run/shm.id'):
  38. return
  39. if not vm.features.check_with_template('gui', not vm.hvm):
  40. vm.log.debug('Not starting gui daemon, disabled by features')
  41. return
  42. if not os.getenv('DISPLAY'):
  43. vm.log.error('Not starting gui daemon, no DISPLAY set')
  44. return
  45. vm.log.info('Starting gui daemon')
  46. guid_cmd = [qubes.config.system_path['qubes_guid_path'],
  47. '-d', str(vm.xid), '-N', vm.name,
  48. '-c', vm.label.color,
  49. '-i', vm.label.icon_path,
  50. '-l', str(vm.label.index)]
  51. if extra_guid_args is not None:
  52. guid_cmd += extra_guid_args
  53. if vm.debug:
  54. guid_cmd += ['-v', '-v']
  55. # elif not verbose:
  56. else:
  57. guid_cmd += ['-q']
  58. retcode = subprocess.call(guid_cmd)
  59. if retcode != 0:
  60. raise qubes.exc.QubesVMError(vm,
  61. 'Cannot start qubes-guid for domain {!r}'.format(vm.name))
  62. vm.notify_monitor_layout()
  63. vm.wait_for_session()
  64. @qubes.ext.handler('monitor-layout-change')
  65. def on_monitor_layout_change(self, vm, monitor_layout):
  66. # pylint: disable=no-self-use
  67. if vm.features.check_with_template('no-monitor-layout', False) \
  68. or not vm.is_running():
  69. return
  70. pipe = vm.run('QUBESRPC qubes.SetMonitorLayout dom0',
  71. passio_popen=True, wait=True)
  72. pipe.stdin.write(''.join(monitor_layout))
  73. pipe.stdin.close()
  74. pipe.wait()