GNOME Bugzilla – Bug 589084
Quartz missing Modal support
Last modified: 2018-02-10 03:38:08 UTC
Please describe the problem: The current implementation of Gdk for Quartz is missing support for Modal windows. It might be nice if the modal windows were made to slide out of the parent as they do with Cocoa applications. Steps to reproduce: 1. Create a parent window. 2. Create a child window and set it transient for the parent and set modal hint. 3. Select the parent window, it will be foremost above the child. Actual results: The parent window will be foremost; above the modal child. Expected results: The child window should stay foremost even if the parent is selected. Does this happen every time? Yes Other information:
So I've looked through the event loop code and at the API provided to us through NSApp and think I have an idea of how we would need to implement this. On X11, you can have multiple Modal windows above their transient parents. Each modal window can be worked with. However, when using the Modal API with NSApp, the concept is more of a SINGLE modal window per application. This means that you work with handling incoming messages in a loop similar to gtk_dialog_run(). To emulate how things work on X11, we would need to the event loop to pump the messages from the available modal "sessions". Therefore, 1) When modal-hint is called for a GdkWindow, we need to setup the modal session using [NSApp beginModalSessionForWindow:<NSWindow*>]. This asynchronously begins the modal session and returns us an opaque handle. 2) The NSModalSession handle needs to be available to the event loop. 3) During event loop iteration, if there are modal sessions pending, their events need to be pumped rather than the general event queue using [NSApp runModalSession:<NSModalSession>]. To get the effect of X11, I think we need to pump the various sessions cooperatively. I'm going to take a stab at implementing this, or at least update based on my failures.
FWIW I wasn't having a whole lot of luck going the route mentioned above. But I was able to get this working in the slide down effect that Cocoa uses for many file dialogs. http://x.dronelabs.com/chris/dropbox/gtkmodal-osx.png After getting this working, I discovered why the previous wasn't working well so I'm going to try a couple patches to see the direction the maintainers which to go. Patches coming soon'ish.
Created attachment 139445 [details] [review] basic fix So this basic fix for the method guard gets things at least working. Another patch to follow for showing modal's as sheets.
Created attachment 139446 [details] [review] Show modal dialogs as sheets displayed from the parent like Cocoa
Created attachment 168786 [details] [review] Show modal dialogs as sheets displayed from the parent like Cocoa and don't move after This makes sure that the window is not moved afterwards. Normally you would have a Window as Modal, TransientFor and position Center. On Mac don't move if it's displayed as a sheet. There are still a serious problem. This only works one time, then it shows the window normally ?
Created attachment 168794 [details] [review] Show modal dialogs as sheets displayed from the parent like Cocoa and don't move after and close properly Will now use "[NSApp endSheet:impl->toplevel];" to close and hide the window, if it is Modal and has TransientFor. Now the "Sheet" effect works every time.
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.