Skip to content

Consistent GLFW backend detection on hybrid Wayland/X11 systems#210

Merged
almarklein merged 7 commits into
pygfx:mainfrom
mortacious:glfw_wayland_fix
Jun 24, 2026
Merged

Consistent GLFW backend detection on hybrid Wayland/X11 systems#210
almarklein merged 7 commits into
pygfx:mainfrom
mortacious:glfw_wayland_fix

Conversation

@mortacious

Copy link
Copy Markdown
Contributor

On linux systems where the glfw library supports both X11 and Wayland (e.g. the universal libglfw3 package), get_x11_window and get_x11_display are present as attributes even when glfw is actually running on the Wayland backend. The old detection logic relied solely on hasattr(glfw, "get_x11_window"), which incorrectly selected the X11 path and caused a TypeError: ... crash because get_x11_display() returned None.

This replaces the attribute check with a runtime probe of the actual display handles: get_wayland_display() is called first; get_x11_display() is only called when Wayland returns None. Both calls are wrapped in warnings.catch_warnings(ignore, GLFWError) to suppress "X11: Platform not initialized" / "Wayland: Platform not initialized" warnings from glfw.

@almarklein almarklein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Great PR.

I think it makes sense to drop the api_is_wayland flag, and move the logic at the top of the module inside the get_glfw_present_info() function. So we have one clear point where the triage happens. What do you think?

@mortacious

Copy link
Copy Markdown
Contributor Author

Thanks! Great PR.

I think it makes sense to drop the api_is_wayland flag, and move the logic at the top of the module inside the get_glfw_present_info() function. So we have one clear point where the triage happens. What do you think?

Yes, the import-time checks are actually quite useless now, since they are executed again at runtime anyway.

@almarklein almarklein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome, thanks!

Comment thread rendercanvas/glfw.py Outdated
…tection to fall back to x11 (xwayland) in case wayland is not available
Comment thread rendercanvas/glfw.py
@almarklein

Copy link
Copy Markdown
Member

I'll do some tests when I have access to my Linux box soon.

Comment thread rendercanvas/core/coreutils.py
@almarklein almarklein merged commit e0f67af into pygfx:main Jun 24, 2026
21 checks passed
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.

2 participants