Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.16.0 causes jumping to another application when Emacs child frame closes #776

Open
nohzafk opened this issue Nov 29, 2024 · 13 comments
Open
Labels
bug Something isn't working as expected help-wanted Maintainers won't work on the issue. Contribution is welcome regression The behavior changed between versions

Comments

@nohzafk
Copy link

nohzafk commented Nov 29, 2024

I encounter this problem when I upgrade to the latest aerospace 0.16.0, I confirmed that previous 0.15.2 version doesn't cause this issue.

This issue is very like #325 , the problem specifically involves Emacs child frames, which are temporary windows created for UI elements like completion menus

Behavior:

  • Emacs auto completion library creates child frame, and when it finished, Emacs deletes its child frame.
  • At this point, Aerospace loses track of which window should have focus
  • This causes incorrectly jumping focus to another application, making Emacs auto completion completely unusable.
  • Disable Aerospace, this issue disappears.

These child frame is often undecorated

(make-frame
 `((name . ,frame-name)   
   (parent-frame . ,parent)
   (undecorated . t)    
   ...))

My attempts to force focus or modify frame parameters didn't work, suggesting this is more of an Aerospace level issue

@nohzafk nohzafk added the bug Something isn't working as expected label Nov 29, 2024
@nikitabobko
Copy link
Owner

nikitabobko commented Nov 29, 2024

I have never user Emacs, which makes it hard for me to reproduce the issue.

Can you please produce elaborate steps to reproduce that would be clear for people who has never used Emacs in default Emacs configuration?

Thanks

@nohzafk
Copy link
Author

nohzafk commented Nov 30, 2024

This is a complex secnario, I've done my best to create steps to reproduce the issue.

I appreciate your effort to invest this issue. I can't bear it if I can't use Emacs.

Everything will be contained in the test directory, after testing you can just delete the test directory.

Screen Recording 2024-11-30 at 01 45 15

The screen record shows that while typing the completion menu shows up, press TAB to trigger the completion, and then the focused window jump to another application. Rollback to previous version of aerospace with the same setup, it won't hapen.

I have tested following scripts

Steps to reproduce the issue

# create the testing directory
mkdir emacs-q
cd emacs-q

# install emacs using homebrew
brew tap d12frosted/emacs-plus
brew install emacs-plus@29 --with-no-frame-refocus

# create a python virtual environment with dependences for lsp-bridge
cat > lsp-bridge.txt << EOF
epc==0.0.5
orjson==3.9.10
sexpdata==1.0.0
setuptools==69.0.2
rapidfuzz==3.6.1
paramiko==3.4.0
six==1.16.0
watchdog==5.0.3
EOF

python3 -m venv venv && venv/bin/pip install -r lsp-bridge.txt

# setup emacs

cat > init.el <<EOF
;; Disable startup screen
(setq inhibit-startup-screen t)

;; Set initial buffer to *scratch*
(setq initial-buffer-choice t)

;; Bootstrap straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;; Configure straight to use use-package
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)

;; Set *scratch* buffer to emacs-lisp-mode
(setq initial-major-mode 'emacs-lisp-mode)

;; Install required dependencies
(use-package markdown-mode
  :straight t)

(use-package yasnippet
  :straight t
  :config
  (yas-global-mode 1))

;; Install and configure lsp-bridge
(use-package lsp-bridge
  :straight '(lsp-bridge :type git
                        :host github
                        :repo "manateelazycat/lsp-bridge"
                        :files ("*.el" "*.py" "acm" "core" "langserver" "multiserver" "resources"))
  :init
  (setq lsp-bridge-python-command (expand-file-name "venv/bin/python" default-directory)))

;; Ensure *scratch* is the initial buffer
(setq inhibit-startup-buffer-menu t)

;; Add startup message to scratch buffer
(add-hook 'emacs-startup-hook
          (lambda ()
            (with-current-buffer "*scratch*"
              (lsp-bridge-mode)
              (goto-char (point-max))
              (insert "\n;; Debug: init.el loaded successfully at " (current-time-string) "\n")
              (insert ";; LSP-Bridge status: " (if (bound-and-true-p lsp-bridge-mode) "enabled" "disabled") "\n\n")
              (insert ";; With Aerospace enabled, try to type a long symbol for example \n")
              (insert "emacs-lisp-compilation-mode-syntax-table\n\n")
              (insert ";; while typing the completion menu will showup and press TAB to trigger the completion \n")
              (insert ";;observe that the focused window will jump to the next application window after pressing TAB.\n")
              (insert ";;This will also happen when you are typing fast.\n")
              (insert "\n")
              (goto-char (point-max)))))
EOF

start emacs to test

With aerospace 0.16.0 enabled, start the emacs.

Emacs will download all the dependecies to the testing directory, if you see warning on Emacs, just ignore it.

emacs --init-directory=. -Q -l init.el

Steps to cleanup after testing

brew uninstall emacs-plus@29
brew untap d12frosted/emacs-plus

remove the testing directory

@goncalvesnelson
Copy link

Hi!
I have the same issue as @nohzafk on emacs-plus@30, after the auto-completion frame closes, the focus changes to another window on the same workspace.

@nohzafk
Copy link
Author

nohzafk commented Dec 9, 2024

I cloud not figure out the issue, right now I just use aerospace 0.15.2, and it works fine 🙃

@dhruvasagar
Copy link

I get this issue all the time and it's incredibly annoying! Any work around would be appreciated!

@squiter
Copy link

squiter commented Feb 11, 2025

I have this problem as well, using emacs-plus@30 with different packages from @nohzafk example... so it seems the problem happens with whatever package that creates those child frames... for my example, it happens when using vertico-postframe.

@ldangelo
Copy link

I have this issue as well. It's so bad I had to stop using aerospace and use Raycast instead. I prefer aerospace but this one is a deal breaker. I'll be in the middle of writing code and autocomplete popsup (as it should) and aerospace switches windows often to another workspace so I can't even see the completion candidates.

@khorser
Copy link

khorser commented Feb 14, 2025

From what I can see that frame is recognized as a dialog, unfortunately I'm not familiar with internals of AeroSpace or Emacs to draw any conclusions out of this

org.gnu.Emacs.window.35507 windowId: 35507
org.gnu.Emacs.window.35507 workspace: 1
org.gnu.Emacs.window.35507 treeNodeParent: Workspace(name: '1', isVisible: 'true', isEffectivelyEmpty: 'false', doKeepAlive: 'true')
org.gnu.Emacs.window.35507 recognizedAsDialog: true
org.gnu.Emacs.window.35507 AXTitle: Optional(posframe)
org.gnu.Emacs.window.35507 AXRole: Optional(AXWindow)
org.gnu.Emacs.window.35507 AXSubrole: Optional(AXFloatingWindow)
org.gnu.Emacs.window.35507 AXFocused: Optional(0)
org.gnu.Emacs.window.35507 AXFullScreen: Optional(0)
org.gnu.Emacs.window.35507 AXFrame: Optional(<AXValue 0x600003db4940> {value = x:113.000000 y:690.000000 w:1420.000000 h:328.000000 type = kAXValueCGRectType})
org.gnu.Emacs.window.35507 AXPosition: Optional(<AXValue 0x6000026118c0> {value = x:113.000000 y:690.000000 type = kAXValueCGPointType})
org.gnu.Emacs.window.35507 AXGrowArea: nil
org.gnu.Emacs.window.35507 AXMinimizeButton: nil
org.gnu.Emacs.window.35507 AXDocument: nil
org.gnu.Emacs.window.35507 AXSections: [
org.gnu.Emacs.window.35507 ]
org.gnu.Emacs.window.35507 AXCloseButton: nil
org.gnu.Emacs.window.35507 AXMain: Optional(0)
org.gnu.Emacs.window.35507 AXActivationPoint: Optional(<AXValue 0x6000026118c0> {value = x:-1.000000 y:1108.000000 type = kAXValueCGPointType})
org.gnu.Emacs.window.35507 AXFullScreenButton: nil
org.gnu.Emacs.window.35507 AXProxy: nil
org.gnu.Emacs.window.35507 AXDefaultButton: nil
org.gnu.Emacs.window.35507 AXMinimized: Optional(0)
org.gnu.Emacs.window.35507 AXParent: Optional(<AXUIElement Application 0x6000026111d0> {pid=63867})
org.gnu.Emacs.window.35507 AXTitleUIElement: nil
org.gnu.Emacs.window.35507 AXCancelButton: nil
org.gnu.Emacs.window.35507 AXModal: Optional(0)
org.gnu.Emacs.window.35507 AXZoomButton: nil
org.gnu.Emacs.window.35507 AXSize: Optional(<AXValue 0x6000026111d0> {value = w:1420.000000 h:328.000000 type = kAXValueCGSizeType})
org.gnu.Emacs.window.35507 AXToolbarButton: nil
org.gnu.Emacs.window.35507 Ignored: AXChildrenInNavigationOrder, AXChildren, AXRoleDescription
org.gnu.Emacs              AXRole: Optional(AXApplication)
org.gnu.Emacs              AXTitle: Optional(Emacs)
org.gnu.Emacs              AXFunctionRowTopLevelElements: [
org.gnu.Emacs              ]
org.gnu.Emacs              AXFrame: nil
org.gnu.Emacs              AXFocusedUIElement: AXUIElement(windowId=35504, title="", role="AXWindow", subrole="AXStandardWindow")
org.gnu.Emacs              AXFrontmost: Optional(1)
org.gnu.Emacs              AXExtrasMenuBar: nil
org.gnu.Emacs              AXMainWindow: AXUIElement(windowId=35504, title="", role="AXWindow", subrole="AXStandardWindow")
org.gnu.Emacs              AXFocusedWindow: AXUIElement(windowId=35504, title="", role="AXWindow", subrole="AXStandardWindow")
org.gnu.Emacs              AXMenuBar: Optional(<AXUIElement 0x6000026396b0> {pid=63867})
org.gnu.Emacs              AXWindows: [
org.gnu.Emacs                  AXUIElement(windowId=35507, title="posframe", role="AXWindow", subrole="AXFloatingWindow"),
org.gnu.Emacs                  AXUIElement(windowId=35504, title="", role="AXWindow", subrole="AXStandardWindow")
org.gnu.Emacs              ]
org.gnu.Emacs              AXSize: nil
org.gnu.Emacs              AXPosition: nil
org.gnu.Emacs              Ignored: AXChildren, AXChildrenInNavigationOrder, AXEnhancedUserInterface, AXPreferredLanguage, AXRoleDescription, AXHidden

@yspreen
Copy link
Contributor

yspreen commented Feb 14, 2025

@ldangelo I'd be curios how you switched to Raycast. it doesn't have any space support does it? just window sizing?

@ldangelo
Copy link

@ldangelo I'd be curios how you switched to Raycast. it doesn't have any space support does it? just window sizing?

No space support. It's not as good as aerospace, but it doesn't switch windows unexpectedly. I am testing out a new emacs build that has --with-no-frame-refocus turned on. I'll report back if it has any effect on this issue.

@dhruvasagar
Copy link

@yspreen It (Raycast) does have support for moving windows between spaces.

@nikitabobko nikitabobko added the regression The behavior changed between versions label Feb 17, 2025
@ldangelo
Copy link

It seems as if building emacs with --with-no-frame-refocus has resolved the issue for me. Still testing but it hasn't happened with the new build. Have not looked into what that flag actually does yet.

@nikitabobko nikitabobko added the help-wanted Maintainers won't work on the issue. Contribution is welcome label Feb 23, 2025
@nikitabobko
Copy link
Owner

I am still too lazy to reproduce this bug due to my restricted Emacs knowledge. Everyone is welcome to git-bisect this issue in range of v0.15.2-Beta..v0.16.0-Beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected help-wanted Maintainers won't work on the issue. Contribution is welcome regression The behavior changed between versions
Projects
None yet
Development

No branches or pull requests

8 participants