English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 02 June 2017, 00:01   #21
edmayn
Registered User

 
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 12
Interesting ...

I now need to determine if a WA_BACKDROP/WLFG_BACKDROP flag is set for a window.
edmayn is offline  
AdSense AdSense  
Old 02 June 2017, 13:24   #22
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 2,273
Quote:
Originally Posted by edmayn View Post
I now need to determine if a WA_BACKDROP/WLFG_BACKDROP flag is set for a window.
No you don't, just check that window->Title isn't null (which is good practice for dealing with any pointers anyway, but especially when dealing with the OS, which often uses null as a a legitimate status or result).
Daedalus is offline  
Old 02 June 2017, 15:02   #23
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Aachen, Germany
Posts: 364
Quote:
Originally Posted by edmayn View Post
Interesting ...

I now need to determine if a WA_BACKDROP/WLFG_BACKDROP flag is set for a window.
I had the same problem when I wrote WinZoom (http://aminet.net/util/cdity/WinZoom.lha), which seems to already do some of the things you want to achieve.

The checks I currently perform to filter out the Workbench Window are:

NextWindow != NULL

and

NextWindow->Title!=0 (which should also be "NULL")

I also tried

NextWindow->Flags & WFLG_BACKDROP

but that didn't work very well.

Could you describe in more detail what you're trying to achieve? I started out to write a tool which places the active window in the largest free spot on screen - this is where I failed, because the "optimal algorithm" takes 60 seconds on a 060/50 and a FullHD screen, so a heuristic approach would be needed.

Instead I created a solution for cascading, maximizing (full, half, quarter screen), minimizing and iconifying (layersV45) windows. Seems as if we could collaborate on this project, if you'd like to?
bubbob42 is offline  
Old 02 June 2017, 17:21   #24
Cylon
Registered User

 
Join Date: Oct 2014
Location: Europe
Posts: 466
All Workbench windows have a special flag called WA_Workbenchwindow or similar. very easy to filter.
Cylon is offline  
Old 02 June 2017, 18:55   #25
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Aachen, Germany
Posts: 364
Quote:
Originally Posted by Cylon View Post
All Workbench windows have a special flag called WA_Workbenchwindow or similar. very easy to filter.
Well, all Workbenchwindows have that flag. Not only the main/backdrop window.

And AFAIR some application windows set this flag as well.
bubbob42 is offline  
Old 03 June 2017, 01:16   #26
edmayn
Registered User

 
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 12
bubbob42: What I am aiming for is to produce is a tiling window manager with features like dwm or XMonad to name a few. I would also like some sort of status bar. I really have no idea if this is even possible with AmigaOS, but so far it has been fun trying. I plan to draw inspiration from two projects above on how to write tiling algorithms. Read more about tiling window managers here

There is windowtiler on aminet already, but no source code is available and I'd like to know how it is done.

Generally speaking I prefer a keyboard controlled tiling wm, since I spend most of work time in a linux cli.

bubbob42, if you're interested in tiling wm's, and WinZoom looks closely related, I'd like to collaborate, but I need to write some more C first. Eventually I will put what I produce on github, perhaps we can take it from there and see if our interests align?

Concerning the window lister thing, I believe I have ironed out the problems pointed out by Thomas. I also found a workaround to Workbench Window/Backdrop problem. I've tried semi-hard to crash the program from different consoles, while running enforcer which gets no hit (is it enough to run it in a separate console?), and the program does not crash.

Code:
#include <stdio.h>
#include <string.h>
#include <proto/intuition.h>

int main(void)
{
  struct Screen *screen;

  // Lock workbench screen
  if (screen = LockPubScreen("Workbench")) {
    struct Window *window;
    int winnr = 0;
    char *wintitle;

    // Loop through windows on screen
    for (window = screen->FirstWindow; window; window = window->NextWindow) {
      // Ignore Workbench window, also if its backdropped.
      if (!(window->Flags & BACKDROP)
      && (!stricmp(window->Title, "Workbench") == 0)) {
    if (!window->Title) {
      wintitle = "Unnamed Window";
    } else {
      wintitle = window->Title;
    }
    printf("%s %d\n%s  \"%s\"\n%s %4d\n%s %d\n%s %8d\n%s %8d\n",
           "Window:", winnr,
           "Title:", wintitle,
           "Width:", window->Width,
           "Height:", window->Height,
           "x:", window->LeftEdge, "y:", window->TopEdge);
    // Increment window id
    winnr++;
      }
    }

    // Unlock screen
    UnlockPubScreen(0, screen);
  }

  return 0;
}
edmayn is offline  
Old 03 June 2017, 01:48   #27
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Aachen, Germany
Posts: 364
Quote:
Originally Posted by edmayn View Post
Generally speaking I prefer a keyboard controlled tiling wm, since I spend most of work time in a linux cli.
That's exactly what WinZoom does. It emulates the Windows-key+Cursor behaviour of Windows 7+ or Gnome, combined with alt-tab window selection. I also hate touching the mouse. :-)

However, it does not provide >2-column or row-tiling like some of the examples you provided.


Quote:
bubbob42, if you're interested in tiling wm's, and WinZoom looks closely related, I'd like to collaborate, but I need to write some more C first. Eventually I will put what I produce on github, perhaps we can take it from there and see if our interests align?
Of course! Your project is a great opportunity to get into C and learn about Intuition as well.

Some hints (possible spoiler alert ) :

- You will have to build and manage some kind of window list. I use exec lists for this purpose.
- I recommend switching from console output to serial debug kprintf() via debug.lib. Why? Because if you're manipulating windows you did not open yourself, the Commodore way (check example windowtabbing Commodity from AmigaMail/NDK) goes like this:

Code:
ilock = LockIBase(0L);       /* lock intuition base */  
 
/* update your window list here, especially check if target window still exists */

Forbid(); /* kill Multitasking */
UnlockIBase(ilock);

/* manipulate the window structure */

Permit(); /* enable Multitasking */
While this approach avoids race conditions with Intuition, it also forbids console output for reasons Thomas described. So serial debug is the only friend left.
bubbob42 is offline  
Old 03 June 2017, 12:13   #28
edmayn
Registered User

 
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 12
Looks like valuable advice bubbob42! Thank you.

Which led me to this:

https://fs-uae.net/docs/serial-port

Great.

(I do have a working A1200, but I use fs-uae for testing)
edmayn is offline  
Old 04 June 2017, 04:31   #29
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,049
Do note that other windows may also have null titles, e.g. requesters and toolbars.
idrougge is offline  
Old 04 June 2017, 18:26   #30
Ami
Registered User

 
Join Date: Sep 2014
Location: Poland
Posts: 23
Quote:
Originally Posted by edmayn View Post
I'll see what I can do to avoid the deadlock you mention in regards to KingCON (and probably other console handlers).
I'm not sure, try to put printf() after UnlockIBase()
Ami is offline  
Old 08 July 2017, 01:22   #31
edmayn
Registered User

 
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 12
The last couple of weeks I have dived deeper in to C on the Amiga and it has been fun!

As a way to get more familiar with intuition and how windows are handled within this framework I have expanded the window lister program quite a bit and refactored it.

It now includes a check for (IMO relevant) intuition window flags and automatic padding and sizing, based on the console width, for the output table.



Code:
https://github.com/RasmusEdgar/amiga.../wlist/wlist.c

(I tried to post the code here with code tags, but it somehow gets mangled up)

The code compiles cleanly with both SAS/C
Code:
mkmk
smake
and GCC
Code:
gcc wlist.c -o wlist -Werror -Wall -s -noixemul
I hope some of you find it interesting.

Critical feedback is welcome.

Br,
edmayn
edmayn is offline  
Old 08 July 2017, 01:57   #32
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 56
General c/c++ suggestions:
Code:
char *wintitle, bd[3], ac[3], bl[3], wb[3], gz[3], zo[3];
strcpy(ac, "/ac");
strcpy(bl, "/bl");
strcpy(wb, "/wb");
strcpy(gz, "/gz");
strcpy(zo, "/zo");

strcat(flags, zo);

if (!wininfos) {
	free(miscinfo);   //  <= missing, memory leak
	printf("Failed to create window array of structs! Exiting.\n");
	return 1;
    }

if ((printer = printwindows(wininfos, miscinfo)) != 0) {
	free(miscinfo);   //  <= missing, memory leak
	free(wininfos);   //  <= missing, memory leak
	printf("Failed to print windows! Exiting.\n");
	return 1;
    }
You have to allocate 4 bytes for those strings (3 + terminator).
Use strncat instead of strcat to be on the safe(r) side.

Try to use a little different code structure that makes it easier to clean-up partially allocated/initialized stuff. For example, set all pointers/handles/etc. to null/0/..., then at the end, regardless whether you managed to fully initialize everything or not, go through all of them and free/deinitialize those that aren't null/0. That way you also have one common exit point from a function, so it's easier to add new code (otherwise you have to do partial deallocs all over the place).

Last edited by a/b; 08 July 2017 at 02:10. Reason: added more stuff
a/b is offline  
Old 08 July 2017, 22:28   #33
edmayn
Registered User

 
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 12
Thank you for the feedback a/b. Highly appreciated. Very valid points you raise. I'll look into fixing them the next couple of days.
edmayn is offline  
Old 22 October 2017, 13:58   #34
edmayn
Registered User

 
Join Date: May 2017
Location: Silkeborg/Denmark
Posts: 12
I fixed the problems several months ago, did some refactoring of the functions and changed the way I check for window flags. Forgot to update this thread.

You can find the finished code here:
https://github.com/RasmusEdgar/amiga.../wlist/wlist.c
edmayn is offline  
AdSense AdSense  
 


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 16:09
rawadf tool for manipulating extended ADFs Redwood News 6 15 January 2010 00:23
Workbench 3.1 or 1.3 - changing windows zygzak New to Emulation or Amiga scene 16 24 October 2009 19:11
Workbench On Windows Oxygene request.Apps 28 29 September 2008 21:24
Window Wizard: How do I clean the windows? mombasajoe support.Games 0 28 June 2008 23:25

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:20.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.24141 seconds with 14 queries