summaryrefslogtreecommitdiff
path: root/src/apprt/embedded.zig
AgeCommit message (Collapse)Author
2025-10-03Zig 0.15: zig build test macOSMitchell Hashimoto
2025-09-05apprt/gtk-ng: clean up our single instance, new window interactionsMitchell Hashimoto
This removes `launched-from` entirely and moves our `gtk-single-instance` detection logic to assume true unless we detect CLI instead of assume false unless we detect desktop/dbus/systemd. The "assume true" scenario for single instance is desirable because detecting a CLI instance is much more reliable. Removing `launched-from` fixes an issue where we had a difficult-to-understand relationship between `launched-from`, `gtk-single-instance`, and `initial-window`. Now, only `gtk-single-instance` has some hueristic logic. And `initial-window` ALWAYS sends a GTK activation signal regardless of single instance or not. As a result, we need to be explicit in our systemd, dbus, desktop files about what we want Ghostty to do, but everything works as you'd mostly expect. Now, if you put plain old `ghostty` in your terminal, you get a new Ghostty instance. If you put it anywhere else, you get a GTK single instance activation call (either creates a first instance or opens a new window in the existing instance). Works for launchers and so on.
2025-09-05gtk-ng: deprecate detection of launch sourceJeffrey C. Ollie
Detecting the launch source frequently failed because various launchers fail to sanitize the environment variables that Ghostty used to detect the launch source. For example, if your desktop environment was launched by `systemd`, but your desktop environment did not sanitize the `INVOCATION_ID` or the `JOURNAL_STREAM` environment variables, Ghostty would assume that it had been launched by `systemd` and behave as such. This led to complaints about Ghostty not creating new windows when users expected that it would. To remedy this, Ghostty no longer does any detection of the launch source. If your launch source is something other than the CLI, it must be explicitly speciflied on the CLI. All of Ghostty's default desktop and service files do this. Users or packagers that create custom desktop or service files will need to take this into account. On GTK, the `desktop` setting for `gtk-single-instance` is replaced with `detect`. `detect` behaves as `gtk-single-instance=true` if one of the following conditions is true: 1. If no CLI arguments have been set. 2. If `--launched-from` has been set to `desktop`, `dbus`, or `systemd`. Otherwise `detect` behaves as `gtk-single-instance=false`.
2025-09-02macOS: firstRect should return full rect width/heightMitchell Hashimoto
Fixes #2473 This commit changes `ghostty_surface_ime_point` to return a full rect with the width/height calculated for the preedit. The `firstRect` function, which calls `ghostty_surface_ime_point` was previously setting the width/height to zero. macOS didn't like this. We then changed it to just hardcode it to width/height of one cell. This worked but made it so the IME cursor didn't follow the preedit.
2025-08-28some typosMitchell Hashimoto
2025-08-28macos: when executing a script directly, always wait after commandMitchell Hashimoto
2025-07-19core: remove Surface.shouldCloseMitchell Hashimoto
This was a noop in all of our apprts and I think is a holdover from the glfw days.
2025-07-19Fully remove the redrawSurface APIMitchell Hashimoto
This is a tiny addon from the recent gtk-ng work. We've moved redraw requests into the apprt action system (the `render` action). I waited until I had my macOS machine to verify that this fix could work. We can now remove this completely. We can probably remove the redraw inspector API too at some point but I'm not there yet with the GTK backend so I'll just wait on it.
2025-07-18apprt/gtk-ng: hook up surface initializationMitchell Hashimoto
2025-07-14cli/gtk: move IPC/sendIPC to App/performIpcJeffrey C. Ollie
2025-07-14cli/gtk: replace @hasDecl for performAction-style APIJeffrey C. Ollie
Instead of using @hasDecl, use a performAction-stype API. The C interface for interfacing with macOS (or any other apprt where Ghostty is embedded) is unfinished.
2025-07-14cli/gtk: move actual IPC code tp apprtJeffrey C. Ollie
2025-07-05macos: support configuration via CLI argumentsMitchell Hashimoto
This makes it so `zig build run` can take arguments such as `--config-default-files=false` or any other configuration. Previously, it only accepted commands such as `+version`. Incidentally, this also makes it so that the app in general can now take configuration arguments via the CLI if it is launched as a new instance via `open`. For example: open -n Ghostty.app --args --config-default-files=false This previously didn't work. This is kind of cool. To make this work, the libghostty C API was modified so that initialization requires the CLI args, and there is a new C API to try to execute an action if it was set.
2025-07-04Nuke GLFW from OrbitMitchell Hashimoto
This deletes the GLFW apprt from the Ghostty codebase. The GLFW apprt was the original apprt used by Ghostty (well, before Ghostty even had the concept of an "apprt" -- it was all just a single application then). It let me iterate on the core terminal features, rendering, etc. without bothering about the UI. It was a good way to get started. But it has long since outlived its usefulness. We've had a stable GTK apprt for Linux (and Windows via WSL) and a native macOS app via libghostty for awhile now. The GLFW apprt only remained within the tree for a few reasons: 1. Primarily, it provided a faster feedback loop on macOS because building the macOS app historically required us to hop out of the zig build system and into Xcode, which is slow and cumbersome. 2. It was a convenient way to narrow whether a bug was in the core Ghostty codebase or in the apprt itself. If a bug was in both the glfw and macOS app then it was likely in the core. 3. It provided us a way on macOS to test OpenGL. All of these reasons are no longer valid. Respectively: 1. Our Zig build scripts now execute the `xcodebuild` CLI directly and can open the resulting app, stream logs, etc. This is the same experience we have on Linux. (Xcode has always been a dependency of building on macOS in general, so this is not cumbersome.) 2. We have a healthy group of maintainers, many of which have access to both macOS and Linux, so we can quickly narrow down bugs regardless of the apprt. 3. Our OpenGL renderer hasn't been compatible with macOS for some time now, so this is no longer a useful feature. At this point, the GLFW apprt is just a burden. It adds complexity across the board, and some people try to run Ghostty with it in the real world and get confused when it doesn't work (it's always been lacking in features and buggy compared to the other apprts). So, it's time to say goodbye. Its bittersweet because it is a big part of Ghostty's history, but we've grown up now and it's time to move on. Thank you, goodbye. (NOTE: If you are a user of the GLFW apprt, then please fork the project prior to this commit or start a new project based on it. We've warned against using it for a very, very long time now.)
2025-06-27reintroduce App.createMitchell Hashimoto
2025-06-27embedded: fix core app initJeffrey C. Ollie
2025-06-27core: con't copy App and apprt.AppJeffrey C. Ollie
Besides avoiding copying, this allows consumers to choose to allocate these structs on the stack or to allocate on the heap. It also gives the apprt.App a stable pointer sooner in the process.
2025-06-24core, apprt: make runtimes implement resourcesDir directlyLeorize
2025-06-22macOS: Run scripts using stdin rather than executing directlyMitchell Hashimoto
Fixes #7647 See #7647 for context. This commit works by extending the `input` work introduced in #7652 to libghostty so that the macOS can take advantage of it. At that point, its just the macOS utilizing `input` in order to set the command and `exit` up similar to Terminal and iTerm2.
2025-06-21macos: support env vars for surface config, clean up surface configMitchell Hashimoto
2025-06-21macos: starting to work on new libghostty data modelsMitchell Hashimoto
2025-06-15apprt/embedded: API to read text can get top left/bottom right coordsMitchell Hashimoto
2025-06-15apprt/embedded: improve text reading APIs (selection, random points)Mitchell Hashimoto
2025-06-07macos: address quick terminal basic functionality with new APIMitchell Hashimoto
2025-06-02config: add launched-from to specify launch sourceMitchell Hashimoto
Related to #7433 This extracts our "launched from desktop" logic into a config option. The default value is detection using the same logic as before, but now this can be overridden by the user. This also adds the systemd and dbus activation sources from #7433. There are a number of reasons why we decided to do this: 1. It automatically gets us caching since the configuration is only loaded once (per reload, a rare occurrence). 2. It allows us to override the logic when testing. Previously, we had to do more complex environment faking to get the same behavior. 3. It forces exhaustive switches in any desktop handling code, which will make it easier to ensure valid behaviors if we introduce new launch sources (as we are in #7433). 4. It lowers code complexity since callsites don't need to have N `launchedFromX()` checks and can use a single value.
2025-05-26style: use decl literalsQwerasd
This commit changes a LOT of areas of the code to use decl literals instead of redundantly referring to the type. These changes were mostly driven by some regex searches and then manual adjustment on a case-by-case basis. I almost certainly missed quite a few places where decl literals could be used, but this is a good first step in converting things, and other instances can be addressed when they're discovered. I tested GLFW+Metal and building the framework on macOS and tested a GTK build on Linux, so I'm 99% sure I didn't introduce any syntax errors or other problems with this. (fingers crossed)
2025-05-09input: remove `physical_key` from the key event (all keys are physical)Mitchell Hashimoto
2025-05-09macOS: buildMitchell Hashimoto
2025-05-07core: fixup callconv(.C) -> callconv(.c)Jeffrey C. Ollie
https://ziglang.org/download/0.14.0/release-notes.html#Calling-Convention-Enhancements-and-setAlignStack-Replaced
2025-04-21libghostty: add API for getting commandsMitchell Hashimoto
2025-04-17macOS/libghostty: rework keyboard input handlingMitchell Hashimoto
This is a large refactor of the keyboard input handling code in libghostty and macOS. Previously, libghostty did a lot of things that felt out of scope or was repeated work due to lacking context. For example, libghostty would do full key translation from key event to character (including unshifted translation) as well as managing dead key states and setting the proper preedit text. This is all information the apprt can and should have on its own. NSEvent on macOS already provides us with all of this information, there's no need to redo the work. The reason we did in the first place is mostly historical: libghostty powered our initial macOS port years ago when we didn't have an AppKit runtime yet. This cruft has already practically been the source of numerous issues, e.g. #5558, but many other hacks along the way, too. This commit pushes all preedit (e.g. dead key) handling and key translation including unshifted keys up into the caller of libghostty. Besides code cleanup, a practical benefit of this is that key event handling on macOS is now about 10x faster on average. That's because we're avoiding repeated key translations as well as other unnecessary work. This should have a meaningful impact on input latency but I didn't measure the full end-to-end latency. A scarier part of this commit is that key handling is not well tested since its a GUI component. I suspect we'll have some fallout for certain keyboard layouts or input methods, but I did my best to run through everything I could think of.
2025-04-10config: allow commands to specify whether they shell expand or notMitchell Hashimoto
This introduces a syntax for `command` and `initial-command` that allows the user to specify whether it should be run via `/bin/sh -c` or not. The syntax is a prefix `direct:` or `shell:` prior to the command, with no prefix implying a default behavior as documented. Previously, we unconditionally ran commands via `/bin/sh -c`, primarily to avoid having to do any shell expansion ourselves. We also leaned on it as a crutch for PATH-expansion but this is an easy problem compared to shell expansion. For the principle of least surprise, this worked well for configurations specified via the config file, and is still the default. However, these configurations are also set via the `-e` special flag to the CLI, and it is very much not the principle of least surprise to have the command run via `/bin/sh -c` in that scenario since a shell has already expanded all the arguments and given them to us in a nice separated format. But we had no way to toggle this behavior. This commit introduces the ability to do this, and changes the defaults so that `-e` doesn't shell expand. Further, we also do PATH lookups ourselves for the non-shell expanded case because thats easy (using execvpe style extensions but implemented as part of the Zig stdlib). We don't do path expansion (e.g. `~/`) because thats a shell expansion. So to be clear, there are no two polar opposite behavioes here with clear semantics: 1. Direct commands are passed to `execvpe` directly, space separated. This will not handle quoted strings, environment variables, path expansion (e.g. `~/`), command expansion (e.g. `$()`), etc. 2. Shell commands are passed to `/bin/sh -c` and will be shell expanded as per the shell's rules. This will handle everything that `sh` supports. In doing this work, I also stumbled upon a variety of smaller improvements that could be made: - A number of allocations have been removed from the startup path that only existed to add a null terminator to various strings. We now have null terminators from the beginning since we are almost always on a system that's going to need it anyways. - For bash shell integration, we no longer wrap the new bash command in a shell since we've formed a full parsed command line. - The process of creating the command to execute by termio is now unit tested, so we can test the various complex cases particularly on macOS of wrapping commands in the login command. - `xdg-terminal-exec` on Linux uses the `direct:` method by default since it is also assumed to be executed via a shell environment.
2025-03-19apprt/embedded: utf8 encoding buffer lifetime must extend beyond callMitchell Hashimoto
Fixes #6821 UTF8 translation using KeymapDarwin requires a buffer and the buffer was stack allocated in the coreKeyEvent call and returned from the function. We need the buffer to live longer than this. Long term, we're removing KeymapDarwin (there is a whole TODO comment in there about how to do it), but this fixes a real problem today.
2025-03-12Lots of 0.14 changesMitchell Hashimoto
2025-03-09macOS: only set LANGUAGE for app bundle, do not inherit in termio envMitchell Hashimoto
Fixes #6633 For macOS, we set LANGUAGE to the priority list of preferred languages for the app bundle, using the GNU gettext priority list format (colon separated list of language codes). This previously was inherited by the termio env. At first, this was by design, but this has inherent flaws. Namely, the priority list format is a GNU gettext specific format, and programs that use alternate gettext implementations (like musl or Python) do not understand it and actually do the wrong thing (not their fault!). This change removes the inheritance of LANGUAGE in the termio env. To make it extra safe, we only do set and unset LANGUAGE when we know we launch from an app bundle. That was always the desired behavior but this makes it more explicit.
2025-02-13apprt/embedded: proper consumed modifier state for ctrl keysMitchell Hashimoto
2025-02-13Revert "macos: don't remove ctrl modifier for text input"Mitchell Hashimoto
This reverts commit 3104b217581a9e580155216a260b1a79135b701a.
2025-02-13apprt: require envmap for exec-based termioMitchell Hashimoto
Supercedes #5726
2025-02-13macos: don't remove ctrl modifier for text inputMitchell Hashimoto
Fixes #5448 We previously removed the ctrl modifier for text commit (IME-style) to workaround a libghostty quirk (as noted in the comment in the diff). But this broke other keyboard layouts. This commit attempts to clean this up slightly -- but not completely -- by removing that hack, and only modifying the ctrl behavior for the UCKeyTranslate call. Long term, I plan to remove UCKeyTranslate completely, as noted in the todo comment already written just below this diff. This fixes the aforementioned issue and hopefully doesn't regress any other behavior. I tested the following: 1. Dvorak Ctrl characters 2. Ergo-L Ctrl characters 3. US standard Ctrl characters 4. Japanese IME input Ctrl input to modify IME state
2025-02-11apprt/embedded: make performAction return the performable stateMitchell Hashimoto
2025-02-11core: performAction now returns a boolJeffrey C. Ollie
This is to facilitate the `performable:` prefix on keybinds that are implemented using app runtime actions.
2025-02-11gtk(x11): set `WINDOWID` env var for subprocessesLeah Amelia Chen
`WINDOWID` is the conventional environment variable for scripts that want to know the X11 window ID of the terminal, so that it may call tools like `xprop` or `xdotool`. We already know the window ID for window protocol handling, so we might as well throw this in for convenience.
2025-02-03macOS: binding checks should never trigger preedit callbacksMitchell Hashimoto
Fixes #5558 Binding checks would sometimes trigger preedit which would cause some characters to leak through. This is a bit of a band-aid. The real long term solution is noted in the TODO comment in this commit, but I wanted to avoid regressions in a patch release so I'm going to defer that to 1.2. This commit fixes the main issue for 1.1.1.
2025-01-23Prevent hyperlink hover state when mouse is outside viewport (#5267)Mitchell Hashimoto
## Description Fixed an issue where hyperlinks would maintain their hover state when the mouse is outside the viewport while holding the Cmd key. This created inconsistent behavior with the window's standard hover state clearing logic. ## Changes - Added viewport boundary check in `mouseRefreshLinks` function to prevent link processing when cursor is outside the window ## Testing To reproduce and verify the fix: 1. Run `fd --hyperlink "\.zig$" src/apprt` to create hyperlinks 2. Move mouse over a hyperlink (it should highlight) 3. Move mouse outside window 4. Hold Cmd key - Before: Link would show hover state - After: Link remains in non-hover state Fixes #5252 @rrotter Could you please try this to see if it solves your issue?
2025-01-23cli: allow renaming config fields to maintain backwards compatibilityMitchell Hashimoto
Fixes #4631 This introduces a mechanism by which parsed config fields can be renamed to maintain backwards compatibility. This already has a use case -- implemented in this commit -- for `background-blur-radius` to be renamed to `background-blur`. The remapping is comptime-known which lets us do some comptime validation. The remap check isn't done unless no fields match which means for well-formed config files, there's no overhead. For future improvements: - We should update our config help generator to note renamed fields. - We could offer automatic migration of config files be rewriting them. - We can enrich the value type with more metadata to help with config gen or other tooling.
2025-01-22Prevent hyperlink hover state when mouse is outside viewportBryan Lee
2025-01-08macos: Handle ctrl characters in IME inputMitchell Hashimoto
Fixes: https://github.com/ghostty-org/ghostty/issues/4634#issuecomment-2573469532 This commit fixes two issues: 1. `libghostty` must not override ctrl+key inputs if we are in a preedit state. This allows thigs like `ctrl+h` to work properly in an IME. 2. On macOS, when an IME commits text, we strip the control modifier from the key event we send to libghostty. This is a bit of a hack but this avoids triggering special ctrl+key handling.
2025-01-05config: allow booleans for `background-blur-radius`Leah Amelia Chen
2025-01-04macos: handle overridden system bindings with no focused windowMitchell Hashimoto
2025-01-04Key events return boolean if handledMitchell Hashimoto