From f7461080c7e9ece34928850b6c9ce99abc808b97 Mon Sep 17 00:00:00 2001 From: Clement Lefebvre Date: Tue, 17 Jan 2023 14:41:25 +0000 Subject: entry: Support the ability to reveal the password. This adds the following features: - Clicking the entry shows a reveal button - Pressing Left or Right shows the button - Clicking the button toggles the visibility of the password - Pressing Alt+F8 shows the button and toggles the visibility Ported from Slick Greeter by Mike Gabriel. https://github.com/linuxmint/slick-greeter/commit/2e8797c80a2d8febf8f89bf38e1040ccbf8be4e0 --- src/prompt-box.vala | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/prompt-box.vala') diff --git a/src/prompt-box.vala b/src/prompt-box.vala index 273c507..a5d44bb 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -629,6 +629,30 @@ public class PromptBox : FadableBox { entry.visibility = false; entry.caps_lock_warning = true; + entry.button_release_event.connect ((widget, event) => { + if (event.button == 1) + show_toggle_visibility_icon (entry); + return false; + }); + entry.key_press_event.connect ((widget, event) => { + switch (event.keyval) { + case Gdk.Key.Left: + case Gdk.Key.KP_Left: + case Gdk.Key.Right: + case Gdk.Key.KP_Right: + show_toggle_visibility_icon (entry); + return false; + case Gdk.Key.F8: + if (Gdk.ModifierType.MOD1_MASK in event.state) { + entry.set_visibility (!entry.get_visibility ()); + show_toggle_visibility_icon (entry); + return true; + } + break; + } + return base.key_press_event (event); + }); + entry.icon_press.connect(entry_icon_press_cb); } entry.respond.connect (entry_activate_cb); @@ -638,6 +662,22 @@ public class PromptBox : FadableBox return entry; } + public void show_toggle_visibility_icon (Gtk.Entry entry) + { + if (entry.get_visibility ()) { + entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, "view-conceal-symbolic"); + } + else { + entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, "view-reveal-symbolic"); + } + } + + public void entry_icon_press_cb (Gtk.Entry entry, Gtk.EntryIconPosition position, Gdk.Event event) + { + entry.set_visibility (!entry.get_visibility ()); + show_toggle_visibility_icon (entry); + } + public Gtk.ComboBox add_combo (GenericArray texts, bool read_only) { Gtk.ComboBoxText combo; -- cgit v1.2.3