From ed901d4219b996a72e5944c6b959086ef2b8431d Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sun, 31 Jan 2021 20:19:53 +0000 Subject: [PATCH] Fix flicker when resizing NS frame programmatically (bug#46155) ; Incidentally fixes bug#21326. * src/nsterm.m ([EmacsView viewWillDraw]): New function. --- src/nsterm.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/nsterm.m b/src/nsterm.m index 1b2328628e..8f2b61a165 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -8452,6 +8452,33 @@ - (void)copyRect:(NSRect)srcRect to:(NSRect)dstRect } +#ifdef NS_IMPL_COCOA +/* If the frame has been garbaged but the toolkit wants to draw, for + example when resizing the frame, we end up with a blank screen. + Sometimes this results in an unpleasant flicker, so try to + redisplay before drawing. */ +- (void)viewWillDraw +{ + if (FRAME_GARBAGED_P (emacsframe)) + { + /* If there is IO going on when redisplay is run here Emacs + crashes. I think it's because this code will always be run + within the run loop and for whatever reason processing input + is dangerous. This technique was stolen wholesale from + nsmenu.m and seems to work. */ + bool owfi = waiting_for_input; + waiting_for_input = 0; + block_input (); + + redisplay(); + + unblock_input (); + waiting_for_input = owfi; + } +} +#endif + + #ifdef NS_DRAW_TO_BUFFER - (BOOL)wantsUpdateLayer { -- 2.29.2