Skip to content

core/gtk: open urls using an apprt action instead of doing it directly - #5988

Merged
mitchellh merged 3 commits into
ghostty-org:mainfrom
jcollie:apprt-action-open-url
Jul 6, 2025
Merged

mitchellh merged 3 commits into
ghostty-org:mainfrom
jcollie:apprt-action-open-url

Conversation

@jcollie

@jcollie jcollie commented Feb 25, 2025 •

Copy link
Copy Markdown
Member

Partial implementation of #5256

This implements the core changes necessary to open urls using an apprt action rather than doing it directly from the core.

Implements the open_url action in the GTK apprt.

Note that this should not be merged until a macOS-savvy developer can add an implementation of the open_url action for the macOS apprt.

@jcollie
jcollie requested review from a team as code owners February 25, 2025 18:19
@tristan957

Copy link
Copy Markdown
Member

Did you see https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html? Seems like we should use that and then fallback to xdg-open.

@mitchellh mitchellh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for starting this, I can take a look for libghostty.

Comment thread src/os/open.zig Outdated
Comment thread src/apprt/action.zig Outdated
@jcollie
jcollie force-pushed the apprt-action-open-url branch from 20f4b88 to 4dde6f4 Compare February 25, 2025 19:13
@jcollie

jcollie commented Feb 25, 2025

Copy link
Copy Markdown
Member Author

Did you see https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html? Seems like we should use that and then fallback to xdg-open.

That looks interesting but I'd rather take that on in a follow-up PR after this is merged.

@jcollie
jcollie force-pushed the apprt-action-open-url branch 2 times, most recently from d339ac3 to 0a69243 Compare March 10, 2025 12:05
@jcollie
jcollie force-pushed the apprt-action-open-url branch from 0a69243 to 70af7a1 Compare March 18, 2025 23:40
@jcollie
jcollie force-pushed the apprt-action-open-url branch 2 times, most recently from 7e852df to aa8e7f2 Compare April 10, 2025 21:23
@jcollie
jcollie force-pushed the apprt-action-open-url branch 2 times, most recently from 1568fd7 to 7fafa50 Compare May 8, 2025 19:23
Comment thread src/apprt/action.zig Outdated
@jcollie
jcollie force-pushed the apprt-action-open-url branch 4 times, most recently from daa12b3 to 7a0028a Compare May 19, 2025 13:04
@jcollie
jcollie force-pushed the apprt-action-open-url branch from 7a0028a to 83d5127 Compare May 29, 2025 16:40
Comment thread src/apprt/action.zig Outdated
Comment thread src/os/open.zig Outdated
Comment thread src/os/open.zig Outdated

@tristan957 tristan957 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.

Would open_uri be a better name than open_url?

Comment thread src/os/open.zig Outdated
Comment thread src/apprt/action.zig Outdated
@tristan957

Copy link
Copy Markdown
Member

Would open_uri be a better name than open_url?

Is this something you've considered? Maybe I'm blind.

@tristan957

tristan957 commented Jun 24, 2025 •

Copy link
Copy Markdown
Member

Did you see https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html? Seems like we should use that and then fallback to xdg-open.

TIL that xdg-open uses the portal already, so I wonder if there is any benefit to using the portal directly vs just calling xdg-open. Maybe lower overhead?

@jcollie

jcollie commented Jun 24, 2025

Copy link
Copy Markdown
Member Author

TIL that xdg-open uses the portal already, so I wonder if there is any benefit to using the portal directly vs just calling xdg-open. Maybe lower overhead?

Yeah, you could avoid the thread spawn and fork/exec in Ghostty, but that's pretty minimal since I doubt that it's going to be called thousands of times per second. The benefit of calling xdg-open is making the logic of making the magic of that happen "not our problem".

@jcollie

jcollie commented Jun 24, 2025

Copy link
Copy Markdown
Member Author

I've updated the PR to rebase on top of #7657 so there's no special "open on linux" function anymore. This still needs a macOS implementation of the open_url action before merging.

@pluiedev

Copy link
Copy Markdown
Member

Actually, I just realized that xdg-open isn't just a wrapper around the D-Bus API — instead it's a bash script that uses a bunch of heuristics to figure out what the user's desktop environment is, and then uses the DE-specific utilities when possible (gio open on GNOME, kde-open on KDE, etc.). In fact, it seems to only use the portal when it's running inside Flatpak. I guess then it would still be worth keeping it in case the user doesn't have a working portal (which seems to be concerningly common for a lot of our users)...?

@tristan957

Copy link
Copy Markdown
Member

Actually, I just realized that xdg-open isn't just a wrapper around the D-Bus API — instead it's a bash script that uses a bunch of heuristics to figure out what the user's desktop environment is, and then uses the DE-specific utilities when possible (gio open on GNOME, kde-open on KDE, etc.). In fact, it seems to only use the portal when it's running inside Flatpak. I guess then it would still be worth keeping it in case the user doesn't have a working portal (which seems to be concerningly common for a lot of our users)...?

So then, I think my position will continue to be prioritize the portal with an xdg-open fallback (future work). Thanks for your research.

@tristan957

Copy link
Copy Markdown
Member

Hm, I guess I have a question. Why does libghostty do the physical opening. Why isn't it left to the apprt? Meaning the macOS apprt would run open for instance.

@jcollie

jcollie commented Jun 24, 2025

Copy link
Copy Markdown
Member Author

Hm, I guess I have a question. Why does libghostty do the physical opening. Why isn't it left to the apprt? Meaning the macOS apprt would run open for instance.

The open function is in libghostty because there's a lot of functionality shared across all the apprts (it's also used by the "open config". If an apprt wanted to do something other than launch a CLI command (some sort of DBus call for GTK, native Swift API call for macOS, some Win32 call for Windows) that can be handled in the open_url apprt handler (GTK: https://github.com/ghostty-org/ghostty/blob/00f824d0efb441bbfe2057e7caeadfcec2ea1d48/src/apprt/gtk/App.zig#L1722-L1730)

@jcollie
jcollie force-pushed the apprt-action-open-url branch 2 times, most recently from c6821f6 to ad845dc Compare July 6, 2025 06:09
@jcollie jcollie changed the title core/gtk/glfw: open urls using an apprt action instead of doing it directly core/gtk: open urls using an apprt action instead of doing it directly Jul 6, 2025
jcollie added 2 commits July 6, 2025 15:02
Partial implementation of ghostty-org#5256

This implements the core changes necessary to open urls using an apprt
action rather than doing it directly from the core.

Implements the open_url action in the GTK and GLFW apprts.

Note that this should not be merged until a macOS-savvy developer can add
an implementation of the open_url action for the macOS apprt.
@mitchellh
mitchellh force-pushed the apprt-action-open-url branch from ad845dc to 70a2a0a Compare July 6, 2025 22:02
Comment thread src/os/open.zig Outdated

const log = std.log.scoped(.@"os-open");
const apprt = @import("../apprt.zig");
const CircBuf = @import("../datastruct/circ_buf.zig").CircBuf;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On a future note, your PRs have a pattern of containing unrelated changes such as this. I'm going to revert all the circular buffer stuff. It makes sense but conflating the purpose and goal of a PR makes review harder and makes things like reverting uglier if we ever to. I'd appreciate keeping things tightly scoped.

@mitchellh

Copy link
Copy Markdown
Contributor

Okay, I made it so that if the apprt doesn't support this we fallback to our old implementation. This will let us merge this without worrying about macOS. I'll make a follow up issue for that. Once CI passes we're good.

@mitchellh
mitchellh merged commit 78e861b into ghostty-org:main Jul 6, 2025
@jcollie
jcollie deleted the apprt-action-open-url branch July 6, 2025 22:20
@github-actions github-actions Bot added this to the 1.2.0 milestone Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants