Forums > Dev

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

July 26, 2012 | 6:19 pm

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


July 26, 2012 | 11:51 pm

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


July 27, 2012 | 7:37 am

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


July 27, 2012 | 11:25 am

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!


July 27, 2012 | 6:53 pm

Hi Luigi.

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

aa


July 27, 2012 | 8:00 pm

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


August 9, 2012 | 5:48 pm

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


August 9, 2012 | 11:01 pm

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


August 9, 2012 | 11:54 pm

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


Viewing 9 posts - 1 through 9 (of 9 total)