Carbon, LSUIElement, and showing a window

Posted by James Turner on Stack Overflow See other posts from Stack Overflow or by James Turner
Published on 2009-10-20T08:47:45Z Indexed on 2010/05/28 23:32 UTC
Read the original article Hit count: 263

Filed under:
|

I have a Carbon LSUIElement application, which runs in the background (possibly with an icon in the menubar, depending on a pref) and occasionally needs to show a dialog to the user - sometimes in response to a user event, but sometimes in response to a background task failing or similar.

(I'm using Qt 4.5, so the application is Carbon based; With Qt 4.6 things will be Cocoa based, but it sounds as if the problem may exist there too).

The problem is that when I open a window, and show it, it doesn't get brought to the front. I assume this is an artefect of being an LSUIElement app. Qt uses SelectWindow in Carbon, and [makeKeyAndOrderFront] in Cocoa, to bring a window (and the app) to the front.

To work around the problem, I tried going direct to the window server: (the first few steps are to get the WindowID, this will be simpler with Qt-Cocoa, since I can use NSWindow:nativeWindow)

WindowRef ref = HIViewGetWindow((HIViewRef) aWidget->winId());
CGSWindow wid = GetNativeWindowFromWindowRef(ref);
CGSConnection cid =_CGSDefaultConnection();
CGSOrderWindow(cid, wid, 1 /* above everything */, 0 /* NULL */);

This works, sort of - the window comes to the front, but it's not highlighted or keyboard focused. Are there additional steps to fix those issues, or is there a simpler solution to the whole problem?

© Stack Overflow or respective owner

Related posts about qt

Related posts about carbon