Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fallback to x11 gdk backend on error #13

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Conversation

psadi
Copy link
Owner

@psadi psadi commented Jan 15, 2025

workaround, fixes #12

build.sh Outdated
exec_command='exec "${HERE}"/ld-linux-x86-64.so.2 --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"'

# Attempt to run normally or fallback GDK_BACKEND to x11
if ! eval "$exec_command"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this method is that the application will be relaunched for any error and not just the wayland error.

So this should only happen if we check that we are on a wayland session at least, iirc there is an env variable you can check to determine that.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❯ echo $WAYLAND_DISPLAY
wayland-0

should this be suffice, for x11 this should return null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think you need to use eval and just check if $? is greater than 0.

@Samueru-sama
Copy link
Contributor

I would do something like this instead:

#!/usr/bin/env sh

HERE="$(dirname "$(readlink -f "$0")")"

export TERM=xterm-256color
export GHOSTTY_RESOURCES_DIR="${HERE}/usr/share/ghostty"

exec "${HERE}"/ld-linux-x86-64.so.2 --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"

if [ "$?" -gt 0 ] && [ -n "$WAYLAND_DISPLAY" ]; then
	export GDK_BACKEND=x11
	exec "${HERE}"/ld-linux-x86-64.so.2 --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"
fi

@psadi psadi force-pushed the feature/x11_fallback branch from 3914f8c to 9c0ac7d Compare January 15, 2025 08:45
@psadi
Copy link
Owner Author

psadi commented Jan 15, 2025

exec "${HERE}"/ld-linux-x86-64.so.2 --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"

if [ "$?" -gt 0 ] && [ -n "$WAYLAND_DISPLAY" ]; then
export GDK_BACKEND=x11
exec "${HERE}"/ld-linux-x86-64.so.2 --library-path "${HERE}"/usr/lib "${HERE}"/usr/bin/ghostty "$@"
fi

Agree with this approach, check my latest -- thought of avoiding the same command twice and reference it from an array for readability.

build.sh Outdated
command=("${HERE}/ld-linux-x86-64.so.2" --library-path "${HERE}/usr/lib" "${HERE}/usr/bin/ghostty" "$@")

# Check if WAYLAND_DISPLAY is set, attempt normally or fallback GDK_BACKEND to x11
if [ -z "$WAYLAND_DISPLAY" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be -n "$WAYLAND_DISPLAY"?

also I don't think "${command[@]}" is posix, remember we are using sh and not bash

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% -- wasn't thinking of POSIX standards. Amended the suggestions :)

@psadi psadi force-pushed the feature/x11_fallback branch from 9c0ac7d to 894a650 Compare January 15, 2025 08:51
@Samueru-sama
Copy link
Contributor

Btw the original person that made the issue said this:

after the error a blank window opens up for a second or 2 then it quickly closes

So none of this is ideal, because on wayland people will see the window open for 2 seconds, then close and finally open again. every time they launch the appimage

we would need to create a file to indicate that wayland failed and check at runtime and all of that xd.

I think it is better to just always set GDK_BACKEND=x11 for now.

@psadi
Copy link
Owner Author

psadi commented Jan 15, 2025

I think it is better to just always set GDK_BACKEND=x11 for now.

Good merge and release ?

@psadi psadi merged commit bbdf46e into main Jan 15, 2025
3 checks passed
@psadi psadi deleted the feature/x11_fallback branch January 15, 2025 09:02
@Samueru-sama
Copy link
Contributor

I think it is better to just always set GDK_BACKEND=x11 for now.

Good merge and release ?

I don't think so.

The problem with this solution is that the app doesn't crash instantly, it instead opens a window for a second and then closes.

So the user that had this problem is going to see the window open for a second, close and then finally open again, instead just opening right the first time.

@psadi
Copy link
Owner Author

psadi commented Jan 15, 2025

merged with the fallback solution at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

appimage crashes when launching on Manjaro
2 participants