summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2020-09-18 14:55:48 +1000
committerDamien Miller <djm@mindrot.org>2020-09-18 14:55:48 +1000
commitf93b187ab900c7d12875952cc63350fe4de8a0a8 (patch)
tree943a08938fa7d640beaa2254b01b7b7513bd6d9e
parent9d3d36bdb10b66abd1af42e8655502487b6ba1fa (diff)
control over the colours in gnome-ssh-askpass[23]
Optionally set the textarea colours via $GNOME_SSH_ASKPASS_FG_COLOR and $GNOME_SSH_ASKPASS_BG_COLOR. These accept the usual three or six digit hex colours.
-rw-r--r--contrib/gnome-ssh-askpass2.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/contrib/gnome-ssh-askpass2.c b/contrib/gnome-ssh-askpass2.c
index 7656a776b..f7912727c 100644
--- a/contrib/gnome-ssh-askpass2.c
+++ b/contrib/gnome-ssh-askpass2.c
@@ -56,6 +56,7 @@
56#include <stdio.h> 56#include <stdio.h>
57#include <string.h> 57#include <string.h>
58#include <unistd.h> 58#include <unistd.h>
59
59#include <X11/Xlib.h> 60#include <X11/Xlib.h>
60#include <gtk/gtk.h> 61#include <gtk/gtk.h>
61#include <gdk/gdkx.h> 62#include <gdk/gdkx.h>
@@ -106,6 +107,48 @@ check_none(GtkWidget *widget, GdkEventKey *event, gpointer dialog)
106} 107}
107 108
108static int 109static int
110parse_env_hex_color(const char *env, GdkColor *c)
111{
112 const char *s;
113 unsigned long ul;
114 char *ep;
115 size_t n;
116
117 if ((s = getenv(env)) == NULL)
118 return 0;
119
120 memset(c, 0, sizeof(*c));
121
122 /* Permit hex rgb or rrggbb optionally prefixed by '#' or '0x' */
123 if (*s == '#')
124 s++;
125 else if (strncmp(s, "0x", 2) == 0)
126 s += 2;
127 n = strlen(s);
128 if (n != 3 && n != 6)
129 goto bad;
130 ul = strtoul(s, &ep, 16);
131 if (*ep != '\0' || ul > 0xffffff) {
132 bad:
133 fprintf(stderr, "Invalid $%s - invalid hex color code\n", env);
134 return 0;
135 }
136 /* Valid hex sequence; expand into a GdkColor */
137 if (n == 3) {
138 /* 4-bit RGB */
139 c->red = ((ul >> 8) & 0xf) << 12;
140 c->green = ((ul >> 4) & 0xf) << 12;
141 c->blue = (ul & 0xf) << 12;
142 } else {
143 /* 8-bit RGB */
144 c->red = ((ul >> 16) & 0xff) << 8;
145 c->green = ((ul >> 8) & 0xff) << 8;
146 c->blue = (ul & 0xff) << 8;
147 }
148 return 1;
149}
150
151static int
109passphrase_dialog(char *message, int prompt_type) 152passphrase_dialog(char *message, int prompt_type)
110{ 153{
111 const char *failed; 154 const char *failed;
@@ -114,11 +157,16 @@ passphrase_dialog(char *message, int prompt_type)
114 int buttons, default_response; 157 int buttons, default_response;
115 GtkWidget *parent_window, *dialog, *entry; 158 GtkWidget *parent_window, *dialog, *entry;
116 GdkGrabStatus status; 159 GdkGrabStatus status;
160 GdkColor fg, bg;
161 int fg_set = 0, bg_set = 0;
117 162
118 grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL); 163 grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL);
119 grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL); 164 grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL);
120 grab_tries = 0; 165 grab_tries = 0;
121 166
167 fg_set = parse_env_hex_color("GNOME_SSH_ASKPASS_FG_COLOR", &fg);
168 bg_set = parse_env_hex_color("GNOME_SSH_ASKPASS_BG_COLOR", &bg);
169
122 /* Create an invisible parent window so that GtkDialog doesn't 170 /* Create an invisible parent window so that GtkDialog doesn't
123 * complain. */ 171 * complain. */
124 parent_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 172 parent_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -147,8 +195,17 @@ passphrase_dialog(char *message, int prompt_type)
147 gtk_dialog_set_default_response(GTK_DIALOG(dialog), default_response); 195 gtk_dialog_set_default_response(GTK_DIALOG(dialog), default_response);
148 gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); 196 gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);
149 197
198 if (fg_set)
199 gtk_widget_modify_fg(dialog, GTK_STATE_NORMAL, &fg);
200 if (bg_set)
201 gtk_widget_modify_bg(dialog, GTK_STATE_NORMAL, &bg);
202
150 if (prompt_type == PROMPT_ENTRY || prompt_type == PROMPT_NONE) { 203 if (prompt_type == PROMPT_ENTRY || prompt_type == PROMPT_NONE) {
151 entry = gtk_entry_new(); 204 entry = gtk_entry_new();
205 if (fg_set)
206 gtk_widget_modify_fg(entry, GTK_STATE_NORMAL, &fg);
207 if (bg_set)
208 gtk_widget_modify_bg(entry, GTK_STATE_NORMAL, &bg);
152 gtk_box_pack_start( 209 gtk_box_pack_start(
153 GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), 210 GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
154 entry, FALSE, FALSE, 0); 211 entry, FALSE, FALSE, 0);