ShowWindow/HideWindow in Cocoa - cocoa

In Carbon you could change a window's visibility with HideWindow(WindowRef) and ShowWindow(WindowRef).
In Cocoa I know you can call NSWindow's orderOut: to hide and orderFront:, orderBack: or orderWindow:relativeTo: to put it back on screen, but none of those respect the ordering of the window relative to other windows when it was last visible.
For example, if I have two windows, one above the other, and then call orderOut: on the back window, how do I show the window again such that it is still behind the front window without calling orderWindow:relativeTo:.
The only thing I can think of right now is to remember the window ID of the window immediately above it and then use orderWindow:relativeTo: when showing it again, but I haven't thought through what happens if the window above is closed before the rear window is made visible again.

I don't think there's any method available in Cocoa. I guess you need to mimic that using your idea.
By the way, what was the Carbon behavior if you start from four windows ordered as
A B X C D E
Then hide X
A B C D E
Now the user reorders them, and removes some:
E A C
and then show X again. Where did X go in Carbon in this case?

Related

Cocoa Accessibility API: Hide a window

I'm looking to hide a window on OSX (not belonging to my app), but not the rest of the application. I have tried simply moving the window off the screen (like I would do in Windows), but the api always positions it at least 20 pixels away from the edge (#annoying).
Other things I have thought of:
Setting the opacity of the window to zero (can this be done?)
Minimizing the window, but it appears that the window handle becomes null once the window is minimized, so might be hard to get back
Setting the window level (i.e. desktop) or z order (can this be done?)
Moving the window to a different workspace (can this be done?)
Does anyone know of a way to do this?

child QMainWindow title bar disappeared on Mac OS X (add more description)

I develop a program on mac OS X using Qt 4.8 as the title.
Now I'm facing a problem that I spent a lot of time on it but still cannot solve.
I have a QWidget (called A) which will open a QMainWindow (called B) after some operation.
When B is opened, I need A to be blocked by B, so I set A as B's parent and set the window modality of B to Qt::WindowModal.
On other platform, it works as what I thought, however, when it comes to mac, B doesn't have its own title bar, it just popped up and attached to the title bar of A. And also, the close button on the title bar of A is grey-out, which means I cannot close B by the button, I need to use an exit QAction on QMenu to close it.
When I set B's parent to 0(NULL) instead of B, then it has independent title bar just as on windows or linux, that's what I want. However it lost the property that B blocked by A.
I tried to set the windows flags such as Qt::CustomizeWindowHint and so on, but no one works.
Is there any way to keep the hierarchal relationship between A and B, and gives B an independent title bar on Mac? Thanks for everyone's help :)
ps. I tried on small program and found that this situation only happened on WindowModal (NonModal and ApplicationModal works fine)
The behavior you are describing is known as sheets on Mac OS X. As you suspected, there is a value for the window flags enum that specifies if the window is to be a sheet. Based on the documentation, it appears that calling setWindowModality() on OS X may default the window to being a sheet -- which is probably what most developers would want for most dialogs. You might try testing for and explicitly removing that flag after setting the modality and see if that helps. Alternately, you may want to check which flags are set, and see if that leads to a solution.

How to create an invisible X11 window for GPGPU?

Is it possible to create an invisible X window? For initialization of an OpenGL ES 2.0 context, one has to create a X window manually, but I can't find a way to make it invisible. Since I'm only doing GPGPU I don't need an output window. In fact, it is rather annoying in my case.
I'm aware of a solution from an earlier question, where it has been pointed out to use InputOnly in XCreateWindow(). This, however, leads to the X error GLXBadDrawable. Probably because EGL requires the window to respond to graphics request. Is there another way? Maybe create it minimized? But I can't find anything on that either. Also setting the window's size really small doesn't help, since it always occupies the whole screen on my device (Nokia N9).
When you create an X window, it is created unmapped, so what about creating an InputOutput window and leaving it unmapped? Another option would be (if the window must stay mapped), to move it out of the screen.

Hide window until the top window is displayed

I am facing a little annoying design problem. Not easy to give a title of my question.
I must display two windows, one over another one. The first one is a Cocoa window, the second is made with Qt. In the second window, an action is performed, but the user can choose to close this window. He must fall back on the first window.
To display my first window, which is actually a SFAuthorizationPluginView, I do:
[myview displayView];
then, to display the window made with Qt on top of first window:
QWidget* w = openMyScreen();
NSView* v = (NSView*)w->winId();
[[v window] setLevel:2003];
This works well, however there is a small delay before the second window is displayed. We can thus see for a very short time the first window.
I need that the second window stays on top of the first window, because the user can close the second window and must have access to the first window.
Any ideas on a trick how to hide the first window, just the time, the second window appears?
Thanks in advance
NSDisableScreenUpdates and NSEnableScreenUpdates (link) might be useful in this situation. The documentation says:
You typically call this function so that operations on multiple windows appear atomic to the user.
which seems to describe your situation.
A word of unrelated advice though: Don't go setting window levels willy-nilly. A window level of 2003 will likely cause the window to appear over things like the dock or even the menu bar, which would definitely be strange. You should stick to the standard levels declared in NSWindow.h unless you have good reason. NSFloatingWindowLevel might be appropriate (although I'm not sure what level the SFAuthorizationPluginView window is displayed at).
Starting with MacOS 10.4, you can use :
[NSWindow disableScreenUpdatesUntilFlush];

Closing old window when opening a new one in Cocoa

Ok, I have two windows, A and B. When I click a button on Window A, I want it to close and take the user to Window B. makeKeyAndOrderFront does a great job of activating Window B, but how do you get it to then close Window A?
Send window A a close or performClose: message (depending on whether you want to emulate the user closing the window, which is the latter, or simply close it immediately and unconditionally).
Note that closing the window may release it; see the releasedWhenClosed property, which has a checkbox in IB and may already be turned on there. You may want to order the window out (as compared to ordering in, such as by ordering front) instead.

Resources