From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs Subject: bug#16097: [PATCH] Treat windows on other spaces as not visible in Cocoa Date: Fri, 28 Jan 2022 09:17:24 +0100 Message-ID: <87r18se0kr.fsf@gmail.com> References: <87zgniphrc.fsf@gnus.org> <87czkdfner.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13954"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 16097@debbugs.gnu.org To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 28 09:20:25 2022 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 1nDMUZ-0003Pn-OJ for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 28 Jan 2022 09:20:23 +0100 Original-Received: from localhost ([::1]:45906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nDMUY-0005Ds-14 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 28 Jan 2022 03:20:22 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nDMSx-0004Qn-KJ for bug-gnu-emacs@gnu.org; Fri, 28 Jan 2022 03:18:44 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nDMSI-00051k-HJ for bug-gnu-emacs@gnu.org; Fri, 28 Jan 2022 03:18:35 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nDMSI-0003dK-7W for bug-gnu-emacs@gnu.org; Fri, 28 Jan 2022 03:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 28 Jan 2022 08:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16097 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 16097-submit@debbugs.gnu.org id=B16097.164335785413547 (code B ref 16097); Fri, 28 Jan 2022 08:18:02 +0000 Original-Received: (at 16097) by debbugs.gnu.org; 28 Jan 2022 08:17:34 +0000 Original-Received: from localhost ([127.0.0.1]:57242 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nDMRp-0003Vu-MY for submit@debbugs.gnu.org; Fri, 28 Jan 2022 03:17:34 -0500 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:37623) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nDMRn-0003QZ-Ts for 16097@debbugs.gnu.org; Fri, 28 Jan 2022 03:17:32 -0500 Original-Received: by mail-wr1-f41.google.com with SMTP id w11so9341660wra.4 for <16097@debbugs.gnu.org>; Fri, 28 Jan 2022 00:17:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :mime-version; bh=PoFqbtGuNoZu0gHVkbcvKP9xub25SlI1nhTff09GfYY=; b=DrAhyWq9q0utscSmsBycSEqB8emWEauVCJz4xdUYjKWcJ4syMl1n2PTgfNPLqY9s4S MaRBOFORjecC6zLzMk5pfVwhtiiUj4gBoC4x7tSe1ySiuCVYxObuEZlkWBaJmKrsJiO4 lPnFxOMg1t4xE6U3fIxAKGXLvc4ZFqz0h4+R6E9omhzPw82wxfZSl3QfuhTz1mqZeJRv bYhKpV2laeb3OpwthmZXWPyeijJUAOWJ+HDkK4JMICQCaEG5bnAQnv26qDK3Nfef0odi z2sCHEeOrraGftTlEp6aLlTElwxqxt7FBGv0hJ5B95NZ1rMsuNuR9qznCXsi9CUBMQTv P3eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version; bh=PoFqbtGuNoZu0gHVkbcvKP9xub25SlI1nhTff09GfYY=; b=L/mMLpjMiq7tGCLgFJC69NX+BJhQLfW6Vc0C6vXbaedSAqJnYAKgk4oOSrYwCfRIWf U4VzwW46EhA/etCRh2hT7wxW/d+vjrppD+KMS08r73O4LLVVBxB71cOXox+p4YWQdVvi xqV+SQl/Xain31ULQzOgmArBGKfKeCn3IyN0Xv/3hr2RXLVH+fmhmTk4SsVvG+oc8DTo LyktygibclIh3NjNIZdWHbion6voi68XFhgyyotX2qCw9vElEieZ+SkOyam+tzfNO2X2 MXVjiRpn2v5tDlhLAOw9KbpZrJJHIU2iROInzlXo11yIODFT5hGGZn8zCyvO0pgzXWaN +wng== X-Gm-Message-State: AOAM532zGdiq+vU1xO37YyDgVPT9swgXydbMvI8PPF8KjzzugBL9cdcz DMvRj8Ny2O3J6rRjIMi0Ivohxks+Kck= X-Google-Smtp-Source: ABdhPJwvxGU1Z96m8OojkEVoicd5Vs2dPhWpfaFgUU2ZZvqL950jw3SnlnZqF1efZV8utBTDcsLS2A== X-Received: by 2002:adf:eacc:: with SMTP id o12mr5829689wrn.576.1643357845780; Fri, 28 Jan 2022 00:17:25 -0800 (PST) Original-Received: from rltb ([2a01:e0a:3f3:fb50:4697:da8d:60b1:c955]) by smtp.gmail.com with ESMTPSA id n10sm5266987wrf.96.2022.01.28.00.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 00:17:24 -0800 (PST) In-Reply-To: (Alan Third's message of "Thu, 27 Jan 2022 20:58:11 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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:225420 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> On Thu, 27 Jan 2022 20:58:11 +0000, Alan Third said: Alan> On Thu, Jan 27, 2022 at 12:06:36PM +0100, Robert Pluim wrote: >> >>>>> On Wed, 26 Jan 2022 17:46:15 +0100, Lars Ingebrigtsen said: >>=20 Lars> David Benjamin writes: >> >> Here's a patch for something that's been bugging me. This makes C= md-` >> >> cycle through only the current space's windows, which is consiste= nt >> >> with other programs on OS X. It also matches the behavior of >> >> other-frame on X11 for window managers that implement virtual des= ktops >> >> by mapping and unmapping windows. The patch is attached. >>=20 Lars> Perhaps Alan has a comment here; added to the CCs. >>=20 >> Please let's apply this. Please. Pretty please. Pretty please with s= ugar on >> top. Please. >>=20 >> I=CA=BCve rebased it to master and attach it here. >>=20 >> Did I mention I like it? Alan> I'm afraid I don't much. It looks like the updateVisibility method Alan> doesn't actually do enough to replace the windowDidBecomeKey meth= od. That=CA=BCs an artifact of me screwing up the patch, I think. But it probably needs updating anyway, as Po pointed out. Alan> It also needs a good clean. For example there's a hunk that appea= rs to Alan> just be removing a single blank line and most of the #ifdef's are Alan> redundant. I guess some of the weirdness in it is just because it= 's so Alan> old. Sorry, I messed up the rebase. The attached should be better. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-other-frame-cycle-on-current-space-only-nsterm.patch >From a7054fc3d66b48161b562a8715730c002994dc4a Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 28 Jan 2022 09:11:09 +0100 Subject: [PATCH] Make other-frame cycle on current space only (nsterm) To: emacs-devel@gnu.org 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/nsterm.h | 1 + src/nsterm.m | 92 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index f027646123..db4e75641b 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -481,6 +481,7 @@ #define NSTRACE_UNSILENCE() #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - (void) updateCollectionBehavior; #endif +- (void) updateVisibility: (NSNotification *)notification; #ifdef NS_IMPL_GNUSTEP - (void)windowDidMove: (id)sender; diff --git a/src/nsterm.m b/src/nsterm.m index a3c7b55218..ce933e73eb 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -5959,6 +5959,22 @@ - (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 */ + /* Clear the view resize notification. */ [[NSNotificationCenter defaultCenter] removeObserver:self @@ -7214,6 +7230,27 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f [NSApp registerServicesMenuSendTypes: ns_send_types returnTypes: [NSArray array]]; + /* 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; } @@ -7383,18 +7420,7 @@ - (NSRect)windowWillUseStandardFrame:(NSWindow *)sender - (void)windowDidDeminiaturize: sender { NSTRACE ("[EmacsView 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]; } @@ -7415,16 +7441,48 @@ - (void)windowDidExpose: sender - (void)windowDidMiniaturize: sender { NSTRACE ("[EmacsView 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); + } } } -- 2.34.0 --=-=-= Content-Type: text/plain Robert -- --=-=-=--