This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_scaled.py
executable file
·105 lines (86 loc) · 2.99 KB
/
run_scaled.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
#!/usr/bin/env python3
copyright_info = '''\
run-scaled, a Python script to run an X application scaled via Xpra
Copyright (c) 2021, Sam L. Yes <https://github.com/SamLukeYes>
Original bash script:
run_scaled <https://github.com/kaueraal/run_scaled>
Copyright (c) 2017, Alexander Kauer
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import argparse
import os
import random
import time
performance_options = "--encoding=rgb --mmap=yes --compress=0"
parser = argparse.ArgumentParser()
parser.add_argument(
'--scale',
dest='scaling_factor',
default=2.0,
type=float,
help='Sets the factor the application is scaled by. \
Fractional scales are supported. It is set to 2 by default.'
)
parser.add_argument(
'--opengl',
choices=['auto', 'yes', 'no'],
default='auto',
help='Sets whether xpra should use opengl for rendering. \
If you get rendering errors, \
especially when the window is resized, try setting it to no. \
It is set to auto by default.'
)
parser.add_argument(
'--sleep',
default=1.0,
dest='sleeptime',
type=float,
help='Sets how many seconds to wait after starting xpra before \
attaching to the xpra session. It is set to 1 by default. \
You might need to increase the value if your machine is \
particularly slow.'
)
parser.add_argument(
'--ime', '--input-method',
help='Sets the IME daemon to run with the application.'
)
parser.add_argument('application', nargs='*')
args = parser.parse_args()
if not args.application:
print(copyright_info)
parser.print_help()
exit(0)
resolution = os.popen("xrandr | grep \\* | cut -d' ' -f4").read().strip()
scaled_resolution = tuple(
map(
lambda x: int(int(x) / args.scaling_factor),
resolution.split('x')
)
)
displaynum = random.randint(10000, 99999999)
escaped_params = ' '.join(args.application)
cmd = f'xpra start ":{displaynum}" --xvfb="Xvfb +extension Composite \
-screen 0 {scaled_resolution[0]}x{scaled_resolution[1]}x24+32 \
-nolisten tcp -noreset -auth \\$XAUTHORITY" \
--env=GDK_SCALE=1 --env=GDK_DPI_SCALE=1 \
--start-child="{escaped_params}" --exit-with-children \
--input-method=keep --start={args.ime}'
print(cmd)
os.system(cmd)
time.sleep(args.sleeptime)
os.system(
f'xpra attach ":{displaynum}" \
"--desktop-scaling={args.scaling_factor}" \
"--opengl={args.opengl}" {performance_options} || \
xpra stop ":{displaynum}"'
)