From 27aad9bd3819d4fb1f7df9139a9ac7a575467f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sun, 20 Oct 2019 12:44:27 +0200 Subject: [PATCH] Handle GuiVM properties --- qubes/app.py | 5 +++++ qubes/ext/gui.py | 21 +++++++++++++++++++++ qubes/vm/qubesvm.py | 3 +++ 3 files changed, 29 insertions(+) diff --git a/qubes/app.py b/qubes/app.py index 65a70946..642736b0 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -716,6 +716,9 @@ class Qubes(qubes.PropertyHolder): Methods and attributes: """ + default_guivm = qubes.VMProperty('default_guivm', load_stage=3, + default=None, allow_none=True, + doc='Default GuiVM for VMs.') default_netvm = qubes.VMProperty('default_netvm', load_stage=3, default=None, allow_none=True, @@ -963,6 +966,7 @@ class Qubes(qubes.PropertyHolder): # stage 5: misc fixups + self.property_require('default_guivm', allow_none=True) self.property_require('default_netvm', allow_none=True) self.property_require('default_template', allow_none=True) self.property_require('clockvm', allow_none=True) @@ -1420,6 +1424,7 @@ class Qubes(qubes.PropertyHolder): def on_domain_deleted(self, event, vm): # pylint: disable=unused-argument for propname in ( + 'default_guivm' 'default_netvm', 'default_fw_netvm', 'clockvm', diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index 32380e78..6e2ec0f1 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -34,6 +34,18 @@ class GUI(qubes.ext.Extension): if vm.features.get('gui-seamless', False) else 'FULLSCREEN')) + @qubes.ext.handler('property-set:guivm') + def on_property_set(self, subject, event, name, newvalue, oldvalue=None): + # Clean other 'guivm-XXX' tags. + # gui-daemon can connect to only one domain + tags_list = list(subject.tags) + for tag in tags_list: + if 'guivm-' in tag: + subject.tags.remove(tag) + + guivm = 'guivm-' + newvalue.name + subject.tags.add(guivm) + @qubes.ext.handler('domain-qdb-create') def on_domain_qdb_create(self, vm, event): # pylint: disable=unused-argument,no-self-use @@ -45,3 +57,12 @@ class GUI(qubes.ext.Extension): feature)) except KeyError: pass + + # Add GuiVM Xen ID for gui-daemon + try: + if vm.guivm is not None: + if str(vm.name) != str(vm.guivm.name): + vm.untrusted_qdb.write('/qubes-gui-domain-xid', + str(vm.guivm.xid)) + except AttributeError: + vm.untrusted_qdb.write('/qubes-gui-domain-xid', '') diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 983584e9..90eb63d8 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -518,6 +518,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): # # properties loaded from XML # + guivm = qubes.VMProperty('guivm', load_stage=4, allow_none=True, + default=(lambda self: self.app.default_guivm), + doc='VM used for Gui') virt_mode = qubes.property( 'virt_mode',