[PATCH pinentry 2/4] gtk: Disable echoing if backspace is pressed first.

Damien Goutte-Gattat dgouttegattat at incenp.org
Sat Aug 4 23:24:09 CEST 2018


* gtk+-2/pinentry-gtk-2.c (backspace_handler): New callback.
(create_window): Attach previous callback to "backspace" signal.

GnuPG-bug-id: 3428
Signed-off-by: Damien Goutte-Gattat <dgouttegattat at incenp.org>
---
 gtk+-2/pinentry-gtk-2.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
index c803628..1e07fdc 100644
--- a/gtk+-2/pinentry-gtk-2.c
+++ b/gtk+-2/pinentry-gtk-2.c
@@ -419,6 +419,22 @@ changed_text_handler (GtkWidget *widget)
 }
 
 
+/* Called upon a press on Backspace in the entry widget.
+   Used to completely disable echoing if we got no prior input. */
+static void
+backspace_handler (GtkWidget *widget, gpointer data)
+{
+  (void)data;
+
+  if (!got_input)
+    {
+      gtk_entry_set_invisible_char (GTK_ENTRY (entry), 0);
+      if (repeat_entry)
+	gtk_entry_set_invisible_char (GTK_ENTRY (repeat_entry), 0);
+    }
+}
+
+
 #ifdef HAVE_LIBSECRET
 static void
 may_save_passphrase_toggled (GtkWidget *widget, gpointer data)
@@ -713,6 +729,8 @@ create_window (pinentry_t ctx)
       gtk_widget_set_size_request (entry, 200, -1);
       g_signal_connect (G_OBJECT (entry), "changed",
                         G_CALLBACK (changed_text_handler), entry);
+      g_signal_connect (G_OBJECT (entry), "backspace",
+                        G_CALLBACK (backspace_handler), entry);
       hbox = gtk_hbox_new (FALSE, HIG_TINY);
       gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
       /* There was a wish in issue #2139 that this button should not
-- 
2.14.4


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20180804/836cbeea/attachment.sig>


More information about the Gnupg-devel mailing list