[gtk/peek-password-3: 1/2] Add an peek-password icon to GtkEntry



commit 1f0b1ee97359b4a03cc156c6f652651796d7bcd8
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Mar 15 19:25:35 2019 -0400

    Add an peek-password icon to GtkEntry
    
    When GtkEntry::show-peek-icon is set to TRUE, show
    an icon that lets users toggle the visibility of
    content.

 gtk/gtkentry.c                                     |  77 +++++++++++++++++++++
 .../status/eye-not-looking-symbolic.symbolic.png   | Bin 0 -> 324 bytes
 .../eye-open-negative-filled-symbolic.symbolic.png | Bin 0 -> 295 bytes
 .../scalable/status/eye-not-looking-symbolic.svg   |   3 +
 .../status/eye-open-negative-filled-symbolic.svg   |  26 +++++++
 5 files changed, 106 insertions(+)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 54a8bcd3ff..a3141a26d7 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -281,6 +281,7 @@ struct _GtkEntryPrivate
   guint         selection_handle_dragged : 1;
   guint         populate_all            : 1;
   guint         handling_key_event      : 1;
+  guint         show_peek_icon          : 1;
 };
 
 struct _EntryIconInfo
@@ -384,6 +385,7 @@ enum {
   PROP_TABS,
   PROP_SHOW_EMOJI_ICON,
   PROP_ENABLE_EMOJI_COMPLETION,
+  PROP_SHOW_PEEK_ICON,
   PROP_EDITING_CANCELED,
   NUM_PROPERTIES = PROP_EDITING_CANCELED
 };
@@ -706,6 +708,8 @@ static void         set_show_emoji_icon                (GtkEntry       *entry,
                                                         gboolean        value);
 static void         set_enable_emoji_completion        (GtkEntry       *entry,
                                                         gboolean        value);
+static void         set_show_peek_icon                 (GtkEntry       *entry,
+                                                        gboolean        value);
 
 static void     gtk_entry_measure  (GtkCssGadget        *gadget,
                                     GtkOrientation       orientation,
@@ -1546,6 +1550,13 @@ gtk_entry_class_init (GtkEntryClass *class)
                             FALSE,
                             GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
+  entry_props[PROP_SHOW_PEEK_ICON] =
+      g_param_spec_boolean ("show-peek-icon",
+                            P_("Peek icon"),
+                            P_("Whether to show an icon to reveal the content"),
+                            FALSE,
+                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, entry_props);
 
   /**
@@ -2460,6 +2471,10 @@ gtk_entry_set_property (GObject         *object,
       set_enable_emoji_completion (entry, g_value_get_boolean (value));
       break;
 
+    case PROP_SHOW_PEEK_ICON:
+      set_show_peek_icon (entry, g_value_get_boolean (value));
+      break;
+
     case PROP_SCROLL_OFFSET:
     case PROP_CURSOR_POSITION:
     default:
@@ -2720,6 +2735,10 @@ gtk_entry_get_property (GObject         *object,
       g_value_set_boolean (value, priv->enable_emoji_completion);
       break;
 
+    case PROP_SHOW_PEEK_ICON:
+      g_value_set_boolean (value, priv->show_peek_icon);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -11182,3 +11201,61 @@ set_enable_emoji_completion (GtkEntry *entry,
 
   g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_ENABLE_EMOJI_COMPLETION]);
 }
+
+static void
+toggle_peek (GtkEntry *entry,
+             int       icon,
+             GdkEvent *event,
+             gpointer  data)
+{
+  if (icon == GTK_ENTRY_ICON_SECONDARY)
+    {
+      if (gtk_entry_get_visibility (entry))
+        {
+          gtk_entry_set_visibility (entry, FALSE);
+
+          gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, "eye-not-looking-symbolic");
+          gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, _("Show text"));
+        }
+      else
+        {
+          gtk_entry_set_visibility (entry, TRUE);
+
+          gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, 
"eye-open-negative-filled-symbolic");
+          gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, _("Hide text"));
+        }
+    }
+}
+
+static void
+set_show_peek_icon (GtkEntry *entry,
+                    gboolean  value)
+{
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->show_peek_icon == value)
+    return;
+
+  priv->show_peek_icon = value;
+
+  if (priv->show_peek_icon)
+    {
+      gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, "eye-not-looking-symbolic");
+      gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, _("Show text"));
+      gtk_entry_set_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY, TRUE);
+      gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, TRUE);
+
+      g_signal_connect (entry, "icon-press", G_CALLBACK (toggle_peek), NULL);
+    }
+  else
+    {
+      g_signal_handlers_disconnect_by_func (entry, toggle_peek, NULL);
+
+      gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
+      gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
+    }
+
+  g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_SHOW_PEEK_ICON]);
+  gtk_widget_queue_resize (GTK_WIDGET (entry));
+}
+
diff --git a/gtk/icons/16x16/status/eye-not-looking-symbolic.symbolic.png 
b/gtk/icons/16x16/status/eye-not-looking-symbolic.symbolic.png
new file mode 100644
index 0000000000..3773d3cc30
Binary files /dev/null and b/gtk/icons/16x16/status/eye-not-looking-symbolic.symbolic.png differ
diff --git a/gtk/icons/16x16/status/eye-open-negative-filled-symbolic.symbolic.png 
b/gtk/icons/16x16/status/eye-open-negative-filled-symbolic.symbolic.png
new file mode 100644
index 0000000000..b642dd7566
Binary files /dev/null and b/gtk/icons/16x16/status/eye-open-negative-filled-symbolic.symbolic.png differ
diff --git a/gtk/icons/scalable/status/eye-not-looking-symbolic.svg 
b/gtk/icons/scalable/status/eye-not-looking-symbolic.svg
new file mode 100644
index 0000000000..792a22ad8a
--- /dev/null
+++ b/gtk/icons/scalable/status/eye-not-looking-symbolic.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg"; width="16" height="16">
+    <path d="M13.98 1.99a1 1 0 0 0-.687.303l-.984.984A8 8 0 0 0 8 2 8 8 0 0 0 .262 8.01a8 8 0 0 0 2.943 
4.37l-.912.913a1 1 0 1 0 1.414 1.414l11-11a1 1 0 0 0-.727-1.717zM8 4a4 4 0 0 1 2.611.974l-1.42 1.42A2 2 0 0 0 
8 6a2 2 0 0 0-2 2 2 2 0 0 0 .396 1.19l-1.42 1.42A4 4 0 0 1 4 8a4 4 0 0 1 4-4zm7.03 2.209l-3.344 3.343a4 4 0 0 
1-2.127 2.127l-2.28 2.28a8 8 0 0 0 .721.04 8 8 0 0 0 7.738-6.01 8 8 0 0 0-.709-1.78zm-7.53.79a.5.5 0 0 1 
.5.5.5.5 0 0 1-.5.5.5.5 0 0 1-.5-.5.5.5 0 0 1 .5-.5z" fill="#2e3436"/>
+</svg>
\ No newline at end of file
diff --git a/gtk/icons/scalable/status/eye-open-negative-filled-symbolic.svg 
b/gtk/icons/scalable/status/eye-open-negative-filled-symbolic.svg
new file mode 100644
index 0000000000..f4e133a928
--- /dev/null
+++ b/gtk/icons/scalable/status/eye-open-negative-filled-symbolic.svg
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"; xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:cc="http://creativecommons.org/ns#"; xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 
xmlns:svg="http://www.w3.org/2000/svg"; xmlns="http://www.w3.org/2000/svg"; width="16" viewBox="0 0 16 16" 
version="1.1" id="svg7384" height="16">
+  <metadata id="metadata90">
+    <rdf:RDF>
+      <cc:Work rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+        <dc:title>Gnome Symbolic Icon Theme</dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <title id="title9167">Gnome Symbolic Icon Theme</title>
+  <defs id="defs7386">
+    <linearGradient osb:paint="solid" id="linearGradient7212">
+      <stop style="stop-color:#000000;stop-opacity:1;" offset="0" id="stop7214"/>
+    </linearGradient>
+  </defs>
+  <g transform="translate(-341.0002,-13.000323)" style="display:inline" id="layer9"/>
+  <g transform="translate(-100,-380.00032)" id="layer1"/>
+  <g transform="translate(-100,-380.00032)" style="display:inline" id="layer10">
+    <path d="m 108,382 a 8,8 0 0 0 -7.73828,6.00977 A 8,8 0 0 0 108,394 8,8 0 0 0 115.73828,387.99023 8,8 0 
0 0 108,382 Z m 0,2 a 4,4 0 0 1 4,4 4,4 0 0 1 -4,4 4,4 0 0 1 -4,-4 4,4 0 0 1 4,-4 z" id="path2314" 
style="opacity:1;vector-effect:none;fill:#2e3436;fill-opacity:1;stroke:none;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal"/>
+    <path id="path2318" d="m 110,388.00003 a 2,2 0 0 1 -2,2 2,2 0 0 1 -2,-2 2,2 0 0 1 2,-2 2,2 0 0 1 2,2 z" 
style="vector-effect:none;fill:#2e3436;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
+  </g>
+  <g transform="translate(-100,-380.00032)" id="g6387"/>
+  <g transform="translate(-100,-380.00032)" id="layer11"/>
+</svg>
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]