palette window

I have an app that acts essentially as a palette of commands for another app. I work in the other app and then occasionally click on a button on my app. The buttons will do some calculation and then return some data back to the original app via Applescript. My app’s window was a global floating window. This worked well in Carbon. Both my window and the other app essentially had focus at the same time, in that I could directly click on either of them.

Cocoa changed things, however. The global floating window now keeps all focus. Some of my Applescripts need the other app to be frontmost, but my global floating window is not allowing the other app frontward. So, I tried other window types and the closest I’ve found to my setup under Carbon is the movable modal window. This works ok, but it trades focus between my app and the other app. So if I’m working in the other app and want to do something in mine, I have to click on my window to give focus to it and then a second time to do something like click a button. I’m trying to avoid the second click.

I see other commercial apps that use this palette concept. BBEdit and TextSoap, for example. They have palette windows that basically share focus with other windows. Are they using older Carbon stuff to make this work or is there something I’m missing in Xojo or are there some plugins or declares that would make this work?

They are probably set to floating window level.
Try this:
Sub WindowLevel(extends w as window, assigns value as integer)
#if targetmacos
declare sub setLevel lib “AppKit.framework” selector “setLevel:” (id as integer, value as Integer)
setLevel w.handle, value
#endif
End Sub

Pass a 1 to make the window float like a palette and 0 to make it return to normal.
(This is for an extension module but you can of course put it into the open event, a window class or whatever). Other values are possible too, you can find them here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/#//apple_ref/doc/constant_group/Window_Levels

The other suggestion I have is to make sure that you bring t’other application forward, this can be done with the Apple Scripts (IIRC).

I gave that a shot but it didn’t make any difference. I still have to make an initial click on my window before I could click a button. I’ll look through that Apple documentation and see if anything looks promising.

I had originally tried that with the global floating window, but it never brought the other app (in this case BBEdit) to complete focus. (I say complete focus because I could access the BBEdit window and do things in it, but my Applescripts didn’t recognize the contents of the window. Once I changed my window to anything other than global floating window, the scripts ran fine.) Now I was just using a simple:

tell app "BBEdit" activate end tell

but maybe there’s a stronger way of doing it via Applescript.

[quote=172420:@Scott Griffitts]tell app “BBEdit”
activate
end tell
but maybe there’s a stronger way of doing it via Applescript.[/quote]
bugger… that’s the command I recognize…

I do wonder if you could tell BBEdit to set the focus to it’s primary window, thus removing it from your floating window. I recall when updated our card software we had terrible trouble with floating windows.

I’m trying to think what we did about it. I have a feeling there’s a declare that allows you to click on things without having to activate the window.

It’s worth noting however, that not even Apple uses floating windows any more. I’m guessing the issues may be why.

Maybe for a futre version of your application, you could use a Status Menu or some other technology.

[quote=172420:@Scott Griffitts]@Ulrich Bogun Pass a 1 to make the window float like a palette and 0 to make it return to normal.
I gave that a shot but it didn’t make any difference. I still have to make an initial click on my window before I could click a button. I’ll look through that Apple documentation and see if anything looks promising.[/quote]

You may want to try the declare posted by Axel Schneider that brings focus to a window. He used it in DragOver, you could use it in MouseEnter or MouseOver :
https://forum.xojo.com/14202-drag-border-vs-focusring-visual-cues-and-drop-file-selected?search="Canvas+DragOver"

[quote=172420:@Scott Griffitts] @Ulrich Bogun Pass a 1 to make the window float like a palette and 0 to make it return to normal.

I gave that a shot but it didn’t make any difference. I still have to make an initial click on my window before I could click a button. I’ll look through that Apple documentation and see if anything looks promising.[/quote]
That’s strange, Scott. I tried it myself on a window with a lot of controls, sent its app to the background, clicked in another app’s window and the palette window reacts immediately without any “focus click” needed …?!

Maybe – though I did not set this – setting worksWhenModal to true enables the correct processing of mouse events?

[quote]Return Value
YES if the window is able to receive keyboard and mouse events even when some other window is being run modally; otherwise, NO.

Discussion
The NSWindow implementation of this method returns NO. Only subclasses of NSPanel should override this default.[/quote]