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

Focus for Mac Window #7

Closed
markusmoenig opened this issue Jun 6, 2015 · 8 comments
Closed

Focus for Mac Window #7

markusmoenig opened this issue Jun 6, 2015 · 8 comments

Comments

@markusmoenig
Copy link

Hi,

first of all thanks for the great work on the Native File Requester. We use it on www.visualgraphics.tv for multi os file requesters for the Desktops.

We have one issue which may not be yours. Under Mac / Cocoa we never succeed in setting the focus back to the SDL2 OpenGL Window after a Dialog was open. Resulting that the user has to select the main window once before being able to continue work.

Did you see this behavior too ?

Thanks again,

Markus

@mlabbe
Copy link
Owner

mlabbe commented Jul 24, 2015

Hi Markus,

Yes, this is happening. I would appreciate any patch or code snippet demonstrating how to reset the focus.

@mlabbe
Copy link
Owner

mlabbe commented Jul 24, 2015

For example, with SDL2, you should be able to call SDL_GetWindowWMInfo(), which returns an SDL_SysWMinfo union. https://wiki.libsdl.org/SDL_SysWMinfo

From there, you can get the NSWindow, from which you can call makeKeyAndOrderFront on.

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instm/NSWindow/makeKeyAndOrderFront:

While I don't want to add an explicit SDL or windowing dependency, I would be happy to accept a code snippet into docs if this works for you.

@markusmoenig
Copy link
Author

Strange thing is, I tried this and it never worked to set the Focus back via Cocoa API calls. I always had to click on the Window. This may be some kind of conflict of SDL2 powered OpenGL windows with Cocoa.

Anyway, it has been some time since I tried to get it to work last time, will retry it in the next days and will let you know.

On Jul 25, 2015, at 04:49, Michael Labbe notifications@github.com wrote:

For example, with SDL2, you should be able to call SDL_GetWindowWMInfo(), which returns an SDL_SysWMInfo union. https://wiki.libsdl.org/SDL_SysWMinfo https://wiki.libsdl.org/SDL_SysWMinfo
From there, you can get the NSWindow, from which you can call makeKeyAndOrderFront on.

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instm/NSWindow/makeKeyAndOrderFront https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instm/NSWindow/makeKeyAndOrderFront:

While I don't want to add an explicit SDL or windowing dependency, I would be happy to accept a code snippet into docs if this works for you.


Reply to this email directly or view it on GitHub #7 (comment).

@velkyel
Copy link

velkyel commented Jul 31, 2015

same issue here. My simple solution is:

NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
// ...before [NSOpenPanel openPanel]

and

[keyWindow makeKeyAndOrderFront:nil];
// ...before return nfdResult;

that's it

@mlabbe
Copy link
Owner

mlabbe commented Jul 31, 2015

That sounds promising! Markus, can you try this and report back?

@markusmoenig
Copy link
Author

Yes, works fine, thanks velkyel.

My issue was that I used the NSWindow supplied by SDL_SysWMinfo which is definitely not working for some reason. Can only imagine it is a bug in SDL2.

Thanks everybody for the help on this.

@mlabbe
Copy link
Owner

mlabbe commented Aug 4, 2015

Thanks, everyone! I am going to update the project as soon as I have time!

The issue will be closed then.

saurvs added a commit to saurvs/nfd-rs that referenced this issue Jul 30, 2016
Big refactor
Added proper Result type
No unwrapping inside the open dialog functions. It now returns a correct restult type instead
Added the nfd sources that is built using the gcc crate instead of having the user compile the code manually
Added DialogBuilder to make it nicer to construct dialogs with filters and paths
Added builder_open_jpg example which uses the builder code and only allows for opening of jpg files
Fixed issue focus issue for Mac dialogs: Outlined here mlabbe/nativefiledialog#7
Support for multi open + example
mlabbe added a commit that referenced this issue Aug 15, 2016
@mlabbe
Copy link
Owner

mlabbe commented Aug 15, 2016

Okay! This fix has finally been merged into master!

@mlabbe mlabbe closed this as completed Aug 15, 2016
ewmailing pushed a commit to ewmailing/nativefiledialog that referenced this issue Sep 4, 2016
* master: (28 commits)
  Issue mlabbe#7 focus for Mac Window fix
  docs
  dummy change, test autobuild
  dummy change, test autobuild
  fix xcode build
  update docs re: mingw
  fix rel paths
  Add mingw/msys support
  don't run premake!
  docs
  docs
  docsdocs
  docs
  docs
  premake5 comment
  new autobuilt
  delete old premade
  premake5 dist
  update readme
  check in premake5 dist projects
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants