emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 86bf8af 1/2: Fix NS toolbar again (bug#50534)


From: Alan Third
Subject: master 86bf8af 1/2: Fix NS toolbar again (bug#50534)
Date: Mon, 27 Sep 2021 06:01:24 -0400 (EDT)

branch: master
commit 86bf8afa45f8d8fe19c82a9351ca445bc6f0e12e
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>

    Fix NS toolbar again (bug#50534)
    
    * src/nsmenu.m (free_frame_tool_bar): Remove toolbar.
    (update_frame_tool_bar_1): New function.
    (update_frame_tool_bar): Move most of the functionality to
    update_frame_tool_bar_1.
    * src/nsterm.h: Definitions of functions and methods.
    * src/nsterm.m (ns_update_begin):
    ([EmacsView windowDidEnterFullScreen]):
    ([EmacsView windowDidExitFullScreen]): We no longer need to reset the
    toolbar visibility as that's done when we create the new fullscreen
    window.
    ([EmacsWindow initWithEmacsFrame:fullscreen:screen:]): Move the check
    for undecorated frames into createToolbar:.
    ([EmacsWindow createToolbar:]): Check whether a toolbar should be
    created, and run the toolbar update immediately.
---
 src/nsmenu.m | 35 +++++++++++++++++++++++------------
 src/nsterm.h |  5 +++++
 src/nsterm.m | 28 ++++++----------------------
 3 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/nsmenu.m b/src/nsmenu.m
index f0c5bb2..9b78643 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -995,25 +995,24 @@ free_frame_tool_bar (struct frame *f)
   /* Note: This triggers an animation, which calls windowDidResize
      repeatedly.  */
   f->output_data.ns->in_animation = 1;
-  [[[view window] toolbar] setVisible: NO];
+  [[[view window] toolbar] setVisible:NO];
   f->output_data.ns->in_animation = 0;
 
+  [[view window] setToolbar:nil];
+
   unblock_input ();
 }
 
 void
-update_frame_tool_bar (struct frame *f)
+update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar)
 /* --------------------------------------------------------------------------
     Update toolbar contents.
    -------------------------------------------------------------------------- 
*/
 {
   int i, k = 0;
-  NSWindow *window = [FRAME_NS_VIEW (f) window];
-  EmacsToolbar *toolbar = (EmacsToolbar *)[window toolbar];
 
   NSTRACE ("update_frame_tool_bar");
 
-  if (window == nil || toolbar == nil) return;
   block_input ();
 
 #ifdef NS_IMPL_COCOA
@@ -1094,13 +1093,6 @@ update_frame_tool_bar (struct frame *f)
 #undef TOOLPROP
     }
 
-  if (![toolbar isVisible] != !FRAME_EXTERNAL_TOOL_BAR (f))
-    {
-      f->output_data.ns->in_animation = 1;
-      [toolbar setVisible: FRAME_EXTERNAL_TOOL_BAR (f)];
-      f->output_data.ns->in_animation = 0;
-    }
-
 #ifdef NS_IMPL_COCOA
   if ([toolbar changed])
     {
@@ -1124,9 +1116,28 @@ update_frame_tool_bar (struct frame *f)
       [newDict release];
     }
 #endif
+
+  [toolbar setVisible:YES];
   unblock_input ();
 }
 
+void
+update_frame_tool_bar (struct frame *f)
+{
+  EmacsWindow *window = (EmacsWindow *)[FRAME_NS_VIEW (f) window];
+  EmacsToolbar *toolbar = (EmacsToolbar *)[window toolbar];
+
+  if (!toolbar)
+    {
+      [window createToolbar:f];
+      return;
+    }
+
+  if (window == nil || toolbar == nil) return;
+
+  update_frame_tool_bar_1 (f, toolbar);
+}
+
 
 /* ==========================================================================
 
diff --git a/src/nsterm.h b/src/nsterm.h
index 6d4ea77..1bedf78 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -418,6 +418,7 @@ typedef id instancetype;
 
 - (instancetype)initWithEmacsFrame:(struct frame *)f;
 - (instancetype)initWithEmacsFrame:(struct frame *)f 
fullscreen:(BOOL)fullscreen screen:(NSScreen *)screen;
+- (void)createToolbar:(struct frame *)f;
 - (void)setParentChildRelationships;
 - (NSInteger)borderWidth;
 - (BOOL)restackWindow:(NSWindow *)win above:(BOOL)above;
@@ -1148,6 +1149,10 @@ extern void ns_init_locale (void);
 
 /* in nsmenu */
 extern void update_frame_tool_bar (struct frame *f);
+#ifdef __OBJC__
+extern void update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar);
+#endif
+
 extern void free_frame_tool_bar (struct frame *f);
 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
                                                    bool keymaps,
diff --git a/src/nsterm.m b/src/nsterm.m
index 4ef20e4..3363fac 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1021,15 +1021,6 @@ ns_update_begin (struct frame *f)
 
   ns_update_auto_hide_menu_bar ();
 
-  NSToolbar *toolbar = [[FRAME_NS_VIEW (f) window] toolbar];
-  if (toolbar)
-  {
-    /* Ensure the toolbars visibility is set correctly.  */
-    BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (f) ? YES : NO;
-    if (! tbar_visible != ! [toolbar isVisible])
-      [toolbar setVisible: tbar_visible];
-  }
-
   ns_updating_frame = f;
   [view lockFocus];
 }
@@ -7401,7 +7392,6 @@ not_in_argv (NSString *arg)
     }
   else
     {
-      BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (emacsframe) ? YES : NO;
 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 \
   && MAC_OS_X_VERSION_MIN_REQUIRED <= 1070
       unsigned val = (unsigned)[NSApp presentationOptions];
@@ -7419,7 +7409,6 @@ not_in_argv (NSString *arg)
           [NSApp setPresentationOptions: options];
         }
 #endif
-      [[[self window]toolbar] setVisible:tbar_visible];
     }
 }
 
@@ -7460,14 +7449,6 @@ not_in_argv (NSString *arg)
 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
   [self updateCollectionBehavior];
 #endif
-  if (FRAME_EXTERNAL_TOOL_BAR (emacsframe))
-    {
-      [[[self window] toolbar] setVisible:YES];
-      update_frame_tool_bar (emacsframe);
-      [[self window] display];
-    }
-  else
-    [[[self window] toolbar] setVisible:NO];
 
   if (next_maximized != -1)
     [[self window] performZoom:self];
@@ -8298,8 +8279,7 @@ not_in_argv (NSString *arg)
         [self setOpaque:NO];
 
       /* toolbar support */
-      if (! FRAME_UNDECORATED (f))
-        [self createToolbar:f];
+      [self createToolbar:f];
 
       /* macOS Sierra automatically enables tabbed windows.  We can't
          allow this to be enabled until it's available on a Free system.
@@ -8316,13 +8296,17 @@ not_in_argv (NSString *arg)
 
 - (void)createToolbar: (struct frame *)f
 {
+  if (FRAME_UNDECORATED (f) || !FRAME_EXTERNAL_TOOL_BAR (f))
+    return;
+
   EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
 
   EmacsToolbar *toolbar = [[EmacsToolbar alloc]
                             initForView:view
                             withIdentifier:[NSString 
stringWithLispString:f->name]];
-  [toolbar setVisible:NO];
+
   [self setToolbar:toolbar];
+  update_frame_tool_bar_1 (f, toolbar);
 
 #ifdef NS_IMPL_COCOA
   {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]