emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 4b0e1c6502 1/2: Handle color allocation failures caused by colorm


From: Po Lu
Subject: master 4b0e1c6502 1/2: Handle color allocation failures caused by colormap changes
Date: Mon, 7 Mar 2022 08:11:05 -0500 (EST)

branch: master
commit 4b0e1c6502534298465675a32ff65653c12df17d
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Handle color allocation failures caused by colormap changes
    
    * src/xterm.c (x_alloc_nearest_color_1): Recompute color cells
    if allocation of cached value failed.
---
 src/xterm.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/xterm.c b/src/xterm.c
index d3e3ed3a06..30229c45a4 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3857,6 +3857,10 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, 
XColor *color)
       long nearest_delta, trial_delta;
       int x;
       Status status;
+      bool retry = false;
+      int ncolor_cells, i;
+
+    start:
 
       cells = x_color_cells (dpy, &no_cells);
 
@@ -3887,6 +3891,30 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, 
XColor *color)
       color->blue = cells[nearest].blue;
       status = XAllocColor (dpy, cmap, color);
 
+      if (status != 0 && !retry)
+       {
+         /* Our private cache of color cells is probably out of date.
+            Refresh it here, and try to allocate the nearest color
+            from the new colormap.  */
+
+         retry = true;
+         xfree (dpyinfo->color_cells);
+
+         ncolor_cells = XDisplayCells (dpy, XScreenNumberOfScreen 
(dpyinfo->screen));
+
+         dpyinfo->color_cells = xnmalloc (ncolor_cells,
+                                          sizeof *dpyinfo->color_cells);
+         dpyinfo->ncolor_cells = ncolor_cells;
+
+         for (i = 0; i < ncolor_cells; ++i)
+           dpyinfo->color_cells[i].pixel = i;
+
+         XQueryColors (dpy, dpyinfo->cmap,
+                       dpyinfo->color_cells, ncolor_cells);
+
+         goto start;
+       }
+
       rc = status != 0;
     }
   else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]