How to tell if patcher window is active/inactive (front-most window or not)

Luigi Castelli's icon

Hi folks,

I just finished coding an UI-object. The object in question has been instantiated in a patcher. Using Max callback methods or API functions, is there a way to tell when the patcher window becomes active (i.e. it is the front-most window and its title bar is highlighted), and when the patcher window becomes inactive? It would be useful as some of the graphics in my object might need to change in order to follow the patcher window state.

Thanks.

- Luigi

terenceformer's icon

there is an object that does just that: [active]

Luigi Castelli's icon

Yes, I know about [active].
In my object I would like to use the same functions that [active] probably uses under the hood.
Is it possible for 3rd party developers ?

- Luigi

terenceformer's icon

Ah, I am sorry, didn't read your first two sentences carefully :S
I mistakenly thought you were talking about creating a patch. But since you are developing your own object I'm afraid I'm of no help :(
I must say, having seen your posts on the forum before, I was wondering how you could have not known about [active] already hehe.
I hope a solution is posted, I am quite curious about this myself. Cheers!

andrea agostini's icon

Hi Luigi.

You've probably tried this already - but doesn't the patcher send any notification when its state changes?

aa

Luigi Castelli's icon

Hi Andrea,

nope, neither the patcher nor the patcherview send any notifications when the window's focus is brought from background to foreground or viceversa. Thanks for the suggestion anyway...

- Luigi

Timothy Place's icon

Hi Luigi,

You can attach to the Max object for notifications:

err = object_attach_byptr((t_object *)x, _sym_max->s_thing);

Then in your 'notify' method you can do something like this:

if (sender == _sym_max->s_thing && name == _sym_activewindow) {
    t_object *w = object_attr_getobj(sender, _sym_activewindow);
    // w is the active window just like if you called
    // object_attr_getobj(_sym_max->s_thing, _sym_activewindow);
}

Of course you need to remember to detach when your object is freed:

object_detach_byptr(x, _sym_max->s_thing);

HTH,
Tim

Luigi Castelli's icon

Hi Tim,

ok, that notifies me and gives me a pointer to the active window, which is always good to know...
However, how do I know that the window where my object is instantiated is the active/inactive one ?

- Luigi

Timothy Place's icon

Good question. If you have a pointer to your patcherview then you should be able to do something like this:

// 1. assume you have a t_patcherview *pv
t_object *w = NULL;
object_method(pv, gensym("getwind"), &w);

best,
Tim