We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Present mode minimizes when it loses focus
Page Index Toggle Pages: 1
Present mode minimizes when it loses focus (Read 1640 times)
Present mode minimizes when it loses focus
Aug 26th, 2006, 7:47pm
 
Hi all,
I'm working on a full-screen installation.. it's basically an (interactive) sign in a retail store, so it needs to be turnkey, i.e. start up automatically when the computer boots up in the morning, and remain in full-screen mode permanently thereafter. The system is Windows XP Pro SP2.

I'm using code like this, doing "Export application", and putting an alias to the application in the Startup folder.

Code:
static public void main(String args[]) {
PApplet.main(new String[] { "--present", "--display=1", "--present-stop-color=#000000", "Censor" });
}

It works really well, except that a few hours later I'll come back and the program will be minimized to the task bar. It's still working when I restore it.

I think what's happening is some other process on the computer is coming to the foreground briefly; and Processing's present mode seems to permanently minimize itself whenver it loses focus. I'm not sure what this other process is, maybe it's a virus scan or a wireless networking notification or something of that nature. Whatever it is it's gone by the time I come back.

Can anyone think of a way to prevent Processing from doing this? i.e. not to ever give up the focus, or not to minimize and instead to keep running full-screen even when another app takes the focus for a bit? Or failing that, a way to restore the app periodically in the event that it has minimized itself?

Thanks for any advice,

Dan Michaelson
linkedbyair.net

Re: Present mode minimizes when it loses focus
Reply #1 - Aug 26th, 2006, 10:43pm
 
i don't know offhand, but this is apparently just a behavior of java's full screen exclusive mode. you might try googling around or checking the sun forums to find out if anyone's run into it. you may just need to add some focus listeners to the window (undocumented variable called 'frame') to catch whether  the window has become minimized.
Re: Present mode minimizes when it loses focus
Reply #2 - Aug 27th, 2006, 3:13am
 
Thanks.. any idea what method to call to re-maximize the app if I do catch the un-focus event?
Dan
Re: Present mode minimizes when it loses focus
Reply #3 - Sep 6th, 2006, 12:29pm
 
Well, here's a solution, it's not perfect but it's not terrible. It's working for me.

Download the cmdow utility from
http://www.commandline.co.uk/cmdow

and put cmdow.exe in your WINDOWS directory.

This is a command-line utility that manipulates windows (e.g. can prevent your app from being closed). Since that's a potentially misused activity, Symantec considers it malware and I had to create an exception. Probably shouldn't have virus software running in a production environment anyway.

Then in the Processing code, include this function:

public void focusLost() {
 open("cmdow java.awt.Frame /RES /ACT");
}

("java.awt.Frame" seems to be the "caption" for all full-screen exported Processing sketches.)

That will immedately /REStore your application whenever it loses focus, which makes it full-screen again. Also the /ACT option gives it back the keyboard focus as well.

You might want to put a large or small delay in there, if you want to ensure that whatever focus-stealing process is finished before you try to restore your app. (Also, without a delay it's basically impossible to use Ctrl-Alt-Del if you ever need to, because the task manager gets obscured immediately.) In that case you can do

public void focusLost() {
 delay(5000); // 5 second delay
 open("cmdow java.awt.Frame /RES /ACT");
}

Hope it helps someone,
Dan
Re: Present mode minimizes when it loses focus
Reply #4 - Sep 13th, 2006, 4:37am
 
thanks for posting, dan. i've added an entry to the bugs db that includes your solution.
Re: Present mode minimizes when it loses focus
Reply #5 - May 22nd, 2008, 11:17pm
 
Hi.

I'm having exactly the same problem in a similar setup (museum kiosk).  I tried the cmdow hack which seemed to do the trick but the client just called and said it's happened again anyway ... any more tricks I can try?   Is there a way to maximize/refocus from within java?

If I put a delay it never seems to run; if I put no delay it actually has about a 5 second delay.  weird.  

This behavior also only seems to happen the first time you power up and autologin.  If you log out and log back in everything's fine.  Weird.  Last time I ever, ever, ever use windows as an installation platform.  I swear.  

That's what I say every time, of course ...

thanks,

--Ben
Re: Present mode minimizes when it loses focus
Reply #6 - May 23rd, 2008, 12:41am
 
Ok, answering my own question, maybe.  What do you guys think of this solution:

Code:

int x;
int dx;
void setup ()
{
size(400,300);
background(255);
x=0;
dx=1;
}

void draw()
{
background(x);
x=x+dx;
if (x>255) { x=255; dx=-dx; }
if (x < 0) { x=0; dx=-dx;}

// If I get minimized, expand again
if (frame.getExtendedState()==1)
{
frame.setExtendedState(0);
}
}


http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Frame.html#setExtendedState(int)

I did this in the draw loop instead of inside focusLost() because setExtendedState() doesn't foreground and focus the window, it just maximizes it.  So if it minimizes again, focusLost() doesn't trigger because the window didn't HAVE focus.  And show() won't work because apparently "some platforms" won't allow java windows to put themselves in front of native application windows.  As usual, I guess Java likes to keep itself locked in its little sandbox.  Smiley

More sophisticated would be to make a window event handler, I guess, but so far this is working...


Page Index Toggle Pages: 1