Jelajahi Sumber

Handle GuiVM properties

Frédéric Pierret (fepitre) 5 tahun lalu
induk
melakukan
27aad9bd38
3 mengubah file dengan 29 tambahan dan 0 penghapusan
  1. 5 0
      qubes/app.py
  2. 21 0
      qubes/ext/gui.py
  3. 3 0
      qubes/vm/qubesvm.py

+ 5 - 0
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',

+ 21 - 0
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', '')

+ 3 - 0
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',