From 78d0d2cabb3c8c80fd0fe63a7792afc1ef69ad20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Wed, 6 Nov 2019 20:36:34 +0100 Subject: [PATCH 1/4] gui: set guivm windows prefix --- qubes/ext/gui.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index 5438425e4..c3f1e6be8 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -70,3 +70,9 @@ 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) From 728766d191e19d18f88c96ee72db746d6d9b2b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sat, 9 Nov 2019 13:20:14 +0100 Subject: [PATCH 2/4] default_guivm: fire property-set on default_guivm --- qubes/ext/gui.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index c3f1e6be8..83bfc9288 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -5,6 +5,7 @@ # Copyright (C) 2013-2016 Marek Marczykowski-Górecki # # Copyright (C) 2014-2018 Wojtek Porczyk +# Copyright (C) 2019 Frédéric Pierret # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -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 @@ -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): @@ -76,3 +84,12 @@ def on_domain_qdb_create(self, vm, event): 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) From 5f934b43abf99a1578082f4bcfd2787a14a4ef95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sat, 9 Nov 2019 17:06:46 +0100 Subject: [PATCH 3/4] tests: add app guivm tests --- qubes/tests/app.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/qubes/tests/app.py b/qubes/tests/app.py index 0f06b641f..7a666396d 100644 --- a/qubes/tests/app.py +++ b/qubes/tests/app.py @@ -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, From 2ccdd4ee8e4f2faa900f0af4509e560276611872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Mon, 11 Nov 2019 11:27:40 +0100 Subject: [PATCH 4/4] gui: make pylint happy --- qubes/ext/gui.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index 83bfc9288..412ce6523 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -88,6 +88,7 @@ def on_domain_qdb_create(self, vm, event): @qubes.ext.handler('property-set:default_guivm', system=True) def on_property_set_default_guivm(self, app, event, name, newvalue, oldvalue=None): + # pylint: disable=unused-argument,no-self-use for vm in app.domains: if hasattr(vm, 'guivm') and vm.property_is_default('guivm'): vm.fire_event('property-set:guivm',