-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
neovide does not focus on launch from terminal (macOS, iTerm2) #2330
Comments
related #2324 |
I noticed this issue start to occur after updating when using Raycast. After updating Neovide when Neovide is launch from Raycast it starts in the background. I am able to work around this by including this in my vim.schedule(function()
vim.cmd "NeovideFocus"
end) |
For me, this is also the case. Launching from Finder results in the same behavior, even with all plugins disabled. Scheduling EDIT: Launching from kitty / Terminal.app works just fine! |
Seeing same behavior from iTerm2 as described above. Also note that when launching from Spotlight, the neovide window is focused, but is appended to the end of the cmd-tab switcher (same as described above when launching from a terminal), which is the opposite of most macOS applications. The focus+stacking issue is likely separate from the cmd-tab issue. |
I can reproduce it as well. It gets focused properly when launched from Raycast or Launchpad (after symlinking from /opt/homebrew/Cellar/neovide/* to $HOME/Applications) but doesn't focus up when starting from WezTerm nor iTerm2 UPDATE1: UPDATE2: It has something to do with how macOS handles CLI binaries vs Neovide.app files. Launching
|
I did some digging about this and looks like it is general macOS problem/default behaviour. For example when launching wezterm from terminal it behaves the same way as neovide does. My current workaround for it:
|
FWIW, adding a delay before calling if exists('g:neovide')
autocmd VimEnter * call timer_start(20, {tid -> execute('NeovideFocus')})
endif This seems like a fairly effective workaround while the application itself doesn't currently request focus on startup. |
Works great! Here is Lua version: if vim.g.neovide then
vim.defer_fn(function()
vim.cmd("NeovideFocus")
end, 25)
end |
I have a potential fix for this here: It would be good if someone could test it. |
@fredizzimo I'm unfortunately still seeing this after #2562, with a locally built neovide. I'm also seeing the same behaviour as @nazriel, the issue only happens when running If it helps, Alacritty doesn't have this problem and they're also using winit afaik. |
Ok, I will re-open this. The list bugs that PR fixed was more of a wishlist than scientific proof, based on the winit documentation:
|
For anyone interested, I solved this by disabling secure keyboard in iTerm2. See this also: https://groups.google.com/g/iterm2-discuss/c/Fg6jOm-PrHo |
The workaround (scheduling NeovideFocus) doesn’t work for me, sadly. I get the “started but not focused” in Terminal.app, iTerm2, and when launching an additional instance from Neovide itself. When launching via Finder or with |
Are you all using homebrew version of Neovide? There's a chance that there's some issue with the recipe there. The recipe is also not updated with our new way of packaging https://github.com/neovide/neovide/tree/main/macos-builder This is what the recipe does: https://github.com/Homebrew/homebrew-core/blob/552d255be9d93db38f7c602345e3a9d0bc3e30db/Formula/n/neovide.rb#L40 |
I am. However, I just uninstalled the Homebrew version and downloaded the Github release and get the same behavior when using the |
How did you run the |
Exactly, using |
Additional data point: If I build Neovide locally using the macOS instructions at https://neovide.dev/installation.html, then:
|
In that case, there's probably something wrong with our The reference is here |
Actually, this is probably not something we can fix:
Source: https://iterm2.com/faq.html, and various forum posts and this post #2330 (comment), by @ruibinx |
I believe that is just a distraction:
|
I do not think |
This isn't a Secure Keyboard issue - I get the same behaviour of neovide opening behind the terminal window when using Alacritty (what I normally use), iTerm with Secure Keyboard enabled or disabled, or the default Terminal app. As I mentioned in #2330 (comment), and as mentioned by a few others, this only happens when running the binary inside the When running the binary from Also what I meant by "Alacritty doesn't have this problem" in #2330 (comment) is that the Alacritty app itself opens in the foreground when launched from a terminal, even when running the binary inside the |
Ah I see now that the new macos-builder script doesn't use cargo-bundle - but I've just tested the So I imagine the problem is probably with the Also since the macos-builder script doesn't use What would be great is if there was a script that only builds the .app and doesn't package it into a dmg - essentially |
Well I've just run the So I still don't think Secure Input is the problem, but who knows. Either way, "disabling secure input" doesn't fix the issue, and the problem occurs when using Alacritty which doesn't support Secure Input at all. Secure Input is not a system-wide setting, it's a function that "provide[s] a secure means for a process to protect keyboard input to a custom data entry field". It could be related to the app not being signed/notarised though - I have come across annoying issues similar to this in an app I was working on that appeared to occur simply because the app wasn't properly signed. However in that case everything worked fine when I built the app locally, and the issues only appeared when building the app somewhere else and copying it over. Here the issue happens every time, no matter where/how the app is built. I've also just built Alacritty locally to test, i.e. signing the app with an ad-hoc certificate and not notarising, and running the binary inside the produced Also just to be clear, I don't really ever run |
Since, @falcucci mentioned that macVim also has the issue, I found this macvim-dev/macvim#1456 And then further this https://developer.apple.com/documentation/appkit/nsapplication/passing_control_from_one_app_to_another_with_cooperative_activation So, it seems like the terminal need to cooporate and focus the launched app. |
To be clear, launching MacVim from iTerm or Terminal on macOS does result in MacVim being in the foreground. (Tested on macOS 14 and macOS 15.) |
To be clear, if you launch neovide from the bundle binary one, you will have this behavior as the same as MacVim, and I do believe that people are installing neovide using this alias. That's what @fredizzimo is mentioning. For example if you launch MacVim using that's the behavior https://share.cleanshot.com/zrjHrD7b If you launch neovide from the build binary tho, you will have always a new instance in the foreground but many instances to manage and neohub comes into action, (at least for now) let's consider here all the facts @fredizzimo has putted. |
But launching |
I don't think it's going to possible to get around having to bundle some kind of wrapper script like MacVim does (a la That script can then call This seems to work, but as a disclaimer, an hour ago my Swift knowledge was exactly zero... #!/usr/bin/env swift
import Cocoa
let bundleId = "com.neovide.neovide"
func main() {
guard let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleId) else {
print("Application with bundle identifier '\(bundleId)' not found")
return
}
let path = Bundle.init(url: url)!.executablePath!
NSApplication.shared.yieldActivation(toApplicationWithBundleIdentifier: bundleId)
var args = CommandLine.arguments
if args.count > 0 {
args.removeFirst()
}
args.insert(path, at: 0)
let cargs = args.map { strdup($0) } + [nil]
execv(path, cargs)
}
main() It can be run directly as a script (after a The difference between this and |
Nice, that’s fairly promising! Perhaps MacVim is doing something similar, where the |
At least on my system, in In macvim-dev/macvim#1456, they say that the reason why MacVim doesn't have this whole foregrounding issue is because they're using the deprecated |
Following the leads from @AThePeanut4 (thank you!), I’ve analyzed two approaches to this problem: (a) using a wrapper for The wrapper approach can be viewed at https://github.com/fboundp/neovide-start. It works pretty well, but I am not excited about it for a few reasons. First, I just generally believe a wrapper should be avoided unless there is no other good way to solve this problem. Additionally, a couple of hacks are necessary for the wrapper to work well. It must do its own processing of the The activate approach is given in PR #2799, using the deprecated |
I just tried neovide and noticed it has this major bug neovide silently launching in bg without focus is ruining the experience and script workarounds like "open ..." with parameter checks are unreliable and insanely full of other problems edit: just tried with Alacritty instead of apple terminal, also doesnt work. Opens the editor in the background on some random window without focus. It has nothing to do with security either.. edit2: I'm probably not going to compile a whole seperate wrapper / codebase, have to wait for the fix I guess brew package: |
@sdfgsdfgd you are probably outdated, the issue was closed and tested on upstream. A release is coming very soon. The wrapper was just a showcase to illustrate how to fix the problem in that way but we aren't using it. |
Hi, MacVim maintainer here. Glad my issue writeup helped a bit.
Knowing how Apple works, it's quite likely that they will formally break the Have you tried just calling Anyway, if you have time, I recommend watching the "What's New in AppKit" WWDC video (which is in June usually) every year (and/or the AppKit release notes) since they usually contain the best practices for each release and what breaking changes they are introducing. I usually watch each with 50/50 excitement and dread depending on how much is new cool features and how much is breaking changes 😅. This really helps keeping on top of things. |
It certainly did, thank you!
Yeah I do agree that that will happen at some point - when it does, we can just switch to the wrapper script solution.
Never though to try this 😑 so to know if I need to be annoyed at myself I just did - and it doesn't work. As I understand, the previous app needs to yield to the new app using |
That's weird. Maybe there's something different in how Neovide and MacVim handle the launching of the app, but when I tested this in MacVim it definitely worked (just calling Either way the current way works now. You can always punt till Apple decides to kill the API. |
Okay I was experimenting with this, and it didn't work (trying to So hopefully that keeps working when the API is eventually removed, and then the fix will be very simple. Thanks for the pointers! |
Describe the bug
I launched
neovide
from iTerm2 and it launched behind the iTerm2 window and all the way at the end of the app switcher. (I had been doing something where I had set neovide to be on the right side of the screen the same as my typical iTerm2 window, and I kept it here because it shows the behaviour fairly well.)Even adding
vim.cmd("NeovideFocus")
to the end ofinit.lua
is not fixing the issue.To Reproduce
Steps to reproduce the behavior:
neovide
in iTerm2 (this probably happens with Terminal.app as well, but I currently use iTerm2).Expected behavior
Neovide should take focus (especially if
vim.cmd("NeovideFocus")
is ininit.lua
orNeovideFocus
is ininit.vim
) from iTerm2 and be positioned in front of iTerm2.Screenshots
Desktop (please complete the following information):
Please run
neovide --log
and paste the contents of the.log
file created in the current directory here:neovide_rCURRENT.log
Additional context
Add any other context about the problem here.
n/a
The text was updated successfully, but these errors were encountered: