home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
- /** Salt Lake City, Utah **/
- /** **/
- /** All Rights Reserved **/
- /** **/
- /** Permission to use, copy, modify, and distribute this software and **/
- /** its documentation for any purpose and without fee is hereby **/
- /** granted, provided that the above copyright notice appear in all **/
- /** copies and that both that copyright notice and this permis- **/
- /** sion notice appear in supporting documentation, and that the **/
- /** name of Evans & Sutherland not be used in advertising or publi- **/
- /** city pertaining to distribution of the software without specif- **/
- /** ic, written prior permission. **/
- /** **/
- /** EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO **/
- /** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI- **/
- /** TY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND BE LIABLE **/
- /** FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAM- **/
- /** AGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, **/
- /** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS **/
- /** ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER- **/
- /** FORMANCE OF THIS SOFTWARE. **/
- /*****************************************************************************/
-
- /**********************************************************************
- *
- * $Header: add_window.c,v 1.7 88/04/15 07:10:05 tlastran Exp $
- *
- * Add a new window, put the titlbar and other stuff around
- * the window
- *
- * 31-Mar-88 Tom LaStrange Initial Version.
- *
- **********************************************************************/
-
- #ifndef lint
- static char RCSinfo[]=
- "$Header: add_window.c,v 1.7 88/04/15 07:10:05 tlastran Exp $";
- #endif lint
-
- #include <stdio.h>
- #include "twm.h"
- #include "util.h"
- #include "resize.h"
- #include "gram.h"
- #include "list.h"
-
- #include "iconify.bm"
- #include "resize.bm"
- #include "xterm.bm"
- #include "focus.bm"
- #include "hilite.bm"
-
- static char NoName[] = "No Name"; /* name if no name is specified */
-
- /***********************************************************************
- *
- * Procedure:
- * AddWindow - add a new window to the twm list
- *
- * Returned Value:
- * (TwmWindow *) - pointer to the TwmWindow structure
- *
- * Inputs:
- * w - the window id of the window to add
- *
- ***********************************************************************
- */
-
- TwmWindow *
- AddWindow(w)
- Window w;
- {
- TwmWindow *tmp_win; /* new twm window structure */
- unsigned long valuemask; /* mask for create windows */
- XSetWindowAttributes attributes; /* attributes for create windows */
- int icon_width; /* width of the icon pixmap */
- int icon_height; /* height of the icon pixmap */
- int width; /* tmp variable */
- int x;
- Pixmap pm; /* tmp pixmap variable */
- XWindowChanges xwc; /* change window structure */
- unsigned int xwcm; /* change window mask */
-
- #ifdef DEBUG
- fprintf(stderr, "AddWindow: w = 0x%x\n", w);
- #endif
-
- /* allocate space for the twm window */
- tmp_win = (TwmWindow *)malloc(sizeof(TwmWindow));
- tmp_win->w = w;
-
- XGetWindowAttributes(dpy, tmp_win->w, &tmp_win->attr);
- XFetchName(dpy, tmp_win->w, &tmp_win->name);
- #ifdef DEBUG
- fprintf(stderr, " name = \"%s\"\n", tmp_win->name);
- #endif
- tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w);
- if (XGetNormalHints(dpy, tmp_win->w, &tmp_win->hints) == 0)
- tmp_win->hints.flags = 0;
-
- if (tmp_win->hints.flags & PSize)
- {
- #ifdef DEBUG
- fprintf(stderr, " program specified hints\n");
- #endif
- tmp_win->attr.x = tmp_win->hints.x;
- tmp_win->attr.y = tmp_win->hints.y;
- tmp_win->attr.width = tmp_win->hints.width;
- tmp_win->attr.height = tmp_win->hints.height;
- }
- if (tmp_win->hints.flags & USSize)
- {
- #ifdef DEBUG
- fprintf(stderr, " user specified hints\n");
- #endif
- tmp_win->attr.x = tmp_win->hints.x;
- tmp_win->attr.y = tmp_win->hints.y;
- tmp_win->attr.width = tmp_win->hints.width;
- tmp_win->attr.height = tmp_win->hints.height;
- }
-
- if (tmp_win->name == NULL)
- tmp_win->name = NoName;
-
- tmp_win->auto_raise = LookInList(AUTO_RAISE, tmp_win->name);
- if (LookInList(NO_TITLE, tmp_win->name))
- {
- tmp_win->title_height = 0;
- }
- else
- {
- tmp_win->title_height = TITLE_BAR_HEIGHT + BorderWidth;
- }
-
- if (tmp_win->attr.y < tmp_win->title_height)
- tmp_win->attr.y = tmp_win->title_height;
-
- xwcm = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
-
- #ifdef DEBUG
- fprintf(stderr, " position window %d, %d %dx%d\n",
- tmp_win->attr.x,
- tmp_win->attr.y,
- tmp_win->attr.width,
- tmp_win->attr.height);
- #endif
- xwc.x = tmp_win->attr.x + tmp_win->attr.border_width;
- xwc.y = tmp_win->attr.y + tmp_win->attr.border_width;
- xwc.width = tmp_win->attr.width;
- xwc.height = tmp_win->attr.height;
- xwc.border_width = 0;
-
- XConfigureWindow(dpy, tmp_win->w, xwcm, &xwc);
-
-
- tmp_win->full_name = tmp_win->name;
-
- if (strncmp("xterm", tmp_win->name, 5) == 0 ||
- strncmp("yterm", tmp_win->name, 5) == 0 ||
- strncmp("console", tmp_win->name, 7) == 0 ||
- strncmp("login", tmp_win->name, 5) == 0)
- tmp_win->xterm = TRUE;
- else
- tmp_win->xterm = FALSE;
-
- if (strncmp("xterm_", tmp_win->name, 6) == 0)
- tmp_win->name = &tmp_win->name[6];
-
- tmp_win->name_width = XTextWidth(TitleBarFont, tmp_win->name,
- strlen(tmp_win->name));
- tmp_win->icon_name = tmp_win->name;
-
- tmp_win->iconified = FALSE;
- tmp_win->icon = FALSE;
-
- /* add the window into the twm list */
- tmp_win->next = TwmRoot.next;
- if (TwmRoot.next != NULL)
- TwmRoot.next->prev = tmp_win;
- tmp_win->prev = &TwmRoot;
- TwmRoot.next = tmp_win;
-
- /* create windows */
-
- tmp_win->frame_x = tmp_win->attr.x;
- tmp_win->frame_y = tmp_win->attr.y - tmp_win->title_height;
-
- tmp_win->frame = XCreateSimpleWindow(dpy, Root,
- tmp_win->frame_x,
- tmp_win->frame_y,
- tmp_win->attr.width,
- tmp_win->attr.height + tmp_win->title_height,
- BorderWidth,
- Foreground, Background);
-
- tmp_win->title_w = XCreateSimpleWindow(dpy, tmp_win->frame,
- -BorderWidth, -BorderWidth,
- tmp_win->attr.width, TITLE_BAR_HEIGHT,
- BorderWidth,
- Foreground, Background);
-
- /* the three buttons have the pixmap as the background of the
- * window, that way I don't have to worry about repainting them
- * on expose events.
- */
-
- valuemask = CWEventMask | CWBackPixmap;
- attributes.event_mask = ButtonPressMask;
- attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
- iconify_bits, iconify_width, iconify_height);
-
- tmp_win->iconify_w = XCreateWindow(dpy, tmp_win->title_w,
- TITLE_BAR_SPACE, TITLE_BAR_SPACE,
- iconify_width, iconify_height,
- 0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
- valuemask, &attributes);
-
- attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
- focus_bits, focus_width, focus_height);
-
- tmp_win->focus_w = XCreateWindow(dpy, tmp_win->title_w,
- tmp_win->attr.width - resize_width -3 - focus_width, TITLE_BAR_SPACE,
- iconify_width, iconify_height,
- 0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
- valuemask, &attributes);
-
- attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
- resize_bits, resize_width, resize_height);
-
- tmp_win->resize_w = XCreateWindow(dpy, tmp_win->title_w,
- tmp_win->attr.width - resize_width - 1,
- TITLE_BAR_SPACE,
- resize_width, resize_height,
- 0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
- valuemask, &attributes);
-
- valuemask = CWBackPixmap;
- attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
- hilite_bits, hilite_width, hilite_height);
-
- tmp_win->hilite_w = XCreateWindow(dpy, tmp_win->title_w,
- TitleBarX, 1,
- 10, hilite_height,
- 0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
- valuemask, &attributes);
-
- XDefineCursor(dpy, tmp_win->title_w, ArrowCursor);
- XDefineCursor(dpy, tmp_win->iconify_w, ButtonCursor);
- XDefineCursor(dpy, tmp_win->focus_w, ButtonCursor);
- XDefineCursor(dpy, tmp_win->resize_w, ButtonCursor);
-
- XSelectInput(dpy, tmp_win->w, StructureNotifyMask);
- XSelectInput(dpy, tmp_win->frame,
- ButtonPressMask | EnterWindowMask | LeaveWindowMask);
-
- XSelectInput(dpy, tmp_win->title_w,
- ButtonPressMask | ButtonReleaseMask |
- ExposureMask | ButtonMotionMask);
-
- XAddToSaveSet(dpy, tmp_win->w);
- XReparentWindow(dpy, tmp_win->w, tmp_win->frame, 0, tmp_win->title_height);
-
- SetupWindow(tmp_win,
- tmp_win->frame_x,
- tmp_win->frame_y,
- tmp_win->attr.width,
- tmp_win->attr.height + tmp_win->title_height);
-
- pm = NULL;
- if (tmp_win->wmhints && tmp_win->wmhints->flags & IconPixmapHint)
- {
- XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap,
- &JunkRoot, &JunkX, &JunkY,
- &icon_width, &icon_height, &JunkBW,
- &JunkDepth);
-
- pm = XCreatePixmap(dpy, Root, icon_width, icon_height,
- DefaultDepth(dpy, 0));
-
- XCopyPlane(dpy, tmp_win->wmhints->icon_pixmap, pm, MenuNormalGC,
- 0,0, icon_width, icon_height, 0, 0, 1 );
- }
- else
- {
- if (tmp_win->xterm)
- {
- pm = MakePixmap(Root, MenuNormalGC,
- xterm_bits, xterm_width, xterm_height);
- icon_width = xterm_width;
- icon_height = xterm_height;
- }
- else if (UnknownPm != NULL)
- {
- XImage *image;
- unsigned mask;
-
- icon_width = UnknownWidth;
- icon_height = UnknownHeight;
- mask = Foreground ^ Background;
- image = XGetImage(dpy, UnknownPm, 0, 0, icon_width, icon_height,
- mask, XYPixmap);
-
- pm = XCreatePixmap(dpy, Root, icon_width, icon_height,
- DefaultDepth(dpy, 0));
-
- XPutImage(dpy, pm, TitleNormalGC,
- image, 0, 0, 0, 0, icon_width, icon_height);
- }
- }
-
- if (pm == NULL)
- {
- icon_height = 0;
- icon_width = 0;
- valuemask = 0;
- }
- else
- {
- valuemask = CWBackPixmap;
- attributes.background_pixmap = pm;
- }
-
- width = XTextWidth(IconFont,
- tmp_win->icon_name, strlen(tmp_win->icon_name));
-
- width += 6;
- if (width < icon_width)
- {
- tmp_win->icon_x = (icon_width - width)/2;
- tmp_win->icon_x += 3;
- width = icon_width;
- }
- else
- {
- tmp_win->icon_x = 3;
- }
- tmp_win->icon_y = icon_height + IconFontHeight;
-
- if (tmp_win->wmhints && tmp_win->wmhints->flags & IconWindowHint)
- {
- tmp_win->icon_w = tmp_win->wmhints->icon_window;
- }
- else
- {
- tmp_win->icon_w = XCreateSimpleWindow(dpy, Root,
- 0,0,
- width,
- icon_height + IconFontHeight + 4,
- 2, Foreground, Background);
- }
-
- XSelectInput(dpy, tmp_win->icon_w,
- ButtonPressMask | ExposureMask);
-
- if (pm != NULL)
- {
- if (width == icon_width)
- x = 0;
- else
- x = (width - icon_width)/2;
-
- XCreateWindow(dpy, tmp_win->icon_w,
- x, 0,
- icon_width, icon_height,
- 0, DefaultDepth(dpy, 0), CopyFromParent,
- DefaultVisual(dpy,0),
- valuemask, &attributes);
- }
-
- XDefineCursor(dpy, tmp_win->icon_w, ArrowCursor);
-
- XSaveContext(dpy, tmp_win->w, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->frame, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->title_w, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->iconify_w, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->resize_w, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->icon_w, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->focus_w, TwmContext, tmp_win);
- XSaveContext(dpy, tmp_win->hilite_w, TwmContext, tmp_win);
-
- return (tmp_win);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * MappedNotOverride - checks to see if we should really
- * put a twm frame on the window
- *
- * Returned Value:
- * TRUE - go ahead and frame the window
- * FALSE - don't frame the window
- *
- * Inputs:
- * w - the window to check
- *
- ***********************************************************************
- */
-
- int
- MappedNotOverride(w)
- Window w;
- {
- XWindowAttributes wa;
-
- XGetWindowAttributes(dpy, w, &wa);
- return ((wa.map_state != IsUnmapped) && (wa.override_redirect != True));
- }
-