Skip to content

Instantly share code, notes, and snippets.

@CTXz
Last active April 5, 2023 10:16
Show Gist options
  • Save CTXz/788ba095eaa24de933f68aeeab91db4c to your computer and use it in GitHub Desktop.
Save CTXz/788ba095eaa24de933f68aeeab91db4c to your computer and use it in GitHub Desktop.
Patches the libQtGui.so.4 library to ignore system themes and thus fixes akward theme issues with the Gowin FPGA IDE on Linux.
#!/usr/bin/env bash
#
# Copyright (C) 2023 Patrick Pedersen
#
# 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/>.
#
# Usage:
# bash gowin-ide-fix-theme.sh <path to Gowin IDE installation>
# Example:
# bash gowin-ide-fix-theme.sh ~/Gowin_V1.9.8.09_Education_linux/
# Dependencies:
# curl
# bspatch
# This script modifies the libQtGui.so.4 library to allow the use of an application-specific theme configuration
# located in the directory of the executable called `gowin_qt4.conf`, instead of the user theme provided by
# `~/.config/Trolltech.conf`. This resolves awkward theme issues with the Gowin FPGA IDE on Linux.
# The script has been successfully tested on "Gowin V1.9.8.09 Education Edition" on Ubuntu 22.04 and 20.04.
# The patch works by replacing the `Trolltech` string in [this line](https://github.com/openwebos/qt/blob/master/src/gui/kernel/qapplication_x11.cpp#L864)
# with `gowin_qt4`, thus forcing it to look for `gowin_qt4.conf` instead. This configuration file may then be
# provided in the local directory of the `gwe_ide` executable, or in the `~/.config/` folder.
# Since this patch only affects the local libQtGui.so.4 library, it does not affect any other Qt-4 applications.
# Before patching, the script makes a backup of the original libQtGui.so.4 file in the lib/ directory of the Gowin IDE installation.
GOWIN_PATH=$(readlink -m $1)
GOWIN_IDE_BIN=$GOWIN_PATH/IDE/bin
GOWIN_IDE_LIBS=$GOWIN_PATH/IDE/lib
LIB_MD5_MATCH="290d04c582a04ac045561b24544d2e25 libQtGui.so.4"
PATCH_GIST="https://gist.githubusercontent.com/CTXz/23042d54f8899a5271a0761aba3d898f/raw/4dc33b666cb94e5767695a5d48a35ea5caea08ce/gowin-ide-libQtGui-custom-conf.patch.hex"
QT_CONF_GIST="https://gist.githubusercontent.com/CTXz/210cc65cd33992f2c38c35df4ad5c781/raw/b50294be909ba57e5f8305de873edc95a98f7669/gowin_qt4.conf"
if [ -z "$GOWIN_PATH" ]; then
echo "Usage: bash gowin-ide-fix-theme.sh <path to Gowin IDE installation>"
exit 1
fi
if [ ! -d "$GOWIN_PATH" ]; then
echo "Error: $GOWIN_PATH is not a directory"
exit 1
fi
which bspatch > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: bspatch not found. Please install bspatch."
exit 1
fi
curl --help > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: curl not found. Please install curl."
exit 1
fi
cd $GOWIN_IDE_LIBS
echo "$LIB_MD5_MATCH" | md5sum -c --status
if [ $? -eq 0 ]; then
echo "libQtGui.so.4 already patched! Skipping..."
else
cd $GOWIN_IDE_LIBS
curl "$PATCH_GIST" | xxd -r > gowin-ide-libQtGui-custom-conf.patch
if [ $? -ne 0 ]; then
echo "Error: Failed to download patch file."
exit 1
fi
mv libQtGui.so.4 libQtGui.so.4.bak && bspatch libQtGui.so.4.bak libQtGui.so.4 gowin-ide-libQtGui-custom-conf.patch
if [ $? -ne 0 ]; then
echo "Error: Failed to patch libQtGui.so.4"
exit 1
fi
echo
echo "Patch applied! A backup of the original libQtGui.so.4 file can be found at $GOWIN_IDE_LIBS/libQtGui.so.4.bak"
echo
echo "If you want to revert the patch, simply run the following command:"
echo -e "\tmv $GOWIN_IDE_LIBS/libQtGui.so.4.bak $GOWIN_IDE_LIBS/libQtGui.so.4"
echo
fi
echo "Downloading recommended gowin_qt4.conf configuration to $GOWIN_IDE_BIN/gowin_qt4.conf"
if [ -f "$GOWIN_IDE_BIN/gowin_qt4.conf" ]; then
echo "Configuration already exists in $GOWIN_IDE_BIN. Skipping..."
else
curl "$QT_CONF_GIST" > $GOWIN_IDE_BIN/gowin_qt4.conf
if [ $? -ne 0 ]; then
echo "Error: Failed to download gowin_qt4.conf configuration file."
exit 1
fi
fi
echo "Done!"
@madushan1000
Copy link

Thanks for this script! the ide is super annoying with the drak theme.

@CTXz
Copy link
Author

CTXz commented Apr 5, 2023

Thanks for this script! the ide is super annoying with the drak theme.

Thank you! Glad to hear I'm not the only one annoyed by this issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment