From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#30699: 26.0.91; buffer contents flicker on macOS frames when frames are resized Date: Mon, 19 Mar 2018 15:15:52 +0000 Message-ID: <20180319151552.GA32506@breton.holly.idiocy.org> References: <20180309120952.GA45581@breton.holly.idiocy.org> <837eqlwf1i.fsf@gnu.org> <20180309232415.GB51893@breton.holly.idiocy.org> <20180310002555.GA54231@breton.holly.idiocy.org> <83h8pouycc.fsf@gnu.org> <20180310230706.GB55832@breton.holly.idiocy.org> <83a7vetw32.fsf@gnu.org> <20180312004638.GA56747@breton.holly.idiocy.org> <20180314150858.GA82855@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="tKW2IUtsqtDRztdT" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1521472514 26725 195.159.176.226 (19 Mar 2018 15:15:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 19 Mar 2018 15:15:14 +0000 (UTC) User-Agent: Mutt/1.9.3 (2018-01-21) Cc: 30699@debbugs.gnu.org To: Aaron Jensen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 19 16:15:09 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1exwVB-0006qX-Dh for geb-bug-gnu-emacs@m.gmane.org; Mon, 19 Mar 2018 16:15:09 +0100 Original-Received: from localhost ([::1]:42499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exwXE-0000Oc-Hl for geb-bug-gnu-emacs@m.gmane.org; Mon, 19 Mar 2018 11:17:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exwX5-0000L2-9R for bug-gnu-emacs@gnu.org; Mon, 19 Mar 2018 11:17:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exwX2-0004PS-2H for bug-gnu-emacs@gnu.org; Mon, 19 Mar 2018 11:17:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34139) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1exwX1-0004Op-Sm for bug-gnu-emacs@gnu.org; Mon, 19 Mar 2018 11:17:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1exwX0-0003XX-IE for bug-gnu-emacs@gnu.org; Mon, 19 Mar 2018 11:17:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Mar 2018 15:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30699 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30699-submit@debbugs.gnu.org id=B30699.152147256513534 (code B ref 30699); Mon, 19 Mar 2018 15:17:02 +0000 Original-Received: (at 30699) by debbugs.gnu.org; 19 Mar 2018 15:16:05 +0000 Original-Received: from localhost ([127.0.0.1]:42035 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1exwW5-0003WE-0a for submit@debbugs.gnu.org; Mon, 19 Mar 2018 11:16:05 -0400 Original-Received: from mail-wr0-f182.google.com ([209.85.128.182]:46238) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1exwW2-0003VU-NB for 30699@debbugs.gnu.org; Mon, 19 Mar 2018 11:16:03 -0400 Original-Received: by mail-wr0-f182.google.com with SMTP id s10so6152901wra.13 for <30699@debbugs.gnu.org>; Mon, 19 Mar 2018 08:16:02 -0700 (PDT) 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=V4EYCOLr8BRzJUOWERLCUjFIveW2+Ds56B9qsYnlEco=; b=H+zx9ghJUJCYu1ZqyUWN2ssb0oUSuW4mO9A/dZvCxTeLyvAZmwjt6lfwiYTxT7vggr nfszazN/Kq6+bxmVp7fPDHv/EoXaWfS8Pc5hn+Slk8shuuDmxrSzc9yxEWBtS/wL3npx O9fOq7w2RhB+ouDOCHqbYVBU9+Px7OWy/wwpGUdfZHrwUvsMCr/23cMqySTghZH6rble wkUd0lw8um8d+ZpcSIdyga3zHfMIYnyZiRJV84bQ1jiBhWX1x7BUOQkakF5PKD3urwct 8Do99YZPjYN564/v8Rfbi5XqdrCoZ1vNd+/3Qcw32aYvU+0URMJ6C3qSSgvaPPV645zg 7Z3A== 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=V4EYCOLr8BRzJUOWERLCUjFIveW2+Ds56B9qsYnlEco=; b=pKHfG6DsOiLYDsZ2K5z0D0LeHWAZdCE98FoyNQI9hyZLrvEpjBs9H/XgJD3xWytxWj dU1xZniJPL6Pb1IgpVsudTFZFQEC4rrK9qaefGwQVLMZq7nS8LZLgjOq3CXnvqyOnX02 7JKKAkoIm2DWCmfHhX1yXwB1w34YG2vocGPcp9uzcNcr43X9Ii+Vva37GCccxMg00uBU nlz0U4KufFpQd5sEcWE6fv2XNfFRjCuG54rq4AuHA5IPFLXr8jr/rFrpf5fjpGa4tVjz ssVxuSpmSOCMRcx557cfAM0qSrZXkCP7eGPXwdM03zUJs5wSSf9CXv/8hY8cublfuM3q iTDw== X-Gm-Message-State: AElRT7EeRsyqubbfF2N4tMawc3Jedj3QkIFr/HyA5sNZVf/iEFq8tJky PPE8+VBQ4hM84TybNtVngb8= X-Google-Smtp-Source: AG47ELsaH8wMW1Iw1PQGx2CJnTuEpfqs8o0RhihtPXB4l92D3Or0U8sedOUsiGbg5aJu6kK2m55DXA== X-Received: by 10.223.208.202 with SMTP id z10mr7505761wrh.15.1521472557014; Mon, 19 Mar 2018 08:15:57 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-c04a-d02f-79d4-a9c8.holly.idiocy.org. [2001:8b0:3f8:8129:c04a:d02f:79d4:a9c8]) by smtp.gmail.com with ESMTPSA id y111sm367634wrc.0.2018.03.19.08.15.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 08:15:54 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20180314150858.GA82855@breton.holly.idiocy.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:144407 Archived-At: --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Mar 14, 2018 at 03:08:58PM +0000, Alan Third wrote: > On Tue, Mar 13, 2018 at 08:34:10AM -0700, Aaron Jensen wrote: > > > > I haven't seen any glitches using this patch yet, fwiw. > > I haven’t come across anything yet, but I’ve not been using this patch > much. > > Watch out for macOS re‐enabling screen updates after ~1 second. It > does this automatically; I guess to stop buggy code from freezing the > application completely. It turns out that even with screen updates disabled some calls still force the screen to update. I’m not sure which ones, but it does mean we’re unlikely to completely lock up Emacs with this. I’ve attached a new version of the patch. Eli, I left the global variable as static since as far as I can tell static global variables are still global to all threads, which is the behaviour I believe we want. These functions should only be called from the main thread anyway, Cocoa will kill the thread if GUI calls are made from non‐main threads. If it definitely shouldn’t be static, what should I do with it? I moved the call to ns_enable_screen_updates in unwind_redisplay as that’s where the double buffering code appears to unblock updates. -- Alan Third --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Fix-frame-resize-flicker-on-macOS-bug-30699.patch" >From 823298202face05009808d2f00e2faa711c3882f Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sat, 10 Mar 2018 00:09:09 +0000 Subject: [PATCH v2] Fix frame resize flicker on macOS (bug#30699) * src/nsterm.h (ns_enable_screen_updates): New function. * src/nsterm.m (ns_enable_screen_updates): (ns_disable_screen_updates): New functions. (disable_screen_updates_count): Count of number of times we've called NSDisableScreenUpdates. (x_set_window_size): Disable screen updates when not in a live resize loop. * src/xdisp.c (redisplay_internal): Reenable screen updates when redisplay doesn't complete due to a popup. (unwind_redisplay): Reenable screen updates. --- src/nsterm.h | 3 +++ src/nsterm.m | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/xdisp.c | 16 +++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/nsterm.h b/src/nsterm.h index 8b985930ec..df59a7dbd9 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1160,6 +1160,9 @@ extern void ns_release_autorelease_pool (void *); extern const char *ns_get_defaults_value (const char *key); extern void ns_init_locale (void); +#ifdef NS_IMPL_COCOA +extern void ns_enable_screen_updates (void); +#endif /* in nsmenu */ extern void update_frame_tool_bar (struct frame *f); diff --git a/src/nsterm.m b/src/nsterm.m index 75e0b837c6..45367dd36f 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -288,6 +288,9 @@ - (NSColor *)colorUsingDefaultColorSpace static BOOL ns_fake_keydown = NO; #ifdef NS_IMPL_COCOA static BOOL ns_menu_bar_is_hidden = NO; + +/* The number of times NSDisableScreenUpdates has been called. */ +static int disable_screen_updates_count = 0; #endif /*static int debug_lock = 0; */ @@ -727,6 +730,40 @@ Free a pool and temporary objects it refers to (callable from C) } +#ifdef NS_IMPL_COCOA +/* Disabling screen updates can be used to make several actions appear + "atomic" to the end user. It seems some actions can still update + the display, though. + + When we re-enable screen updates the number of calls to + NSEnableScreenUpdates should match the number to + NSDisableScreenUpdates. + + We use this to prevent the user seeing a blank frame after it has + been resized. x_set_window_size disables updates and when + redisplay compeltes unwind_redisplay enables them again + (bug#30699). */ + +static void +ns_disable_screen_updates (void) +{ + NSDisableScreenUpdates (); + disable_screen_updates_count++; +} + +void +ns_enable_screen_updates (void) +/* Re-enable screen updates. Called from unwind_redisplay. */ +{ + while (disable_screen_updates_count > 0) + { + NSEnableScreenUpdates (); + disable_screen_updates_count--; + } +} +#endif + + static BOOL ns_menu_bar_should_be_hidden (void) /* True, if the menu bar should be hidden. */ @@ -1877,6 +1914,15 @@ -(void)remove block_input (); +#ifdef NS_IMPL_COCOA + /* To prevent showing the user a blank frame, stop updates being + flushed to the screen until after redisplay has completed. This + breaks live resize (resizing with a mouse), so don't do it if + we're in a live resize loop. */ + if (![view inLiveResize]) + ns_disable_screen_updates (); +#endif + if (pixelwise) { pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); diff --git a/src/xdisp.c b/src/xdisp.c index a97d4db607..4778f532cd 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -13918,7 +13918,15 @@ redisplay_internal (void) #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) if (popup_activated ()) - return; + { +#ifdef NS_IMPL_COCOA + /* On macOS we may have disabled screen updates due to window + resizing. We should re-enable them so the popup can be + displayed. */ + ns_enable_screen_updates (); +#endif + return; + } #endif /* I don't think this happens but let's be paranoid. */ @@ -14722,6 +14730,12 @@ unwind_redisplay (void) { redisplaying_p = false; unblock_buffer_flips (); +#ifdef NS_IMPL_COCOA + /* On macOS we may have disabled screen updates due to window + resizing. When redisplay completes we want to re-enable + them. */ + ns_enable_screen_updates (); +#endif } -- 2.16.1 --tKW2IUtsqtDRztdT--