118 Commits

Author SHA1 Message Date
Mitchell Hashimoto
a482224da8 renderer: set QoS class of the renderer thread on macOS
This sets the macOS QoS class of the renderer thread. Apple
recommends[1] that all threads should have a QoS class set, and there
are many benefits[2] to that, mainly around power management moreso than
performance I'd expect.

In this commit, I start by setting the QoS class of the renderer thread.
By default, the renderer thread is set to user interactive, because it
is a UI thread after all. But under some conditions we downgrade:

  - If the surface is not visible at all (i.e. another window is fully
    covering it or its minimized), we set the QoS class to utility. This
    is lower than the default, previous QoS and should help macOS
    unschedule the workload or move it to a different core.

  - If the surface is visible but not focused, we set the QoS class to
    user initiated. This is lower than user interactive but higher than
    default. The renderer should remain responsive but not consume as
    much time as it would if it was user interactive.

I'm unable to see any noticable difference in anything from these
changes. Unfortunately it doesn't seem like Apple provides good tools to
play around with this.

We should continue to apply QoS classes to our other threads on macOS.

[1]: https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon?preferredLanguage=occl
[2]: https://blog.xoria.org/macos-tips-threading/
2024-11-26 15:43:35 -08:00
Mitchell Hashimoto
b9345e8d6a try to abstract bundle ID to a zig file 2024-11-25 16:11:02 -08:00
Mitchell Hashimoto
adc59be977 os: more error handling on reading the app support dir 2024-11-25 16:04:41 -08:00
Kyaw
10e37a3dee config: support loading from "Application Support" directory on macOS 2024-11-24 17:08:07 +07:00
Jon Parise
433b6b4fe2 os: replace PATH_SEP with std.fs.path.delimiter
This standard library symbol is equivalent.
2024-11-19 10:51:02 -05:00
Mitchell Hashimoto
75fe0b2dfb Merge pull request #2617 from ghostty-org/pagelist-wip
chore: rename fields in PageList, move data structures to package, move PageList to intrusive linked list
2024-11-07 15:49:08 -08:00
Kristófer R
84707932d2 os/hostname: fix mac address handling when last section starts with '0'
I hit an edge case when using Private Wi-Fi addressing on macOS where
the last section of the randomized mac address starts with a '0'. The
hostname parsing for the shell integration didn't handle this case, so
issue #2512 reappeared.

This fixes that by explicitly handling port numbers < 10.
2024-11-07 18:17:51 -05:00
Mitchell Hashimoto
a436bd0af6 move datastructures to dedicated "datastruct" package 2024-11-07 14:39:10 -08:00
Mitchell Hashimoto
c8b99f7891 remove refalldecls test 2024-11-05 10:36:16 -08:00
Mitchell Hashimoto
4a263f43af stylistic changes 2024-11-05 10:30:56 -08:00
Kristófer R
9c2f260351 os/hostname: add and use explicit error structs 2024-11-04 19:26:29 -05:00
Kristófer R
e85b114031 os/hostname: add better validation for mac-address hostnames 2024-11-04 18:59:42 -05:00
Kristófer R
9ae6806e30 os/hostname: test bufPrintHostnameFromFileUri
Note that this includes some failing tests because I want to make the
uri handling better and more specific. It's a little bit too general
right now so I want to lock it down to:

1. macOS only; and
2. valid mac address values

because that's how the macOS private Wi-Fi address thing works;
randomizes your mac address and sets that as your hostname.
2024-11-04 18:59:41 -05:00
Kristófer R
78abd051a2 os/hostname: test isLocalHostname 2024-11-04 18:59:41 -05:00
Kristófer R
03bb16fcec Move hostname helpers to src/os/hostname.zig 2024-11-04 16:54:38 -05:00
Mitchell Hashimoto
115e14f19f macos: NSProcessInfo-based arg iterator
Fixes #2432

On macOS, processes with an NSApplicationMain entrypoint do not have
access to libc argc/argv. Instead, we must use NSProcessInfo. This
commit introduces an args iterator that uses NSProcessInfo, giving us
access to the args.

This also fixes an issue where we were not properly skipping argv0 when
iterating over the args. This happened to be fine because we happened to
ignore invalid args but it introduces a config error.
2024-10-14 17:08:33 -07:00
Mitchell Hashimoto
2abdf291f4 implement sentry transport to write crash reports to XDG_STATE_HOME 2024-08-28 21:43:18 -07:00
Mitchell Hashimoto
7f143d9df4 os: add xdg cache dir function 2024-08-28 21:43:17 -07:00
Mitchell Hashimoto
677f0376a0 os: yeet usingns 2024-08-16 14:29:08 -07:00
Mitchell Hashimoto
d0ca949c09 os: start yeeting 2024-08-16 10:57:19 -07:00
Mitchell Hashimoto
a158a1d45f os: unify memory/processes cgroup limiting func 2024-08-11 15:37:54 -07:00
Christian Kugler
ba41f142ed Add Config Option to Limit Number of Processes
To protect your system and ghostty from misbehaving programs that launch
too many processes for the system to handle (e.g. like a fork bomb),
this implements an option to limit the number of processes that can be
started in a surface.

A fork bomb for example or other misbehaving program would then only
take down one surface and not the entire system.

Side node:
If I am right in issue #2084, this feature does not actually work on a
per surface basis but on all surfaces. If this is the case, it could
probably be fixed together. Chances are, that I am wrong though 😉

Further improvements that could be done:
- unify way to set cgroup attributes
- set sane default: 10% of system max?
2024-08-11 23:37:57 +02:00
multifred
72c672adb7 Fix multiple deprecated names for zig lib/std 2024-07-22 00:07:17 +02:00
Mitchell Hashimoto
1100145cf3 tweaks 2024-07-18 15:57:55 -07:00
Łukasz Niemier
255e50124c fix: instead of overriding MANPATHs set by OS, append to them
Quoting `man man`:

>  If MANPATH begins with a colon, it is appended to the default list;

Alternatively we can think about:

> if it ends with a colon, it is prepended to the default list;

To take preference over existing values, but that shouldn't be really a
problem, as there rather isn't much of another projects named `ghostty`.
2024-07-19 00:36:42 +02:00
Mitchell Hashimoto
3038cb4979 Move CFReleaseThread to os package 2024-06-22 20:15:59 -07:00
Mitchell Hashimoto
8f9cdff1f5 small stylistic tweaks 2024-06-08 19:07:10 -07:00
Jeffrey C. Ollie
e6f97c28f8 Use clone3 / CLONE_INTO_CGROUP on Linux
Use clone3 / CLONE_INTO_CGROUP to have the Linux kernel create the process in the
correct cgroup rather than move the process into the cgroup after it is created.
2024-06-07 23:48:03 -06:00
Jon Parise
b1e1d8c3eb os: std.ChildProcess -> std.process.Child
std.ChildProcess was deprecated in favor of std.process.Child a few
releases back, and the old name is removed in Zig 0.13.0.
2024-06-07 12:36:30 -04:00
Mitchell Hashimoto
be598be6de config: xdg-terminal-exec parsing should ignore the initial "-e" 2024-06-06 14:50:04 -07:00
Mitchell Hashimoto
7d9da34259 termio/exec: move subprocess into cgroup 2024-06-05 09:30:21 -07:00
Mitchell Hashimoto
01bfce0981 os: cgroup can set memory limits 2024-06-04 21:02:25 -07:00
Mitchell Hashimoto
d351e80158 os: cgroup create/move 2024-06-04 20:22:17 -07:00
Mitchell Hashimoto
bbe525c964 os: API to configure cgroup controllers 2024-06-04 19:36:48 -07:00
Mitchell Hashimoto
b5c4d2f60d os: rename linux => cgroup 2024-06-04 19:28:12 -07:00
Mitchell Hashimoto
c0b061edd9 os: API for listing cgroup controllers 2024-06-04 19:23:18 -07:00
Mitchell Hashimoto
0a5f3fa0a4 os: add linux API for getting cgroup by pid 2024-06-04 15:15:11 -07:00
Gregory Anders
695bc307ba os/open: do not wait for commands which do not terminate
Some opener commands (like macOS's open) finish immediately after
running, while others (xdg-open) do not, staying alive until the
application that was opened itself terminates.

For now, we explicitly state whether or not we should wait for a
command. Eventually we may want to do something more generic (e.g. wait
for some predetermined amount of time and if the process does not
complete, give up without collecting stderr).
2024-05-31 12:25:17 -05:00
Mitchell Hashimoto
1e60f7186c os: some stylistic changes, comments for stderr logging 2024-05-20 19:11:30 -04:00
Gregory Anders
e710a59a43 os: log stderr from open command 2024-05-19 09:00:53 -05:00
Jon Parise
29a5b52885 os/homedir: remove now unnecessary fba.reset() 2024-03-31 08:56:56 -07:00
Jon Parise
55b611e4cb os/homedir: use NSFileManager on macOS
NSFileManager has offered a homeDirectoryForCurrentUser property since
macOS 10.12. Using that is preferable to running a directory service
child process.
2024-03-30 20:24:43 -07:00
Mitchell Hashimoto
b7bf59d772 update zig 2024-03-22 11:15:26 -07:00
Krzysztof Wolicki
f4e8982e5c Windows Utf8 -> Wtf8 2024-02-26 18:01:06 +01:00
Jonathan Marler
e1996ad1e5 os: remove UB, tmpDir is returning stack memory on Windows
On Windows, the tmpDir function is currently using a buffer on the stack
to convert the WTF16-encoded environment variable value "TMP" to utf8
and then returns it as a slice...but that stack buffer is no longer valid
when the function returns.  This was causing the "image load...temporary
file" test to fail on Windows.

I've updated the function to take an allocator but it only uses
the allocator on Windows.  No allocation is needed on other platforms
because they return environment variables that are already utf8 (ascii)
encoded, and the OS pre-allocates all environment variables in the process.
To keep the conditional that determines when allocation is required, I
added the `freeTmpDir` function.
2024-02-10 21:09:05 -07:00
Mitchell Hashimoto
c2e0cff1d2 termio/exec: only add ghostty path if it isn't already in path 2024-01-31 18:57:42 -08:00
Mitchell Hashimoto
470b57f194 os: no mouse interval on ios 2024-01-14 14:48:56 -08:00
Mitchell Hashimoto
3360a008cd build: build produces a broken object file for iOS
This gets `zig build -Dtarget=aarch64-ios` working. By "working" I mean
it produces an object file without compiler errors. However, the object
file certainly isn't useful since it uses a number of features that will
not work in the iOS sandbox.

This is just an experiment more than anything to see how hard it would be to
get libghostty working within iOS to render a terminal. Note iOS doesn't
support ptys so this wouldn't be a true on-device terminal. The
challenge right now is to just get a terminal rendering (not usable).
2024-01-13 21:38:58 -08:00
Mitchell Hashimoto
8a816dc5ef os: mac app launched with bundle env var is treated as desktop launch 2024-01-06 12:30:44 -08:00
Mitchell Hashimoto
86bd972d22 macos: do not change nofile rlimit max
Fixes #1146

I can't remember why we did this before. The comment in question makes
sense if we were trying to set cur to infinity but doesn't make sense to
me why we'd change max. Removing this doesn't seem to cause any issues
so lets give it a shot.
2023-12-22 08:58:31 -08:00