Example #1
0
/*
*+
*  Name:
*     Foreground
*
*  Purpose:
*     Demonstrate how to change the foreground of a GWM window.
*
*  Language:
*     C
*
*  Invocation:
*     foreground <window name> <colour>
*
*  Description:
*     The foreground window property is updated and the colour table
*     updated either buy changing the colour representation of entry
*     1 (if the colour table is writable) or changing the value of
*     entry 1 to point to the closest available colour.
*
*  Arguments:
*
*  Copyright:
*     Copyright (C) 1992 Science & Engineering Research Council.
*     All Rights Reserved.

*  Licence:
*     This program is free software; you can redistribute it and/or
*     modify it under the terms of the GNU General Public License as
*     published by the Free Software Foundation; either version 2 of
*     the License, or (at your option) any later version.
*
*     This program is distributed in the hope that it will be
*     useful,but WITHOUT ANY WARRANTY; without even the implied
*     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
*     PURPOSE. See the GNU General Public License for more details.
*
*     You should have received a copy of the GNU General Public License
*     along with this program; if not, write to the Free Software
*     Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA
*     02110-1301, USA

*  Authors:
*     DLT: David Terrett (Starlink RAL)
*     {enter_new_authors_here}
*
*  History:
*      3-APR-1992 (DLT):
*        Orignal version
*     {enter_changes_here}
*
*  Bugs:
*     The error handling is somewhat brutal!
*     {note_any_bugs_here}
*-
*/
int main(int argc, char *argv[])
{
    Display *display;                             /* display id              */
    Window win;                                   /* window id               */
    Pixmap pix;                                   /* pixmap id               */
    int status;                                   /* status                  */
    unsigned int width, height, border, depth;    /*    "        "           */
    unsigned long *table, size;                   /* colour table array      */
    int visual_class;				  /* visual class of display */
    XColor fg_color;				  /* X colour structure */

/*
**  Open the default X display
*/
    display = XOpenDisplay( NULL );

/*
**  Get the id of the specified window
*/
    status = GWM_FindWindow( display, argv[1], &win);
    if (status) GWM_Error(status);

/*
**  Get the associated colour table array
*/
    status = GWM_GetColTable( display, win, &table, &size);
    if (status) GWM_Error(status);

/*
**  Set the new foreground window property
*/
    status = GWM_SetFgCol( display, win, argv[2]);
    if (status) GWM_Error(status);

/*
**  Convert the colour specification to an XColor structure (the
**  specification must be valid because SetFgCol succeeded).
*/
    XParseColor( display, DefaultColormap( display, DefaultScreen( display )),
	argv[2], &fg_color);

/*
**  Get the visual class of the display
*/
    visual_class = DefaultVisual( display, DefaultScreen( display ) )-> class;

    if (visual_class == StaticGray || visual_class == StaticColor ||
            visual_class == TrueColor )
    {

/*
**     Colour table is static so find nearest available colour
*/
        XAllocColor( display, DefaultColormap( display,
            DefaultScreen( display )), &fg_color);
        table[1] = fg_color.pixel;

/*
**      Write the revised colour table back to the window
*/
	status = GWM_SetColTable( display, win, table, size);
    }
    else
    {

/*
**      Colour table is dynamic so store the new colour in the server's
**      colourmap.
*/
	fg_color.pixel = table[1];
	XStoreColor( display, DefaultColormap( display,
            DefaultScreen( display )), &fg_color);
     }

/*
**  Close the display
*/
    XCloseDisplay( display);
}
Example #2
0
/*
*+
*  Name:
*     Scroll
*
*  Purpose:
*     Demonstrate how to scroll the contents of a GWM window.
*
*  Language:
*     C
*
*  Invocation:
*     scroll <window name> <x offset> <y offset>
*
*  Description:
*     The specified values are added to the scroll offsets and the the
*     window contents updated.
*
*  Arguments:
*
*  Copyright:
*     Copyright (C) 1992 Science & Engineering Research Council.
*     All Rights Reserved.

*  Licence:
*     This program is free software; you can redistribute it and/or
*     modify it under the terms of the GNU General Public License as
*     published by the Free Software Foundation; either version 2 of
*     the License, or (at your option) any later version.
*
*     This program is distributed in the hope that it will be
*     useful,but WITHOUT ANY WARRANTY; without even the implied
*     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
*     PURPOSE. See the GNU General Public License for more details.
*
*     You should have received a copy of the GNU General Public License
*     along with this program; if not, write to the Free Software
*     Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA
*     02110-1301, USA

*  Authors:
*     DLT: David Terrett (Starlink RAL)
*     {enter_new_authors_here}
*
*  History:
*      9-MAR-1992 (DLT):
*        Orignal version
*     {enter_changes_here}
*
*  Bugs:
*     The error handling is somewhat brutal!
*     {note_any_bugs_here}
*-
*/
int main(int argc, char *argv[])
{
    Display *display;                             /* display id              */
    Window win;                                   /* window id               */
    Pixmap pix;                                   /* pixmap id               */
    int status;                                   /* status                  */
    unsigned long mask;                            /* overlay plane mask      */
    GC gc;                                        /* graphics context        */
    XGCValues gcval;                              /* graphics context values */
    int xoff, yoff, addxoff, addyoff;             /* window offsets          */
    Window root;                                  /* parent window id        */
    int x, y;                                     /* pixmap dimensions       */
    unsigned int width, height, border, depth;    /*    "        "           */
    unsigned long *table, size;                   /* colour table array      */

    /*
    **  Open the default X display
    */
    display = XOpenDisplay( NULL );

    /*
    **  Get the id of the specified window
    */
    status = GWM_FindWindow( display, argv[1], &win);
    if (status) GWM_Error(status);

    /*
    **  Get the id of the assocated pixmap
    */
    status = GWM_GetPixmap( display, win, &pix);
    if (status) GWM_Error(status);

    /*
    **  Get the overlay mask
    */
    status = GWM_GetOvMask( display, win, &mask);
    if (status) GWM_Error(status);

    /*
    **  Get the current scroll values
    */
    status = GWM_GetScroll( display, win, &xoff, &yoff);

    /*
    **  Get the associated colour table array
    */
    status = GWM_GetColTable( display, win, &table, &size);
    if (status) GWM_Error(status);

    /*
    **  Get the dimensions of the pixmap
    */
    XGetGeometry( display, pix, &root, &x, &y, &width, &height, &border,
                  &depth);

    /*
    **  Create a graphics context with the foreground set to the background
    **  colour of the window (entry 0 in the colour table array) and the plane
    **  mask set to protect the overlay plane.
    */
    gcval.foreground = table[0];
    gcval.plane_mask = mask;
    gc = XCreateGC( display, win, GCForeground | GCPlaneMask, &gcval);

    /*
    **  Erase the area of the window currently occupied by the pixmap
    */
    XFillRectangle( display, win, gc, xoff, yoff, width, height);

    /*
    **  decode the offset arguments
    */
    sscanf( argv[2], "%d", &addxoff);
    sscanf( argv[3], "%d", &addyoff);

    /*
    **  Set the new scroll values
    */
    status = GWM_SetScroll( display, win, xoff + addxoff, yoff + addyoff);
    /*
    **  Copy the pixmap to the new location in the window
    */
    XCopyArea( display, pix, win, gc, 0, 0, width, height,
               xoff + addxoff, yoff + addyoff);

    /*
    **  Close the display
    */
    XCloseDisplay( display);
}