From 29f54a9d9bc8479c4e02e5be537fdf46ecfcef9e Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Sun, 30 Mar 2025 12:33:58 +0200 Subject: [PATCH] Support unix-based X11 server connections as well as TCP-based ones Typically, on unix systems, local X11 is connected through the socket `/tmp/.X11-unix/X0`, as indicated by the missing host name part in `DISPLAY=:0` or `DISPLAY=:0.0`. WSLg (the X11 implementation provided with WSL in Microsoft Windows) does not listen on the TCP socket localhost:6000, but on the Unix socket only. So this commit enables SSH X11 forwarding to connect to the unix domain socket if the X server host name is set to the empty string. --- package.json | 12 ++++++------ src/backend/mi2/mi2.ts | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 107d513..bea5c72 100644 --- a/package.json +++ b/package.json @@ -281,12 +281,12 @@ "number", "string" ], - "description": "Port to redirect X11 data to (by default port = display + 6000)", + "description": "TCP port to redirect X11 data to (by default port = display + 6000); raw display number for unix domain connection", "default": 6000 }, "x11host": { "type": "string", - "description": "Hostname/ip to redirect X11 data to", + "description": "Hostname/ip to redirect X11 data to; empty string for a unix domain connection", "default": "localhost" }, "remotex11screen": { @@ -455,12 +455,12 @@ "number", "string" ], - "description": "Port to redirect X11 data to (by default port = display + 6000)", + "description": "TCP port to redirect X11 data to (by default port = display + 6000); raw display number for unix domain connection", "default": 6000 }, "x11host": { "type": "string", - "description": "Hostname/ip to redirect X11 data to", + "description": "Hostname/ip to redirect X11 data to; empty string for a unix domain connection", "default": "localhost" }, "remotex11screen": { @@ -755,7 +755,7 @@ }, "x11host": { "type": "string", - "description": "Hostname/ip to redirect X11 data to", + "description": "Hostname/ip to redirect X11 data to; empty string for a unix domain connection", "default": "localhost" }, "x11port": { @@ -763,7 +763,7 @@ "number", "string" ], - "description": "Port to redirect X11 data to (by default port = display + 6000)", + "description": "TCP port to redirect X11 data to (by default port = display + 6000); raw display number for unix domain connection", "default": 6000 }, "remotex11screen": { diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 5b91e59..9a32193 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -155,7 +155,10 @@ export class MI2 extends EventEmitter implements IBackend { const xclientsock = accept(); xclientsock.pipe(xserversock).pipe(xclientsock); }); - xserversock.connect(args.x11port, args.x11host); + if (args.x11host !== "") + xserversock.connect(args.x11port, args.x11host); + else + xserversock.connect(`/tmp/.X11-unix/X${args.x11port}`); }); }