qubes_monitor_layout_notify.py 2.2 KB

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