From 19d9edc291f15012630531aadceb519461a5aca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 6 Sep 2016 13:32:31 +0200 Subject: [PATCH] qubes/ext/gui: adjust guid parameters when running on KDE5 Commit from core2: commit 94d52a13e79dc0274593768ad39ba68f19e5131c core: adjust guid parameters when running on KDE5 On KDE5 native decoration plugin is used and requires special properties set (instead of `_QUBES_VMNAME` etc). Special care needs to be taken when detecting environment, because environment variables aren't good enough - this script may be running with cleared environment (through sudo, or from systemd). So check properties of X11 root window. QubesOS/qubes-issues#1784 --- qubes/ext/gui.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index f3dccbe9..82de66cd 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -94,6 +94,40 @@ def get_monitor_layout(): class GUI(qubes.ext.Extension): + @staticmethod + def kde_guid_args(vm): + '''Return KDE-specific arguments for guid, if applicable''' + + guid_cmd = [] + # Avoid using environment variables for checking the current session, + # because this script may be called with cleared env (like with sudo). + if subprocess.check_output( + ['xprop', '-root', '-notype', 'KDE_SESSION_VERSION']) == \ + 'KDE_SESSION_VERSION = 5\n': + # native decoration plugins is used, so adjust window properties + # accordingly + guid_cmd += ['-T'] # prefix window titles with VM name + # get owner of X11 session + session_owner = None + for line in subprocess.check_output(['xhost']).splitlines(): + if line == 'SI:localuser:root': + pass + elif line.startswith('SI:localuser:'): + session_owner = line.split(":")[2] + if session_owner is not None: + data_dir = os.path.expanduser( + '~{}/.local/share'.format(session_owner)) + else: + # fallback to current user + data_dir = os.path.expanduser('~/.local/share') + + guid_cmd += ['-p', + '_KDE_NET_WM_COLOR_SCHEME=s:{}'.format( + os.path.join(data_dir, + 'qubes-kde', vm.label.name + '.colors'))] + return guid_cmd + + @qubes.ext.handler('domain-start', 'domain-cmd-pre-run') def start_guid(self, vm, event, preparing_dvm=False, start_guid=True, extra_guid_args=None, **kwargs): @@ -146,6 +180,8 @@ class GUI(qubes.ext.Extension): open(stubdom_guid_pidfile, 'r').read().strip() guid_cmd += ['-K', stubdom_guid_pid] + guid_cmd += self.kde_guid_args(vm) + try: subprocess.check_call(guid_cmd) except subprocess.CalledProcessError: @@ -207,6 +243,8 @@ class GUI(qubes.ext.Extension): else: guid_cmd += ['-q'] + guid_cmd += self.kde_guid_args(vm) + try: subprocess.check_call(guid_cmd) except subprocess.CalledProcessError: