Determining if the stack has the focus

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Determining if the stack has the focus

Post by massung » Sun Jan 24, 2010 6:38 am

Is there a way of telling whether or not the the stack has the current application focus? Basically, I'd like to know if it's hidden (OS X), minimized (OS X/Win32) or not the current top-level application. I can use the mode of the stack to tell if it's minimized, but not any of the others.

Basically, I have my app interfacing with Growl just fine, but I only want to popup Growl notifications if the user is off doing something else and Growl would be letting the user know "hey, something's up and you may want to go check it out.."

Thanks!

Jeff M.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Re: Determining if the stack has the focus

Post by Janschenkel » Tue Jan 26, 2010 10:01 am

When your app is sent to the background, the current card receives a suspend event, and when it comes back to the foreground, the current card receives a resume event. So you can do something like this in your mainstack script:

Code: Select all

on suspend
  set the uSuspended of me to true
end suspend

on resume
  set the uSuspended of me to false
end resume

command NotifyUser pNotification
  if the uSuspended of me then
    -- we're in the background, so use Growl
  else
    -- we're in the foreground, so use in-app notification
  end if
end NotifyUser
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Determining if the stack has the focus

Post by jacque » Thu Jan 28, 2010 3:40 am

Also, if you only want to know which stack window has focus (as opposed to the whole app) then you can catch "suspendStack" and "resumeStack". They work the same way as Jan's example, only on a stack-by-stack basis. When a stack recieves a resumeStack message, it's on top and has focus.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply