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#28872: [PATCH v2] Fix NS frame resizing issues (bug#40200, bug#28872) Date: Thu, 26 Mar 2020 22:21:29 +0100 (CET) Message-ID: <20200326212125.GA66331@breton.holly.idiocy.org> References: 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="113988"; 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 Thu Mar 26 22:22:22 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 1jHZxG-000TWz-Lh for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Mar 2020 22:22:22 +0100 Original-Received: from localhost ([::1]:60566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHZxF-0002AY-I4 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Mar 2020 17:22:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38087) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHZwy-0002A8-A8 for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 17:22:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHZww-0002lm-JD for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 17:22:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54296) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHZww-0002ko-1m for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 17:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jHZwv-0001ka-Sa for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 17:22:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Mar 2020 21:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28872 X-GNU-PR-Package: emacs Original-Received: via spool by 28872-submit@debbugs.gnu.org id=B28872.15852577036686 (code B ref 28872); Thu, 26 Mar 2020 21:22:01 +0000 Original-Received: (at 28872) by debbugs.gnu.org; 26 Mar 2020 21:21:43 +0000 Original-Received: from localhost ([127.0.0.1]:60267 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHZwc-0001jk-24 for submit@debbugs.gnu.org; Thu, 26 Mar 2020 17:21:43 -0400 Original-Received: from mailout-l3b-97.contactoffice.com ([212.3.242.97]:38812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHZwZ-0001jN-8L; Thu, 26 Mar 2020 17:21:40 -0400 Original-Received: from smtpauth1.co-bxl (smtpauth1.co-bxl [10.2.0.15]) by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id AD2393C1; Thu, 26 Mar 2020 22:21:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1585257692; 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=10422; bh=VGVdo9HQqJE8iMOYMRCWiRNWz8KI6Pv3Epz0nGBlRLY=; b=dsVltGf0sH2llkaTj6mh6RBFj95QfyJGsK5rDrLdQfCCEuXwXCLMug8ME6G0havh B0LJlN2hasd1Az4HaQH5mPYkVSZ4bb/Xn5/C0WIh2OQ/pNwEatIjRcu0P08kr41HX5N 3+QOgNeiMGcFkk98YRi5RnV0l01ekZXWfUAUpenVlvjE1YWU5U0bYIKrKVThVmRFclM vad4IkD9/eNnyXKZfFAF/xacVPzAG0GX7OEdj40h5yMvr0UenQHB7wQ+L9wLDsIRjKn HF++AsjtTtnyD7FFksD8lTRxt5DlCNiGzTsa/xA4PZDuAqO0nc5ooa53HBIc7Z1aXg+ YGCKmd4NmQ== Original-Received: by smtp.mailfence.com with ESMTPA ; Thu, 26 Mar 2020 22:21:27 +0100 (CET) Original-Received: by idiocy.org (Postfix, from userid 501) id E6FE02020A6446; Thu, 26 Mar 2020 21:21:25 +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: 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:177761 Archived-At: * src/nsmenu.m (update_frame_tool_bar): Remove reference to updateFrameSize. * src/nsterm.h: ([EmacsView updateFrameSize]): ([EmacsView setRows:andColumns:]): Remove unused method definitions. * 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 and release buffer. ([EmacsView updateFrameSize:]): Remove function. ([EmacsView windowWillResize:toSize:]): Move some code to viewDidResize. ([EmacsView viewDidResize]): New function. ([EmacsView initFrameFromEmacs:]): Set up resize notification and move buffer creation until after the prerequisite objects are created. ([EmacsView toggleFullScreen:]): Set frame to the size of the contentview, not the whole window, and remove reference to updateFrameSize. ([EmacsView setRows:andColumns:]): Remove unused method. --- Hopefully this works better. src/nsmenu.m | 2 - src/nsterm.h | 3 - src/nsterm.m | 189 ++++++++++++++++++--------------------------------- 3 files changed, 68 insertions(+), 126 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..3c2e4c2b07 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -439,7 +439,6 @@ #define NS_DRAW_TO_BUFFER 1 #endif @public struct frame *emacsframe; - int rows, cols; int scrollbarsNeedingUpdate; EmacsToolbar *toolbar; NSRect ns_userRect; @@ -458,11 +457,9 @@ #define NS_DRAW_TO_BUFFER 1 /* Emacs-side interface */ - (instancetype) initFrameFromEmacs: (struct frame *) f; - (void) createToolbar: (struct frame *)f; -- (void) setRows: (int) r andColumns: (int) c; - (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..95ab4390a0 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,15 @@ - (void) setWindowClosing: (BOOL)closing - (void)dealloc { NSTRACE ("[EmacsView dealloc]"); + + /* Clear the view resize notification. */ + [[NSNotificationCenter defaultCenter] + removeObserver:self + name:NSViewFrameDidChangeNotification + object:nil]; + + CGContextRelease (drawingBuffer); + [toolbar release]; if (fs_state == FULLSCREEN_BOTH) [nonfs_window release]; @@ -7039,108 +7043,12 @@ - (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. */ { int extra = 0; + int cols, rows; NSTRACE ("[EmacsView windowWillResize:toSize: " NSTRACE_FMT_SIZE "]", NSTRACE_ARG_SIZE (frameSize)); @@ -7277,11 +7185,6 @@ - (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); } @@ -7302,6 +7205,51 @@ - (void)viewDidEndLiveResize #endif /* NS_IMPL_COCOA */ +- (void)viewDidResize:(NSNotification *)notification +{ + NSRect frame = [self frame]; + int oldw, oldh, neww, newh; + + if (! FRAME_LIVE_P (emacsframe)) + return; + +#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]"); + + /* Don't want to do anything when the view size hasn't changed. */ + if ((oldh == newh && oldw == neww)) + { + NSTRACE_MSG ("No change"); + return; + } + + NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh)); + NSTRACE_SIZE ("New size", NSMakeSize (neww, newh)); + + 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() */ { @@ -7463,10 +7411,6 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f maximizing_resize = NO; #endif -#ifdef NS_DRAW_TO_BUFFER - [self createDrawingBuffer]; -#endif - win = [[EmacsWindow alloc] initWithContentRect: r styleMask: (FRAME_UNDECORATED (f) @@ -7572,6 +7516,17 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f [NSApp registerServicesMenuSendTypes: ns_send_types returnTypes: [NSArray array]]; +#ifdef NS_DRAW_TO_BUFFER + [self createDrawingBuffer]; +#endif + + /* Set up view resize notifications. */ + [self setPostsFrameChangedNotifications:YES]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector (viewDidResize:) + name:NSViewFrameDidChangeNotification object:nil]; + /* macOS Sierra automatically enables tabbed windows. We can't allow this to be enabled until it's available on a Free system. Currently it only happens by accident and is buggy anyway. */ @@ -7902,7 +7857,6 @@ - (void)windowDidExitFullScreen /* provided for direct calls */ { [toolbar setVisible:YES]; update_frame_tool_bar (emacsframe); - [self updateFrameSize:YES]; [[self window] display]; } else @@ -8115,11 +8069,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]; } } @@ -8628,13 +8582,6 @@ - (instancetype)setMiniwindowImage: (BOOL) setMini } -- (void) setRows: (int) r andColumns: (int) c -{ - NSTRACE ("[EmacsView setRows:%d andColumns:%d]", r, c); - rows = r; - cols = c; -} - - (int) fullscreenState { return fs_state; -- 2.24.0 -- Alan Third