Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtk: use AdwAlertDialog for close dialogs, fix incorrect close dialogs #5741

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pluiedev
Copy link
Contributor

@pluiedev pluiedev commented Feb 13, 2025

AdwAlertDialog is the recommended way to do alert/message dialogs starting from libadwaita 1.5, and is much easier to manage than GtkMessageDialog. (The latter is also deprecated since GTK 4.10, but this PR does not migrate it to use GtkAlertDialog, mostly because of its obtuse interface and that we'll remove the GtkMessageDialog code anyway in 1.2 when we remove non-Adwaita builds.)

We also had two bugs where tabs with only one split would display the "close surface" confirmation dialog, and windows would do the same when closed via the "Close Window" menu item or by the close_window keybind action. (The "close window" dialog only appears when the user clicks on the close button on the titlebar.) Initially I was very confused by this, but it turns out that we don't have any apprt action related to closing a window, and it was simply closing surfaces...

@pluiedev pluiedev requested review from a team as code owners February 13, 2025 19:35
@pluiedev pluiedev added this to the 1.2.0 milestone Feb 13, 2025
Copy link
Collaborator

@tristan957 tristan957 left a comment

Choose a reason for hiding this comment

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

I decided to take a look at what GNOME Console does in these situations:

image

image

Maybe we could align our wording a little more closely with what they do, except without the run-on sentence 😄. One quick suggestion is to remove the this.

What do you think about waiting to merge this PR until after we remove vanilla GTK and add zig-gobject?

src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
@tristan957
Copy link
Collaborator

Maybe the second commit in this series should be its own PR? It doesn't seem related to GTK other than implementing the action which we could then do in a subsequent PR.

@tristan957
Copy link
Collaborator

Could you also provide some screenshots so we can see everything put together?

@pluiedev
Copy link
Contributor Author

pluiedev commented Feb 13, 2025

We've already added zig-gobject, and honestly IMO this can be the first step to removing non-Adwaita builds — an advantage of zig-gobject is that because the bindings are all statically generated extern functions, we don't actually need to compile with adwaita.h and it would not complain about missing symbols. Removing vanilla GTK support is as simple as just removing the vanilla GTK code (though, we might need to provide a fallback for older libadwaita versions using AdwMessageDialog, but the API is essentially the same)

@pluiedev
Copy link
Contributor Author

pluiedev commented Feb 13, 2025

I agree that removing "this" looks better xD

image
image
image
image

@tristan957
Copy link
Collaborator

What's the difference between "close window" and "quit ghostty"? Also what are your thoughts on Close and Cancel terminology?

@pluiedev
Copy link
Contributor Author

pluiedev commented Feb 13, 2025

Close window closes one window, quit Ghostty quits all windows. I think Close and Cancel would probably look better, but the current labels are just for the sake of being the same as vanilla GTK, which used Yes/No buttons.

EDIT: The GNOME HIG suggests using Cancel/Close. Will follow that then.

@tristan957
Copy link
Collaborator

Close window closes one window, quit Ghostty quits all windows. I think Close and Cancel would probably look better, but the current labels are just for the sake of being the same as vanilla GTK, which used Yes/No buttons.

EDIT: The GNOME HIG suggests using Cancel/Close. Will follow that then.

Loving the prose updates! I also like the idea of the CloseTarget you've added. Nice little abstraction.

@@ -4242,7 +4242,11 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool

.close_surface => self.close(),

.close_window => self.app.closeSurface(self),
.close_window => return try self.rt_app.performAction(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! I remember the history here. Close window was implemented for macOS only for a time because its a common macOS-ism. The handling is all done in the apprt and not here, so I just put whatever here since nothing ever triggered it. That is, until GTK added a menu item to do so. 😄

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Looks great, just wanted to add a few of my notes.

src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
return switch (self) {
.window => "Close this Window?",
.tab => "Close this Tab?",
.surface => "Close this Surface?",
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend changing this to "Terminal" (the copy, not the enum). It will be more instantly recognizable to users I think than surface...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Terminal" is kind of a confusing term since it can refer to the entire terminal... That's part of the terminology problem I've been bringing up in discussions lately — we need a better term than "split" or "terminal" since the former isn't exactly accurate (a surface directly under a tab wouldn't be considered as a "split") and the latter is too vague. Maybe we should lean into iTerm2's terminology of panes and such?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that with Mitchell that surface probably shouldn't be surfaced to users. I'm not sure terminal is the right word to use, but I like panel over surface.

src/apprt/gtk/close_dialog.zig Show resolved Hide resolved
@pluiedev pluiedev force-pushed the push-mslmmoznqtvo branch 4 times, most recently from 69fbec1 to 948d019 Compare February 13, 2025 23:46
For *some* reason we have a binding for close_window but it merely closes
the surface and not the entire window. That is not only misleading but
also just wrong. Now we make a separate apprt action for close_window
that would make it show a close confirmation prompt identical to as if
the user had clicked the (X) button on the window titlebar.
src/apprt/gtk/adwaita.zig Show resolved Hide resolved

pub fn closeWithConfirmation(self: *Window) void {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't love the name of this function given the next comment. What about just close with documentation in a function level comment?

src/apprt/gtk/close_dialog.zig Show resolved Hide resolved
src/apprt/gtk/close_dialog.zig Show resolved Hide resolved
src/apprt/gtk/close_dialog.zig Show resolved Hide resolved
src/apprt/gtk/Surface.zig Show resolved Hide resolved
src/apprt/gtk/Surface.zig Show resolved Hide resolved
@jcollie
Copy link
Collaborator

jcollie commented Feb 18, 2025

@pluiedev if you can resolve the conflicts and take a look at the open comments I'd like to review this one next.

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.

4 participants