File xscreensaver-glmatrix-add-red-and-amber-options-for-color.patch of Package xscreensaver

From df5b2889dcf7bf644b7565e40ea3001ed90eaee4 Mon Sep 17 00:00:00 2001
From: v-fox <virtuousfox@gmail.com>
Date: Thu, 22 Aug 2024 11:37:41 +0500
Subject: [PATCH] glmatrix: add red and amber options for color

---
 hacks/config/glmatrix.xml |  6 ++++++
 hacks/glx/glmatrix.c      | 38 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/hacks/config/glmatrix.xml b/hacks/config/glmatrix.xml
index 58f8f10..e05456e 100644
--- a/hacks/config/glmatrix.xml
+++ b/hacks/config/glmatrix.xml
@@ -27,6 +27,12 @@
     <option id="dna"    _label="Genetic encoding"     arg-set="--mode dna"/>
   </select>
 
+  <select id="color">
+    <option id="green"  _label="Canonical green color"/>
+    <option id="red"    _label="Night vision red color" arg-set="--color red"/>
+    <option id="amber"  _label="Old-timey amber color"   arg-set="--color amber"/>
+  </select>
+
   <hgroup>
    <boolean id="fog"    _label="Fog"     arg-unset="--no-fog"/>
    <boolean id="waves"  _label="Waves"   arg-unset="--no-waves"/>
diff --git a/hacks/glx/glmatrix.c b/hacks/glx/glmatrix.c
index 4087ec1..1c85a07 100644
--- a/hacks/glx/glmatrix.c
+++ b/hacks/glx/glmatrix.c
@@ -41,6 +41,7 @@
 #define DEF_ROTATE      "True"
 #define DEF_TEXTURE     "True"
 #define DEF_MODE        "Matrix"
+#define DEF_COLOR       "Green"
 #define DEF_TIMEFMT     " %l%M%p "
 
 
@@ -179,6 +180,7 @@ static Bool do_waves;
 static Bool do_rotate;
 static Bool do_texture;
 static char *mode_str;
+static char *color_str;
 
 static XrmOptionDescRec opts[] = {
   { "-speed",       ".speed",     XrmoptionSepArg, 0 },
@@ -188,6 +190,9 @@ static XrmOptionDescRec opts[] = {
   { "-hexadecimal", ".mode",      XrmoptionNoArg, "hexadecimal" },
   { "-decimal",     ".mode",      XrmoptionNoArg, "decimal"     },
   { "-dna",         ".mode",      XrmoptionNoArg, "dna"         },
+  { "-color",       ".color",     XrmoptionSepArg, 0 },
+  { "-red",         ".color",     XrmoptionNoArg, "red"   },
+  { "-amber",       ".color",     XrmoptionNoArg, "amber" },
   { "-clock",       ".clock",     XrmoptionNoArg, "True"  },
   { "+clock",       ".clock",     XrmoptionNoArg, "False" },
   { "-timefmt",     ".timefmt",   XrmoptionSepArg, 0  },
@@ -203,6 +208,7 @@ static XrmOptionDescRec opts[] = {
 
 static argtype vars[] = {
   {&mode_str,   "mode",       "Mode",    DEF_MODE,      t_String},
+  {&color_str,  "color",      "Color",   DEF_COLOR,     t_String},
   {&speed,      "speed",      "Speed",   DEF_SPEED,     t_Float},
   {&density,    "density",    "Density", DEF_DENSITY,   t_Float},
   {&do_clock,   "clock",      "Clock",   DEF_CLOCK,     t_Bool},
@@ -768,8 +774,36 @@ load_textures (ModeInfo *mi, Bool flip_p)
           unsigned char r = (p >> rpos) & 0xFF;
           unsigned char g = (p >> gpos) & 0xFF;
           unsigned char b = (p >> bpos) & 0xFF;
-          unsigned char a = g;
-          g = 0xFF;
+          unsigned char a;
+          if (!color_str || !*color_str || !strcasecmp(color_str, "g") ||
+             !strcasecmp (color_str, "green"))
+            {
+              a = g;
+              g = 0xFF;
+            }
+          else if (!strcasecmp (color_str, "r") ||
+                   !strcasecmp (color_str, "red"))
+            {
+              a = r;
+              r = 0xFF;
+              g = 0x31;
+              b = 0x31;
+            }
+          else if (!strcasecmp (color_str, "a") ||
+                   !strcasecmp (color_str, "amber"))
+            {
+              a = r;
+              r = 0xFF;
+              g = 0xBF;
+              b = 0x00;
+            }
+          else
+            {
+              fprintf (stderr,
+                   "%s: `color' must be green, red, or amber: not `%s'\n",
+                       progname, color_str);
+              exit (1);
+            }
           p = (r << rpos) | (g << gpos) | (b << bpos) | (a << apos);
           XPutPixel (xi, x, y, p);
         }
-- 
2.46.0

openSUSE Build Service is sponsored by