Skip to content

Instantly share code, notes, and snippets.

@Gitsack
Last active January 4, 2021 17:09
Show Gist options
  • Save Gitsack/6c8ce86f2821ea8093ca6e6c9ee52eee to your computer and use it in GitHub Desktop.
Save Gitsack/6c8ce86f2821ea8093ca6e6c9ee52eee to your computer and use it in GitHub Desktop.
Start Linux GUI apps from WSL2 to X410
# If there isn't a running process that contains "x410"...
if (!((Get-Process | select ProcessName).ProcessName | where {$_ -like "*x410*"}))
{
# Find the executable and run it.
&(where.exe /R "C:\Program Files\WindowsApps\ChoungNetworksUS.X410_2.8.2.0_x64__vvzc8y2tzcnsr\X410" "x410.exe /wm")
}
# Get actual screen width
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$width = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
if ($width -eq 2560) {
# Regular dpi settings
wsl.exe /home/martin/winstart/gitkraken
} else {
# Hidpi settings
wsl.exe /home/martin/winstart/gitkraken -d
}
HIDPI=0
while [ $# -gt 0 ] ; do
case $1 in
-d | --hidpi) HIDPI=1 ;;
esac
shift
done
echo "$HIDPI"
if [ "$HIDPI" = 1 ] ; then
echo "Hidpi settings are used."
export QT_SCALE_FACTOR=2
export GDK_SCALE=2
fi
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
gitkraken
' Run Powershell script without showing console window
Dim shell,command
' Alter command for different file or command
command = "powershell.exe -nologo -file ""C:\wsl\gitkraken.ps1"""
Set shell = CreateObject("WScript.Shell")
shell.Run command,0
Using this technique, linux apps (WSL2) can be piped to X410 Windows X-Server.
Windows:
- VBS script to execute/run a powershell without viewing a shell window.
- PS1 script to
1) start X410 server if not already running
2) get screen width of monitor
3) execute linux script with optional possibility to pass parameter for hidpi settings
Linux:
- Optionally set HIDPI options
- Set DISPLAY env variable
- Launch program
Prerequisites:
X410: https://x410.dev/
WSL2
Caveats:
Screen width is not calculated correctly on hidpi resolutions/scales, e.g. 3840 results in 1920 with a dpi scaling of 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment