all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Anders Lindgren <andlind@gmail.com>
To: 21662@debbugs.gnu.org, John Wiegley <johnw@newartisans.com>,
	Steve Purcell <steve@sanityinc.com>,
	Mustafa Kocaturk <murskt@gmail.com>
Subject: bug#21662: visible-bell causes display artifacts on OS X 10.11
Date: Sat, 21 Nov 2015 21:05:07 +0100	[thread overview]
Message-ID: <CABr8ebbNNZ_Qust7K27eEBPbJh4VhGdig2ONq4f=i16iNVF5uw@mail.gmail.com> (raw)
In-Reply-To: <CABr8ebahFnC0H=wFT9mGfaVpbMTCsCQ4FDUO3fN6b1JBLZ=0-w@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1356 bytes --]

Hi again,

I decided to reimplement Mustafas ideas in a 10.6.8 compatible manner, and
to address the problem with the image being covered by scroll bars I
mentioned before. In addition, my implementation is aware that several
bell:s may be active at once and won't remove the image until the last one
times out, which eliminated flickering.

Unless anyone objects, I will publish this in the beginning of next week.

Sincerely,
    Anders Lindgren

On Wed, Nov 18, 2015 at 9:27 PM, Anders Lindgren <andlind@gmail.com> wrote:

> Hi,
>
> Today I tested suggested patch on an 10.11 and on 10.6.8.
>
> The good news is that, visually, the patch looks really good! It replaced
> the boring black square with the standard OS X icon "Caution" icon -- an
> exclamation mark on a triangle. It is less intrusive, which I consider a
> good thing.
>
> Unfortunately, the code doesn't compile under 10.6.8. The code use the
> "hidden" property of NSView (introduced in 10.10), and it the compiler
> complains about the "." in the "[BellView.instance ..." construct.
>
> I notices a minor problem under 10.11 as well. The icon is shadowed by
> scroll bars, if they happen to be displayed in the middle of the frame,
> like when having two side-by-side windows.
>
> I will make an attempt to rewrite to code to work under 10.6.8.
>
> Sincerely,
>     Anders Lindgren
>
>

[-- Attachment #1.2: Type: text/html, Size: 1941 bytes --]

[-- Attachment #2: bell-3.diff --]
[-- Type: text/plain, Size: 4382 bytes --]

diff --git a/src/nsterm.m b/src/nsterm.m
index 58ace48..5f22405 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -584,28 +584,6 @@ ns_load_path (void)
   return NULL;
 }
 
-static void
-ns_timeout (int usecs)
-/* --------------------------------------------------------------------------
-     Blocking timer utility used by ns_ring_bell
-   -------------------------------------------------------------------------- */
-{
-  struct timespec wakeup = timespec_add (current_timespec (),
-					 make_timespec (0, usecs * 1000));
-
-  /* Keep waiting until past the time wakeup.  */
-  while (1)
-    {
-      struct timespec timeout, now = current_timespec ();
-      if (timespec_cmp (wakeup, now) <= 0)
-	break;
-      timeout = timespec_sub (wakeup, now);
-
-      /* Try to wait that long--but we might wake up sooner.  */
-      pselect (0, NULL, NULL, NULL, &timeout, NULL);
-    }
-}
-
 
 void
 ns_release_object (void *obj)
@@ -1161,6 +1139,77 @@ ns_clip_to_row (struct window *w, struct glyph_row *row,
 }
 
 
+/* ==========================================================================
+
+    Visibel bell and beep.
+
+   ========================================================================== */
+
+
+@interface EmacsBell : NSImageView
+{
+  // Number of currently active bell:s.
+  unsigned int nestCount;
+}
+- (void)show:(NSView *)view;
+- (void)hide;
+@end
+
+@implementation EmacsBell
+
+- (id)init;
+{
+  if ((self = [super init]))
+    {
+      nestCount = 0;
+      self.image = [NSImage imageNamed:NSImageNameCaution];
+    }
+  return self;
+}
+
+- (void)show:(NSView *)view
+{
+  NSTRACE ("[EmacsBell show:]");
+  NSTRACE_MSG ("nestCount: %u", nestCount);
+
+  // Show the image, unless it's already shown.
+  if (nestCount == 0)
+    {
+      NSRect rect = [view bounds];
+      NSPoint pos;
+      pos.x = rect.origin.x + (rect.size.width  - self.image.size.width )/2;
+      pos.y = rect.origin.y + (rect.size.height - self.image.size.height)/2;
+
+      [self setFrameOrigin:pos];
+      [self setFrameSize:self.image.size];
+
+      [[[view window] contentView] addSubview:self
+                                   positioned:NSWindowAbove
+                                   relativeTo:nil];
+    }
+
+  ++nestCount;
+
+  [self performSelector:@selector(hide) withObject:self afterDelay:0.5];
+}
+
+
+- (void)hide
+{
+  // Note: Trace output from this method isn't shown, reason unknown.
+  // NSTRACE ("[EmacsBell hide]");
+
+  --nestCount;
+
+  // Remove the image once the last bell became inactive.
+  if (nestCount == 0)
+    {
+      [self removeFromSuperview];
+    }
+}
+
+@end
+
 static void
 ns_ring_bell (struct frame *f)
 /* --------------------------------------------------------------------------
@@ -1170,37 +1219,24 @@ ns_ring_bell (struct frame *f)
   NSTRACE ("ns_ring_bell");
   if (visible_bell)
     {
-      NSAutoreleasePool *pool;
       struct frame *frame = SELECTED_FRAME ();
       NSView *view;
 
+      static EmacsBell * bell_view = nil;
+      if (bell_view == nil)
+        {
+          bell_view = [[EmacsBell alloc] init];
+          [bell_view retain];
+        }
+
       block_input ();
-      pool = [[NSAutoreleasePool alloc] init];
 
       view = FRAME_NS_VIEW (frame);
       if (view != nil)
         {
-          NSRect r, surr;
-          NSPoint dim = NSMakePoint (128, 128);
-
-          r = [view bounds];
-          r.origin.x += (r.size.width - dim.x) / 2;
-          r.origin.y += (r.size.height - dim.y) / 2;
-          r.size.width = dim.x;
-          r.size.height = dim.y;
-          surr = NSInsetRect (r, -2, -2);
-          ns_focus (frame, &surr, 1);
-          [[view window] cacheImageInRect: [view convertRect: surr toView:nil]];
-          [ns_lookup_indexed_color (NS_FACE_FOREGROUND
-                                      (FRAME_DEFAULT_FACE (frame)), frame) set];
-          NSRectFill (r);
-          [[view window] flushWindow];
-          ns_timeout (150000);
-          [[view window] restoreCachedImage];
-          [[view window] flushWindow];
-          ns_unfocus (frame);
+          [bell_view show:view];
         }
-      [pool release];
+
       unblock_input ();
     }
   else
@@ -1209,6 +1245,7 @@ ns_ring_bell (struct frame *f)
     }
 }
 
+
 /* ==========================================================================
 
     Frame / window manager related functions

  reply	other threads:[~2015-11-21 20:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-11  3:41 bug#21662: 25.0.50; visible-bell causes display artifacts on OS X 10.11 Steve Purcell
2015-10-11 14:31 ` Spike Ilacqua
2015-10-14  2:13 ` Mustafa Kocaturk
2015-10-22 14:41 ` Mustafa Kocaturk
2015-10-22 16:07   ` Mustafa Kocaturk
2015-11-18 20:27 ` bug#21662: " Anders Lindgren
2015-11-21 20:05   ` Anders Lindgren [this message]
2015-11-23 22:09 ` bug#21662: Fixed Anders Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABr8ebbNNZ_Qust7K27eEBPbJh4VhGdig2ONq4f=i16iNVF5uw@mail.gmail.com' \
    --to=andlind@gmail.com \
    --cc=21662@debbugs.gnu.org \
    --cc=johnw@newartisans.com \
    --cc=murskt@gmail.com \
    --cc=steve@sanityinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.