Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: set guivm windows prefix and default_guivm tag #291

Merged
merged 4 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions qubes/ext/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright (C) 2013-2016 Marek Marczykowski-Górecki
# <[email protected]>
# Copyright (C) 2014-2018 Wojtek Porczyk <[email protected]>
# Copyright (C) 2019 Frédéric Pierret <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -34,6 +35,12 @@ def send_gui_mode(vm):
if vm.features.get('gui-seamless', False)
else 'FULLSCREEN'))

# property-del <=> property-reset-to-default
@qubes.ext.handler('property-del:guivm')
def on_property_del(self, subject, event, name, oldvalue=None):
newvalue = getattr(subject, 'guivm', None)
self.on_property_set(subject, event, name, newvalue, oldvalue)

@qubes.ext.handler('property-set:guivm')
def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
# pylint: disable=unused-argument,no-self-use
Expand All @@ -45,8 +52,9 @@ def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
if 'guivm-' in tag:
subject.tags.remove(tag)

guivm = 'guivm-' + newvalue.name
subject.tags.add(guivm)
if newvalue:
guivm = 'guivm-' + newvalue.name
subject.tags.add(guivm)

@qubes.ext.handler('domain-qdb-create')
def on_domain_qdb_create(self, vm, event):
Expand All @@ -70,3 +78,18 @@ def on_domain_qdb_create(self, vm, event):
kbd_layout = vm.guivm.features.get('keyboard-layout', None)
if kbd_layout:
vm.untrusted_qdb.write('/keyboard-layout', kbd_layout)

# Set GuiVM prefix
guivm_windows_prefix = vm.features.get('guivm-windows-prefix', 'GuiVM')
if vm.features.get('service.guivm-gui-agent', None):
vm.untrusted_qdb.write('/guivm-windows-prefix',
guivm_windows_prefix)

@qubes.ext.handler('property-set:default_guivm', system=True)
def on_property_set_default_guivm(self, app, event, name, newvalue,
oldvalue=None):
for vm in app.domains:
if hasattr(vm, 'guivm') and vm.property_is_default('guivm'):
vm.fire_event('property-set:guivm',
name='guivm', newvalue=newvalue,
oldvalue=oldvalue)
39 changes: 39 additions & 0 deletions qubes/tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,45 @@ def test_111_netvm_loop(self):
finally:
del netvm

def test_112_default_guivm(self):
class MyTestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
default_guivm = qubes.property('default_guivm',
default=(lambda self: 'dom0'))
holder = MyTestHolder(None)
guivm = self.app.add_new_vm('AppVM', name='sys-gui', guivm='dom0',
template=self.template, label='red')
appvm = self.app.add_new_vm('AppVM', name='test-vm',
template=self.template, label='red')
holder.default_guivm = 'sys-gui'
self.assertEqual(holder.default_guivm, 'sys-gui')
self.assertIsNone(self.app.default_guivm)
self.assertTrue(appvm.property_is_default('guivm'))
self.app.default_guivm = guivm
self.assertEventFired(holder, 'property-set:default_guivm',
kwargs={'name': 'default_guivm',
'newvalue': 'sys-gui'})

self.assertIn('guivm-sys-gui', appvm.tags)

def test_113_guivm(self):
class MyTestHolder(qubes.tests.TestEmitter, qubes.PropertyHolder):
guivm = qubes.property('guivm',
default=(lambda self: 'dom0'))
holder = MyTestHolder(None)
guivm = self.app.add_new_vm('AppVM', name='sys-gui', guivm='dom0',
template=self.template, label='red')
appvm = self.app.add_new_vm('AppVM', name='test-vm', guivm='dom0',
template=self.template, label='red')
holder.guivm = 'sys-gui'
self.assertEqual(holder.guivm, 'sys-gui')
self.assertFalse(appvm.property_is_default('guivm'))
appvm.guivm = guivm
self.assertEventFired(holder, 'property-set:guivm',
kwargs={'name': 'guivm',
'newvalue': 'sys-gui'})

self.assertIn('guivm-sys-gui', appvm.tags)

def test_200_remove_template(self):
appvm = self.app.add_new_vm('AppVM', name='test-vm',
template=self.template,
Expand Down