tkUnixWm.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:195k
- /*
- * tkUnixWm.c --
- *
- * This module takes care of the interactions between a Tk-based
- * application and the window manager. Among other things, it
- * implements the "wm" command and passes geometry information
- * to the window manager.
- *
- * Copyright (c) 1991-1994 The Regents of the University of California.
- * Copyright (c) 1994-1997 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tkUnixWm.c,v 1.36.2.7 2006/04/11 20:23:45 hobbs Exp $
- */
- #include "tkPort.h"
- #include "tkInt.h"
- #include "tkUnixInt.h"
- /*
- * A data structure of the following type holds information for
- * each window manager protocol (such as WM_DELETE_WINDOW) for
- * which a handler (i.e. a Tcl command) has been defined for a
- * particular top-level window.
- */
- typedef struct ProtocolHandler {
- Atom protocol; /* Identifies the protocol. */
- struct ProtocolHandler *nextPtr;
- /* Next in list of protocol handlers for
- * the same top-level window, or NULL for
- * end of list. */
- Tcl_Interp *interp; /* Interpreter in which to invoke command. */
- char command[4]; /* Tcl command to invoke when a client
- * message for this protocol arrives.
- * The actual size of the structure varies
- * to accommodate the needs of the actual
- * command. THIS MUST BE THE LAST FIELD OF
- * THE STRUCTURE. */
- } ProtocolHandler;
- #define HANDLER_SIZE(cmdLength)
- ((unsigned) (sizeof(ProtocolHandler) - 3 + cmdLength))
- /*
- * A data structure of the following type holds window-manager-related
- * information for each top-level window in an application.
- */
- typedef struct TkWmInfo {
- TkWindow *winPtr; /* Pointer to main Tk information for
- * this window. */
- Window reparent; /* If the window has been reparented, this
- * gives the ID of the ancestor of the window
- * that is a child of the root window (may
- * not be window's immediate parent). If
- * the window isn't reparented, this has the
- * value None. */
- char *title; /* Title to display in window caption. If
- * NULL, use name of widget. Malloced. */
- char *iconName; /* Name to display in icon. Malloced. */
- XWMHints hints; /* Various pieces of information for
- * window manager. */
- char *leaderName; /* Path name of leader of window group
- * (corresponds to hints.window_group).
- * Malloc-ed. Note: this field doesn't
- * get updated if leader is destroyed. */
- TkWindow *masterPtr; /* Master window for TRANSIENT_FOR property,
- * or NULL. */
- Tk_Window icon; /* Window to use as icon for this window,
- * or NULL. */
- Tk_Window iconFor; /* Window for which this window is icon, or
- * NULL if this isn't an icon for anyone. */
- int withdrawn; /* Non-zero means window has been withdrawn. */
- /*
- * In order to support menubars transparently under X, each toplevel
- * window is encased in an additional window, called the wrapper,
- * that holds the toplevel and the menubar, if any. The information
- * below is used to keep track of the wrapper and the menubar.
- */
- TkWindow *wrapperPtr; /* Pointer to information about the wrapper.
- * This is the "real" toplevel window as
- * seen by the window manager. Although
- * this is an official Tk window, it
- * doesn't appear in the application's
- * window hierarchy. NULL means that
- * the wrapper hasn't been created yet. */
- Tk_Window menubar; /* Pointer to information about the
- * menubar, or NULL if there is no
- * menubar for this toplevel. */
- int menuHeight; /* Amount of vertical space needed for
- * menubar, measured in pixels. If
- * menubar is non-NULL, this is >= 1 (X
- * servers don't like dimensions of 0). */
- /*
- * Information used to construct an XSizeHints structure for
- * the window manager:
- */
- int sizeHintsFlags; /* Flags word for XSizeHints structure.
- * If the PBaseSize flag is set then the
- * window is gridded; otherwise it isn't
- * gridded. */
- int minWidth, minHeight; /* Minimum dimensions of window, in
- * pixels or grid units. */
- int maxWidth, maxHeight; /* Maximum dimensions of window, in
- * pixels or grid units. 0 to default.*/
- Tk_Window gridWin; /* Identifies the window that controls
- * gridding for this top-level, or NULL if
- * the top-level isn't currently gridded. */
- int widthInc, heightInc; /* Increments for size changes (# pixels
- * per step). */
- struct {
- int x; /* numerator */
- int y; /* denominator */
- } minAspect, maxAspect; /* Min/max aspect ratios for window. */
- int reqGridWidth, reqGridHeight;
- /* The dimensions of the window (in
- * grid units) requested through
- * the geometry manager. */
- int gravity; /* Desired window gravity. */
- /*
- * Information used to manage the size and location of a window.
- */
- int width, height; /* Desired dimensions of window, specified
- * in pixels or grid units. These values are
- * set by the "wm geometry" command and by
- * ConfigureNotify events (for when wm
- * resizes window). -1 means user hasn't
- * requested dimensions. */
- int x, y; /* Desired X and Y coordinates for window.
- * These values are set by "wm geometry",
- * plus by ConfigureNotify events (when wm
- * moves window). These numbers are
- * different than the numbers stored in
- * winPtr->changes because (a) they could be
- * measured from the right or bottom edge
- * of the screen (see WM_NEGATIVE_X and
- * WM_NEGATIVE_Y flags) and (b) if the window
- * has been reparented then they refer to the
- * parent rather than the window itself. */
- int parentWidth, parentHeight;
- /* Width and height of reparent, in pixels
- * *including border*. If window hasn't been
- * reparented then these will be the outer
- * dimensions of the window, including
- * border. */
- int xInParent, yInParent; /* Offset of wrapperPtr within reparent,
- * measured in pixels from upper-left outer
- * corner of reparent's border to upper-left
- * outer corner of wrapperPtr's border. If
- * not reparented then these are zero. */
- int configWidth, configHeight;
- /* Dimensions passed to last request that we
- * issued to change geometry of the wrapper.
- * Used to eliminate redundant resize
- * operations. */
- /*
- * Information about the virtual root window for this top-level,
- * if there is one.
- */
- Window vRoot; /* Virtual root window for this top-level,
- * or None if there is no virtual root
- * window (i.e. just use the screen's root). */
- int vRootX, vRootY; /* Position of the virtual root inside the
- * root window. If the WM_VROOT_OFFSET_STALE
- * flag is set then this information may be
- * incorrect and needs to be refreshed from
- * the X server. If vRoot is None then these
- * values are both 0. */
- int vRootWidth, vRootHeight;/* Dimensions of the virtual root window.
- * If vRoot is None, gives the dimensions
- * of the containing screen. This information
- * is never stale, even though vRootX and
- * vRootY can be. */
- /*
- * Miscellaneous information.
- */
- ProtocolHandler *protPtr; /* First in list of protocol handlers for
- * this window (NULL means none). */
- int cmdArgc; /* Number of elements in cmdArgv below. */
- CONST char **cmdArgv; /* Array of strings to store in the
- * WM_COMMAND property. NULL means nothing
- * available. */
- char *clientMachine; /* String to store in WM_CLIENT_MACHINE
- * property, or NULL. */
- int flags; /* Miscellaneous flags, defined below. */
- int numTransients; /* number of transients on this window */
- int iconDataSize; /* size of iconphoto image data */
- unsigned char *iconDataPtr; /* iconphoto image data, if set */
- struct TkWmInfo *nextPtr; /* Next in list of all top-level windows. */
- } WmInfo;
- /*
- * Flag values for WmInfo structures:
- *
- * WM_NEVER_MAPPED - non-zero means window has never been
- * mapped; need to update all info when
- * window is first mapped.
- * WM_UPDATE_PENDING - non-zero means a call to UpdateGeometryInfo
- * has already been scheduled for this
- * window; no need to schedule another one.
- * WM_NEGATIVE_X - non-zero means x-coordinate is measured in
- * pixels from right edge of screen, rather
- * than from left edge.
- * WM_NEGATIVE_Y - non-zero means y-coordinate is measured in
- * pixels up from bottom of screen, rather than
- * down from top.
- * WM_UPDATE_SIZE_HINTS - non-zero means that new size hints need to be
- * propagated to window manager.
- * WM_SYNC_PENDING - set to non-zero while waiting for the window
- * manager to respond to some state change.
- * WM_VROOT_OFFSET_STALE - non-zero means that (x,y) offset information
- * about the virtual root window is stale and
- * needs to be fetched fresh from the X server.
- * WM_ABOUT_TO_MAP - non-zero means that the window is about to
- * be mapped by TkWmMapWindow. This is used
- * by UpdateGeometryInfo to modify its behavior.
- * WM_MOVE_PENDING - non-zero means the application has requested
- * a new position for the window, but it hasn't
- * been reflected through the window manager
- * yet.
- * WM_COLORMAPS_EXPLICIT - non-zero means the colormap windows were
- * set explicitly via "wm colormapwindows".
- * WM_ADDED_TOPLEVEL_COLORMAP - non-zero means that when "wm colormapwindows"
- * was called the top-level itself wasn't
- * specified, so we added it implicitly at
- * the end of the list.
- * WM_WIDTH_NOT_RESIZABLE - non-zero means that we're not supposed to
- * allow the user to change the width of the
- * window (controlled by "wm resizable"
- * command).
- * WM_HEIGHT_NOT_RESIZABLE - non-zero means that we're not supposed to
- * allow the user to change the height of the
- * window (controlled by "wm resizable"
- * command).
- * WM_WITHDRAWN - non-zero means that this window has explicitly
- * been withdrawn. If it's a transient, it should
- * not mirror state changes in the master.
- */
- #define WM_NEVER_MAPPED 1
- #define WM_UPDATE_PENDING 2
- #define WM_NEGATIVE_X 4
- #define WM_NEGATIVE_Y 8
- #define WM_UPDATE_SIZE_HINTS 0x10
- #define WM_SYNC_PENDING 0x20
- #define WM_VROOT_OFFSET_STALE 0x40
- #define WM_ABOUT_TO_MAP 0x100
- #define WM_MOVE_PENDING 0x200
- #define WM_COLORMAPS_EXPLICIT 0x400
- #define WM_ADDED_TOPLEVEL_COLORMAP 0x800
- #define WM_WIDTH_NOT_RESIZABLE 0x1000
- #define WM_HEIGHT_NOT_RESIZABLE 0x2000
- #define WM_WITHDRAWN 0x4000
- /*
- * This module keeps a list of all top-level windows, primarily to
- * simplify the job of Tk_CoordsToWindow. The list is called
- * firstWmPtr and is stored in the TkDisplay structure.
- */
- /*
- * The following structures are the official type records for geometry
- * management of top-level and menubar windows.
- */
- static void TopLevelReqProc _ANSI_ARGS_((ClientData dummy,
- Tk_Window tkwin));
- static Tk_GeomMgr wmMgrType = {
- "wm", /* name */
- TopLevelReqProc, /* requestProc */
- (Tk_GeomLostSlaveProc *) NULL, /* lostSlaveProc */
- };
- static void MenubarReqProc _ANSI_ARGS_((ClientData clientData,
- Tk_Window tkwin));
- static Tk_GeomMgr menubarMgrType = {
- "menubar", /* name */
- MenubarReqProc, /* requestProc */
- (Tk_GeomLostSlaveProc *) NULL, /* lostSlaveProc */
- };
- /*
- * Structures of the following type are used for communication between
- * WaitForEvent, WaitRestrictProc, and WaitTimeoutProc.
- */
- typedef struct WaitRestrictInfo {
- Display *display; /* Window belongs to this display. */
- WmInfo *wmInfoPtr;
- int type; /* We only care about this type of event. */
- XEvent *eventPtr; /* Where to store the event when it's found. */
- int foundEvent; /* Non-zero means that an event of the
- * desired type has been found. */
- } WaitRestrictInfo;
- /*
- * Forward declarations for procedures defined in this file:
- */
- static int ComputeReparentGeometry _ANSI_ARGS_((WmInfo *wmPtr));
- static void ConfigureEvent _ANSI_ARGS_((WmInfo *wmPtr,
- XConfigureEvent *eventPtr));
- static void CreateWrapper _ANSI_ARGS_((WmInfo *wmPtr));
- static void GetMaxSize _ANSI_ARGS_((WmInfo *wmPtr,
- int *maxWidthPtr, int *maxHeightPtr));
- static void MenubarDestroyProc _ANSI_ARGS_((ClientData clientData,
- XEvent *eventPtr));
- static int ParseGeometry _ANSI_ARGS_((Tcl_Interp *interp,
- char *string, TkWindow *winPtr));
- static void ReparentEvent _ANSI_ARGS_((WmInfo *wmPtr,
- XReparentEvent *eventPtr));
- static void TkWmStackorderToplevelWrapperMap _ANSI_ARGS_((
- TkWindow *winPtr,
- Display *display,
- Tcl_HashTable *reparentTable));
- static void TopLevelReqProc _ANSI_ARGS_((ClientData dummy,
- Tk_Window tkwin));
- static void UpdateCommand _ANSI_ARGS_((TkWindow *winPtr));
- static void UpdateGeometryInfo _ANSI_ARGS_((
- ClientData clientData));
- static void UpdateHints _ANSI_ARGS_((TkWindow *winPtr));
- static void UpdateSizeHints _ANSI_ARGS_((TkWindow *winPtr,
- int newWidth, int newHeight));
- static void UpdateTitle _ANSI_ARGS_((TkWindow *winPtr));
- static void UpdatePhotoIcon _ANSI_ARGS_((TkWindow *winPtr));
- static void UpdateVRootGeometry _ANSI_ARGS_((WmInfo *wmPtr));
- static void UpdateWmProtocols _ANSI_ARGS_((WmInfo *wmPtr));
- static void WaitForConfigureNotify _ANSI_ARGS_((TkWindow *winPtr,
- unsigned long serial));
- static int WaitForEvent _ANSI_ARGS_((Display *display,
- WmInfo *wmInfoPtr, int type, XEvent *eventPtr));
- static void WaitForMapNotify _ANSI_ARGS_((TkWindow *winPtr,
- int mapped));
- static Tk_RestrictAction
- WaitRestrictProc _ANSI_ARGS_((ClientData clientData,
- XEvent *eventPtr));
- static void WrapperEventProc _ANSI_ARGS_((ClientData clientData,
- XEvent *eventPtr));
- static void WmWaitMapProc _ANSI_ARGS_((
- ClientData clientData, XEvent *eventPtr));
- static int WmAspectCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmAttributesCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmClientCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmColormapwindowsCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmCommandCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmDeiconifyCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmFocusmodelCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmFrameCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmGeometryCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmGridCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmGroupCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconbitmapCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconifyCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconmaskCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconnameCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconphotoCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconpositionCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmIconwindowCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmMaxsizeCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmMinsizeCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmOverrideredirectCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmPositionfromCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmProtocolCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmResizableCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmSizefromCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmStackorderCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmStateCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmTitleCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmTransientCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static int WmWithdrawCmd _ANSI_ARGS_((Tk_Window tkwin,
- TkWindow *winPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]));
- static void WmUpdateGeom _ANSI_ARGS_((WmInfo *wmPtr,
- TkWindow *winPtr));
- /*
- *--------------------------------------------------------------
- *
- * TkWmCleanup --
- *
- * This procedure is invoked to cleanup remaining wm resources
- * associated with a display.
- *
- * Results:
- * None.
- *
- * Side effects:
- * All WmInfo structure resources are freed and invalidated.
- *
- *--------------------------------------------------------------
- */
- void TkWmCleanup(dispPtr)
- TkDisplay *dispPtr;
- {
- WmInfo *wmPtr, *nextPtr;
- for (wmPtr = dispPtr->firstWmPtr; wmPtr != NULL; wmPtr = nextPtr) {
- /*
- * We can't assume we have access to winPtr's anymore, so some
- * cleanup requiring winPtr data is avoided.
- */
- nextPtr = wmPtr->nextPtr;
- if (wmPtr->title != NULL) {
- ckfree(wmPtr->title);
- }
- if (wmPtr->iconName != NULL) {
- ckfree(wmPtr->iconName);
- }
- if (wmPtr->iconDataPtr != NULL) {
- ckfree((char *)wmPtr->iconDataPtr);
- }
- if (wmPtr->leaderName != NULL) {
- ckfree(wmPtr->leaderName);
- }
- if (wmPtr->menubar != NULL) {
- Tk_DestroyWindow(wmPtr->menubar);
- }
- if (wmPtr->wrapperPtr != NULL) {
- Tk_DestroyWindow((Tk_Window) wmPtr->wrapperPtr);
- }
- while (wmPtr->protPtr != NULL) {
- ProtocolHandler *protPtr;
- protPtr = wmPtr->protPtr;
- wmPtr->protPtr = protPtr->nextPtr;
- Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC);
- }
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- }
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- }
- ckfree((char *) wmPtr);
- }
- if (dispPtr->iconDataPtr != NULL) {
- ckfree((char *)dispPtr->iconDataPtr);
- dispPtr->iconDataPtr = NULL;
- }
- }
- /*
- *--------------------------------------------------------------
- *
- * TkWmNewWindow --
- *
- * This procedure is invoked whenever a new top-level
- * window is created. Its job is to initialize the WmInfo
- * structure for the window.
- *
- * Results:
- * None.
- *
- * Side effects:
- * A WmInfo structure gets allocated and initialized.
- *
- *--------------------------------------------------------------
- */
- void
- TkWmNewWindow(winPtr)
- TkWindow *winPtr; /* Newly-created top-level window. */
- {
- register WmInfo *wmPtr;
- TkDisplay *dispPtr = winPtr->dispPtr;
- wmPtr = (WmInfo *) ckalloc(sizeof(WmInfo));
- memset(wmPtr, 0, sizeof(WmInfo));
- wmPtr->winPtr = winPtr;
- wmPtr->reparent = None;
- wmPtr->masterPtr = NULL;
- wmPtr->numTransients = 0;
- wmPtr->hints.flags = InputHint | StateHint;
- wmPtr->hints.input = True;
- wmPtr->hints.initial_state = NormalState;
- wmPtr->hints.icon_pixmap = None;
- wmPtr->hints.icon_window = None;
- wmPtr->hints.icon_x = wmPtr->hints.icon_y = 0;
- wmPtr->hints.icon_mask = None;
- wmPtr->hints.window_group = None;
- /*
- * Default the maximum dimensions to the size of the display, minus
- * a guess about how space is needed for window manager decorations.
- */
- wmPtr->gridWin = NULL;
- wmPtr->minWidth = wmPtr->minHeight = 1;
- wmPtr->maxWidth = wmPtr->maxHeight = 0;
- wmPtr->widthInc = wmPtr->heightInc = 1;
- wmPtr->minAspect.x = wmPtr->minAspect.y = 1;
- wmPtr->maxAspect.x = wmPtr->maxAspect.y = 1;
- wmPtr->reqGridWidth = wmPtr->reqGridHeight = -1;
- wmPtr->gravity = NorthWestGravity;
- wmPtr->width = -1;
- wmPtr->height = -1;
- wmPtr->x = winPtr->changes.x;
- wmPtr->y = winPtr->changes.y;
- wmPtr->parentWidth = winPtr->changes.width
- + 2*winPtr->changes.border_width;
- wmPtr->parentHeight = winPtr->changes.height
- + 2*winPtr->changes.border_width;
- wmPtr->configWidth = -1;
- wmPtr->configHeight = -1;
- wmPtr->vRoot = None;
- wmPtr->flags = WM_NEVER_MAPPED;
- wmPtr->nextPtr = (WmInfo *) dispPtr->firstWmPtr;
- dispPtr->firstWmPtr = wmPtr;
- winPtr->wmInfoPtr = wmPtr;
- UpdateVRootGeometry(wmPtr);
- /*
- * Arrange for geometry requests to be reflected from the window
- * to the window manager.
- */
- Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, (ClientData) 0);
- }
- /*
- *--------------------------------------------------------------
- *
- * TkWmMapWindow --
- *
- * This procedure is invoked to map a top-level window. This
- * module gets a chance to update all window-manager-related
- * information in properties before the window manager sees
- * the map event and checks the properties. It also gets to
- * decide whether or not to even map the window after all.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Properties of winPtr may get updated to provide up-to-date
- * information to the window manager. The window may also get
- * mapped, but it may not be if this procedure decides that
- * isn't appropriate (e.g. because the window is withdrawn).
- *
- *--------------------------------------------------------------
- */
- void
- TkWmMapWindow(winPtr)
- TkWindow *winPtr; /* Top-level window that's about to
- * be mapped. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- XTextProperty textProp;
- if (wmPtr->flags & WM_NEVER_MAPPED) {
- Tcl_DString ds;
- wmPtr->flags &= ~WM_NEVER_MAPPED;
- /*
- * This is the first time this window has ever been mapped.
- * First create the wrapper window that provides space for a
- * menubar.
- */
- if (wmPtr->wrapperPtr == NULL) {
- CreateWrapper(wmPtr);
- }
- /*
- * Store all the window-manager-related information for the
- * window.
- */
- TkWmSetClass(winPtr);
- UpdateTitle(winPtr);
- UpdatePhotoIcon(winPtr);
- if (wmPtr->masterPtr != NULL) {
- /*
- * Don't map a transient if the master is not mapped.
- */
- if (!Tk_IsMapped(wmPtr->masterPtr)) {
- wmPtr->withdrawn = 1;
- wmPtr->hints.initial_state = WithdrawnState;
- } else {
- XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
- wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
- }
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- UpdateHints(winPtr);
- UpdateWmProtocols(wmPtr);
- if (wmPtr->cmdArgv != NULL) {
- UpdateCommand(winPtr);
- }
- if (wmPtr->clientMachine != NULL) {
- Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, -1, &ds);
- if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
- &textProp) != 0) {
- XSetWMClientMachine(winPtr->display, wmPtr->wrapperPtr->window,
- &textProp);
- XFree((char *) textProp.value);
- }
- Tcl_DStringFree(&ds);
- }
- }
- if (wmPtr->hints.initial_state == WithdrawnState) {
- return;
- }
- if (wmPtr->iconFor != NULL) {
- /*
- * This window is an icon for somebody else. Make sure that
- * the geometry is up-to-date, then return without mapping
- * the window.
- */
- if (wmPtr->flags & WM_UPDATE_PENDING) {
- Tcl_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
- }
- UpdateGeometryInfo((ClientData) winPtr);
- return;
- }
- wmPtr->flags |= WM_ABOUT_TO_MAP;
- if (wmPtr->flags & WM_UPDATE_PENDING) {
- Tcl_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
- }
- UpdateGeometryInfo((ClientData) winPtr);
- wmPtr->flags &= ~WM_ABOUT_TO_MAP;
- /*
- * Map the window, then wait to be sure that the window manager has
- * processed the map operation.
- */
- XMapWindow(winPtr->display, wmPtr->wrapperPtr->window);
- if (wmPtr->hints.initial_state == NormalState) {
- WaitForMapNotify(winPtr, 1);
- }
- }
- /*
- *--------------------------------------------------------------
- *
- * TkWmUnmapWindow --
- *
- * This procedure is invoked to unmap a top-level window. The
- * only thing it does special is to wait for the window actually
- * to be unmapped.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Unmaps the window.
- *
- *--------------------------------------------------------------
- */
- void
- TkWmUnmapWindow(winPtr)
- TkWindow *winPtr; /* Top-level window that's about to
- * be mapped. */
- {
- /*
- * It seems to be important to wait after unmapping a top-level
- * window until the window really gets unmapped. I don't completely
- * understand all the interactions with the window manager, but if
- * we go on without waiting, and if the window is then mapped again
- * quickly, events seem to get lost so that we think the window isn't
- * mapped when in fact it is mapped. I suspect that this has something
- * to do with the window manager filtering Map events (and possily not
- * filtering Unmap events?).
- */
- XUnmapWindow(winPtr->display, winPtr->wmInfoPtr->wrapperPtr->window);
- WaitForMapNotify(winPtr, 0);
- }
- /*
- *--------------------------------------------------------------
- *
- * TkWmDeadWindow --
- *
- * This procedure is invoked when a top-level window is
- * about to be deleted. It cleans up the wm-related data
- * structures for the window.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The WmInfo structure for winPtr gets freed up.
- *
- *--------------------------------------------------------------
- */
- void
- TkWmDeadWindow(winPtr)
- TkWindow *winPtr; /* Top-level window that's being deleted. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- WmInfo *wmPtr2;
- if (wmPtr == NULL) {
- return;
- }
- if ((WmInfo *) winPtr->dispPtr->firstWmPtr == wmPtr) {
- winPtr->dispPtr->firstWmPtr = wmPtr->nextPtr;
- } else {
- register WmInfo *prevPtr;
- for (prevPtr = (WmInfo *) winPtr->dispPtr->firstWmPtr; ;
- prevPtr = prevPtr->nextPtr) {
- if (prevPtr == NULL) {
- Tcl_Panic("couldn't unlink window in TkWmDeadWindow");
- }
- if (prevPtr->nextPtr == wmPtr) {
- prevPtr->nextPtr = wmPtr->nextPtr;
- break;
- }
- }
- }
- if (wmPtr->title != NULL) {
- ckfree(wmPtr->title);
- }
- if (wmPtr->iconName != NULL) {
- ckfree(wmPtr->iconName);
- }
- if (wmPtr->iconDataPtr != NULL) {
- ckfree((char *)wmPtr->iconDataPtr);
- }
- if (wmPtr->hints.flags & IconPixmapHint) {
- Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
- }
- if (wmPtr->hints.flags & IconMaskHint) {
- Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_mask);
- }
- if (wmPtr->leaderName != NULL) {
- ckfree(wmPtr->leaderName);
- }
- if (wmPtr->icon != NULL) {
- wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
- wmPtr2->iconFor = NULL;
- wmPtr2->withdrawn = 1;
- }
- if (wmPtr->iconFor != NULL) {
- wmPtr2 = ((TkWindow *) wmPtr->iconFor)->wmInfoPtr;
- wmPtr2->icon = NULL;
- wmPtr2->hints.flags &= ~IconWindowHint;
- UpdateHints((TkWindow *) wmPtr->iconFor);
- }
- if (wmPtr->menubar != NULL) {
- Tk_DestroyWindow(wmPtr->menubar);
- }
- if (wmPtr->wrapperPtr != NULL) {
- /*
- * The rest of Tk doesn't know that we reparent the toplevel
- * inside the wrapper, so reparent it back out again before
- * deleting the wrapper; otherwise the toplevel will get deleted
- * twice (once implicitly by the deletion of the wrapper).
- */
- XUnmapWindow(winPtr->display, winPtr->window);
- XReparentWindow(winPtr->display, winPtr->window,
- XRootWindow(winPtr->display, winPtr->screenNum), 0, 0);
- Tk_DestroyWindow((Tk_Window) wmPtr->wrapperPtr);
- }
- while (wmPtr->protPtr != NULL) {
- ProtocolHandler *protPtr;
- protPtr = wmPtr->protPtr;
- wmPtr->protPtr = protPtr->nextPtr;
- Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC);
- }
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- }
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- }
- if (wmPtr->flags & WM_UPDATE_PENDING) {
- Tcl_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
- }
- /*
- * Reset all transient windows whose master is the dead window.
- */
- for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
- wmPtr2 = wmPtr2->nextPtr) {
- if (wmPtr2->masterPtr == winPtr) {
- wmPtr->numTransients--;
- Tk_DeleteEventHandler((Tk_Window) wmPtr2->masterPtr,
- StructureNotifyMask,
- WmWaitMapProc, (ClientData) wmPtr2->winPtr);
- wmPtr2->masterPtr = NULL;
- if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
- XDeleteProperty(winPtr->display, wmPtr2->wrapperPtr->window,
- Tk_InternAtom((Tk_Window) winPtr, "WM_TRANSIENT_FOR"));
- /* FIXME: Need a call like Win32's UpdateWrapper() so
- we can recreate the wrapper and get rid of the
- transient window decorations. */
- }
- }
- }
- if (wmPtr->numTransients != 0)
- Tcl_Panic("numTransients should be 0");
- if (wmPtr->masterPtr != NULL) {
- wmPtr2 = wmPtr->masterPtr->wmInfoPtr;
- /*
- * If we had a master, tell them that we aren't tied
- * to them anymore
- */
- if (wmPtr2 != NULL) {
- wmPtr2->numTransients--;
- }
- Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
- StructureNotifyMask,
- WmWaitMapProc, (ClientData) winPtr);
- wmPtr->masterPtr = NULL;
- }
- ckfree((char *) wmPtr);
- winPtr->wmInfoPtr = NULL;
- }
- /*
- *--------------------------------------------------------------
- *
- * TkWmSetClass --
- *
- * This procedure is invoked whenever a top-level window's
- * class is changed. If the window has been mapped then this
- * procedure updates the window manager property for the
- * class. If the window hasn't been mapped, the update is
- * deferred until just before the first mapping.
- *
- * Results:
- * None.
- *
- * Side effects:
- * A window property may get updated.
- *
- *--------------------------------------------------------------
- */
- void
- TkWmSetClass(winPtr)
- TkWindow *winPtr; /* Newly-created top-level window. */
- {
- if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
- return;
- }
- if (winPtr->classUid != NULL) {
- XClassHint *classPtr;
- Tcl_DString name, class;
- Tcl_UtfToExternalDString(NULL, winPtr->nameUid, -1, &name);
- Tcl_UtfToExternalDString(NULL, winPtr->classUid, -1, &class);
- classPtr = XAllocClassHint();
- classPtr->res_name = Tcl_DStringValue(&name);
- classPtr->res_class = Tcl_DStringValue(&class);
- XSetClassHint(winPtr->display, winPtr->wmInfoPtr->wrapperPtr->window,
- classPtr);
- XFree((char *) classPtr);
- Tcl_DStringFree(&name);
- Tcl_DStringFree(&class);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * Tk_WmObjCmd --
- *
- * This procedure is invoked to process the "wm" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- /* ARGSUSED */
- int
- Tk_WmObjCmd(clientData, interp, objc, objv)
- ClientData clientData; /* Main window associated with
- * interpreter. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- Tk_Window tkwin = (Tk_Window) clientData;
- static CONST char *optionStrings[] = {
- "aspect", "attributes", "client", "colormapwindows",
- "command", "deiconify", "focusmodel", "frame",
- "geometry", "grid", "group", "iconbitmap",
- "iconify", "iconmask", "iconname",
- "iconphoto", "iconposition",
- "iconwindow", "maxsize", "minsize", "overrideredirect",
- "positionfrom", "protocol", "resizable", "sizefrom",
- "stackorder", "state", "title", "transient",
- "withdraw", (char *) NULL };
- enum options {
- WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS,
- WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FRAME,
- WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBITMAP,
- WMOPT_ICONIFY, WMOPT_ICONMASK, WMOPT_ICONNAME,
- WMOPT_ICONPHOTO, WMOPT_ICONPOSITION,
- WMOPT_ICONWINDOW, WMOPT_MAXSIZE, WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT,
- WMOPT_POSITIONFROM, WMOPT_PROTOCOL, WMOPT_RESIZABLE, WMOPT_SIZEFROM,
- WMOPT_STACKORDER, WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT,
- WMOPT_WITHDRAW };
- int index;
- int length;
- char *argv1;
- TkWindow *winPtr;
- TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
- if (objc < 2) {
- wrongNumArgs:
- Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
- return TCL_ERROR;
- }
- argv1 = Tcl_GetStringFromObj(objv[1], &length);
- if ((argv1[0] == 't') && (strncmp(argv1, "tracing", (size_t) length) == 0)
- && (length >= 3)) {
- int wmTracing;
- if ((objc != 2) && (objc != 3)) {
- Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
- return TCL_ERROR;
- }
- if (objc == 2) {
- Tcl_SetResult(interp,
- ((dispPtr->flags & TK_DISPLAY_WM_TRACING) ? "on" : "off"),
- TCL_STATIC);
- return TCL_OK;
- }
- if (Tcl_GetBooleanFromObj(interp, objv[2], &wmTracing) != TCL_OK) {
- return TCL_ERROR;
- }
- if (wmTracing) {
- dispPtr->flags |= TK_DISPLAY_WM_TRACING;
- } else {
- dispPtr->flags &= ~TK_DISPLAY_WM_TRACING;
- }
- return TCL_OK;
- }
- if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0,
- &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (objc < 3) {
- goto wrongNumArgs;
- }
- if (TkGetWindowFromObj(interp, tkwin, objv[2], (Tk_Window *) &winPtr)
- != TCL_OK) {
- return TCL_ERROR;
- }
- if (!Tk_IsTopLevel(winPtr)) {
- Tcl_AppendResult(interp, "window "", winPtr->pathName,
- "" isn't a top-level window", (char *) NULL);
- return TCL_ERROR;
- }
- switch ((enum options) index) {
- case WMOPT_ASPECT:
- return WmAspectCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ATTRIBUTES:
- return WmAttributesCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_CLIENT:
- return WmClientCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_COLORMAPWINDOWS:
- return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_COMMAND:
- return WmCommandCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_DEICONIFY:
- return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_FOCUSMODEL:
- return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_FRAME:
- return WmFrameCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_GEOMETRY:
- return WmGeometryCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_GRID:
- return WmGridCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_GROUP:
- return WmGroupCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONBITMAP:
- return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONIFY:
- return WmIconifyCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONMASK:
- return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONNAME:
- return WmIconnameCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONPHOTO:
- return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONPOSITION:
- return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONWINDOW:
- return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_MAXSIZE:
- return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_MINSIZE:
- return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_OVERRIDEREDIRECT:
- return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_POSITIONFROM:
- return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_PROTOCOL:
- return WmProtocolCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_RESIZABLE:
- return WmResizableCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_SIZEFROM:
- return WmSizefromCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_STACKORDER:
- return WmStackorderCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_STATE:
- return WmStateCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_TITLE:
- return WmTitleCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_TRANSIENT:
- return WmTransientCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_WITHDRAW:
- return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv);
- }
- /* This should not happen */
- return TCL_ERROR;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmAspectCmd --
- *
- * This procedure is invoked to process the "wm aspect" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmAspectCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- int numer1, denom1, numer2, denom2;
- if ((objc != 3) && (objc != 7)) {
- Tcl_WrongNumArgs(interp, 2, objv,
- "window ?minNumer minDenom maxNumer maxDenom?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->sizeHintsFlags & PAspect) {
- char buf[TCL_INTEGER_SPACE * 4];
- sprintf(buf, "%d %d %d %d", wmPtr->minAspect.x,
- wmPtr->minAspect.y, wmPtr->maxAspect.x,
- wmPtr->maxAspect.y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- wmPtr->sizeHintsFlags &= ~PAspect;
- } else {
- if ((Tcl_GetIntFromObj(interp, objv[3], &numer1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) {
- return TCL_ERROR;
- }
- if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) ||
- (denom2 <= 0)) {
- Tcl_SetResult(interp, "aspect number can't be <= 0",
- TCL_STATIC);
- return TCL_ERROR;
- }
- wmPtr->minAspect.x = numer1;
- wmPtr->minAspect.y = denom1;
- wmPtr->maxAspect.x = numer2;
- wmPtr->maxAspect.y = denom2;
- wmPtr->sizeHintsFlags |= PAspect;
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmAttributesCmd --
- *
- * This procedure is invoked to process the "wm attributes" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmAttributesCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "window");
- return TCL_ERROR;
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmClientCmd --
- *
- * This procedure is invoked to process the "wm client" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmClientCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- char *argv3;
- int length;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?name?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->clientMachine != NULL) {
- Tcl_SetResult(interp, wmPtr->clientMachine, TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- if (argv3[0] == 0) {
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- wmPtr->clientMachine = NULL;
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
- Tk_InternAtom((Tk_Window) winPtr,
- "WM_CLIENT_MACHINE"));
- }
- }
- return TCL_OK;
- }
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- }
- wmPtr->clientMachine = (char *)
- ckalloc((unsigned) (length + 1));
- strcpy(wmPtr->clientMachine, argv3);
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- XTextProperty textProp;
- Tcl_DString ds;
- Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, -1, &ds);
- if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
- &textProp) != 0) {
- XSetWMClientMachine(winPtr->display, wmPtr->wrapperPtr->window,
- &textProp);
- XFree((char *) textProp.value);
- }
- Tcl_DStringFree(&ds);
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmColormapwindowsCmd --
- *
- * This procedure is invoked to process the "wm colormapwindows"
- * Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Window *cmapList;
- TkWindow *winPtr2;
- int count, i, windowObjc, gotToplevel;
- Tcl_Obj **windowObjv;
- char buffer[20];
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?windowList?");
- return TCL_ERROR;
- }
- Tk_MakeWindowExist((Tk_Window) winPtr);
- if (wmPtr->wrapperPtr == NULL) {
- CreateWrapper(wmPtr);
- }
- if (objc == 3) {
- if (XGetWMColormapWindows(winPtr->display,
- wmPtr->wrapperPtr->window, &cmapList, &count) == 0) {
- return TCL_OK;
- }
- for (i = 0; i < count; i++) {
- if ((i == (count-1))
- && (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
- break;
- }
- winPtr2 = (TkWindow *) Tk_IdToWindow(winPtr->display,
- cmapList[i]);
- if (winPtr2 == NULL) {
- sprintf(buffer, "0x%lx", cmapList[i]);
- Tcl_AppendElement(interp, buffer);
- } else {
- Tcl_AppendElement(interp, winPtr2->pathName);
- }
- }
- XFree((char *) cmapList);
- return TCL_OK;
- }
- if (Tcl_ListObjGetElements(interp, objv[3], &windowObjc, &windowObjv)
- != TCL_OK) {
- return TCL_ERROR;
- }
- cmapList = (Window *) ckalloc((unsigned)
- ((windowObjc+1)*sizeof(Window)));
- gotToplevel = 0;
- for (i = 0; i < windowObjc; i++) {
- if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
- (Tk_Window *) &winPtr2) != TCL_OK)
- {
- ckfree((char *) cmapList);
- return TCL_ERROR;
- }
- if (winPtr2 == winPtr) {
- gotToplevel = 1;
- }
- if (winPtr2->window == None) {
- Tk_MakeWindowExist((Tk_Window) winPtr2);
- }
- cmapList[i] = winPtr2->window;
- }
- if (!gotToplevel) {
- wmPtr->flags |= WM_ADDED_TOPLEVEL_COLORMAP;
- cmapList[windowObjc] = wmPtr->wrapperPtr->window;
- windowObjc++;
- } else {
- wmPtr->flags &= ~WM_ADDED_TOPLEVEL_COLORMAP;
- }
- wmPtr->flags |= WM_COLORMAPS_EXPLICIT;
- XSetWMColormapWindows(winPtr->display, wmPtr->wrapperPtr->window,
- cmapList, windowObjc);
- ckfree((char *) cmapList);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmCommandCmd --
- *
- * This procedure is invoked to process the "wm command" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmCommandCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- char *argv3;
- int cmdArgc;
- CONST char **cmdArgv;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?value?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->cmdArgv != NULL) {
- Tcl_SetResult(interp,
- Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv),
- TCL_DYNAMIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (argv3[0] == 0) {
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- wmPtr->cmdArgv = NULL;
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
- Tk_InternAtom((Tk_Window) winPtr, "WM_COMMAND"));
- }
- }
- return TCL_OK;
- }
- if (Tcl_SplitList(interp, argv3, &cmdArgc, &cmdArgv) != TCL_OK) {
- return TCL_ERROR;
- }
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- }
- wmPtr->cmdArgc = cmdArgc;
- wmPtr->cmdArgv = cmdArgv;
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- UpdateCommand(winPtr);
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmDeiconifyCmd --
- *
- * This procedure is invoked to process the "wm deiconify" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "window");
- return TCL_ERROR;
- }
- if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't deiconify ", Tcl_GetString(objv[2]),
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
- (char *) NULL);
- return TCL_ERROR;
- }
- if (winPtr->flags & TK_EMBEDDED) {
- Tcl_AppendResult(interp, "can't deiconify ", winPtr->pathName,
- ": it is an embedded window", (char *) NULL);
- return TCL_ERROR;
- }
- wmPtr->flags &= ~WM_WITHDRAWN;
- TkpWmSetState(winPtr, NormalState);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmFocusmodelCmd --
- *
- * This procedure is invoked to process the "wm focusmodel" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- static CONST char *optionStrings[] = {
- "active", "passive", (char *) NULL };
- enum options {
- OPT_ACTIVE, OPT_PASSIVE };
- int index;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?active|passive?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- Tcl_SetResult(interp, (wmPtr->hints.input ? "passive" : "active"),
- TCL_STATIC);
- return TCL_OK;
- }
- if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
- &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (index == OPT_ACTIVE) {
- wmPtr->hints.input = False;
- } else { /* OPT_PASSIVE */
- wmPtr->hints.input = True;
- }
- UpdateHints(winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmFrameCmd --
- *
- * This procedure is invoked to process the "wm frame" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmFrameCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Window window;
- char buf[TCL_INTEGER_SPACE];
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "window");
- return TCL_ERROR;
- }
- window = wmPtr->reparent;
- if (window == None) {
- window = Tk_WindowId((Tk_Window) winPtr);
- }
- sprintf(buf, "0x%x", (unsigned int) window);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmGeometryCmd --
- *
- * This procedure is invoked to process the "wm geometry" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmGeometryCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- char xSign, ySign;
- int width, height;
- char *argv3;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?newGeometry?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- char buf[16 + TCL_INTEGER_SPACE * 4];
- xSign = (wmPtr->flags & WM_NEGATIVE_X) ? '-' : '+';
- ySign = (wmPtr->flags & WM_NEGATIVE_Y) ? '-' : '+';
- if (wmPtr->gridWin != NULL) {
- width = wmPtr->reqGridWidth + (winPtr->changes.width
- - winPtr->reqWidth)/wmPtr->widthInc;
- height = wmPtr->reqGridHeight + (winPtr->changes.height
- - winPtr->reqHeight)/wmPtr->heightInc;
- } else {
- width = winPtr->changes.width;
- height = winPtr->changes.height;
- }
- sprintf(buf, "%dx%d%c%d%c%d", width, height, xSign, wmPtr->x,
- ySign, wmPtr->y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (*argv3 == ' ') {
- wmPtr->width = -1;
- wmPtr->height = -1;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- return ParseGeometry(interp, argv3, winPtr);
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmGridCmd --
- *
- * This procedure is invoked to process the "wm grid" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmGridCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- int reqWidth, reqHeight, widthInc, heightInc;
- if ((objc != 3) && (objc != 7)) {
- Tcl_WrongNumArgs(interp, 2, objv,
- "window ?baseWidth baseHeight widthInc heightInc?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->sizeHintsFlags & PBaseSize) {
- char buf[TCL_INTEGER_SPACE * 4];
- sprintf(buf, "%d %d %d %d", wmPtr->reqGridWidth,
- wmPtr->reqGridHeight, wmPtr->widthInc,
- wmPtr->heightInc);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- /*
- * Turn off gridding and reset the width and height
- * to make sense as ungridded numbers.
- */
- wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
- if (wmPtr->width != -1) {
- wmPtr->width = winPtr->reqWidth + (wmPtr->width
- - wmPtr->reqGridWidth)*wmPtr->widthInc;
- wmPtr->height = winPtr->reqHeight + (wmPtr->height
- - wmPtr->reqGridHeight)*wmPtr->heightInc;
- }
- wmPtr->widthInc = 1;
- wmPtr->heightInc = 1;
- } else {
- if ((Tcl_GetIntFromObj(interp, objv[3], &reqWidth) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[6], &heightInc) != TCL_OK)) {
- return TCL_ERROR;
- }
- if (reqWidth < 0) {
- Tcl_SetResult(interp, "baseWidth can't be < 0", TCL_STATIC);
- return TCL_ERROR;
- }
- if (reqHeight < 0) {
- Tcl_SetResult(interp, "baseHeight can't be < 0", TCL_STATIC);
- return TCL_ERROR;
- }
- if (widthInc <= 0) {
- Tcl_SetResult(interp, "widthInc can't be <= 0", TCL_STATIC);
- return TCL_ERROR;
- }
- if (heightInc <= 0) {
- Tcl_SetResult(interp, "heightInc can't be <= 0", TCL_STATIC);
- return TCL_ERROR;
- }
- Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
- heightInc);
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmGroupCmd --
- *
- * This procedure is invoked to process the "wm group" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmGroupCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Tk_Window tkwin2;
- WmInfo *wmPtr2;
- char *argv3;
- int length;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->hints.flags & WindowGroupHint) {
- Tcl_SetResult(interp, wmPtr->leaderName, TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- if (*argv3 == ' ') {
- wmPtr->hints.flags &= ~WindowGroupHint;
- if (wmPtr->leaderName != NULL) {
- ckfree(wmPtr->leaderName);
- }
- wmPtr->leaderName = NULL;
- } else {
- if (TkGetWindowFromObj(interp, tkwin, objv[3], &tkwin2) != TCL_OK) {
- return TCL_ERROR;
- }
- while (!Tk_TopWinHierarchy(tkwin2)) {
- /*
- * Ensure that the group leader is actually a Tk toplevel.
- */
- tkwin2 = Tk_Parent(tkwin2);
- }
- Tk_MakeWindowExist(tkwin2);
- wmPtr2 = ((TkWindow *) tkwin2)->wmInfoPtr;
- if (wmPtr2->wrapperPtr == NULL) {
- CreateWrapper(wmPtr2);
- }
- if (wmPtr->leaderName != NULL) {
- ckfree(wmPtr->leaderName);
- }
- wmPtr->hints.window_group = Tk_WindowId(wmPtr2->wrapperPtr);
- wmPtr->hints.flags |= WindowGroupHint;
- wmPtr->leaderName = ckalloc((unsigned) (length + 1));
- strcpy(wmPtr->leaderName, argv3);
- }
- UpdateHints(winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconbitmapCmd --
- *
- * This procedure is invoked to process the "wm iconbitmap" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Pixmap pixmap;
- char *argv3;
- if ((objc < 3) || (objc > 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->hints.flags & IconPixmapHint) {
- Tcl_SetResult(interp, (char *)
- Tk_NameOfBitmap(winPtr->display, wmPtr->hints.icon_pixmap),
- TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (*argv3 == ' ') {
- if (wmPtr->hints.icon_pixmap != None) {
- Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
- wmPtr->hints.icon_pixmap = None;
- }
- wmPtr->hints.flags &= ~IconPixmapHint;
- } else {
- pixmap = Tk_GetBitmap(interp, (Tk_Window) winPtr, argv3);
- if (pixmap == None) {
- return TCL_ERROR;
- }
- wmPtr->hints.icon_pixmap = pixmap;
- wmPtr->hints.flags |= IconPixmapHint;
- }
- UpdateHints(winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconifyCmd --
- *
- * This procedure is invoked to process the "wm iconify" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconifyCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "window");
- return TCL_ERROR;
- }
- if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
- Tcl_AppendResult(interp, "can't iconify "", winPtr->pathName,
- "": override-redirect flag is set", (char *) NULL);
- return TCL_ERROR;
- }
- if (wmPtr->masterPtr != NULL) {
- Tcl_AppendResult(interp, "can't iconify "", winPtr->pathName,
- "": it is a transient", (char *) NULL);
- return TCL_ERROR;
- }
- if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't iconify ", winPtr->pathName,
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
- (char *) NULL);
- return TCL_ERROR;
- }
- if (winPtr->flags & TK_EMBEDDED) {
- Tcl_AppendResult(interp, "can't iconify ", winPtr->pathName,
- ": it is an embedded window", (char *) NULL);
- return TCL_ERROR;
- }
- if (TkpWmSetState(winPtr, IconicState) == 0) {
- Tcl_SetResult(interp,
- "couldn't send iconify message to window manager",
- TCL_STATIC);
- return TCL_ERROR;
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconmaskCmd --
- *
- * This procedure is invoked to process the "wm iconmask" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconmaskCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Pixmap pixmap;
- char *argv3;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->hints.flags & IconMaskHint) {
- Tcl_SetResult(interp, (char *)
- Tk_NameOfBitmap(winPtr->display, wmPtr->hints.icon_mask),
- TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (*argv3 == ' ') {
- if (wmPtr->hints.icon_mask != None) {
- Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_mask);
- }
- wmPtr->hints.flags &= ~IconMaskHint;
- } else {
- pixmap = Tk_GetBitmap(interp, tkwin, argv3);
- if (pixmap == None) {
- return TCL_ERROR;
- }
- wmPtr->hints.icon_mask = pixmap;
- wmPtr->hints.flags |= IconMaskHint;
- }
- UpdateHints(winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconnameCmd --
- *
- * This procedure is invoked to process the "wm iconname" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconnameCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- char *argv3;
- int length;
- if (objc > 4) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?newName?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- Tcl_SetResult(interp,
- ((wmPtr->iconName != NULL) ? wmPtr->iconName : ""),
- TCL_STATIC);
- return TCL_OK;
- } else {
- if (wmPtr->iconName != NULL) {
- ckfree((char *) wmPtr->iconName);
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- wmPtr->iconName = ckalloc((unsigned) (length + 1));
- strcpy(wmPtr->iconName, argv3);
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- UpdateTitle(winPtr);
- }
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconphotoCmd --
- *
- * This procedure is invoked to process the "wm iconphoto"
- * Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconphotoCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Tk_PhotoHandle photo;
- Tk_PhotoImageBlock block;
- int i, size = 0, width, height, index = 0, x, y, isDefault = 0;
- long R, G, B, A;
- long *iconPropertyData;
- unsigned char *pixelByte;
- if (objc < 4) {
- Tcl_WrongNumArgs(interp, 2, objv,
- "window ?-default? image1 ?image2 ...?");
- return TCL_ERROR;
- }
- if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) {
- isDefault = 1;
- if (objc == 4) {
- Tcl_WrongNumArgs(interp, 2, objv,
- "window ?-default? image1 ?image2 ...?");
- return TCL_ERROR;
- }
- }
- /*
- * Iterate over all images to retrieve their sizes, in order to allocate a
- * buffer large enough to hold all images.
- */
- for (i = 3 + isDefault; i < objc; i++) {
- photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
- if (photo == NULL) {
- Tcl_AppendResult(interp, "can't use "", Tcl_GetString(objv[i]),
- "" as iconphoto: not a photo image", (char *) NULL);
- return TCL_ERROR;
- }
- Tk_PhotoGetSize(photo, &width, &height);
- /* We need to cardinals for width & height and one cardinal for each
- * image pixel. */
- size += 2 + width * height;
- }
- /* We have calculated the size of the data. Try to allocate the needed
- * memory space. */
- iconPropertyData = (long *) Tcl_AttemptAlloc(sizeof(long)*size);
- if (iconPropertyData == NULL) {
- return TCL_ERROR;
- }
- memset(iconPropertyData, 0, sizeof(long)*size);
- for (i = 3 + isDefault; i < objc; i++) {
- photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
- if (photo == NULL) {
- Tcl_Free((char *) iconPropertyData);
- return TCL_ERROR;
- }
- Tk_PhotoGetSize(photo, &width, &height);
- Tk_PhotoGetImage(photo, &block);
- /*
- * Each image data will be placed as an array of 32bit packed
- * CARDINAL, in a window property named "_NET_WM_ICON":
- * _NET_WM_ICON
- *
- * _NET_WM_ICON CARDINAL[][2+n]/32
- *
- * This is an array of possible icons for the client.
- * This specification does not stipulate what size these icons should
- * be, but individual desktop environments or toolkits may do so.
- * The Window Manager MAY scale any of these icons to an appropriate
- * size.
- *
- * This is an array of 32bit packed CARDINAL ARGB with high byte being
- * A, low byte being B. The first two cardinals are width, height.
- * Data is in rows, left to right and top to bottom.
- */
- /*
- * Encode the image data in the iconPropertyData array.
- */
- iconPropertyData[index++] = width;
- iconPropertyData[index++] = height;
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- R = *(block.pixelPtr + x*block.pixelSize +
- y*block.pitch + block.offset[0]);
- G = *(block.pixelPtr + x*block.pixelSize +
- y*block.pitch + block.offset[1]);
- B = *(block.pixelPtr + x*block.pixelSize +
- y*block.pitch + block.offset[2]);
- A = *(block.pixelPtr + x*block.pixelSize +
- y*block.pitch + block.offset[3]);
- pixelByte = (unsigned char *) &iconPropertyData[index];
- pixelByte[3] = A;
- pixelByte[2] = R;
- pixelByte[1] = G;
- pixelByte[0] = B;
- index++;
- }
- }
- }
- if (wmPtr->iconDataPtr != NULL) {
- ckfree((char *)wmPtr->iconDataPtr);
- wmPtr->iconDataPtr = NULL;
- }
- if (isDefault) {
- if (winPtr->dispPtr->iconDataPtr != NULL) {
- ckfree((char *) winPtr->dispPtr->iconDataPtr);
- }
- winPtr->dispPtr->iconDataPtr = (unsigned char *) iconPropertyData;
- winPtr->dispPtr->iconDataSize = size;
- } else {
- wmPtr->iconDataPtr = (unsigned char *) iconPropertyData;
- wmPtr->iconDataSize = size;
- }
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- UpdatePhotoIcon(winPtr);
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconpositionCmd --
- *
- * This procedure is invoked to process the "wm iconposition"
- * Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconpositionCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- int x, y;
- if ((objc != 3) && (objc != 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?x y?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->hints.flags & IconPositionHint) {
- char buf[TCL_INTEGER_SPACE * 2];
- sprintf(buf, "%d %d", wmPtr->hints.icon_x,
- wmPtr->hints.icon_y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- wmPtr->hints.flags &= ~IconPositionHint;
- } else {
- if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)){
- return TCL_ERROR;
- }
- wmPtr->hints.icon_x = x;
- wmPtr->hints.icon_y = y;
- wmPtr->hints.flags |= IconPositionHint;
- }
- UpdateHints(winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmIconwindowCmd --
- *
- * This procedure is invoked to process the "wm iconwindow" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmIconwindowCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- Tk_Window tkwin2;
- WmInfo *wmPtr2;
- XSetWindowAttributes atts;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->icon != NULL) {
- Tcl_SetResult(interp, Tk_PathName(wmPtr->icon), TCL_STATIC);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- wmPtr->hints.flags &= ~IconWindowHint;
- if (wmPtr->icon != NULL) {
- /*
- * Remove the icon window relationship. In principle we
- * should also re-enable button events for the window, but
- * this doesn't work in general because the window manager
- * is probably selecting on them (we'll get an error if
- * we try to re-enable the events). So, just leave the
- * icon window event-challenged; the user will have to
- * recreate it if they want button events.
- */
- wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
- wmPtr2->iconFor = NULL;
- wmPtr2->withdrawn = 1;
- wmPtr2->hints.initial_state = WithdrawnState;
- }
- wmPtr->icon = NULL;
- } else {
- if (TkGetWindowFromObj(interp, tkwin, objv[3], &tkwin2) != TCL_OK) {
- return TCL_ERROR;
- }
- if (!Tk_IsTopLevel(tkwin2)) {
- Tcl_AppendResult(interp, "can't use ", Tcl_GetString(objv[3]),
- " as icon window: not at top level", (char *) NULL);
- return TCL_ERROR;
- }
- wmPtr2 = ((TkWindow *) tkwin2)->wmInfoPtr;
- if (wmPtr2->iconFor != NULL) {
- Tcl_AppendResult(interp, Tcl_GetString(objv[3]),
- " is already an icon for ",
- Tk_PathName(wmPtr2->iconFor), (char *) NULL);
- return TCL_ERROR;
- }
- if (wmPtr->icon != NULL) {
- WmInfo *wmPtr3 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
- wmPtr3->iconFor = NULL;
- wmPtr3->withdrawn = 1;
- wmPtr3->hints.initial_state = WithdrawnState;
- }
- /*
- * Disable button events in the icon window: some window
- * managers (like olvwm) want to get the events themselves,
- * but X only allows one application at a time to receive
- * button events for a window.
- */
- atts.event_mask = Tk_Attributes(tkwin2)->event_mask
- & ~ButtonPressMask;
- Tk_ChangeWindowAttributes(tkwin2, CWEventMask, &atts);
- Tk_MakeWindowExist(tkwin2);
- if (wmPtr2->wrapperPtr == NULL) {
- CreateWrapper(wmPtr2);
- }
- wmPtr->hints.icon_window = Tk_WindowId(wmPtr2->wrapperPtr);
- wmPtr->hints.flags |= IconWindowHint;
- wmPtr->icon = tkwin2;
- wmPtr2->iconFor = (Tk_Window) winPtr;
- if (!wmPtr2->withdrawn && !(wmPtr2->flags & WM_NEVER_MAPPED)) {
- wmPtr2->withdrawn = 0;
- if (XWithdrawWindow(Tk_Display(tkwin2),
- Tk_WindowId(wmPtr2->wrapperPtr),
- Tk_ScreenNumber(tkwin2)) == 0) {
- Tcl_SetResult(interp,
- "couldn't send withdraw message to window manager",
- TCL_STATIC);
- return TCL_ERROR;
- }
- WaitForMapNotify((TkWindow *) tkwin2, 0);
- }
- }
- UpdateHints(winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmMaxsizeCmd --
- *
- * This procedure is invoked to process the "wm maxsize" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- int width, height;
- if ((objc != 3) && (objc != 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- char buf[TCL_INTEGER_SPACE * 2];
- GetMaxSize(wmPtr, &width, &height);
- sprintf(buf, "%d %d", width, height);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- return TCL_OK;
- }
- if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
- return TCL_ERROR;
- }
- wmPtr->maxWidth = width;
- wmPtr->maxHeight = height;
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- if (width <= 0 && height <= 0) {
- wmPtr->sizeHintsFlags &= ~PMaxSize;
- } else {
- wmPtr->sizeHintsFlags |= PMaxSize;
- }
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmMinsizeCmd --
- *
- * This procedure is invoked to process the "wm minsize" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmMinsizeCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- int width, height;
- if ((objc != 3) && (objc != 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- char buf[TCL_INTEGER_SPACE * 2];
- sprintf(buf, "%d %d", wmPtr->minWidth, wmPtr->minHeight);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- return TCL_OK;
- }
- if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
- return TCL_ERROR;
- }
- wmPtr->minWidth = width;
- wmPtr->minHeight = height;
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmOverrideredirectCmd --
- *
- * This procedure is invoked to process the "wm overrideredirect"
- * Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- int boolean, curValue;
- XSetWindowAttributes atts;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
- return TCL_ERROR;
- }
- curValue = Tk_Attributes((Tk_Window) winPtr)->override_redirect;
- if (objc == 3) {
- Tcl_SetBooleanObj(Tcl_GetObjResult(interp), curValue);
- return TCL_OK;
- }
- if (Tcl_GetBooleanFromObj(interp, objv[3], &boolean) != TCL_OK) {
- return TCL_ERROR;
- }
- if (curValue != boolean) {
- /*
- * Only do this if we are really changing value, because it
- * causes some funky stuff to occur
- */
- atts.override_redirect = (boolean) ? True : False;
- Tk_ChangeWindowAttributes((Tk_Window) winPtr, CWOverrideRedirect,
- &atts);
- if (winPtr->wmInfoPtr->wrapperPtr != NULL) {
- Tk_ChangeWindowAttributes(
- (Tk_Window) winPtr->wmInfoPtr->wrapperPtr,
- CWOverrideRedirect, &atts);
- }
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmPositionfromCmd --
- *
- * This procedure is invoked to process the "wm positionfrom"
- * Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmPositionfromCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- static CONST char *optionStrings[] = {
- "program", "user", (char *) NULL };
- enum options {
- OPT_PROGRAM, OPT_USER };
- int index;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?user/program?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->sizeHintsFlags & USPosition) {
- Tcl_SetResult(interp, "user", TCL_STATIC);
- } else if (wmPtr->sizeHintsFlags & PPosition) {
- Tcl_SetResult(interp, "program", TCL_STATIC);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- wmPtr->sizeHintsFlags &= ~(USPosition|PPosition);
- } else {
- if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
- &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (index == OPT_USER) {
- wmPtr->sizeHintsFlags &= ~PPosition;
- wmPtr->sizeHintsFlags |= USPosition;
- } else {
- wmPtr->sizeHintsFlags &= ~USPosition;
- wmPtr->sizeHintsFlags |= PPosition;
- }
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmProtocolCmd --
- *
- * This procedure is invoked to process the "wm protocol" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmProtocolCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- register ProtocolHandler *protPtr, *prevPtr;
- Atom protocol;
- char *cmd;
- int cmdLength;
- if ((objc < 3) || (objc > 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?name? ?command?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- /*
- * Return a list of all defined protocols for the window.
- */
- for (protPtr = wmPtr->protPtr; protPtr != NULL;
- protPtr = protPtr->nextPtr) {
- Tcl_AppendElement(interp,
- Tk_GetAtomName((Tk_Window) winPtr, protPtr->protocol));
- }
- return TCL_OK;
- }
- protocol = Tk_InternAtom((Tk_Window) winPtr, Tcl_GetString(objv[3]));
- if (objc == 4) {
- /*
- * Return the command to handle a given protocol.
- */
- for (protPtr = wmPtr->protPtr; protPtr != NULL;
- protPtr = protPtr->nextPtr) {
- if (protPtr->protocol == protocol) {
- Tcl_SetResult(interp, protPtr->command, TCL_STATIC);
- return TCL_OK;
- }
- }
- return TCL_OK;
- }
- /*
- * Delete any current protocol handler, then create a new
- * one with the specified command, unless the command is
- * empty.
- */
- for (protPtr = wmPtr->protPtr, prevPtr = NULL; protPtr != NULL;
- prevPtr = protPtr, protPtr = protPtr->nextPtr) {
- if (protPtr->protocol == protocol) {
- if (prevPtr == NULL) {
- wmPtr->protPtr = protPtr->nextPtr;
- } else {
- prevPtr->nextPtr = protPtr->nextPtr;
- }
- Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC);
- break;
- }
- }
- cmd = Tcl_GetStringFromObj(objv[4], &cmdLength);
- if (cmdLength > 0) {
- protPtr = (ProtocolHandler *) ckalloc(HANDLER_SIZE(cmdLength));
- protPtr->protocol = protocol;
- protPtr->nextPtr = wmPtr->protPtr;
- wmPtr->protPtr = protPtr;
- protPtr->interp = interp;
- strcpy(protPtr->command, cmd);
- }
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- UpdateWmProtocols(wmPtr);
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmResizableCmd --
- *
- * This procedure is invoked to process the "wm resizable" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmResizableCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- int width, height;
- if ((objc != 3) && (objc != 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- char buf[TCL_INTEGER_SPACE * 2];
- sprintf(buf, "%d %d",
- (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) ? 0 : 1,
- (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) ? 0 : 1);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- return TCL_OK;
- }
- if ((Tcl_GetBooleanFromObj(interp, objv[3], &width) != TCL_OK)
- || (Tcl_GetBooleanFromObj(interp, objv[4], &height) != TCL_OK)) {
- return TCL_ERROR;
- }
- if (width) {
- wmPtr->flags &= ~WM_WIDTH_NOT_RESIZABLE;
- } else {
- wmPtr->flags |= WM_WIDTH_NOT_RESIZABLE;
- }
- if (height) {
- wmPtr->flags &= ~WM_HEIGHT_NOT_RESIZABLE;
- } else {
- wmPtr->flags |= WM_HEIGHT_NOT_RESIZABLE;
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmSizefromCmd --
- *
- * This procedure is invoked to process the "wm sizefrom" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmSizefromCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- static CONST char *optionStrings[] = {
- "program", "user", (char *) NULL };
- enum options {
- OPT_PROGRAM, OPT_USER };
- int index;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?user|program?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->sizeHintsFlags & USSize) {
- Tcl_SetResult(interp, "user", TCL_STATIC);
- } else if (wmPtr->sizeHintsFlags & PSize) {
- Tcl_SetResult(interp, "program", TCL_STATIC);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- wmPtr->sizeHintsFlags &= ~(USSize|PSize);
- } else {
- if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
- &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (index == OPT_USER) {
- wmPtr->sizeHintsFlags &= ~PSize;
- wmPtr->sizeHintsFlags |= USSize;
- } else { /* OPT_PROGRAM */
- wmPtr->sizeHintsFlags &= ~USSize;
- wmPtr->sizeHintsFlags |= PSize;
- }
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmStackorderCmd --
- *
- * This procedure is invoked to process the "wm stackorder" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmStackorderCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- TkWindow **windows, **window_ptr;
- static CONST char *optionStrings[] = {
- "isabove", "isbelow", (char *) NULL };
- enum options {
- OPT_ISABOVE, OPT_ISBELOW };
- int index;
- if ((objc != 3) && (objc != 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?isabove|isbelow window?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- windows = TkWmStackorderToplevel(winPtr);
- if (windows == NULL) {
- Tcl_Panic("TkWmStackorderToplevel failed");
- } else {
- for (window_ptr = windows; *window_ptr ; window_ptr++) {
- Tcl_AppendElement(interp, (*window_ptr)->pathName);
- }
- ckfree((char *) windows);
- return TCL_OK;
- }
- } else {
- TkWindow *winPtr2;
- int index1=-1, index2=-1, result;
- if (TkGetWindowFromObj(interp, tkwin, objv[4], (Tk_Window *) &winPtr2)
- != TCL_OK) {
- return TCL_ERROR;
- }
- if (!Tk_IsTopLevel(winPtr2)) {
- Tcl_AppendResult(interp, "window "", winPtr2->pathName,
- "" isn't a top-level window", (char *) NULL);
- return TCL_ERROR;
- }
- if (!Tk_IsMapped(winPtr)) {
- Tcl_AppendResult(interp, "window "", winPtr->pathName,
- "" isn't mapped", (char *) NULL);
- return TCL_ERROR;
- }
- if (!Tk_IsMapped(winPtr2)) {
- Tcl_AppendResult(interp, "window "", winPtr2->pathName,
- "" isn't mapped", (char *) NULL);
- return TCL_ERROR;
- }
- /*
- * Lookup stacking order of all toplevels that are children
- * of "." and find the position of winPtr and winPtr2
- * in the stacking order.
- */
- windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr);
- if (windows == NULL) {
- Tcl_AppendResult(interp, "TkWmStackorderToplevel failed",
- (char *) NULL);
- return TCL_ERROR;
- } else {
- for (window_ptr = windows; *window_ptr ; window_ptr++) {
- if (*window_ptr == winPtr)
- index1 = (window_ptr - windows);
- if (*window_ptr == winPtr2)
- index2 = (window_ptr - windows);
- }
- if (index1 == -1)
- Tcl_Panic("winPtr window not found");
- if (index2 == -1)
- Tcl_Panic("winPtr2 window not found");
- ckfree((char *) windows);
- }
- if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
- &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (index == OPT_ISABOVE) {
- result = index1 > index2;
- } else { /* OPT_ISBELOW */
- result = index1 < index2;
- }
- Tcl_SetIntObj(Tcl_GetObjResult(interp), result);
- return TCL_OK;
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmStateCmd --
- *
- * This procedure is invoked to process the "wm state" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmStateCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- static CONST char *optionStrings[] = {
- "normal", "iconic", "withdrawn", (char *) NULL };
- enum options {
- OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN };
- int index;
- if ((objc < 3) || (objc > 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?state?");
- return TCL_ERROR;
- }
- if (objc == 4) {
- if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't change state of ",
- Tcl_GetString(objv[2]),
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
- (char *) NULL);
- return TCL_ERROR;
- }
- if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
- &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (index == OPT_NORMAL) {
- wmPtr->flags &= ~WM_WITHDRAWN;
- (void) TkpWmSetState(winPtr, NormalState);
- } else if (index == OPT_ICONIC) {
- if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
- Tcl_AppendResult(interp, "can't iconify "",
- winPtr->pathName,
- "": override-redirect flag is set",
- (char *) NULL);
- return TCL_ERROR;
- }
- if (wmPtr->masterPtr != NULL) {
- Tcl_AppendResult(interp, "can't iconify "",
- winPtr->pathName,
- "": it is a transient", (char *) NULL);
- return TCL_ERROR;
- }
- if (TkpWmSetState(winPtr, IconicState) == 0) {
- Tcl_SetResult(interp,
- "couldn't send iconify message to window manager",
- TCL_STATIC);
- return TCL_ERROR;
- }
- } else { /* OPT_WITHDRAWN */
- wmPtr->flags |= WM_WITHDRAWN;
- if (TkpWmSetState(winPtr, WithdrawnState) == 0) {
- Tcl_SetResult(interp,
- "couldn't send withdraw message to window manager",
- TCL_STATIC);
- return TCL_ERROR;
- }
- }
- } else {
- if (wmPtr->iconFor != NULL) {
- Tcl_SetResult(interp, "icon", TCL_STATIC);
- } else if (wmPtr->withdrawn) {
- Tcl_SetResult(interp, "withdrawn", TCL_STATIC);
- } else if (Tk_IsMapped((Tk_Window) winPtr)
- || ((wmPtr->flags & WM_NEVER_MAPPED)
- && (wmPtr->hints.initial_state == NormalState))) {
- Tcl_SetResult(interp, "normal", TCL_STATIC);
- } else {
- Tcl_SetResult(interp, "iconic", TCL_STATIC);
- }
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmTitleCmd --
- *
- * This procedure is invoked to process the "wm title" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmTitleCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- char *argv3;
- int length;
- if (objc > 4) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?newTitle?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- Tcl_SetResult(interp, (char *)
- ((wmPtr->title != NULL) ? wmPtr->title : winPtr->nameUid),
- TCL_STATIC);
- return TCL_OK;
- } else {
- if (wmPtr->title != NULL) {
- ckfree((char *) wmPtr->title);
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- wmPtr->title = ckalloc((unsigned) (length + 1));
- strcpy(wmPtr->title, argv3);
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- UpdateTitle(winPtr);
- }
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmTransientCmd --
- *
- * This procedure is invoked to process the "wm transient" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmTransientCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- TkWindow *masterPtr = wmPtr->masterPtr;
- WmInfo *wmPtr2;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?master?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (masterPtr != NULL) {
- Tcl_SetResult(interp, Tk_PathName(masterPtr), TCL_STATIC);
- }
- return TCL_OK;
- }
- if (Tcl_GetString(objv[3])[0] == ' ') {
- if (masterPtr != NULL) {
- /*
- * If we had a master, tell them that we aren't tied
- * to them anymore
- */
- masterPtr->wmInfoPtr->numTransients--;
- Tk_DeleteEventHandler((Tk_Window) masterPtr,
- StructureNotifyMask,
- WmWaitMapProc, (ClientData) winPtr);
- /* FIXME: Need a call like Win32's UpdateWrapper() so
- we can recreate the wrapper and get rid of the
- transient window decorations. */
- }
- wmPtr->masterPtr = NULL;
- } else {
- if (TkGetWindowFromObj(interp, tkwin, objv[3],
- (Tk_Window *) &masterPtr) != TCL_OK) {
- return TCL_ERROR;
- }
- while (!Tk_TopWinHierarchy(masterPtr)) {
- /*
- * Ensure that the master window is actually a Tk toplevel.
- */
- masterPtr = masterPtr->parentPtr;
- }
- Tk_MakeWindowExist((Tk_Window) masterPtr);
- if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't make "",
- Tcl_GetString(objv[2]),
- "" a transient: it is an icon for ",
- Tk_PathName(wmPtr->iconFor),
- (char *) NULL);
- return TCL_ERROR;
- }
- wmPtr2 = masterPtr->wmInfoPtr;
- if (wmPtr2->wrapperPtr == NULL) {
- CreateWrapper(wmPtr2);
- }
- if (wmPtr2->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't make "",
- Tcl_GetString(objv[3]),
- "" a master: it is an icon for ",
- Tk_PathName(wmPtr2->iconFor),
- (char *) NULL);
- return TCL_ERROR;
- }
- if (masterPtr == winPtr) {
- Tcl_AppendResult(interp, "can't make "", Tk_PathName(winPtr),
- "" its own master",
- (char *) NULL);
- return TCL_ERROR;
- } else if (masterPtr != wmPtr->masterPtr) {
- /*
- * Remove old master map/unmap binding before setting
- * the new master. The event handler will ensure that
- * transient states reflect the state of the master.
- */
- if (wmPtr->masterPtr != NULL) {
- wmPtr->masterPtr->wmInfoPtr->numTransients--;
- Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
- StructureNotifyMask,
- WmWaitMapProc, (ClientData) winPtr);
- }
- masterPtr->wmInfoPtr->numTransients++;
- Tk_CreateEventHandler((Tk_Window) masterPtr,
- StructureNotifyMask,
- WmWaitMapProc, (ClientData) winPtr);
- wmPtr->masterPtr = masterPtr;
- }
- }
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- if (wmPtr->masterPtr != NULL && !Tk_IsMapped(wmPtr->masterPtr)) {
- if (TkpWmSetState(winPtr, WithdrawnState) == 0) {
- Tcl_SetResult(interp,
- "couldn't send withdraw message to window manager",
- TCL_STATIC);
- return TCL_ERROR;
- }
- } else {
- if (wmPtr->masterPtr != NULL) {
- XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
- wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
- } else {
- XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
- Tk_InternAtom((Tk_Window)winPtr, "WM_TRANSIENT_FOR"));
- }
- }
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmWithdrawCmd --
- *
- * This procedure is invoked to process the "wm withdraw" Tcl command.
- * See the user documentation for details on what it does.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmWithdrawCmd(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "window");
- return TCL_ERROR;
- }
- if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't withdraw ", Tcl_GetString(objv[2]),
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
- (char *) NULL);
- return TCL_ERROR;
- }
- wmPtr->flags |= WM_WITHDRAWN;
- if (TkpWmSetState(winPtr, WithdrawnState) == 0) {
- Tcl_SetResult(interp,
- "couldn't send withdraw message to window manager",
- TCL_STATIC);
- return TCL_ERROR;
- }
- return TCL_OK;
- }
- /*
- * Invoked by those wm subcommands that affect geometry.
- * Schedules a geometry update.
- */
- static void
- WmUpdateGeom(wmPtr, winPtr)
- WmInfo *wmPtr;
- TkWindow *winPtr;
- {
- if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
- Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr);
- wmPtr->flags |= WM_UPDATE_PENDING;
- }
- }
- /*
- * Invoked when a MapNotify or UnmapNotify event is delivered for a
- * toplevel that is the master of a transient toplevel.
- */
- static void
- WmWaitMapProc(clientData, eventPtr)
- ClientData clientData; /* Pointer to window. */
- XEvent *eventPtr; /* Information about event. */
- {
- TkWindow *winPtr = (TkWindow *) clientData;
- TkWindow *masterPtr = winPtr->wmInfoPtr->masterPtr;
- if (masterPtr == NULL)
- return;
- if (eventPtr->type == MapNotify) {
- if (!(winPtr->wmInfoPtr->flags & WM_WITHDRAWN))
- (void) TkpWmSetState(winPtr, NormalState);