unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16097: [PATCH] Treat windows on other spaces as not visible in Cocoa
@ 2013-12-10  1:42 David Benjamin
  2020-08-12 22:34 ` Stefan Kangas
  2022-01-26 16:46 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 19+ messages in thread
From: David Benjamin @ 2013-12-10  1:42 UTC (permalink / raw)
  To: 16097


[-- Attachment #1.1: Type: text/plain, Size: 1123 bytes --]

Here's a patch for something that's been bugging me. This makes Cmd-` cycle
through only the current space's windows, which is consistent with other
programs on OS X. It also matches the behavior of other-frame on X11 for
window managers that implement virtual desktops by mapping and unmapping
windows. The patch is attached.

It's not perfect; if you go into Mission Control or so and move a window
onto another space without switching spaces, it won't notice until you
switch spaces again. I wasn't able to find a notification to listen to;
it'd be nice to replace the visible field in a frame with some virtual call
that, in Cocoa, would just call out to [win isVisible] and [win
isOnActiveSpace], but that'd be a more invasive change. It also doesn't fix
the behavior where closing the last window on a space warps you to a window
on another space. I'm not sure yet what's causing that.

As far as copyright goes, if this is a large enough change to matter (a
decent chunk of the diff is just moving some code around), I'm a Google
employee. I'm told we already have an agreement on file with the FSF.

David Benjamin

[-- Attachment #1.2: Type: text/html, Size: 1293 bytes --]

[-- Attachment #2: 0001-In-nsterm-update-frame-visibility-on-space-change-an.patch --]
[-- Type: application/octet-stream, Size: 5718 bytes --]

From 3482a017935469aa2b6d5d759bfcf0446c56dc1f Mon Sep 17 00:00:00 2001
From: David Benjamin <davidben@google.com>
Date: Sat, 9 Nov 2013 19:01:00 -0500
Subject: [PATCH] In nsterm, update frame visibility on space change and
 application hide/unhide. This makes other-frame cycle through windows
 correctly.

* nsterm.m (updateVisibility:): New function from code in
windowDidMiniaturize and windowDidDeminiaturize.
(windowDidMiniaturize:, windowDidDeminiaturize:): Call updateVisibility.
(initFrameFromEmacs:): Register for notifications of application
hide/unhide and, on Cocoa, space changes.
(dealloc): Clean up notifications.

* nsterm.h (EmacsView): Declaration for updateVisibility.
---
 src/ChangeLog | 11 ++++++++
 src/nsterm.h  |  1 +
 src/nsterm.m  | 90 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 85 insertions(+), 17 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 17ea85d..e261b7b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2013-12-08  David Benjamin  <davidben@google.com>
+
+	* nsterm.m (updateVisibility:): New function from code in
+	windowDidMiniaturize and windowDidDeminiaturize.
+	(windowDidMiniaturize:, windowDidDeminiaturize:): Call
+	updateVisibility.
+	(initFrameFromEmacs:): Register for notifications of application
+	hide/unhide and, on Cocoa, space changes.
+	(dealloc): Clean up notifications.
+	* nsterm.h (EmacsView): Declaration for updateVisibility.
+
 2013-12-08  Jan Djärv  <jan.h.d@swipnet.se>
 
 	* nsterm.m (updateFrameSize:): Fix GNUStep toolbar not updating.
diff --git a/src/nsterm.h b/src/nsterm.h
index 0215f13..da9907f 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -173,6 +173,7 @@ typedef float EmacsCGFloat;
 #ifdef HAVE_NATIVE_FS
 - (void) updateCollectionBehaviour;
 #endif
+- (void) updateVisibility: (NSNotification *)notification;
 
 #ifdef NS_IMPL_GNUSTEP
 - (void)windowDidMove: (id)sender;
diff --git a/src/nsterm.m b/src/nsterm.m
index 9c87923..3bbcf08 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4932,6 +4932,21 @@ not_in_argv (NSString *arg)
 - (void)dealloc
 {
   NSTRACE (EmacsView_dealloc);
+  [[NSNotificationCenter defaultCenter]
+      removeObserver: self
+                name: NSApplicationDidHideNotification
+              object: nil];
+  [[NSNotificationCenter defaultCenter]
+      removeObserver: self
+                name: NSApplicationDidUnhideNotification
+              object: nil];
+#if defined(NS_IMPL_COCOA) && \
+  MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+  [[[NSWorkspace sharedWorkspace] notificationCenter]
+    removeObserver: self
+              name: NSWorkspaceActiveSpaceDidChangeNotification
+            object: nil];
+#endif /* NS_IMPL_COCOA && >= MAC_OS_X_VERSION_10_6 */
   [toolbar release];
   if (fs_state == FULLSCREEN_BOTH)
     [nonfs_window release];
@@ -6037,6 +6052,27 @@ if (cols > 0 && rows > 0)
   [NSApp registerServicesMenuSendTypes: ns_send_types
                            returnTypes: nil];
 
+  /* Update visibility state on application hide and unhide. */
+  [[NSNotificationCenter defaultCenter]
+      addObserver: self
+         selector: @selector (updateVisibility:)
+             name: NSApplicationDidHideNotification
+           object: nil];
+  [[NSNotificationCenter defaultCenter]
+      addObserver: self
+         selector: @selector (updateVisibility:)
+             name: NSApplicationDidUnhideNotification
+           object: nil];
+
+#if defined(NS_IMPL_COCOA) && \
+  MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+  [[[NSWorkspace sharedWorkspace] notificationCenter]
+    addObserver: self
+       selector: @selector (updateVisibility:)
+           name: NSWorkspaceActiveSpaceDidChangeNotification
+         object: nil];
+#endif /* NS_IMPL_COCOA && >= MAC_OS_X_VERSION_10_6 */
+
   ns_window_num++;
   return self;
 }
@@ -6143,18 +6179,7 @@ if (cols > 0 && rows > 0)
 - (void)windowDidDeminiaturize: sender
 {
   NSTRACE (windowDidDeminiaturize);
-  if (!emacsframe->output_data.ns)
-    return;
-
-  SET_FRAME_ICONIFIED (emacsframe, 0);
-  SET_FRAME_VISIBLE (emacsframe, 1);
-  windows_or_buffers_changed = 63;
-
-  if (emacs_event)
-    {
-      emacs_event->kind = DEICONIFY_EVENT;
-      EV_TRAILER ((id)nil);
-    }
+  [self updateVisibility:nil];
 }
 
 
@@ -6175,16 +6200,47 @@ if (cols > 0 && rows > 0)
 - (void)windowDidMiniaturize: sender
 {
   NSTRACE (windowDidMiniaturize);
+  [self updateVisibility:nil];
+}
+
+- (void)updateVisibility: (NSNotification *)notification
+{
+  NSTRACE (updateVisibility);
   if (!emacsframe->output_data.ns)
     return;
 
-  SET_FRAME_ICONIFIED (emacsframe, 1);
-  SET_FRAME_VISIBLE (emacsframe, 0);
+  NSWindow *win = [self window];
+  BOOL on_active_space = YES;
+  if ([win respondsToSelector: @selector (isOnActiveSpace)])
+    on_active_space = [win isOnActiveSpace];
+  if (on_active_space && [win isVisible])
+    {
+      if (FRAME_VISIBLE_P (emacsframe) && !FRAME_ICONIFIED_P (emacsframe))
+        return;
 
-  if (emacs_event)
+      SET_FRAME_ICONIFIED (emacsframe, 0);
+      SET_FRAME_VISIBLE (emacsframe, 1);
+      windows_or_buffers_changed = 63;
+
+      if (emacs_event)
+        {
+          emacs_event->kind = DEICONIFY_EVENT;
+          EV_TRAILER ((id)nil);
+        }
+    }
+  else
     {
-      emacs_event->kind = ICONIFY_EVENT;
-      EV_TRAILER ((id)nil);
+      if (!FRAME_VISIBLE_P (emacsframe) && FRAME_ICONIFIED_P (emacsframe))
+        return;
+
+      SET_FRAME_ICONIFIED (emacsframe, 1);
+      SET_FRAME_VISIBLE (emacsframe, 0);
+
+      if (emacs_event)
+        {
+          emacs_event->kind = ICONIFY_EVENT;
+          EV_TRAILER ((id)nil);
+        }
     }
 }
 
-- 
1.8.3.4 (Apple Git-47)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-02-01 22:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-10  1:42 bug#16097: [PATCH] Treat windows on other spaces as not visible in Cocoa David Benjamin
2020-08-12 22:34 ` Stefan Kangas
2020-10-13  1:43   ` Lars Ingebrigtsen
2020-10-13 16:05     ` David Benjamin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-10-14  4:09       ` Lars Ingebrigtsen
2022-01-26 16:46 ` Lars Ingebrigtsen
2022-01-27 11:06   ` Robert Pluim
2022-01-27 13:59     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-27 14:23       ` Robert Pluim
2022-01-28  0:35         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-28  8:42           ` Robert Pluim
2022-01-28  8:47             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-28  8:55               ` Robert Pluim
2022-01-28 10:02                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-28 10:51                   ` Robert Pluim
2022-01-28 11:06                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found]     ` <YfMHYwc+BjAwdkke@idiocy.org>
2022-01-28  8:17       ` Robert Pluim
2022-01-29  0:16         ` Alan Third
2022-02-01 22:48     ` Alan Third

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).