05 May 2017, 19:02 | #1 |
Registered User
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 22
|
Window listing and manipulating windows in workbench 3.x
Hi,
I have two questions: 1. How should I go about getting a list of all windows on the current screen? I have read through the intuition.library and workbench.library functions and I can't seem to find a function or a combination of functions which would return a list of current windows on a given screen and their IDCMPs. 2. Can I assume that when I have a list of these window IDCMPs I can manipulate the geometry and placement of the windows? Or am I approaching this using the wrong tools, so to speak? |
05 May 2017, 19:50 | #2 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
For a given screen, you can enumerate its windows by looking at the FirstWindow member, and the NextWindow member for each successive window.
When you have found the window you're looking for, you can f.ex. use Intuition ChangeWindowBox() to control its size and position. |
05 May 2017, 19:54 | #3 |
Amigan
Join Date: Feb 2012
Location: London
Posts: 1,311
|
The Screen struct has a linked list of Windows. see: screen->FirstWindow
|
05 May 2017, 19:55 | #4 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,005
|
Actually you must not manipulate anything that does not belong to your program.
If you do it, you have to keep in mind that there is no way to prevent a window from closing before you can manipulate it. In this case the window pointer you are using becomes invalid and your program will crash. Or do something bad in memory which belongs to another program. To get a list of windows on a screen you can start with screen->FirstWindow and follow window->NextWindow until you got all. Protect this by a call to LockIBase() before you start and UnlockIBase() when you are ready. Be aware that you must not call any intuition.library function between LockIBase and UnlockIBase. IDCMPs are not involved. Many windows don't even have an IDCMP. Also be aware that there are borderless windows, backdrop windows and such whose position and size you might not want to change. It's dangerous to fiddle with things that are not under your control. |
06 May 2017, 00:11 | #5 |
Registered User
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 22
|
Thank you everyone for the awesome information. Enough to get me experimenting.
I was planning to write some code which would manipulate windows on demand (also those owned by other programs) so they would tile in a non-overlapping way (i.e. a tiling window manager), but your advice Thomas confirmed my suspicion that this might be very hard with AmigaOS. Some other tiling thing might come of it still. I'll begin experimentation, which will probably involve some pretty dangerous fiddling and return if I produce anything interesting, or get hopelessly stuck. |
07 May 2017, 04:24 | #6 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,342
|
To put things in perspective, even Commodore's own FKey commodity makes spurious assumptions about legal pointers.
|
07 May 2017, 05:32 | #7 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,651
|
It should be a safe enough operation as long as Forbid()/Permit() are used to prevent the window being closed in the interim.
|
09 May 2017, 17:18 | #8 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,369
|
Forbid()/Permit() can help avoid dangerous situations, but try not to use them any longer than is absolutely necessary.
I would suggest being especially careful of resizing windows that aren't meant to be resized, or not to the sizes you might require by tiling. A good idea might be to only resize those windows that have the WFLG_SIZEGADGET bit set in the Flags field, and *always* respect the min and max window size settings. Bear in mind that some programs might not set safe max and min values simply because they don't expect to be resized due to not having a resize gadget in the bottom right corner. If you make a window larger than was intended, it could end up larger than the bitmap it's displaying for example, giving you garbage on screen or possibly causing crashes. Making it smaller could result in a program drawing over the borders, also resulting in display issues and potential crashes. |
15 May 2017, 20:24 | #9 |
Registered User
Join Date: Oct 2014
Location: Europe
Posts: 472
|
Whatever you try to code, have a look at WinZoom first. Maybe this is what you're looking for. No need to invent the Wheel twice. ;-)
ftp://aminet.net/util/cdity/WinZoom.lha |
18 May 2017, 21:12 | #10 |
Registered User
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 22
|
Thanks Cylon.
Actually, I found a tool I had previously overlooked: http://aminet.net/package/util/wb/windowtiler21b It does exactly what I want and works flawlessly. A very nice piece of software, which I can recommend. I have written the programmer Doug Dyer an email and asked if he is willing to share the source code, as I'm really interested in how he managed to control the windows so efficiently. It is probably very unlikely that he is reachable by the email he was using 22 years ago, so does anyone here by any chance know Doug Dyer or know how to reach him? |
18 May 2017, 21:28 | #11 |
Phone Homer
Join Date: Jun 2006
Location: 5150
Posts: 5,790
|
If exist a program to list all open windows id be intrested.
|
19 May 2017, 06:09 | #12 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,651
|
Scout can list all open windows.
|
19 May 2017, 18:27 | #13 |
Registered User
Join Date: Oct 2014
Location: Europe
Posts: 472
|
http://aminet.net/package/util/wb/listwindows
coincidentally uploaded two days ago??? Last edited by Cylon; 20 May 2017 at 02:34. Reason: url was wrong??? |
19 May 2017, 18:37 | #14 |
Phone Homer
Join Date: Jun 2006
Location: 5150
Posts: 5,790
|
I'll check it out
What I want to do is have a reboot script for things like WHDload then after load Workbench again and open all the windows you had open. |
20 May 2017, 23:38 | #15 |
Registered User
Join Date: Oct 2012
Location: Germany
Posts: 585
|
I'm planning to add an ARexx-Port to the next WinZoom-version, which should help to automate things, like window presets for each screen, etc.
|
23 May 2017, 14:42 | #16 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,369
|
If you're just looking to remember the Workbench windows that were open (and not applications etc.), and have Workbench 3.9, I wrote a set of scripts a while back that does just that. You place a script in the WBStartup drawer, and it opens the saved windows at the saved locations. It also adds a menu item to the Tools menu which lets you snapshot the current window setup. If it's not exactly what you want, it might be of use to you for writing your own version. RememberOpenDrawers on Aminet
|
31 May 2017, 22:57 | #17 |
Registered User
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 22
|
I wrote a little window lister program as an exercise to get familiar with the intuition library. It lists windows, their size an coordinates, on the Workbench screen only:
Code:
#include <stdio.h> #include <string.h> #include <proto/intuition.h> int main(void) { struct Screen *screen; // Lock workbench if(screen=LockPubScreen("Workbench")) { struct Window *window; ULONG ilock; int winnr = 0; ilock=LockIBase(0); // Loop through windows on screen for (window=screen->FirstWindow; window; window=window->NextWindow) { // Not really interested in Workbench window information if (!stricmp(window->Title,"Workbench")==0) { printf("%s %d\n%s \"%s\"\n%s %4d\n%s %d\n%s %8d\n%s %8d\n", "Window:", winnr, "Title:", window->Title, "Width:", window->Width, "Height:", window->Height, "x:", window->LeftEdge, "y:", window->TopEdge); // Increment window id winnr++; } } // Unlock IBase and screen UnlockIBase(ilock); UnlockPubScreen(0,screen); } return 0; } Last edited by edmayn; 31 May 2017 at 23:33. |
01 June 2017, 08:11 | #18 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,005
|
window->Title might be NULL, so your program may cause Enforcer hits. In fact the Workbench window does not have a title, so your stricmp does not work anyway and causes a hit.
Also this program causes a deadlock because the console handler does LockIBase, too (at least with KongCON) and output to the window will wait for the console while the console waits for the lock. |
01 June 2017, 20:35 | #19 |
Registered User
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 22
|
Thanks for the feedback Thomas.
The workbench window does have a title. Here is a screenshot with the stricmp if commented out: And here is one with the stricmp enabled again: You do have point with the empty window titles and I will check for it and set a default title. I'll see what I can do to avoid the deadlock you mention in regards to KingCON (and probably other console handlers). Last edited by edmayn; 01 June 2017 at 20:42. |
01 June 2017, 22:19 | #20 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,005
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I save window positions and sizes in Workbench? | Foebane | support.Apps | 6 | 10 April 2017 15:09 |
rawadf tool for manipulating extended ADFs | Redwood | News | 6 | 14 January 2010 23:23 |
Workbench 3.1 or 1.3 - changing windows | zygzak | New to Emulation or Amiga scene | 16 | 24 October 2009 18:11 |
Workbench On Windows | Oxygene | request.Apps | 28 | 29 September 2008 20:24 |
Window Wizard: How do I clean the windows? | mombasajoe | support.Games | 0 | 28 June 2008 22:25 |
|
|