qubes_monitor_layout_notify.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2015-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2015-2016 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program 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
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. '''qvm-create - Create new Qubes OS store'''
  24. # TODO allow to set properties and create domains
  25. import threading
  26. import qubes.ext.gui
  27. import qubes.tools
  28. parser = qubes.tools.QubesArgumentParser(
  29. description='Send monitor layout to one qube or to all of them',
  30. want_app=True,
  31. want_vm=True,
  32. want_vm_optional=True)
  33. def main(args=None):
  34. '''Main routine of :program:`qubes-create`.
  35. :param list args: Optional arguments to override those delivered from \
  36. command line.
  37. '''
  38. args = parser.parse_args(args)
  39. monitor_layout = qubes.ext.gui.get_monitor_layout()
  40. # notify only if we've got a non-empty monitor_layout or else we
  41. # break proper qube resolution set by gui-agent
  42. if not monitor_layout:
  43. args.app.log.error('cannot get monitor layout')
  44. return 1
  45. subprocess.check_call(['killall', '-HUP', 'qubes-guid'])
  46. if args.vm:
  47. args.vm.fire_event('monitor-layout-change', monitor_layout)
  48. else:
  49. threads = []
  50. for vm in args.app.domains:
  51. thread = threading.Thread(name=vm.name, target=vm.fire_event,
  52. args=('monitor-layout-change',),
  53. kwargs={'monitor_layout': monitor_layout})
  54. threads.append(thread)
  55. thread.run()
  56. for thread in threads:
  57. thread.join()
  58. return 0