Skip to content

Commit e1c8fb8

Browse files
committed
Fix password visibility changing between monitors
1 parent 71a816e commit e1c8fb8

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

window.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,32 @@ static gboolean window_pwerror(gpointer data) {
7777
return G_SOURCE_REMOVE;
7878
}
7979

80-
static gpointer window_pwwait(gpointer data) {
80+
static gpointer window_pw_wait(gpointer data) {
8181
struct Window *ctx = data;
8282
gboolean ret = auth_pwcheck(gtk_entry_get_text((GtkEntry*)ctx->input_field), gtklock->auth_handle);
8383
if(ret != FALSE) g_application_quit(G_APPLICATION(gtklock->app));
8484
g_main_context_invoke(NULL, window_pwerror, ctx);
8585
return NULL;
8686
}
8787

88-
static void window_pwcheck(GtkWidget *widget, gpointer data) {
88+
static void window_pw_check(GtkWidget *widget, gpointer data) {
8989
struct Window *ctx = data;
9090
gtk_widget_set_sensitive(ctx->input_field, FALSE);
9191
gtk_widget_set_sensitive(ctx->unlock_button, FALSE);
9292
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);
9494
}
9595

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";
10098
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);
102106
}
103107

104108
static void window_setup_input(struct Window *ctx) {
@@ -119,12 +123,9 @@ static void window_setup_input(struct Window *ctx) {
119123

120124
ctx->input_field = gtk_entry_new();
121125
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);
128129
gtk_widget_set_size_request(ctx->input_field, 384, -1);
129130
gtk_widget_set_halign(ctx->input_field, GTK_ALIGN_END);
130131
gtk_container_add(GTK_CONTAINER(question_box), ctx->input_field);
@@ -139,7 +140,7 @@ static void window_setup_input(struct Window *ctx) {
139140

140141
ctx->unlock_button = gtk_button_new_with_label("Unlock");
141142
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);
143144
gtk_style_context_add_class(unlock_button_style, "suggested-action");
144145
gtk_widget_set_halign(ctx->unlock_button, GTK_ALIGN_END);
145146
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) {
223224
// Update new cursor position
224225
g_signal_emit_by_name((GtkEntry*)win->input_field, "move-cursor", GTK_MOVEMENT_BUFFER_ENDS, -1, FALSE);
225226
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));
226230
}
227231
window_setup(old);
228232
gtk_widget_show_all(old->window);

0 commit comments

Comments
 (0)