Go back to the alert-style add/import dialogs, in a taller window

The plain `AdwDialog`s with the accept button in the header bar are not
wanted; restore the `AdwAlertDialog` versions of "Create an identity key" and
"Import an identity key".

The clipping they were meant to fix was the window height, not the dialog
style: the identities window is a fixed size and GTK never resizes a mapped
window, so its default has to fit the first-run empty state and the dialogs.
Keep the taller window (420x560); the width goes back to the original 420.

Reverts most of the previous commit.
This commit is contained in:
raucao committed 2026-11-28 15:18:58 +04:00
1 parent ab09201a2e
commit fca9851d8f
3 files changed
+40 -135

No files matched your search

+5 -9
View File
@@ -191,9 +191,9 @@ data/ desktop, metainfo, gschema (all `.in` templates), icons, re
(`data/resources/ui/keys.blp`) around the existing `KeysView`. A second
`AppState` would mean a second registry and a second signer on one device key
(see M5), so the registry is created once in `application.rs` and shared. The
window is sized (480×560) for the **first-run empty state**, the tallest thing
it shows — GTK never resizes a mapped window, so the default has to fit it —
and is wide enough for the add/import form dialogs (`keys_view::FORM_WIDTH`).
window is 420×560: tall enough for the **first-run empty state** and the
add/import alert dialogs, because GTK never resizes a mapped window, so the
default has to fit the tallest thing it shows.
- **The invariant: the main window is presentable exactly when the responder can
serve prompts.** The approval dialogs are parented to the main window, so a
request must never arrive without it. With no keys there is nothing to sign
@@ -537,12 +537,8 @@ data/ desktop, metainfo, gschema (all `.in` templates), icons, re
button uses — which is what lets a locked user reach "Change…" without leaving
Preferences. It is inert until a key (and so a passphrase) exists. The
identities window's add/import dialogs carry the passphrase field
(with a confirmation only when that call *sets* the passphrase). They are plain
`AdwDialog`s — a header bar with Cancel and the accept button over a scrolling
body (`keys_view::form_dialog`) — **not** `AdwAlertDialog`s: an alert's message
area only propagates its natural height, so a form taller than the window is
clipped instead of scrolling. Export needs the vault open first
(`with_unlocked`).
(with a confirmation only when that call *sets* the passphrase). Export needs
the vault open first (`with_unlocked`).
- **Never log, print or put the passphrase in argv/env.** The passphrase is
`Zeroizing` where it crosses the vault and the headless path, and is dropped as
soon as the unlock lands; the GTK dialog fields hand it over as a plain
+1 -1
View File
@@ -3,7 +3,7 @@ using Adw 1;
Adw.ApplicationWindow keys_window {
title: "Identities";
default-width: 480;
default-width: 420;
default-height: 560;
content: Adw.ToolbarView toolbar_view {
+34 -125
View File
@@ -319,100 +319,6 @@ impl PassphraseFields {
const NEW_VAULT_NOTE: &str = "Choose a passphrase for the key vault. Every identity key is \
stored encrypted under it, and it is needed to sign. There is no recovery if you forget it.";
/// The width of the add/import form dialogs.
///
/// A floating `AdwDialog` is clipped by the window it is presented in, and these
/// live in the identities window (480 px), so they must be narrower than that.
/// The approval and "Connect an app" dialogs use `plain::DIALOG_WIDTH` (480),
/// but they live in the wider main window.
const FORM_WIDTH: i32 = 420;
/// A form dialog: a header bar with Cancel and an accept button over a body that
/// scrolls rather than growing past the window.
///
/// Deliberately **not** an `AdwAlertDialog`: its message area only *propagates*
/// its natural height (see `adw-alert-dialog.c`), so a form taller than the
/// window is clipped instead of scrolling — the confirm row and the buttons were
/// cut off in the 480 px identities window. This is the same shape as "Connect
/// an app": an `AdwToolbarView` whose content is a scroller, with
/// `follows_content_size` so the dialog hugs its content.
///
/// Returns the dialog and its accept button; the caller wires the button up.
/// Cancel just closes the dialog.
fn form_dialog(
title: &str,
note: &str,
content: &impl IsA<gtk::Widget>,
accept: &str,
) -> (adw::Dialog, gtk::Button) {
let note = gtk::Label::builder()
.label(note)
.use_markup(false)
.wrap(true)
.wrap_mode(gtk::pango::WrapMode::WordChar)
.xalign(0.0)
.css_classes(["dim-label"])
.build();
let body = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.spacing(18)
.margin_top(18)
.margin_bottom(18)
.margin_start(12)
.margin_end(12)
.build();
body.append(&note);
body.append(content);
// A scroller's natural height is 0 unless it propagates, and the dialog sizes
// to its child's natural height (trap 15). The cap keeps a long body from
// making the dialog taller than the window.
let scrolled = gtk::ScrolledWindow::builder()
.child(&body)
.vexpand(true)
.hscrollbar_policy(gtk::PolicyType::Never)
.propagate_natural_height(true)
.max_content_height(620)
.build();
let header = adw::HeaderBar::new();
header.set_title_widget(Some(&adw::WindowTitle::new(title, "")));
let cancel = gtk::Button::with_label("Cancel");
let accept_button = gtk::Button::builder()
.label(accept)
.css_classes(["suggested-action"])
.build();
header.pack_start(&cancel);
header.pack_end(&accept_button);
let toolbar = adw::ToolbarView::new();
toolbar.add_top_bar(&header);
toolbar.set_content(Some(&scrolled));
// Pin the width on the dialog's child: with `follows_content_size` below,
// libadwaita ignores `content_width` and uses the content's natural width
// instead (trap 16).
toolbar.set_size_request(FORM_WIDTH, -1);
let dialog = adw::Dialog::builder()
.title(title)
.follows_content_size(true)
.child(&toolbar)
.build();
// The user is typing the secret themselves, so a default action is fine here
// (unlike the approval dialog, which deliberately has none).
dialog.set_default_widget(Some(&accept_button));
{
let dialog = dialog.clone();
cancel.connect_clicked(move |_| {
dialog.close();
});
}
(dialog, accept_button)
}
fn present_create(handles: Handles, state: Rc<AppState>) {
let store = state.store();
let first = !store.has_vault();
@@ -430,21 +336,28 @@ fn present_create(handles: Handles, state: Rc<AppState>) {
list.append(&name);
fields.append_to(&list);
let (dialog, create) = form_dialog(
"Create an identity key",
if first {
let dialog = adw::AlertDialog::builder()
.heading("Create an identity key")
.body(if first {
NEW_VAULT_NOTE
} else {
"The new key is encrypted under your vault passphrase."
},
&list,
"Create",
);
})
.extra_child(&list)
.build();
plain::dialog(&dialog);
dialog.add_response("cancel", "Cancel");
dialog.add_response("create", "Create");
dialog.set_default_response(Some("create"));
dialog.set_response_appearance("create", adw::ResponseAppearance::Suggested);
dialog.set_close_response("cancel");
{
let (handles, state) = (handles.clone(), Rc::clone(&state));
let dialog_to_close = dialog.clone();
create.connect_clicked(move |_| {
dialog.connect_response(None, move |_, response| {
if response != "create" {
return;
}
let passphrase = match fields.value() {
Ok(passphrase) => passphrase,
Err(error) => return report_error(&handles, &error),
@@ -453,16 +366,10 @@ fn present_create(handles: Handles, state: Rc<AppState>) {
let after = Rc::clone(&state);
let handles = handles.clone();
let store = Arc::clone(&store);
let dialog = dialog_to_close.clone();
runtime::spawn(
async move { store.generate_user_key(&name, &passphrase).await },
move |result| match result {
Ok(_) => {
after.refresh_identities();
dialog.force_close();
}
// Keep the dialog open so a passphrase that does not match
// can be corrected, unlike the old alert that closed first.
Ok(_) => after.refresh_identities(),
Err(error) => report_error(&handles, &error),
},
);
@@ -490,21 +397,28 @@ fn present_import(handles: Handles, state: Rc<AppState>) {
list.append(&import_password);
fields.append_to(&list);
let (dialog, import) = form_dialog(
"Import an identity key",
if first {
let dialog = adw::AlertDialog::builder()
.heading("Import an identity key")
.body(if first {
NEW_VAULT_NOTE
} else {
"The imported key is re-encrypted under your vault passphrase."
},
&list,
"Import",
);
})
.extra_child(&list)
.build();
plain::dialog(&dialog);
dialog.add_response("cancel", "Cancel");
dialog.add_response("import", "Import");
dialog.set_default_response(Some("import"));
dialog.set_response_appearance("import", adw::ResponseAppearance::Suggested);
dialog.set_close_response("cancel");
{
let (handles, state) = (handles.clone(), Rc::clone(&state));
let dialog_to_close = dialog.clone();
import.connect_clicked(move |_| {
dialog.connect_response(None, move |_, response| {
if response != "import" {
return;
}
let passphrase = match fields.value() {
Ok(passphrase) => passphrase,
Err(error) => return report_error(&handles, &error),
@@ -515,7 +429,6 @@ fn present_import(handles: Handles, state: Rc<AppState>) {
let after = Rc::clone(&state);
let handles = handles.clone();
let store = Arc::clone(&store);
let dialog = dialog_to_close.clone();
runtime::spawn(
async move {
if text.starts_with("ncryptsec1") {
@@ -527,11 +440,7 @@ fn present_import(handles: Handles, state: Rc<AppState>) {
}
},
move |result| match result {
Ok(_) => {
after.refresh_identities();
dialog.force_close();
}
// Keep the dialog open so the input can be corrected.
Ok(_) => after.refresh_identities(),
Err(error) => report_error(&handles, &error),
},
);