Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noseratio/c38cff3d4ad293f85249301be77fccb8 to your computer and use it in GitHub Desktop.
Save noseratio/c38cff3d4ad293f85249301be77fccb8 to your computer and use it in GitHub Desktop.
Use existing Xorg session for chrome-remote-desktop
Add an option to use the existing Xorg session with
chrome-remote-desktop.
The original idea of the patch: https://superuser.com/a/850359
--- a/chrome-remote-desktop 2021-04-05 11:53:16.537908500 +0000
+++ b/chrome-remote-desktop 2021-04-05 12:04:52.768536483 +0000
@@ -107,6 +107,8 @@
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock"
FIRST_X_DISPLAY_NUMBER = 20
+EXISTING_X_DISPLAY_FILE_PATH = os.path.join(CONFIG_DIR, "Xsession")
+X_SESSION_FILE_TEMPLATE = "/tmp/.X11-unix/X%d"
# Amount of time to wait between relaunching processes.
SHORT_BACKOFF_TIME = 5
@@ -774,14 +776,36 @@
"Session output: ", SESSION_OUTPUT_TIME_LIMIT_SECONDS)
output_filter_thread.start()
+ def _use_existing_session(self):
+ with open(EXISTING_X_DISPLAY_FILE_PATH) as fh:
+ try:
+ display = int(fh.readline().rstrip())
+ except ValueError:
+ logging.error("Display is not a number")
+ sys.exit(1)
+ if not os.path.exists(X_SESSION_FILE_TEMPLATE % display):
+ logging.error("Xorg session file doesn't exist")
+ sys.exit(1)
+
+ logging.info("Using existing Xorg session: %d" % display)
+ self.child_env["DISPLAY"] = ":%d" % display
+ self.child_env["CHROME_REMOTE_DESKTOP_SESSION"] = "1"
+
+ # Set SSH_AUTH_SOCK to the file name to listen on.
+ if self.ssh_auth_sockname:
+ self.child_env["SSH_AUTH_SOCK"] = self.ssh_auth_sockname
+
def launch_session(self, x_args):
self._init_child_env()
self._setup_pulseaudio()
self._setup_gnubby()
- self._launch_x_server(x_args)
- if not self._launch_pre_session():
- # If there was no pre-session script, launch the session immediately.
- self.launch_x_session()
+ if os.path.exists(EXISTING_X_DISPLAY_FILE_PATH):
+ self._use_existing_session()
+ else:
+ self._launch_x_server(x_args)
+ if not self._launch_pre_session():
+ # If there was no pre-session script, launch the session immediately.
+ self.launch_x_session()
def launch_host(self, host_config, extra_start_host_args):
# Start remoting host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment