From 08787800a3d668fad2d8fcc8815f33a30bc78687 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 23 May 2023 23:04:52 +0100 Subject: [PATCH] fix(macos): hide all child frames when toggling non-native fullscreen For a couple of years now, there's been a bug on macOS with the non-native fullscreen implementation. When enabling fullscreen, any child-frames created by packages like lsp-ui, company-box, posframe, etc. all re-appear on top of the fullscreened frame, and stay there until you re-trigger whatever package/command that created the childframe originally. This works around this issue by simply closing all child frames when toggling non-native fullscreen. --- core/siren-core-macos.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/siren-core-macos.el b/core/siren-core-macos.el index 798f2e3..2c5a3c9 100644 --- a/core/siren-core-macos.el +++ b/core/siren-core-macos.el @@ -39,7 +39,28 @@ ;; Fix the default default-directory value. (if (string= default-directory "/") - (setq default-directory "~/"))) + (setq default-directory "~/")) + + (defun delete-child-frames (&optional frame) + "Close all child frames of FRAME. +If FRAME is nil, it defaults to the currently selected frame." + (interactive) + (let ((frame (or frame (selected-frame)))) + (dolist (f (frame-list)) + (when (eq (frame-parent f) frame) + (delete-frame f))))) + + (defun siren-toggle-frame-fullscreen-advice (&optional frame) + "If `ns-use-native-fullscreen' is not t, close all child frames of FRAME. +If FRAME is nil, it defaults to the currently selected frame." + (unless ns-use-native-fullscreen + (delete-child-frames frame))) + + ;; On macOS when using non-native fullscreen, child-frames re-appear and are + ;; stuck on top of the main frame when fullscreen is enabled. This advice + ;; closes all child-frames when toggling fullscreen state to avoid this. + (advice-add 'toggle-frame-fullscreen :after + #'siren-toggle-frame-fullscreen-advice)) ;; macOS Fullscreen (requires Emacs 24.4 or later) (global-set-key (kbd "s-") 'toggle-frame-fullscreen)