Show only the key's name and drop the selection highlight

The approval dialog's "Signing as" field showed the key's name over its npub.
The npub is long and rarely read, so it now rides along as the name's tooltip;
the identities window still offers "Copy public key".

The values were rendered with selectable labels, and a selectable GtkLabel
selects its whole text the moment it takes focus — and a dialog focuses its
first focusable widget on open. So the first value (the identity name) opened
with a selection highlight behind it, drawn grey because focus had already
moved on to a response button. Make plain::label non-selectable: the values are
for reading. Measured under Broadway, the first selectable label reported
selection=(True,0,5); a non-selectable one reports none.

plain::label is used only by the approval dialog and the content preview, so
nothing else changes. The AGENTS.md convention note is updated with it.
This commit is contained in:
raucao committed 2026-11-26 17:24:18 +04:00
1 parent 6077a1fbc9
commit a8bbee1eb5
3 files changed
+31 -40

No files matched your search

+14 -11
View File
@@ -507,12 +507,16 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
an identity key must open the vault first, so the activity log never claims a
`silent` or `allowed` answer for a request that was refused.
- Event content and client-supplied metadata are attacker-controlled text. Show
them only as **plain, selectable labels** (`use_markup(false)`), never as Pango
markup — a client must not be able to forge formatting that looks like Regent's
own UI. The approval dialog deliberately has **no default response**, so Enter
cannot approve; Escape (and the timeout) deny. The *passphrase* dialogs are the
one exception: they carry a default response because the user is typing the
secret themselves, and an empty submit simply fails and asks again.
them only as **plain labels** (`use_markup(false)`), never as Pango markup — a
client must not be able to forge formatting that looks like Regent's own UI.
They are deliberately **not** `selectable`: a selectable `GtkLabel` selects its
whole text the moment it takes focus, and a dialog focuses its first focusable
widget on open, so the first value would open with a selection highlight behind
it (grey, once focus has moved on). The approval dialog deliberately has **no
default response**, so Enter cannot approve; Escape (and the timeout) deny. The
*passphrase* dialogs are the one exception: they carry a default response
because the user is typing the secret themselves, and an empty submit simply
fails and asks again.
- Set `wrap_mode(gtk::pango::WrapMode::WordChar)` on labels that show client
text. The default `Word` mode will not break a long token (an `npub`, a URL),
so the label's **minimum** width becomes the whole token and the dialog grows
@@ -546,8 +550,7 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
`bunker://…&secret=…` connection string shows nothing) and lets a client
inject formatting. Build them through `crate::ui::plain`
(`plain::row`, `plain::expander`, `plain::dialog`), which
turns markup off; put untrusted text in an `extra-child` of plain, selectable
labels. **Order matters:** a builder that sets `title`/`subtitle` before
turns markup off; put untrusted text in an `extra-child` of plain labels. **Order matters:** a builder that sets `title`/`subtitle` before
`use_markup(false)` parses them as markup while it is still on, so an `&`
warns even though `use_markup(false)` follows — set markup off first, then the
text (`plain` does this). Symptom: a row renders empty and GTK logs "Failed to
@@ -605,9 +608,9 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
at the *unwrapped* width (trap 15), so a long token must stay on one line.
14. A shortened subtitle hides the full value, so carry it as a plain
`tooltip_text` (never `tooltip_markup` — it is still attacker-supplied text
for a client key). The approval dialog's "Signing as" npub is a plain
`GtkLabel`, deliberately **not** `selectable`: a shortened label would only
copy the cut. The identities window still offers "Copy public key".
for a client key). The approval dialog's "Signing as" shows only the key's
name, with the full npub as its tooltip (a signing key always has a name).
The identities window still offers "Copy public key".
`AdwExpanderRow` is not an `AdwActionRow`, but that no longer matters: its
byline is shortened like any other subtitle instead of reaching into the
label to change its ellipsis mode.
+11 -27
View File
@@ -542,43 +542,27 @@ fn more_details(question: &Question) -> gtk::ListBox {
list
}
/// The identity a request would act as: the name on the "Signing as" line, and
/// the npub beneath it. The name is what the user recognises, so it leads; when
/// there is none only the npub is shown.
/// The identity a request would act as: the key's name, with its npub as a
/// tooltip. The name is what the user recognises; the npub is long and rarely
/// read, so it stays out of the way (the identities window still offers
/// "Copy public key").
fn identity_field(identity: &crate::signer::approval::SigningKey) -> gtk::Box {
let npub = identity
.public_key
.to_bech32()
.unwrap_or_else(|_| identity.public_key.to_hex());
let value = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.spacing(2)
.build();
let name = identity
.name
.as_deref()
.map(str::trim)
.filter(|name| !name.is_empty());
// The npub is a long token: cut to `head…tail` on one line. Not Pango's
// middle ellipsis, which pads the `…` to fill the width and would widen the
// dialog. The label is **not** selectable — a shortened label would only
// copy the cut — so the full npub is the tooltip; the identities window
// still offers "Copy public key".
let npub_label = gtk::Label::builder()
.label(plain::shorten_npub(&npub))
.use_markup(false)
.xalign(0.0)
.halign(gtk::Align::Start)
.ellipsize(gtk::pango::EllipsizeMode::End)
.build();
npub_label.set_tooltip_text(Some(&npub));
match name {
Some(name) => {
value.append(&plain::label(name));
value.append(&npub_label);
}
None => value.append(&npub_label),
}
// A signing key always has a name; the shortened npub is only a fallback
// for a key that somehow does not.
let value = match name {
Some(name) => plain::label(name),
None => plain::label(&plain::shorten_npub(&npub)),
};
value.set_tooltip_text(Some(&npub));
plain::field("Signing as", &value)
}
+6 -2
View File
@@ -52,7 +52,7 @@ pub fn row(title: &str, subtitle: &str) -> adw::ActionRow {
row
}
/// A plain, selectable, word-char-wrapped label.
/// A plain, word-char-wrapped label.
///
/// `WordChar` wrapping matters: the values include long tokens with no spaces
/// (an `npub`, a URL, a JSON key). With the default `Word` mode a long token
@@ -61,6 +61,11 @@ pub fn row(title: &str, subtitle: &str) -> adw::ActionRow {
/// gets clipped. The full value stays reachable as a plain tooltip where the
/// caller sets one.
///
/// Deliberately **not** selectable. A selectable `GtkLabel` selects its whole
/// text the moment it takes focus, and a dialog focuses its first focusable
/// widget on open — so the first value would open with a selection highlight
/// behind it (grey, because focus has already moved to a response button).
///
/// The label **fills** its allocation (no `halign(Start)`): a start-aligned
/// label is sized to its natural width, so wrapped lines stop early instead of
/// spanning the dialog. `max_width_chars` still caps the natural width, so the
@@ -69,7 +74,6 @@ pub fn label(text: &str) -> gtk::Label {
gtk::Label::builder()
.label(text)
.use_markup(false)
.selectable(true)
.wrap(true)
.wrap_mode(gtk::pango::WrapMode::WordChar)
.xalign(0.0)