Re: Second frontmost app?
Re: Second frontmost app?
- Subject: Re: Second frontmost app?
- From: Jean-Daniel Dupas <email@hidden>
- Date: Tue, 28 Apr 2009 19:53:48 +0200
To iterate over all apps, you should pass { 0, kNoProcess } in the
first GetNextProcess call. But as I mention, the result list is not
usefull top solve this issue.
That said, using Carbon event to track application switching as
suggested sooner would be a cleaner and more reliable way to do this
than polling using a Timer.
IIRC, the API required to do this is available on 64bits (as there is
no replacement yet).
And it's not very difficult:
======================================
#include <Carbon/Carbon.h>
#if __LP64__
// workaround missing declaration
extern EventTargetRef GetApplicationEventTarget(void);
#endif
static
OSStatus _SDProcessManagerEvent(EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void *inUserData) {
if (GetEventClass(inEvent) == kEventClassApplication) {
ByteCount size;
EventParamType type;
ProcessSerialNumber psn;
MyClass *handler = (MyClass *)inUserData;
verify_noerr(GetEventParameter(inEvent, kEventParamProcessID,
typeProcessSerialNumber, &type, sizeof(psn), &size, &psn));
switch (GetEventKind(inEvent)) {
case kEventAppFrontSwitched:
[handler frontApplicationDidChange:&psn];
return noErr;
}
}
return eventNotHandledErr;
}
======================================
And in your initialization code:
======================================
EventTypeSpec eventTypes[] = {
{ kEventClassApplication, kEventAppFrontSwitched },
};
InstallApplicationEventHandler(_SDProcessManagerEvent,
GetEventTypeCount(eventTypes), eventTypes, self, NULL);
======================================
Le 28 avr. 09 à 19:06, Gary L. Wade a écrit :
You're starting off with GetCurrentProcess, which returns the
process number
of your application; have you tried GetFrontProcess, which returns
the front
process? This will not be your application if you're in the
background.
On 04/28/2009 9:57 AM, "Jean-Daniel Dupas" <email@hidden>
wrote:
Don't bother with that. I did a try, and it look like the Process
Manager order has nothing to do with the cmd + tab order.
it returns -600, probably because psn is the last process in the
Process Manager list.
Sorry for the noise.
Le 28 avr. 09 à 17:55, Dave DeLong a écrit :
Well, I got this working with a timer that just keeps track of the
activeApplication and the previously activeApplication, but I'm
intrigued by this approach, so I'd like to see if this works, too.
Here's what I've got:
ProcessSerialNumber psn;
OSErr result = GetCurrentProcess(&psn);
if (result != 0) {
NSLog(@"Error for current process: %d", result);
return;
}
result = GetNextProcess(&psn);
if (result != 0) {
NSLog(@"Error for next process: %d", result);
return;
}
However, when I run that, I always get:
Error for next process: -600 (-600 = No eligible process with
specified process serial number.)
Any ideas?
Thanks,
Dave
On Apr 28, 2009, at 1:44 AM, Jean-Daniel Dupas wrote:
You can use the ProcessManager API.
AFAK, the GetNextProcess() will returns the processes in the order
you see them in the cmd+tab panel.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden