-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
config.py
executable file
·1659 lines (1503 loc) · 57.4 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# This file is part of Xpra.
# Copyright (C) 2010-2023 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.
import re
import sys
import os
import glob
import shlex
from typing import Any
from collections.abc import Callable, Iterable
from xpra.common import noop
from xpra.util.str_fn import csv
from xpra.os_util import WIN32, OSX, POSIX, getuid, getgid, get_username_for_uid
from xpra.util.env import osexpand
from xpra.util.io import stderr_print, which
from xpra.util.system import is_Ubuntu, is_Debian
def warn(msg: str) -> None:
stderr_print(msg)
def is_arm() -> bool:
import platform
return platform.uname()[4].startswith("arm")
# can be overridden
debug = noop
class InitException(Exception):
pass
class InitInfo(Exception):
pass
class InitExit(Exception):
def __init__(self, status, msg):
self.status = status
super().__init__(msg)
DEBUG_CONFIG_PROPERTIES: list[str] = os.environ.get("XPRA_DEBUG_CONFIG_PROPERTIES", "").split()
DEFAULT_XPRA_CONF_FILENAME : str = os.environ.get("XPRA_CONF_FILENAME", 'xpra.conf')
DEFAULT_NET_WM_NAME : str = os.environ.get("XPRA_NET_WM_NAME", "Xpra")
DEFAULT_POSTSCRIPT_PRINTER : str = ""
if POSIX:
DEFAULT_POSTSCRIPT_PRINTER = os.environ.get("XPRA_POSTSCRIPT_PRINTER", "drv:///sample.drv/generic.ppd")
DEFAULT_PULSEAUDIO = None # auto
if OSX or WIN32: # pragma: no cover
DEFAULT_PULSEAUDIO = False
# pylint: disable=import-outside-toplevel
def remove_dupes(seq: Iterable[Any]) -> list[Any]:
seen : set[Any] = set()
seen_add : Callable = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
_has_audio_support = None
def has_audio_support():
global _has_audio_support
if _has_audio_support is None:
try:
import xpra.audio
_has_audio_support = bool(xpra.audio)
except ImportError:
_has_audio_support = False
return _has_audio_support
def get_xorg_bin() -> str:
xorg = os.environ.get("XPRA_XORG_BIN")
if xorg:
return xorg
# Detect Xorg Binary
if is_arm() and is_Debian() and os.path.exists("/usr/bin/Xorg"):
# Raspbian breaks if we use a different binary..
return "/usr/bin/Xorg"
for p in (
"/usr/libexec/Xorg", # fedora 22+
"/usr/lib/xorg/Xorg", # ubuntu 16.10
"/usr/lib/xorg-server/Xorg", # arch linux
"/usr/lib/Xorg", # arch linux (new 2019)
"/usr/X11/bin/X", # OSX
):
if os.path.exists(p):
return p
# look for it in $PATH:
for x in os.environ.get("PATH", "").split(os.pathsep): # pragma: no cover
xorg = os.path.join(x, "Xorg")
if os.path.isfile(xorg):
return xorg
return ""
def get_Xdummy_confdir():
from xpra.platform.posix.paths import get_runtime_dir
xrd = get_runtime_dir()
if xrd:
base = "${XPRA_SESSION_DIR}"
else: # pragma: no cover
base = "${HOME}/.xpra"
return base+"/xorg.conf.d/$PID"
def get_Xdummy_command(xorg_cmd="Xorg",
log_dir="${XPRA_SESSION_DIR}",
xorg_conf="${XORG_CONFIG_PREFIX}/etc/xpra/xorg.conf") -> list[str]:
return [
# ie: "Xorg" or "xpra_Xdummy" or "./install/bin/xpra_Xdummy"
xorg_cmd,
"-noreset", "-novtswitch",
"-nolisten", "tcp",
"+extension", "GLX",
"+extension", "RANDR",
"+extension", "RENDER",
"-auth", "$XAUTHORITY",
"-logfile", f"{log_dir}/Xorg.log",
# must be specified with some Xorg versions (ie: arch linux)
# this directory can store xorg config files, it does not need to be created:
"-configdir", f'"{get_Xdummy_confdir()}"',
"-config", f'"{xorg_conf}"',
]
def get_Xvfb_command(width=8192, height=4096, dpi=96) -> list[str]:
cmd = [
"Xvfb",
"+extension", "GLX",
"+extension", "Composite",
"-screen", "0", f"{width}x{height}x24+32",
# better than leaving to vfb after a resize?
"-nolisten", "tcp",
"-noreset",
"-auth", "$XAUTHORITY",
]
if dpi > 0:
cmd += ["-dpi", f"{dpi}x{dpi}"]
return cmd
def detect_xvfb_command(conf_dir="/etc/xpra/", bin_dir="",
Xdummy_ENABLED: bool | None = None, Xdummy_wrapper_ENABLED: bool | None=None,
warn_fn:Callable = warn) -> list[str]:
"""
This function returns the xvfb command to use.
It can either be an `Xvfb` command or one that uses `Xdummy`,
depending on the platform and file attributes.
"""
if WIN32: # pragma: no cover
return []
if OSX: # pragma: no cover
return get_Xvfb_command()
if sys.platform.find("bsd")>=0 and Xdummy_ENABLED is None: # pragma: no cover
warn_fn(f"Warning: sorry, no support for Xdummy on {sys.platform}")
return get_Xvfb_command()
# if is_arm():
# arm used to struggle to launch Xdummy because of
# the large number of pre-defined resolutions,
# but it should work OK now that we use RandR 1.6
# return get_Xvfb_command()
if is_Ubuntu() or is_Debian():
# These distros do weird things and this can cause the real X11 server to crash
# see ticket #2834
return get_Xvfb_command()
if Xdummy_ENABLED is False:
return get_Xvfb_command()
if Xdummy_ENABLED is None:
debug("Xdummy support unspecified, will try to detect")
return detect_xdummy_command(conf_dir, bin_dir, Xdummy_wrapper_ENABLED, warn_fn)
def detect_xdummy_command(conf_dir="/etc/xpra/", bin_dir="",
Xdummy_wrapper_ENABLED: bool | None = None,
warn_fn: Callable = warn) -> list[str]:
if not POSIX or OSX:
return get_Xvfb_command()
xorg_bin = get_xorg_bin()
if Xdummy_wrapper_ENABLED is not None:
# honour what was specified:
use_wrapper = Xdummy_wrapper_ENABLED
elif not xorg_bin:
warn_fn("Warning: Xorg binary not found, assuming the wrapper is needed!")
use_wrapper = True
else:
# auto-detect
import stat
xorg_stat = os.stat(xorg_bin)
if (xorg_stat.st_mode & stat.S_ISUID)!=0:
if (xorg_stat.st_mode & stat.S_IROTH)==0:
warn_fn(f"{xorg_bin} is suid and not readable, Xdummy support unavailable")
return get_Xvfb_command()
debug(f"{xorg_bin} is suid and readable, using the xpra_Xdummy wrapper")
use_wrapper = True
else:
use_wrapper = False
xorg_conf = "${XORG_CONFIG_PREFIX}"+os.path.join(conf_dir, "xorg.conf")
if use_wrapper:
xorg_cmd = "xpra_Xdummy"
else:
xorg_cmd = xorg_bin or "Xorg"
# so we can run from install dir:
if bin_dir and os.path.exists(os.path.join(bin_dir, xorg_cmd)):
if bin_dir not in os.environ.get("PATH", "/bin:/usr/bin:/usr/local/bin").split(os.pathsep):
xorg_cmd = os.path.join(bin_dir, xorg_cmd)
return get_Xdummy_command(xorg_cmd, xorg_conf=xorg_conf)
def wrap_cmd_str(cmd) -> str:
xvfb_str = ""
cr = " \\\n "
while cmd:
s = ""
while cmd:
item = cmd[0]
l = len(item)
if (item.startswith("-") or item.startswith("+")) and len(cmd)>1:
l += len(cmd[1])
if s and len(s)+l > 55:
break
v = cmd.pop(0)
if not s:
s += v
else:
s += " "+v
if xvfb_str:
xvfb_str += cr
xvfb_str += s
return xvfb_str
def get_build_info() -> list[str]:
info = []
try:
from xpra.src_info import REVISION, LOCAL_MODIFICATIONS, BRANCH, COMMIT
info.append(f"revision {REVISION}")
if COMMIT:
info.append(f"commit {COMMIT} from {BRANCH} branch")
try:
mods = int(LOCAL_MODIFICATIONS)
info.append(f"with {mods} local changes")
except ValueError:
pass
except Exception as e:
warn(f"Error: could not find the source information: {e}")
try:
from xpra.build_info import (
BUILD_DATE, BUILD_TIME, BUILD_BIT,
CYTHON_VERSION, COMPILER_VERSION,
)
info.insert(0, "")
einfo = "Python " + ".".join(str(v) for v in sys.version_info[:2])
if BUILD_BIT:
einfo += ", "+BUILD_BIT
info.insert(0, einfo)
try:
from xpra.build_info import BUILT_BY, BUILT_ON
info.append(f"built on {BUILT_ON} by {BUILT_BY}")
except ImportError:
# reproducible builds dropped this info
pass
if BUILD_DATE and BUILD_TIME:
info.append(f"{BUILD_DATE} {BUILD_TIME}")
if CYTHON_VERSION != "unknown" or COMPILER_VERSION != "unknown":
info.append("")
if CYTHON_VERSION != "unknown":
info.append(f"using Cython {CYTHON_VERSION}")
if COMPILER_VERSION != "unknown":
cv = COMPILER_VERSION.replace("Optimizing Compiler Version", "Optimizing Compiler\nVersion")
info += cv.splitlines()
except Exception as e:
warn(f"Error: could not find the build information: {e}")
return info
def name_to_field(name: str) -> str:
return name.replace("-", "_")
def save_config(conf_file: str, config, keys, extras_types=None):
with open(conf_file, "w", encoding="utf8") as f:
option_types = OPTION_TYPES.copy()
if extras_types:
option_types.update(extras_types)
saved = {}
for key in keys:
if key not in option_types:
raise ValueError(f"invalid configuration key {key!r}")
v = getattr(config, name_to_field(key))
saved[key] = v
f.write(f"{key}={v}{os.linesep}")
debug(f"save_config: saved {saved} to {conf_file!r}")
def read_config(conf_file: str) -> dict[str, Any]:
"""
Parses a config file into a dict of strings.
If the same key is specified more than once,
the value for this key will be an array of strings.
"""
d : dict[str, str | list[str]] = {}
if not os.path.exists(conf_file) or not os.path.isfile(conf_file):
debug("read_config(%s) is not a file or does not exist", conf_file)
return d
with open(conf_file, encoding="utf8") as f:
lines = []
no = 0
for line in f:
sline = line.strip().strip('\r\n').strip()
no += 1
if not sline:
debug("%4s empty line", no)
continue
if sline[0] in ('!', '#'):
debug("%4s skipping comments : %s", no, sline[:16]+"..")
continue
debug("%4s loaded : %s", no, sline)
lines.append(sline)
debug("loaded %s lines", len(lines))
# aggregate any lines with trailing backslash
agg_lines = []
l = ""
for line in lines:
if line.endswith("\\"):
l += line[:-1]+" "
else:
l += line
agg_lines.append(l)
l = ""
if l:
# last line had a trailing backslash... meh
agg_lines.append(l)
debug("loaded %s aggregated lines", len(agg_lines))
# parse name=value pairs:
for sline in agg_lines:
if sline.find("=") <= 0:
debug(f"skipping line which is missing an equal sign: {sline!r}")
continue
props = sline.split("=", 1)
assert len(props) == 2
name = props[0].strip()
value = props[1].strip()
current_value = d.get(name)
if current_value:
if isinstance(current_value, list):
d[name] = current_value + [value]
else:
d[name] = [current_value, value]
debug("added to: %s='%s'", name, d[name])
else:
debug("assigned (new): %s='%s'", name, value)
d[name] = value
if name in DEBUG_CONFIG_PROPERTIES:
from xpra.log import Logger
log = Logger("util")
log.info(f"{name}={d[name]} (was {current_value}), from {conf_file!r}")
return d
def conf_files(conf_dir: str, xpra_conf_filename: str = DEFAULT_XPRA_CONF_FILENAME) -> list[str]:
"""
Returns all the config file paths found in the config directory
ie: ["/etc/xpra/conf.d/15_features.conf", ..., "/etc/xpra/xpra.conf"]
"""
d: list[str] = []
cdir = os.path.expanduser(conf_dir)
if not os.path.exists(cdir) or not os.path.isdir(cdir):
debug(f"invalid config directory: {cdir!r}")
return d
# look for conf.d subdirectory:
conf_d_dir = os.path.join(cdir, "conf.d")
if os.path.exists(conf_d_dir) and os.path.isdir(conf_d_dir):
for f in sorted(os.listdir(conf_d_dir)):
if f.endswith(".conf"):
conf_file = os.path.join(conf_d_dir, f)
if os.path.isfile(conf_file):
d.append(conf_file)
conf_file = os.path.join(cdir, xpra_conf_filename)
if not os.path.exists(conf_file) or not os.path.isfile(conf_file):
debug(f"config file does not exist: {conf_file!r}")
else:
d.append(conf_file)
return d
def read_xpra_conf(conf_dir: str) -> dict[str, Any]:
"""
Reads all config files from the directory,
returns a dict with key as strings,
values as strings or arrays of strings.
"""
cdir = os.path.expanduser(conf_dir)
if not os.path.exists(cdir) or not os.path.isdir(cdir):
debug(f"invalid config directory: {cdir!r}")
return {}
files = glob.glob(f"{cdir}/{DEFAULT_XPRA_CONF_FILENAME}") + glob.glob(f"{cdir}/conf.d/*.conf")
debug(f"read_xpra_conf({conf_dir}) found conf files: {files}")
d = {}
for f in files:
cd = read_config(f)
debug(f"config({f})={cd}")
d.update(cd)
return d
def read_xpra_defaults(username: str | None = None, uid=None, gid=None):
"""
Reads the global <xpra_conf_filename> from the <conf_dir>
and then the user-specific one.
(the latter overrides values from the former)
returns a dict with values as strings and arrays of strings.
If the <conf_dir> is not specified, we figure out its location.
"""
dirs = get_xpra_defaults_dirs(username, uid, gid)
defaults = {}
for d in dirs:
conf_data = read_xpra_conf(d)
defaults.update(conf_data)
debug(f"read_xpra_defaults: updated defaults with {d!r} : {conf_data}")
may_create_user_config()
return defaults
def get_xpra_defaults_dirs(username: str | None = None, uid=None, gid=None):
from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
# load config files in this order (the later ones override earlier ones):
# * application defaults (ie: "/Volumes/Xpra/Xpra.app/Contents/Resources/" on OSX)
# (ie: "C:\Program Files\Xpra\" on win32)
# (ie: None on others)
# * system defaults (ie: "/etc/xpra" on Posix - not on OSX)
# (ie: "/Library/Application Support/Xpra" on OSX)
# (ie: "C:\Documents and Settings\All Users\Application Data\Xpra" with XP)
# (ie: "C:\ProgramData\Xpra" with Vista onwards)
# * user config (ie: "~/.xpra/" on all Posix, including OSX)
# (ie: "C:\Documents and Settings\Username\Application Data\Xpra" with XP)
# (ie: "C:\Users\<user name>\AppData\Roaming" with Visa onwards)
dirs = get_default_conf_dirs() + get_system_conf_dirs() + get_user_conf_dirs(uid)
defaults_dirs = []
for d in dirs:
if not d:
continue
ad = osexpand(d, actual_username=username, uid=uid, gid=gid)
if not os.path.exists(ad):
debug(f"get_xpra_defaults_dirs: skipped missing directory {ad!r}")
continue
defaults_dirs.append(ad)
return defaults_dirs
def may_create_user_config(xpra_conf_filename:str = DEFAULT_XPRA_CONF_FILENAME):
from xpra.platform.paths import get_user_conf_dirs
# save a user config template:
udirs = get_user_conf_dirs()
if udirs:
has_user_conf = None
for d in udirs:
if os.path.exists(d):
has_user_conf = d
break
if not has_user_conf:
debug("no user configuration file found, trying to create one")
for d in udirs:
ad = os.path.expanduser(d)
conf_file = os.path.join(ad, xpra_conf_filename)
try:
if not os.path.exists(ad):
os.makedirs(ad, int('700', 8))
with open(conf_file, 'w', encoding="utf8") as f:
f.write("""# xpra user configuration file
# place your custom settings in this file
# they will take precedence over the system default ones.
# Examples:
# speaker=off
# dpi=144
# For more information on the file format,
# see the xpra manual at:
# https://github.com/Xpra-org/xpra/tree/master/docs/
""")
f.flush()
debug(f"created default config in {d!r}")
break
except Exception as e:
debug(f"failed to create default config in {conf_file!r}: {e}")
OPTIONS_VALIDATION : dict[str, Callable] = {}
OPTION_TYPES = {
# string options:
"encoding" : str,
"opengl" : str,
"title" : str,
"username" : str,
"password" : str,
"wm-name" : str,
"session-name" : str,
"dock-icon" : str,
"tray-icon" : str,
"window-icon" : str,
"keyboard-raw" : bool,
"keyboard-layout" : str,
"keyboard-layouts" : list,
"keyboard-variant" : str,
"keyboard-variants" : list,
"keyboard-options" : str,
"clipboard" : str,
"clipboard-direction" : str,
"clipboard-filter-file" : str,
"remote-clipboard" : str,
"local-clipboard" : str,
"pulseaudio-command": str,
"bandwidth-limit" : str,
"tcp-encryption" : str,
"tcp-encryption-keyfile": str,
"encryption" : str,
"encryption-keyfile": str,
"pidfile" : str,
"mode" : str,
"ssh" : str,
"systemd-run" : str,
"systemd-run-args" : str,
"system-proxy-socket" : str,
"chdir" : str,
"xvfb" : str,
"socket-dir" : str,
"sessions-dir" : str,
"mmap" : str,
"log-dir" : str,
"log-file" : str,
"border" : str,
"window-close" : str,
"min-size" : str,
"max-size" : str,
"desktop-scaling" : str,
"refresh-rate" : str,
"display" : str,
"download-path" : str,
"open-command" : str,
"remote-logging" : str,
"lpadmin" : str,
"lpinfo" : str,
"add-printer-options" : list,
"pdf-printer" : str,
"postscript-printer": str,
"debug" : str,
"input-method" : str,
"video-scaling" : str,
"video" : bool,
"audio" : bool,
"microphone" : str,
"speaker" : str,
"audio-source" : str,
"html" : str,
"http-scripts" : str,
"socket-permissions": str,
"exec-wrapper" : str,
"dbus-launch" : str,
"webcam" : str,
"mousewheel" : str,
"input-devices" : str,
"shortcut-modifiers": str,
"open-files" : str,
"open-url" : str,
"file-transfer" : str,
"printing" : str,
"headerbar" : str,
"challenge-handlers": list,
# ssl options:
"ssl" : str,
"ssl-key" : str,
"ssl-key-password" : str,
"ssl-cert" : str,
"ssl-protocol" : str,
"ssl-ca-certs" : str,
"ssl-ca-data" : str,
"ssl-ciphers" : str,
"ssl-client-verify-mode" : str,
"ssl-server-verify-mode" : str,
"ssl-verify-flags" : str,
"ssl-check-hostname": bool,
"ssl-server-hostname" : str,
"ssl-options" : str,
# int options:
"displayfd" : int,
"pings" : int,
"quality" : int,
"min-quality" : int,
"speed" : int,
"min-speed" : int,
"compression_level" : int,
"dpi" : int,
"file-size-limit" : str,
"idle-timeout" : int,
"server-idle-timeout" : int,
"sync-xvfb" : int,
"pixel-depth" : int,
"uid" : int,
"gid" : int,
"min-port" : int,
"rfb-upgrade" : int,
# float options:
"auto-refresh-delay": float,
# boolean options:
"minimal" : bool,
"daemon" : bool,
"start-via-proxy" : bool,
"attach" : bool,
"use-display" : str,
"resize-display" : str,
"reconnect" : bool,
"tray" : bool,
"pulseaudio" : bool,
"mmap-group" : str,
"readonly" : bool,
"keyboard-sync" : bool,
"cursors" : bool,
"bell" : bool,
"notifications" : bool,
"xsettings" : str,
"system-tray" : bool,
"sharing" : bool,
"lock" : bool,
"delay-tray" : bool,
"windows" : bool,
"terminate-children": bool,
"exit-with-children": bool,
"exit-with-client" : bool,
"exit-with-windows" : bool,
"exit-ssh" : bool,
"dbus-control" : bool,
"av-sync" : bool,
"mdns" : bool,
"swap-keys" : bool,
"start-new-commands": bool,
"proxy-start-sessions": bool,
"desktop-fullscreen": bool,
"forward-xdg-open" : bool,
"modal-windows" : bool,
"bandwidth-detection" : bool,
"ssl-upgrade" : bool,
"websocket-upgrade" : bool,
"ssh-upgrade" : bool,
"splash" : bool,
# arrays of strings:
"pulseaudio-configure-commands" : list,
"socket-dirs" : list,
"client-socket-dirs" : list,
"remote-xpra" : list,
"encodings" : list,
"proxy-video-encoders" : list,
"video-encoders" : list,
"csc-modules" : list,
"video-decoders" : list,
"speaker-codec" : list,
"microphone-codec" : list,
"compressors" : list,
"packet-encoders" : list,
"key-shortcut" : list,
"source" : list,
"source-start" : list,
"start" : list,
"start-late" : list,
"start-child" : list,
"start-child-late" : list,
"start-after-connect" : list,
"start-child-after-connect" : list,
"start-on-connect" : list,
"start-child-on-connect" : list,
"start-on-last-client-exit" : list,
"start-child-on-last-client-exit" : list,
"bind" : list,
"bind-vsock" : list,
"bind-tcp" : list,
"bind-ws" : list,
"bind-wss" : list,
"bind-ssl" : list,
"bind-ssh" : list,
"bind-rfb" : list,
"bind-quic" : list,
"auth" : list,
"vsock-auth" : list,
"tcp-auth" : list,
"ws-auth" : list,
"wss-auth" : list,
"ssl-auth" : list,
"ssh-auth" : list,
"rfb-auth" : list,
"quic-auth" : list,
"password-file" : list,
"start-env" : list,
"env" : list,
}
# in the options list, available in session files,
# but not on the command line:
NON_COMMAND_LINE_OPTIONS : list[str] = [
"mode",
"wm-name",
"download-path",
"display",
"pdf-printer",
"postscript-printer",
"add-printer-options",
]
START_COMMAND_OPTIONS : list[str] = [
"start", "start-child",
"start-late", "start-child-late",
"start-after-connect", "start-child-after-connect",
"start-on-connect", "start-child-on-connect",
"start-on-last-client-exit", "start-child-on-last-client-exit",
]
BIND_OPTIONS : list[str] = [
"bind", "bind-tcp", "bind-ssl", "bind-ws", "bind-wss", "bind-vsock", "bind-rfb", "bind-quic",
]
# keep track of the options added since v5,
# so we can generate command lines that work with older supported versions:
OPTIONS_ADDED_SINCE_V5 : list[str] = [
"minimal",
]
OPTIONS_COMPAT_NAMES : dict[str, str] = {
"--compression_level=" : "-z"
}
CLIENT_OPTIONS : list[str] = [
"title", "username", "password", "session-name",
"dock-icon", "tray-icon", "window-icon",
"clipboard", "clipboard-direction", "clipboard-filter-file",
"remote-clipboard", "local-clipboard",
"tcp-encryption", "tcp-encryption-keyfile", "encryption", "encryption-keyfile",
"systemd-run", "systemd-run-args",
"socket-dir", "socket-dirs", "client-socket-dirs",
"border", "window-close", "min-size", "max-size", "desktop-scaling",
"file-transfer", "file-size-limit", "download-path",
"open-command", "open-files", "printing", "open-url",
"headerbar",
"challenge-handlers",
"remote-logging",
"lpadmin", "lpinfo",
"debug",
"microphone", "speaker", "audio-source",
"microphone-codec", "speaker-codec",
"mmap", "encodings", "encoding",
"quality", "min-quality", "speed", "min-speed",
"compression_level",
"dpi", "video-scaling", "auto-refresh-delay",
"webcam", "mousewheel", "input-devices", "shortcut-modifiers", "pings",
"tray", "keyboard-sync", "cursors", "bell", "notifications",
"xsettings", "system-tray", "sharing", "lock",
"delay-tray", "windows", "readonly",
"av-sync", "swap-keys",
"opengl",
"start-new-commands",
"desktop-fullscreen",
"video-encoders", "csc-modules", "video-decoders",
"compressors", "packet-encoders",
"key-shortcut",
"env",
]
CLIENT_ONLY_OPTIONS : list[str] = [
"username", "swap-keys", "dock-icon",
"tray", "delay-tray", "tray-icon",
"attach",
"reconnect",
]
# options that clients can pass to the proxy
# and which will be forwarded to the new proxy instance process:
PROXY_START_OVERRIDABLE_OPTIONS : list[str] = [
"env", "start-env", "chdir",
"dpi",
"encoding", "encodings",
"quality", "min-quality", "speed", "min-speed",
# "auto-refresh-delay", float!
# no corresponding command line option:
# "wm-name", "download-path",
"compression_level", "video-scaling",
"title", "session-name",
"clipboard", "clipboard-direction", "clipboard-filter-file",
"input-method",
"video",
"audio", "microphone", "speaker", "audio-source", "pulseaudio",
"idle-timeout", "server-idle-timeout",
"use-display",
"resize-display", "dpi", "pixel-depth",
"readonly", "keyboard-sync", "cursors", "bell", "notifications", "xsettings",
"system-tray", "sharing", "lock", "windows", "webcam", "html", "http-scripts",
"terminate-children", "exit-with-children", "exit-with-client", "exit-with-windows",
"av-sync",
"forward-xdg-open", "modal-windows", "bandwidth-detection",
"ssh-upgrade",
"splash",
"printing", "file-transfer", "open-command", "open-files", "open-url", "start-new-commands",
"mmap", "mmap-group", "mdns",
"auth", "vsock-auth", "tcp-auth", "ws-auth", "wss-auth", "ssl-auth", "ssh-auth", "rfb-auth", "quic-auth",
"bind", "bind-vsock", "bind-tcp", "bind-ssl", "bind-ws", "bind-wss", "bind-ssh", "bind-rfb", "bind-quic",
"rfb-upgrade", "bandwidth-limit",
"start", "start-child",
"start-late", "start-child-late",
"source", "source-start",
"start-after-connect", "start-child-after-connect",
"start-on-connect", "start-child-on-connect",
"start-on-last-client-exit", "start-child-on-last-client-exit",
"sessions-dir",
]
tmp: str = os.environ.get("XPRA_PROXY_START_OVERRIDABLE_OPTIONS", "")
if tmp:
PROXY_START_OVERRIDABLE_OPTIONS = tmp.split(",")
del tmp
def get_default_key_shortcuts() -> list[str]:
return [shortcut for e, shortcut in (
(True, "Control+Menu:toggle_keyboard_grab"),
(True, "Shift+Menu:toggle_pointer_grab"),
(not OSX, "Shift+F11:toggle_fullscreen"),
(OSX, "Control+F11:toggle_fullscreen"),
(True, "#+F1:show_menu"),
(True, "#+F2:show_start_new_command"),
(True, "#+F3:show_bug_report"),
(True, "#+F4:quit"),
(True, "#+F5:show_window_info"),
(True, "#+F6:show_shortcuts"),
(True, "#+F7:show_docs"),
(True, "#+F8:toggle_keyboard_grab"),
(True, "#+F9:toggle_pointer_grab"),
(True, "#+F10:magic_key"),
(True, "#+F11:show_session_info"),
(True, "#+F12:toggle_debug"),
(True, "#+plus:scaleup"),
(OSX, "#+plusminus:scaleup"),
(True, "#+minus:scaledown"),
(True, "#+underscore:scaledown"),
(OSX, "#+emdash:scaledown"),
(True, "#+KP_Add:scaleup"),
(True, "#+KP_Subtract:scaledown"),
(True, "#+KP_Multiply:scalereset"),
(True, "#+bar:scalereset"),
(True, "#+question:scalingoff"),
(OSX, "#+degree:scalereset"),
(OSX, "meta+grave:void"),
(OSX, "meta+shift+asciitilde:void"),
)
if e]
def get_default_systemd_run() -> str:
if WIN32 or OSX:
return "no"
# systemd-run was previously broken in Fedora 26:
# https://github.com/systemd/systemd/issues/3388
# but with newer kernels, it is working again..
# now that we test it before using it,
# it should be safe to leave it on auto:
return "auto"
def get_default_pulseaudio_command() -> list[str]:
if WIN32 or OSX:
return []
def description(desc):
return f"device.description=\"{desc}\""
def load_opt(name, **kwargs):
args = " ".join([f"--load={name}"] + [f"{n}={v}" for n, v in kwargs.items()])
return f"'{args}'"
cmd = [
"pulseaudio", "--start", "-n", "--daemonize=false", "--system=false",
"--exit-idle-time=-1", "--load=module-suspend-on-idle",
load_opt("module-null-sink",
sink_name="Xpra-Speaker",
sink_properties=description("Xpra\\ Speaker")),
load_opt("module-null-sink",
sink_name="Xpra-Microphone",
sink_properties=description("Xpra\\ Microphone")),
load_opt("module-remap-source",
source_name="Xpra-Mic-Source",
source_properties=description("Xpra\\ Mic\\ Source"),
master="Xpra-Microphone.monitor",
channels=1),
load_opt("module-native-protocol-unix", socket="$XPRA_PULSE_SERVER"),
load_opt("module-dbus-protocol"),
load_opt("module-x11-publish"),
"--log-level=2", "--log-target=stderr",
]
from xpra.util.env import envbool
if not envbool("XPRA_PULSEAUDIO_MEMFD", False):
cmd.append("--enable-memfd=no")
if not envbool("XPRA_PULSEAUDIO_REALTIME", True):
cmd.append("--realtime=no")
if not envbool("XPRA_PULSEAUDIO_HIGH_PRIORITY", True):
cmd.append("--high-priority=no")
return cmd
def unexpand(path: str) -> str:
xrd = os.environ.get("XDG_RUNTIME_DIR", "")
if POSIX and xrd and path.startswith(xrd):
return "$XDG_RUNTIME_DIR/" + path[len(xrd):].lstrip("/")
home = os.environ.get("HOME", "")
if POSIX and home and path.startswith(home):
return "~/" + path[len(home):].lstrip("/")
return path
def unexpand_all(paths: list[str]) -> list[str]:
return [unexpand(x) for x in paths]
GLOBAL_DEFAULTS = None
# lowest common denominator here
# (the xpra.conf file shipped is generally better tuned than this - especially for 'xvfb')
def get_defaults() -> dict[str, Any]:
global GLOBAL_DEFAULTS
if GLOBAL_DEFAULTS is not None:
return GLOBAL_DEFAULTS
from xpra.platform.features import (
OPEN_COMMAND, DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS,
SOURCE, DEFAULT_ENV, DEFAULT_START_ENV, CAN_DAEMONIZE, SYSTEM_PROXY_SOCKET,
)
from xpra.platform.paths import (
get_download_dir, get_remote_run_xpra_scripts,
get_sessions_dir, get_socket_dirs, get_client_socket_dirs,
)
conf_dirs = [os.environ.get("XPRA_CONF_DIR", "")]
build_root = os.environ.get("RPM_BUILD_ROOT")
if build_root:
conf_dirs.append(os.path.join(build_root, "etc", "xpra"))
bin_dir = ""
if sys.argv:
xpra_cmd = sys.argv[0]
for strip in ("/usr/bin", "/bin"):
pos = xpra_cmd.find(strip)
if pos >= 0:
bin_dir = xpra_cmd[:pos+len(strip)]
root = xpra_cmd[:pos] or "/"
conf_dirs.append(os.path.join(root, "etc", "xpra"))
break
if sys.prefix == "/usr":
conf_dirs.append("/etc/xpra")
else:
conf_dirs.append(os.path.join(sys.prefix, "etc", "xpra"))
try:
conf_dirs.append(os.getcwd())
except FileNotFoundError:
pass
conf_dir = ""
for conf_dir in conf_dirs:
if conf_dir and os.path.exists(conf_dir):
break
xvfb = detect_xvfb_command(conf_dir, bin_dir, warn_fn=noop)
xdummy = detect_xdummy_command(conf_dir, bin_dir, warn_fn=noop)
ssl_protocol = "TLS"
GLOBAL_DEFAULTS = {
"encoding" : "auto",
"title" : "@title@ on @hostinfo@",
"username" : "",
"password" : "",
"wm-name" : DEFAULT_NET_WM_NAME,
"session-name" : "",
"dock-icon" : "",
"tray-icon" : "",
"window-icon" : "",
"keyboard-raw" : False,
"keyboard-layout" : "",
"keyboard-layouts" : [],
"keyboard-variant" : "",
"keyboard-variants" : [],
"keyboard-options" : "",
"clipboard" : "yes",
"clipboard-direction" : "both",
"clipboard-filter-file" : "",
"remote-clipboard" : "CLIPBOARD",
"local-clipboard" : "CLIPBOARD",