Info on releasing the pubscreen lock

Have a question about our Software Developer Kit? Ask them here.
Post Reply
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Info on releasing the pubscreen lock

Post by trixie »

The Intuition autodoc (as well as the RKRM) encourages releasing the pubscreen lock after opening the window:
You needn't hold the "pubscreen lock" for the duration that your window is opened. LockPubScreen() basically has the same effect as an open visitor window: it prevents the screen from being closed.
While the information is correct, this practice can be dangerous now that
1) most programs can iconify their windows;
2) users can freely define their own "automatic" public screens using the Screens editor in Prefs.

To give an example: if a program opens on a user-defined public screen that is set to "Open/Close Automatically", the screen will get closed right after you iconify the program. The program then has nowhere to return, and naturally locks up the OS when you try to deiconify it.

The documentation, of course, says "for the duration that your window is opened". But I don't think it is made clear enough that you should keep the lock if you intend to allow your program to iconify. A warning of a situation like the above would be appropriate at least.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
Hans-Joerg Frieden
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 223
Joined: Wed Dec 08, 2010 3:52 pm

Re: Info on releasing the pubscreen lock

Post by Hans-Joerg Frieden »

Good point. Unfortunately, a lot of documentation is still in a pre-4.0 state.

Thanks for the pointer.
NOTICE: If you want to contact me, use E-Mail. I cannot be contacted via the forum/private messages anymore
User avatar
Rigo
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 360
Joined: Mon Jan 17, 2011 9:42 pm

Re: Info on releasing the pubscreen lock

Post by Rigo »

And as a result of this, I have changed window.class to now check for the validity of the screen it is supposed to open on before attempting to open.

Basically what this means is that if you unlock the pubscreen while your window is iconified, then try to open it again, it will check to make sure the screen is still around. If it is, it will open on it, if not, it will default to WorkBench.

I shall update the documentation to highlight this fact.

Thanks for the report.

Simon
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: Info on releasing the pubscreen lock

Post by tonyw »

To give an example: if a program opens on a user-defined public screen that is set to "Open/Close Automatically", the screen will get closed right after you iconify the program. The program then has nowhere to return, and naturally locks up the OS when you try to deiconify it.
Is that right? I just tried with the console, opened it on its own (Auto) screen, then iconified it. It closes the screen, sure, but the icon appears on the WB screen and when I double-click the icon, the Auto screen opens again. I can't see a problem with the console, anyway. IIRC it checks to make sure that the screen has the same address as before the iconification (I had to do that to make sure that DisplayBeep() worked properly). Maybe there are other programs that don't check when they reopen?
cheers
tony
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: Info on releasing the pubscreen lock

Post by trixie »

@Rigo
Rigo wrote:And as a result of this, I have changed window.class to now check for the validity of the screen it is supposed to open on before attempting to open.
Basically what this means is that if you unlock the pubscreen while your window is iconified, then try to open it again, it will check to make sure the screen is still around. If it is, it will open on it, if not, it will default to WorkBench.
Thanks a lot, Simon! I was going to ask for a solution like this (very sensible I believe) but you were quicker than my thoughts :-)
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: Info on releasing the pubscreen lock

Post by trixie »

@tonyw
tonyw wrote:Is that right? I just tried with the console, opened it on its own (Auto) screen, then iconified it. It closes the screen, sure, but the icon appears on the WB screen and when I double-click the icon, the Auto screen opens again.
I guess the auto screen opens at LockPubScreen() time, so it looks like the console performs a screen check and calls LockPubScreen() again when it deiconifies.
Maybe there are other programs that don't check when they reopen?
I'm afraid there will be many of them because the documentation tells you to just release the lock after the window opens - which makes you wrongly assume that you don't have to care about it any more. This is why it's worth noting the possible trouble in the documentation, as well as describing how things should be done properly. (Sure it is me who is at fault here but had I been warned by the docs, I wouldn't have made such as stupid mistake.)
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
Post Reply