@@ -93,6 +93,14 @@ static void window_pwcheck(GtkWidget *widget, gpointer data) {
93
93
g_thread_new (NULL , window_pwwait , ctx );
94
94
}
95
95
96
+ static void toggle_pw_visibility (GtkEntry * entry , GtkEntryIconPosition icon_pos ) {
97
+ if (icon_pos != GTK_ENTRY_ICON_SECONDARY ) return ;
98
+ gboolean state = !gtk_entry_get_visibility (entry );
99
+ char * icon = state ? "view-conceal-symbolic" : "view-reveal-symbolic" ;
100
+ gtk_entry_set_icon_from_icon_name (entry , GTK_ENTRY_ICON_SECONDARY , icon );
101
+ gtk_entry_set_visibility (entry , state );
102
+ }
103
+
96
104
static void window_setup_input (struct Window * ctx ) {
97
105
if (ctx -> input_box != NULL ) {
98
106
gtk_widget_destroy (ctx -> input_box );
@@ -112,6 +120,10 @@ static void window_setup_input(struct Window *ctx) {
112
120
ctx -> input_field = gtk_entry_new ();
113
121
gtk_entry_set_input_purpose ((GtkEntry * )ctx -> input_field , GTK_INPUT_PURPOSE_PASSWORD );
114
122
gtk_entry_set_visibility ((GtkEntry * )ctx -> input_field , FALSE);
123
+ gtk_entry_set_icon_from_icon_name ((GtkEntry * )ctx -> input_field ,
124
+ GTK_ENTRY_ICON_SECONDARY ,
125
+ "view-reveal-symbolic" );
126
+ g_signal_connect (ctx -> input_field , "icon-release" , G_CALLBACK (toggle_pw_visibility ), NULL );
115
127
g_signal_connect (ctx -> input_field , "activate" , G_CALLBACK (window_pwcheck ), ctx );
116
128
gtk_widget_set_size_request (ctx -> input_field , 384 , -1 );
117
129
gtk_widget_set_halign (ctx -> input_field , GTK_ALIGN_END );
0 commit comments