187 Commits

Author SHA1 Message Date
Mitchell Hashimoto
d1e45ef768 apprt/gtk: when text is committed, end the preedit state
Fixes #3567

ibus 1.5.29 doesn't trigger a preedit end state when text is committed.
This is fixed in ibus 1.5.30, but we need to handle this case for older
versions which are shipped on LTS distributions such as Ubuntu.

Every other input method engine I've tried thus far also triggers a
preedit end state when text is committed, and none would expect preedit
to continue after text is committed. So I think it's safe to assume that
this is the expected behavior.
2025-01-23 11:47:46 -08:00
Mitchell Hashimoto
4408101b8d apprt/gtk: ibus activation should not encode keys
This cleans up our handling of when GTK tells us the input method
handled the key press to address more scenarios we should not encode the
key event. The comments in this diff should explain clearly.
2025-01-22 20:19:25 -08:00
Mitchell Hashimoto
52936b9b68 apprt/gtk: fundamentally rework input method handling
Fixes #4332

This commit fundamentally reworks the input method handling in the GTK
apprt, making it work properly (as reported in the linked issue) on both
Wayland and X11. This was tested with both a Gnome desktop on Wayland
and i3 on X11 with fcitx and mozc.

The main changes are:

- Both key press and release events must be forwarded to the input
  method.

- Input method callbacks such as preedit and commit must be expected
  outside of keypress events to handle on-screen keyboards and
  non-keyboard input devices.

- Input methods should always commit when told to. Previously, we would
  only commit when a keypress event was given. This is incorrect. For
  example, it didn't work with input method changes outside the app
  which should result in committed text (as can be seen with "official"
  Gnome apps like Notes or Console).

The key input handling also now generally does less so I think input
latency should be positively affected by this change. I didn't measure.
2025-01-21 14:37:40 -08:00
Leah Amelia Chen
4e0d9b1b27 gtk(wayland): implement server-side decorations 2025-01-14 09:57:59 -08:00
james
faea09bbde for GTK runtime, don't call cursorPosCallback in mouse motion callback if the cursor hasn't actually moved 2025-01-11 23:53:19 -05:00
Mitchell Hashimoto
ed81b62ec2 apprt/gtk: winproto
Rename "protocol" to "winproto".
2025-01-10 09:39:34 -08:00
Leah Amelia Chen
03fee2ac33 gtk: unify Wayland and X11 platforms 2025-01-09 14:57:02 -08:00
Mitchell Hashimoto
19ffb0b51f Implement a size-limit function for GTK (#4840)
A "size-limit" function has been implemented for GTK which calls
gtk_widget_set_size_request() to set the minimum widget/window size.
Without
this function, it's left to GTK to set the minimum size which is usually
a lot larger than the documented 10x4 cell minimum size. This doesn't
fix the
issue completely as GTK retains the final say in how small a window can
be
but it gets closer.

Resolves: #4836
2025-01-08 18:49:05 -08:00
George Joseph
dac13701e3 Implement a size-limit function for GTK
A "size-limit" function has been implemented for GTK which calls
gtk_widget_set_size_request() to set the minimum widget/window size. Without
this function, it's left to GTK to set the minimum size which is usually
a lot larger than the documented 10x4 cell minimum size.  This doesn't fix the
issue completely as GTK retains the final say in how small a window can be
but it gets closer.

Resolves: #4836
2025-01-08 15:50:18 -07:00
Jeffrey C. Ollie
c33629aae5 gtk: clean up context menu creation & refresh 2025-01-08 16:01:31 -06:00
Mitchell Hashimoto
ef12d90b74 gtk: implement dropping files and strings (#4211)
This allows dropping files and strings onto Ghostty in the GTK apprt. If
you drop files onto Ghostty it will be pasted as a list of shell-escaped
paths separated by newlines. If you drop a string onto Ghostty it will
paste the string. Normal rules for pasting (bracketed pasts, unsafe
pastes) apply.
2025-01-08 13:12:09 -08:00
Jeffrey C. Ollie
e7c71df0b7 gtk: implement dropping files and strings 2025-01-08 08:39:28 -06:00
Tristan Partin
3698b37588 apprt/gtk: use a subtitle to mark the current working directory
If the title is already the current working directory, hide the
subtitle. Otherwise show the current working directory, like if
a command is running for instance.

Signed-off-by: Tristan Partin <tristan@partin.io>
2025-01-06 08:05:24 -06:00
Tim Culverhouse
4d4b785a58 gtk: send copy_to_clipboard toast from Surface
Move the toast we send when copying to the clipboard to the Surface
implementation. Previously, we only called this from the gtk accelerator
callback which we only call when the *last set* keybind is activated.

We also only send a toast if we have copied to the standard clipboard,
as opposed to the selection clipboard. By default, we have
copy-to-clipboard true for linux, which sets the selection keyboard on
any select. This becomes *very* noisy.
2025-01-05 09:25:47 -06:00
Matt Rochford
6a4842f110 Don't steal focus on mouse events that are within 1 px 2025-01-02 13:46:15 -08:00
Liam Hupfer
aa34b91856 gtk: Always read gtk-xft-dpi for font scaling
Commit ad503b8c4fa7 ("linux: consider Xft.dpi to scale the content")
introduced reading gtk-xft-dpi when the X11 build option is enabled.

While the name suggests it is X11-specific (perhaps it was at one
point), gtk-xft-dpi is a GTK setting that can be modified regardless of
GDK backend. GNOME’s Large Text accessibility setting ultimately
modifies it. Outside of desktop environments, it can be set via GTK
configuration files.

Remove the conditional gating the code on X11, since none of the code is
actually X11-specific. While we’re here, document scaling behaviors
under Config.font-size.

Fixes: ad503b8c4fa7 ("linux: consider Xft.dpi to scale the content")
Fixes: https://github.com/ghostty-org/ghostty/issues/4338
Link: https://docs.gtk.org/gtk4/class.Settings.html
Link: https://docs.gtk.org/gtk4/property.Settings.gtk-xft-dpi.html
2025-01-02 12:48:28 -06:00
Mitchell Hashimoto
64c393716a GTK: add delay before updating the title (#3746)
This pr fixes https://github.com/ghostty-org/ghostty/issues/2503 for
GTK.
The implementation is quite similar to what was done in
https://github.com/ghostty-org/ghostty/pull/2929 for the macOS version.

Before (i was able to reproduce the issue by just invoking `ls`):


https://github.com/user-attachments/assets/011acb1d-de71-46a1-8a14-45e8eb932183



After:


https://github.com/user-attachments/assets/b749cd1c-355e-47de-a976-62d98a56f966
2024-12-29 07:18:56 -08:00
Maciej Bartczak
2b245c965c Invalidate the timer when the surface is destroyed 2024-12-29 09:27:59 +01:00
Misaki Kasumi
02ca5bedac cgroup: change suffix to .scope 2024-12-29 11:25:45 +08:00
Jeffrey C. Ollie
8ecb11a602 gtk: add option to not link against libX11 2024-12-28 13:40:17 -06:00
Maciej Bartczak
4ed8306b02 Add delay before updating the title 2024-12-28 17:18:15 +01:00
Tristan Partin
a38acbc11c apprt/gtk: handle nullable event from event controller
gtk_event_controller_get_current_event() is documented to possibly
return NULL.

Fixes: https://github.com/ghostty-org/ghostty/issues/2022
Fixes: https://github.com/ghostty-org/ghostty/issues/3088
Link: https://docs.gtk.org/gtk4/method.EventController.get_current_event.html
Signed-off-by: Tristan Partin <tristan@partin.io>
2024-12-25 23:38:18 -06:00
Khang Nguyen Duy
cb67fbd08d gtk: pass surface to clipboard window by reference instead of by value
The surface might be mutated during the clipboard confirmation
(resized in my case), leading to the copied cursor page_pin being
invalidated.
2024-12-12 00:21:59 +07:00
Mitchell Hashimoto
b9345e8d6a try to abstract bundle ID to a zig file 2024-11-25 16:11:02 -08:00
Mitchell Hashimoto
7aeee06471 apprt/gtk: set inherited working directory manually
Fixes #2745

GTK uses a delayed surface initialization since we initialize on
GTKGLArea realize not on the actual callback. Because of that, our
inherited directory doesn't always work since that depends on a
previously focused widget.

This copies our desired inherited directory to an allocation so that we
can set it during realize.
2024-11-20 14:49:01 -08:00
Tristan Partin
9c25811576 apprt/gtk: handle pwd action
Use it as a tooltip for the tab.

Signed-off-by: Tristan Partin <tristan@partin.io>
2024-11-16 15:20:53 -06:00
Paul Berg
1e003b2e0f gtk: implement toggle_split_zoom 2024-11-06 09:59:10 +01:00
Mitchell Hashimoto
745079cbb5 core: simplify scroll math, fix horizontal scroll direction on macOS
This simplifies the math for calculating scroll vectors based on mouse
scroll events. This was done to fix inverted horizontal scrolling on
macOS with natural scrolling enabled. Many assertions were added for
assumptions and our preconditions are clearly documented.

The preconditions are:

  * Apprt scroll offsets are negative down/left, positive up/right
  * Terminal vertical scroll is postive down, negative up (opposite
    since scroll for a terminal means how many rows to move down).
  * `Surface.scrollCallback` is always call with an apprt offset.
  * Apprt is responsible for implementing natural scrolling. Surface
    always assumes negative is down/left.
2024-10-10 16:24:16 -07:00
Mitchell Hashimoto
9c547dd8cd apprt/gtk: forward window key events to the focused surface 2024-10-07 13:06:35 -07:00
Mitchell Hashimoto
9e435f050e apprt/gtk: setup window key event infrastructure 2024-10-07 13:01:36 -07:00
Mitchell Hashimoto
eab6c0d4af gtk: only set initial window size if its the first terminal in a window
Fixes #2391
2024-10-07 09:46:13 -07:00
Mitchell Hashimoto
c7f83fcef8 gtk: notify core of cursor leave 2024-10-06 18:23:53 -07:00
Mitchell Hashimoto
4ae20212bf libghostty: unified action dispatch
First, this commit modifies libghostty to use a single unified action
dispatch system based on a tagged union versus the one-off callback
system that was previously in place. This change simplifies the code on
both the core and consumer sides of the library. Importantly, as we
introduce new actions, we can now maintain ABI compatibility so long as
our union size does not change (something I don't promise yet).

Second, this moves a lot more of the functions call on a surface into
the action system. This affects all apprts and continues the previous
work of introducing a more unified API for optional surface features.
2024-09-26 22:00:11 -07:00
Mitchell Hashimoto
4cc4eb5ed0 core: remove more hasdecls 2024-09-26 14:21:06 -07:00
Mitchell Hashimoto
4e2781fdec apprt/gtk 2024-09-26 14:13:18 -07:00
Mitchell Hashimoto
26cba70b69 core: no need for hasTabs apprt function 2024-09-26 08:34:20 -07:00
Mitchell Hashimoto
261ce00552 apprt/macos,gtk: unfocused splits now highlight hovered links
Fixes #1547

The core change to make this work is to make the cursor position
callback support taking updated modifiers. On both macOS and GTK, cursor
position events also provide the pressed modifiers so we can pass those
in.
2024-09-21 15:16:14 -07:00
Mitchell Hashimoto
9e73d865fb apprt/gtk: small comments 2024-09-13 20:45:39 -07:00
Jeffrey C. Ollie
5f759a19d1 GTK: Fix clicking on desktop notifications
Currently, clicking on a desktop notification will bring Ghostty
to the foreground, but it won't necessarily bring the right window
to the top and it won't switch tabs or change the focus on splits.

With this patch, clicking on a desktop notification will raise the
correct window, change to the correct tab, and focus on the correct
split that send the original desktop notification.
2024-09-13 13:37:38 -07:00
Paul Berg
0c286a049a gtk: add adwaita banner 2024-09-11 15:42:31 +02:00
Paul
0e22695ec4 gtk: use adwaita tab view when possible
add tab bar view
2024-09-11 15:35:22 +02:00
Mitchell Hashimoto
a3aa5463a1 Revert "Merge pull request #2060 from jcollie/gtk-compatibility"
This reverts commit 9ce789cc85d411c59eff2a01c7fe18ce14ccd2b8, reversing
changes made to f1aea10a84176ff4338f7d2f0bf1b9c700b41baa.
2024-09-05 08:45:37 -07:00
Mitchell Hashimoto
2142ba53c4 apprt/gtk: do not remove unfocused widget from overlay
See comment
2024-09-04 14:17:51 -07:00
Jeffrey C. Ollie
bbb204ac85 rename gtkVersionMinimum->gtkVersionAtLeast for consistency 2024-08-31 19:16:43 -07:00
Jeffrey C. Ollie
b6c943386c Conditional compilation against different GTK versions
Adds a comptime function to enable conditional compilation against
different GTK versions that have added new API calls in newer versions
of GTK.

Use this function to get fractional scaling information for GTK
surfaces, which is only available with GTK 4.12+.
2024-08-31 19:15:24 -07:00
Mitchell Hashimoto
512b24818a apprt/gtk: fix int cast 2024-08-26 20:16:23 -07:00
Mitchell Hashimoto
d7e7f55956 apprt/gtk: support last_tab 2024-08-26 20:13:28 -07:00
Mitchell Hashimoto
9409e3072f apprt/gtk: remove usingnamespace 2024-08-16 14:58:04 -07:00
Jeffrey C. Ollie
414fdc0214 gtk: prettify the url overlays 2024-08-13 14:21:28 -05:00
Jeffrey C. Ollie
f4bdf8d3a1 gtk: resize overlay improvements
* runtime changing of `resize-overlay` now works on GTK
* shorten function names in ResizeOverlay
* improve documentation
2024-08-11 12:23:43 -05:00