From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#40200: [PATCH] Fix NS frame resizing issues (bug#40200, bug#28872) Date: Wed, 25 Mar 2020 23:28:44 +0100 (CET) Message-ID: <20200325222841.GA60879@breton.holly.idiocy.org> References: <20200323235432.GA24426@breton.holly.idiocy.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="49758"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 40200@debbugs.gnu.org, 28872@debbugs.gnu.org, aaronjensen@gmail.com To: Andrii Kolomoiets Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 25 23:29:20 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHEWW-000CpV-8Y for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Mar 2020 23:29:20 +0100 Original-Received: from localhost ([::1]:44044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHEWU-0005pi-9W for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Mar 2020 18:29:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56770) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHEWH-0005pW-Ul for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2020 18:29:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHEWG-00037O-3d for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2020 18:29:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51991) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHEWF-00036S-0b for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2020 18:29:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jHEWE-0002GK-UO for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2020 18:29:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Mar 2020 22:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40200 X-GNU-PR-Package: emacs Original-Received: via spool by 40200-submit@debbugs.gnu.org id=B40200.15851753388679 (code B ref 40200); Wed, 25 Mar 2020 22:29:02 +0000 Original-Received: (at 40200) by debbugs.gnu.org; 25 Mar 2020 22:28:58 +0000 Original-Received: from localhost ([127.0.0.1]:57963 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHEWA-0002Fp-20 for submit@debbugs.gnu.org; Wed, 25 Mar 2020 18:28:58 -0400 Original-Received: from mailout-l3b-97.contactoffice.com ([212.3.242.97]:47074) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHEW6-0002FV-Gt; Wed, 25 Mar 2020 18:28:55 -0400 Original-Received: from smtpauth1.co-bxl (smtpauth1.co-bxl [10.2.0.15]) by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id F3F01118; Wed, 25 Mar 2020 23:28:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1585175328; s=20200222-6h9o; d=idiocy.org; i=alan@idiocy.org; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:In-Reply-To; l=9494; bh=16JvBZzqRRHIDuv0KRqaqCGHrMEWArCfItGDWUptCUw=; b=m+/iLvUAev3fLdaue9vydMrHzPvsUxbV5+cOtStmcnMW++n9fTiW6BW7W5150OL2 bxLpMMuQZKHxEgvTCPE1o4hSuPwEHxBMwztKDEfHHkkJ92lOAp9lxhYff997/ktQtRi ur3ql/IzKtzZiTMGUPXt2ziec37+F2VxtGH3S3+WhXjongnAhe9fw9pSIQWU7lTPVgE 3xQBsPdi+qMZv7fCK3U3d88Ao3p//PI5fFiPj9TRzTRBuFT1lHRh9BVo4j7v/2HksT0 iQ0fBUQzIfoRnrkmHl54EtEtK4c6isGF7IIlJetWryicOHDa97Hy+AySLnQ2KObiMyS R4ivBP8HOA== Original-Received: by smtp.mailfence.com with ESMTPA ; Wed, 25 Mar 2020 23:28:43 +0100 (CET) Original-Received: by idiocy.org (Postfix, from userid 501) id DA0552020A37ED; Wed, 25 Mar 2020 22:28:41 +0000 (GMT) Mail-Followup-To: Alan Third , Andrii Kolomoiets , 40200@debbugs.gnu.org, 28872@debbugs.gnu.org, aaronjensen@gmail.com Content-Disposition: inline In-Reply-To: <20200323235432.GA24426@breton.holly.idiocy.org> X-ContactOffice-Account: com:241649512 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: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177738 Archived-At: * src/nsmenu.m (update_frame_tool_bar): Remove reference to updateFrameSize. * src/nsterm.h: Remove definition of updateFrameSize. * src/nsterm.m (ns_set_window_size): (ns_set_undecorated): ([EmacsView windowDidResize:]): ([EmacsView windowDidExitFullScreen]): (ns_judge_scroll_bars): Remove references to updateFrameSize. ([EmacsView dealloc]): Unset resize notification. ([EmacsView updateFrameSize:]): Remove function. ([EmacsView viewWillStartLiveResize]): ([EmacsView viewDidResize]): New functions. ([EmacsView initFrameFromEmacs:]): Set up resize notification. ([EmacsView toggleFullScreen:]): Set frame to the size of the contentview, not the whole window, and remove reference to updateFrameSize. --- src/nsmenu.m | 2 - src/nsterm.h | 1 - src/nsterm.m | 191 ++++++++++++++++++++++----------------------------- 3 files changed, 81 insertions(+), 113 deletions(-) diff --git a/src/nsmenu.m b/src/nsmenu.m index 67f9a45a40..b7e4cbd565 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1141,8 +1141,6 @@ - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f } #endif - if (oldh != FRAME_TOOLBAR_HEIGHT (f)) - [view updateFrameSize:YES]; if (view->wait_for_tool_bar && FRAME_TOOLBAR_HEIGHT (f) > 0) { view->wait_for_tool_bar = NO; diff --git a/src/nsterm.h b/src/nsterm.h index 8396a542f7..c454c1ff36 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -462,7 +462,6 @@ #define NS_DRAW_TO_BUFFER 1 - (void) setWindowClosing: (BOOL)closing; - (EmacsToolbar *) toolbar; - (void) deleteWorkingText; -- (void) updateFrameSize: (BOOL) delay; - (void) handleFS; - (void) setFSValue: (int)value; - (void) toggleFullScreen: (id) sender; diff --git a/src/nsterm.m b/src/nsterm.m index 04fc051223..41780c9a42 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1864,7 +1864,6 @@ Hide the window (X11 semantics) [window setFrame: wr display: YES]; - [view updateFrameSize: NO]; unblock_input (); } @@ -1913,7 +1912,6 @@ Hide the window (X11 semantics) so some key presses (TAB) are swallowed by the system. */ [window makeFirstResponder: view]; - [view updateFrameSize: NO]; unblock_input (); } } @@ -5024,9 +5022,6 @@ in certain situations (rapid incoming events). if ([view judge]) removed = YES; } - - if (removed) - [eview updateFrameSize: NO]; } /* ========================================================================== @@ -6198,6 +6193,13 @@ - (void) setWindowClosing: (BOOL)closing - (void)dealloc { NSTRACE ("[EmacsView dealloc]"); + + /* Clear the view resize notification. */ + [[NSNotificationCenter defaultCenter] + removeObserver:self + name:NSViewFrameDidChangeNotification + object:nil]; + [toolbar release]; if (fs_state == FULLSCREEN_BOTH) [nonfs_window release]; @@ -7039,103 +7041,6 @@ - (BOOL)windowShouldClose: (id)sender return NO; } -- (void) updateFrameSize: (BOOL) delay -{ - NSWindow *window = [self window]; - NSRect wr = [window frame]; - int extra = 0; - int oldc = cols, oldr = rows; - int oldw = FRAME_PIXEL_WIDTH (emacsframe); - int oldh = FRAME_PIXEL_HEIGHT (emacsframe); - int neww, newh; - - NSTRACE ("[EmacsView updateFrameSize:]"); - NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh)); - NSTRACE_RECT ("Original frame", wr); - NSTRACE_MSG ("Original columns: %d", cols); - NSTRACE_MSG ("Original rows: %d", rows); - - if (! [self isFullscreen]) - { - int toolbar_height; -#ifdef NS_IMPL_GNUSTEP - // GNUstep does not always update the tool bar height. Force it. - if (toolbar && [toolbar isVisible]) - update_frame_tool_bar (emacsframe); -#endif - - toolbar_height = FRAME_TOOLBAR_HEIGHT (emacsframe); - if (toolbar_height < 0) - toolbar_height = 35; - - extra = FRAME_NS_TITLEBAR_HEIGHT (emacsframe) - + toolbar_height; - } - - if (wait_for_tool_bar) - { - /* The toolbar height is always 0 in fullscreen and undecorated - frames, so don't wait for it to become available. */ - if (FRAME_TOOLBAR_HEIGHT (emacsframe) == 0 - && FRAME_UNDECORATED (emacsframe) == false - && ! [self isFullscreen]) - { - NSTRACE_MSG ("Waiting for toolbar"); - return; - } - wait_for_tool_bar = NO; - } - - neww = (int)wr.size.width - emacsframe->border_width; - newh = (int)wr.size.height - extra; - - NSTRACE_SIZE ("New size", NSMakeSize (neww, newh)); - NSTRACE_MSG ("FRAME_TOOLBAR_HEIGHT: %d", FRAME_TOOLBAR_HEIGHT (emacsframe)); - NSTRACE_MSG ("FRAME_NS_TITLEBAR_HEIGHT: %d", FRAME_NS_TITLEBAR_HEIGHT (emacsframe)); - - cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (emacsframe, neww); - rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (emacsframe, newh); - - if (cols < MINWIDTH) - cols = MINWIDTH; - - if (rows < MINHEIGHT) - rows = MINHEIGHT; - - NSTRACE_MSG ("New columns: %d", cols); - NSTRACE_MSG ("New rows: %d", rows); - - if (oldr != rows || oldc != cols || neww != oldw || newh != oldh) - { - NSView *view = FRAME_NS_VIEW (emacsframe); - - change_frame_size (emacsframe, - FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww), - FRAME_PIXEL_TO_TEXT_HEIGHT (emacsframe, newh), - 0, delay, 0, 1); - SET_FRAME_GARBAGED (emacsframe); - cancel_mouse_face (emacsframe); - - /* The next two lines set the frame to the same size as we've - already set above. We need to do this when we switch back - from non-native fullscreen, in other circumstances it appears - to be a noop. (bug#28872) */ - wr = NSMakeRect (0, 0, neww, newh); - [view setFrame: wr]; -#ifdef NS_DRAW_TO_BUFFER - [self createDrawingBuffer]; -#endif - - // To do: consider using [NSNotificationCenter postNotificationName:]. - [self windowDidMove: // Update top/left. - [NSNotification notificationWithName:NSWindowDidMoveNotification - object:[view window]]]; - } - else - { - NSTRACE_MSG ("No change"); - } -} - (NSSize)windowWillResize: (NSWindow *)sender toSize: (NSSize)frameSize /* Normalize frame to gridded text size. */ @@ -7277,15 +7182,21 @@ - (void)windowDidResize: (NSNotification *)notification sz = [self windowWillResize: theWindow toSize: sz]; #endif /* NS_IMPL_GNUSTEP */ - if (cols > 0 && rows > 0) - { - [self updateFrameSize: YES]; - } - ns_send_appdefined (-1); } #ifdef NS_IMPL_COCOA +- (void)viewWillStartLiveResize +{ + NSTRACE ("[EmacsView viewWillStartLiveResize]"); + + /* We just want a blank frame during live resizes. Redisplaying the + contents is too slow, and stretching the contents looks + weird. */ + ns_clear_frame (emacsframe); +} + + - (void)viewDidEndLiveResize { NSTRACE ("[EmacsView viewDidEndLiveResize]"); @@ -7302,6 +7213,60 @@ - (void)viewDidEndLiveResize #endif /* NS_IMPL_COCOA */ +- (void)viewDidResize:(NSNotification *)notification +{ + NSRect frame = [self frame]; + int oldw, oldh; + int neww, newh; + +#ifdef NS_DRAW_TO_BUFFER + CGFloat scale = [[self window] backingScaleFactor]; + oldw = (CGFloat)CGBitmapContextGetWidth (drawingBuffer) / scale; + oldh = (CGFloat)CGBitmapContextGetHeight (drawingBuffer) / scale; +#else + oldw = FRAME_PIXEL_WIDTH (emacsframe); + oldh = FRAME_PIXEL_HEIGHT (emacsframe); +#endif + neww = (int)NSWidth (frame); + newh = (int)NSHeight (frame); + + NSTRACE ("[EmacsView viewDidResize]"); + NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh)); + NSTRACE_SIZE ("New size", NSMakeSize (neww, newh)); + + /* Don't want to do anything when the actual view size hasn't + changed. */ + if ((oldh == newh && oldw == neww)) + { + NSTRACE_MSG ("No change"); + return; + } + + cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (emacsframe, neww); + rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (emacsframe, newh); + + if (cols < MINWIDTH) + cols = MINWIDTH; + + if (rows < MINHEIGHT) + rows = MINHEIGHT; + + NSTRACE_MSG ("New columns: %d", cols); + NSTRACE_MSG ("New rows: %d", rows); + + change_frame_size (emacsframe, + FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww), + FRAME_PIXEL_TO_TEXT_HEIGHT (emacsframe, newh), + 0, YES, 0, 1); +#ifdef NS_DRAW_TO_BUFFER + [self createDrawingBuffer]; +#endif + ns_clear_frame (emacsframe); + SET_FRAME_GARBAGED (emacsframe); + cancel_mouse_face (emacsframe); +} + + - (void)windowDidBecomeKey: (NSNotification *)notification /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */ { @@ -7456,6 +7421,13 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f [self initWithFrame: r]; [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + /* Set up view resize notifications. */ + [self setPostsFrameChangedNotifications:YES]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector (viewDidResize:) + name:NSViewFrameDidChangeNotification object:nil]; + FRAME_NS_VIEW (f) = self; emacsframe = f; #ifdef NS_IMPL_COCOA @@ -7902,7 +7874,6 @@ - (void)windowDidExitFullScreen /* provided for direct calls */ { [toolbar setVisible:YES]; update_frame_tool_bar (emacsframe); - [self updateFrameSize:YES]; [[self window] display]; } else @@ -8115,11 +8086,11 @@ - (void)toggleFullScreen: (id)sender // send notifications. [self windowWillExitFullScreen]; - [fw setFrame: [w frame] display:YES animate:ns_use_fullscreen_animation]; + [fw setFrame:[[w contentView] frame] + display:YES animate:ns_use_fullscreen_animation]; [fw close]; [w makeKeyAndOrderFront:NSApp]; [self windowDidExitFullScreen]; - [self updateFrameSize:YES]; } } -- 2.24.0 -- Alan Third