From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: UI input unresponsive on macOS Date: Tue, 3 Jan 2017 14:36:21 +0000 Message-ID: <20170103143621.GA41725@breton.holly.idiocy.org> References: <72DF4592-73FE-452D-9CF3-C892E73BD36E@play-bow.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="mP3DRpeJDSE+ciuQ" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1483454233 29778 195.159.176.226 (3 Jan 2017 14:37:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 3 Jan 2017 14:37:13 +0000 (UTC) User-Agent: Mutt/1.7.1 (2016-10-04) Cc: emacs-devel@gnu.org To: Bob Halley Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 03 15:37:09 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOQD5-00077Z-Nn for ged-emacs-devel@m.gmane.org; Tue, 03 Jan 2017 15:37:07 +0100 Original-Received: from localhost ([::1]:34005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOQD9-0006Qx-MJ for ged-emacs-devel@m.gmane.org; Tue, 03 Jan 2017 09:37:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOQCW-0006P3-9l for emacs-devel@gnu.org; Tue, 03 Jan 2017 09:36:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cOQCR-0000gT-R3 for emacs-devel@gnu.org; Tue, 03 Jan 2017 09:36:32 -0500 Original-Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:36639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cOQCR-0000fq-Fq for emacs-devel@gnu.org; Tue, 03 Jan 2017 09:36:27 -0500 Original-Received: by mail-wm0-x233.google.com with SMTP id c85so200796987wmi.1 for ; Tue, 03 Jan 2017 06:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=l1sS+b3emZRryDHKvemwjL8fu1LNXXCV1DmXt9AUE1w=; b=juAIc8AxVbZKiLRr7UUWFRnmsg/NIB2RYw98XENJoSyBi7zdGpMLAvMR9oLrT80ZPd R4jmCCKcV2urb2b75FdaFlVd5j/NOeeINbrp8mi3ajVneiUT/SFWFkYWFMbkyP0JPsWK 38EW7ww0JzMkMSPMf6xf7Ob17K4yZ2llucVtp4Ze4fD+C0Ehyxdzf9U+/fFf/NGX3FDU oeCbCcgh83t/qUyb2EkqOHwSsAl4N1wWgn6uqZ7Vylh5mJhslTbrFh+9fnX41MEjtLrM daxasRTzoBGNR/uzOxk43Xh+xeWmA+8YaRuto1gIR4vVZWgTF/ByBM5gwGnJRTNgPWcO kthQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=l1sS+b3emZRryDHKvemwjL8fu1LNXXCV1DmXt9AUE1w=; b=UgWUpay2k+w63YB7Dmg5OE4HAha7BJgH5rvRJIhwoCnLoB1rB51tuiSQ/s18yohOSu xvYOfOat2nTW1/rJnP9xWtKLT41vJNN5/Mx1wsL5Z49p0em/6Cru/5mhhlF5gma0HNHh 91pSQQD3iR8oFLN1ohV7TRLh1wpzP0o9B678u6MNPv9LIxh6kagQxb6JA8yqk1pkk71q 1bRpZAzlTxGlWaoye7Tc991VrM+wjn/Bc64h+Ddpmz2P75NQWzAjzZTLy4DTu/V5XO8B wyoIVxPaSeDiRoJ5g01506K5cA2vG9Bj8gWyOGndS/GNMidRKh/xtclRfexxZOkVu2fk FtVw== X-Gm-Message-State: AIkVDXJnnIVqVVi0WK6qmQq13wV73rhQ4F4DFlFyYqxu17eBM8GF2Cp+k6GSjAZRkX+0Yw== X-Received: by 10.28.156.210 with SMTP id f201mr56150567wme.86.1483454184768; Tue, 03 Jan 2017 06:36:24 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-8471-fd78-dc83-6a18.holly.idiocy.org. [2001:8b0:3f8:8129:8471:fd78:dc83:6a18]) by smtp.gmail.com with ESMTPSA id cl10sm92993085wjb.4.2017.01.03.06.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jan 2017 06:36:23 -0800 (PST) Content-Disposition: inline In-Reply-To: <72DF4592-73FE-452D-9CF3-C892E73BD36E@play-bow.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::233 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211079 Archived-At: --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, Jan 03, 2017 at 05:36:01AM -0800, Bob Halley wrote: > I was running from the master branch with a build containing the > recent macOS event changes, > e0e5b0f4a4ce1d19ee0240c514dedd873d4165dc, and the UI became > unresponsive to the mouse and keyboard. I had to kill Emacs by hand. > > I was in the middle of something so I rolled back to my prior Emacs > build. I also am not sure how to debug this. If someone tells me how > to gather info that’s useful should this happen again, I’m willing > to reinstate the build and report if it fails. Hi Bob, I’m working on coming up with a better solution. Can you try the attached patch? So far the only problem I’ve seen is that emacsclient doesn’t return to the shell when it exits. I suspect it’s because I’m not monitoring write or exeption fds correctly. If you spot any other problems, either reply here or to bug 25265. Additionally, if anyone has any better ideas of how to deal with ns_select, please feel free to let me know. -- Alan Third --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Improve-NS-event-handling-bug-25265.patch" >From 9663d300d231242fc77f93a35219d56ba9c90601 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Tue, 3 Jan 2017 14:16:37 +0000 Subject: [PATCH] Improve NS event handling (bug#25265) * src/nsterm.h: Remove reference to timeout_handler. * src/nsterm.m (ns_select): Monitor fd changes using NSFileHandler. --- src/nsterm.h | 1 - src/nsterm.m | 62 +++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index dc222a7..8b5b691 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -392,7 +392,6 @@ char const * nstrace_fullscreen_type_name (int); - (void)sendEvent: (NSEvent *)theEvent; - (void)showPreferencesWindow: (id)sender; - (BOOL) openFile: (NSString *)fileName; -- (void)timeout_handler: (NSTimer *)timedEntry; - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg; #ifdef NS_IMPL_GNUSTEP - (void)sendFromMainThread:(id)unused; diff --git a/src/nsterm.m b/src/nsterm.m index 98fd8ab..51cccd0 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -4098,28 +4098,55 @@ overwriting cursor (usually when cursor on a tab) */ return pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask); - result = pselect(nfds, readfds, writefds, exceptfds, - &(struct timespec){.tv_sec = 0, .tv_nsec = 100}, - sigmask); - [outerpool release]; outerpool = [[NSAutoreleasePool alloc] init]; + /* Set up one NSFileHandle for each fd we want to monitor. */ + for (int i = 0 ; i < nfds ; i++) + { + if ((readfds != NULL && FD_ISSET(i, readfds)) + || (writefds != NULL && FD_ISSET(i, writefds)) + || (exceptfds != NULL &&FD_ISSET(i, exceptfds))) + { + NSFileHandle *fh = [[NSFileHandle alloc] initWithFileDescriptor: i + closeOnDealloc: NO]; + /* Send a notification to EmacsApp:fileHandleDataAvailable, + which will raise an appDefined event. */ + /* NOTE: I don't think this will pick up writes and + exceptions, so ns_select may not always behave correctly. + I've yet to see a problem, though. */ + [fh waitForDataInBackgroundAndNotify]; + [fh autorelease]; + } + } + if (timeout) { double time = timespectod (*timeout); - timeout_date = [NSDate dateWithTimeIntervalSinceNow:time]; + timeout_date = [NSDate dateWithTimeIntervalSinceNow: time]; } /* Listen for a new NSEvent. */ - ns_event = [NSApp nextEventMatchingMask:NSEventMaskAny - untilDate:timeout_date - inMode:NSDefaultRunLoopMode - dequeue:NO]; + ns_event = [NSApp nextEventMatchingMask: NSEventMaskAny + untilDate: timeout_date + inMode: NSDefaultRunLoopMode + dequeue: NO]; if (ns_event != nil) { - raise (SIGIO); + if ([ns_event type] == NSEventTypeApplicationDefined + && [ns_event data1] == -3) + { + result = pselect(nfds, readfds, writefds, exceptfds, + &(struct timespec){.tv_sec = 0, .tv_nsec = 0}, + sigmask); + } + else + { + raise (SIGIO); + errno = EINTR; + return -1; + } } return result; @@ -5132,6 +5159,12 @@ - (void)applicationDidFinishLaunching: (NSNotification *)notification object:nil]; #endif + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector (fileHandleDataAvailable:) + name: NSFileHandleDataAvailableNotification + object: nil]; + ns_send_appdefined (-2); } @@ -5315,14 +5348,9 @@ - (void)applicationDidResignActive: (NSNotification *)notification ========================================================================== */ - -- (void)timeout_handler: (NSTimer *)timedEntry -/* -------------------------------------------------------------------------- - The timeout specified to ns_select has passed. - -------------------------------------------------------------------------- */ +- (void)fileHandleDataAvailable: (NSNotification *)notification { - /*NSTRACE ("timeout_handler"); */ - ns_send_appdefined (-2); + ns_send_appdefined (-3); } - (void)sendFromMainThread:(id)unused -- 2.10.2 --mP3DRpeJDSE+ciuQ--