@@ -77,28 +77,32 @@ static gboolean window_pwerror(gpointer data) {
77
77
return G_SOURCE_REMOVE ;
78
78
}
79
79
80
- static gpointer window_pwwait (gpointer data ) {
80
+ static gpointer window_pw_wait (gpointer data ) {
81
81
struct Window * ctx = data ;
82
82
gboolean ret = auth_pwcheck (gtk_entry_get_text ((GtkEntry * )ctx -> input_field ), gtklock -> auth_handle );
83
83
if (ret != FALSE) g_application_quit (G_APPLICATION (gtklock -> app ));
84
84
g_main_context_invoke (NULL , window_pwerror , ctx );
85
85
return NULL ;
86
86
}
87
87
88
- static void window_pwcheck (GtkWidget * widget , gpointer data ) {
88
+ static void window_pw_check (GtkWidget * widget , gpointer data ) {
89
89
struct Window * ctx = data ;
90
90
gtk_widget_set_sensitive (ctx -> input_field , FALSE);
91
91
gtk_widget_set_sensitive (ctx -> unlock_button , FALSE);
92
92
gtk_label_set_text (GTK_LABEL (ctx -> error_label ), NULL );
93
- g_thread_new (NULL , window_pwwait , ctx );
93
+ g_thread_new (NULL , window_pw_wait , 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" ;
96
+ static void window_pw_set_vis (GtkEntry * entry , gboolean visibility ) {
97
+ const char * icon = visibility ? "view-conceal-symbolic" : "view-reveal-symbolic" ;
100
98
gtk_entry_set_icon_from_icon_name (entry , GTK_ENTRY_ICON_SECONDARY , icon );
101
- gtk_entry_set_visibility (entry , state );
99
+ gtk_entry_set_visibility (entry , visibility );
100
+ }
101
+
102
+ static void window_pw_toggle_vis (GtkEntry * entry , GtkEntryIconPosition icon_pos ) {
103
+ if (icon_pos != GTK_ENTRY_ICON_SECONDARY ) return ;
104
+ gboolean visibility = gtk_entry_get_visibility (entry );
105
+ window_pw_set_vis (entry , !visibility );
102
106
}
103
107
104
108
static void window_setup_input (struct Window * ctx ) {
@@ -119,12 +123,9 @@ static void window_setup_input(struct Window *ctx) {
119
123
120
124
ctx -> input_field = gtk_entry_new ();
121
125
gtk_entry_set_input_purpose ((GtkEntry * )ctx -> input_field , GTK_INPUT_PURPOSE_PASSWORD );
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 );
127
- g_signal_connect (ctx -> input_field , "activate" , G_CALLBACK (window_pwcheck ), ctx );
126
+ window_pw_set_vis ((GtkEntry * )ctx -> input_field , FALSE);
127
+ g_signal_connect (ctx -> input_field , "icon-release" , G_CALLBACK (window_pw_toggle_vis ), NULL );
128
+ g_signal_connect (ctx -> input_field , "activate" , G_CALLBACK (window_pw_check ), ctx );
128
129
gtk_widget_set_size_request (ctx -> input_field , 384 , -1 );
129
130
gtk_widget_set_halign (ctx -> input_field , GTK_ALIGN_END );
130
131
gtk_container_add (GTK_CONTAINER (question_box ), ctx -> input_field );
@@ -139,7 +140,7 @@ static void window_setup_input(struct Window *ctx) {
139
140
140
141
ctx -> unlock_button = gtk_button_new_with_label ("Unlock" );
141
142
GtkStyleContext * unlock_button_style = gtk_widget_get_style_context (ctx -> unlock_button );
142
- g_signal_connect (ctx -> unlock_button , "clicked" , G_CALLBACK (window_pwcheck ), ctx );
143
+ g_signal_connect (ctx -> unlock_button , "clicked" , G_CALLBACK (window_pw_check ), ctx );
143
144
gtk_style_context_add_class (unlock_button_style , "suggested-action" );
144
145
gtk_widget_set_halign (ctx -> unlock_button , GTK_ALIGN_END );
145
146
gtk_container_add (GTK_CONTAINER (button_box ), ctx -> unlock_button );
@@ -223,6 +224,9 @@ static void window_set_focus(struct Window *win, struct Window *old) {
223
224
// Update new cursor position
224
225
g_signal_emit_by_name ((GtkEntry * )win -> input_field , "move-cursor" , GTK_MOVEMENT_BUFFER_ENDS , -1 , FALSE);
225
226
g_signal_emit_by_name ((GtkEntry * )win -> input_field , "move-cursor" , GTK_MOVEMENT_LOGICAL_POSITIONS , cursor_pos , FALSE);
227
+
228
+ // Copy pw visibility
229
+ window_pw_set_vis ((GtkEntry * )win -> input_field , gtk_entry_get_visibility ((GtkEntry * )old -> input_field ));
226
230
}
227
231
window_setup (old );
228
232
gtk_widget_show_all (old -> window );
0 commit comments