qubes/ext/gui: adjust guid parameters when running on KDE5

Commit from core2:

    commit 94d52a13e7

    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
This commit is contained in:
Marek Marczykowski-Górecki 2016-09-06 13:32:31 +02:00
parent 2285789b49
commit 19d9edc291
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -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: