Subject: Re: bug#21415: 25.0.50; Emacs Trunk -- pixelwise width/height for x-create-frame

From: Anders Lindgren <[email-masked]>
Date: Thu, 29 Oct 2015 23:53:45 +0100

Hi,

> I will take a look at fringe-related problems next.
>
> That inversion effect is pretty distracting, indeed.

I have attached a fix for the fringe issue. The images were reversed, the
background was not transparent (which the rendering code assumed it was),
and finally, all images were mirror flipped left-to-right...

I have attached a patch for this, please try it out. If possible, try to
check if this causes some other image-related problems which I haven't
thought of.

(I will clean up the trace code before I commit it.)

> I might be able to take
> > a look at this after that.
> >
> >
> > I just pushed the toolbar fix and the startup crash fix.
>
> Fine.  Keith, can you test it?  Just turn off/on the tool bar once with
> a normal and a maximized frame.
>
> Eventually it would be to nice to have adding/removing the tool bar obey
> ‘frame-inhibit-implied-resize’ (it currently works OK for the maximized
> frame so the fix shouldn't be too hard).
>

I don't think it really worked for fullheight frames. When enabling the
tool bar in a maximized frame it looked OK at first glance. However, below
the screen, the window stretched out about three text lines, but due to the
bug Keith reported, the text grid was restricted with the same amount. The
effect was that it only looked like it worked.

Now, when enabling tool-bar mode in a fullheight frames, after Keiths bug
was fixed, the frame stretches below the screen. It's a bit unfortunate,
but it will be a lot of work to do anything about it -- given how the tool
bar is currently implemented.

Keith wrote:

> The first time I turned off the toolbar from a maximized frame, the frame
shrunk a little.  When I turned the toolbar back on again, the frame did
not return to a maximized position -- i.e., it remained a few pixels shy of
full-screen in terms of height.

I can see the same effect here. I have only tried this with a fullheight
frame, in which case it worked. I will take a look at it and try to figure
out what the difference between the fullheight and maximized cases.

    -- Anders

Ps. I will be away over the weekend -- hopefully I will be able to answer
mail but not do any Emacs core work.
diff --git a/src/nsimage.m b/src/nsimage.m
index e76a7db..a2e0618 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -206,6 +206,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
            fg: (unsigned long)fg bg: (unsigned long)bg
 {
   unsigned char *planes[5];
+  unsigned char bg_alpha = 0xff;
 
   [self initWithSize: NSMakeSize (w, h)];
 
@@ -219,7 +220,10 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
   [bmRep getBitmapDataPlanes: planes];
 
   if (fg == 0 && bg == 0)
-    bg = 0xffffff;
+    {
+      bg = 0xffffff;
+      bg_alpha = 0;
+    }
 
   {
     /* pull bits out to set the (bytewise) alpha mask */
@@ -244,21 +248,22 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
           c = *s++;
           for (k = 0; i < w && k < 8; ++k, ++i)
             {
-              *alpha++ = 0xff;
-              if (c & 1)
+              if (c & 0x80)
                 {
                   *rr++ = fgr;
                   *gg++ = fgg;
                   *bb++ = fgb;
+                  *alpha++ = 0xff;
                 }
               else
                 {
                   *rr++ = bgr;
                   *gg++ = bgg;
                   *bb++ = bgb;
+                  *alpha++ = bg_alpha;
                 }
               idx++;
-              c >>= 1;
+              c <<= 1;
             }
         }
   }
diff --git a/src/nsterm.h b/src/nsterm.h
index 3fb8cfc..2e3076d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2461,6 +2461,10 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
   static EmacsImage **bimgs = NULL;
   static int nBimgs = 0;
 
+  // NSTRACE ("ns_draw_fringe_bitmap");
+  // NSTRACE_MSG ("which:%d cursor:%d overlay:%d",
+  //              p->which, p->cursor_p, p->overlay_p);
+
   /* grow bimgs if needed */
   if (nBimgs < max_used_fringe_bitmap)
     {
@@ -2499,13 +2503,15 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
           unsigned char *cbits = xmalloc (len);
 
           for (i = 0; i < len; i++)
-            cbits[i] = ~(bits[i] & 0xff);
+            cbits[i] = bits[i];
           img = [[EmacsImage alloc] initFromXBM: cbits width: 8 height: p->h
                                              fg: 0 bg: 0];
           bimgs[p->which - 1] = img;
           xfree (cbits);
         }
 
+      // NSTRACE_RECT ("r", r);
+
       NSRectClip (r);
       /* Since we composite the bitmap instead of just blitting it, we need
          to erase the whole background. */