Adapt to software render without using wrapper scripts.

This commit is contained in:
cyteen 2026-03-11 01:38:12 +00:00
parent 3ac25e39bd
commit ccb8933f77
2 changed files with 148 additions and 4 deletions

View File

@ -2,6 +2,8 @@
DEST=${1:-/etc/skel}
GHOSTTY_HOME=${DEST}/.config/ghostty
ALIASES_D="${DEST}/.zsh_aliases.d"
ALIAS_FILE="${ALIASES_D}/003_ghostty.zsh"
sudo apt update
sudo apt install ghostty
@ -77,4 +79,115 @@ EOF
}
conf_print_ghostty_config | tee "${GHOSTTY_HOME}/config.yaml"
# OpenGL detection → decide if we force software rendering
# Necessary is opengl is <=3.2
should_use_software() {
local es_version=""
# local gl_version=""
# if command -v glxinfo >/dev/null 2>&1; then
# gl_version=$(glxinfo | grep -i "OpenGL version string" | head -n 1 | awk -F: '{print $2}')
# if [[ "$gl_version" =~ ^([4-9]\.|3\.[3-9]) ]]; then
# return 1 # hardware ok
# fi
# fi
local max_core
max_core=$(glxinfo -B 2>/dev/null | grep "Max core profile" | awk '{print $5}')
printf "max_core: %s\n" "${max_core}"
if [[ "$max_core" =~ ^([4-9]\.|3\.[3-9]) ]]; then
return 1 # Hardware supports OpenGL 3.2+
fi
if command -v eglinfo >/dev/null 2>&1; then
es_version=$(eglinfo -B 2>/dev/null | grep -i "OpenGL ES profile version" | head -n 1 | grep -oE '[0-9]+\.[0-9]+' || true)
printf "es_version %s\n" "${es_version}"
if [[ "$es_version" =~ ^[3-9]\. ]]; then
return 1 # GLES 3+ usually good enough
fi
fi
return 0 # force software
}
conf_print_ghostty_desktop() {
cat <<EOF
[Desktop Entry]
Version=1.0
Name=Ghostty
Type=Application
Comment=A terminal emulator
TryExec=/usr/bin/ghostty
Exec=env LIBGL_ALWAYS_SOFTWARE=1 /usr/bin/ghostty --gtk-single-instance=true
Icon=com.mitchellh.ghostty
Categories=System;TerminalEmulator;
Keywords=terminal;tty;pty;
StartupNotify=true
StartupWMClass=com.mitchellh.ghostty
Terminal=false
Actions=new-window;
X-GNOME-UsesNotifications=true
X-TerminalArgExec=-e
X-TerminalArgTitle=--title=
X-TerminalArgAppId=--class=
X-TerminalArgDir=--working-directory=
X-TerminalArgHold=--wait-after-command
DBusActivatable=true
X-KDE-Shortcuts=Ctrl+Alt+T
[Desktop Action new-window]
Name=New Window
Exec=env LIBGL_ALWAYS_SOFTWARE=1 /usr/bin/ghostty --gtk-single-instance=true
[Desktop Action preferences]
Name=Preferences
Exec=env LIBGL_ALWAYS_SOFTWARE=1 /usr/bin/ghostty +edit-config --gtk-single-instance=true --preferences
EOF
}
conf_print_ghostty_alias_hw() {
cat <<'EOF' | tee "${ALIAS_FILE}" >/dev/null
# kitty → hardware rendering (OpenGL ≥3.3 detected)
alias ghostty="ghostty"
EOF
}
conf_print_ghostty_alias_sw() {
cat <<'EOF' | tee "${ALIAS_FILE}" >/dev/null
# ghostty → software rendering (old/weak OpenGL)
alias ghostty="LIBGL_ALWAYS_SOFTWARE=1 ghostty"
EOF
}
# We now use the adapted desktop file
conf_print_ghostty_wrapper() {
mkdir -p /usr/local/bin/
cat >/usr/local/bin/ghostty-wrapper <<'EOF'
#!/bin/sh
export LIBGL_ALWAYS_SOFTWARE=1
exec /usr/bin/ghostty "$@"
EOF
}
# conf_print_ghostty_wrapper
# sudo chmod +x "/usr/local/bin/ghostty-wrapper"
if should_use_software; then
conf_print_ghostty_alias_sw
echo "# Forced software rendering due to insufficient OpenGL support" | tee -a "${ALIAS_FILE}" >/dev/null
# For xfce4 that ignores user aliases
conf_print_ghostty_desktop | tee "${DEST}/.local/share/applications/com.mitchellh.ghostty.desktop" >/dev/null
update-desktop-database "${DEST}/.local/share/applications"
# Add to alternatives and select default
#sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/local/bin/ghostty-wrapper 60
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/ghostty 60
sudo update-alternatives --config x-terminal-emulator
else
conf_print_ghostty_alias_hw
echo "# Using hardware rendering" | tee -a "${ALIAS_FILE}" >/dev/null
sudo update-alternatives --config x-terminal-emulator
fi
ghostty +validate-config

View File

@ -59,6 +59,35 @@ should_use_software() {
return 0 # force software
}
conf_print_kitty_desktop() {
cat <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=kitty
GenericName=Terminal emulator
Comment=Fast, feature-rich, GPU based terminal
TryExec=env LIBGL_ALWAYS_SOFTWARE=1 kitty
StartupNotify=true
Exec=kitty
Icon=kitty
Categories=System;TerminalEmulator;
X-TerminalArgExec=--
X-TerminalArgTitle=--title
X-TerminalArgAppId=--class
X-TerminalArgDir=--working-directory
X-TerminalArgHold=--hold
[Desktop Action new-window]
Name=New Window
Exec=env LIBGL_ALWAYS_SOFTWARE=1 kitty
[Desktop Action preferences]
Name=Preferences
Exec=env LIBGL_ALWAYS_SOFTWARE=1 kitty --single-instance @ edit_config_file
EOF
}
conf_print_kitty_alias_hw() {
cat <<'EOF' | tee "${ALIAS_FILE}" >/dev/null
# kitty → hardware rendering (OpenGL ≥3.3 detected)
@ -81,18 +110,20 @@ export LIBGL_ALWAYS_SOFTWARE=1
exec /usr/bin/kitty "$@"
EOF
}
# ssudo conf_print_kitty_wrapper
# sudo chmod +x "/usr/local/bin/kitty-wrapper"
if should_use_software; then
conf_print_kitty_alias_sw
echo "# Forced software rendering due to insufficient OpenGL support" | tee -a "${ALIAS_FILE}" >/dev/null
# For xfce4 that ignores user aliases
ssudo conf_print_kitty_wrapper
sudo chmod +x "/usr/local/bin/kitty-wrapper"
conf_print_kitty_desktop | tee "${DEST}/.local/share/applications/kitty.desktop" >/dev/null
update-desktop-database ~/.local/share/applications
# Add to alternatives and select default
# sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/kitty 100
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/local/bin/kitty-wrapper 60
# sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/local/bin/kitty-wrapper 60
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/kitty 100
sudo update-alternatives --config x-terminal-emulator
else