/*
 *  This program will attempt to let you at the screen depth arrangment
 *  gadgets. All windows that are tight to the top border will be moved
 *  down by one pixel, and resized if necessary (ie they are as high as
 *  the screen). After running it, you can also access the screen drag
 *  bars.
 *
 *  Does anyone else hate having to fiddle with the initial CLI window
 *  and the VT100 window to get at those $@$@#$@ gadgets???
 *
 *  ((c)) 1987, John Russell
 *  Unlimited distribution; donations to starving programmers always welcome.
 */

/*
 *  This is the second posting of this program. The first would act flakey,
 *  since there was a missing ",0L" in the OpenLibrary call. It would work
 *  time after time in some cases, and not at all in others.
 *
 *  This release also incorporates a fix which should keep it from moving any
 *  windows which really don't want to be moved (the DPaint window is one
 *  example). I initially used a delay to see if the window responded to the
 *  sizewindow message; it seems like the sizewindow itself may introduce
 *  problems, so I no longer try to size the window if it has no size gadget.
 *  There is no delay, but the window will not be moved if it is full screen-
 *  height and cannot be resized.
 */

char *copyright = "((c)) 1987, John Russell";
char *address = "5 Alderdice Place";
char *city = "St. John's, Newfoundland, Canada";
char *postal_code = "A1B 2P8";
char *phone = "(709) 726-7847";

#include "intuition/intuition.h"

struct IntuitionBase *IntuitionBase;

main(argc, argv)
int argc;
char *argv[];
{
    struct Screen *screen;
    struct Window *window;

    if ((IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0L))==NULL) {
        exit(0);
    }

    Forbid();

    screen=IntuitionBase->FirstScreen;

    while (screen) {

        window=screen->FirstWindow;

        while(window) {

            if (window->TopEdge == 0) {   /* NOT "== screen->topedge" */

                if ((window->Height == screen->Height) &&
                    (window->Flags & WINDOWSIZING)) {

/* window sent resizing message only if full screen-height AND it has a
   sizing gadget. Otherwise results with backdrop windows and those with
   odd Viewmodes, overscan, etc are unpredictable. */

                    SizeWindow(window,0,-1);
                }

                if ((window->Height != screen->Height) ||
                    (window->Flags & WINDOWSIZING) ) {

/* move a window that is
    1) not as tall as the screen and hence can be lowered
    2) equipped with a size gadget, which will shrink vertically when it
       gets the first message
*/

                    MoveWindow(window,0,1); /* move down and expose gadgets */
                }
            }
            window=window->NextWindow;
        }
        screen=screen->NextScreen;
    }

    Permit();

    CloseLibrary(IntuitionBase);
}


