diff options
author | Damien Miller <djm@mindrot.org> | 2016-11-25 14:03:53 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2016-12-06 18:43:37 +1100 |
commit | 7be85ae02b9de0993ce0a1d1e978e11329f6e763 (patch) | |
tree | 7a02be83370a67d5b07e05185a2fddbc2fd08965 | |
parent | b9844a45c7f0162fd1b5465683879793d4cc4aaa (diff) |
Make gnome-ssh-askpass2.c GTK+3-friendly
Patch from Colin Watson via bz#2640
-rw-r--r-- | contrib/gnome-ssh-askpass2.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/contrib/gnome-ssh-askpass2.c b/contrib/gnome-ssh-askpass2.c index 9d97c30c0..535a69274 100644 --- a/contrib/gnome-ssh-askpass2.c +++ b/contrib/gnome-ssh-askpass2.c | |||
@@ -57,19 +57,17 @@ | |||
57 | #include <gdk/gdkx.h> | 57 | #include <gdk/gdkx.h> |
58 | 58 | ||
59 | static void | 59 | static void |
60 | report_failed_grab (const char *what) | 60 | report_failed_grab (GtkWidget *parent_window, const char *what) |
61 | { | 61 | { |
62 | GtkWidget *err; | 62 | GtkWidget *err; |
63 | 63 | ||
64 | err = gtk_message_dialog_new(NULL, 0, | 64 | err = gtk_message_dialog_new(GTK_WINDOW(parent_window), 0, |
65 | GTK_MESSAGE_ERROR, | 65 | GTK_MESSAGE_ERROR, |
66 | GTK_BUTTONS_CLOSE, | 66 | GTK_BUTTONS_CLOSE, |
67 | "Could not grab %s. " | 67 | "Could not grab %s. " |
68 | "A malicious client may be eavesdropping " | 68 | "A malicious client may be eavesdropping " |
69 | "on your session.", what); | 69 | "on your session.", what); |
70 | gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER); | 70 | gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER); |
71 | gtk_label_set_line_wrap(GTK_LABEL((GTK_MESSAGE_DIALOG(err))->label), | ||
72 | TRUE); | ||
73 | 71 | ||
74 | gtk_dialog_run(GTK_DIALOG(err)); | 72 | gtk_dialog_run(GTK_DIALOG(err)); |
75 | 73 | ||
@@ -89,22 +87,27 @@ passphrase_dialog(char *message) | |||
89 | const char *failed; | 87 | const char *failed; |
90 | char *passphrase, *local; | 88 | char *passphrase, *local; |
91 | int result, grab_tries, grab_server, grab_pointer; | 89 | int result, grab_tries, grab_server, grab_pointer; |
92 | GtkWidget *dialog, *entry; | 90 | GtkWidget *parent_window, *dialog, *entry; |
93 | GdkGrabStatus status; | 91 | GdkGrabStatus status; |
94 | 92 | ||
95 | grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL); | 93 | grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL); |
96 | grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL); | 94 | grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL); |
97 | grab_tries = 0; | 95 | grab_tries = 0; |
98 | 96 | ||
99 | dialog = gtk_message_dialog_new(NULL, 0, | 97 | /* Create an invisible parent window so that GtkDialog doesn't |
98 | * complain. */ | ||
99 | parent_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
100 | |||
101 | dialog = gtk_message_dialog_new(GTK_WINDOW(parent_window), 0, | ||
100 | GTK_MESSAGE_QUESTION, | 102 | GTK_MESSAGE_QUESTION, |
101 | GTK_BUTTONS_OK_CANCEL, | 103 | GTK_BUTTONS_OK_CANCEL, |
102 | "%s", | 104 | "%s", |
103 | message); | 105 | message); |
104 | 106 | ||
105 | entry = gtk_entry_new(); | 107 | entry = gtk_entry_new(); |
106 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, | 108 | gtk_box_pack_start( |
107 | FALSE, 0); | 109 | GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry, |
110 | FALSE, FALSE, 0); | ||
108 | gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); | 111 | gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); |
109 | gtk_widget_grab_focus(entry); | 112 | gtk_widget_grab_focus(entry); |
110 | gtk_widget_show(entry); | 113 | gtk_widget_show(entry); |
@@ -112,8 +115,6 @@ passphrase_dialog(char *message) | |||
112 | gtk_window_set_title(GTK_WINDOW(dialog), "OpenSSH"); | 115 | gtk_window_set_title(GTK_WINDOW(dialog), "OpenSSH"); |
113 | gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | 116 | gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); |
114 | gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); | 117 | gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); |
115 | gtk_label_set_line_wrap(GTK_LABEL((GTK_MESSAGE_DIALOG(dialog))->label), | ||
116 | TRUE); | ||
117 | 118 | ||
118 | /* Make <enter> close dialog */ | 119 | /* Make <enter> close dialog */ |
119 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); | 120 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); |
@@ -127,8 +128,8 @@ passphrase_dialog(char *message) | |||
127 | if (grab_pointer) { | 128 | if (grab_pointer) { |
128 | for(;;) { | 129 | for(;;) { |
129 | status = gdk_pointer_grab( | 130 | status = gdk_pointer_grab( |
130 | (GTK_WIDGET(dialog))->window, TRUE, 0, NULL, | 131 | (gtk_widget_get_window(GTK_WIDGET(dialog))), TRUE, |
131 | NULL, GDK_CURRENT_TIME); | 132 | 0, NULL, NULL, GDK_CURRENT_TIME); |
132 | if (status == GDK_GRAB_SUCCESS) | 133 | if (status == GDK_GRAB_SUCCESS) |
133 | break; | 134 | break; |
134 | usleep(GRAB_WAIT * 1000); | 135 | usleep(GRAB_WAIT * 1000); |
@@ -139,8 +140,9 @@ passphrase_dialog(char *message) | |||
139 | } | 140 | } |
140 | } | 141 | } |
141 | for(;;) { | 142 | for(;;) { |
142 | status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window, | 143 | status = gdk_keyboard_grab( |
143 | FALSE, GDK_CURRENT_TIME); | 144 | gtk_widget_get_window(GTK_WIDGET(dialog)), FALSE, |
145 | GDK_CURRENT_TIME); | ||
144 | if (status == GDK_GRAB_SUCCESS) | 146 | if (status == GDK_GRAB_SUCCESS) |
145 | break; | 147 | break; |
146 | usleep(GRAB_WAIT * 1000); | 148 | usleep(GRAB_WAIT * 1000); |
@@ -157,7 +159,7 @@ passphrase_dialog(char *message) | |||
157 | 159 | ||
158 | /* Ungrab */ | 160 | /* Ungrab */ |
159 | if (grab_server) | 161 | if (grab_server) |
160 | XUngrabServer(GDK_DISPLAY()); | 162 | XUngrabServer(gdk_x11_get_default_xdisplay()); |
161 | if (grab_pointer) | 163 | if (grab_pointer) |
162 | gdk_pointer_ungrab(GDK_CURRENT_TIME); | 164 | gdk_pointer_ungrab(GDK_CURRENT_TIME); |
163 | gdk_keyboard_ungrab(GDK_CURRENT_TIME); | 165 | gdk_keyboard_ungrab(GDK_CURRENT_TIME); |
@@ -193,10 +195,10 @@ passphrase_dialog(char *message) | |||
193 | gdk_pointer_ungrab(GDK_CURRENT_TIME); | 195 | gdk_pointer_ungrab(GDK_CURRENT_TIME); |
194 | nograb: | 196 | nograb: |
195 | if (grab_server) | 197 | if (grab_server) |
196 | XUngrabServer(GDK_DISPLAY()); | 198 | XUngrabServer(gdk_x11_get_default_xdisplay()); |
197 | gtk_widget_destroy(dialog); | 199 | gtk_widget_destroy(dialog); |
198 | 200 | ||
199 | report_failed_grab(failed); | 201 | report_failed_grab(parent_window, failed); |
200 | 202 | ||
201 | return (-1); | 203 | return (-1); |
202 | } | 204 | } |