unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* weird startup error in MacOS Mojave
@ 2018-09-25 13:46 Perry E. Metzger
  2018-09-25 14:26 ` Herbert J. Skuhra
  0 siblings, 1 reply; 15+ messages in thread
From: Perry E. Metzger @ 2018-09-25 13:46 UTC (permalink / raw)
  To: emacs-devel

I just upgraded my Mac to Mojave, and for the first time, starting the
GUI is spitting out this error:

2018-09-25 09:43:29.255 Emacs[1948:30669] Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver}

-- 
Perry E. Metzger		perry@piermont.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-25 13:46 weird startup error in MacOS Mojave Perry E. Metzger
@ 2018-09-25 14:26 ` Herbert J. Skuhra
  2018-09-25 22:08   ` Perry E. Metzger
  0 siblings, 1 reply; 15+ messages in thread
From: Herbert J. Skuhra @ 2018-09-25 14:26 UTC (permalink / raw)
  To: emacs-devel

On Tue, Sep 25, 2018 at 09:46:06AM -0400, Perry E. Metzger wrote:
> I just upgraded my Mac to Mojave, and for the first time, starting the
> GUI is spitting out this error:
> 
> 2018-09-25 09:43:29.255 Emacs[1948:30669] Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver}

I think you manually have to merge a few commits from branch scratch/ns-drawing
(last synced August 11th).

I still get an error on startup (not sure if it is the same one) but the
GUI is usable. Emacs is sporadically crashing.

-- 
Herbert



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-25 14:26 ` Herbert J. Skuhra
@ 2018-09-25 22:08   ` Perry E. Metzger
  2018-09-25 22:56     ` Herbert J. Skuhra
  0 siblings, 1 reply; 15+ messages in thread
From: Perry E. Metzger @ 2018-09-25 22:08 UTC (permalink / raw)
  To: Herbert J. Skuhra; +Cc: emacs-devel

On Tue, 25 Sep 2018 16:26:57 +0200 "Herbert J. Skuhra"
<herbert@gojira.at> wrote:
> On Tue, Sep 25, 2018 at 09:46:06AM -0400, Perry E. Metzger wrote:
> > I just upgraded my Mac to Mojave, and for the first time,
> > starting the GUI is spitting out this error:
> > 
> > 2018-09-25 09:43:29.255 Emacs[1948:30669] Failed to initialize
> > color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864
> > "*** -[NSKeyedUnarchiver
> > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > archive cannot be decoded by NSKeyedUnarchiver"
> > UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
> > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > archive cannot be decoded by NSKeyedUnarchiver}  
> 
> I think you manually have to merge a few commits from branch
> scratch/ns-drawing (last synced August 11th).
> 
> I still get an error on startup (not sure if it is the same one)
> but the GUI is usable. Emacs is sporadically crashing.

I'm not sure I understand what you are telling me here. Is it that if
I don't pull some unnamed patches that I'll have problems, or is it
the reverse?

-- 
Perry E. Metzger		perry@piermont.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-25 22:08   ` Perry E. Metzger
@ 2018-09-25 22:56     ` Herbert J. Skuhra
  2018-09-25 23:13       ` Perry E. Metzger
  2018-09-26 18:35       ` Alan Third
  0 siblings, 2 replies; 15+ messages in thread
From: Herbert J. Skuhra @ 2018-09-25 22:56 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

On Tue, Sep 25, 2018 at 06:08:37PM -0400, Perry E. Metzger wrote:
> On Tue, 25 Sep 2018 16:26:57 +0200 "Herbert J. Skuhra"
> <herbert@gojira.at> wrote:
> > On Tue, Sep 25, 2018 at 09:46:06AM -0400, Perry E. Metzger wrote:
> > > I just upgraded my Mac to Mojave, and for the first time,
> > > starting the GUI is spitting out this error:
> > > 
> > > 2018-09-25 09:43:29.255 Emacs[1948:30669] Failed to initialize
> > > color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864
> > > "*** -[NSKeyedUnarchiver
> > > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > > archive cannot be decoded by NSKeyedUnarchiver"
> > > UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
> > > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > > archive cannot be decoded by NSKeyedUnarchiver}  
> > 
> > I think you manually have to merge a few commits from branch
> > scratch/ns-drawing (last synced August 11th).
> > 
> > I still get an error on startup (not sure if it is the same one)
> > but the GUI is usable. Emacs is sporadically crashing.
> 
> I'm not sure I understand what you are telling me here. Is it that if
> I don't pull some unnamed patches that I'll have problems, or is it
> the reverse?

Building Emacs on MacOS 10.14 results in a non-functional GUI. 

With the following commits from scratch/ns-drawing the GUI is working
again:

http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00152.html
http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00150.html
http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00151.html

But I still see the reported error on start and Emacs sporadically
crashes. 

-- 
Herbert



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-25 22:56     ` Herbert J. Skuhra
@ 2018-09-25 23:13       ` Perry E. Metzger
  2018-09-26 18:35       ` Alan Third
  1 sibling, 0 replies; 15+ messages in thread
From: Perry E. Metzger @ 2018-09-25 23:13 UTC (permalink / raw)
  To: Herbert J. Skuhra; +Cc: emacs-devel

On Wed, 26 Sep 2018 00:56:35 +0200 "Herbert J. Skuhra"
<herbert@gojira.at> wrote:
> Building Emacs on MacOS 10.14 results in a non-functional GUI. 
> 
> With the following commits from scratch/ns-drawing the GUI is
> working again:
> 
> http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00152.html
> http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00150.html
> http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00151.html
> 
> But I still see the reported error on start and Emacs sporadically
> crashes.

Ick. Given that 10.14 has been released, fixing this is probably a
priority...

Perry
-- 
Perry E. Metzger		perry@piermont.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-25 22:56     ` Herbert J. Skuhra
  2018-09-25 23:13       ` Perry E. Metzger
@ 2018-09-26 18:35       ` Alan Third
  2018-09-26 18:42         ` Perry E. Metzger
  1 sibling, 1 reply; 15+ messages in thread
From: Alan Third @ 2018-09-26 18:35 UTC (permalink / raw)
  To: Herbert J. Skuhra; +Cc: emacs-devel, Perry E. Metzger

[-- Attachment #1: Type: text/plain, Size: 2013 bytes --]

On Wed, Sep 26, 2018 at 12:56:35AM +0200, Herbert J. Skuhra wrote:
> On Tue, Sep 25, 2018 at 06:08:37PM -0400, Perry E. Metzger wrote:
> > On Tue, 25 Sep 2018 16:26:57 +0200 "Herbert J. Skuhra"
> > <herbert@gojira.at> wrote:
> > > On Tue, Sep 25, 2018 at 09:46:06AM -0400, Perry E. Metzger wrote:
> > > > I just upgraded my Mac to Mojave, and for the first time,
> > > > starting the GUI is spitting out this error:
> > > > 
> > > > 2018-09-25 09:43:29.255 Emacs[1948:30669] Failed to initialize
> > > > color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864
> > > > "*** -[NSKeyedUnarchiver
> > > > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > > > archive cannot be decoded by NSKeyedUnarchiver"
> > > > UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
> > > > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > > > archive cannot be decoded by NSKeyedUnarchiver}  

This is nice. I don’t know what’s going on. I guess it’s maybe related
to the colour list we generate and which caused us some problems with
the high sierra beta last year.

Try deleting ’~/Library/Colors/Emacs.clr’. It will be recreated the
next time you run Emacs.

> Building Emacs on MacOS 10.14 results in a non-functional GUI. 
> 
> With the following commits from scratch/ns-drawing the GUI is working
> again:
> 
> http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00152.html
> http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00150.html
> http://lists.gnu.org/archive/html/emacs-diffs/2018-08/msg00151.html
> 
> But I still see the reported error on start and Emacs sporadically
> crashes. 

Try the attached patch, please. It replaces the above three commits.
If nobody objects I’ll push it to emacs-26 in a few days.

I believe it fixes the crash, but it still fails to redraw the frame
correctly when the font is changed. I don’t have 10.14 yet (and
probably won’t before the end of the year) so I can’t test it directly
myself.
-- 
Alan Third

[-- Attachment #2: 0001-Make-all-NS-drawing-be-done-from-drawRect.patch --]
[-- Type: text/plain, Size: 35795 bytes --]

From 9196236afa609a77d294ef9a77b05518c6fb031f Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Sat, 4 Aug 2018 11:08:23 +0100
Subject: [PATCH] Make all NS drawing be done from drawRect

See bug#31904 and bug#32812.

* src/nsterm.m (ns_update_begin): Don't lock focus, only clip if there
is already a view focused.
(ns_update_end): Don't mess with view focusing any more.
(ns_focus): Only clip drawing if there is already a focused view,
otherwise mark area dirty for later drawing.  Renamed ns_clip_to_rect.
All callers changed.
(ns_unfocus): Don't unfocus the view any more.  Renamed
ns_reset_clipping. All callers changed.
(ns_clip_to_row): Update to match ns_clip_to_rect.
(ns_clear_frame):
(ns_clear_frame_area):
(ns_draw_fringe_bitmap):
(ns_draw_window_cursor):
(ns_draw_vertical_window_border):
(ns_draw_window_divider):
(ns_dumpglyphs_stretch):
(ns_draw_glyph_string): Only draw if ns_focus or ns_clip_to_row
return YES.
(ns_copy_bits): Remove superfluous calls to ns_(un)focus.
(ns_flush_display): New function.
---
 src/nsterm.m | 767 +++++++++++++++++++++++++--------------------------
 1 file changed, 376 insertions(+), 391 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 5ed71c9f8f..954020dcde 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -276,12 +276,7 @@ - (NSColor *)colorUsingDefaultColorSpace
 long context_menu_value = 0;
 
 /* display update */
-static struct frame *ns_updating_frame;
-static NSView *focus_view = NULL;
 static int ns_window_num = 0;
-#ifdef NS_IMPL_GNUSTEP
-static NSRect uRect;            // TODO: This is dead, remove it?
-#endif
 static BOOL gsaved = NO;
 static BOOL ns_fake_keydown = NO;
 #ifdef NS_IMPL_COCOA
@@ -1039,12 +1034,13 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
    external (RIF) call; whole frame, called before update_window_begin
    -------------------------------------------------------------------------- */
 {
+#ifdef NS_IMPL_COCOA
   EmacsView *view = FRAME_NS_VIEW (f);
+
   NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_update_begin");
 
   ns_update_auto_hide_menu_bar ();
 
-#ifdef NS_IMPL_COCOA
   if ([view isFullscreen] && [view fsIsNative])
   {
     // Fix reappearing tool bar in fullscreen for Mac OS X 10.7
@@ -1053,36 +1049,29 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
     if (! tbar_visible != ! [toolbar isVisible])
       [toolbar setVisible: tbar_visible];
   }
-#endif
-
-  ns_updating_frame = f;
-  [view lockFocus];
 
   /* drawRect may have been called for say the minibuffer, and then clip path
      is for the minibuffer.  But the display engine may draw more because
      we have set the frame as garbaged.  So reset clip path to the whole
      view.  */
-#ifdef NS_IMPL_COCOA
-  {
-    NSBezierPath *bp;
-    NSRect r = [view frame];
-    NSRect cr = [[view window] frame];
-    /* If a large frame size is set, r may be larger than the window frame
-       before constrained.  In that case don't change the clip path, as we
-       will clear in to the tool bar and title bar.  */
-    if (r.size.height
-        + FRAME_NS_TITLEBAR_HEIGHT (f)
-        + FRAME_TOOLBAR_HEIGHT (f) <= cr.size.height)
-      {
-        bp = [[NSBezierPath bezierPathWithRect: r] retain];
-        [bp setClip];
-        [bp release];
-      }
-  }
-#endif
-
-#ifdef NS_IMPL_GNUSTEP
-  uRect = NSMakeRect (0, 0, 0, 0);
+  /* FIXME: I don't think we need to do this.  */
+  if ([NSView focusView] == FRAME_NS_VIEW (f))
+    {
+      NSBezierPath *bp;
+      NSRect r = [view frame];
+      NSRect cr = [[view window] frame];
+      /* If a large frame size is set, r may be larger than the window frame
+         before constrained.  In that case don't change the clip path, as we
+         will clear in to the tool bar and title bar.  */
+      if (r.size.height
+          + FRAME_NS_TITLEBAR_HEIGHT (f)
+          + FRAME_TOOLBAR_HEIGHT (f) <= cr.size.height)
+        {
+          bp = [[NSBezierPath bezierPathWithRect: r] retain];
+          [bp setClip];
+          [bp release];
+        }
+    }
 #endif
 }
 
@@ -1164,99 +1153,66 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
    external (RIF) call; for whole frame, called after update_window_end
    -------------------------------------------------------------------------- */
 {
-  EmacsView *view = FRAME_NS_VIEW (f);
-
   NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_update_end");
 
 /*   if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
   MOUSE_HL_INFO (f)->mouse_face_defer = 0;
-
-  block_input ();
-
-  [view unlockFocus];
-  [[view window] flushWindow];
-
-  unblock_input ();
-  ns_updating_frame = NULL;
 }
 
-static void
-ns_focus (struct frame *f, NSRect *r, int n)
+
+static BOOL
+ns_clip_to_rect (struct frame *f, NSRect *r, int n)
 /* --------------------------------------------------------------------------
-   Internal: Focus on given frame.  During small local updates this is used to
-     draw, however during large updates, ns_update_begin and ns_update_end are
-     called to wrap the whole thing, in which case these calls are stubbed out.
-     Except, on GNUstep, we accumulate the rectangle being drawn into, because
-     the back end won't do this automatically, and will just end up flushing
-     the entire window.
+   Clip the drawing area to rectangle r in frame f.  If drawing is not
+   currently possible mark r as dirty and return NO, otherwise return
+   YES.
    -------------------------------------------------------------------------- */
 {
-  NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "ns_focus");
-  if (r != NULL)
+  NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "ns_clip_to_rect");
+  if (r)
     {
       NSTRACE_RECT ("r", *r);
-    }
 
-  if (f != ns_updating_frame)
-    {
-      NSView *view = FRAME_NS_VIEW (f);
-      if (view != focus_view)
+      if ([NSView focusView] == FRAME_NS_VIEW (f))
         {
-          if (focus_view != NULL)
-            {
-              [focus_view unlockFocus];
-              [[focus_view window] flushWindow];
-/*debug_lock--; */
-            }
+          [[NSGraphicsContext currentContext] saveGraphicsState];
+          if (n == 2)
+            NSRectClipList (r, 2);
+          else
+            NSRectClip (*r);
+          gsaved = YES;
 
-          if (view)
-            [view lockFocus];
-          focus_view = view;
-/*if (view) debug_lock++; */
+          return YES;
         }
-    }
-
-  /* clipping */
-  if (r)
-    {
-      [[NSGraphicsContext currentContext] saveGraphicsState];
-      if (n == 2)
-        NSRectClipList (r, 2);
       else
-        NSRectClip (*r);
-      gsaved = YES;
+        {
+          NSView *view = FRAME_NS_VIEW (f);
+          int i;
+          for (i = 0 ; i < n ; i++)
+            [view setNeedsDisplayInRect:r[i]];
+        }
     }
+
+  return NO;
 }
 
 
 static void
-ns_unfocus (struct frame *f)
-/* --------------------------------------------------------------------------
-     Internal: Remove focus on given frame
-   -------------------------------------------------------------------------- */
+ns_reset_clipping (struct frame *f)
+/* Internal: Restore the previous graphics state, unsetting any
+   clipping areas.  */
 {
-  NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "ns_unfocus");
+  NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "ns_reset_clipping");
 
   if (gsaved)
     {
       [[NSGraphicsContext currentContext] restoreGraphicsState];
       gsaved = NO;
     }
-
-  if (f != ns_updating_frame)
-    {
-      if (focus_view != NULL)
-        {
-          [focus_view unlockFocus];
-          [[focus_view window] flushWindow];
-          focus_view = NULL;
-/*debug_lock--; */
-        }
-    }
 }
 
 
-static void
+static BOOL
 ns_clip_to_row (struct window *w, struct glyph_row *row,
 		enum glyph_row_area area, BOOL gc)
 /* --------------------------------------------------------------------------
@@ -1275,7 +1231,19 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
   clip_rect.size.width = window_width;
   clip_rect.size.height = row->visible_height;
 
-  ns_focus (f, &clip_rect, 1);
+  return ns_clip_to_rect (f, &clip_rect, 1);
+}
+
+
+static void
+ns_flush_display (struct frame *f)
+/* Force the frame to redisplay.  If areas have previously been marked
+   dirty by setNeedsDisplayInRect (in ns_clip_to_rect), then this will call
+   draw_rect: which will "expose" those areas.  */
+{
+  block_input ();
+  [FRAME_NS_VIEW (f) displayIfNeeded];
+  unblock_input ();
 }
 
 
@@ -2699,14 +2667,16 @@ so some key presses (TAB) are swallowed by the system. */
   r = [view bounds];
 
   block_input ();
-  ns_focus (f, &r, 1);
-  [ns_lookup_indexed_color (NS_FACE_BACKGROUND
-			    (FACE_FROM_ID (f, DEFAULT_FACE_ID)), f) set];
-  NSRectFill (r);
-  ns_unfocus (f);
-
-  /* as of 2006/11 or so this is now needed */
-  ns_redraw_scroll_bars (f);
+  if (ns_clip_to_rect (f, &r, 1))
+    {
+      [ns_lookup_indexed_color (NS_FACE_BACKGROUND
+                                (FACE_FROM_ID (f, DEFAULT_FACE_ID)), f) set];
+      NSRectFill (r);
+      ns_reset_clipping (f);
+
+      /* as of 2006/11 or so this is now needed */
+      ns_redraw_scroll_bars (f);
+    }
   unblock_input ();
 }
 
@@ -2727,13 +2697,14 @@ so some key presses (TAB) are swallowed by the system. */
   NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_clear_frame_area");
 
   r = NSIntersectionRect (r, [view frame]);
-  ns_focus (f, &r, 1);
-  [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set];
+  if (ns_clip_to_rect (f, &r, 1))
+    {
+      [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set];
 
-  NSRectFill (r);
+      NSRectFill (r);
 
-  ns_unfocus (f);
-  return;
+      ns_reset_clipping (f);
+    }
 }
 
 static void
@@ -2745,11 +2716,11 @@ so some key presses (TAB) are swallowed by the system. */
     {
       hide_bell();              // Ensure the bell image isn't scrolled.
 
-      ns_focus (f, &dest, 1);
+      /* FIXME: scrollRect:by: is deprecated in macOS 10.14.  There is
+         no obvious replacement so we may have to come up with our own.  */
       [FRAME_NS_VIEW (f) scrollRect: src
                                  by: NSMakeSize (dest.origin.x - src.origin.x,
                                                  dest.origin.y - src.origin.y)];
-      ns_unfocus (f);
     }
 }
 
@@ -2960,85 +2931,86 @@ so some key presses (TAB) are swallowed by the system. */
     }
 
   /* Must clip because of partially visible lines.  */
-  ns_clip_to_row (w, row, ANY_AREA, YES);
-
-  if (!p->overlay_p)
+  if (ns_clip_to_row (w, row, ANY_AREA, YES))
     {
-      int bx = p->bx, by = p->by, nx = p->nx, ny = p->ny;
-
-      if (bx >= 0 && nx > 0)
+      if (!p->overlay_p)
         {
-          NSRect r = NSMakeRect (bx, by, nx, ny);
-          NSRectClip (r);
-          [ns_lookup_indexed_color (face->background, f) set];
-          NSRectFill (r);
-        }
-    }
+          int bx = p->bx, by = p->by, nx = p->nx, ny = p->ny;
 
-  if (p->which)
-    {
-      NSRect r = NSMakeRect (p->x, p->y, p->wd, p->h);
-      EmacsImage *img = bimgs[p->which - 1];
-
-      if (!img)
-        {
-          // Note: For "periodic" images, allocate one EmacsImage for
-          // the base image, and use it for all dh:s.
-          unsigned short *bits = p->bits;
-          int full_height = p->h + p->dh;
-          int i;
-          unsigned char *cbits = xmalloc (full_height);
-
-          for (i = 0; i < full_height; i++)
-            cbits[i] = bits[i];
-          img = [[EmacsImage alloc] initFromXBM: cbits width: 8
-                                         height: full_height
-                                             fg: 0 bg: 0];
-          bimgs[p->which - 1] = img;
-          xfree (cbits);
+          if (bx >= 0 && nx > 0)
+            {
+              NSRect r = NSMakeRect (bx, by, nx, ny);
+              NSRectClip (r);
+              [ns_lookup_indexed_color (face->background, f) set];
+              NSRectFill (r);
+            }
         }
 
-      NSTRACE_RECT ("r", r);
+      if (p->which)
+        {
+          NSRect r = NSMakeRect (p->x, p->y, p->wd, p->h);
+          EmacsImage *img = bimgs[p->which - 1];
 
-      NSRectClip (r);
-      /* Since we composite the bitmap instead of just blitting it, we need
-         to erase the whole background. */
-      [ns_lookup_indexed_color(face->background, f) set];
-      NSRectFill (r);
+          if (!img)
+            {
+              // Note: For "periodic" images, allocate one EmacsImage for
+              // the base image, and use it for all dh:s.
+              unsigned short *bits = p->bits;
+              int full_height = p->h + p->dh;
+              int i;
+              unsigned char *cbits = xmalloc (full_height);
+
+              for (i = 0; i < full_height; i++)
+                cbits[i] = bits[i];
+              img = [[EmacsImage alloc] initFromXBM: cbits width: 8
+                                             height: full_height
+                                                 fg: 0 bg: 0];
+              bimgs[p->which - 1] = img;
+              xfree (cbits);
+            }
 
-      {
-        NSColor *bm_color;
-        if (!p->cursor_p)
-          bm_color = ns_lookup_indexed_color(face->foreground, f);
-        else if (p->overlay_p)
-          bm_color = ns_lookup_indexed_color(face->background, f);
-        else
-          bm_color = f->output_data.ns->cursor_color;
-        [img setXBMColor: bm_color];
-      }
+          NSTRACE_RECT ("r", r);
 
-#ifdef NS_IMPL_COCOA
-      // Note: For periodic images, the full image height is "h + hd".
-      // By using the height h, a suitable part of the image is used.
-      NSRect fromRect = NSMakeRect(0, 0, p->wd, p->h);
+          NSRectClip (r);
+          /* Since we composite the bitmap instead of just blitting it, we need
+             to erase the whole background.  */
+          [ns_lookup_indexed_color(face->background, f) set];
+          NSRectFill (r);
 
-      NSTRACE_RECT ("fromRect", fromRect);
+          {
+            NSColor *bm_color;
+            if (!p->cursor_p)
+              bm_color = ns_lookup_indexed_color(face->foreground, f);
+            else if (p->overlay_p)
+              bm_color = ns_lookup_indexed_color(face->background, f);
+            else
+              bm_color = f->output_data.ns->cursor_color;
+            [img setXBMColor: bm_color];
+          }
 
-      [img drawInRect: r
-              fromRect: fromRect
-             operation: NSCompositingOperationSourceOver
-              fraction: 1.0
-           respectFlipped: YES
-                hints: nil];
+#ifdef NS_IMPL_COCOA
+          // Note: For periodic images, the full image height is "h + hd".
+          // By using the height h, a suitable part of the image is used.
+          NSRect fromRect = NSMakeRect(0, 0, p->wd, p->h);
+
+          NSTRACE_RECT ("fromRect", fromRect);
+
+          [img drawInRect: r
+                 fromRect: fromRect
+                operation: NSCompositingOperationSourceOver
+                 fraction: 1.0
+               respectFlipped: YES
+                    hints: nil];
 #else
-      {
-        NSPoint pt = r.origin;
-        pt.y += p->h;
-        [img compositeToPoint: pt operation: NSCompositingOperationSourceOver];
-      }
+          {
+            NSPoint pt = r.origin;
+            pt.y += p->h;
+            [img compositeToPoint: pt operation: NSCompositingOperationSourceOver];
+          }
 #endif
+        }
+      ns_reset_clipping (f);
     }
-  ns_unfocus (f);
 }
 
 
@@ -3120,67 +3092,66 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
   r.size.height = h;
   r.size.width = w->phys_cursor_width;
 
-  /* Prevent the cursor from being drawn outside the text area. */
-  ns_clip_to_row (w, glyph_row, TEXT_AREA, NO); /* do ns_focus(f, &r, 1); if remove */
-
-
-  face = FACE_FROM_ID_OR_NULL (f, phys_cursor_glyph->face_id);
-  if (face && NS_FACE_BACKGROUND (face)
-      == ns_index_color (FRAME_CURSOR_COLOR (f), f))
+  /* Prevent the cursor from being drawn outside the text area.  */
+  if (ns_clip_to_row (w, glyph_row, TEXT_AREA, NO))
     {
-      [ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), f) set];
-      hollow_color = FRAME_CURSOR_COLOR (f);
-    }
-  else
-    [FRAME_CURSOR_COLOR (f) set];
+      face = FACE_FROM_ID_OR_NULL (f, phys_cursor_glyph->face_id);
+      if (face && NS_FACE_BACKGROUND (face)
+          == ns_index_color (FRAME_CURSOR_COLOR (f), f))
+        {
+          [ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), f) set];
+          hollow_color = FRAME_CURSOR_COLOR (f);
+        }
+      else
+        [FRAME_CURSOR_COLOR (f) set];
 
 #ifdef NS_IMPL_COCOA
-  /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
-           atomic.  Cleaner ways of doing this should be investigated.
-           One way would be to set a global variable DRAWING_CURSOR
-  	   when making the call to draw_phys..(), don't focus in that
-  	   case, then move the ns_unfocus() here after that call. */
-  NSDisableScreenUpdates ();
+      /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
+         atomic.  Cleaner ways of doing this should be investigated.
+         One way would be to set a global variable DRAWING_CURSOR
+         when making the call to draw_phys..(), don't focus in that
+         case, then move the ns_reset_clipping() here after that call.  */
+      NSDisableScreenUpdates ();
 #endif
 
-  switch (cursor_type)
-    {
-    case DEFAULT_CURSOR:
-    case NO_CURSOR:
-      break;
-    case FILLED_BOX_CURSOR:
-      NSRectFill (r);
-      break;
-    case HOLLOW_BOX_CURSOR:
-      NSRectFill (r);
-      [hollow_color set];
-      NSRectFill (NSInsetRect (r, 1, 1));
-      [FRAME_CURSOR_COLOR (f) set];
-      break;
-    case HBAR_CURSOR:
-      NSRectFill (r);
-      break;
-    case BAR_CURSOR:
-      s = r;
-      /* If the character under cursor is R2L, draw the bar cursor
-         on the right of its glyph, rather than on the left.  */
-      cursor_glyph = get_phys_cursor_glyph (w);
-      if ((cursor_glyph->resolved_level & 1) != 0)
-        s.origin.x += cursor_glyph->pixel_width - s.size.width;
-
-      NSRectFill (s);
-      break;
-    }
-  ns_unfocus (f);
+      switch (cursor_type)
+        {
+        case DEFAULT_CURSOR:
+        case NO_CURSOR:
+          break;
+        case FILLED_BOX_CURSOR:
+          NSRectFill (r);
+          break;
+        case HOLLOW_BOX_CURSOR:
+          NSRectFill (r);
+          [hollow_color set];
+          NSRectFill (NSInsetRect (r, 1, 1));
+          [FRAME_CURSOR_COLOR (f) set];
+          break;
+        case HBAR_CURSOR:
+          NSRectFill (r);
+          break;
+        case BAR_CURSOR:
+          s = r;
+          /* If the character under cursor is R2L, draw the bar cursor
+             on the right of its glyph, rather than on the left.  */
+          cursor_glyph = get_phys_cursor_glyph (w);
+          if ((cursor_glyph->resolved_level & 1) != 0)
+            s.origin.x += cursor_glyph->pixel_width - s.size.width;
+
+          NSRectFill (s);
+          break;
+        }
+      ns_reset_clipping (f);
 
-  /* draw the character under the cursor */
-  if (cursor_type != NO_CURSOR)
-    draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
+      /* draw the character under the cursor */
+      if (cursor_type != NO_CURSOR)
+        draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
 
 #ifdef NS_IMPL_COCOA
-  NSEnableScreenUpdates ();
+      NSEnableScreenUpdates ();
 #endif
-
+    }
 }
 
 
@@ -3198,12 +3169,14 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
 
   face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID);
 
-  ns_focus (f, &r, 1);
-  if (face)
-    [ns_lookup_indexed_color(face->foreground, f) set];
+  if (ns_clip_to_rect (f, &r, 1))
+    {
+      if (face)
+        [ns_lookup_indexed_color(face->foreground, f) set];
 
-  NSRectFill(r);
-  ns_unfocus (f);
+      NSRectFill(r);
+      ns_reset_clipping (f);
+    }
 }
 
 
@@ -3230,39 +3203,40 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
 
   NSTRACE ("ns_draw_window_divider");
 
-  ns_focus (f, &divider, 1);
-
-  if ((y1 - y0 > x1 - x0) && (x1 - x0 >= 3))
-    /* A vertical divider, at least three pixels wide: Draw first and
-       last pixels differently.  */
+  if (ns_clip_to_rect (f, &divider, 1))
     {
-      [ns_lookup_indexed_color(color_first, f) set];
-      NSRectFill(NSMakeRect (x0, y0, 1, y1 - y0));
-      [ns_lookup_indexed_color(color, f) set];
-      NSRectFill(NSMakeRect (x0 + 1, y0, x1 - x0 - 2, y1 - y0));
-      [ns_lookup_indexed_color(color_last, f) set];
-      NSRectFill(NSMakeRect (x1 - 1, y0, 1, y1 - y0));
-    }
-  else if ((x1 - x0 > y1 - y0) && (y1 - y0 >= 3))
-    /* A horizontal divider, at least three pixels high: Draw first and
-       last pixels differently.  */
-    {
-      [ns_lookup_indexed_color(color_first, f) set];
-      NSRectFill(NSMakeRect (x0, y0, x1 - x0, 1));
-      [ns_lookup_indexed_color(color, f) set];
-      NSRectFill(NSMakeRect (x0, y0 + 1, x1 - x0, y1 - y0 - 2));
-      [ns_lookup_indexed_color(color_last, f) set];
-      NSRectFill(NSMakeRect (x0, y1 - 1, x1 - x0, 1));
-    }
-  else
-    {
-      /* In any other case do not draw the first and last pixels
-         differently.  */
-      [ns_lookup_indexed_color(color, f) set];
-      NSRectFill(divider);
-    }
+      if ((y1 - y0 > x1 - x0) && (x1 - x0 >= 3))
+        /* A vertical divider, at least three pixels wide: Draw first and
+           last pixels differently.  */
+        {
+          [ns_lookup_indexed_color(color_first, f) set];
+          NSRectFill(NSMakeRect (x0, y0, 1, y1 - y0));
+          [ns_lookup_indexed_color(color, f) set];
+          NSRectFill(NSMakeRect (x0 + 1, y0, x1 - x0 - 2, y1 - y0));
+          [ns_lookup_indexed_color(color_last, f) set];
+          NSRectFill(NSMakeRect (x1 - 1, y0, 1, y1 - y0));
+        }
+      else if ((x1 - x0 > y1 - y0) && (y1 - y0 >= 3))
+        /* A horizontal divider, at least three pixels high: Draw first and
+           last pixels differently.  */
+        {
+          [ns_lookup_indexed_color(color_first, f) set];
+          NSRectFill(NSMakeRect (x0, y0, x1 - x0, 1));
+          [ns_lookup_indexed_color(color, f) set];
+          NSRectFill(NSMakeRect (x0, y0 + 1, x1 - x0, y1 - y0 - 2));
+          [ns_lookup_indexed_color(color_last, f) set];
+          NSRectFill(NSMakeRect (x0, y1 - 1, x1 - x0, 1));
+        }
+      else
+        {
+          /* In any other case do not draw the first and last pixels
+             differently.  */
+          [ns_lookup_indexed_color(color, f) set];
+          NSRectFill(divider);
+        }
 
-  ns_unfocus (f);
+      ns_reset_clipping (f);
+    }
 }
 
 static void
@@ -3846,83 +3820,84 @@ Function modeled after x_draw_glyph_string_box ().
       n = ns_get_glyph_string_clip_rect (s, r);
       *r = NSMakeRect (s->x, s->y, s->background_width, s->height);
 
-      ns_focus (s->f, r, n);
-
-      if (s->hl == DRAW_MOUSE_FACE)
-       {
-         face = FACE_FROM_ID_OR_NULL (s->f,
-				      MOUSE_HL_INFO (s->f)->mouse_face_face_id);
-         if (!face)
-           face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
-       }
-      else
-       face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
-
-      bgCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f);
-      fgCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
-
-      for (i = 0; i < n; ++i)
+      if (ns_clip_to_rect (s->f, r, n))
         {
-          if (!s->row->full_width_p)
+          if (s->hl == DRAW_MOUSE_FACE)
             {
-	      int overrun, leftoverrun;
-
-              /* truncate to avoid overwriting fringe and/or scrollbar */
-	      overrun = max (0, (s->x + s->background_width)
-			     - (WINDOW_BOX_RIGHT_EDGE_X (s->w)
-				- WINDOW_RIGHT_FRINGE_WIDTH (s->w)));
-              r[i].size.width -= overrun;
-
-	      /* truncate to avoid overwriting to left of the window box */
-	      leftoverrun = (WINDOW_BOX_LEFT_EDGE_X (s->w)
-			     + WINDOW_LEFT_FRINGE_WIDTH (s->w)) - s->x;
-
-	      if (leftoverrun > 0)
-		{
-		  r[i].origin.x += leftoverrun;
-		  r[i].size.width -= leftoverrun;
-		}
-
-              /* XXX: Try to work between problem where a stretch glyph on
-                 a partially-visible bottom row will clear part of the
-                 modeline, and another where list-buffers headers and similar
-                 rows erroneously have visible_height set to 0.  Not sure
-                 where this is coming from as other terms seem not to show. */
-              r[i].size.height = min (s->height, s->row->visible_height);
+              face = FACE_FROM_ID_OR_NULL (s->f,
+                                           MOUSE_HL_INFO (s->f)->mouse_face_face_id);
+              if (!face)
+                face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
             }
+          else
+            face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
 
-          [bgCol set];
+          bgCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f);
+          fgCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
 
-          /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
-             overwriting cursor (usually when cursor on a tab) */
-          if (s->hl == DRAW_CURSOR)
+          for (i = 0; i < n; ++i)
             {
-              CGFloat x, width;
+              if (!s->row->full_width_p)
+                {
+                  int overrun, leftoverrun;
+
+                  /* truncate to avoid overwriting fringe and/or scrollbar */
+                  overrun = max (0, (s->x + s->background_width)
+                                 - (WINDOW_BOX_RIGHT_EDGE_X (s->w)
+                                    - WINDOW_RIGHT_FRINGE_WIDTH (s->w)));
+                  r[i].size.width -= overrun;
+
+                  /* truncate to avoid overwriting to left of the window box */
+                  leftoverrun = (WINDOW_BOX_LEFT_EDGE_X (s->w)
+                                 + WINDOW_LEFT_FRINGE_WIDTH (s->w)) - s->x;
+
+                    if (leftoverrun > 0)
+                      {
+                        r[i].origin.x += leftoverrun;
+                        r[i].size.width -= leftoverrun;
+                      }
+
+                    /* XXX: Try to work between problem where a stretch glyph on
+                       a partially-visible bottom row will clear part of the
+                       modeline, and another where list-buffers headers and similar
+                       rows erroneously have visible_height set to 0.  Not sure
+                       where this is coming from as other terms seem not to show.  */
+                    r[i].size.height = min (s->height, s->row->visible_height);
+                }
+
+              [bgCol set];
+
+              /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
+                 overwriting cursor (usually when cursor on a tab).  */
+              if (s->hl == DRAW_CURSOR)
+                {
+                  CGFloat x, width;
 
-              x = r[i].origin.x;
-              width = s->w->phys_cursor_width;
-              r[i].size.width -= width;
-              r[i].origin.x += width;
+                  x = r[i].origin.x;
+                  width = s->w->phys_cursor_width;
+                  r[i].size.width -= width;
+                  r[i].origin.x += width;
 
-              NSRectFill (r[i]);
+                  NSRectFill (r[i]);
 
-              /* Draw overlining, etc. on the cursor. */
-              if (s->w->phys_cursor_type == FILLED_BOX_CURSOR)
-                ns_draw_text_decoration (s, face, bgCol, width, x);
+                  /* Draw overlining, etc. on the cursor.  */
+                  if (s->w->phys_cursor_type == FILLED_BOX_CURSOR)
+                    ns_draw_text_decoration (s, face, bgCol, width, x);
+                  else
+                    ns_draw_text_decoration (s, face, fgCol, width, x);
+                }
               else
-                ns_draw_text_decoration (s, face, fgCol, width, x);
-            }
-          else
-            {
-              NSRectFill (r[i]);
-            }
+                {
+                  NSRectFill (r[i]);
+                }
 
-          /* Draw overlining, etc. on the stretch glyph (or the part
-             of the stretch glyph after the cursor). */
-          ns_draw_text_decoration (s, face, fgCol, r[i].size.width,
-                                   r[i].origin.x);
+              /* Draw overlining, etc. on the stretch glyph (or the part
+                 of the stretch glyph after the cursor).  */
+              ns_draw_text_decoration (s, face, fgCol, r[i].size.width,
+                                       r[i].origin.x);
+            }
+          ns_reset_clipping (s->f);
         }
-      ns_unfocus (s->f);
       s->background_filled_p = 1;
     }
 }
@@ -4072,9 +4047,11 @@ overwriting cursor (usually when cursor on a tab) */
             if (next->first_glyph->type != STRETCH_GLYPH)
               {
                 n = ns_get_glyph_string_clip_rect (s->next, r);
-                ns_focus (s->f, r, n);
-                ns_maybe_dumpglyphs_background (s->next, 1);
-                ns_unfocus (s->f);
+                if (ns_clip_to_rect (s->f, r, n))
+                  {
+                    ns_maybe_dumpglyphs_background (s->next, 1);
+                    ns_reset_clipping (s->f);
+                  }
               }
             else
               {
@@ -4089,10 +4066,12 @@ overwriting cursor (usually when cursor on a tab) */
 	    || s->first_glyph->type == COMPOSITE_GLYPH))
     {
       n = ns_get_glyph_string_clip_rect (s, r);
-      ns_focus (s->f, r, n);
-      ns_maybe_dumpglyphs_background (s, 1);
-      ns_dumpglyphs_box_or_relief (s);
-      ns_unfocus (s->f);
+      if (ns_clip_to_rect (s->f, r, n))
+        {
+          ns_maybe_dumpglyphs_background (s, 1);
+          ns_dumpglyphs_box_or_relief (s);
+          ns_reset_clipping (s->f);
+        }
       box_drawn_p = 1;
     }
 
@@ -4101,9 +4080,11 @@ overwriting cursor (usually when cursor on a tab) */
 
     case IMAGE_GLYPH:
       n = ns_get_glyph_string_clip_rect (s, r);
-      ns_focus (s->f, r, n);
-      ns_dumpglyphs_image (s, r[0]);
-      ns_unfocus (s->f);
+      if (ns_clip_to_rect (s->f, r, n))
+        {
+          ns_dumpglyphs_image (s, r[0]);
+          ns_reset_clipping (s->f);
+        }
       break;
 
     case STRETCH_GLYPH:
@@ -4113,66 +4094,68 @@ overwriting cursor (usually when cursor on a tab) */
     case CHAR_GLYPH:
     case COMPOSITE_GLYPH:
       n = ns_get_glyph_string_clip_rect (s, r);
-      ns_focus (s->f, r, n);
+      if (ns_clip_to_rect (s->f, r, n))
+        {
+          if (s->for_overlaps || (s->cmp_from > 0
+                                  && ! s->first_glyph->u.cmp.automatic))
+            s->background_filled_p = 1;
+          else
+            ns_maybe_dumpglyphs_background
+              (s, s->first_glyph->type == COMPOSITE_GLYPH);
 
-      if (s->for_overlaps || (s->cmp_from > 0
-			      && ! s->first_glyph->u.cmp.automatic))
-        s->background_filled_p = 1;
-      else
-        ns_maybe_dumpglyphs_background
-          (s, s->first_glyph->type == COMPOSITE_GLYPH);
+          if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
+            {
+              unsigned long tmp = NS_FACE_BACKGROUND (s->face);
+              NS_FACE_BACKGROUND (s->face) = NS_FACE_FOREGROUND (s->face);
+              NS_FACE_FOREGROUND (s->face) = tmp;
+            }
 
-      if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
-        {
-          unsigned long tmp = NS_FACE_BACKGROUND (s->face);
-          NS_FACE_BACKGROUND (s->face) = NS_FACE_FOREGROUND (s->face);
-          NS_FACE_FOREGROUND (s->face) = tmp;
-        }
+          {
+            BOOL isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
 
-      {
-        BOOL isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
+            if (isComposite)
+              ns_draw_composite_glyph_string_foreground (s);
+            else
+              ns_draw_glyph_string_foreground (s);
+          }
 
-        if (isComposite)
-          ns_draw_composite_glyph_string_foreground (s);
-        else
-          ns_draw_glyph_string_foreground (s);
-      }
+          {
+            NSColor *col = (NS_FACE_FOREGROUND (s->face) != 0
+                            ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (s->face),
+                                                       s->f)
+                            : FRAME_FOREGROUND_COLOR (s->f));
+            [col set];
+
+            /* Draw underline, overline, strike-through.  */
+            ns_draw_text_decoration (s, s->face, col, s->width, s->x);
+          }
 
-      {
-        NSColor *col = (NS_FACE_FOREGROUND (s->face) != 0
-                        ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (s->face),
-                                                   s->f)
-                        : FRAME_FOREGROUND_COLOR (s->f));
-        [col set];
-
-        /* Draw underline, overline, strike-through. */
-        ns_draw_text_decoration (s, s->face, col, s->width, s->x);
-      }
+          if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
+            {
+              unsigned long tmp = NS_FACE_BACKGROUND (s->face);
+              NS_FACE_BACKGROUND (s->face) = NS_FACE_FOREGROUND (s->face);
+              NS_FACE_FOREGROUND (s->face) = tmp;
+            }
 
-      if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
-        {
-          unsigned long tmp = NS_FACE_BACKGROUND (s->face);
-          NS_FACE_BACKGROUND (s->face) = NS_FACE_FOREGROUND (s->face);
-          NS_FACE_FOREGROUND (s->face) = tmp;
+          ns_reset_clipping (s->f);
         }
-
-      ns_unfocus (s->f);
       break;
 
     case GLYPHLESS_GLYPH:
       n = ns_get_glyph_string_clip_rect (s, r);
-      ns_focus (s->f, r, n);
-
-      if (s->for_overlaps || (s->cmp_from > 0
-			      && ! s->first_glyph->u.cmp.automatic))
-        s->background_filled_p = 1;
-      else
-        ns_maybe_dumpglyphs_background
-          (s, s->first_glyph->type == COMPOSITE_GLYPH);
-      /* ... */
-      /* Not yet implemented.  */
-      /* ... */
-      ns_unfocus (s->f);
+      if (ns_clip_to_rect (s->f, r, n))
+        {
+          if (s->for_overlaps || (s->cmp_from > 0
+                                  && ! s->first_glyph->u.cmp.automatic))
+            s->background_filled_p = 1;
+          else
+            ns_maybe_dumpglyphs_background
+              (s, s->first_glyph->type == COMPOSITE_GLYPH);
+          /* ... */
+          /* Not yet implemented.  */
+          /* ... */
+          ns_reset_clipping (s->f);
+        }
       break;
 
     default:
@@ -4183,9 +4166,11 @@ overwriting cursor (usually when cursor on a tab) */
   if (!s->for_overlaps && !box_drawn_p && s->face->box != FACE_NO_BOX)
     {
       n = ns_get_glyph_string_clip_rect (s, r);
-      ns_focus (s->f, r, n);
-      ns_dumpglyphs_box_or_relief (s);
-      ns_unfocus (s->f);
+      if (ns_clip_to_rect (s->f, r, n))
+        {
+          ns_dumpglyphs_box_or_relief (s);
+          ns_reset_clipping (s->f);
+        }
     }
 
   s->num_clips = 0;
@@ -4991,7 +4976,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
   ns_after_update_window_line,
   ns_update_window_begin,
   ns_update_window_end,
-  0, /* flush_display */
+  ns_flush_display, /* flush_display */
   x_clear_window_mouse_face,
   x_get_glyph_overhangs,
   x_fix_overlapping_area,
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-26 18:35       ` Alan Third
@ 2018-09-26 18:42         ` Perry E. Metzger
  2018-09-26 21:36           ` [PATCH] Fix deprecation warning Alan Third
  2018-09-28 19:35           ` weird startup error in MacOS Mojave Alan Third
  0 siblings, 2 replies; 15+ messages in thread
From: Perry E. Metzger @ 2018-09-26 18:42 UTC (permalink / raw)
  To: Alan Third; +Cc: Herbert J. Skuhra, emacs-devel

On Wed, 26 Sep 2018 19:35:12 +0100 Alan Third <alan@idiocy.org> wrote:
> On Wed, Sep 26, 2018 at 12:56:35AM +0200, Herbert J. Skuhra wrote:
> > On Tue, Sep 25, 2018 at 06:08:37PM -0400, Perry E. Metzger
> > wrote:
> > > On Tue, 25 Sep 2018 16:26:57 +0200 "Herbert J. Skuhra"
> > > <herbert@gojira.at> wrote:
> > > > On Tue, Sep 25, 2018 at 09:46:06AM -0400, Perry E. Metzger
> > > > wrote:
> > > > > I just upgraded my Mac to Mojave, and for the first time,
> > > > > starting the GUI is spitting out this error:
> > > > >
> > > > > 2018-09-25 09:43:29.255 Emacs[1948:30669] Failed to
> > > > > initialize color list unarchiver: Error
> > > > > Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver
> > > > > _initForReadingFromData:error:throwLegacyExceptions:]:
> > > > > non-keyed archive cannot be decoded by NSKeyedUnarchiver"
> > > > > UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
> > > > > _initForReadingFromData:error:throwLegacyExceptions:]:
> > > > > non-keyed archive cannot be decoded by
> > > > > NSKeyedUnarchiver}
>
> This is nice. I don't know what's going on. I guess it's maybe
> related to the colour list we generate and which caused us some
> problems with the high sierra beta last year.
>
> Try deleting ~/Library/Colors/Emacs.clr. It will be recreated the
> next time you run Emacs.

Removing it gets rid of the error. Then if I restart emacs, the error
has come back with the file. So you do have a good idea of where the
problem is, but just removing that doesn't fix it.

> Try the attached patch, please. It replaces the above three commits.
> If nobody objects I'll push it to emacs-26 in a few days.
>
> I believe it fixes the crash, but it still fails to redraw the frame
> correctly when the font is changed. I don't have 10.14 yet (and
> probably won't before the end of the year) so I can't test it
> directly myself.

Would remote access to a 10.14 machine help?

Perry
--
Perry E. Metzger		perry@piermont.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] Fix deprecation warning
  2018-09-26 18:42         ` Perry E. Metzger
@ 2018-09-26 21:36           ` Alan Third
  2018-09-28 17:51             ` Herbert J. Skuhra
  2018-09-28 19:35           ` weird startup error in MacOS Mojave Alan Third
  1 sibling, 1 reply; 15+ messages in thread
From: Alan Third @ 2018-09-26 21:36 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: Herbert J. Skuhra, emacs-devel

* src/nsterm.m (ns_term_init): Use writeToFile or writeToURL as
required.
---
I believe this should fix the colour list error.

 src/nsterm.m | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 954020dcde..d92d6c3244 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5193,7 +5193,21 @@ Needs to be here because ns_initialize_display_info () uses AppKit classes.
                                       alpha: 1.0]
                   forKey: [NSString stringWithUTF8String: name]];
           }
-        [cl writeToFile: nil];
+
+        /* FIXME: Report any errors writing the color file below.  */
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
+        if ([cl respondsToSelector:@selector(writeToURL:error:)])
+#endif
+          [cl writeToURL:nil error:nil];
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
+        else
+#endif
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 */
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 \
+  || defined (NS_IMPL_GNUSTEP)
+          [cl writeToFile: nil];
+#endif
       }
   }
 
-- 
2.18.0


-- 
Alan Third



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix deprecation warning
  2018-09-26 21:36           ` [PATCH] Fix deprecation warning Alan Third
@ 2018-09-28 17:51             ` Herbert J. Skuhra
  2018-09-28 19:26               ` Alan Third
  0 siblings, 1 reply; 15+ messages in thread
From: Herbert J. Skuhra @ 2018-09-28 17:51 UTC (permalink / raw)
  To: Alan Third; +Cc: emacs-devel, Perry E. Metzger

On Wed, 26 Sep 2018 23:36:52 +0200, Alan Third wrote:
> 
> * src/nsterm.m (ns_term_init): Use writeToFile or writeToURL as
> required.
> ---
> I believe this should fix the colour list error.
> 
>  src/nsterm.m | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)

Yes, the error is gone. Thanks.

--
Herbert



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix deprecation warning
  2018-09-28 17:51             ` Herbert J. Skuhra
@ 2018-09-28 19:26               ` Alan Third
  2018-09-29 14:43                 ` Perry E. Metzger
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Third @ 2018-09-28 19:26 UTC (permalink / raw)
  To: Herbert J. Skuhra; +Cc: emacs-devel, Perry E. Metzger

On Fri, Sep 28, 2018 at 07:51:55PM +0200, Herbert J. Skuhra wrote:
> On Wed, 26 Sep 2018 23:36:52 +0200, Alan Third wrote:
> > 
> > * src/nsterm.m (ns_term_init): Use writeToFile or writeToURL as
> > required.
> > ---
> > I believe this should fix the colour list error.
> > 
> >  src/nsterm.m | 16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> Yes, the error is gone. Thanks.

Thanks, I’ve pushed both the patches to emacs-26.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: weird startup error in MacOS Mojave
  2018-09-26 18:42         ` Perry E. Metzger
  2018-09-26 21:36           ` [PATCH] Fix deprecation warning Alan Third
@ 2018-09-28 19:35           ` Alan Third
  1 sibling, 0 replies; 15+ messages in thread
From: Alan Third @ 2018-09-28 19:35 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: Herbert J. Skuhra, emacs-devel

On Wed, Sep 26, 2018 at 02:42:25PM -0400, Perry E. Metzger wrote:
> 
> Would remote access to a 10.14 machine help?

It probably would. Although I may be able to get by with some of these
issues just by seeing if there are any new deprecation notices being
flagged up on a build.

Also nobody else has ever confirmed the font change bug, so that might
help. (bug#31904)
-- 
Alan Third



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix deprecation warning
  2018-09-28 19:26               ` Alan Third
@ 2018-09-29 14:43                 ` Perry E. Metzger
  2018-09-29 16:41                   ` Alan Third
  0 siblings, 1 reply; 15+ messages in thread
From: Perry E. Metzger @ 2018-09-29 14:43 UTC (permalink / raw)
  To: Alan Third; +Cc: Herbert J. Skuhra, emacs-devel

On Fri, 28 Sep 2018 20:26:54 +0100 Alan Third <alan@idiocy.org> wrote:
> On Fri, Sep 28, 2018 at 07:51:55PM +0200, Herbert J. Skuhra wrote:
> > On Wed, 26 Sep 2018 23:36:52 +0200, Alan Third wrote:
> > >
> > > * src/nsterm.m (ns_term_init): Use writeToFile or writeToURL as
> > > required.
> > > ---
> > > I believe this should fix the colour list error.
> > >
> > >  src/nsterm.m | 16 +++++++++++++++-
> > >  1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > Yes, the error is gone. Thanks.
>
> Thanks, I've pushed both the patches to emacs-26.

I still see this when running this morning's emacs-26 branch:

2018-09-29 10:40:33.355 Emacs[61583:10052482] Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver}

--
Perry E. Metzger		perry@piermont.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix deprecation warning
  2018-09-29 14:43                 ` Perry E. Metzger
@ 2018-09-29 16:41                   ` Alan Third
  2018-09-29 19:33                     ` Perry E. Metzger
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Third @ 2018-09-29 16:41 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: Herbert J. Skuhra, emacs-devel

On Sat, Sep 29, 2018 at 10:43:22AM -0400, Perry E. Metzger wrote:
> I still see this when running this morning's emacs-26 branch:
> 
> 2018-09-29 10:40:33.355 Emacs[61583:10052482] Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver}

Try deleting ~/Library/Colors/Emacs.clr again. You’re probably getting
it because I asked you to delete the file and Emacs created a
corrupted copy.

-- 
Alan Third



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix deprecation warning
  2018-09-29 16:41                   ` Alan Third
@ 2018-09-29 19:33                     ` Perry E. Metzger
  2018-09-29 21:20                       ` Alan Third
  0 siblings, 1 reply; 15+ messages in thread
From: Perry E. Metzger @ 2018-09-29 19:33 UTC (permalink / raw)
  To: Alan Third; +Cc: Herbert J. Skuhra, emacs-devel

On Sat, 29 Sep 2018 17:41:47 +0100 Alan Third <alan@idiocy.org> wrote:
> On Sat, Sep 29, 2018 at 10:43:22AM -0400, Perry E. Metzger wrote:
> > I still see this when running this morning's emacs-26 branch:
> > 
> > 2018-09-29 10:40:33.355 Emacs[61583:10052482] Failed to
> > initialize color list unarchiver: Error Domain=NSCocoaErrorDomain
> > Code=4864 "*** -[NSKeyedUnarchiver
> > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > archive cannot be decoded by NSKeyedUnarchiver"
> > UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
> > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > archive cannot be decoded by NSKeyedUnarchiver}  
> 
> Try deleting ~/Library/Colors/Emacs.clr again. You’re probably
> getting it because I asked you to delete the file and Emacs created
> a corrupted copy.

That worked.

Perry
-- 
Perry E. Metzger		perry@piermont.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix deprecation warning
  2018-09-29 19:33                     ` Perry E. Metzger
@ 2018-09-29 21:20                       ` Alan Third
  0 siblings, 0 replies; 15+ messages in thread
From: Alan Third @ 2018-09-29 21:20 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: Herbert J. Skuhra, Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

On Sat, 29 Sep 2018, 20:33 Perry E. Metzger, <perry@piermont.com> wrote:

> On Sat, 29 Sep 2018 17:41:47 +0100 Alan Third <alan@idiocy.org> wrote:
> > On Sat, Sep 29, 2018 at 10:43:22AM -0400, Perry E. Metzger wrote:
> > > I still see this when running this morning's emacs-26 branch:
> > >
> > > 2018-09-29 10:40:33.355 Emacs[61583:10052482] Failed to
> > > initialize color list unarchiver: Error Domain=NSCocoaErrorDomain
> > > Code=4864 "*** -[NSKeyedUnarchiver
> > > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > > archive cannot be decoded by NSKeyedUnarchiver"
> > > UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
> > > _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed
> > > archive cannot be decoded by NSKeyedUnarchiver}
> >
> > Try deleting ~/Library/Colors/Emacs.clr again. You’re probably
> > getting it because I asked you to delete the file and Emacs created
> > a corrupted copy.
>
> That worked.
>

Thanks, and sorry for the extra hassle.

>

[-- Attachment #2: Type: text/html, Size: 1697 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-09-29 21:20 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-25 13:46 weird startup error in MacOS Mojave Perry E. Metzger
2018-09-25 14:26 ` Herbert J. Skuhra
2018-09-25 22:08   ` Perry E. Metzger
2018-09-25 22:56     ` Herbert J. Skuhra
2018-09-25 23:13       ` Perry E. Metzger
2018-09-26 18:35       ` Alan Third
2018-09-26 18:42         ` Perry E. Metzger
2018-09-26 21:36           ` [PATCH] Fix deprecation warning Alan Third
2018-09-28 17:51             ` Herbert J. Skuhra
2018-09-28 19:26               ` Alan Third
2018-09-29 14:43                 ` Perry E. Metzger
2018-09-29 16:41                   ` Alan Third
2018-09-29 19:33                     ` Perry E. Metzger
2018-09-29 21:20                       ` Alan Third
2018-09-28 19:35           ` weird startup error in MacOS Mojave Alan Third

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).