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

neovide does not focus on launch from terminal (macOS, iTerm2) #2330

Open
halostatue opened this issue Jan 31, 2024 · 11 comments · Fixed by #2562
Open

neovide does not focus on launch from terminal (macOS, iTerm2) #2330

halostatue opened this issue Jan 31, 2024 · 11 comments · Fixed by #2562
Labels
bug Something isn't working macos Specific to macOS and not investigable on other platforms

Comments

@halostatue
Copy link

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 of init.lua is not fixing the issue.

To Reproduce

Steps to reproduce the behavior:

  1. Type neovide in iTerm2 (this probably happens with Terminal.app as well, but I currently use iTerm2).
  2. Observe that the window opens behind the iTerm2 window.
  3. Observe on ⌘-Tab that Neovide's icon is at the end of the app switcher.

Expected behavior

Neovide should take focus (especially if vim.cmd("NeovideFocus") is in init.lua or NeovideFocus is in init.vim) from iTerm2 and be positioned in front of iTerm2.

Screenshots

CleanShot 2024-01-30 at 23 41 08@2x

Desktop (please complete the following information):

  • OS: macOS 14.3 23D56 arm64
  • Neovide 0.12.2
  • Neovim 0.9.5

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

@halostatue halostatue added the bug Something isn't working label Jan 31, 2024
@D00mch
Copy link

D00mch commented Jan 31, 2024

related #2324

@wSedlacek
Copy link

wSedlacek commented Mar 10, 2024

I noticed this issue start to occur after updating when using Raycast.
https://www.raycast.com/

After updating Neovide when Neovide is launch from Raycast it starts in the background.
I did not notice this behavior on prior versions.

I am able to work around this by including this in my init.lua

  vim.schedule(function()
    vim.cmd "NeovideFocus"
  end)

@thraizz
Copy link

thraizz commented Mar 11, 2024

For me, this is also the case. Launching from Finder results in the same behavior, even with all plugins disabled. Scheduling NeovideFocus event does not help for me sadly.

EDIT: Launching from kitty / Terminal.app works just fine!

@brnt
Copy link

brnt commented Mar 14, 2024

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.

@nazriel
Copy link
Contributor

nazriel commented Mar 25, 2024

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:
Isn't an issue anymore on HEAD but on HEAD there are other issues like not playing well with Yabai

UPDATE2:
I got confused.

It has something to do with how macOS handles CLI binaries vs Neovide.app files.

Launching
./target/debug/bundle/osx/Neovide.app/Contents/MacOS/neovide [1]
yields different result than
./target/debug/neovide [2]

  1. Doesn't get focused but plays well with Window manager like yabai
  2. Gets focused by doesn't play well with yabai and starts with weird size and position

@nazriel
Copy link
Contributor

nazriel commented Mar 25, 2024

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.
On other hand kitty somehow works around it.

My current workaround for it:

alias nv="open -n -a Neovide --args "

@brnt
Copy link

brnt commented Apr 7, 2024

FWIW, adding a delay before calling NeovideFocus from .vimrc seems to do the trick. Here's the command for adding a 20ms delay:

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.

@nazriel
Copy link
Contributor

nazriel commented Apr 12, 2024

FWIW, adding a delay before calling NeovideFocus from .vimrc seems to do the trick. Here's the command for adding a 20ms delay:

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

@fredizzimo fredizzimo added the macos Specific to macOS and not investigable on other platforms label May 17, 2024
@fredizzimo
Copy link
Member

fredizzimo commented May 18, 2024

I have a potential fix for this here:

It would be good if someone could test it.

@AThePeanut4
Copy link
Contributor

@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 target/release/bundle/osx/Neovide.app/Contents/MacOS/neovide, and not target/release/neovide.

If it helps, Alacritty doesn't have this problem and they're also using winit afaik.

@fredizzimo
Copy link
Member

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:

Winit has an OS requirement of macOS 10.11 or higher (same as Rust itself), and is regularly tested on macOS 10.14.

A lot of functionality expects the application to be ready before you start doing anything; this includes creating windows, fetching monitors, drawing, and so on, see issues #2238, #2051 and #2087.

If you encounter problems, you should try doing your initialization inside Event::Resumed.

@fredizzimo fredizzimo reopened this May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macos Specific to macOS and not investigable on other platforms
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants