]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Switch to gdk_rgba_parse() for GDK 3.
authorSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 12:37:30 +0000 (13:37 +0100)
committerSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 12:37:30 +0000 (13:37 +0100)
I'm using a slightly more up-to-date GTK version for testing on MacOS,
and it's marked a few more functions as deprecated, among which is
gdk_color_parse(). So now parsing -fg and -bg options has to be done
by two different calls and an ugly #ifdef, depending on GTK version.

unix/gtkwin.c

index 3c0ac10dd65c508030b0ed43c013180af797196b..89b2787a45c8b5778c41486ed320655775b4ad23 100644 (file)
@@ -3362,27 +3362,47 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
        } else if (!strcmp(p, "-fg") || !strcmp(p, "-bg") ||
                   !strcmp(p, "-bfg") || !strcmp(p, "-bbg") ||
                   !strcmp(p, "-cfg") || !strcmp(p, "-cbg")) {
-           GdkColor col;
-
            EXPECTS_ARG;
            SECOND_PASS_ONLY;
-           if (!gdk_color_parse(val, &col)) {
-               err = 1;
-               fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
-                        appname, val);
-           } else {
-               int index;
-               index = (!strcmp(p, "-fg") ? 0 :
-                        !strcmp(p, "-bg") ? 2 :
-                        !strcmp(p, "-bfg") ? 1 :
-                        !strcmp(p, "-bbg") ? 3 :
-                        !strcmp(p, "-cfg") ? 4 :
-                        !strcmp(p, "-cbg") ? 5 : -1);
-               assert(index != -1);
-               conf_set_int_int(conf, CONF_colours, index*3+0, col.red / 256);
-               conf_set_int_int(conf, CONF_colours, index*3+1,col.green/ 256);
-               conf_set_int_int(conf, CONF_colours, index*3+2, col.blue/ 256);
-           }
+
+            {
+#if GTK_CHECK_VERSION(3,0,0)
+                GdkRGBA rgba;
+                int success = gdk_rgba_parse(&rgba, val);
+#else
+                GdkColor col;
+                int success = gdk_color_parse(val, &col);
+#endif
+
+                if (!success) {
+                    err = 1;
+                    fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
+                            appname, val);
+                } else {
+#if GTK_CHECK_VERSION(3,0,0)
+                    int r = rgba.red * 255;
+                    int g = rgba.green * 255;
+                    int b = rgba.blue * 255;
+#else
+                    int r = col.red / 256;
+                    int g = col.green / 256;
+                    int b = col.blue / 256;
+#endif
+
+                    int index;
+                    index = (!strcmp(p, "-fg") ? 0 :
+                             !strcmp(p, "-bg") ? 2 :
+                             !strcmp(p, "-bfg") ? 1 :
+                             !strcmp(p, "-bbg") ? 3 :
+                             !strcmp(p, "-cfg") ? 4 :
+                             !strcmp(p, "-cbg") ? 5 : -1);
+                    assert(index != -1);
+
+                    conf_set_int_int(conf, CONF_colours, index*3+0, r);
+                    conf_set_int_int(conf, CONF_colours, index*3+1, g);
+                    conf_set_int_int(conf, CONF_colours, index*3+2, b);
+                }
+            }
 
        } else if (use_pty_argv && !strcmp(p, "-e")) {
            /* This option swallows all further arguments. */