aboutsummaryrefslogtreecommitdiff
path: root/src/prompt-box.vala
diff options
context:
space:
mode:
authorClement Lefebvre <clement.lefebvre@linuxmint.com>2023-01-17 14:41:25 +0000
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-02-06 12:08:33 +0100
commitf7461080c7e9ece34928850b6c9ce99abc808b97 (patch)
treef799bddd5425306aa0608863f3b500a3f36f5dc0 /src/prompt-box.vala
parent3d288d37411db11a4826d6a70a26d842241af3e0 (diff)
downloadarctica-greeter-f7461080c7e9ece34928850b6c9ce99abc808b97.tar.gz
arctica-greeter-f7461080c7e9ece34928850b6c9ce99abc808b97.tar.bz2
arctica-greeter-f7461080c7e9ece34928850b6c9ce99abc808b97.zip
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
Diffstat (limited to 'src/prompt-box.vala')
-rw-r--r--src/prompt-box.vala40
1 files changed, 40 insertions, 0 deletions
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<string> texts, bool read_only)
{
Gtk.ComboBoxText combo;