Skip to content

feat(embedded): support GTK OpenGL hosts - #196

Open
bvolpato wants to merge 3 commits into
manaflow-ai:mainfrom
bvolpato:bvolpato/limux-embedded-2026-08
Open

feat(embedded): support GTK OpenGL hosts#196
bvolpato wants to merge 3 commits into
manaflow-ai:mainfrom
bvolpato:bvolpato/limux-embedded-2026-08

Conversation

@bvolpato

@bvolpato bvolpato commented Aug 10, 2026

Copy link
Copy Markdown

Summary

  • add a Linux embedded platform for main-thread GTK GLArea rendering
  • expose display unrealize/realize hooks so hosts can rebuild OpenGL resources after widget reparenting
  • preserve callback-backed OpenGL sizing and swap behavior
  • make font query APIs compile and report names with FreeType as well as CoreText

This ports the minimal GTK embedding support originally implemented by FreeMeWat onto current manaflow-ai/ghostty without carrying the older fork. The commit retains original authorship credit through Co-authored-by.

Why

GTK GLArea owns a main-thread framebuffer. Generic callback-backed OpenGL may render on Ghostty’s renderer thread, so it cannot safely replace this path. Linux also exposed a pre-existing build failure in the font query API because it directly accessed CoreText-only fields.

Validation

  • zig build -Dapp-runtime=none -Doptimize=ReleaseFast -Dcpu=baseline
  • zig build test -Dapp-runtime=none -Dtest-filter="OpenGL presentation preserves"
  • zig build test -Dapp-runtime=none -Dtest-filter="face name"
  • C header translation through focused test builds

Full unfiltered Ghostty test process was killed with exit 137 on a memory-pressured workstation. Focused changed-path tests pass; downstream Limux full Rust and live GTK smoke gates run separately.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Add Linux GTK GLArea embedding for OpenGL with per-surface app-thread rendering and explicit display realize/unrealize hooks. Font queries are now portable across CoreText and FreeType, preserving file paths for file-backed faces on Linux.

  • New Features

    • Added GHOSTTY_PLATFORM_LINUX and linux_platform in ghostty.h, plus ghostty_surface_display_unrealized and ghostty_surface_display_realized.
    • Linux GLArea draws on the app thread, uses the current FBO/viewport for size, and lets GTK swap after the render callback; callback-backed OpenGL retains enter/leave and swap_buffers.
  • Bug Fixes

    • Choose app-thread drawing per surface so GTK GLArea uses its owning thread while callback-backed OpenGL stays on the renderer thread.
    • FreeType now returns a PostScript name and exposes urlPath for file-backed faces; the path is preserved across synthetic bold/italic. Memory-backed faces still have no URL.

Written for commit 1a89efa. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added Linux as a supported embedded platform.
    • Added support for notifying surfaces when the host OpenGL display is created or destroyed.
    • Improved embedded OpenGL handling for Linux-based environments.
    • Added font metadata access for PostScript names and source paths where available.

Restore app-thread rendering and display lifecycle hooks for GTK GLArea embedders while preserving callback-backed OpenGL behavior. Make font query API portable across CoreText and FreeType.

Co-authored-by: FreeMeWat <freeme62410@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds Linux to the embedded platform ABI. It adds Linux-specific drawing and OpenGL context lifecycle handling. It also adds cross-backend font PostScript name and source path accessors.

Changes

Linux embedded support

Layer / File(s) Summary
Linux platform contract
include/ghostty.h, src/apprt/embedded.zig
Adds the Linux platform enum, payload, union member, platform tag, initialization path, and application-thread drawing flag.
Font metadata access
src/font/face/coretext.zig, src/font/face/freetype.zig, src/apprt/embedded.zig
Adds Face.postscriptName and Face.urlPath for CoreText and FreeType. Embedded font reporting uses these accessors.
Embedded context lifecycle
include/ghostty.h, src/apprt/embedded.zig, src/renderer/OpenGL.zig
Adds display lifecycle callbacks. Linux skips explicit context switching, uses the current GTK context, queries the current viewport, and leaves presentation to GTK.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: mitchellh, lawrencecchen

Sequence Diagram(s)

sequenceDiagram
  participant HostApplication
  participant SurfaceLifecycle
  participant OpenGL
  participant SurfaceDraw
  HostApplication->>SurfaceLifecycle: call ghostty_surface_display_unrealized
  SurfaceLifecycle->>OpenGL: release renderer resources
  HostApplication->>OpenGL: make GTK context current
  HostApplication->>SurfaceLifecycle: call ghostty_surface_display_realized
  SurfaceLifecycle->>OpenGL: prepare current embedded context
  HostApplication->>SurfaceDraw: draw surface
  SurfaceDraw->>OpenGL: drawFrame(false)
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding embedded GTK OpenGL host support.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec9b2a0afe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/apprt/embedded.zig Outdated
Comment thread src/font/face/freetype.zig

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/font/face/freetype.zig`:
- Around line 193-199: Update the FreeType Face path handling so
initFile-created faces retain their owned source path and urlPath returns it,
while memory-backed faces continue returning null. Ensure synthetic face copies
propagate the stored path and preserve correct buffer handling in urlPath.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d3db61cf-18bf-4453-ab72-a95c90ef1691

📥 Commits

Reviewing files that changed from the base of the PR and between f76c132 and ec9b2a0.

📒 Files selected for processing (5)
  • include/ghostty.h
  • src/apprt/embedded.zig
  • src/font/face/coretext.zig
  • src/font/face/freetype.zig
  • src/renderer/OpenGL.zig

Comment thread src/font/face/freetype.zig Outdated
Choose app-thread drawing per surface so GTK GLArea uses its owning thread while callback-backed OpenGL keeps its renderer-thread context.
Retain file-backed face paths across synthetic copies so Linux font queries report discovered fonts accurately. Keep memory-backed faces pathless.
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.

1 participant