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

Ability to create Spotlight/Alfred like windows #4939

Closed
florian opened this issue Mar 29, 2016 · 31 comments
Closed

Ability to create Spotlight/Alfred like windows #4939

florian opened this issue Mar 29, 2016 · 31 comments

Comments

@florian
Copy link

florian commented Mar 29, 2016

Spotlight/Alfred (and other native apps like 1Password Mini) on Mac have a special behaviour, their windows are displayed above all other windows, but the last used app is still focused.
The closest I could find for Electron was the alwaysOnTop option, but it doesn't have the exact same behaviour.

My Electron app has a Spotlight/Alfred like floating window and the visibility of the window can be toggled with a hotkey. However after hiding the window, the last used application doesn't get focused, which is pretty annoying for the user.
E.g. if I type a message in Skype, open the floating window to quickly look something up and then close it again, I won't be able to keep typing in Skype. I have to click on the Skype window before that. Spotlight/Alfred don't have that problem.

Is there any way to replicate this behaviour in Electron?

@zcbenz
Copy link
Member

zcbenz commented Mar 31, 2016

You can create a always-on-top hidden window, and then call showInactive().

@zcbenz zcbenz closed this as completed Mar 31, 2016
@florian
Copy link
Author

florian commented Mar 31, 2016

@zcbenz Sadly this isn't what I meant. While this will keep the last app focused, I'm not able to type in my app anymore.

Do you use a Mac? If you open Spotlight (Cmd + Space) you will be able to type into Spotlight (i.e it captures all keyboard and mouse events) while the last app is still shown as "focused" (maybe this isn't the right term to describe it).
With focused I meant that the name of the last app is still displayed in the top left of the menubar. The windows actions buttons (close, hide, fullscreen) are also colored, which in OS X shows that the window is focused.

bildschirmfoto 2016-03-31 um 14 23 45

@zcbenz
Copy link
Member

zcbenz commented Mar 31, 2016

Hmm what you want should be a way to prevent window from being focused.

@zcbenz zcbenz reopened this Mar 31, 2016
@zcbenz zcbenz changed the title Is it possible to create Spotlight/Alfred like windows? Add a way to prevent window from being focused Mar 31, 2016
@florian
Copy link
Author

florian commented Mar 31, 2016

Thanks for reopening :)

Maybe OS X offers a standard way to implement those windows? It might be a possibility, since a bunch of 3rd party Mac apps (Alfred, 1PW Mini, …) have those windows.

@zcbenz zcbenz changed the title Add a way to prevent window from being focused Ability to create Spotlight/Alfred like windows Jun 13, 2016
@florian
Copy link
Author

florian commented Sep 10, 2016

@zcbenz Any chance that this is coming to Electron soon?

@zaaack
Copy link

zaaack commented Oct 6, 2016

@florian app.hide() would meet your demand

@florian
Copy link
Author

florian commented Oct 6, 2016

It has a similar behaviour and I also ended up using it. But it's not the exact same thing as the Spotlight/Alfred behaviour.

@joshaber
Copy link
Contributor

joshaber commented Oct 6, 2016

#7296 is possibly related since it allows lots of different window levels.

@ajprax
Copy link

ajprax commented Jul 10, 2017

Hi @florian, it sounds like you have a workaround while this behavior isn't fully supported; are you happy with it? Would you be willing to share your solution?

@codebytere
Copy link
Member

closing due to abandonment.

@electron electron deleted a comment from jcj52436999 Sep 27, 2017
@electron electron deleted a comment from jcj52436999 Sep 27, 2017
@florian
Copy link
Author

florian commented Sep 27, 2017

Is not making progress on this really a reason to close the issue? I would still very much like to see this in Electron and apparently others are interested, too.

@awright415
Copy link

Not sure how it could be implemented, but the key seems to be using NSPanel with NSNonactivatingPanelMask instead of NSWindow.

@codebytere
Copy link
Member

codebytere commented Sep 27, 2017

We're trying to close out issues that haven't seen activity in some time and are not on our radars at the moment. If there's still some interest i can most definitely reopen :)

@ajprax
Copy link

ajprax commented Sep 27, 2017

I'm still interested in seeing better support for this style of window. I'm working around it right now (app.dock.hide() allows my app's windows to join the space of other apps' full screen windows) but it creates awkward UX (no icon in cmd+tab, no dock icon).

@codebytere codebytere reopened this Sep 27, 2017
@florian
Copy link
Author

florian commented Sep 28, 2017

Thanks a lot for reopening! :)

@QuadDepo
Copy link

QuadDepo commented Oct 2, 2017

Any updates so far?

@mdings
Copy link

mdings commented Mar 28, 2018

#7296 is possibly related since it allows lots of different window levels.

I tried a few things out with that feature the other day but I couldn't find a window level at which the underlying app keeps focus.

@Bpazy
Copy link

Bpazy commented Apr 14, 2018

I find that win.close() will send back the focus.
As same as app.quit().
So I use the above solution to resolve this issue.

Any ideas please?

@mattpilott
Copy link

#10078

See this issue too, i'm looking for the picture in picture functionality in macos

@xudaolong
Copy link

xudaolong commented Jul 10, 2018

After deal with logic, I use auto applescript's script to switch application on press cmd + tab.
oncework

@tommoor
Copy link
Contributor

tommoor commented Nov 6, 2018

Hey everyone, I just open sourced a module which in my testing allows creation of NSPanel windows on Mac (it's a no-op on other platforms right now). Take a look and let me know if it helps out – allows creation of a window that does not activate the application.

https://github.com/goabstract/electron-panel-window

@bernatfortet
Copy link

@tommoor Awesome package! One issue I'm finding is that if I use titleBarStyle with anything different than default it will crash on me.

So I'm still looking for a solution. I'm using electron v7 but can't find a way to make it work.

@mefyl
Copy link

mefyl commented Jan 29, 2021

Unfortunately it seems that the previous, library based solution (https://github.com/goabstract/electron-panel-window) does not work anymore : it segfaults right away when calling object_setClass, at least on Apple Silicon. It used to sort-of work, but I still had memory errors when leaving the app. I'm no ObjectiveC expert, but I don't think swapping an NSWindow subclass classes for NSPanel later at runtime is defined behavior.

It is my impression that the only way to get this feature properly is to add it to electron, to spawn an actual proper NSPanel from the get-go. We'd be willing to sponsor work of this if anyone is interested.

@stefanoTron
Copy link

@mefyl was opened suggesting just that #26596
but was closed for some reason.

@proxi
Copy link

proxi commented Jul 9, 2021

@mefyl I agree that spawning NSPanel from the get-go is the only way to make it work reliably. It's not hard (see my comment here) but unfortunately not possible without patching Chromium, and involves duplicating a lot of code in NativeWidgetMacNSWindow, ElectronNSWindow.

@mitchchn
Copy link
Contributor

mitchchn commented Aug 11, 2021

I would love to see the ability to create NSPanel browser windows. Floating command palettes are extremely popular nowadays and the web stack lends itself well to their aesthetic -- it's a natural fit for Electron.

Most other aspects of native window management are already available, or are at least possible to imitate, but this one does really does need a bit of help from the library before developers can run with it.

@stephancasas
Copy link

Until this feature is added, a workaround you might consider is a library like iohook, which can intercept HID events. You could keep the already-frontmost app active, while still sending keystrokes to your alwaysOnTop Electron window.

At the moment, it looks like there's an open PR to stop propagation of keystrokes to whatever has the current focus, so it should be possible to intercept and then redirect input wherever you want it to go. I'm currently experimenting with this, and will be happy to update if anyone is interested.

@vmwsree
Copy link

vmwsree commented Mar 12, 2023

can any one update me on what is the current way to implement this

@YongzeYao
Copy link

Any updates?

@clavin
Copy link
Member

clavin commented Feb 26, 2024

I'm closing this as it was implemented in #34388 👍

@clavin clavin closed this as completed Feb 26, 2024
@YongzeYao
Copy link

@clavin hey Clavin, there is currently no way to achieve spotlight, alfred like window with electron...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests