I'm developping an application running on GNU/Linux and OS-X. On linux, if I start the application with command line I have no problem. On OS-X, the application start but not on "front". I must click on the icon in the dock to see the application. Is there a way to bring an application on front at start.
-
1Have you tried `gtk_window_set_urgency_hint ()`? – Erik W May 11 '17 at 15:39
-
OK, I did it thanks to you. In Glade I've set the property "urgency_hint" to TRUE. And it is working. So you're right. Thank you so much. – lock May 12 '17 at 08:26
-
Oh no. Sorry. It does not work – lock May 12 '17 at 08:32
-
If `gtk_window_present()` doesn't work its perhaps a Gtk on OSX bug, what Gtk version? – TingPing May 12 '17 at 17:54
-
1gtk_window_present dors not work indeed. And I use the last stable version. – lock May 12 '17 at 18:51
-
In my opinion you should provide a [MWE](https://stackoverflow.com/help/mcve) that creates a window and exhibits that problem. – ntd May 13 '17 at 19:46
-
I can give the link to the full application. This is an opensource software that can be installed through homebrew. – lock May 14 '17 at 11:00
-
Ah, I see now you are using Homebrew to run someone else's app. My answer still applies, but now applying that answer is harder... It is a good question, and I wonder if the Homebrew devs themselves have tackled it before. – andlabs May 29 '17 at 16:33
-
I think that generally homebrew should be used for not GUI programs, while homeberw-cask (https://caskroom.github.io/) is intended to be used for that. homebrew-cask uses a bundle but building an .app bundle is not easy for me as I do not really have OSX. – lock May 30 '17 at 20:58
1 Answers
This issue has to do with OS X's process launching model, not with GTK+. The only correct and sustainable way to fix this is to use an .app
bundle.
When running an app with OS X, the app needs to explicitly ask to be brought to front after setting its activation policy using the NSApplication
method activateIgnoringOtherApps:
. However, when Launch Services launches an .app
bundle, it takes care of this automatically. Having an explicit call to activateIgnoringOtherApps:
in your code will just make things more complicated for you to get everything right. I asked this question a while ago; the answer there explains in more detail.
By the same rationale, GTK+ itself does not make this call either. You can add this call yourself right before gtk_main()
if you want for development, but for actually distributing your apps, it's better to leave things as is.

- 11,290
- 1
- 31
- 52